You are on page 1of 7

OOPS ALV Concept in SAP ABAP

ALV
ABAP List Viewer is used to enhance the readability and functionality of any report
output. We can develop ALV using different ways like using type pool SLIS or using
the class Cl_GUI_ALV_GRID. In case of Object-Oriented concept, the Control
Framework is required as it provides global classes for various functionalities.

CL_GUI_ALV_GRID
It is the wrapper class implemented to encapsulate ALV Grid functionality for list
display. ALV Grid control is a flexible tool which provides following capabilities:
For building and displaying interactive, non-hierarchical and modern-design

lists.

Provides typical list functions such as sorting, filtering, summing etc.

Provides common list operations and can be enhanced by user-defined
options.
Basic Components required for ALV Grid Control are:

1.

List Data : Data to be listed is populated in an internal table. This table can be
of any flat type

2.

Field Catalog: This is an internal table which contains the list of fields as per
specification. It comprises of some additional information about display options for
each column to be displayed. It must be referenced to the dictionary type
“LVC_T_FCAT” while the work-area should be of type “LVC_S_FCAT”. Function
“LVC_FIELDCATALOG_MERGE” can also be used to get field catalog by passing
structure name.

3.

Container: Container is a storage area where the list will be displayed. It
should be of type “CL_GUI_CUSTOM_CONTAINER”. Other Container Classes are:

CL_GUI_DOCKING_CONTAINER- For displaying multiple ALV’s by using
methods such as dock_at_left, dock_at_right, dock_at_top, dock_at_bottom. Internal
tables can be displayed in these containers.

CL_GUI_EASY_SPLITTER_CONTAINER- For displaying two ALV Grids on
single screen, container is splitted into two containers by using this class.

1

we must register an instance of this event handler class to handle ALV Grid events. Layout Structure: It is a structure to specify general layout options for the grid. buttons to be deactivated.This is used in case of Interactive  ALV. it should be checked whether the operation is successful.Drag Icons from Tree to rows of Grid BCALV_DND_03. 4. 5. Event Handler: For handling events. color adjustments etc. we need to define and implement an event handler class triggered by the ALV Grid instance. Here. GUI Status and title etc. initial sorting criteria (class used is LVC_S_SORT).Drag ALV row to Tree Folder BCALV_DND_02.  Print_End_Of_Page: Used for Footers. The layout structure must be of type “LVC_S_LAYO”. grid customizing. General Declarations and Steps to Create Object-oriented ALV:  Add custom control on screen related to container. For example: update the used internal table if a row has been moved. totals options.ALV Grid: Drag and Drop with ALV Tree (Simple) 6.NOTE: For Drag and Drop functionality refer to these standard examples-BCALV_DND_01. Handler is ‘SET HANDLER’. 2 .Drag & Drop on cells of grid BCALV_DND_04. Various Events are as follows-  Print_Top_Of_Page: Used for Headers. OnDropComplete: This event is used to change the state after a  successful drag and drop operation. where details list will be displayed in dialog box. Additional Data: To trigger some additional features of ALV Grid we can have some additional data to pass as parameters.  OnDrag : This event is used to ‘fetch’ information from the drag source. For example: DATA: gc_custom_control_name TYPE scrfname VALUE ‘CC_ALV’. With this structure we can set general display options.CL_GUI_DIALOGBOX_CONTAINER. For this functionality refer to example BCALV_GRID_02.  OnDrop : This event is used to use the dragged information in combination with drop source. After creating ALV Grid instance.ALV Grid: Drag and Drop with ALV Tree BCALV_GRID_DND_TREE_SIMPLE.Drag & Drop within ALV Grid Control BCALV_GRID_DND_TREE. Handler is ‘SET HANDLER’. For example.

Data: t_sflight type standard table of Sflight. For example: Ob_custom type reference to cl_gui_custom_container. Create object ob_custom Exporting container_name = ‘CONTAINER’. Create object ob_grid Exporting i_parent = ob_custom.  Example for Docking Container using Object-Oriented ALV Step1: Create Two Docking Containers for Two Grids using Following Code. For example: This Internal table is filled with data from Sflight.  Populate the internal table that you want to display on the GRID.  Create object of class CL_GUI_ALV_GRID for putting Grid in above container.   Call the screen that contains Custom Container which is done at PBO of screen. g_dock1 TYPE REF TO cl_gui_docking_container. For example: CALL METHOD ob_grid->set_table_for_first_display exporting i_structure_name = ‘SFLIGHT’ is_layout = gs_layout changing it_outtab = T_SFLIGHT [] it_fieldcatalog = gt_fieldcat exceptions invalid_parameter_combination = 1 program_error = 2 too_many_lines = 3 others = 4. IF g_dock1 IS INITIAL. g_dock2 TYPE REF TO cl_gui_docking_container. DATA: r_grid1 TYPE REF TO cl_gui_alv_grid. Create object of class CL_GUI_CUSTOM_CONTAINER for container. r_grid2 TYPE REF TO cl_gui_alv_grid. Method SET_TABLE_FOR_FIRST_DISPLAY of class CL_GUI_ALV_GRID is used to display the output. CREATE OBJECT g_dock1 EXPORTING 3 . For example: Ob_grid type reference to cl_gui_grid_display.

ENDIF. Step3: Set internal table it_tab to grid r_grid1. CALL METHOD r_grid2->set_table_for_first_display EXPORTING is_layout = gs_layout CHANGING it_outtab = it_count it_fieldcatalog = gt_fieldcat1. ENDIF. Also fill the field catalog with corresponding structures of internal tables. IF NOT it_count[] IS INITIAL. ENDIF. CALL METHOD r_grid1->set_table_for_first_display EXPORTING is_layout = gs_layout CHANGING it_outtab = it_tab it_fieldcatalog = gt_fieldcat. 4 . CREATE OBJECT g_dock2 EXPORTING repid = sy-repid dynnr = sy-dynnr side = g_dock2->dock_at_bottom extension = 100. CREATE OBJECT r_grid1 EXPORTING i_parent = g_dock1. For example: it_tab. CREATE OBJECT r_grid2 EXPORTING i_parent = g_dock2. Step4: Set internal table it_count to grid r_grid2. IF it_tab[] IS INITIAL. Step2: Take two internal tables and populate them with desired data. IF g_dock2 IS INITIAL.repid = sy-repid dynnr = sy-dynnr side = g_dock1->dock_at_left extension = 300. it_count.

ENDIF. Screen-shots for Output of ALV for displaying two internal tables in two different Docking Containers along with Selection-screen: we can display more than one internal table on the same screen as selectionscreen unlike ALV using Type-pool SLIS Also we can filter records by putting in the selection screen and executing the report as follows: 5 .

g.Click on Execute Further filtration is possible by entering Plant e. 1000 in above screen 6 .

7 .