Application Development and Automation Blog Posts
Learn and share on deeper, cross technology development topics such as integration and connectivity, automation, cloud extensibility, developing at scale, and security.
cancel
Showing results for 
Search instead for 
Did you mean: 
sibatsya
Discoverer
10,994

Introduction:

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.

Sollution :-

  • Step 1 :- Create an executable program in ABAP Editor ( Se38 )sibatsya_0-1715253150503.png
    • Step 2 :- Create a type structure from VBAK and VBAP table and then create a corresponding internal table for the same.
    sibatsya_1-1715253427098.png

     

    • Step 3 :- Define a select option for user input.
    sibatsya_2-1715253427101.png

     

    • Step 4 :- In start of selection, write a select query from VBAK table.
    sibatsya_3-1715253427103.png

     

    • Step 5 :- Now we need to get object of CL_SALV_TABLE by using its factory method.
    sibatsya_4-1715253427107.png

     

    • Step 6 :- Then we will use display method to display first ALV.
    sibatsya_5-1715253427107.png

     

    • Step 7 :- Now, we need to call the GET_EVENT method of CL_SALV_TABLE class to get the event object.
    sibatsya_6-1715253427109.png

     

    • 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.
    sibatsya_7-1715253427112.png

     

    • Step 9 :- We will create the object for our local class to handle the event.
    sibatsya_8-1715253427118.png

     

    • 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. :

    sibatsya_9-1715253427121.png

     

 

REPORT zsi_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,
        column 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.

 

 

Execute the Code :-

sibatsya_10-1715253531044.png

 

  • Press F8.

sibatsya_11-1715253531049.png

 

  • Suppose I double clicked on the first row.

sibatsya_12-1715253531051.png

 

1 Comment
Labels in this area