Hello friends in this article we are going to see how you can add More than one internal table in SAP ABAP using OOPS ABAP Concept.
Scenario
Displaying more than one table in ALV grid report by splitting the custom container.
TABLE 1 | TABLE 2 |
TABLE 3 |
Step by step Solution
Step 1: Creating Screen
Go to Screen painter Transaction Code SE51.
Create a screen with no 9010.
Provide description for the screen and click on the Layout Button.
Place a Custom container UI element and give name as ‘CCONTAINER’ now you will have a screen with custom container as below screen shot. Activate the Object.
Step 2: Flow Logic
Go to the Flow Logic Tab to write coding for PBO & PAI.
Step 3: Report
Go to SE38 and create a program in Z name space and paste the following code snippet.
*&---------------------------------------------------------------------* *& Report ZPC_CONTAINER_CONTROL * *&---------------------------------------------------------------------* REPORT zpc_container_control.
*Declaration DATA: Splitter_1 TYPE REF TO cl_gui_splitter_container, Splitter_2 TYPE REF TO cl_gui_splitter_container, Container TYPE REF TO cl_gui_custom_container, Container_1 TYPE REF TO cl_gui_container, Container_2 TYPE REF TO cl_gui_container, Container_3 TYPE REF TO cl_gui_container, Grid1 TYPE REF TO cl_gui_alv_grid, Grid2 TYPE REF TO cl_gui_alv_grid, Grid3 TYPE REF TO cl_gui_alv_grid. DATA: Gt_sflight_1 TYPE TABLE OF sflight, Gt_sflight_2 TYPE TABLE OF sflight, Gt_sflight_3 TYPE TABLE OF sflight, G_container TYPE scrfname VALUE 'CCONTAINER'. DATA: ok_code TYPE sy-ucomm.
* fetching data from table for different internal tables SELECT * FROM sflight INTO TABLE gt_sflight_1. “Itab 1 SELECT * FROM sflight INTO TABLE gt_sflight_2 UP TO 3 ROWS. “Itab 2 SELECT * FROM sflight INTO TABLE gt_sflight_3 UP TO 2 ROWS. “Itab 3
CALL SCREEN 9010.
*&---------------------------------------------------------------------* *& Module STATUS_9010 OUTPUT * *&---------------------------------------------------------------------* MODULE status_9010 OUTPUT. SET PF-STATUS 'TEST'.
*creating object reference for container CREATE OBJECT container EXPORTING container_name = 'CCONTAINER'. “Pass name of container created in Screen no 9010 *splitting the main container into 1 row & 2 coloum CREATE OBJECT splitter_1 EXPORTING Parent = container Rows = 1 Columns = 2. *getting the reference for the splited container (row 1 & col 1 container) CALL METHOD splitter_1->get_container EXPORTING Row = 1 Column = 1 RECEIVING Container = container_1. *getting the reference for the splited container (row 1 & col 2 container) CALL METHOD splitter_1->get_container EXPORTING Row = 1 Column = 2 RECEIVING Container = container_2. *splitting the 2nd coloum container in to 2 rows & 1 coloum CREATE OBJECT splitter_2 EXPORTING Parent = container_2 Rows = 2 Columns = 1. *getting the reference for the splited container2 (row 1 & col 2 container) CALL METHOD splitter_2->get_container EXPORTING Row = 1 Column = 1 RECEIVING Container = container_2. *getting the reference for the splited container2 (row 2 & col 1 container) CALL METHOD splitter_2->get_container EXPORTING Row = 2 Column = 1 RECEIVING Container = container_3. *populating first internal table to the container CREATE OBJECT container EXPORTING container_name = g_container. CREATE OBJECT grid1 EXPORTING i_parent = container_1. CALL METHOD grid1->set_table_for_first_display EXPORTING i_structure_name = 'SFLIGHT' CHANGING it_outtab = gt_sflight_1. *populating second internal table CREATE OBJECT container EXPORTING container_name = g_container. CREATE OBJECT grid2 EXPORTING i_parent = container_2. CALL METHOD grid2->set_table_for_first_display EXPORTING i_structure_name = 'SFLIGHT' CHANGING it_outtab = gt_sflight_2. *populating third internal table CREATE OBJECT container EXPORTING container_name = g_container. CREATE OBJECT grid3 EXPORTING i_parent = container_3. CALL METHOD grid3->set_table_for_first_display EXPORTING i_structure_name = 'SFLIGHT' CHANGING it_outtab = gt_sflight_3. ENDMODULE. “STATUS_9010 OUTPUT
*&---------------------------------------------------------------------* *& Module EXIT INPUT * *&---------------------------------------------------------------------* MODULE exit INPUT. *free the container memory when exit CALL METHOD container->free. LEAVE PROGRAM. ENDMODULE. “EXIT INPUT
*&---------------------------------------------------------------------* *& Module USER_COMMAND_9010 INPUT * *&---------------------------------------------------------------------* MODULE user_command_9010 INPUT. CALL METHOD cl_gui_cfw=>dispatch. CASE ok_code. WHEN 'BACK'. LEAVE SCREEN. WHEN 'CANCEL'. LEAVE PROGRAM. WHEN 'EXIT'. LEAVE SCREEN. ENDCASE. ENDMODULE. “USER_COMMAND_9010 INPUT