系统MB52/MB51/MB5B等类似的报表 ,虽然数据很全面,执行效率也够快,但是经常会不满足用户需求(增添字段、添加查询条件等),很多ABAP 会选择去COPY出标准程序,然后去做修改,强烈不推荐此种方式,弊端太大,容易使标准程序出现问题,且效率低(特别涉及MSEG等数据库表)。
我们可以使用SUBMIT,此语法可将获取系统标准报表数据,然后你就可以自己去加一层壳来实现自己的定制。
语法:selscreen_options:主要是标准程序选择界面Field,通过F1去查看具体Field name。
SUBMIT {rep|(name)} [selscreen_options]
[list_options]
[job_options]
[AND RETURN].
下列案例是获取MB51的数据
有两个方法来建数据赋值
方法一:获取ALV报表结果数据(不局限于严格意义上的ALV Grid、LIST报表也能获取到值),关键代码:
*&---------------------------------------------------------------------*
*&
*& 获取MB5B数据
*&---------------------------------------------------------------------*
DATA:lr_alv_data TYPE REF TO data. FIELD-SYMBOLS : TYPE ANY TABLE .
FIELD-SYMBOLS : TYPE ANY. "LIKE LINE OF it_tab . *&---------------------------------------------------------------------*
*& "计算特殊库存E的期初期末
*&---------------------------------------------------------------------*cl_salv_bs_runtime_info=>set( EXPORTING display = abap_falsemetadata = abap_falsedata = abap_true ).CLEAR lr_alv_data.UNASSIGN .SUBMIT rm07mlbd "MB5B特殊库存及搜索条件WITH matnr IN so_matnrWITH werks IN so_werksWITH lgort EQ so_lgort-low "循环获取每个库存地点的期初期末WITH sobkz EQ 'E'WITH datum IN so_budat"库存类型-特殊库存WITH lgbst EQ spaceWITH bwbst EQ spaceWITH sbbst EQ 'X'"设置WITH xsum EQ spaceWITH pa_sumfl EQ 'X'WITH xchar EQ spaceWITH xnomchb EQ spaceWITH xnomchb EQ spaceWITH nosto EQ spaceWITH pa_dbstd EQ 'X'AND RETURN.TRY."关键代码cl_salv_bs_runtime_info=>get_data_ref( IMPORTING r_data = lr_alv_data ).ASSIGN lr_alv_data->* TO .CATCH cx_salv_bs_sc_runtime_info.MESSAGE 'Unable to retrieve ALV data! Please try other conditions.' TYPE 'E'.ENDTRY.cl_salv_bs_runtime_info=>clear_all( )."IF IS ASSIGNED.UNASSIGN .LOOP AT ASSIGNING ."即所需要内表数据ENDLOOP.ENDIF.
将执行结果放入MEMORY(此法用于结果不是很明确的ALV结构),关键代码:
*&---------------------------------------------------------------------*
*& Report ZTEST_CALL_MB51
*&
*&---------------------------------------------------------------------*
*&
*& 获取MB51数据
*&---------------------------------------------------------------------*REPORT ztest_call_mb51.TYPE-POOLS:abap.
TABLES:mseg,mara,mard.DATA:flag(01) TYPE c VALUE 'X', "Name for compatibility with MB03 "MAA EhP4no_list(01) TYPE c VALUE 'X'. "Do not show the list "MAA EhP4DATA: BEGIN OF export_list OCCURS 0,matnr TYPE mseg-matnr,maktx TYPE makt-maktx,werks TYPE mseg-werks,name1 TYPE t001w-name1,lgort TYPE mseg-lgort,charg TYPE mseg-charg, "351455bwtar TYPE mseg-bwtar, "351455bwart TYPE mseg-bwart,sobkz TYPE mseg-sobkz,btext TYPE t156t-btext,mblnr TYPE mseg-mblnr,mjahr TYPE mseg-mjahr,zeile TYPE mseg-zeile,budat TYPE mkpf-budat,erfmg TYPE mseg-erfmg,erfme TYPE mseg-erfme,lifnr TYPE mseg-lifnr,vgart TYPE mkpf-vgart,END OF export_list.SELECTION-SCREEN: BEGIN OF BLOCK blk1 WITH FRAME TITLE text-t01.
SELECT-OPTIONS:so_werks FOR mseg-werks OBLIGATORY,so_matnr FOR mseg-matnr,so_mtart FOR mara-mtart,so_matkl FOR mara-matkl,so_lgort FOR mard-lgort.
SELECT-OPTIONS so_mtr_i FOR mseg-matnr NO-DISPLAY .
SELECTION-SCREEN: END OF BLOCK blk1.START-OF-SELECTION.EXPORT flag TO MEMORY ID 'MB51_FLAG'.EXPORT no_list TO MEMORY ID 'MB51_NOLIST' .EXPORT export_list TO MEMORY ID 'MB51_EXPORT_LIST'.SUBMIT rm07docsWITH matnr IN so_matnrWITH werks IN so_werksWITH lgort IN so_lgortWITH database EQ abap_trueWITH pa_dbstd EQ abap_trueWITH mb51_flag EQ flagWITH mb51_nolist EQ no_listEXPORTING LIST TO MEMORY AND RETURN.IMPORT export_list FROM MEMORY ID 'MB51_EXPORT_LIST'."关键代码FREE MEMORY ID 'MB51_EXPORT_LIST'.LOOP AT export_list."export_list 为需要的内表数据ENDLOOP.
执行结果