Double Click Event Using CL_SALV_TABLE_CLASS in OOPS ALV
The class CL_SALV_TABLE
in ABAP (Advanced Business Application Programming) is used to create ALV (ABAP List Viewer) reports. One of the features of ALV reports is the ability to handle user actions like double clicking on a row of the report. This is achieved using the CL_SALV_TABLE
class.
To implement the double click functionality, you need to first create an instance of the CL_SALV_TABLE
class and then get the event object for the table using the GET_EVENT( )
method. Once you have the event object, you can register a handler method for the double click event.
let’s take a requirement.
Requirement :-
- User wants to give a range of Sales Document Number as a input on the selection screen.
- We will display ALV for the Header details of Sales Document Number from VBAK table.
- When user will double click on any row, then it will display the Item details from VBAP table.
Solution :-
-
Step 1 :- Create a executable program in ABAP Editor ( Se38 ).
-
Step 2 :- Create a type structure from VBAK and VBAP table and then create a corresponding internal table for the same.
-
Step 3 :- Define a select option for user input.
-
Step 4 :- In start of selection, write a select query from VBAK table.
-
Step 5 :- Now we need to get object of CL_SALV_TABLE by using its factory method.
-
Step 6 :- Then we will use display method to display first ALV.
-
Step 7 :- Now, we need to call the GET_EVENT method of CL_SALV_TABLE class to get the event object.
- In the above method we will get the object of CL_SALV_EVENTS_TABLE class.
-
Step 8 :- We will call the event handle method of above received class.
-
To achieve this requirement we will have to create a local class in which we will create a event handler method for the above class.
-
-
Step 9 :- We will create the object for our local class to handle the event.
-
Step 10 :- Now whenever we will double click on any row we will get into the methods of our local class, so we need to get the selected rows.
here, DOUBLE_CLICK event will return us the row on which we have double clicked..
So, we will write the rest logic into our method to display the output. :
Code :-
*&---------------------------------------------------------------------*
*& Report ZAR_SALES_ORDER_DOUBLE_CLICK
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT zar_sales_order_double_click.
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,
lt_vbap TYPE TABLE OF ty_vbap.
DATA : lv_vbeln TYPE vbeln_va.
SELECT-OPTIONS : s_vbeln FOR lv_vbeln.
data : row type SALV_DE_ROW,
columne type SALV_DE_COLUMN.
CLASS LOCAL DEFINITION.
public SECTION.
methods handle for event DOUBLE_CLICK of CL_SALV_EVENTS_TABLE importing row column.
endclass.
class local IMPLEMENTATION.
method handle.
Read table lt_vbak into data(ls_vbak) index row.
if sy-subrc eq 0.
select vbeln posnr matnr
from vbap
into table lt_vbap
where vbeln = ls_vbak-vbeln.
if lt_vbap is not INITIAL.
TRY.
CALL METHOD cl_salv_table=>factory
EXPORTING
list_display = IF_SALV_C_BOOL_SAP=>FALSE
IMPORTING
r_salv_table = data(lo_obj2)
CHANGING
t_table = lt_vbap
.
CATCH cx_salv_msg.
ENDTRY.
lo_obj2->display( ).
endif.
endif.
endmethod.
endclass.
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.
TRY.
CALL METHOD cl_salv_table=>factory
EXPORTING
list_display = IF_SALV_C_BOOL_SAP=>FALSE
* r_container =
* container_name =
IMPORTING
r_salv_table = data(lo_object)
CHANGING
t_table = lt_vbak
.
CATCH cx_salv_msg.
ENDTRY.
CALL METHOD lo_object->get_event
RECEIVING
value = data(lo_event)
.
DATA(lo_local) = new local( ).
set handler lo_local->handle for lo_event.
lo_object->display( ).
endif.
*&-------------------------------------------------------------------------------
*&End of Program
*&-----------------------------------------------------------------------------------------
Execute the Code :-
- Press F8.
- Suppose I double clicked on first row.
Comments
Post a Comment