Variante 1 (SUBMIT)
* https://blogs.sap.com/2011/07/07/gain-programmatic-access-to-data-of-sapgui-alv-reports/
* http://www.saptutorial.org/get-data-from-alv-report-sap-standard-and-output-into-internal-table/
* Initialisierung
cl_salv_bs_runtime_info=>set( EXPORTING display = abap_false " Report anzeigen?
metadata = abap_true " Metadaten des ALV-Grids ermitteln?
data = abap_true ). " Datenimport aus ALV-Grid?
* Selektionsparameter des Reports 'RSVTPROT' (Transaktion SCU3)
DATA: it_sel_par TYPE STANDARD TABLE OF rsparams WITH DEFAULT KEY.
APPEND VALUE #( selname = 'CUSOBJ' " Name Parameter oder Selektionskriterium
kind = 'P' " P - Parameter, S - Selektionskriterium
sign = 'I'
option = 'EQ'
low = 'Z...' ) TO it_sel_par. " NAME des Customizing-Objektes (Z-Tabelle ...)
APPEND VALUE #( selname = 'DBEG' " Name Parameter oder Selektionskriterium
kind = 'P' " P - Parameter, S - Selektionskriterium
sign = 'I'
option = 'EQ'
low = '20170101' ) TO it_sel_par.
APPEND VALUE #( selname = 'DEND' " Name Parameter oder Selektionskriterium
kind = 'P' " P - Parameter, S - Selektionskriterium
sign = 'I'
option = 'EQ'
low = '20171231' ) TO it_sel_par.
APPEND VALUE #( selname = 'TBEG' " Name Parameter oder Selektionskriterium
kind = 'P' " P - Parameter, S - Selektionskriterium
sign = 'I'
option = 'EQ'
low = '000000' ) TO it_sel_par.
APPEND VALUE #( selname = 'TEND' " Name Parameter oder Selektionskriterium
kind = 'P' " P - Parameter, S - Selektionskriterium
sign = 'I'
option = 'EQ'
low = '235959' ) TO it_sel_par.
APPEND VALUE #( selname = 'ALV_GRID' " Name Parameter oder Selektionskriterium
kind = 'P' " P - Parameter, S - Selektionskriterium
sign = 'I'
option = 'EQ'
low = 'X' ) TO it_sel_par.
* Report mit Selektionsparametern aufrufen
SUBMIT rsvtprot WITH SELECTION-TABLE it_sel_par AND RETURN.
TRY.
DATA: o_alv_data TYPE REF TO data.
* Datenreferenz auf ALV-Daten des Reports
cl_salv_bs_runtime_info=>get_data_ref( IMPORTING r_data = o_alv_data ).
IF o_alv_data IS BOUND.
FIELD-SYMBOLS: <alv> TYPE ANY TABLE.
ASSIGN o_alv_data->* TO <alv>.
IF <alv> IS ASSIGNED.
* Metadaten des ALV-Grids
DATA(lv_metadata) = cl_salv_bs_runtime_info=>get_metadata( ).
* ALV-Grid-Titel
WRITE: / lv_metadata-s_layout-grid_title.
ULINE.
* ALV-Spaltentitel (Feldkatalog)
LOOP AT lv_metadata-t_fcat ASSIGNING FIELD-SYMBOL(<f>).
WRITE: / <f>-fieldname, <f>-seltext, <f>-tooltip, <f>-reptext, <f>-domname.
ENDLOOP.
ULINE.
* Anzahl Spalten
DATA(lv_col_cnt) = lines( lv_metadata-t_fcat ).
* Datenausgabe
LOOP AT <alv> ASSIGNING FIELD-SYMBOL(<row>).
DO lv_col_cnt TIMES.
* Spaltenweise die Zellen der akt. Zeile
ASSIGN COMPONENT sy-index OF STRUCTURE <row> TO FIELD-SYMBOL(<cell>).
IF <cell> IS ASSIGNED.
WRITE: <cell>.
ENDIF.
ENDDO.
SKIP.
ENDLOOP.
ENDIF.
ELSE.
WRITE: / 'Keine ALV-Daten verfügbar.'.
ENDIF.
CATCH cx_root INTO DATA(e_txt).
WRITE: / e_txt->get_text( ).
ENDTRY.
TRY.
cl_salv_bs_runtime_info=>clear_all( ).
CATCH cx_root INTO DATA(e_txt2).
WRITE: / e_txt2->get_text( ).
ENDTRY.
Variante 2 (CALL TRANSACTION)
* Initialisierung
cl_salv_bs_runtime_info=>set( EXPORTING display = abap_false " Report anzeigen?
metadata = abap_true " Metadaten des ALV-Grids ermitteln?
data = abap_true ). " Datenimport aus ALV-Grid?
* Selektionparameter "Werk" vorbelegen
SET PARAMETER ID 'WRK' FIELD '10'.
* Transaktion aufrufen
CALL TRANSACTION 'MM60' WITHOUT AUTHORITY-CHECK AND SKIP FIRST SCREEN.
IF sy-subrc = 0.
TRY.
DATA: o_alv_data TYPE REF TO data.
* Datenreferenz auf ALV-Daten des Reports
cl_salv_bs_runtime_info=>get_data_ref( IMPORTING r_data = o_alv_data ).
IF o_alv_data IS BOUND.
FIELD-SYMBOLS: <alv> TYPE ANY TABLE.
ASSIGN o_alv_data->* TO <alv>.
IF <alv> IS ASSIGNED.
* Metadaten des ALV-Grids
DATA(lv_metadata) = cl_salv_bs_runtime_info=>get_metadata( ).
* ALV-Grid-Titel
WRITE: / lv_metadata-s_layout-grid_title.
ULINE.
* ALV-Spaltentitel (Feldkatalog)
LOOP AT lv_metadata-t_fcat ASSIGNING FIELD-SYMBOL(<f>).
WRITE: / <f>-fieldname, <f>-seltext, <f>-tooltip, <f>-reptext, <f>-domname.
ENDLOOP.
ULINE.
* Anzahl Spalten
DATA(lv_col_cnt) = lines( lv_metadata-t_fcat ).
* Datenausgabe
LOOP AT <alv> ASSIGNING FIELD-SYMBOL(<row>).
DO lv_col_cnt TIMES.
* Spaltenweise die Zellen der akt. Zeile
ASSIGN COMPONENT sy-index OF STRUCTURE <row> TO FIELD-SYMBOL(<cell>).
IF <cell> IS ASSIGNED.
WRITE: <cell>.
ENDIF.
ENDDO.
SKIP.
ENDLOOP.
ENDIF.
ELSE.
WRITE: / 'Keine ALV-Daten verfügbar.'.
ENDIF.
CATCH cx_root INTO DATA(e_txt).
WRITE: / e_txt->get_text( ).
ENDTRY.
TRY.
cl_salv_bs_runtime_info=>clear_all( ).
CATCH cx_root INTO DATA(e_txt2).
WRITE: / e_txt2->get_text( ).
ENDTRY.
ENDIF.