Double Click Event in OOPS ALV - aidamate13/AMS-Knowledge-Base GitHub Wiki
[!NOTE] DOUBLE_CLICK is an event in the ALV grid control and this is triggered when the user double clicks a selected cell.
To understand it more clearly, we will take requirement and implement it Requirement :- User will pass range of Sales Document number into the selection screen. We will display details of Sales Document number from VBAK table in one column and as soon as User will double click on one row, we will get details from VBAP table as well in another container. Solution
Step 1 :- Create a executable program from ABAP Editor (SE38).
Step 2 :- Firstly we need to create a type structure from VBAK table and another type structure from VBAP table.
Step 3 :- We need to create internal table and work area and also we will have to create objects of CL_GUI_ALV_GRID and CL_GUI_CUSTOM_CONTAINER.
Step 4 :- We will have to create a class in which we will handle the double click event.
Step 5 :- Now we will create a select option for user input of Sales Document number.
Step 6 :- In Start of selection we will write the logic to fetch data and we will create the field catalog for first container for VBAK table..
Step 7 :- Now we will create object for CL_GUI_CUSTOM_COTAINER and CL_GUI_ALV_GRID and call set table for first display to display in ALV.
Step 8 :- We will handle the event for lo_grid1 object.
Step 9 :- Call screen ‘0100’.
Step 10 :- We will create two containers on screen 100.
Step 11 :- Now we will go to implementation part of method display where we will call method get_selected_rows to get selected rows.
Step 12 :- Here we will read the selected row and will fetch data based on selected row from VBAK table.
Step 13 :- We will find the field catalog for VBAP table and call method set table for first display.
*&---------------------------------------------------------------------*
*& Report ZAR_DOCUBLE_CLICK_EVENT
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT zar_docuble_click_event.
TYPES : BEGIN OF ty_vbak,
vbeln TYPE vbeln_va,
erdat TYPE erdat,
erzet TYPE erzet,
ernam TYPE ernam,
vbtyp TYPE vbtypl,
END OF ty_vbak.
TYPES : BEGIN OF ty_vbap,
vbeln TYPE vbeln_va,
posnr TYPE posnr_va,
matnr TYPE matnr,
END OF ty_vbap.
DATA : lt_vbak TYPE TABLE OF ty_vbak,
ls_vbak TYPE ty_vbak,
lt_vbap TYPE TABLE OF ty_vbap,
ls_vbap TYPE ty_vbap,
lt_fieldcat1 TYPE TABLE OF lvc_s_fcat,
ls_fieldcat1 TYPE lvc_s_fcat,
lt_fieldcat2 TYPE TABLE OF lvc_s_fcat,
ls_fieldcat2 TYPE lvc_s_fcat,
lo_cont1 TYPE REF TO cl_gui_custom_container,
lo_cont2 TYPE REF TO cl_gui_custom_container,
lo_grid1 TYPE REF TO cl_gui_alv_grid,
lo_grid2 TYPE REF TO cl_gui_alv_grid.
CLASS local DEFINITION.
PUBLIC SECTION.
METHODS display FOR EVENT double_click OF cl_gui_alv_grid.
ENDCLASS.
CLASS local IMPLEMENTATION.
METHOD display.
DATA : lt_rows type table of LVC_S_ROW,
ls_rows type LVC_S_ROW.
CALL METHOD lo_grid1->get_selected_rows
IMPORTING
et_index_rows = lt_rows
* et_row_no =
.
read table lt_rows into ls_rows index 1.
if sy-subrc eq 0.
read table lt_vbak into ls_vbak with key vbeln = ls_rows-index.
if sy-subrc eq 0.
select vbeln posnr matnr
from vbap
into table lt_vbap
where vbeln = ls_vbak-vbeln.
clear lt_fieldcat2.
ls_fieldcat2-scrtext_l = 'Sales Document Number'.
ls_fieldcat2-fieldname = 'VBELN'.
append ls_fieldcat2 to lt_fieldcat2.
clear ls_fieldcat2.
ls_fieldcat2-scrtext_l = 'Item Number'.
ls_fieldcat2-fieldname = 'POSNR'.
append ls_fieldcat2 to lt_fieldcat2.
clear ls_fieldcat2.
ls_fieldcat2-scrtext_l = 'Material Number'.
ls_fieldcat2-fieldname = 'MATNR'.
append ls_fieldcat2 to lt_fieldcat2.
clear ls_fieldcat2.
CALL METHOD lo_grid2->set_table_for_first_display
CHANGING
it_outtab = lt_vbap
it_fieldcatalog = lt_fieldcat2
EXCEPTIONS
invalid_parameter_combination = 1
program_error = 2
too_many_lines = 3
others = 4
.
endif.
endif.
ENDMETHOD.
ENDCLASS.
DATA : lv_vbeln TYPE vbeln_va.
SELECT-OPTIONS : s_vbeln FOR lv_vbeln.
START-OF-SELECTION.
select vbeln erdat erzet ernam vbtyp
from vbak into table lt_vbak
where vbeln in s_vbeln.
if lt_vbak is NOT INITIAL.
clear lt_fieldcat1.
ls_fieldcat1-scrtext_l = 'Sales Document Number'.
ls_fieldcat1-fieldname = 'VBELN'.
append ls_fieldcat1 to lt_fieldcat1.
clear ls_fieldcat1.
ls_fieldcat1-scrtext_l = 'Creation Date'.
ls_fieldcat1-fieldname = 'ERDAT'.
append ls_fieldcat1 to lt_fieldcat1.
clear ls_fieldcat1.
ls_fieldcat1-scrtext_l = 'Time'.
ls_fieldcat1-fieldname = 'ERZET'.
append ls_fieldcat1 to lt_fieldcat1.
clear ls_fieldcat1.
ls_fieldcat1-scrtext_l = 'Created By'.
ls_fieldcat1-fieldname = 'ERNAM'.
append ls_fieldcat1 to lt_fieldcat1.
clear ls_fieldcat1.
ls_fieldcat1-scrtext_l = 'Document Category'.
ls_fieldcat1-fieldname = 'VBTYP'.
append ls_fieldcat1 to lt_fieldcat1.
clear ls_fieldcat1.
create object lo_cont1
EXPORTING
CONTAINER_NAME = 'CONT1'.
create object lo_grid1
EXPORTING
I_PARENT = lo_cont1.
CALL METHOD lo_grid1->set_table_for_first_display
CHANGING
it_outtab = lt_vbak
it_fieldcatalog = lt_fieldcat1
EXCEPTIONS
invalid_parameter_combination = 1
program_error = 2
too_many_lines = 3
others = 4
.
create OBJECT lo_cont2
EXPORTING
CONTAINER_NAME = 'CONT2'.
create object lo_grid2
EXPORTING
I_PARENT = lo_cont2.
DATA(lo_obj) = new local( ).
set HANDLER lo_obj->display for lo_grid1.
CALL SCREEN '0100'.
endif.
*&------------------------------------------------------------------
*&End of Program
*&---------------------------------------------------------------------
Execution Example
Press F8 to execute.
Now double click on any row.