Preface – This post is part of the ABAP Programs and Object Oriented ABAP series.
Table of Contents
The OO ALV is ALV using object-oriented ABAP. ALV stands for ABAP List Viewer and provides the standard list format and user interface for all the ABAP programs. The advantage of using OOPS ALV in SAP ABAP is that is flexible and used to build interactive and modern-designing list. SAP has provided a class (class name: CL_GUI_ALV_GRID) which acts as the wrapper class encapsulating ALV GRID functionality.
The basic components for ALV Grid are:
- List data: List data are the internal table data’s to be listed.
- Field Catalog: The field catalog is the internal table that defines the specification on the display of fields. To generate field catalog there are three methods: Automatic generation, semi-automatic generation and manual generation. The internal table must be referred to LVC_T_FCAT.
- Layout Structure: The layout structure must be of type “LVC_S_LAYO”. This can be used to modify the layout including colour adjustments, grid customization etc.
- Event Handler: To handle events triggered by ALV, event handler class should be defined and implemented.
- Additional Data: To stimulate additional data in ALV Grid, additional data should be passed as a parameter.
Follow the steps to create an OOPS ALV in SAP ABAP:
- Create an object of class CL_GUI_CUSTOM_CONTAINER and class CL_GUI_ALV_GRID.
- Populate internal table.
- Call screen in which you want to display the list.
- Create Custom Container from layout lab
- Call method of class CL_GUI_ALV_GRID and pass the required parameters.
"SCARR is the SAP Standard table which stores Airlines data DATA: t_flight TYPE TABLE OF SCARR. DATA: cust_container TYPE REF TO CL_GUI_CUSTOM_CONTAINER, cust_grid TYPE REF TO CL_GUI_ALV_GRID. Select * from SCARR into table t_flight. CALL screen 100. MODULE STATUS_0100 OUTPUT. SET PF-STATUS 'SCREEN1'. SET TITLEBAR 'AIRLINES LIST'. ENDMODULE. MODULE USER_COMMAND_0100 INPUT. CASE SY-UCOMM. WHEN 'BACK'. LEAVE TO SCREEN 0. ENDCASE. ENDMODULE. MODULE LIST OUTPUT. CREATE OBJECT CUST_CONTAINER EXPORTING CONTAINER_NAME = 'CONTAINER'. CREATE OBJECT CUST_GRID EXPORTING I_PARENT = CUST_CONTAINER. CALL METHOD CUST_GRID->SET_TABLE_FOR_FIRST_DISPLAY EXPORTING i_structure_name = 'SCARR' Changing it_outtab = t_flight. ENDMODULE.
After you paste the above code, you need to double-click on “CALL screen 100.” so that you can create a Screen. If you try to execute without creating a screen, then you will get an exception mentioning the same, i.e., “No Screen 100 available.”
After double-clicking the screen, you will see the below view, update info as shown below:
Double click on “SET PF-STATUS ‘SCREEN1’. ” and enter these:
Add a button by double-clicking on Screen 100 and performing below:
Update and Activate the screen after changing the below:
Now change the Layout as shown below:
1. Click on Layouts
2. Create a custom container as shown below, choose the button and draw a rectangular shape:
3. It will create something, as shown below. Double-click on it and then enter the name as “CONTAINER”
5. Now Activate the screen, go back to the program, activate the program and run the program, you will see the OO ALV screen as shown below: