*&---------------------------------------------------------------------*
*& Report ZOOPS_SALV_ALV3*&
*&---------------------------------------------------------------------*
*& In this example will show you how to Enable Adding Layout toolbar
*&---------------------------------------------------------------------*
REPORT zsalv_alv3.
*&---------------------------------------------------------------------*
*& Data declaration
*&---------------------------------------------------------------------*
DATA: gv_vbeln TYPE vbak-vbeln.
*&---------------------------------------------------------------------*
*& Selection Screen
*&---------------------------------------------------------------------*
SELECTION-SCREEN BEGIN OF BLOCK a1 WITH FRAME TITLE text-001.
SELECT-OPTIONS s_vbeln FOR gv_vbeln.
SELECTION-SCREEN END OF BLOCK a1.
*&---------------------------------------------------------------------*
*& Class Defination
*&---------------------------------------------------------------------*
CLASS lcl_salv_data DEFINITION.
"&... Visibility Section
PUBLIC SECTION.
"&... Public Method for display data
METHODS display_data.
PRIVATE SECTION.
"&... Type Declaration for data
TYPES: BEGIN OF ty_data,
vbeln TYPE vbeln,
audat TYPE audat,
auart TYPE auart,
posnr TYPE posnr,
matnr TYPE matnr,
arktx TYPE arktx,
netwr TYPE netwr,
waerk TYPE waerk,
kwmeng TYPE kwmeng,
meins TYPE meins,
END OF ty_data.
*&---------------------------------------------------------------------*
*& Internal Table Declaration
*&---------------------------------------------------------------------*
DATA: gt_data TYPE TABLE OF ty_data.
"&... Method for fetch the data
METHODS get_data.
ENDCLASS.
*&---------------------------------------------------------------------*
*& Class Implementation
*&---------------------------------------------------------------------*
CLASS lcl_salv_data IMPLEMENTATION.
METHOD get_data.
SELECT a~vbeln
a~audat
a~auart
b~posnr
b~matnr
b~arktx
b~netwr
b~waerk
b~kwmeng
b~meins
FROM vbak AS a INNER JOIN vbap AS b
ON a~vbeln EQ b~vbeln INTO TABLE gt_data
WHERE a~vbeln IN s_vbeln.
IF sy-subrc NE 0.
MESSAGE 'Data not found for given input' TYPE 'E'.
ENDIF.
ENDMETHOD.
METHOD display_data.
"&... Local Reference variable declaration
DATA: lref_alv TYPE REF TO cl_salv_table,
lref_function TYPE REF TO cl_salv_functions_list,
lref_layout TYPE REF TO cl_salv_layout.
"&... Local variable declaration
DATA: lv_key TYPE salv_s_layout_key.
"&... Call Method for fetch display data
me->get_data( ).
"&... FACTORY Method instantiating the ALV of the Class CL_SALV_TABLE
cl_salv_table=>factory(
* EXPORTING
* list_display = IF_SALV_C_BOOL_SAP=>FALSE
* r_container = r_container
* container_name = container_name
IMPORTING
r_salv_table = lref_alv
CHANGING
t_table = gt_data
).
"&... GET_FUNCTIONS method provides access to the ALV's functions' objects
lref_function = lref_alv->get_functions( ).
"&... SET_ALL method set all the function
lref_function->set_all( ).
"&... GET_LAYOUT method get the layout object from ALV
lref_layout = lref_alv->get_layout( ).
"&... Pass Current program name
lv_key-report = sy-repid.
"&... SET_KEY method call the layout object for current program
lref_layout->set_key( lv_key ).
"&... Pass static attribute (SAVE layout button enable)
lref_layout->set_save_restriction( if_salv_c_layout=>restrict_user_dependant ).
"&... Set defualt layout
lref_layout->set_default( abap_true ).
"&... DISPLAY Method display the data in ALV
lref_alv->display( ).
ENDMETHOD.
ENDCLASS.
*&---------------------------------------------------------------------*
*& START-OF-SELECTION Events
*&---------------------------------------------------------------------*
START-OF-SELECTION.
DATA: lo_data TYPE REF TO lcl_salv_data.
"&... Create Object for class LCL_SALV_DATA.
CREATE OBJECT lo_data.
"&... Call Display Method for display data.
lo_data->display_data( ).
Output: