Application Development 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: 
Naveen_n
Explorer
13,281

The SAP List Viewer (SALV) is a powerful tool in SAP ABAP that simplifies the creation and display of interactive lists. While SALV provides a range of standard functionalities, there are scenarios where you might need to enhance the user experience by adding custom buttons and handling events associated with them. In this blog, we'll explore the step-by-step process of creating a custom button and handling events in SALV. 

  In this process i have used some standard classes mentioned below: - 

CL_SALV_TABLE 

CL_SALV_EVENTS_TABLE 

 

Procedure: - To achieve this First we have to Create one report program then we have to create one local class in that local class create Handle click and added function method and implement that method.  

 

REPORT zna_rp_scn_salv.

DATA : lo_table  TYPE REF TO cl_salv_table,
        lo_events TYPE REF TO cl_salv_events_table,
        lt_emp TYPE TABLE OF zna_t_emp,
        ls_emp TYPE zna_t_emp,
        lo_cx  TYPE REF TO cx_salv_msg.

CREATE OBJECT lo_cx.

CLASS lcl_salv_handler DEFINITION.
   PUBLIC SECTION.

    CLASS-METHODS : handle_click FOR EVENT double_click OF cl_salv_events_table
       IMPORTING row column.

    CLASS-METHODS : added_function FOR EVENT added_function OF cl_salv_events_table
       IMPORTING e_salv_function.
 ENDCLASS.

CLASS lcl_salv_handler IMPLEMENTATION.
   METHOD: handle_click .
     MESSAGE sy-ucomm TYPE zif_na_salv_constants=>message."'I'.
     READ TABLE lt_emp INDEX row INTO ls_emp.
     DATA msg TYPE string.

    IF column EQ zif_na_salv_constants=>id."'EMP_ID'.
       MESSAGE i000(zna_scn_msg)  WITH ls_emp-emp_id . "'You choose employee id:'
 message msg TYPE 'I'.
     ENDIF.
   ENDMETHOD.

  METHOD added_function .

    MESSAGE e_salv_function  TYPE zif_na_salv_constants=>message.  "'I'.
   ENDMETHOD.


ENDCLASS.

START-OF-SELECTION.

  SELECT * FROM zna_t_emp
     INTO CORRESPONDING FIELDS OF TABLE lt_emp.

  TRY .
       cl_salv_table=>factory(

        IMPORTING
           r_salv_table   =  lo_table                         " Basis Class Simple ALV Tables
         CHANGING
           t_table        = lt_emp
       ).
     CATCH cx_salv_msg INTO lo_cx. " ALV: General Error Class with Message
       WRITE : zif_na_salv_constants=>wstatment.  "'Error Occured'.
   ENDTRY.

  lo_table->set_screen_status(
     EXPORTING
       report        =   sy-repid               " ABAP Program: Current Master Program
       pfstatus      = 'ZPFSTATUS'               " Screens, Current GUI Status
       set_functions = cl_salv_table=>c_functions_all " ALV: Data Element for Constants
   ).


  CASE sy-ucomm.
     WHEN  zif_na_salv_constants=>back.  "'BACK'.
       LEAVE PROGRAM.
   ENDCASE.


  lo_events = lo_table->get_event( ).
   SET HANDLER lcl_salv_handler=>handle_click  FOR lo_events.
   SET HANDLER lcl_salv_handler=>added_function FOR lo_events.
   lo_table->display( ).

 

In T-code: -SE80 we have to create the toolbar buttons. 

Naveen_n_0-1709288518259.png

Give status name and description. 

Naveen_n_1-1709288518264.png

Here we have to select icon. 

Naveen_n_2-1709288518273.png

Naveen_n_3-1709288518276.png

Here we have to give toolbar button name select icons. 

Naveen_n_4-1709288518278.png

In output screen we have to see the output. 

 

Naveen_n_5-1709288518281.png

Naveen_n_6-1709288518284.png

When I double click on a particular field value it will display value. 

Naveen_n_7-1709288518286.png

Conclusion: 

By following these steps, you can enhance the functionality of SALV by adding a custom button and handling the associated events. This allows you to tailor the SAP List Viewer to meet specific business requirements and improve the user experience in your SAP applications. Always follow SAP development best practices and thoroughly test your SALV enhancements in a development environment before deploying to production. 

1 Comment
Labels in this area