The leading actor for this post is CL_SALV_BS_RUNTIME_INFO class. And only three steps, you can get the ALV report’s output into internal table. You can see all source code at Appendix A.
Step 1: Call SET method and set parameters to suppress ALV display and get data as per your purpose.
Step 2: Submit report program with required criteria.
Step 3: Call GET_DATA_REF method to get data from ALV report into TRY…CATCH and CLEAR_ALL method subsequently.
Appendix A
REPORT zget_alv_output.
TABLES:
mara, marc, mard, mch1.
SELECT-OPTIONS:
s_matnr FOR mara-matnr,
s_werks FOR marc-werks,
s_lgort FOR mard-lgort,
s_charg FOR mch1-charg,
s_mtart FOR mara-mtart,
s_matkl FOR mara-matkl.
PARAMETERS:
pc_nzero AS CHECKBOX.
TYPES:
BEGIN OF gy_mb52,
* Key fields
matnr TYPE mara-matnr,
werks TYPE t001w-werks,
lgort TYPE mard-lgort,
sobkz TYPE mkol-sobkz,
ssnum TYPE bickey-ssnum,
pspnr TYPE mspr-pspnr,
vbeln TYPE mska-vbeln,
posnr TYPE mska-posnr,
lifnr TYPE mkol-lifnr,
kunnr TYPE msku-kunnr,
kzbws TYPE mssa-kzbws,
charg TYPE mchb-charg,
* Additional data (texts, unit, …)
maktx TYPE marav-maktx,
bwkey TYPE mbew-bwkey,
mtart TYPE marav-mtart,
matkl TYPE marav-matkl,
meins TYPE marav-meins,
bwtty TYPE marc-bwtty,
xchar TYPE marc-xchar,
lgobe TYPE t001l-lgobe,
bwtar TYPE mcha-bwtar,
waers TYPE t001-waers,
name1 TYPE t001w-name1,
* Quantities and currencies
labst TYPE mard-labst,
wlabs TYPE mbew-salk3,
insme TYPE mard-insme,
winsm TYPE mbew-salk3,
speme TYPE mard-speme,
wspem TYPE mbew-salk3,
einme TYPE mard-einme,
weinm TYPE mbew-salk3,
retme TYPE mard-retme,
wretm TYPE mbew-salk3,
umlme TYPE mard-umlme,
wumlm TYPE mbew-salk3,
glgmg TYPE marc-glgmg,
wglgm TYPE mbew-salk3,
trame TYPE marc-trame,
wtram TYPE mbew-salk3,
umlmc TYPE marc-umlmc,
wumlc TYPE mbew-salk3,
* valuated blocked GR stock
bwesb TYPE marc-bwesb,
wbwesb TYPE mbew-salk3,
sgt_scat TYPE mchb-sgt_scat,
* CWM Fields
* CWM parallel Quantities
/cwm/labst TYPE mard-/cwm/labst,
/cwm/insme TYPE mard-/cwm/insme,
/cwm/speme TYPE mard-/cwm/speme,
/cwm/einme TYPE mard-/cwm/einme,
/cwm/retme TYPE mard-/cwm/retme,
/cwm/umlme TYPE mard-/cwm/umlme,
/cwm/trame TYPE marc-/cwm/trame,
/cwm/umlmc TYPE marc-/cwm/umlmc,
/cwm/bwesb TYPE marc-/cwm/bwesb,
* CWM
/cwm/meins TYPE mari-/cwm/meins,
/cwm/valum TYPE mari-/cwm/meins,
/cwm/xcwmat TYPE mara-/cwm/xcwmat,
END OF gy_mb52.
DATA:
gt_mb52 TYPE TABLE OF gy_mb52,
gw_mb52 TYPE gy_mb52.
DATA:
go_data TYPE REF TO data.
FIELD-SYMBOLS:
<gt_data> TYPE ANY TABLE.
cl_salv_bs_runtime_info=>set( EXPORTING display = abap_false
metadata = abap_false
data = abap_true ).
“Submit MB52
SUBMIT rm07mlbs
WITH matnr IN s_matnr
WITH werks IN s_werks
WITH lgort IN s_lgort
WITH charg IN s_charg
WITH matart IN s_mtart
WITH matkla IN s_matkl
WITH negativ = abap_false
WITH pa_sond = abap_true
WITH xmchb = abap_true
WITH nozero = pc_nzero
WITH novalues = abap_false
WITH pa_hsq = abap_false
WITH pa_flt = abap_true
AND RETURN.
“Get data from MB52
TRY.
cl_salv_bs_runtime_info=>get_data_ref(
IMPORTING r_data = go_data ).
ASSIGN go_data->* TO <gt_data>.
“Keep MB52 data into internal table
IF <gt_data> IS ASSIGNED.
LOOP AT <gt_data> ASSIGNING FIELD-SYMBOL(<fs_data>).
MOVE-CORRESPONDING <fs_data> TO gw_mb52.
APPEND gw_mb52 TO gt_mb52.
ENDLOOP.
ENDIF.
CATCH cx_salv_bs_sc_runtime_info ##NO_HANDLER.
MESSAGE ‘Unable to retrieve ALV data’ TYPE ‘E’.
ENDTRY.
cl_salv_bs_runtime_info=>clear_all( ).