You are on page 1of 55

Containers in Object Oriented ABAP

A SAP Container is a control that accommodates other controls, such as the SAP Tree Control, SAP Picture Control, SAP Textedit Control, SAP Splitter Control, and so on. It manages these controls logically in a collection, and provides a physical area in which they are displayed. All controls lives in a container. Since containers are themselves controls, you can nest them. The container is the parent of the control within it. They are 5 types of containers are available in SAP. These are shown below: 1. 2. 3. 4. 5. Custom Container Splitter Container Docking Container Dialog Box Container Easy Splitter Container

All SAP Containers have a common parent with the type CL_GUI_CONTROL. They are all derived from this basic container, and therefore all have the same object-oriented interface. Some of the controls types are shows below: 1. 2. 3. 4. 5. 6. 7. 8. HTML Control, Picture Control, Container Control Tree Control, Grid Control Text edit Control, Splitter Control, Table Control and so on.

Example programs for the different types of Containers

Custom Container
The Custom Container display controls in an area defined on a normal screen using the Screen Painter SE51. The class used for Custom Container is CL_GUI_CUSTOM_CONTAINER.

Use
Use the SAP Custom Container to build a control into an area on a screen or subscreen. You define the area occupied by the control in the Screen Painter. The default size of the control that you place in the Custom Container is the same as that of the container itself.

Prerequisites
Before you can include a control in a Custom Container, you must define the area that the container will occupy. You do this in the Screen Painter.

Objective:
The following procedure shows designing of custom container, it displays the list of Sales Details. 1. First you have create a program in SE38 and then create a screen in SE51 and place the custom container in it as shown below :

2. Provide name as CONTAINER.

3. Then perform the below steps for the Custom Container.

Create the Custom Container Create the Grid for the Custom Containers Get the data from databas table. Build the field catalog for displaying data onto the grid. Data displayed on to the grid.

Source Code:
Code for SE38: *&---------------------------------------------------------------------* *& Report ZSR_CUSTOM_CONTAINER *& *&---------------------------------------------------------------------* *& *& *&---------------------------------------------------------------------* REPORT ZSR_CUSTOM_CONTAINER.

*******Data Declarations.............. DATA : O_CUSTOM TYPE REF TO CL_GUI_CUSTOM_CONTAINER, O_GRID TYPE REF TO CL_GUI_ALV_GRID. * For Sales Data DATA : T_VBAK TYPE TABLE OF VBAK, * For Field Catalog T_FIELDCAT TYPE LVC_T_FCAT. ******Extracting the Data..... SELECT * FROM VBAK INTO TABLE T_VBAK UP TO 30 ROWS. ****** Call the Screen with Custom Control....... CALL SCREEN 0001. *&---------------------------------------------------------------------* *& Module STATUS_0001 OUTPUT *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* MODULE STATUS_0001 OUTPUT. SET PF-STATUS 'STATUS'. SET TITLEBAR 'TITLE'. * To fill the Field Catalog CALL FUNCTION 'LVC_FIELDCATALOG_MERGE' EXPORTING * I_BUFFER_ACTIVE = I_STRUCTURE_NAME = 'VBAK' * I_CLIENT_NEVER_DISPLAY = 'X'

* *

I_BYPASSING_BUFFER = I_INTERNAL_TABNAME = CHANGING CT_FIELDCAT = T_FIELDCAT EXCEPTIONS INCONSISTENT_INTERFACE = 1 PROGRAM_ERROR = 2 OTHERS = 3 . IF SY-SUBRC <> 0. * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO * WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4. ENDIF. CREATE OBJECT O_CUSTOM EXPORTING * parent = CONTAINER_NAME = EXCEPTIONS CNTL_ERROR = CNTL_SYSTEM_ERROR = CREATE_ERROR = LIFETIME_ERROR = LIFETIME_DYNPRO_DYNPRO_LINK = OTHERS = . IF SY-SUBRC <> 0. * MESSAGE ID SY-MSGID TYPE SY-MSGTY * WITH SY-MSGV1 SY-MSGV2 ENDIF.

'CONTAINER' 1 2 3 4 5 6

NUMBER SY-MSGNO SY-MSGV3 SY-MSGV4.

* To Create the Grid Instance CREATE OBJECT O_GRID EXPORTING I_PARENT = O_CUSTOM EXCEPTIONS ERROR_CNTL_CREATE = 1 ERROR_CNTL_INIT = 2 ERROR_CNTL_LINK = 3 ERROR_DP_CREATE = 4 OTHERS = 5. IF SY-SUBRC <> 0. MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4. ENDIF. " IF sy-subrc <> 0. * Formatted Output Table is Sent to Control CALL METHOD O_GRID->SET_TABLE_FOR_FIRST_DISPLAY

CHANGING IT_OUTTAB = T_VBAK IT_FIELDCATALOG = T_FIELDCAT * it_sort = * it_filter = EXCEPTIONS INVALID_PARAMETER_COMBINATION = 1 PROGRAM_ERROR = 2 TOO_MANY_LINES = 3 OTHERS = 4 . IF SY-SUBRC <> 0. MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4. ENDIF. ENDMODULE. " STATUS_0001 OUTPUT *&---------------------------------------------------------------------* *& Module USER_COMMAND_0001 INPUT *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* MODULE USER_COMMAND_0001 INPUT. CASE SY-UCOMM. WHEN 'BACK' OR 'CANCEL' OR 'EXIT'. LEAVE TO SCREEN 0. ENDCASE.

ENDMODULE. Code for SE51: PROCESS MODULE * PROCESS MODULE BEFORE OUTPUT. STATUS_0001. AFTER INPUT. USER_COMMAND_0001.

" USER_COMMAND_0001

INPUT

Output :
Then it will shows the output as below:

Splitter Container
To display more than one control in a given area by dividing it into cells. The class used for Custom Container is CL_GUI_SPLITTER_CONTAINER

Use
Use the SAP Splitter Container to construct a group of control within an area, each of which is placed in a separate cell. The Splitter Control manages and displays the cells. You can change the size of the cells using a splitter bar. Enlarging one cell reduces the size of the adjacent cell. You can only use the Splitter Container within another container (parent), for example, a Custom Container or Docking Container. You can embed a Splitter Control within a cell of another Splitter Container and thus nest them. The default setting for the splitter grid is 0X0. The maximum division is 16X16. You can specify the size of lines and columns either in pixels (absolute) or as a percentage (relative). The default setting is relative. You can set the splitter bar to immovable.

Prerequisites

Before you can include a control in a Splitter Container, you must define the area that the container will occupy. You do this in the Screen Painter.

Objective:
The following procedure shows designing of Splitter container, it displays the list of Purchasing Document Header Details in one control and Item details in another control. 1. First you have create a program in SE38 and then create a screen in SE51 and place the custom container in it as shown below :

2. Provide name as CONTAINER.

3. Then perform the below steps for the Splitter Container. Create the Custom Container Create the Splitter Container

Create the 2 Grids for the Custom Containers Create 2 ALVs for the data Get the data from databas table. Split the Contianer into Two rows and one column Assign the splitted containers to the grids. Data displayed on to the grid.

Source Code:
Then below is the code will execute splitter container: Code for SE38: *&---------------------------------------------------------------------* *& Report ZSR_SPLITTER_CONTAINER *& *&---------------------------------------------------------------------* *& *& *&---------------------------------------------------------------------* REPORT ZSR_SPLITTER_CONTAINER NO STANDARD PAGE HEADING.

*******Data Declarations.............. DATA : O_CUSTOM TYPE REF TO CL_GUI_CUSTOM_CONTAINER, "Custom container O_SPLITTER TYPE REF TO CL_GUI_SPLITTER_CONTAINER, "Splitter Container O_GRID1 TYPE REF TO CL_GUI_CONTAINER, "Grid1 O_GRID2 TYPE REF TO CL_GUI_CONTAINER, "Grid2 O_DISPLAY TYPE REF TO CL_SALV_DISPLAY_SETTINGS, "ALV Display Settings SALV1 TYPE REF TO CL_SALV_TABLE, "ALV Table1 SALV2 TYPE REF TO CL_SALV_TABLE, "ALV Table2 T_EKKO TYPE TABLE OF EKKO, "Purchasing Document Header Table T_EKPO TYPE TABLE OF EKPO. "Purchasing Document Item Table ******Extracting the Data..... SELECT * FROM EKKO INTO TABLE T_EKKO UP TO 10 ROWS. SELECT * FROM EKPO INTO TABLE T_EKPO UP TO 10 ROWS. ****** Call the Screen with Custom Control....... CALL SCREEN 0001. *&---------------------------------------------------------------------* *& Module STATUS_0001 OUTPUT *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* MODULE STATUS_0001 OUTPUT. ****Setting PF Status and Title bar...........

SET PF-STATUS 'ZSTAT'. SET TITLEBAR 'TITLE'. *****Creating object for container...... CREATE OBJECT O_CUSTOM EXPORTING CONTAINER_NAME = 'CONTAINER'. *****Assgning object for splitter container...... CREATE OBJECT O_SPLITTER EXPORTING PARENT = O_CUSTOM ROWS = 2 COLUMNS = 1. ********Divding Splitter Container into two rows and one column ......... **********Refer GRID1, GRID2 to the each Splitter container ....... CALL METHOD O_SPLITTER->GET_CONTAINER EXPORTING ROW = 1 COLUMN = 1 RECEIVING CONTAINER = O_GRID1. CALL METHOD O_SPLITTER->GET_CONTAINER EXPORTING ROW = 2 COLUMN = 1 RECEIVING CONTAINER = O_GRID2. *******Creating new instance of ALV table for each grid and passing output da ta to it....... TRY. CALL METHOD CL_SALV_TABLE=>FACTORY EXPORTING * list_display = IF_SALV_C_BOOL_SAP=>FALSE R_CONTAINER = O_GRID1 * container_name = IMPORTING R_SALV_TABLE = SALV1 CHANGING T_TABLE = T_EKKO . CATCH CX_SALV_MSG . ENDTRY. TRY. CALL METHOD CL_SALV_TABLE=>FACTORY

* *

EXPORTING list_display = IF_SALV_C_BOOL_SAP=>FALSE R_CONTAINER = O_GRID2 container_name = IMPORTING R_SALV_TABLE = SALV2 CHANGING T_TABLE = T_EKPO . CATCH CX_SALV_MSG . ENDTRY.

*******Setting Text for Header Details.. O_DISPLAY = SALV1->GET_DISPLAY_SETTINGS( ). O_DISPLAY->SET_STRIPED_PATTERN( CL_SALV_DISPLAY_SETTINGS=>TRUE ). O_DISPLAY->SET_LIST_HEADER( 'Purchasing Doc Header Details' ). * ********Setting Text for Item Details.. O_DISPLAY = SALV2->GET_DISPLAY_SETTINGS( ). O_DISPLAY->SET_STRIPED_PATTERN( CL_SALV_DISPLAY_SETTINGS=>TRUE ). O_DISPLAY->SET_LIST_HEADER( 'Purcahsing Doc Item Details' ). ******Displaying Data...... CALL METHOD SALV1->DISPLAY. CALL METHOD SALV2->DISPLAY. ENDMODULE. " STATUS_0001 OUTPUT *&---------------------------------------------------------------------* *& Module USER_COMMAND_0001 INPUT *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* MODULE USER_COMMAND_0001 INPUT. CASE SY-UCOMM. WHEN 'BACK' OR 'EXIT' OR 'CANCEL'. LEAVE TO SCREEN 0. ENDCASE. ENDMODULE. Code for SE51: PROCESS MODULE * PROCESS MODULE BEFORE OUTPUT. STATUS_0001. AFTER INPUT. USER_COMMAND_0001.

" USER_COMMAND_0001

INPUT

Output :
Then it will show below output:

Objective2:
The following procedure shows designing of Splitter container, it displays the list of Purchasing Document st nd rd Header Details in 1 control and Item details in 2 control and Purchase Requistion in 3 Control. 1. First you have create a program in SE38 and then create a screen in SE51 and place the custom container in it as shown below :

2. Provide name as CONTAINER.

3. Then perform the below steps for the Splitter Container. Create the Custom Container Create the Splitter Container

Create the 3 Grids for the Custom Containers Create 3 Alvs for the data to display Get the data from databas table. Split the Contianer into Three rows and one column Assign the splitted containers to the grids. Data displayed on to the grid.

Source Code:
Then below is the code will execute splitter container: Code for SE38: *&---------------------------------------------------------------------* *& Report ZSR_SPLITTER_CONTAINER *& *&---------------------------------------------------------------------* *& *& *&---------------------------------------------------------------------* REPORT ZSR_SPLITTER_CONTAINER_3 NO STANDARD PAGE HEADING.

*******Data Declarations.............. DATA : O_CUSTOM TYPE REF TO CL_GUI_CUSTOM_CONTAINER, "Custom container O_GRID1 TYPE REF TO CL_GUI_CONTAINER, "Grid1 O_GRID2 TYPE REF TO CL_GUI_CONTAINER, "Grid2 O_GRID3 TYPE REF TO CL_GUI_CONTAINER, "Grid3 O_SPLITTER TYPE REF TO CL_GUI_SPLITTER_CONTAINER, "Splitter Container O_DISPLAY TYPE REF TO CL_SALV_DISPLAY_SETTINGS, "ALV Display Settings SALV1 TYPE REF TO CL_SALV_TABLE, "ALV Table1 SALV2 TYPE REF TO CL_SALV_TABLE, "ALV Table2 SALV3 TYPE REF TO CL_SALV_TABLE, "ALV Table3 T_EKKO TYPE TABLE OF EKKO, "Purchasing Document Head er Table T_EKPO TYPE TABLE OF EKPO, "Purchasing Document Item Table T_EBAN TYPE TABLE OF EBAN. "Purchasing Document Item Table ******Extracting the Data..... SELECT * FROM EKKO INTO TABLE T_EKKO UP TO 10 ROWS. SELECT * FROM EKPO INTO TABLE T_EKPO UP TO 10 ROWS. SELECT * FROM EBAN INTO TABLE T_EBAN UP TO 10 ROWS. ****** Call the Screen with Custom Control....... CALL SCREEN 0001. *&---------------------------------------------------------------------*

*& Module STATUS_0001 OUTPUT *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* MODULE STATUS_0001 OUTPUT. ****Setting PF Status and Title bar........... SET PF-STATUS 'ZSTAT'. SET TITLEBAR 'TITLE'. *****Creating object for container...... CREATE OBJECT O_CUSTOM EXPORTING CONTAINER_NAME = 'CONTAINER'. *****Assgning object for splitter container...... CREATE OBJECT O_SPLITTER EXPORTING PARENT = O_CUSTOM ROWS = 3 COLUMNS = 1. ********Divding Splitter Container into two rows and one column ......... **********Refer GRID1, GRID2 to the each Splitter container ....... CALL METHOD O_SPLITTER->GET_CONTAINER EXPORTING ROW = 1 COLUMN = 1 RECEIVING CONTAINER = O_GRID1. CALL METHOD O_SPLITTER->GET_CONTAINER EXPORTING ROW = 2 COLUMN = 1 RECEIVING CONTAINER = O_GRID2. CALL METHOD O_SPLITTER->GET_CONTAINER EXPORTING ROW = 3 COLUMN = 1 RECEIVING CONTAINER = O_GRID3. *******Creating new instance of ALV table for each grid and passing output da ta to it....... TRY. CALL METHOD CL_SALV_TABLE=>FACTORY EXPORTING * list_display = IF_SALV_C_BOOL_SAP=>FALSE

R_CONTAINER container_name = IMPORTING R_SALV_TABLE CHANGING T_TABLE . CATCH CX_SALV_MSG . ENDTRY. TRY.

= O_GRID1

= SALV1 = T_EKKO

* *

CALL METHOD CL_SALV_TABLE=>FACTORY EXPORTING list_display = IF_SALV_C_BOOL_SAP=>FALSE R_CONTAINER = O_GRID2 container_name = IMPORTING R_SALV_TABLE = SALV2 CHANGING T_TABLE = T_EKPO . CATCH CX_SALV_MSG . ENDTRY. TRY. CALL METHOD CL_SALV_TABLE=>FACTORY EXPORTING list_display = IF_SALV_C_BOOL_SAP=>FALSE R_CONTAINER = O_GRID3 container_name = IMPORTING R_SALV_TABLE = SALV3 CHANGING T_TABLE = T_EBAN . CATCH CX_SALV_MSG . ENDTRY.

* *

*******Setting Text for Header Details.. O_DISPLAY = SALV1->GET_DISPLAY_SETTINGS( ). O_DISPLAY->SET_STRIPED_PATTERN( CL_SALV_DISPLAY_SETTINGS=>TRUE ). O_DISPLAY->SET_LIST_HEADER( 'Purchasing Doc Header Details' ). * ********Setting Text for Item Details.. O_DISPLAY = SALV2->GET_DISPLAY_SETTINGS( ). O_DISPLAY->SET_STRIPED_PATTERN( CL_SALV_DISPLAY_SETTINGS=>TRUE ). O_DISPLAY->SET_LIST_HEADER( 'Purcahsing Doc Item Details' ).

********Setting Text for Purchase Requisition Details.. O_DISPLAY = SALV3->GET_DISPLAY_SETTINGS( ). O_DISPLAY->SET_STRIPED_PATTERN( CL_SALV_DISPLAY_SETTINGS=>TRUE ). O_DISPLAY->SET_LIST_HEADER( 'Purchase Requisition Details' ). ******Displaying Data...... CALL METHOD SALV1->DISPLAY. CALL METHOD SALV2->DISPLAY. CALL METHOD SALV3->DISPLAY. ENDMODULE. " STATUS_0001 OUTPUT *&---------------------------------------------------------------------* *& Module USER_COMMAND_0001 INPUT *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* MODULE USER_COMMAND_0001 INPUT. CASE SY-UCOMM. WHEN 'BACK' OR 'EXIT' OR 'CANCEL'. LEAVE TO SCREEN 0. ENDCASE. ENDMODULE. Code for SE51: PROCESS MODULE * PROCESS MODULE BEFORE OUTPUT. STATUS_0001. AFTER INPUT. USER_COMMAND_0001.

" USER_COMMAND_0001

INPUT

Output :
Then it will show below output:

So with the help of Splitter Container, we can divide it into maximum of 16X16 cells. This is not possible with the Easy Splitter Container.

Docking Container
The SAP Docking Container allows you to attach a control to any of the four edges of a screen as a resizable screen area like TOP, BOTTOM, LEFT and RIGHT. You can also detach it so that it becomes an independent modal dialog box. The class used for Custom Container is CL_GUI_DOCKING_CONTAINER

Use
Use the SAP Docking Container to attach one or more areas to a screen. The screen is made smaller to accommodate the docking container. You can detach the docking container from the screen (floating) and reattach it.

The behavior of the areas in the container is determined by the sequence in which they are initialized. Docking Containers are attached to the screen from the inside out. This means that when you create a second container, it is attached to the edge of the screen, and the container that was already there is pushed outwards. From a purely technical point of view, you can attach any number of docking containers to a screen. However, remember that using too many can make your application confusing for the user.

Prerequisites
In Screen Painter you have the design the screen as per your requirement. Here, am adding one field Customer as input variable.

Objective:
The following procedure shows designing of Docking container, it displays the list of Customer details based on the user selection in the input field. In this example am attaching Docking Container at bottom of the screen. 1. First design the screen painter as per the requirement shown below:

Note : No need to place Custom container on the screen. 2. Then perform the below steps for the Docking Container. Create the Docking Container Create the Grid for the Docking Container at the bottom Assign the Docking container to the grid. Get the data from databas table. Prepare fieldcatalog to display output. Data displayed on to the grid.

Source Code:
Code for SE38: *&---------------------------------------------------------------------* *& Report ZSR_DOCKING_CONTAINER

*& *&---------------------------------------------------------------------* *& *& *&---------------------------------------------------------------------* REPORT ZSR_DOCKING_CONTAINER_CUSTOMER.

TABLES : KNA1. *---------------------------------------------------------------------* * W O R K A R E A S * *---------------------------------------------------------------------* DATA: WA_KNA1 TYPE KNA1. *---------------------------------------------------------------------* * I N T E R N A L T A B L E S * *---------------------------------------------------------------------* DATA: * For Customer Data T_KNA1 LIKE STANDARD TABLE OF WA_KNA1, * For Field Catalog T_FIELDCAT TYPE LVC_T_FCAT. *---------------------------------------------------------------------* * W O R K V A R I A B L E S * *---------------------------------------------------------------------* DATA: * User Command OK_CODE TYPE SY-UCOMM, * Reference Variable for Docking Container R_DOCK_CONTAINER TYPE REF TO CL_GUI_DOCKING_CONTAINER, * Reference Variable for alv grid R_GRID TYPE REF TO CL_GUI_ALV_GRID. *---------------------------------------------------------------------* * S T A R T O F S E L E C T I O N * *---------------------------------------------------------------------* START-OF-SELECTION. * To Display the Data PERFORM DISPLAY_OUTPUT. *&--------------------------------------------------------------------* *& Form display_output * *&--------------------------------------------------------------------* * To Call the screen & display the output * *---------------------------------------------------------------------* * There are no interface parameters to be passed to this subroutine.* *---------------------------------------------------------------------* FORM DISPLAY_OUTPUT . * To fill the Field Catalog

* * * *

* * * *

* *

CALL FUNCTION 'LVC_FIELDCATALOG_MERGE' EXPORTING I_BUFFER_ACTIVE = I_STRUCTURE_NAME = 'KNA1' I_CLIENT_NEVER_DISPLAY = 'X' I_BYPASSING_BUFFER = I_INTERNAL_TABNAME = CHANGING CT_FIELDCAT = T_FIELDCAT EXCEPTIONS INCONSISTENT_INTERFACE = 1 PROGRAM_ERROR = 2 OTHERS = 3 . IF SY-SUBRC <> 0. MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4. ENDIF.

CALL SCREEN 0001. ENDFORM.

" Display_output

*&---------------------------------------------------------------------* *& Module STATUS_0001 OUTPUT *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* MODULE STATUS_0001 OUTPUT. SET PF-STATUS 'STATUS'. SET TITLEBAR 'TITLE'. ENDMODULE. " STATUS_0001 OUTPUT *&---------------------------------------------------------------------* *& Module CREATE_OBJECT OUTPUT *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* MODULE CREATE_OBJECT OUTPUT. * Create a Docking container and dock the control at bottom of the screen CHECK R_DOCK_CONTAINER IS INITIAL. CREATE OBJECT R_DOCK_CONTAINER EXPORTING SIDE = CL_GUI_DOCKING_CONTAINER=>DOCK_AT_BOTTOM EXTENSION = 123 CAPTION = 'CUSTOMERS' EXCEPTIONS

CNTL_ERROR = 1 CNTL_SYSTEM_ERROR = 2 CREATE_ERROR = 3 LIFETIME_ERROR = 4 LIFETIME_DYNPRO_DYNPRO_LINK = 5 OTHERS = 6. IF SY-SUBRC <> 0. MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4. ENDIF. " IF sy-subrc <> 0. * To Create the Grid Instance CREATE OBJECT R_GRID EXPORTING I_PARENT = R_DOCK_CONTAINER EXCEPTIONS ERROR_CNTL_CREATE = 1 ERROR_CNTL_INIT = 2 ERROR_CNTL_LINK = 3 ERROR_DP_CREATE = 4 OTHERS = 5. IF SY-SUBRC <> 0. MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4. ENDIF. " IF sy-subrc <> 0. * Formatted Output Table is Sent to Control CALL METHOD R_GRID->SET_TABLE_FOR_FIRST_DISPLAY CHANGING IT_OUTTAB = T_KNA1 IT_FIELDCATALOG = T_FIELDCAT * it_sort = * it_filter = EXCEPTIONS INVALID_PARAMETER_COMBINATION = 1 PROGRAM_ERROR = 2 TOO_MANY_LINES = 3 OTHERS = 4 . IF SY-SUBRC <> 0. MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4. ENDIF. ENDMODULE. " CREATE_OBJECT OUTPUT *&---------------------------------------------------------------------* *& Module USER_COMMAND_0001 INPUT *&---------------------------------------------------------------------* * text

*----------------------------------------------------------------------* MODULE USER_COMMAND_0001 INPUT. CASE OK_CODE. WHEN 'EXECUTE'. SELECT * FROM KNA1 INTO TABLE T_KNA1 WHERE KUNNR = KNA1-KUNNR. CALL METHOD R_GRID->REFRESH_TABLE_DISPLAY. WHEN 'BACK' OR 'CANCEL' OR 'EXIT'. LEAVE TO SCREEN 0. ENDCASE. ENDMODULE. Code for SE51: PROCESS BEFORE OUTPUT. MODULE STATUS_0001. MODULE CREATE_OBJECT. * PROCESS AFTER INPUT. MODULE USER_COMMAND_0001. " USER_COMMAND_0001 INPUT

Output :
Then it displays output as:

Enter the Customer Number using F4 help and Click on Enter button, then it shows Customer Details below:

Similarly we can divide the screen at Right, Left and Top of the screen. Just change the attribute of Docking Container while creating Object. Here showing same example for all sides, based on the requirement we can design. * Create a Docking container and dock the control at left side of screen CHECK R_DOCK_CONTAINER IS INITIAL. CREATE OBJECT R_DOCK_CONTAINER EXPORTING SIDE = CL_GUI_DOCKING_CONTAINER=>DOCK_AT_LEFT EXTENSION = 123 CAPTION = 'CUSTOMERS' EXCEPTIONS CNTL_ERROR = 1

CNTL_SYSTEM_ERROR = 2 CREATE_ERROR = 3 LIFETIME_ERROR = 4 LIFETIME_DYNPRO_DYNPRO_LINK = 5 OTHERS = 6. IF SY-SUBRC <> 0. MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4. ENDIF. " IF sy-subrc <> 0.

* Create a Docking container and dock the control at right side of screen CHECK R_DOCK_CONTAINER IS INITIAL. CREATE OBJECT R_DOCK_CONTAINER EXPORTING SIDE = CL_GUI_DOCKING_CONTAINER=>DOCK_AT_RIGHT EXTENSION = 123 CAPTION = 'CUSTOMERS' EXCEPTIONS CNTL_ERROR = 1 CNTL_SYSTEM_ERROR = 2 CREATE_ERROR = 3 LIFETIME_ERROR = 4

LIFETIME_DYNPRO_DYNPRO_LINK = 5 OTHERS = 6. IF SY-SUBRC <> 0. MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4. ENDIF. " IF sy-subrc <> 0.

* Create a Docking container and dock the control at TOP of screen CHECK R_DOCK_CONTAINER IS INITIAL. CREATE OBJECT R_DOCK_CONTAINER EXPORTING SIDE = CL_GUI_DOCKING_CONTAINER=>DOCK_AT_TOP EXTENSION = 123 CAPTION = 'CUSTOMERS' EXCEPTIONS CNTL_ERROR = 1 CNTL_SYSTEM_ERROR = 2 CREATE_ERROR = 3 LIFETIME_ERROR = 4 LIFETIME_DYNPRO_DYNPRO_LINK = 5 OTHERS = 6. IF SY-SUBRC <> 0.

MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4. ENDIF. " IF sy-subrc <> 0.

SAP Dialog Box Container


The class used for Custom Container is CL_GUI_ DIALOGBOX _CONTAINER

Use
Use the SAP Dialog Box Container to display controls in an a modal dialog box that can be moved anywhere on the screen. You can also use it to display a control in full screen. Unlike the SAP Docking Container, you cannot attach a SAP Dialog Box Container to a screen.

Prerequisites
In Screen Painter you have to just create the screen.

Objective:

The following procedure shows designing of Dialog Box container, it displays the list of Material details in a Modal Dialog Box using Splitter Container. 1. First create the screen using Screen Painter SE51 as shown below: Note : No need to place any Custom Control on the Screen, simply create empty screen

2. Then perform the following steps: Here first create the Dialbox container. Create class for closing the dialog box. Split the Container into two columns. Create the Grids for the above splitted Containers Get the data from databas table. Build the field catalog for displaying data onto the grid. Data displayed on to the grid.

Source Code:
Code for SE38: *&---------------------------------------------------------------------* *& Report ZSR_DIALOGBOX_CONTAINER *& *&---------------------------------------------------------------------* *& *& *&---------------------------------------------------------------------* REPORT ZSR_DIALOGBOX_CONTAINER1.

* data declarations for creating dialog box container. DATA:DIALOG_BOX TYPE REF TO CL_GUI_DIALOGBOX_CONTAINER, SPLITTER TYPE REF TO CL_GUI_SPLITTER_CONTAINER, CONT1 TYPE REF TO CL_GUI_CONTAINER, CONT2 TYPE REF TO CL_GUI_CONTAINER, GRID TYPE REF TO CL_GUI_ALV_GRID, GRID1 TYPE REF TO CL_GUI_ALV_GRID. * here declaring the internal table for field catalog. DATA:LT_FCAT TYPE LVC_T_FCAT, LS_FCAT TYPE LVC_S_FCAT, LT_FCAT1 TYPE LVC_T_FCAT, LS_FCAT1 TYPE LVC_S_FCAT. * here create the structure for the internal table creation. TYPES:BEGIN OF TY_MARA, MATNR LIKE MARA-MATNR, MTART LIKE MARA-MTART, MBRSH LIKE MARA-MBRSH, END OF TY_MARA. TYPES:BEGIN OF TY_MARC, MATNR LIKE MARC-MATNR, WERKS LIKE MARC-WERKS, LVORM LIKE MARC-LVORM, END OF TY_MARC. * here create the internal table using the above structure. DATA:T_MARA TYPE TABLE OF TY_MARA, T_MARC TYPE TABLE OF TY_MARC, WA_MARA TYPE TY_MARA, WA_MARC TYPE TY_MARC. CREATE OBJECT DIALOG_BOX EXPORTING * parent WIDTH HEIGHT REPID DYNNR TOP LEFT CAPTION Data'.

= = = = = = = =

800 300 SY-REPID '3000' 20 50 'This Dialog displayed MARA and MARC Table

IF SY-SUBRC <> 0. * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO * WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4. ENDIF. * here splitt the dialog box into 1 row and 2 columns CREATE OBJECT SPLITTER EXPORTING PARENT = DIALOG_BOX ROWS = 1 COLUMNS = 2. IF SY-SUBRC <> 0. * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO * WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4. ENDIF. * here get the reference of particular cell in the dialog box iner method returns reference of cell CALL METHOD SPLITTER->GET_CONTAINER EXPORTING ROW = 1 COLUMN = 1 RECEIVING CONTAINER = CONT1. CALL METHOD SPLITTER->GET_CONTAINER EXPORTING ROW = 1 COLUMN = 2 RECEIVING CONTAINER = CONT2. * here creating the class for close the dialogbox event CLASS LCL_DIALOGBOX_HANDLER DEFINITION. PUBLIC SECTION. METHODS:ON_DIALOGBOX_CLOSE FOR EVENT CLOSE OF CL_GUI_DIALOGBOX_CONTAINER IMPORTING SENDER. ENDCLASS. "lcl_dialogbox_handler DEFINITION here get_conta

*----------------------------------------------------------------------* * CLASS lcl_dialogbox_handler IMPLEMENTATION *----------------------------------------------------------------------* * *----------------------------------------------------------------------*

CLASS LCL_DIALOGBOX_HANDLER IMPLEMENTATION. METHOD:ON_DIALOGBOX_CLOSE. IF NOT SENDER IS INITIAL. CALL METHOD SENDER->FREE EXCEPTIONS CNTL_ERROR = 1 CNTL_SYSTEM_ERROR = 2 OTHERS = 3. LEAVE PROGRAM. IF SY-SUBRC <> 0. MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4. ENDIF. ENDIF. ENDMETHOD. ENDCLASS. "on_dialogbox_close "lcl_dialogbox_handler IMPLEMENTATION

* *

DATA:DIALOGBOX_HANDLER TYPE REF TO LCL_DIALOGBOX_HANDLER. START-OF-SELECTION. IF DIALOGBOX_HANDLER IS INITIAL. CREATE OBJECT DIALOGBOX_HANDLER. ENDIF.

* here registering the event SET HANDLER DIALOGBOX_HANDLER->ON_DIALOGBOX_CLOSE FOR ALL INSTANCES. * here getting the data into internal tables SELECT MATNR MTART MBRSH FROM MARA INTO TABLE T_MARA UP TO 20 ROWS. SELECT MATNR WERKS LVORM FROM MARC INTO TABLE T_MARC UP TO 20 ROWS. * here build the field catalog PERFORM BUILD_FCAT. * here display the grid into container

CREATE OBJECT GRID EXPORTING I_PARENT = CONT1. IF SY-SUBRC <> 0. * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO * WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4. ENDIF. CREATE OBJECT GRID1 EXPORTING I_PARENT = CONT2. IF SY-SUBRC <> 0. * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO * WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4. ENDIF. ***************************************************************************** **** * here displaying data in first grid that is mara data ***************************************************************************** ** CALL METHOD GRID->SET_TABLE_FOR_FIRST_DISPLAY * EXPORTING * i_buffer_active = * i_bypassing_buffer = * i_consistency_check = * i_structure_name = * is_variant = * i_save = * i_default = 'X' * is_layout = * is_print = * it_special_groups = * it_toolbar_excluding = * it_hyperlink = * it_alv_graphics = * it_except_qinfo = * ir_salv_adapter = CHANGING IT_OUTTAB = T_MARA IT_FIELDCATALOG = LT_FCAT * it_sort = * it_filter = EXCEPTIONS

INVALID_PARAMETER_COMBINATION PROGRAM_ERROR TOO_MANY_LINES OTHERS . IF SY-SUBRC <> 0. * MESSAGE ID SY-MSGID TYPE SY-MSGTY * WITH SY-MSGV1 SY-MSGV2 ENDIF.

= = = =

1 2 3 4

NUMBER SY-MSGNO SY-MSGV3 SY-MSGV4.

*************************************************************************** * here displaying data in second grid that is marc data ************************************************************************8 CALL METHOD GRID1->SET_TABLE_FOR_FIRST_DISPLAY EXPORTING i_buffer_active = i_bypassing_buffer = i_consistency_check = i_structure_name = is_variant = i_save = i_default = 'X' is_layout = is_print = it_special_groups = it_toolbar_excluding = it_hyperlink = it_alv_graphics = it_except_qinfo = ir_salv_adapter = CHANGING IT_OUTTAB = T_MARC IT_FIELDCATALOG = LT_FCAT1 it_sort = it_filter = EXCEPTIONS INVALID_PARAMETER_COMBINATION = 1 PROGRAM_ERROR = 2 TOO_MANY_LINES = 3 OTHERS = 4 . IF SY-SUBRC <> 0. MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4. ENDIF.

* * * * * * * * * * * * * * * *

* *

* *

CALL SCREEN 3000.

" here calling the scree[n

*&---------------------------------------------------------------------* *& Form BUILD_FCAT *&---------------------------------------------------------------------* FORM BUILD_FCAT . ***************************************************************************** *************************** * here buliding field catalog lt_fact ***************************************************************************** *************************** LS_FCAT-COL_POS = 1. LS_FCAT-ROW_POS = 1. LS_FCAT-FIELDNAME = 'MATNR'. LS_FCAT-TABNAME = 'T_MARA'. LS_FCAT-REPTEXT = 'Material Number'. APPEND LS_FCAT TO LT_FCAT. CLEAR LS_FCAT. LS_FCAT-COL_POS = LS_FCAT-ROW_POS = LS_FCAT-FIELDNAME LS_FCAT-TABNAME = LS_FCAT-REPTEXT = 2. 1. = 'MTART'. 'T_MARA'. 'Material Type'.

APPEND LS_FCAT TO LT_FCAT. CLEAR LS_FCAT. LS_FCAT-COL_POS = LS_FCAT-ROW_POS = LS_FCAT-FIELDNAME LS_FCAT-TABNAME = LS_FCAT-REPTEXT = 3. 1. = 'MBRSH'. 'T_MARA'. 'Industry Sector'.

APPEND LS_FCAT TO LT_FCAT. CLEAR LS_FCAT. ***************************************************************************** *************************** * here buliding field catalog lt_fact1 ***************************************************************************** ***************************

LS_FCAT1-COL_POS = LS_FCAT1-ROW_POS = LS_FCAT1-FIELDNAME LS_FCAT1-TABNAME = LS_FCAT1-REPTEXT =

1. 1. = 'MATNR'. 'T_MARC'. 'Material Number'.

APPEND LS_FCAT1 TO LT_FCAT1. CLEAR LS_FCAT1. LS_FCAT1-COL_POS = LS_FCAT1-ROW_POS = LS_FCAT1-FIELDNAME LS_FCAT1-TABNAME = LS_FCAT1-REPTEXT = 2. 1. = 'WERKS'. 'T_MARC'. 'Plant'.

APPEND LS_FCAT1 TO LT_FCAT1. CLEAR LS_FCAT1. LS_FCAT1-COL_POS = LS_FCAT1-ROW_POS = LS_FCAT1-FIELDNAME LS_FCAT1-TABNAME = LS_FCAT1-REPTEXT = 3. 1. = 'LVORM'. 'T_MARC'. 'Flag Material for Deletion at plant Level'.

APPEND LS_FCAT1 TO LT_FCAT1. CLEAR LS_FCAT1. ENDFORM. Code for SE51: PROCESS BEFORE OUTPUT. * MODULE STATUS_3000. * PROCESS AFTER INPUT. * MODULE USER_COMMAND_3000. " Build fcat

Output :

SAP Easy Splitter Container


The SAP Easy Splitter Container allows you to divide an area into two cells with a control in each. The cells are separated by a moveable splitter bar. The class used for Custom Container is CL_GUI_EASY_SPLITTER_CONTAINER

Use
The SAP Easy Splitter Container is a version of the SAP Splitter Container with a reduced set of features. Use the Easy Splitter Container when you want to display controls in a sector divided into two cells like TOP_LEFT, BOTTOM_RIGHT Containers. You can set the splitter bar between the two cells either horizontally or vertically. You can only use the Easy Splitter Container within another container (parent), for example, a Custom Container or Docking Container. Unlike Splitter container, you cant divide screens morethan 2 as shown in above example of Splitter container.

You can nest Easy Splitter Containers to any depth.

Objective:
The following procedure shows designing of Splitter container, it displays the list of Purchasing Document Header Details in one control and Item details in another control. 1. First you have create a program in SE38 and then create a screen in SE51 and place the custom container in it as shown below :

2. Provide name as CONTAINER.

3. Then perform the below steps for the Splitter Container. Create the Custom Container Create the Easy Splitter Container

Attach the 2 Containers to the Easy Splitter Create the 2 Containers with reference to CL_GUI_CONTAINERS Create 2 ALVs for the data Get the data from databas table for Purchasing Document Haeder and Item Details. Data displayed on to the grid.

Source Code:
Code for SE38: *&--------------------------------------------------------------------* *& Report ZSR_EASY_SPLITTER_CONTAINER *& *&--------------------------------------------------------------------* *& *& *&--------------------------------------------------------------------* REPORT ZSR_EASY_SPLITTER_CONTAINER.

* splitter control DATA SPLITTER TYPE REF TO CL_GUI_EASY_SPLITTER_CONTAINER. * container for the splitter control DATA CONTAINER TYPE REF TO CL_GUI_CUSTOM_CONTAINER. * containers created by the splitter control DATA CONTAINER_1 TYPE REF TO CL_GUI_CONTAINER. DATA CONTAINER_2 TYPE REF TO CL_GUI_CONTAINER. DATA : O_DISPLAY TYPE REF TO CL_SALV_DISPLAY_SETTINGS, "ALV Display Set tings SALV1 TYPE REF TO CL_SALV_TABLE, "ALV Table1 SALV2 TYPE REF TO CL_SALV_TABLE, "ALV Table2 T_EKKO TYPE TABLE OF EKKO, "Purchase D ocument Header table T_EKPO TYPE TABLE OF EKPO. "Purchase D ocument Item table ******Extracting the Data..... SELECT * FROM EKKO INTO TABLE T_EKKO UP TO 25 ROWS. SELECT * FROM EKPO INTO TABLE T_EKPO UP TO 25 ROWS. CALL SCREEN 100. *&--------------------------------------------------------------------* *& Module STATUS_0100 OUTPUT

*&--------------------------------------------------------------------* * text *---------------------------------------------------------------------* MODULE STATUS_0100 OUTPUT. SET PF-STATUS 'STATUS'. * create a container for the splitter control CREATE OBJECT CONTAINER EXPORTING CONTAINER_NAME = 'CONTAINER'. * create the splitter control CREATE OBJECT SPLITTER EXPORTING PARENT = CONTAINER ORIENTATION = 1. * get the containers of the splitter control CONTAINER_1 = SPLITTER->TOP_LEFT_CONTAINER. CONTAINER_2 = SPLITTER->BOTTOM_RIGHT_CONTAINER. *******Creating new instance of ALV table for each grid and passing out put data to it....... TRY. CALL METHOD CL_SALV_TABLE=>FACTORY EXPORTING * list_display = IF_SALV_C_BOOL_SAP=>FALSE R_CONTAINER = CONTAINER_1 * container_name = IMPORTING R_SALV_TABLE = SALV1 CHANGING T_TABLE = T_EKKO . CATCH CX_SALV_MSG . ENDTRY. TRY. CALL METHOD CL_SALV_TABLE=>FACTORY EXPORTING list_display = IF_SALV_C_BOOL_SAP=>FALSE R_CONTAINER = CONTAINER_2 container_name = IMPORTING R_SALV_TABLE = SALV2 CHANGING T_TABLE = T_EKPO .

* *

CATCH CX_SALV_MSG . ENDTRY. *******Setting Text for Header Details.. O_DISPLAY = SALV1->GET_DISPLAY_SETTINGS( ). O_DISPLAY->SET_STRIPED_PATTERN( CL_SALV_DISPLAY_SETTINGS=>TRUE ). O_DISPLAY->SET_LIST_HEADER( 'Purchasing Doc Header Details' ). * ********Setting Text for Item Details.. O_DISPLAY = SALV2->GET_DISPLAY_SETTINGS( ). O_DISPLAY->SET_STRIPED_PATTERN( CL_SALV_DISPLAY_SETTINGS=>TRUE ). O_DISPLAY->SET_LIST_HEADER( 'Purcahsing Doc Item Details' ). ******Displaying Data...... CALL METHOD SALV1->DISPLAY. CALL METHOD SALV2->DISPLAY. ENDMODULE. " STATUS_0100 OUTPUT

*&--------------------------------------------------------------------* *& Module EXIT INPUT *&--------------------------------------------------------------------* * text *---------------------------------------------------------------------* MODULE EXIT INPUT. CALL METHOD CONTAINER->FREE. LEAVE PROGRAM. ENDMODULE. " EXIT INPUT *&--------------------------------------------------------------------* *& Module USER_COMMAND_0100 INPUT *&--------------------------------------------------------------------* * text *---------------------------------------------------------------------* MODULE USER_COMMAND_0100 INPUT. CASE SY-UCOMM. WHEN 'BACK' OR 'EXIT' OR 'CANCEL'. LEAVE TO SCREEN 0. ENDCASE.

ENDMODULE. Code for SE51: PROCESS MODULE * PROCESS MODULE BEFORE OUTPUT. STATUS_0100. AFTER INPUT. USER_COMMAND_0100.

" USER_COMMAND_0100

INPUT

Output :

Tree Control
This control allows you to display tree structures on a screen. It has been developed by SAP, and while it fulfills the basic requirements of a tree control, it has not been adapted for individual applications. There are three different versions of the SAP Tree.

Simple tree structure: A simple tree with a single text entry for each node. List structure: Each node may have more than one entry. The entries are displayed from left to right. Column structure: Tree structure with freely-definable columns.

The R/3 System contains the following example programs: SAPCOLUMN_TREE_CONTROL_DEMO , SAPSIMPLE_TREE_CONTROL_DEMO, and SAPTLIST_TREE_CONTROL_DEMO. In this we are seeing displyaing through ALV output as Simple Tree.

Objective:
To display the ALV ouput as a Tree structure which shows list of Flight Details availble. 1. First design a screen with Custom Container in Screen Painter SE51.

2. Then provide name to Custom Container as Tree1.

Source Code :
Source code for Se38:

*&---------------------------------------------------------------------* *& Report ZSR_ALV_TREE *& *&---------------------------------------------------------------------* *& *& *&---------------------------------------------------------------------* REPORT ZSR_ALV_TREE.

* Demo program for ALV Tree..... CLASS CL_GUI_COLUMN_TREE DEFINITION LOAD. CLASS CL_GUI_CFW DEFINITION LOAD. DATA TREE1 TYPE REF TO CL_GUI_ALV_TREE_SIMPLE. " Output-Table " Field Catalog " Sorting Table " OK-Code

DATA: GT_SFLIGHT TYPE SFLIGHT OCCURS 0, GT_FIELDCATALOG TYPE LVC_T_FCAT, GT_SORT TYPE LVC_T_SORT, OK_CODE LIKE SY-UCOMM. CALL SCREEN 100.

*&---------------------------------------------------------------------* *& Form BUILD_FIELDCATALOG *&---------------------------------------------------------------------* * This subroutine is used to build the field catalog for the ALV list *----------------------------------------------------------------------* FORM BUILD_FIELDCATALOG. * get fieldcatalog CALL FUNCTION 'LVC_FIELDCATALOG_MERGE' EXPORTING I_STRUCTURE_NAME = 'SFLIGHT' CHANGING CT_FIELDCAT = GT_FIELDCATALOG. * change fieldcatalog DATA: LS_FIELDCATALOG TYPE LVC_S_FCAT. LOOP AT GT_FIELDCATALOG INTO LS_FIELDCATALOG. CASE LS_FIELDCATALOG-FIELDNAME. WHEN 'CARRID' OR 'CONNID' OR 'FLDATE'. LS_FIELDCATALOG-NO_OUT = 'X'. LS_FIELDCATALOG-KEY = ''. WHEN 'PRICE' OR 'SEATSOCC' OR 'SEATSMAX' OR 'PAYMENTSUM'. LS_FIELDCATALOG-DO_SUM = 'X'. ENDCASE. MODIFY GT_FIELDCATALOG FROM LS_FIELDCATALOG. ENDLOOP.

ENDFORM. " BUILD_FIELDCATALOG *&---------------------------------------------------------------------* *& Form BUILD_OUTTAB *&---------------------------------------------------------------------* * Retrieving the data from the table and filling it in the output table * of the ALV list *----------------------------------------------------------------------* FORM BUILD_OUTTAB. SELECT * FROM SFLIGHT INTO TABLE GT_SFLIGHT. ENDFORM. " BUILD_OUTTAB

*&---------------------------------------------------------------------* *& Form BUILD_SORT_TABLE *&---------------------------------------------------------------------* * This subroutine is used to build the sort table or the sort criteria *----------------------------------------------------------------------* FORM BUILD_SORT_TABLE. DATA LS_SORT_WA TYPE LVC_S_SORT. * create sort-table LS_SORT_WA-SPOS = 1. LS_SORT_WA-FIELDNAME = 'CARRID'. LS_SORT_WA-UP = 'X'. APPEND LS_SORT_WA TO GT_SORT. LS_SORT_WA-SPOS = 2. LS_SORT_WA-FIELDNAME = 'CONNID'. LS_SORT_WA-UP = 'X'. APPEND LS_SORT_WA TO GT_SORT. LS_SORT_WA-SPOS = 3. LS_SORT_WA-FIELDNAME = 'FLDATE'. LS_SORT_WA-UP = 'X'. APPEND LS_SORT_WA TO GT_SORT. ENDFORM. " BUILD_SORT_TABLE *&---------------------------------------------------------------------* *& Module STATUS_0100 OUTPUT *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* MODULE STATUS_0100 OUTPUT. SET PF-STATUS 'ZSTATUS'. SET TITLEBAR 'TITLE'.

IF TREE1 IS INITIAL. PERFORM INIT_TREE. ENDIF. ENDMODULE. " STATUS_0100 OUTPUT *&---------------------------------------------------------------------* *& Module USER_COMMAND_0100 INPUT *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* MODULE USER_COMMAND_0100 INPUT. OK_CODE = SY-UCOMM. CASE OK_CODE. WHEN 'EXIT' OR 'BACK' OR 'CANCEL'. CALL METHOD TREE1->FREE. LEAVE PROGRAM. CLEAR OK_CODE. ENDCASE. ENDMODULE. " USER_COMMAND_0100 INPUT *&---------------------------------------------------------------------* *& Form build_header *&---------------------------------------------------------------------* * build table for header *----------------------------------------------------------------------* FORM BUILD_COMMENT USING PT_LIST_COMMENTARY TYPE SLIS_T_LISTHEADER P_LOGO TYPE SDYDO_VALUE. DATA: LS_LINE TYPE SLIS_LISTHEADER. * LIST HEADING LINE: TYPE H CLEAR LS_LINE. LS_LINE-TYP = 'H'. * LS_LINE-KEY: NOT USED FOR THIS TYPE LS_LINE-INFO = 'ALV TREE DEMO'. APPEND LS_LINE TO PT_LIST_COMMENTARY. P_LOGO = 'ENJOYSAP_LOGO'. ENDFORM. "build_comment

*&---------------------------------------------------------------------* *& Form init_tree *&---------------------------------------------------------------------* * Building the ALV-Tree for the first time display *----------------------------------------------------------------------*

FORM INIT_TREE. PERFORM BUILD_FIELDCATALOG. PERFORM BUILD_OUTTAB. PERFORM BUILD_SORT_TABLE. * create container for alv-tree DATA: L_TREE_CONTAINER_NAME(30) TYPE C, L_CUSTOM_CONTAINER TYPE REF TO CL_GUI_CUSTOM_CONTAINER. L_TREE_CONTAINER_NAME = 'TREE1'. CREATE OBJECT L_CUSTOM_CONTAINER EXPORTING CONTAINER_NAME = EXCEPTIONS CNTL_ERROR = CNTL_SYSTEM_ERROR = CREATE_ERROR = LIFETIME_ERROR = LIFETIME_DYNPRO_DYNPRO_LINK =

L_TREE_CONTAINER_NAME 1 2 3 4 5.

* create tree control CREATE OBJECT TREE1 EXPORTING I_PARENT = L_CUSTOM_CONTAINER I_NODE_SELECTION_MODE = CL_GUI_COLUMN_TREE=>NODE_SEL_MODE_MULTIPLE I_ITEM_SELECTION = 'X' I_NO_HTML_HEADER = '' I_NO_TOOLBAR = '' EXCEPTIONS CNTL_ERROR = 1 CNTL_SYSTEM_ERROR = 2 CREATE_ERROR = 3 LIFETIME_ERROR = 4 ILLEGAL_NODE_SELECTION_MODE = 5 FAILED = 6 ILLEGAL_COLUMN_NAME = 7. * create info-table for html-header DATA: LT_LIST_COMMENTARY TYPE SLIS_T_LISTHEADER, L_LOGO TYPE SDYDO_VALUE. PERFORM BUILD_COMMENT USING LT_LIST_COMMENTARY L_LOGO. * repid for saving variants DATA: LS_VARIANT TYPE DISVARIANT. LS_VARIANT-REPORT = SY-REPID.

* create hierarchy CALL METHOD TREE1->SET_TABLE_FOR_FIRST_DISPLAY EXPORTING IT_LIST_COMMENTARY = LT_LIST_COMMENTARY I_LOGO = L_LOGO I_BACKGROUND_ID = 'ALV_BACKGROUND' I_SAVE = 'A' IS_VARIANT = LS_VARIANT CHANGING IT_SORT = GT_SORT IT_OUTTAB = GT_SFLIGHT IT_FIELDCATALOG = GT_FIELDCATALOG. * optimize column-width CALL METHOD TREE1->COLUMN_OPTIMIZE EXPORTING I_START_COLUMN = TREE1->C_HIERARCHY_COLUMN_NAME I_END_COLUMN = TREE1->C_HIERARCHY_COLUMN_NAME. * I_INCLUDE_HEADING = 'X'.

ENDFORM. Source code for Se51: PROCESS MODULE * PROCESS MODULE BEFORE OUTPUT. STATUS_0100. AFTER INPUT. USER_COMMAND_0100.

" init_tree

Output:
Initially its shows output as below, you can expand it.

You might also like