1:输入事务代码:SHDB.点击新建记录。
输入记录名和需要录屏的事务代码。
开始记录后会进入事务代码点击返回后会记录下操作过程。
点击程序按钮,生成可以调用的代码。
代码如下:
report ZTEST_APPLICTION
no standard page heading line-size 255.
include bdcrecx1.
parameters: dataset(132) lower case.
*** DO NOT CHANGE - the generated data section - DO NOT CHANGE ***
*
* If it is nessesary to change the data section use the rules:
* 1.) Each definition of a field exists of two lines
* 2.) The first line shows exactly the comment
* '* data element: ' followed with the data element
* which describes the field.
* If you don't have a data element use the
* comment without a data element name
* 3.) The second line shows the fieldname of the
* structure, the fieldname must consist of
* a fieldname and optional the character '_' and
* three numbers and the field length in brackets
* 4.) Each field must be type C.
*
*** Generated data section with specific formatting - DO NOT CHANGE ***
data: begin of record,
* data element: VBELN_VA
VBELN_001(030),
end of record.
*** End generated data section ***
start-of-selection.
perform open_dataset using dataset.
perform open_group.
do.
read dataset dataset into record.
if sy-subrc <> 0. exit. endif.
perform bdc_dynpro using 'SAPMV45A' '0102'.
perform bdc_field using 'BDC_CURSOR'
'VBAK-VBELN'.
perform bdc_field using 'BDC_OKCODE'
'=ENT2'.
perform bdc_field using 'VBAK-VBELN'
record-VBELN_001.
perform bdc_dynpro using 'SAPMV45A' '4001'.
perform bdc_field using 'BDC_OKCODE'
'=HEAD'.
perform bdc_field using 'BDC_CURSOR'
'RV45A-MABNR(01)'.
perform bdc_dynpro using 'SAPMV45A' '4002'.
perform bdc_field using 'BDC_OKCODE'
'/EBACK'.
perform bdc_field using 'BDC_CURSOR'
'VBAK-VBELN'.
perform bdc_dynpro using 'SAPMV45A' '4001'.
perform bdc_field using 'BDC_OKCODE'
'/EBAC1'.
perform bdc_transaction using 'VA03'.
enddo.
perform close_group.
perform close_dataset using dataset.
如果需要调用 BDC 只需要 perform bdc_field 。
调用的实际应用例子——清账:
LOOP AT lt_sel INTO ls_sel WHERE s_count = 0.
CLEAR:bdcdata,lv_index,ls_alv2.
REFRESH:bdcdata,lt_belnr.
split ls_sel-s_belnr at ',' into TABLE lt_belnr.
perform bdc_dynpro using 'SAPMF05A' '0131'.
perform bdc_field using 'BDC_CURSOR'
'RF05A-XPOS1(04)'.
perform bdc_field using 'BDC_OKCODE'
'/00'.
perform bdc_field using 'RF05A-AGKON'
ls_sel-kunnr.
perform bdc_field using 'BKPF-BUDAT'
sy-datum.
perform bdc_field using 'BKPF-MONAT'
sy-datum+4(2).
perform bdc_field using 'BKPF-BUKRS'
ls_sel-bukrs.
* perform bdc_field using 'BKPF-WAERS'
* 'CNY'.
perform bdc_field using 'RF05A-XNOPS'
'X'.
perform bdc_field using 'RF05A-XPOS1(01)'
''.
perform bdc_field using 'RF05A-XPOS1(04)'
'X'.
perform bdc_dynpro using 'SAPMF05A' '0731'.
perform bdc_field using 'BDC_CURSOR'
'RF05A-SEL01(02)'.
perform bdc_field using 'BDC_OKCODE'
'=PA'.
*如果是表格,可以循环赋值
LOOP at lt_belnr into ls_belnr.
CLEAR lv_str.
lv_index = lv_index + 1.
CONCATENATE 'RF05A-SEL01(' lv_index ')' INTO lv_str.
perform bdc_field using lv_str
ls_belnr-belnr.
ENDLOOP.
* perform bdc_field using 'RF05A-SEL01(01)'
* '5200000000'.
* perform bdc_field using 'RF05A-SEL01(02)'
* '5200000002'.
perform bdc_dynpro using 'SAPDF05X' '3100'.
perform bdc_field using 'BDC_OKCODE'
'=BU'.
perform bdc_field using 'BDC_CURSOR'
'DF05B-PSSKT(01)'.
perform bdc_field using 'RF05A-ABPOS'
'1'.
opt-dismode = 'N'. "显示模式
opt-updmode = 'L'. "更新模式
opt-racommit = 'X'. "提交后继续
REFRESH gt_message.
CALL TRANSACTION 'F-32' USING bdcdata
OPTIONS FROM opt
MESSAGES INTO gt_message.
CLEAR:lv_message,lv_bdc_message.
*获取返回的错误提示
LOOP AT gt_message.
IF gt_message-msgtyp = 'E' OR gt_message-msgtyp = 'A'
OR ( gt_message-msgid = 'F5' AND gt_message-msgnr = '263' ).
CLEAR: lv_bdc_message.
MESSAGE ID gt_message-msgid TYPE gt_message-msgtyp NUMBER gt_message-msgnr
WITH gt_message-msgv1 gt_message-msgv2 gt_message-msgv3 gt_message-msgv4
INTO lv_bdc_message.
CONCATENATE lv_message lv_bdc_message INTO lv_message.
ENDIF.
ENDLOOP.