《SAP_BDC精华教程.docx》由会员分享,可在线阅读,更多相关《SAP_BDC精华教程.docx(15页珍藏版)》请在课桌文档上搜索。
1、BDC技术介绍首先筋单解释一下BDC(BatchDataConversion):在SAP系统里.由于某种原因,可能要宣JUt入敷帚,数据不同,但是黑件是相同的,典型的情形就是切排累腕的H候,旧累优的数据要呼入SAP).大致过程不外乎建这样:输入一个I-COdC.进入一个某个屏幕,然后输入一个值(右时迁要加上一些附加的CheCkboX选项等),点执行或者确定按钮,进入另一个屏幕,在某些字段输入值(也可能是标注CheCkbOX选中或者不选中)或者修改这些字段里的值.然后按“Eneter”最后按“SAVE”.一条记录完成了,继续下一条,如此循环.上面所述的情形,如果让一个“人”来做的话,可能是真是受
2、不了的。但是对于计算机来说,就很简隼了。SAP过一个轿殊的程序(T-Code=SHDB)把用户的一次业务施作的所有过程记录下来.从用户脩入transactioncode(事务代码).点下“StartRecording”开始.对于用户的来说是一次省通的业务操作,但是SAp却在记录:1 .光标放到寿个字段,(在履序中不用改变)2 .填入了什么值.(变量,循环中的IntenUdTab1.e某个字段)3 .点击了什么按钮(在看序中不用改变)本次操作的作为一个“代表.是一个“模板”,告诉SAP系统以怎样的方式来执行程序,也就是用计算机的话育来描述如果手工操作的话应该是怎样的一个过程。用BDC技术揭程时,
3、有以下几个步骤:1 .把外部的It据源(Txt.Exce1.)用读Jtinterna1.SbIeJt者用doenddo循环.2 .在环里耙用SHDB记录的步*重兔执行N次,(N=DiaIog界*数量)这片实际上并没行完成数据的入,第诜只是在*,*一个叫做-BDCDatar的InteEnTab1.e.*兆bdcdata以后.Aca1.1.transaction/XXXX,usingbdc这个令来宾正的coadt动作或1.Ieve1.eData输入一个物料后,点击Se1.ectView(三)*BasicData1BwicData2Sa1.es:Sa1.esOxcData1Sa1.es:Sa1.es
4、Oxc.Data2Sa1.es:Genera1.ZP1.antDataForeignTrade:ExportDataSa1.esTextMRP*,假设我们只选BasicRata1*和uBasicData然后点击绿色的小勾EntcreMateria1.6000-00001autonaticXep1.enishnentnatexia1.H“辞Basicdata11.豺Basicdata21.Sa1.es:sa1.esoc*11.Sa1.es:5a1.esorc2我们在读物料后面添加一个*,GroupA,描述改为:Basicdata115B&sicdata2jSa1.es:sa1.esoxg.11S
5、a1.es:sa1.esorgRateria1.600000001autA3txcXep1.emshnentnatea1.(GxoupA)然后点-SAVE,保存这次修改.现在SAP回观了SHDB.DO三QQB先点“SAVE*,保存ReCOrding:ZteSt.然后点*Back*.返回SHDB的第一屏。选中“Ztest”,然后点击“PrograiT.SSAP臼动生成一个程序。在上面的花话框中输入程序的名字注意SRP的命名标准.丫或者Z开头).确认给人再输入一些程序的属性信忠如下:点击aSourceCode”,指定wDeveiopC1.ass等后,就可以进入ABAPEditor,产生如下代码:r
6、ejrtZBDCTHSTnostandardpageheading1.ine-size255.inc1.udebdcrecx1.parameters:dataset(132)1.owercase.DONOTCHANGE-thegenerateddatasection-DONOTCHANGE* Ifitisnessesarytochangethedatasectionusetheru1.es:* 1.)Eachdefinitionofafie1.dexistsoftwo1.ines* 2.)Thefirst1.ineshowsexact1.ytheCOnmen1.* ,*datae1.ement
7、:fo1.1.owedwiththedatae1.ement* whichdescribesthefie1.d.* Ifyoudonthaveadatae1.ementusethe* commentwithoutadatae1.ementname* 3.)Thesecond1.ineshowsthefie1.dnameofthe* structure,thefie1.dnamemustconsistof* afie1.dnameandoptiona1.thecharacterand* threenumbersandthefie1.d1.engthinbrackets* 4.)Eachfie1.
8、dmustbetypeC.* *Generateddatasectionwithspecificformatting-DONOTCHANGEdata:beginofrecord.* datae1.ement:MTNRMATNRJ)O1.(018),* datae1.ement:XFE1.DKZSE1.01.002(001),* datae1.ement:XFE1.DKZSE1.j)2J)O3(00D,* datae1.ement:MKTXMAKTX004(040).* datae1.ement:MEINSME1.NSJ)O5(003)、* datae1.ement:MTPOS_MARAMTPO
9、SMARA006(004),* datae1.ement:GEWEIGEWEI_007(003).endofrecord.* *Endgenerateddatasection*start-of-se1ection.performopendatasetusingdataset,performopen_group.do.readdatasetdatasetintorecord.ifsy-subreO0.exit,endif.performbdcdynproperformbdc_fie1.dusingSap1.mgmm,ooeo.usingBDC,CIRSOR,RMMG1-MATNR,.perfor
10、mbdc_fie1.dusingbdjokcode,=AUSW,.performbdc_fie1.tiusing,RMMG1.-KWTNR,record-MATNR001.performbdc_dynprousingSAP1.MGMMr0070.perforinbdc_fie1.dusingbdjcursor,msiChtausw-Dytxt(02)performbdcfie1.dusingBDCOKCODE=ENTR,.perforinbdc_fie1.dusingMsichtausw-Kzse1.(OI)record-KZSE1._01.002.performbdcfie1.dusing,
11、MSICItTAUSW-KZSE1.(02)record-KZSE1._02003.performbdc_dynprousingSap1.mgmm4004.performbdc_fie1.dusingbdjokcode,=BU,.performbdc_fie1.dusing,BDCC1.iRSORMAKT-MAKTX.performbdc_fie1.dUSing,MKT-MKTXrecord-MAKTX004.performbdc_fie1.dusingMARA-MEINSrecord-MEINS_005.performbdc_fie1.dusing,MR-MTK)SMRArecord-MTP
12、OSMARA006.performbdc_fie1.dusingmrayeweirecord-GEWE1._007.performbdc_transactiorusingMM02.enddo.performc1.ose_group.performc1.osedatasetusingdataset.上面的程序的主旻逻辑为:opendataset”读取外部覆揖源do.“循环perform填充BDCDTA子程序performbdc_transcationendo.C1.osedataset.注去上面的InCIUde程序里有两个要的form* Startnewscreenformbdc_dynprou
13、singprogramdynpro.c1.earbdcaesstab,名环可以受,但是声典同一嵬要* Batchinputdataofsing1.etransactiondata:abc1.ikebdcdataoccurs0withheader1.ine.* messagesofca1.1.transactiondata:def1.ikebdcsgco1.1.occurs0withheader1.ine.1.ike后面的tab1.etype(这里是一个StniCtUre)是不凭改交的.有两个Hi定动施的fombdc-dynapro和bdc-fi1.d名不同样是任Jt的.便是看序代码应该是相同的
14、,(强烈筵议不要改动,因为会给自己添加麻烦)另个还才一个Intema1.Tab1.e或者workarea是用来放从外部读遗耒的数据的.结杓应该和你的外部文件的有相关的字段偌构.一次读进全部的记录禽后循环处理1.oopatinterna1.tab1.eprocessend1.oop.或弄一条一条读进并处能后棚环读下一条do-process-end.其中PrOCe8s分为两个舄彝:1.“克bdcdata表.2.Ca1.1.transactionorCa1.1.FunctionBDJInser返回消息放入Messtab.另外有一个运验之谈:1,最“柴作,的时候,不要有多余的握作,(什么是多余的操作?
15、自己思考吧)如果有,就重新录吧,不然这些掾作也被记录下未,程序每次都要做一些不必要的动作,2、尽量用H标去点击按钮,而不主只是故Enter*.3.光标的位一般也可以不指定,也就是Perftrmbdcfie1.dusinf1.,BDCCURSOR,XXXX-XXXX通常可以不用写.不过,据说有时候去了也会出问题,如上去就没了,这个我就不知道了。呵Batchinput-RecordingWiththerecordingfunctionSAPautomatica1.1.yCdZngenereratetheBDCtab1.e.Findthetransactioncodeforthescreenthat
16、youwan,ttorecordOpentransactionSM35-BatchInputPushthebuttonRecordingIntheRecordingscreen,enterthennameyouwanttogivetherecording,anmdpushtheCreatebuttonYouwi1.1.nowbepromptedforthetransactioncode.Enterthetransactioncode.Pushtheenterbutton.Youarenowinthescreenwhereyouenterthetransactions.E.ts.51.tidyn
17、proUSING,SAPM1.03T,10.参Insertfie1.dsPERFORM1.xic-fie1.dUSINGf1.TAK-BW1.VSfw_screen1.000-io_bw1.s.PERH)RMbdcfie1.dUSING1.TAP-MA三wscreen1000iomatnr.PERFORMIxijfie1.dUSINGR1.03T-NIMEru_tmpstr.PERFoRMbdcJie1.dUSING1.TRP-CHARGwScreen1.OOOHocharg.PERFORMbdc-fie1.dUSINGBDC.OKCODB=TM,.ndmuchmoreoftheSaBeUse
18、thispartifyouwanttouseca1.1transaction* Ca1.1thetransaction.MessagesfromCa1.1Transactionarestoredinthe*interna1.tah1.e三esstabCA1.I.TRANSACTION,I.T0USINGbdctabMoDEKUPDATESMESSAGESINTOmesstab.IFsysubrc=0. Ca1.1transactionsuccessfu1.1.getthenumberoftheTransferOrderthat WaScreatedI-OOPATmeSS1.db.IFBssta
19、b-dynumb=0104ANDaesstab-msgnr=016.w_transportorderno=messtab-sv1.ENDIF.END1.OOP.E1.SE. Ca1.1.transaction“id.createabatchinputsessioninstead.Pi-RFORMopcnucroup.PERFORMbdc_insertUSING*1.T0.PERFORMc1.ose_group.ENDIF.ENDFORM.HerearetheStrandardformsusedforca1.1.transactionandbatchinput StartsanewscreenA
20、*/*EORMbdc.ncwdynproUSINGprogramdynpro.C1.EARbdctab.bdc_tab-program=program.1.xic.tab-dynpro=dynpro.bdctab-dynbegi11三X.APPENDbdc-tab.ENDFORM.*,木*,*京*京* Insertsafie1.dinbdc_tabFORMbdc.fic1.dUSINGfnafva1.C1.EARbdc.tab.bdc_tab-fnam=fna三,bdctab-fva1.=fva1.APPENDbdc.tab.ENDFORM.参*京*京*今*京*今*h*京*京*Opensgro
21、up,*,*,*,*参*,*种,*,*,*12RMopen_group.CA1.1.FUNCTIONIW)J0PEN一GROuPEXPORTINGc1.ient三sy-mandtDEST=FI1.1.ERS*group=,ZSM02,Ho1.DDATE=FI1.1.ERSkeep三X*user=Sy-UnameRECORD=E11.1.ER1ImtortingQIDEXCEPTIONSCIienJinVaIid=1dcstination_inva1.id=2group_inva1.id=3group_is_1.ocked=4ho1.ddatc-inva1.id=5interna1._error
22、=6queue_error=7running=8syste_1.ock_crror=9USeJinVa1.id三10OTHERS=11.ENDFORM.,米*京*.*.*.*/*.,*)f*.*.*C1.osesgroupar*相FORMc1.osegroup.CA1.1.FUNCTION*BDC_C1.OSE_GRO1.P,EXCEPTIONSnot_opcn=1queueerror=2OTHERS=3.ENDI-ORM.*我*我*A*BDC-INSERT*M(*)M(*FORMbdc_insertUSINGtcode.CA1.1.FUNCTI(WBDC_JNSERTEXPORTINGtcode*PoS1.OCA1.=tcode=Novb1.oca1.*PRINTINGTAB1.ES=NOPRINTdynprotab=bdc_tabEXCEPTIONSinterna1.error三1not_open=2queue.error=3ICOde.inva1.id=4Priritinginva1.id三5posting_inva1.id=6OTHERS=7.ENDFORM.