点击保存执行成功:
REPORT YTEST1.
TABLES:t001.
SELECT-OPTIONS:s_bukrs FOR t001-bukrs NO INTERVALS.
PARAMETERS:p_x TYPE char01 AS CHECKBOX.
DATA:l_mode TYPE c,
l_msg TYPE char255,
l_flag TYPE c.
DATA:
-
BDC数据内表
wt_bdcdata TYPE STANDARD TABLE OF bdcdata, -
BDC消息内表
wt_msgtab TYPE STANDARD TABLE OF bdcmsgcoll,
ws_mode TYPE ctu_params, "BDC运行时的参数字符串
ws_bdcdata TYPE bdcdata, "BDC数据结构
ws_msgtab TYPE bdcmsgcoll. "BDC消息结构
DATA:varmsgno TYPE symsgno.
DATA:varmsgv1 TYPE msgv1.
DATA:varmsgv2 TYPE msgv2.
DATA:varmsgv3 TYPE msgv3.
DATA:varmsgv4 TYPE msgv4.
DATA msr TYPE bapiret1. "错误信息
l_mode = ‘N’.
LOOP AT s_bukrs.
PERFORM bdc_dynpro USING ‘SAPMM03Y’ ‘0100’.
PERFORM bdc_field USING: ‘BDC_CURSOR’ ‘MARV-BUKRS’.
PERFORM bdc_field USING: ‘BDC_OKCODE’ ‘/00’.
PERFORM bdc_field USING: ‘MARV-BUKRS’ s_bukrs-low .PERFORM bdc_dynpro USING: ‘SAPMM03Y’ ‘0110’ .
PERFORM bdc_field USING: ‘BDC_CURSOR’ ‘MARV-XRUEM’.
PERFORM bdc_field USING: ‘BDC_OKCODE’ ‘=BU’.
PERFORM bdc_field USING: ‘MARV-XRUEM’ p_x ."是否允许当前期间记账"调用事务代码
CALL TRANSACTION ‘MMRV’
USING wt_bdcdata
MODE l_mode
MESSAGES INTO wt_msgtab.
LOOP AT wt_msgtab INTO ws_msgtab WHERE msgtyp = ‘E’ OR
msgtyp = ‘A’ OR
msgtyp = ‘X’.
l_flag = ‘E’.
EXIT.
ENDLOOP.
IF l_flag = ‘E’.
LOOP AT wt_msgtab INTO ws_msgtab .
varmsgno = ws_msgtab-msgnr.
varmsgv1 = ws_msgtab-msgv1.
varmsgv2 = ws_msgtab-msgv2.
varmsgv3 = ws_msgtab-msgv3.
varmsgv4 = ws_msgtab-msgv4.
CALL FUNCTION ‘BALW_BAPIRETURN_GET1’
EXPORTING
type = ws_msgtab-msgtyp
cl = ws_msgtab-msgid
number = varmsgno
par1 = varmsgv1
par2 = varmsgv2
par3 = varmsgv3
par4 = varmsgv4
IMPORTING
bapireturn = msr.
CONCATENATE l_msg ’ ’ msr-message INTO l_msg.
WRITE:‘/’,l_msg.
CLEAR:msr,varmsgno,varmsgv1,varmsgv2,varmsgv3,varmsgv4,ws_msgtab.
ENDLOOP.
ELSE.
l_msg = ‘执行完成’.
WRITE:l_msg.
ENDIF.
CLEAR:wt_bdcdata[],wt_msgtab[],ws_msgtab,l_msg.
ENDLOOP.
&---------------------------------------------------------------------
*& FORM BDC_DYNPRO
&---------------------------------------------------------------------
-
BDC_DYNPRO
----------------------------------------------------------------------
-
-->U_PROGRAM
-
-->U_DYNPRO
----------------------------------------------------------------------
FORM bdc_dynpro USING u_program TYPE any
u_dynpro TYPE any.
CLEAR ws_bdcdata.
ws_bdcdata-program = u_program.
ws_bdcdata-dynpro = u_dynpro.
ws_bdcdata-dynbegin = ‘X’.
APPEND ws_bdcdata TO wt_bdcdata.
ENDFORM. "BDC_DYNPRO
&---------------------------------------------------------------------
*& FORM BDC_FIELD
&---------------------------------------------------------------------
-
BDC_FIELD
----------------------------------------------------------------------
-
-->U_FNAM
-
-->U_FVAL
----------------------------------------------------------------------
FORM bdc_field USING u_fnam TYPE any
u_fval TYPE any.
CLEAR ws_bdcdata.
ws_bdcdata-fnam = u_fnam.
ws_bdcdata-fval = u_fval.
CONDENSE ws_bdcdata-fval.
APPEND ws_bdcdata TO wt_bdcdata.
ENDFORM. "BDC_FIELD