
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.
Give status name and description.
Here we have to select icon.
Here we have to give toolbar button name select icons.
In output screen we have to see the output.
When I double click on a particular field value it will display value.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
3 | |
2 | |
2 | |
1 | |
1 | |
1 | |
1 | |
1 | |
1 | |
1 |