OOPS ALV in SAP ABAP

Introduction

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.

Example

Follow the steps to create an OOPS ALV in SAP ABAP:

  1. Create an object of class CL_GUI_CUSTOM_CONTAINER and class CL_GUI_ALV_GRID.
  2. Populate internal table.
  3. Call screen in which you want to display the list.
  4. Create Custom Container from layout lab
  5. Call method of class CL_GUI_ALV_GRID and pass the required parameters.

Program

“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

CONATINER_NAME = ‘CONATINER’ .

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.

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.