Académique Documents
Professionnel Documents
Culture Documents
4Replies Latestreply:Feb29,201211:03AMbyGuest
PrasadAkole Sep7,200711:38AM
CreatingBDC
ThisquestionisAssumedAnswered.
howtoCreateBDCforcertainTransaction?
5671Views
AverageUserRating
(0ratings)
Re:CreatingBDC
recordthetransactionbygoingtotransaction<b>SHDB</b>.
thereyougivethetransactionthatyouwanttorecord.recordforonerecordandwriteprogramforit.
example:
reportZKIRAN_UPLOAD
nostandardpageheadinglinesize255.
includebdcrecx1.
Tablesdeclaration
tables:zkiran_tab2.
datadeclaration
data:itablikezkiran_tab2occurs15withheaderline.
selectionscreen
selectionscreen:beginofblocka1.
parameters:i_filelikerlgrapfilenamedefault'D:\DocumentsandSettings\tzj13g\Desktop\sample.txt'.
selectionscreen:endofblocka1.
*atselectionscreenonvaluerequestfori_file.
*CALLFUNCTION'F4_FILENAME'
*EXPORTING
*PROGRAM_NAME=syrepid
DYNPRO_NUMBER=SYSTDYNNR
FIELD_NAME=''
IMPORTING
*FILE_NAME=i_file.
startofselection.
parameters:dataset(132)lowercase.
DONOTCHANGEthegenerateddatasectionDONOTCHANGE***
*
Ifitisnessesarytochangethedatasectionusetherules:
1.)Eachdefinitionofafieldexistsoftwolines
2.)Thefirstlineshowsexactlythecomment
'*dataelement:'followedwiththedataelement
whichdescribesthefield.
Ifyoudon'thaveadataelementusethe
commentwithoutadataelementname
3.)Thesecondlineshowsthefieldnameofthe
structure,thefieldnamemustconsistof
afieldnameandoptionalthecharacter'_'and
threenumbersandthefieldlengthinbrackets
4.)EachfieldmustbetypeC.
*
GenerateddatasectionwithspecificformattingDONOTCHANGE***
data:beginofrecord,
dataelement:CLASSTAB
TBMA_001(001),
dataelement:TABNAME16
TBMA_VAL_002(016),
dataelement:ZEMPNO
EMPNO_003(010),
dataelement:ZNAME
NAME_004(020),
dataelement:ZDEPTID
DEPTID_005(002),
dataelement:ZDESIG
DESIG_006(010),
dataelement:ZPLACE
PLACE_007(010),
dataelement:CLASSTAB
TBMA_008(001),
dataelement:TABNAME16
TBMA_VAL_009(016),
endofrecord.
Endgenerateddatasection***
startofselection.
performu_itab.
performupload_ztable.
endofselection.
&
*&Formupload_ztable
&
FORMupload_ztable.
performopen_datasetusingdataset.
performopen_group.
loopatitab.
readdatasetdatasetintorecord.
ifsysubrc<>0.exit.endif.
performbdc_dynprousing'SAPMSRD0''0102'.
performbdc_fieldusing'BDC_CURSOR'
'RSRD1TBMA_VAL'.
performbdc_fieldusing'BDC_OKCODE'
'=SHOW'.
performbdc_fieldusing'RSRD1TBMA'
recordTBMA_001.
performbdc_fieldusing'RSRD1TBMA_VAL'
'ZKIRAN_TAB2'.
performbdc_dynprousing'SAPLSD41''2200'.
performbdc_fieldusing'BDC_CURSOR'
'DD02DTABCLTEXT'.
performbdc_fieldusing'BDC_OKCODE'
'=TDED'.
performbdc_dynprousing'/1BCDWB/DBZKIRAN_TAB2''0101'.
performbdc_fieldusing'BDC_CURSOR'
'ZKIRAN_TAB2PLACE'.
performbdc_fieldusing'BDC_OKCODE'
'=SAVE'.
performbdc_fieldusing'ZKIRAN_TAB2EMPNO'
ITABEMPNO.
performbdc_fieldusing'ZKIRAN_TAB2NAME'
ITABNAME.
performbdc_fieldusing'ZKIRAN_TAB2DEPTID'
ITABDEPTID.
performbdc_fieldusing'ZKIRAN_TAB2DESIG'
ITABDESIG.
performbdc_fieldusing'ZKIRAN_TAB2PLACE'
ITABPLACE.
performbdc_dynprousing'/1BCDWB/DBZKIRAN_TAB2''0101'.
performbdc_fieldusing'BDC_OKCODE'
'/EBACK'.
performbdc_fieldusing'BDC_CURSOR'
'ZKIRAN_TAB2EMPNO'.
performbdc_dynprousing'SAPLSD41''2200'.
performbdc_fieldusing'BDC_CURSOR'
'DD02DTABCLTEXT'.
performbdc_fieldusing'BDC_OKCODE'
'=WB_BACK'.
performbdc_dynprousing'SAPMSRD0''0102'.
performbdc_fieldusing'BDC_CURSOR'
'RSRD1TBMA_VAL'.
performbdc_fieldusing'BDC_OKCODE'
'=BACK'.
performbdc_fieldusing'RSRD1TBMA'
recordTBMA_008.
performbdc_fieldusing'RSRD1TBMA_VAL'
recordTBMA_VAL_009.
performbdc_transactionusing'SE11'.
endloop.
performclose_group.
performclose_datasetusingdataset.
ENDFORM."upload_ztable
&
*&Formupload_itab
&
FORMu_itab.
breakpoint.
CALLFUNCTION'WS_UPLOAD'
EXPORTING
CODEPAGE=''
FILENAME=i_file
FILETYPE='DAT'
HEADLEN=''
LINE_EXIT=''
TRUNCLEN=''
USER_FORM=''
USER_PROG=''
DAT_D_FORMAT=''
IMPORTING
FILELENGTH=
TABLES
DATA_TAB=itab
EXCEPTIONS
CONVERSION_ERROR=1
FILE_OPEN_ERROR=2
FILE_READ_ERROR=3
INVALID_TYPE=4
NO_BATCH=5
UNKNOWN_ERROR=6
INVALID_TABLE_WIDTH=7
GUI_REFUSE_FILETRANSFER=8
CUSTOMER_ERROR=9
NO_AUTHORITY=10
OTHERS=11
.
IFSYSUBRC<>0.
MESSAGEIDSYMSGIDTYPESYMSGTYNUMBERSYMSGNO
WITHSYMSGV1SYMSGV2SYMSGV3SYMSGV4.
ENDIF.
Like(0)
Re:CreatingBDC
Hi,
TocreateaBDCforacertaintransactionsgothroughthefollowingsteps:
1)<b>CreatearecordingforthetransactionusingtransactioncodeSHDB:</b>
gotoSHDB>itdispalysinitialscreenofrecordingwithrequiredfields.Hereprovideinformationlike
nameofrecording,TRANSACTIONusedforrecording.
chooseSTARTrecording.ItdispalysthescreensofTRANSACTION.
providedatatothefieldsasperyourneedsandsaveit.
2)<b>GeneratetheProgram</b>:
InSHDBselectyourrecordingandclicktheprogramtab.Thiswillgeneratetheprogramfordata
transfer.
itprovides
1)oneincludeprogramINCLUDEBDCRECX1.
2)internaltablesBDCDATA.
3)twosubroutineesBDC_DYNPROandBDC_FIELD
4)twosubroutineesOPEN_GROUP(itcontainsbdc_open_groupandbdc_insert)
CLOSE_GROUP(itcontainsbdc_close_group).
3)<b>ModificationsinProgram</b>:
declarethevariablestobeusedandgetthedatatobeuploadedintheinternaltable.
uploaddataintointernaltableusingfunctionws_uploadorgui_upload.
4)BDC_OPEN_GROUPopensasession.
5)LOOPAT<internaltable>.
perform<name>using<applicationname><screen>.
perform<name>using<screenfield><internaltablevalue>.
6))nowendloopwithENDLOOPstatement
7)BDC_CLOSE_GROUP.Thisclosesthesession.
8)executetheprogram,givethesessionnameand(keeptheseesion).
9)gotoSM35>selectSESSIONname>selectPROCESS.
Youcanalsogothroughthefollowinglinkforsamplecode
BDCexampleforMM01Tcode...
Like(0)
Re:CreatingBDC
hi,
ifuuserecordingitisveryeasy.
gotoSHDB>newrecording>givenameandtcode(XK01)>givemaditoryfields>recordtransaction
>save>tranferfromrecording>giveprogramname(aatributes)
checkthisexample:
reportZSK_BDC
nostandardpageheadinglinesize255.
data:beginofw_input1,
g_data(200)typec,
endofw_input1,
t_input1likestandardtableofw_input1initialsize0,
beginofw_input,
ekorg(4)typec,
ktokk(4)typec,
anred(15)typec,
name1(30)typec,
sortl(10)typec,
land1(3)typec,
spras(2)typec,
waers(5)typec,
endofw_input,
t_inputlikestandardtableofw_inputinitialsize0,
g_stringtypestring,
t_bdcdatatypestandardtableofbdcdatainitialsize0,
t_bdcmsgcolltypestandardtableofbdcmsgcoll,
w_bdcdatatypebdcdata,
w_bdcmsgcolltypebdcmsgcoll.
parameters:p_filetypeIBIPPARMSPATH.
atselectionscreenonvaluerequestforp_file.
CALLFUNCTION'F4_FILENAME'
EXPORTING
PROGRAM_NAME=SYSTCPROG
DYNPRO_NUMBER=SYSTDYNNR
FIELD_NAME=''
IMPORTING
FILE_NAME=p_file
.
g_string=p_file.
*includebdcrecx1.
startofselection.
CALLFUNCTION'GUI_UPLOAD'
EXPORTING
filename=g_string
FILETYPE='ASC'
HAS_FIELD_SEPARATOR='X'
HEADER_LENGTH=0
READ_BY_LINE='X'
DAT_MODE=''
CODEPAGE=''
IGNORE_CERR=ABAP_TRUE
REPLACEMENT='#'
CHECK_BOM=''
IMPORTING
FILELENGTH=
HEADER=
tables
data_tab=t_input1
EXCEPTIONS
FILE_OPEN_ERROR=1
FILE_READ_ERROR=2
NO_BATCH=3
GUI_REFUSE_FILETRANSFER=4
INVALID_TYPE=5
NO_AUTHORITY=6
UNKNOWN_ERROR=7
BAD_DATA_FORMAT=8
HEADER_NOT_ALLOWED=9
SEPARATOR_NOT_ALLOWED=10
HEADER_TOO_LONG=11
UNKNOWN_DP_ERROR=12
ACCESS_DENIED=13
DP_OUT_OF_MEMORY=14
DISK_FULL=15
DP_TIMEOUT=16
OTHERS=17
.
IFsysubrc<>0.
MESSAGEIDSYMSGIDTYPESYMSGTYNUMBERSYMSGNO
WITHSYMSGV1SYMSGV2SYMSGV3SYMSGV4.
ENDIF.
loopatt_input1intow_input1.
splitw_input1g_dataat','intow_inputekorg
w_inputktokk
w_inputanred
w_inputname1
w_inputsortl
w_inputland1
w_inputspras
w_inputwaers.
appendw_inputtot_input.
endloop.
*performopen_group.
loopatt_inputintow_input.
refresht_bdcdata.
performbdc_dynprousing'SAPMF02K''0107'.
performbdc_fieldusing'BDC_CURSOR'
'RF02KKTOKK'.
performbdc_fieldusing'BDC_OKCODE'
'/00'.
performbdc_fieldusing'RF02KEKORG'
w_inputekorg.
performbdc_fieldusing'RF02KKTOKK'
w_inputktokk.
performbdc_dynprousing'SAPMF02K''0110'.
performbdc_fieldusing'BDC_CURSOR'
'LFA1SPRAS'.
performbdc_fieldusing'BDC_OKCODE'
'/00'.
performbdc_fieldusing'LFA1ANRED'
w_inputanred.
performbdc_fieldusing'LFA1NAME1'
w_inputname1.
performbdc_fieldusing'LFA1SORTL'
w_inputsortl.
performbdc_fieldusing'LFA1LAND1'
w_inputland1.
performbdc_fieldusing'LFA1SPRAS'
w_inputspras.
performbdc_dynprousing'SAPMF02K''0120'.
performbdc_fieldusing'BDC_CURSOR'
'LFA1KUNNR'.
performbdc_fieldusing'BDC_OKCODE'
'/00'.
performbdc_dynprousing'SAPMF02K''0130'.
performbdc_fieldusing'BDC_CURSOR'
'LFBKBANKS(01)'.
performbdc_fieldusing'BDC_OKCODE'
'=ENTR'.
performbdc_dynprousing'SAPMF02K''0310'.
performbdc_fieldusing'BDC_CURSOR'
'LFM1WAERS'.
performbdc_fieldusing'BDC_OKCODE'
'/00'.
performbdc_fieldusing'LFM1WAERS'
w_inputwaers.
performbdc_dynprousing'SAPMF02K''0320'.
performbdc_fieldusing'BDC_CURSOR'
'RF02KLIFNR'.
performbdc_fieldusing'BDC_OKCODE'
'=ENTR'.
performbdc_dynprousing'SAPLSPO1''0300'.
performbdc_fieldusing'BDC_OKCODE'
'=YES'.
calltransaction'MK01'usingt_bdcdata
mode'n'
update'S'
messagesintot_bdcmsgcoll.
endloop.
loopatt_bdcmsgcollintow_bdcmsgcoll.
write:w_bdcmsgcollDYNAME,
w_bdcmsgcollDYNUMB,
w_bdcmsgcollMSGTYP,
w_bdcmsgcollMSGSPRA,
w_bdcmsgcollMSGID,
w_bdcmsgcollMSGNR,
w_bdcmsgcollMSGV1,
w_bdcmsgcollMSGV2,
w_bdcmsgcollMSGV3,
w_bdcmsgcollMSGV4.
endloop.
*performbdc_transactionusing'MK01'.
*performclose_group.
&
*&Formbdc_dynpro
&
text
>P_0156text
>P_0157text
formbdc_dynprousingvalue(p_0156)
value(p_0157).
clearw_bdcdata.
w_bdcdataprogram=p_0156.
w_bdcdatadynpro=p_0157.
w_bdcdatadynbegin='X'.
appendw_bdcdatatot_bdcdata.
endform."bdc_dynpro
&
*&Formbdc_field
&
text
>P_0175text
>P_0176text
formbdc_fieldusingvalue(p_0175)
value(p_0176).
clearw_bdcdata.
w_bdcdatafnam=p_0175.
w_bdcdatafval=p_0176.
appendw_bdcdatatot_bdcdata.
endform."bdc_field
Sessionmethod
calltransation
directinputmethod
TouploadmutiplefilesuseFMGui_uploadforeveryflatfile
GothruthisDocbelow.
BATCHDATACOMMUNICATION
AboutDataTransferInR/3System
WhenacompanydecidestoimplementtheSAPR/3tomanagebusinesscriticaldata,itusuallydoes
notstartfromanodatasituation.Normally,aSAPR/3projectcomesintoreplaceorcomplement
existingapplication.
Intheprocessofreplacingcurrentapplicationsandtransferringapplicationdata,twosituationsmight
occur:
Thefirstiswhenapplicationdatatobereplacedistransferredatonce,andonlyonce.
ThesecondsituationistotransferdataperiodicallyfromexternalsystemstoSAPandviceversa.
Thereisaperiodoftimewheninformationhastobetransferredfromexistingapplication,toSAP
R/3,andoftenthisprocesswillberepetitive.
TheSAPsystemofferstwoprimarymethodsfortransferringdataintoSAPsystems.FromnonSAP
systemsorlegacysystem.Thesetwomethodsarecollectivelycalledbatchinputorbatchdata
communication.
1.SESSIONMETHOD
2.CALLTRANSACTION
3.DIRECTINPUT
AdvantagesofferedbyBATCHINPUTmethod:
1.Canprocesslargedatavolumesinbatch.
2.Canbeplannedandsubmittedinthebackground.
3.Nomanualinteractionisrequiredwhendataistransferred.
4.Dataintegrityismaintainedaswhateverdataistransferredtothetableisthroughtransaction.
Hencebatchinputdataissubmittedtoallthechecksandvalidations.
Toimplementoneofthesupporteddatatransfers,youmustoftenwritetheprogramthatexportsthe
datafromyournonSAPsystem.Thisprogram,knownasadatatransferprogrammustmapthedata
fromtheexternalsystemintothedatastructurerequiredbytheSAPbatchinputprogram.
ThebatchinputprogrammustbuildalloftheinputtoexecutetheSAPtransaction.
Twomainstepsarerequired:
Tobuildaninternaltablecontainingeveryscreenandeveryfieldtobefilledinduringtheexecution
ofanSAPtransaction.
TopassthetabletoSAPforprocessing.
PrerequisiteforDataTransferProgram
WritingaDataTransferPrograminvolvesfollowingprerequisites:
Analyzingdatafromlocalfile
Analyzingtransaction
Analyzingtransactioninvolvesfollowingsteps:
Thetransactioncode,ifyoudonotalreadyknowit.
Whichfieldsrequireinputi.e.,mandatory.
Whichfieldscanyouallowtodefaulttostandardvalues.
Thenames,types,andlengthsofthefieldsthatareusedbyatransaction.
ScreennumberandNameofmodulepoolprogrambehindaparticulartransaction.
Toanalyzeatransaction::
Startthetransactionbymenuorbyenteringthetransactioncodeinthecommandbox.
(YoucandeterminethetransactionnamebychoosingSystemStatus.)
Stepthroughthetransaction,enteringthedatawillberequiredforprocessingyourbatchinputdata.
Oneachscreen,notetheprogramnameandscreen(dynpro)number.
(dynpro=dyn+pro.Dyn=screen,pro=number)
DisplaythesebychoosingSystemStatus.TherelevantfieldsareProgram(dynpro)andDynpro
number.Ifpopupwindowsoccurduringexecution,youcangettheprogramnameandscreen
numberbypressingF1onanyfieldorbuttononthescreen.
Thetechnicalinfopopupshowsnotonlythefieldinformationbutalsotheprogramandscreen.
Foreachfield,checkbox,andradiobuttononeachscreen,pressF1(help)andthenchoose
TechnicalInfo.
Notethefollowinginformation:
Thefieldnameforbatchinput,whichyoullfindinitsownbox.
Thelengthanddatatypeofthefield.YoucandisplaythisinformationbydoubleclickingontheData
Elementfield.
Findouttheidentificationcodeforeachfunction(buttonormenu)thatyoumustexecutetoprocess
thebatchinputdata(ortogotonewscreen).
Placethecursoronthebuttonormenuentrywhileholdingdowntheleftmousebutton.Thenpress
F1.
Inthepopupwindowthatfollows,chooseTechnicalinfoandnotethecodethatisshowninthe
Functionfield.
Youcanalsorunanyfunctionthatisassignedtoafunctionkeybywayofthefunctionkeynumber.To
displaythelistofavailablefunctionkeys,clickontherightmousebutton.Notethekeynumberthatis
assignedtothefunctionsyouwanttorun.
Onceyouhaveprogramname,screennumber,fieldname(screenfieldname),youcanstartwriting.
DATATRANSFERprogram.
Declaringinternaltable
FirstIntegralTablesimilartostructurelikelocalfile.
DeclaringinternaltablelikeBDCDATA
Thedatafrominternaltableisnottransferreddirectlytodatabasetable,ithastogothrough
transaction.Youneedtopassdatatoparticularscreenandtoparticularscreenfield.Dataispassed
totransactioninparticularformat,hencethereisaneedforbatchinputstructure.
ThebatchinputstructurestoresthedatathatistobeenteredintoSAPsystemandtheactionsthatare
necessarytoprocessthedata.Thebatchinputstructureisusedbyallofthebatchinputmethods.You
canusethesamestructureforalltypesofbatchinput,regardlessofwhetheryouarecreatinga
sessioninthebatchinputqueueorusingCALLTRANSACTION.
ThisstructureisBDCDATA,whichcancontainthebatchinputdataforonlyasinglerunofa
transaction.Thetypicalprocessingloopinaprogramisasfollows:
CreateaBDCDATAstructure
WritethestructureouttoasessionorprocessitwithCALLTRANSACTIONUSINGandthen
CreateaBDCDATAstructureforthenexttransactionthatistobeprocessed.
WithinaBDCDATAstructure,organizethedataofscreensinatransaction.Eachscreenthatis
processedinthecourseofatransactionmustbeidentifiedwithaBDCDATArecord.Thisrecorduses
theProgram,Dynpro,andDynbeginfieldsofthestructure.
ThescreenidentifierrecordisfollowedbyaseparateBDCDATArecordforeachvalue,tobeentered
intoafield.TheserecordsusetheFNAMandFVALfieldsoftheBDCDATAstructure.Valuestobe
enteredinafieldcanbeanyofthefollowing:
Datathatisenteredintoscreenfields.
Functioncodesthatareenteredintothecommandfield.Suchfunctioncodesexecutefunctionsina
transaction,suchasSaveorEnter.
TheBDCDATAstructurecontainsthefollowingfields:
PROGRAM:Nameofmodulepoolprogramassociatedwiththescreen.Setthisfieldonlyforthefirst
recordforthescreen.
DYNPRO:ScreenNumber.Setthisfieldonlyinthefirstrecordforthescreen.
DYNBEGIN:Indicatesthefirstrecordforthescreen.SetthisfieldtoX,onlyforthefirstrecordforthe
screen.(Resetto(blank)forallotherrecords.)
FNAM:FieldName.TheFNAMfieldisnotcasesensitive.
FVAL:ValueforthefieldnamedinFNAM.TheFVALfieldiscasesensitive.Valuesassignedtothis
fieldarealwayspaddedontheright,iftheyarelessthan132characters.Valuesmustbeincharacter
format.
Transferringdatafromlocalfiletointernaltable
DataisuploadedtointernaltablebyUPLOADofWS_UPLOADfunction.
PopulationofBDCDATA
Foreachrecordofinternaltable,youneedtopopulateInternaltable,whichissimilartoBDCDATA
structure.
AllthesefiveinitialstepsarenecessaryforanytypeofBDCinterface.
DATATRANSFERprogramcancallSESSIONMETHODorCALLTRANSACTION.Theinitialstepsfor
boththemethodsaresame.
Firststepforboththemethodsistouploadthedatatointernaltable.FromInternalTable,thedatais
transferredtodatabasetablebytwowaysi.e.,SessionmethodandCalltransaction.
SESSIONMETHOD
AboutSessionmethod
Inthismethodyoutransferdatafrominternaltabletodatabasetablethroughsessions.
Inthismethod,anABAP/4programreadstheexternaldatathatistobeenteredintheSAPSystem
andstoresthedatainsession.Asessionstorestheactionsthatarerequiredtoenteryourdatausing
normalSAPtransactioni.e.,Dataistransferredtosessionwhichinturntransfersdatatodatabase
table.
Sessionisintermediatestepbetweeninternaltableanddatabasetable.Dataalongwithitsactionis
storedinsessioni.e.,dataforscreenfields,towhichscreenitispassed,theprogramnamebehindit,
andhowthenextscreenisprocessed.
Whentheprogramhasfinishedgeneratingthesession,youcanrunthesessiontoexecutetheSAP
transactionsinit.Youcaneitherexplicitlystartandmonitorasessionorhavethesessionruninthe
backgroundprocessingsystem.
Unlesssessionisprocessed,thedataisnottransferredtodatabasetable.
BDC_OPEN_GROUP
YoucreatethesessionthroughprogrambyBDC_OPEN_GROUPfunction.
Parameterstothisfunctionare:
UserName:Username
Group:Nameofthesession
LockDate:Thedateonwhichyouwanttoprocessthesession.
Keep:ThisparameterispassedasXwhenyouwanttoretainsessionafter
processingitortodeleteitafterprocessing.
BDC_INSERT
Thisfunctioncreatesthesession&dataistransferredtoSession.
Parameterstothisfunctionare:
Tcode:TransactionName
Dynprotab:BDCData
BDC_CLOSE_GROUP
ThisfunctionclosestheBDCGroup.NoParameters.
Someadditionalinformationforsessionprocessing
WhenthesessionisgeneratedusingtheKEEPoptionwithintheBDC_OPEN_GROUP,thesystem
alwayskeepsthesessionsinthequeue,whetherithasbeenprocessedsuccessfullyornot.
However,ifthesessionisprocessed,youhavetodeleteitmanually.Whensessionprocessingis
completedsuccessfullywhileKEEPoptionwasnotset,itwillberemovedautomaticallyfromthe
sessionqueue.Logisnotremovedforthatsession.
Ifthebatchinputsessionisterminatedwitherrors,thenitappearsinthelistofINCORRECTsession
anditcanbeprocessedagain.Tocorrectincorrectsession,youcananalyzethesession.The
Analysisfunctionallowstodeterminewhichscreenandvaluehasproducedtheerror.Ifyoufindsmall
errorsindata,youcancorrecttheminteractively,otherwiseyouneedtomodifybatchinputprogram,
whichhasgeneratedthesessionormanytimeseventhedatafile.
CALLTRANSACTION
AboutCALLTRANSACTION
AtechniquesimilartoSESSIONmethod,whilebatchinputisatwostepprocedure,CallTransaction
doesbothstepsonline,oneaftertheother.Inthismethod,youcallatransactionfromyourprogramby
Calltransaction<tcode>using<BDCTAB>
Mode<A/N/E>
Update<S/A>
Messagesinto<MSGTAB>.
Parameter1istransactioncode.
Parameter2isnameofBDCTABtable.
Parameter3hereyouarespecifyingmodeinwhichyouexecutetransaction
Aisallscreenmode.Allthescreenoftransactionaredisplayed.
Nisnoscreenmode.Noscreenisdisplayedwhenyouexecutethetransaction.
Eiserrorscreen.Onlythosescreensaredisplayedwhereinyouhaveerrorrecord.
Parameter4hereyouarespecifyingupdatetypebywhichdatabasetableisupdated.
SisforSynchronousupdateinwhichifyouchangedataofonetablethenalltherelatedTablesgets
updated.Andsysubrcisreturnedi.e.,sysubrcisreturnedforonceandall.
AisforAsynchronousupdate.Whenyouchangedataofonetable,thesysubrcisreturned.Andthen
updatingofotheraffectedtablestakesplace.Soifsystemfailstoupdateothertables,stillsysubrc
returnedis0(i.e.,whenfirsttablegetsupdated).
Parameter5whenyouupdatedatabasetable,operationiseithersuccessfulorunsuccessfulor
operationissuccessfulwithsomewarning.Thesemessagesarestoredininternaltable,whichyou
specifyalongwithMESSAGEstatement.ThisinternaltableshouldbedeclaredlikeBDCMSGCOLL,a
structureavailableinABAP/4.Itcontainsthefollowingfields:
1.Tcode:Transactioncode
2.Dyname:Batchpointmodulename
3.Dynumb:BatchinputDynnumber
4.Msgtyp:Batchinputmessagetype(A/E/W/I/S)
5.Msgspra:BatchinputLang,idofmessage
6.Msgid:Messageid
7.MsgvN:Messagevariables(N=14)
Foreachentry,whichisupdatedindatabase,tablemessageisavailableinBDCMSGCOLL.As
BDCMSGCOLLisstructure,youneedtodeclareainternaltablewhichcancontainmultiplerecords
(unlikestructure).
StepsforCALLTRANSACTIONmethod
1.Internaltableforthedata(structuresimilartoyourlocalfile)
2.BDCTABlikeBDCDATA
3.UPLOADorWS_UPLOADfunctiontouploadthedatafromlocalfiletoitab.(Consideringfileis
localfile)
4.Loopatitab.
PopulateBDCTABtable.
Calltransaction<tcode>using<BDCTAB>
Mode<A/N/E>
Update<S/A>.
RefreshBDCTAB.
Endloop.
(TopopulateBDCTAB,Youneedtotransfereachandeveryfield)
ThemajordifferencesbetweenSessionmethodandCalltransactionareasfollows:
SESSIONMETHODCALLTRANSACTION
1.DataisnotupdatedindatabasetableunlessSessionisprocessed.Immediateupdationin
databasetable.
2.Nosysubrcisreturned.Sysubrcisreturned.
3.Errorlogiscreatedforerrorrecords.Errorsneedtobehandledexplicitly
4.UpdationindatabasetableisalwayssynchronousUpdationindatabasetablecanbesynchronous
OrAsynchronous.
ErrorHandlinginCALLTRANSACTION
WhenSessionMethodupdatestherecordsindatabasetable,errorrecordsarestoredinthelogfile.
InCalltransactionthereisnosuchlogfileavailableanderrorrecordislostunlesshandled.Usually
youneedtogivereportofalltheerrorrecordsi.e.,recordswhicharenotinsertedorupdatedinthe
databasetable.Thiscanbedonebythefollowingmethod:
StepsfortheerrorhandlinginCALLTRANSACTION
1.Internaltableforthedata(structuresimilartoyourlocalfile)
2.BDCTABlikeBDCDATA
3.InternaltableBDCMSGlikeBDCMSGCOLL
4.InternaltablesimilartoIstinternaltable
(Thirdandfourthstepsareforerrorhandling)
5.UPLOADorWS_UPLOADfunctiontouploadthedatafromthelocalfiletoitab.(Consideringfileis
localfile)
6.Loopatitab.
PopulateBDCTABtable.
Calltransaction<tr.code>using<Bdctab>
Mode<A/N/E>
Update<S/A>
Messages<BDCMSG>.
Performcheck.
RefreshBDCTAB.
Endloop.
7Formcheck.
IFsysubrc<>0.(Calltransactionreturnsthesysubrcifupdatingisnotsuccessful).
CallfunctionFormat_message.
(Thisfunctioniscalledtostorethemessagegivenbysystemandtodisplayitalongwithrecord)
Appenditab2.
Displaytherecordandmessage.
DIRECTINPUT
AboutDirectInput
Incontrasttobatchinput,thistechniquedoesnotcreatesessions,butstoresthedatadirectly.Itdoes
notsimulatetheonlinetransaction.Toenterthedataintothecorrespondingdatabasetablesdirectly,
thesystemcallsanumberoffunctionmodulesthatexecuteanynecessarychecks.Incaseoferrors,
thedirectinputtechniqueprovidesarestartmechanism.However,tobeabletoactivatetherestart
mechanism,directinputprogramsmustbeexecutedinthebackgroundonly.Directinputchecksthe
datathoroughlyandthenupdatesthedatabasedirectly.
YoucanstartaDirectInputprogramintwoways
Starttheprogramdirectly
Thisisthequickestwaytoseeiftheprogramworkswithyourflatfile.Thisoptionispossiblewithall
directinputprograms.Iftheprogramendsabnormally,youwillnothaveanylogstellingyouwhathas
orhasnotbeenposted.Tominimizethechanceofthishappening,alwaysusethecheckfileoption
forthefirstrunwithyourflatfile.Thisallowsyoutodetectformaterrorsbeforetransfer.
StartingtheprogramviatheDIadministrationtransaction
Thistransactionrestartstheprocessing,ifthedatatransferprogramaborts.SinceDIdocumentare
immediatelypostedintotheSAPD/B,therestartoptionpreventstheduplicatedocumentpostingthat
occursduringaprogramrestart(i.e.,withoutadjustingyourflatfile).
Directinputisusuallydoneforstandarddatalikematerialmaster,FIaccountingdocument,SDsales
orderandClassificationforwhichSAPhasprovidedstandardprograms.
FirsttimeyouworkwiththeDirectInputadministrationprogram,youwillneedtodosomepreparation
beforeyoucantransferdata:
Createvariant
Definejob
Startjob
Restartjob
Commonbatchinputerrors
ThebatchinputBDCDATAstructuretriestoassignvaluestofieldswhichdonotexistinthecurrent
transactionscreen.
ThescreenintheBDCDATAstructuredoesnotmatchtherightsequence,oranintermediatescreen
ismissing.
Onexceptionaloccasions,thelogicflowofbatchinputsessiondoesnotexactlymatchthatof
manualonlineprocessing.Testingthesessionsonlinecandiscoverbythis.
TheBDCDATAstructurecontainsfields,whicharelongerthantheactualdefinition.
Authorizationproblems.
RECORDINGABATCHINPUT
ABrecordingallowsyoutorecordaR/3transactionandgenerateaprogramthatcontainsallscreens
andfieldinformationintherequiredBDCDATAformat.
YoucaneitheruseSHDBtransactionforrecordingor
SYSTEM?SERVICES?BATCHINPUT?EDIT
Andfromhereclickrecording.
Enternamefortherecording.
(Datesareoptional)
Clickrecording.
Entertransactioncode.
Enter.
ClickSavebutton.
Youfinallycometoascreenwhere,youhavealltheinformationforeachscreenincluding
BDC_OKCODE.
ClickGetTransaction.
ReturntoBI.
Clickoverview.
Positionthecursoronthejustrecordedentryandclickgenerateprogram.
Enterprogramname.
Clickenter
Theprogramisgeneratedfortheparticulartransaction.
BACKGROUNDPROCESSING
NeedforBackgroundprocessing
Whenalargevolumeofdataisinvolved,usuallyallbatchinputsaredoneinbackground.
TheR/3systemincludesfunctionsthatallowuserstoworknoninteractivelyoroffline.The
backgroundprocessingsystemshandlethesefunctions.
NoninteractivelymeansthatinsteadofexecutingtheABAP/4programsandwaitingforananswer,
usercansubmitthoseprogramsforexecutionatamoreconvenientplannedtime.
Thereareseveralreasonstosubmitprogramsforbackgroundexecution.
Themaximumtimeallowedforonlineexecutionshouldnotexceed300seconds.Usergets
TIMEOUTerrorandanabortedtransaction,iftimeforexecutionexceeds300seconds.Toavoidthese
typesoferror,youcansubmitjobsforbackgroundprocessing.
Youcanusethesystemwhileyourprogramisexecuting.
Thisdoesnotmeanthatinteractiveoronlineworkisnotuseful.Bothtypeofprocessinghavetheir
ownpurposes.Onlineworkisthemostcommononeenteringbusinessdata,displayinginformation,
printingsmallreports,managingthesystemandsoon.Backgroundjobsaremainlyusedforthe
followingtaskstoprocesslargeamountofdata,toexecuteperiodicjobswithouthumanintervention,
torunprogramatamoreconvenient,plannedtimeotherthanduringnormalworkinghoursi.e.,
Nightsorweekends.
ThetransactionforbackgroundprocessingisSM36.
Or
Tools?Administration?Jobs?Definejobs
Or
System?services?Jobs
Componentsofthebackgroundjobs
AjobinBackgroundprocessingisaseriesofstepsthatcanbescheduledandstepisaprogramfor
backgroundprocessing.
Jobname.Definethenameofassignedtothejob.Itidentifiesthejob.Youcanspecifyupto32
charactersforthename.
Jobclass.Indicatesthetypeofbackgroundprocessingpriorityassignedtothejob.
Thejobclassdeterminesthepriorityofajob.Thebackgroundsystemadmitsthreetypesofjob
classes:AB&C,whichcorrespondtojobpriority.
Jobsteps.Parameterstobepassedforthisscreenareasfollows:
Programname.
Variantifitisreportprogram
Startcriteriaforthejob:Optionavailableforthisareasfollows:
Immediateallowsyoutostartajobimmediately.
Date/Timeallowsyoutostartajobataspecificname.
Afterjobyoucanstartajobafteraparticularjob.
Aftereventallowsyoutostartajobafteraparticularevent.
Atoperationmodeallowsyoutostartajobwhenthesystemswitchestoaparticularoperationmode.
DefiningBackgroundjobs
Itistwostepprocess:Firstly,youdefinethejobandthenreleaseit.
Whenusersdefineajobandsaveit,theyareactuallyschedulingthereporti.e.,specifyingthejob
components,thesteps,thestarttime.
Whenusersscheduleprogramforbackgroundprocessing,theyareinstructingthesystemtoexecute
anABAP/4reportoranexternalprograminthebackground.Scheduledjobsarenotexecuteduntil
theyarereleased.Whenjobsarereleased,theyaresentforexecutiontothebackgroundprocessing
systematthespecifiedstarttime.Bothschedulingandreleasingofjobsrequireauthorizations.
HANDLINGOFPOPUPSCREENINBDC
Manytimesintransactionpopupscreenappearsandforthisscreenyoudontpassanyrecordbut
someindicationtosystemtellingittoproceedfurther.Forexample:Thefollowingscreen
Tohandlesuchscreen,systemhasprovidedavariablecalledBDC_CURSOR.Youpassthisvariable
toBDCDATAandprocessthescreen.
Usuallysuchscreenappearsinmanytransactions,inthiscaseyouarejustpassinginformation,that
YESyouwanttosavetheinformation,thatmeansYESshouldbeclicked.Soyouaretransferringthis
informationtoBDCDATAi.e.,fieldnameofYESwhichisusuallySPOT_OPTION.Insteadof
BDC_OKCODE,youarepassingBDC_CURSOR.
BDC_CURSORisalsousedtoplacecursoronparticularfield.
ANEXAMPLEWITHSESSIONMETHOD
FollowingprogramdemonstrateshowdataispassedfromflatfiletoSAPtransactionandfurtherto
databasetablebyusingSESSIONmethod.
ThetransactionisTFBA(tochangecustomer).
Asimpletransactionwhereyouareenteringcustomernumberonfirstscreenandonnextscreendata
isdisplayedfortheparticularcustomernumber.Field,whichwearechanginghere,arenameand
city.Whenyouclickonsave,thechangedrecordgetssaved.
PrerequisitetowritethisBDCinterfaceasindicatedearlieris:
1.Tofindscreennumber
2.Tofindscreenfieldnames,typeofthefieldandlengthofthefield.
3.TofindBDC_OKCODEforeachscreen
4.Createflatfile.
Flatfilecanbecreatedinyourharddiskasfollows:
1VinodKrishnaHyderabad
2KavithaSecunderabad
3KishoreHyderabad
(Where1stcharacterfieldisCustomernumber,2ndfieldisCustomernameand3rdfieldisCity.)
TotransferthisdatatodatabasetableSCUSTOMfollowinginterfacecanbeused.
REPORTDEMO1.
Followinginternaltableistouploadflatfile.
DATA:BEGINOFITABOCCURS0,
ID(10),
NAME(25),
CITY(25),
ENDOFITAB.
*FollowinginternaltableBDCDATAistopassdatefrominternaltabletosession.
DATA:BDCTABLIKEBDCDATAOCCURS0WITHHEADERLINE.
Variables
DATA:DATE1LIKESYDATUM.DATE1=SYDATUM1.ThisisforHoldDate
Touploadflatfiletointernaltable.
CALLFUNCTIONUPLOAD
EXPORTING
FILENAME=C:\FF.TXT
FILETYPE=ASC
TABLES
DATA_TAB=ITAB
EXCEPTIONS
CONVERSION_ERROR=1
INVALID_TABLE_WIDTH=2
INVALID_TYPE=3
NO_BATCH=4
UNKNOWN_ERROR=5
OTHERS=6.
Ifsysubrc=0.
CallingFunctiontoCreateaSession
CALLFUNCTIONBDC_OPEN_GROUP
EXPORTING
CLIENT=SYMANDT
GROUP=POTHURI
HOLDDATE=DATE1
KEEP=X
USER=SYUNAME
EXCEPTIONS
CLIENT_INVALID=1
DESTINATION_INVALID=2
GROUP_INVALID=3
GROUP_IS_LOCKED=4
HOLDDATE_INVALID=5
INTERNAL_ERROR=6
QUEUE_ERROR=7
RUNNING=8
SYSTEM_LOCK_ERROR=9
USER_INVALID=10
OTHERS=11.
Ifsysubrc=0.
*
MAINLogic
LOOPATITAB
PERFORMGENERATE_DATA.PopulatingBDCDATATable
CALLFUNCTIONBDC_INSERT
EXPORTING
TCODE=TFBA
TABLES
DYNPROTAB=BDCTAB
EXCEPTIONS
INTERNAL_ERROR=1
NOT_OPEN=2
QUEUE_ERROR=3
TCODE_INVALID=4
PRINTING_INVALID=5
POSTING_INVALID=6
OTHERS=7.
REFRESHBDCTAB
ENDLOOP.
Callingfunctiontoclosethesession
CALLFUNCTIONBDC_CLOSE_GROUP
EXCEPTIONS
NOT_OPEN=1
QUEUE_ERROR=2
OTHERS=3.
Endif.
Endif.
&
*&FormGENERATE_DATA
&
CreateBDCData
&
FORMGENERATE_DATA
Passinginformationfor1stscreenonBDCDATA
BDCTABPROGRAM=SAPMTFBA.
BDCTAXDYNPRO=100.
BDCTAPDYNBEGIN=X.
APPENDBCDTAB.CLEARBDCTAB.
PassingfieldinformationtoBDCDATA
BDCTABFNAM=SCUSTOMID
BDCTABFVAL=ITABID.
APPENDBDCTAB.CLEARBDCTAB.
PassingBDC_OKCODEtoBDCDATA
BDCTABFNAM=BDC_OKCODE.
BDCTABFVAL=/5.
APPENDBDCTAB.CLEARBDCTAB.
PassingscreeninformationfornextscreentoBDCDATA
BDCTABPROGRAM=SAPMTFBA.
BDCTABDYNPRO=200.
BDCTABDYNBEGIN=X.
APPENDBDCTAB.CLEARBDCTAB.
PassingscreeninformationtoBDCDATA
BDCTABFNAM=SCUSTOMNAME.
BDCTABFVAL=ITABNAME.
APPENDBDCTAB.CLEARBDCTAB.
PassingscreeninformationtoBDCDATA
BDCTABFNAM=SCUSTOMCITY.
BDCTABFVAL=ITABCITY.
APPENDBDCTAB.CLEARBDCTAB.
PassingBDC_OKCODEtoBDCDATA
BDCTABFNAM=BDC_OKCODE.
BDCTABFVAL=SAVE.
APPENDBDCTAB.CLEARBDCTAB.
ENDFORM.GENERATE_DATA
Messagewaseditedby:
SudhaRaniPathuri
Like(0)
GuestFeb29,201211:03AM (inresponsetoPrasadAkole)
Re:CreatingBDC
Hi
Purpose
BDCstandforBATCHDATACOMMUNICATION
ThroughthisconceptwetransferthedataintoSAPR/3System
LegacySystemR/3System
1)Batchinputisusedtotransferlargeamountsofdataintothe
SAPsystem.Inthistopic,wewilllearnthebasicsofbatchinput.
2)Thereare2typesoftransfersConversionsandinterfaces.
3)Conversions:ThistypeoftransferreferstoaonetimetransferfromalegacysystemtotheSAP
system.Inthiscase,thelegacysystemistheoldsystemthatisbeingreplacedbytheSAPsystem.
4)Interfaces:Thistypeoftransferreferstoanongoingtransferfromacomplementarysystemtothe
SAPsystem.Inthiscase,thecomplementarysystemisasystemthatwillrunalongsidetheSAP
system.
Use
Thisisusedforuploadingthemasterdataanddifferenttypeofapplicationdatafromlegacy
systemtoSAPR/3systemlikeas:
CreateVendorusingtransaction(FK01),
ChangeVendorusingtransaction(FK02)
Readingdatafromapplicationserverorpresentationserver
DialogProgram
Adialogprogramconductsadialogwiththeuser.Asaresultofuserinputtheprogramexecutes
whichinturndisplaysanoutputorchangesthedatabaseinaconsistentway.
Atransactioncodecanbeconnectedtodialogprogramwhichcallsthecorrespondingprogram
Structureofadialogprogram
Proceduralstepsindatamigration
1)Dataanalysis
2)GenarateSAPstructure
3)Developtransferprogram
4)Creatsequentialfile
5)Creatbatchinputprogram
6)Processbatchinputdata
7)Analyzeresults
8)Analyzeerrorsession
BDCDATAStructure
Tosimulateuserdialogue,youmustknowthefollowinginformation:
1.Onlineprogramname,
2.Screennumbers,
3.Fieldnames
4.Fieldvalues
TheBDCDATAABAPDictionarystructureisusedinabatchinputprogramtocollectthisinformation
foranentiretransaction.
BDCDATA
PROGRAM
DYNPRO
DYNBEGIN
FNAM
FVAL
ExampleChangeVendor
Forourexample,wewillusetheChangeVendortransaction(FK02)toaddastreetaddresstoan
alreadyexistingvendor.
ResearchingTransaction2ndScreen
Step#1
UseSystemStatusmenupathtodetermineonlineprogramname(SAPMF02K),screennumber
(0110)
Step#2
UseF1keyandTechnicalInfopushbuttonineachscreenfieldtobefilledtodeterminethefield
name.
Step#3
Determinehowtoproceedinthetransaction
(savetherecordbyclickingontheSavepushbuttonorpressingtheF11key).
BDCTableContents
AfterresearchingthetransactionwecandeterminethecontentsoftheBDCtable.
BatchInputMethods
METHOD#1
CALLTRANSACTIONUSING
STATEMENT
METHOD#2BATCHINPUTSESSION
METHOD#3DIRECTINPUT
Calltransactionfordatatransfer
ProcessingbatchinputdatawithCALLTRANSACTIONUSINGisthefasterofthetworecommended
datatransfermethods.Inthismethod,legacydataisprocessedinlineinyourdatatransferprogram.
Syntax:
CALLTRANSACTION0.
WRITE:/ERROR.
ENDIF.
ENDDO.
Errorhandling
Tostoreerrormessages(CALLTRANSACTION)
data:beginofTab_Messoccurs0.
includestructurebdcmsgcoll.
data:endofTab_Mess,
CALLTRANSACTIONFK02USINGBDC_TABMODENUPDATES
MESSAGESINTOTAB_MESS.
IFSYSUBRCNE0.
WRITE:/Tab_MESSTCODE,Tab_MESSDYNUMB,Tab_MESSMSGTYP,
Tab_MESSMSGID.
ENDIF.
rewardifusefull
Like(0)