BDC program (Batch Data communication program)也是通过ABAP程序将数据批量导入SAP业务系统的方法。
BDC是模拟屏幕操作,记录相关屏幕出现顺序和处理过程,产生数据格式的文件,在调整数据文件后,通过运行BDC产生的ABAP程序,将数据更新到SAP的业务系统.
在此基础上,查阅BDC所产生的程序,可以非常清晰地了解BDC的工作原理,通过编程可以完成功能更强大的ABAP数据导入程序。在这一点上,BDC比CATT更加的灵活,对于大批量的数据特别是单据类型数据的录入,BDC比CATT更快,而且能更有效地控制出错数据。对于一个项目的期初上线,BDC或BAPI是不可或缺的,但BAPI的开发和调测的工作量较大。
BDC步骤:
1.记录屏幕操作;
Tcode:SHDB,进入事务记录窗口,输入名称后单机“New recording”按钮,录制新的记录
2.产生相关程序和数据格式文件;
3.调整数据文件;
4.运行BDC产生的程序读取文件导入数据;
5.代码分析;
6.用BDC导入单据;
一般BDC录制屏幕后扩展性不灵活,只可在生成的代码中做简单的改动。批量的导入数据首先是获取数据,可以通过Excel上传,或者从标准表中获取数据,将要上传的数据放到内表中,使用Loop.......endloop来完成上传的步骤。
A.BDC结构:
field name type description
Program char(8) program name of transaction
Dynpro char(4) screen number of transaction
Dynbegin char(1) indicator for new screen
Fname char(35) name of database field from screen
Fval char(80) value to submit to field
B.BDC code:
okcode description
/nn function key nn
/00 enter
/8 F8,continue otr execute
/11 F11 post
%ex exit
back F3, back previous screen
dlt delete
pick double click
save f11,save
C.BDC同步异步问题,调用事务码VA02时,如果选择异步方式,因为多条记录同时处理,导致异常出现,最好选用同步处理的方式。
call TRANSACTION 'VA02' using bdcdata mode 'A' update 'S'.
updata upd: value 'A' Asynchronous update
value 'S' Synchronous update
value 'L' Local uodate
mode mode : value 'A', proceesing with screen displayed
value 'E' Screen displayed only if an error occurs
value 'N' process withous screens displayed,if a breakpoint is reached in one of the called transactions,processing is terminate with sy-subrc equal to 1001.
value 'P' processing without screen displayed.if a breakpoint is reached in one of the called transactions,the system branches to the ABAP Debugger.
others as for 'A'.
程序:
tables:vbap.
include bdcrecx1.
data:begin of wa_vbap,
vbeln like vbap-vbeln,
posnr like vbap-posnr,
ARKTX like vbap-arktx,
end of wa_vbap.
data:itab_vbap like wa_vbap OCCURS 0 WITH HEADER LINE .
data:posnr(6) type c.
start-of-selection.
select vbeln posnr arktx from vbap
into CORRESPONDING FIELDS OF TABLE itab_vbap
where vbeln = '0000004972'.
loop at itab_vbap.
if itab_vbap-arktx = 'Sunny Sunny 02' or itab_vbap-arktx = 'Sunny Xa1'.
itab_vbap-arktx = '1'.
modify itab_vbap.
posnr = itab_vbap-posnr.
clear bdcdata.
perform open_group.
perform bdc_dynpro using 'SAPMV45A' '0102'.
perform bdc_field using 'BDC_CURSOR'
'VBAK-VBELN'.
perform bdc_field using 'BDC_OKCODE'
'/00'.
perform bdc_field using 'VBAK-VBELN'
itab_vbap-vbeln.
perform bdc_dynpro using 'SAPMV45A' '4001'.
perform bdc_field using 'BDC_OKCODE'
'=POPO'.
perform bdc_field using 'BDC_CURSOR'
'RV45A-MABNR(01)'.
perform bdc_dynpro using 'SAPMV45A' '0251'.
perform bdc_field using 'BDC_CURSOR'
'RV45A-POSNR'.
perform bdc_field using 'BDC_OKCODE'
'=POSI'.
perform bdc_field using 'RV45A-POSNR'
posnr.
perform bdc_dynpro using 'SAPMV45A' '4001'.
perform bdc_field using 'BDC_OKCODE'
'=SICH'.
perform bdc_field using 'BDC_CURSOR'
'VBAP-ARKTX(01)'.
perform bdc_field using 'VBAP-ARKTX(01)'
itab_vbap-arktx.
call TRANSACTION 'VA02' using bdcdata mode 'A' update 'S'.
perform close_group.
endif.
endloop.