SUBMIT的用法
一、简介
-
系统MB52/MB51/MB5B等类似的报表 ,虽然数据很全面,执行效率也够快,但是经常会不满足用户需求(增添字段、添加查询条件等),很多ABAP 会选择去COPY出标准程序,然后去做修改,强烈不推荐此种方式,弊端太大,容易使标准程序出现问题,且效率低(特别涉及MSEG等数据库表)。
-
我们可以使用SUBMIT,此语法可将获取系统标准报表数据,然后你就可以自己去加一层壳来实现自己的定制。
-
语法:selscreen_options:主要是标准程序选择界面Field,通过F1去查看具体Field name。
SUBMIT {rep|(name)} [selscreen_options] [list_options] [job_options] [AND RETURN].
二、Submit的使用方法和案例
-
下列案例是获取MB51的数据
-
有两个方法来建数据赋值
-
方法一:获取ALV报表结果数据(不局限于严格意义上的ALV Grid、LIST报表也能获取到值),关键代码:
*&---------------------------------------------------------------------* *& *& 获取MB5B数据 *&---------------------------------------------------------------------* DATA:lr_alv_data TYPE REF TO data. FIELD-SYMBOLS : <lt_alv_data> TYPE ANY TABLE . FIELD-SYMBOLS : <lt_data> TYPE ANY. "LIKE LINE OF it_tab . *&---------------------------------------------------------------------* *& "计算特殊库存E的期初期末 *&---------------------------------------------------------------------* cl_salv_bs_runtime_info=>set( EXPORTING display = abap_false metadata = abap_false data = abap_true ). CLEAR lr_alv_data. UNASSIGN <lt_alv_data>. SUBMIT rm07mlbd "MB5B特殊库存及搜索条件 WITH matnr IN so_matnr WITH werks IN so_werks WITH lgort EQ so_lgort-low "循环获取每个库存地点的期初期末 WITH sobkz EQ 'E' WITH datum IN so_budat "库存类型-特殊库存 WITH lgbst EQ space WITH bwbst EQ space WITH sbbst EQ 'X' "设置 WITH xsum EQ space WITH pa_sumfl EQ 'X' WITH xchar EQ space WITH xnomchb EQ space WITH xnomchb EQ space WITH nosto EQ space WITH 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 <lt_alv_data>. 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 <lt_alv_data> IS ASSIGNED. UNASSIGN <lt_data>. LOOP AT <lt_alv_data> ASSIGNING <lt_data>."即所需要内表数据 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 EhP4 no_list(01) TYPE c VALUE 'X'. "Do not show the list "MAA EhP4 DATA: 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, "351455 bwtar TYPE mseg-bwtar, "351455 bwart 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 rm07docs WITH matnr IN so_matnr WITH werks IN so_werks WITH lgort IN so_lgort WITH database EQ abap_true WITH pa_dbstd EQ abap_true WITH mb51_flag EQ flag WITH mb51_nolist EQ no_list EXPORTING 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.
-
-
执行结果