Keywords
ABAP, ALV, Splitter, Custom Controller,Double click event of ALV
Introduction
There aremany situations in which one needs to display multiple ALV’s in a single Report.In such a situation there are two solutions i.e. we can go for eitherProcedural Programming or ABAP Objects Concept to cater to our need.
When wedecide to go for Procedural Programming concept, we have to make use of thefunction modules:
REUSE_ALV_BLOCK_LIST_INIT toinitialize the block before appending ALV’s,REUSE_ALV_FIELDCATALOG_MERGE to build a field catalogautomatically, REUSE_ALV_BLOCK_LIST_APPENDto append ALV’s; and finally REUSE_ALV_BLOCK_LIST_DISPLAYto display the ALV.
Aproblem with this approach is in order to create a field catalog automaticallywe will use the FM,REUSE_ALV_FIELDCATALOG_MERGE but it does not work if the internal table is created usingLIKE instead of TYPE and hence we might have to create a field catalog manually.
Alsothe ALV list is full-screen size and cannot be moved whereas when created usingABAB Objects it can be easily resized and moved.
The secondoption that we have is to go for ABAP Objects. In ABAP Objects again we havetwo options. We can either go for a single Container and split it using Splitters or we can go for multiple Containers.
1 Single Container
In this method we create a single container and then split it to rows and columns. We can then use these splitted portions as containers.
Steps:
1. Create aScreen and place a Custom Control in it.
1. Create the internal tableswhose data is required to be displayed.
2. Create an object each ofCL_GUI_CUSTOM_CONTAINER and CL_GUI_ALV_GRID.
3. Create splitter objects oftypeCL_GUI_SPLITTER_CONTAINER.
4. Write the Flow Logic for thescreen.
Code:
*&---------------------------------------------------------------------*
*& Report YIRIS_ALV_MULTIPLE_ALV
*&
*&---------------------------------------------------------------------*
REPORT yiris_alv_multiple_alv.
DATA: splitter TYPE REF TO cl_gui_splitter_container,
c_container TYPE REF TO cl_gui_custom_container,
container_1 TYPE REF TO cl_gui_container,
container_2 TYPE REF TO cl_gui_container,
g_container TYPE scrfname VALUE 'CONTAINER',
grid_1 TYPE REF TO cl_gui_alv_grid,
grid_2 TYPE REF TO cl_gui_alv_grid.
DATA: ok_code TYPE sy-ucomm.
DATA: it_vbak TYPE TABLE OF vbak,
it_vbap TYPE TABLE OF vbap,
gs_vbak TYPE vbak.
CLASS lcl_event_receiver DEFINITION DEFERRED."for ALV double click event
DATA: event_receiver TYPE REF TO lcl_event_receiver.
.
*fetch the Sales Order data into internal table
SELECT * INTO TABLE it_vbak FROM vbak up to 5 rows
where vbeln >= '0000000016'.
CALL SCREEN 900.
*----------------------------------------------------------------------*
* CLASS lcl_event_receiver DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS lcl_event_receiver DEFINITION.
PUBLIC SECTION.
METHODS catch_doubleclick
FOR EVENT double_click OF cl_gui_alv_grid
IMPORTING e_row e_column es_row_no.
ENDCLASS. "lcl_event_receiver DEFINITION
*----------------------------------------------------------------------*
* CLASS lcl_event_receiver IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS lcl_event_receiver IMPLEMENTATION.
METHOD catch_doubleclick.
DATA: lt_row TYPE lvc_t_row,
ls_row LIKE LINE OF lt_row,
lv_index TYPE i.
CLEAR: lt_row,ls_row,gs_vbak.
REFRESH: lt_row.
CALL METHOD grid_1->get_selected_rows
IMPORTING
et_index_rows = lt_row.
READ TABLE lt_row INTO ls_row INDEX 1.
READ TABLE it_vbak INTO gs_vbak INDEX ls_row-index.
CLEAR: it_vbap. REFRESH: it_vbap.
SELECT * INTO TABLE it_vbap FROM vbap WHERE vbeln = gs_vbak-vbeln.
CALL METHOD grid_2->set_table_for_first_display
EXPORTING
i_structure_name = 'VBAP'
CHANGING
it_outtab = it_vbap.
CALL METHOD grid_2->refresh_table_display.
ENDMETHOD. "catch_doubleclick
ENDCLASS. "lcl_event_receiver IMPLEMENTATION
*&---------------------------------------------------------------------*
*& Module pbo_0900 OUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE pbo_0900 OUTPUT.
IF c_container IS INITIAL.
*create object reference for the container
CREATE OBJECT c_container
EXPORTING container_name = 'CONTAINER'.
*split the container into two container
CREATE OBJECT splitter
EXPORTING parent = c_container
rows = 2
columns = 1.
*get the refernce for the splitted containers
CALL METHOD splitter->get_container
EXPORTING
row = 1
column = 1
RECEIVING
container = container_1.
CALL METHOD splitter->get_container
EXPORTING
row = 2
column = 1
RECEIVING
container = container_2.
*put the internal table data into the container
IF grid_1 IS NOT BOUND.
CREATE OBJECT grid_1
EXPORTING i_parent = container_1.
ENDIF.
*handle double click event of grid_1
CREATE OBJECT event_receiver.
SET HANDLER event_receiver->catch_doubleclick FOR grid_1.
CALL METHOD grid_1->set_table_for_first_display
EXPORTING
i_structure_name = 'VBAK'
CHANGING
it_outtab = it_vbak.
IF grid_2 IS NOT BOUND.
CREATE OBJECT grid_2
EXPORTING i_parent = container_2.
ENDIF.
CLEAR: gs_vbak, it_vbap. REFRESH: it_vbap.
READ TABLE it_vbak INTO gs_vbak INDEX 1.
SELECT * INTO TABLE it_vbap FROM vbap WHERE vbeln = gs_vbak-vbeln.
*Display Sales Order Items of the first Sales order in defact
CALL METHOD grid_2->set_table_for_first_display
EXPORTING
i_structure_name = 'VBAP'
CHANGING
it_outtab = it_vbap.
CALL METHOD grid_2->refresh_table_display.
ENDIF.
ENDMODULE. " pbo_0900 OUTPUT
*&---------------------------------------------------------------------*
*& Module STATUS_0900 OUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE status_0900 OUTPUT.
SET PF-STATUS 'STA_0900'.
ENDMODULE. " STATUS_0900 OUTPUT
*&---------------------------------------------------------------------*
*& Module USER_COMMAND_0900 INPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
module USER_COMMAND_0900 input.
CASE ok_code.
WHEN 'BACK'.
LEAVE TO SCREEN 0.
WHEN 'EXIT'.
LEAVE PROGRAM.
ENDCASE.
endmodule. " USER_COMMAND_0900 INPUT
Output:
The ALV report generated is given below.
Different Sales Order Itemswill be dispalyed when we double click the second record of the first ALV
2 Multiple Containers
In this method we create multiplecontainers and put the data into these containers. As we create multiplecontainers in the same screen they give us multiple ALV’s in the same screen.
Steps:
1. Create aScreen and place more than one Custom Controls in it.
1. Create the internal tableswhose data is required to be displayed.
2. Create an object each ofCL_GUI_CUSTOM_CONTAINER and CL_GUI_ALV_GRID.
3. Write the Flow Logic for theScreen.
Code:
*&---------------------------------------------------------------------*
*& Report YIRIS_ALV_MULTIPLE_ALV_2
*&
*&---------------------------------------------------------------------*
REPORT yiris_alv_multiple_alv_2.
DATA: c_container_1 TYPE REF TO cl_gui_custom_container,
c_container_2 TYPE REF TO cl_gui_custom_container,
g_container_1 TYPE scrfname VALUE 'CONTAINER1',
g_container_2 TYPE scrfname VALUE 'CONTAINER2',
grid_1 TYPE REF TO cl_gui_alv_grid,
grid_2 TYPE REF TO cl_gui_alv_grid.
DATA: ok_code TYPE sy-ucomm.
DATA: it_vbak TYPE TABLE OF vbak,
it_vbap TYPE TABLE OF vbap,
gs_vbak TYPE vbak.
CLASS lcl_event_receiver DEFINITION DEFERRED."for ALV double click event
DATA: event_receiver TYPE REF TO lcl_event_receiver.
*fetch the Sales Order data into internal table
SELECT * INTO TABLE it_vbak FROM vbak UP TO 5 ROWS
WHERE vbeln >= '0000000016'.
CALL SCREEN 0900.
*----------------------------------------------------------------------*
* CLASS lcl_event_receiver DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS lcl_event_receiver DEFINITION.
PUBLIC SECTION.
METHODS catch_doubleclick
FOR EVENT double_click OF cl_gui_alv_grid
IMPORTING e_row e_column es_row_no.
ENDCLASS. "lcl_event_receiver DEFINITION
*----------------------------------------------------------------------*
* CLASS lcl_event_receiver IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS lcl_event_receiver IMPLEMENTATION.
METHOD catch_doubleclick.
DATA: lt_row TYPE lvc_t_row,
ls_row LIKE LINE OF lt_row,
lv_index TYPE i.
CLEAR: lt_row,ls_row,gs_vbak.
REFRESH: lt_row.
CALL METHOD grid_1->get_selected_rows
IMPORTING
et_index_rows = lt_row.
READ TABLE lt_row INTO ls_row INDEX 1.
READ TABLE it_vbak INTO gs_vbak INDEX ls_row-index.
CLEAR: it_vbap. REFRESH: it_vbap.
SELECT * INTO TABLE it_vbap FROM vbap WHERE vbeln = gs_vbak-vbeln.
CALL METHOD grid_2->set_table_for_first_display
EXPORTING
i_structure_name = 'VBAP'
CHANGING
it_outtab = it_vbap.
CALL METHOD grid_2->refresh_table_display.
ENDMETHOD. "catch_doubleclick
ENDCLASS. "lcl_event_receiver IMPLEMENTATION
*&---------------------------------------------------------------------*
*& Module PBO_0900 OUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE pbo_0900 OUTPUT.
IF c_container_1 IS INITIAL.
CREATE OBJECT c_container_1
EXPORTING container_name = g_container_1.
ENDIF.
IF grid_1 IS NOT BOUND.
CREATE OBJECT grid_1
EXPORTING i_parent = c_container_1.
ENDIF.
*handle double click event of grid_1
CREATE OBJECT event_receiver.
SET HANDLER event_receiver->catch_doubleclick FOR grid_1.
CALL METHOD grid_1->set_table_for_first_display
EXPORTING
i_structure_name = 'VBAK'
CHANGING
it_outtab = it_vbak.
IF c_container_2 IS NOT BOUND.
CREATE OBJECT c_container_2
EXPORTING container_name = g_container_2.
ENDIF.
IF grid_2 IS INITIAL.
CREATE OBJECT grid_2
EXPORTING i_parent = c_container_2.
ENDIF.
CLEAR: gs_vbak, it_vbap. REFRESH: it_vbap.
READ TABLE it_vbak INTO gs_vbak INDEX 1.
SELECT * INTO TABLE it_vbap FROM vbap WHERE vbeln = gs_vbak-vbeln.
*Display Sales Order Items of the first Sales order in defact
CALL METHOD grid_2->set_table_for_first_display
EXPORTING
i_structure_name = 'VBAP'
CHANGING
it_outtab = it_vbap.
CALL METHOD grid_2->refresh_table_display.
ENDMODULE. " PBO_0900 OUTPUT
*&---------------------------------------------------------------------*
*& Module STATUS_0900 OUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE status_0900 OUTPUT.
SET PF-STATUS 'STAS_0900'.
*
ENDMODULE. " STATUS_0900 OUTPUT
*&---------------------------------------------------------------------*
*& Module USER_COMMAND_0900 INPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE user_command_0900 INPUT.
CASE ok_code.
WHEN 'EXIT'.
LEAVE PROGRAM.
WHEN 'BACK'.
LEAVE TO SCREEN 0.
ENDCASE.
ENDMODULE. " USER_COMMAND_0900 INPUT
Output:
The ALVreport generated is given below.
Different Sales Order Itemswill be dispalyed when we double click the second record of the first ALV