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:
- List Data : Data to be listed is populated in an internal table. This table can be of any flat type
- 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.
- 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.
- CL_GUI_DIALOGBOX_CONTAINER- This is used in case of Interactive ALV, where details list will be displayed in dialog box. For this functionality refer to example BCALV_GRID_02.
- Layout Structure: It is a structure to specify general layout options for the grid. With this structure we can set general display options, grid customizing, totals options, color adjustments etc. The layout structure must be of type “LVC_S_LAYO”.
- Event Handler: For handling events, we need to define and implement an event handler class triggered by the ALV Grid instance. After creating ALV Grid instance, we must register an instance of this event handler class to handle ALV Grid events.
Various Events are as follows-
- Print_Top_Of_Page: Used for Headers. Handler is ‘SET HANDLER’.
- Print_End_Of_Page: Used for Footers. Handler is ‘SET HANDLER’.
- OnDrag : This event is used to ‘fetch’ information from the drag source.
- OnDrop : This event is used to use the dragged information in combination with drop source. Here, it should be checked whether the operation is successful.
- OnDropComplete: This event is used to change the state after a successful drag and drop operation. For example: update the used internal table if a row has been moved.NOTE: For Drag and Drop functionality refer to these standard examples-BCALV_DND_01- Drag ALV row to Tree Folder
BCALV_DND_02- Drag Icons from Tree to rows of Grid
BCALV_DND_03- Drag & Drop on cells of grid
BCALV_DND_04- Drag & Drop within ALV Grid Control
BCALV_GRID_DND_TREE- ALV Grid: Drag and Drop with ALV Tree
BCALV_GRID_DND_TREE_SIMPLE- ALV Grid: Drag and Drop with ALV Tree (Simple)- Additional Data: To trigger some additional features of ALV Grid we can have some additional data to pass as parameters. For example, initial sorting criteria (class used is LVC_S_SORT), buttons to be deactivated, GUI Status and title etc.
General Declarations and Steps to Create Object-oriented ALV:
- Add custom control on screen related to container.
For example:
DATA: gc_custom_control_name TYPE scrfname VALUE ‘CC_ALV’.- Create object of class CL_GUI_CUSTOM_CONTAINER for container.
For example:
Ob_custom type reference to cl_gui_custom_container.
Create object ob_custom
Exporting
container_name = ‘CONTAINER’.- Create object of class CL_GUI_ALV_GRID for putting Grid in above container.
For example:
Ob_grid type reference to cl_gui_grid_display.
Create object ob_grid
Exporting
i_parent = ob_custom.- Populate the internal table that you want to display on the GRID.
For example:
This Internal table is filled with data from Sflight.
Data: t_sflight type standard table of Sflight.- Call the screen that contains Custom Container which is done at PBO of screen.
- Method SET_TABLE_FOR_FIRST_DISPLAY of class CL_GUI_ALV_GRID is used to display the output.
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.Example for Docking Container using Object-Oriented ALV
Step1:
Create Two Docking Containers for Two Grids using Following Code.
DATA: r_grid1 TYPE REF TO cl_gui_alv_grid,
r_grid2 TYPE REF TO cl_gui_alv_grid,
g_dock1 TYPE REF TO cl_gui_docking_container,
g_dock2 TYPE REF TO cl_gui_docking_container,IF g_dock1 IS INITIAL.
CREATE OBJECT g_dock1
EXPORTING
repid = sy-repid
dynnr = sy-dynnr
side = g_dock1->dock_at_left
extension = 300.
CREATE OBJECT r_grid1
EXPORTING
i_parent = g_dock1.
ENDIF.IF g_dock2 IS INITIAL.
CREATE OBJECT g_dock2
EXPORTING
repid = sy-repid
dynnr = sy-dynnr
side = g_dock2->dock_at_bottom
extension = 100.
CREATE OBJECT r_grid2
EXPORTING
i_parent = g_dock2.
ENDIF.Step2:
Take two internal tables and populate them with desired data.
For example:
it_tab, it_count.Also fill the field catalog with corresponding structures of internal tables.
Step3:
Set internal table it_tab to grid r_grid1.
IF it_tab[] IS INITIAL.
CALL METHOD r_grid1->set_table_for_first_display
EXPORTING
is_layout = gs_layout
CHANGING
it_outtab = it_tab
it_fieldcatalog = gt_fieldcat.
ENDIF.Step4:
Set internal table it_count to grid r_grid2.
IF NOT it_count[] IS INITIAL.
CALL METHOD r_grid2->set_table_for_first_display
EXPORTING
is_layout = gs_layout
CHANGING
it_outtab = it_count
it_fieldcatalog = gt_fieldcat1.
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 selection-screen unlike ALV using Type-pool SLIS
Also we can filter records by putting in the selection screen and executing the report as follows:
Click on Execute
Further filtration is possible by entering Plant e.g. 1000 in above screen
Please send us your questions, comments or assistance, and our team would be glad to assist you.
By Sreedhar Babu (on behalf of SAP Consulting Team)
Apprisia
SAP :: Streamlined
We offer variety of services including SAP ECC ,SAP HR,SAP BW,SAP CRM, SAP SCM,SAP BPM, Business Objects, SAP ABAP Development, SAP BASIS and SAP NetWeaver consulting. We have expertise in providing implementation,development, SAP Migration and SAP support services to SAP customers across diverse industries at a global level.
Have a question on SAP? Write to our SAP Architect : AskTheArchitect@Apprisia.com
(We promise a no-obligation consulting reply)