In this blog post, we explore how to implement interactive ALV reports in ABAP using the CL_SALV_TABLE class and its FACTORY method. Specifically, we focus on handling double-click event to display related or detailed data dynamically.
Introduction
In many SAP reports, users often want to see more details about a record by simply double-clicking on it. For example, when looking at a list of vendors, a user may want to quickly view all the items or company-code details related to that vendor.
In this blog, I will show how to create an ALV report where a user can double-click a vendor in the main list and automatically open another ALV showing the related vendor-item details. This makes the report more interactive and user-friendly without needing extra screens or complex logic.
Code:
REPORT ZOOPS_DOUBLECLICK_FACTORY.
” Declare internal tables for vendor header and item data
TABLES: zva_vendor_item, zva_vendor_ta.
DATA: lt_vendor TYPE TABLE OF zva_vendor_ta,
lt_vendoritem TYPE TABLE OF zva_vendor_item.
” Selection screen: allows filtering vendors by vendor number
SELECT-OPTIONS: s_veno FOR zva_vendor_ta-venderno.
*———————————————————————*
* Event handler class for SALV double-click
*———————————————————————*
CLASS cl1 DEFINITION.
PUBLIC SECTION.
METHODS handle FOR EVENT double_click OF cl_salv_events_table
IMPORTING row column.
ENDCLASS.
CLASS cl1 IMPLEMENTATION.
METHOD handle.
” Read the vendor entry that was double-clicked
READ TABLE lt_vendor INTO DATA(ls_vendor) INDEX row.
IF sy-subrc EQ 0.
” Fetch related vendor items for selected vendor
SELECT * FROM zva_vendor_item
INTO TABLE lt_vendoritem
WHERE venderno = ls_vendor-venderno.
” Display item data only if available
IF lt_vendoritem IS NOT INITIAL.
TRY.
” Create new SALV table to show vendor items
CALL METHOD cl_salv_table=>factory
IMPORTING
r_salv_table = DATA(lo_salv1)
CHANGING
t_table = lt_vendoritem.
CATCH cx_salv_msg.
” Handle SALV creation error (optional logging)
ENDTRY.
” Display the item list
lo_salv1->display( ).
ENDIF.
ENDIF.
ENDMETHOD.
ENDCLASS.
*———————————————————————*
* Main program logic (initial ALV display)
*———————————————————————*
START-OF-SELECTION.
” Read vendor master data based on selection criteria
SELECT venderno, name, city, postalcode,
accountgroup, processorgroup, postingblock
FROM zva_vendor_ta
INTO CORRESPONDING FIELDS OF TABLE _vendor
WHERE venderno IN @s_veno.
IF lt_vendor IS NOT INITIAL.
TRY.
” Create SALV table for vendor master list
CALL METHOD cl_salv_table=>factory
IMPORTING
r_salv_table = DATA(lo_salv)
CHANGING
t_table = lt_vendor.
CATCH cx_salv_msg.
” Handle SALV creation error (optional)
ENDTRY.
” Register double-click event handler
CALL METHOD lo_salv->get_event
RECEIVING
value = DATA(lo_event).
” Instantiate event handler class
DATA(lo_cl) = NEW cl1( ).
” Link handler method to SALV event
SET HANDLER lo_cl->handle FOR lo_event.
” Display the vendor list ALV
lo_salv->display( ).
ENDIF.
Output :
I Double click on 1st row
Summary:
This example demonstrates how to enhance a standard ALV report by enabling interactive navigation through double-click events. Using the class CL_SALV_TABLE together with the event handler CL_SALV_EVENTS_TABLE, the program allows users to double-click a vendor row in the header ALV to immediately view the corresponding vendor-item details in a secondary ALV.
The solution showcases several key SAP GUI reporting capabilities:
Displaying master data using the SALV framework
Capturing user interaction through the double_click event
Dynamically reading and displaying detail records based on user selection
Using a clean, object-oriented approach to separate event handling from the main program logic
With minimal coding effort, this technique significantly improves usability by allowing users to drill down into related records without creating additional screens or complex logic. This interactive ALV pattern is highly reusable and suitable for many SAP GUI scenarios involving master–detail relationships.
In this blog post, we explore how to implement interactive ALV reports in ABAP using the CL_SALV_TABLE class and its FACTORY method. Specifically, we focus on handling double-click event to display related or detailed data dynamically.IntroductionIn many SAP reports, users often want to see more details about a record by simply double-clicking on it. For example, when looking at a list of vendors, a user may want to quickly view all the items or company-code details related to that vendor.In this blog, I will show how to create an ALV report where a user can double-click a vendor in the main list and automatically open another ALV showing the related vendor-item details. This makes the report more interactive and user-friendly without needing extra screens or complex logic.Code:REPORT ZOOPS_DOUBLECLICK_FACTORY.
” Declare internal tables for vendor header and item data
TABLES: zva_vendor_item, zva_vendor_ta.
DATA: lt_vendor TYPE TABLE OF zva_vendor_ta,
lt_vendoritem TYPE TABLE OF zva_vendor_item.
” Selection screen: allows filtering vendors by vendor number
SELECT-OPTIONS: s_veno FOR zva_vendor_ta-venderno.
*———————————————————————*
* Event handler class for SALV double-click
*———————————————————————*
CLASS cl1 DEFINITION.
PUBLIC SECTION.
METHODS handle FOR EVENT double_click OF cl_salv_events_table
IMPORTING row column.
ENDCLASS.
CLASS cl1 IMPLEMENTATION.
METHOD handle.
” Read the vendor entry that was double-clicked
READ TABLE lt_vendor INTO DATA(ls_vendor) INDEX row.
IF sy-subrc EQ 0.
” Fetch related vendor items for selected vendor
SELECT * FROM zva_vendor_item
INTO TABLE lt_vendoritem
WHERE venderno = ls_vendor-venderno.
” Display item data only if available
IF lt_vendoritem IS NOT INITIAL.
TRY.
” Create new SALV table to show vendor items
CALL METHOD cl_salv_table=>factory
IMPORTING
r_salv_table = DATA(lo_salv1)
CHANGING
t_table = lt_vendoritem.
CATCH cx_salv_msg.
” Handle SALV creation error (optional logging)
ENDTRY.
” Display the item list
lo_salv1->display( ).
ENDIF.
ENDIF.
ENDMETHOD.
ENDCLASS.
*———————————————————————*
* Main program logic (initial ALV display)
*———————————————————————*
START-OF-SELECTION.
” Read vendor master data based on selection criteria
SELECT venderno, name, city, postalcode,
accountgroup, processorgroup, postingblock
FROM zva_vendor_ta
INTO CORRESPONDING FIELDS OF TABLE _vendor
WHERE venderno IN @s_veno.
IF lt_vendor IS NOT INITIAL.
TRY.
” Create SALV table for vendor master list
CALL METHOD cl_salv_table=>factory
IMPORTING
r_salv_table = DATA(lo_salv)
CHANGING
t_table = lt_vendor.
CATCH cx_salv_msg.
” Handle SALV creation error (optional)
ENDTRY.
” Register double-click event handler
CALL METHOD lo_salv->get_event
RECEIVING
value = DATA(lo_event).
” Instantiate event handler class
DATA(lo_cl) = NEW cl1( ).
” Link handler method to SALV event
SET HANDLER lo_cl->handle FOR lo_event.
” Display the vendor list ALV
lo_salv->display( ).
ENDIF.Output : I Double click on 1st rowSummary:This example demonstrates how to enhance a standard ALV report by enabling interactive navigation through double-click events. Using the class CL_SALV_TABLE together with the event handler CL_SALV_EVENTS_TABLE, the program allows users to double-click a vendor row in the header ALV to immediately view the corresponding vendor-item details in a secondary ALV.The solution showcases several key SAP GUI reporting capabilities:Displaying master data using the SALV frameworkCapturing user interaction through the double_click eventDynamically reading and displaying detail records based on user selectionUsing a clean, object-oriented approach to separate event handling from the main program logicWith minimal coding effort, this technique significantly improves usability by allowing users to drill down into related records without creating additional screens or complex logic. This interactive ALV pattern is highly reusable and suitable for many SAP GUI scenarios involving master–detail relationships. Read More Technology Blog Posts by Members articles
#SAP
#SAPTechnologyblog