0% found this document useful (0 votes)
99 views

Ale-Idoc Inbound FM

This document contains example code for processing IDocs in ABAP. It includes: 1) A main program that imports IDocs in mass, loops through each IDoc, calls subroutines to process the IDoc data and populate application tables, and inserts the application data into backend database tables. 2) A subroutine that interprets IDoc data fields and populates internal application header and item tables. It also checks the application object and returns a document number. 3) The code demonstrates mass processing of IDocs without serialization or calling transactions. It provides examples of internal table declarations, moving IDoc data to application tables, and filling return variables.

Uploaded by

Kumaresh Karar
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
99 views

Ale-Idoc Inbound FM

This document contains example code for processing IDocs in ABAP. It includes: 1) A main program that imports IDocs in mass, loops through each IDoc, calls subroutines to process the IDoc data and populate application tables, and inserts the application data into backend database tables. 2) A subroutine that interprets IDoc data fields and populates internal application header and item tables. It also checks the application object and returns a document number. 3) The code demonstrates mass processing of IDocs without serialization or calling transactions. It provides examples of internal table declarations, moving IDoc data to application tables, and filling return variables.

Uploaded by

Kumaresh Karar
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 34

Example Program for Mass Processing IDocs

FUNCTIONIDOC_INPUT_XAMPLE4.
*"---------------------------------------------------------------------*"
*"Localinterface:
*"IMPORTING
*"VALUE(INPUT_METHOD)LIKEBDWFAP_PAR-INPUTMETHD
*"VALUE(MASS_PROCESSING)LIKEBDWFAP_PAR-MASS_PROC
*"EXPORTING
*"VALUE(WORKFLOW_RESULT)LIKEBDWF_PARAM-RESULT
*"VALUE(APPLICATION_VARIABLE)LIKEBDWF_PARAM-APPL_VAR
*"VALUE(IN_UPDATE_TASK)LIKEBDWFAP_PAR-UPDATETASK
*"VALUE(CALL_TRANSACTION_DONE)LIKEBDWFAP_PAR-CALLTRANS
*"TABLES
*"IDOC_CONTRLSTRUCTUREEDIDC
*"IDOC_DATASTRUCTUREEDIDD
*"IDOC_STATUSSTRUCTUREBDIDOCSTAT
*"RETURN_VARIABLESSTRUCTUREBDWFRETVAR
*"SERIALIZATION_INFOSTRUCTUREBDI_SER
*"EXCEPTIONS
*"WRONG_FUNCTION_CALLED
*"---------------------------------------------------------------------*---------------------------------------------------------------------*----------------------05July1996---------------------------------*---------------------------------------------------------------------*ExamplefunctionmoduleforprocessinginboundIDocsforALEorEDI.
*Thisexampleappliesforprocessing
*
*with-massprocessing(morethanoneIDocatatime)
*
*without-serialization
*-customer-exits
*-callinganALE-enabledtransaction
*--------------------Namingconventions-----------------------------*Internaltablesstartwith't_'
*Internalfieldstringsstartwith'f_'
*---------------------------------------------------------------------*>>Thefollowinglinemustappearintheglobalpartofyour
*>>functiongroup:
*includembdconwf."ReportcontainingtheALEconstants.
*TheALEconstantsstartwith'c_'.
*Internaltableforthedocumentheaders.
DATA:T_XHEADLIKEXHEADOCCURS0WITHHEADERLINE.
*Internaltableforthedocumentitems.
DATA:T_XITEMLIKEXITEMOCCURS0WITHHEADERLINE.

DATA:SUBRCLIKESY-SUBRC,
OBJECT_NUMBERLIKEXHEAD-DOCMNT_NO.
*Initializevariables
SUBRC=0.
*FilltheALEexportparameterspriortoloopthroughIDocs.
CLEARIN_UPDATE_TASK.
CLEARCALL_TRANSACTION_DONE."CallTransactionisnotused.
WORKFLOW_RESULT=C_WF_RESULT_OK.
*LoopthroughtheIDocs'controlrecords
LOOPATIDOC_CONTRL.
*ProcesstheIDocandcheckthedata;nodatabaseupdates!
PERFORMIDOC_PROCESS_XAMPLE4TABLESIDOC_DATA
IDOC_STATUS
t_xhead
t_xitem
USINGIDOC_CONTRL
CHANGINGOBJECT_NUMBER
SUBRC.
*FilltheALEexportparameters.
IFSUBRC<>0."Erroroccurred
WORKFLOW_RESULT=C_WF_RESULT_ERROR.
RETURN_VARIABLES-WF_PARAM=C_WF_PAR_ERROR_IDOCS.
RETURN_VARIABLES-DOC_NUMBER=IDOC_CONTRL-DOCNUM.
APPENDRETURN_VARIABLES.
ELSE."IDocprocessedsuccessfully
RETURN_VARIABLES-WF_PARAM=C_WF_PAR_PROCESSED_IDOCS.
RETURN_VARIABLES-DOC_NUMBER=IDOC_CONTRL-DOCNUM.
APPENDRETURN_VARIABLES.
RETURN_VARIABLES-WF_PARAM=C_WF_PAR_APPL_OBJECTS.
RETURN_VARIABLES-DOC_NUMBER=OBJECT_NUMBER.
APPENDRETURN_VARIABLES.
ENDIF.
ENDLOOP. "loopatidoc_contrl.
*OnceallIDocshavebeenprocessed,inserttheapplicationdatato
*thedatabase(aslongasthereissomedatatoinsert).
readtablet_xitemindex1.
ifsy-subrc=0."i.e.atleastoneentry
*Thisfictitiousfunctionmoduleinsertsthedataintables
*t_xheadandt_xitemtothedatabasetablesxheadandxitem.
*Ithasnoexceptions,becauseafailedinsertleadstoarun-time
*error.
CALLFUNCTION'XAMPLE_OBJECTS_INSERT_TO_DATABASE'
TABLES

XHEAD=T_XHEAD
XITEM=T_XITEM.
endif."ifsy-subrc=0.
ENDFUNCTION.
*---------------------------------------------------------------------*
*FORMIDOC_PROCESS_XAMPLE4*
*---------------------------------------------------------------------*
*Thisroutineaddsanapplicationdocumenttotablest_xheadand*
*t_xitembasedontheIDoc'Scontents.*
*Object_Numbercontainsthenewdocument'snumber.*
*Ifanerroroccurs,subrcisnon-zero,t_idoc_statusisfilled.*
*Note:ifmorethanoneerrorisdetected,t_idoc_statuscontains*
*morethanonestatusrecord.*
*---------------------------------------------------------------------*
*-->F_IDOC_CONTRLIDoccontrolrecord*
*-->T_IDOC_DATAIDocdatarecords*
*<--T_XHEADApplicationdocument'sheaderrecords*
*<--T_XITEMApplicationdocument'slineitemrecords*
*<--T_IDOC_STATUSIDocstatusrecords*
*<--OBJECT_NUMBERCreateddocument'snumber*
*<--SUBRCReturncode*
*---------------------------------------------------------------------*
FORMIDOC_PROCESS_XAMPLE4
TABLEST_IDOC_DATASTRUCTUREEDIDD
T_IDOC_STATUSSTRUCTUREBDIDOCSTAT
T_XHEADSTRUCTUREXHEAD
T_XITEMSTRUCTUREXITEM
USINGF_IDOC_CONTRLSTRUCTUREEDIDC
CHANGINGOBJECT_NUMBERLIKEXHEAD-DOCMNT_NO
SUBRCLIKESY-SUBRC.
*Internaltablestringforthedocumentheaders.
DATA:F_XHEADLIKEXHEADOCCURS0WITHHEADERLINE.
*Internaltableforonedocument'sitems.
DATA:T_ONE_XITEMLIKEXITEMOCCURS0WITHHEADERLINE.
*Numbergiventothecreateddocument
DATA:DOCUMENT_NUMBERLIKEXHEAD-DOCMNT_NO.
*MovethedataintheIDoctotheinternalstructures/tables
*f_xheadandt_xitem.
PERFORMIDOC_INTERPRETTABLEST_IDOC_DATA
T_ONE_XITEM
T_IDOC_STATUS
USINGF_IDOC_CONTRL
CHANGINGF_XHEAD
SUBRC.
*Createtheapplicationobjectifnoerroroccurredsofar.
IFSUBRC=0.
*Thisfictitiousfunctionmodulechecksthenewobjectbasedonthe

*datathatwasreadfromtheIDoc.
*Ifthecheckssucceed, thenewobject'sIDisreturnedinthe
*parameter'document_number'.
*Ifthechecksfail,anexceptionisraised.
*Note:thisfunctionmustnotinsertormodifydatabaserecords!
CALLFUNCTION'XAMPLE_OBJECT_CHECK'
EXPORTING
XHEAD=F_XHEAD
IMPORTING
DOCUMENT_NUMBER=DOCUMENT_NUMBER
TABLES
XITEM=T_ONE_XITEM
EXCEPTIONS
OTHERS=1.
IFSY-SUBRC<>0.
SUBRC=1.
*Puttheerrormessageinto't_idoc_status'
PERFORMSTATUS_FILL_SY_ERROR
TABLEST_IDOC_STATUS
USINGT_IDOC_DATA
SY
''"Fieldname
'idoc_process_xample'."Formroutine
ELSE.
*Filltheremainingexportparameters
OBJECT_NUMBER=DOCUMENT_NUMBER."Newdocument'snumber
appendf_xheadtot_xhead.
APPENDLINESOFT_ONE_XITEMTOT_XITEM.
t_idoc_status-docnum=f_idoc_contrl-docnum.
t_idoc_status-status=c_idoc_status_ok.
t_idoc_status-msgty='S'.
t_idoc_status-msgid=your_msgid."Globalvariable.
t_idoc_status-msgno=msgno_success."Globalvariable.
t_idoc_status-msgv1=object_number.
APPENDT_IDOC_STATUS.
ENDIF."ifsy-subrc<>0.
ENDIF."ifsubrc=0.
ENDFORM.

Example Program for a Customer Exit


FUNCTIONIDOC_INPUT_XAMPLE3.
*"----------------------------------------------------------------------

*"
*"Localinterface:
*"IMPORTING
*"VALUE(INPUT_METHOD)LIKEBDWFAP_PAR-INPUTMETHD
*"VALUE(MASS_PROCESSING)LIKEBDWFAP_PAR-MASS_PROC
*"EXPORTING
*"VALUE(WORKFLOW_RESULT)LIKEBDWF_PARAM-RESULT
*"VALUE(APPLICATION_VARIABLE)LIKEBDWF_PARAM-APPL_VAR
*"VALUE(IN_UPDATE_TASK)LIKEBDWFAP_PAR-UPDATETASK
*"VALUE(CALL_TRANSACTION_DONE)LIKEBDWFAP_PAR-CALLTRANS
*"TABLES
*"IDOC_CONTRLSTRUCTUREEDIDC
*"IDOC_DATASTRUCTUREEDIDD
*"IDOC_STATUSSTRUCTUREBDIDOCSTAT
*"RETURN_VARIABLESSTRUCTUREBDWFRETVAR
*"SERIALIZATION_INFOSTRUCTUREBDI_SER
*"EXCEPTIONS
*"WRONG_FUNCTION_CALLED
*"---------------------------------------------------------------------*---------------------------------------------------------------------*---------------------------05July1996----------------------------*---------------------------------------------------------------------*ExamplefunctionmoduleforprocessinginboundIDocsforALEorEDI.
*Thisexampleappliesforprocessing
*
*with-oneIDocatatime
*-serialization
*-customer-exits
*
*without-callinganALE-enabledtransaction
*-massprocessing(morethanoneIDocatatime)
*--------------------Namingconventions-----------------------------*Internaltablesstartwith't_'
*Internalfieldstringsstartwith'f_'
*---------------------------------------------------------------------*>>Thefollowinglinemustappearintheglobalpartofyour
*>>functiongroup:
*includembdconwf."ReportcontainingtheALEconstants.
*TheALEconstantsstartwith'c_'.
DATA:SUBRCLIKESY-SUBRC,
OBJECT_NUMBERLIKEXHEAD-DOCMNT_NO.
*Initializevariables
SUBRC=0.
*ReadtheIDoc'scontrolrecord
READTABLEIDOC_CONTRLINDEX1.
*>>>>>>>>>>>>>Customerexit1(Start)<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
*ThisexitgivesthecustomeraccesstotheIDoc'scontrolrecord,
*theimportparametersandallowsthecustomertodoserialization.

CALLCUSTOMER-FUNCTION'001'
EXPORTING
INPUT_METHOD=INPUT_METHOD
MASS_PROCESSING=MASS_PROCESSING
TABLES
IDOC_SERIAL=SERIALIZATION_INFO
IDOC_DATA=IDOC_DATA
IDOC_CONTROL=IDOC_CONTRL
EXCEPTIONS
OTHERS=1.
IFSY-SUBRC<>0.
SUBRC=1.
PERFORMSTATUS_FILL_SY_ERRORTABLESIDOC_STATUS
USINGIDOC_DATA
SY
''
'customer-function001'.
ENDIF.
*>>>>>>>>>>>>>Customerexit1(End)<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
PERFORMIDOC_PROCESS_XAMPLE3TABLESIDOC_DATA
IDOC_STATUS
USINGIDOC_CONTRL
CHANGINGOBJECT_NUMBER
SUBRC.
*FilltheALEexportparameters
*Inthisexampleweassumethat'callfunction'xxx'inupdatetask'is
*notusedtoupdatethedatabase.
CLEARIN_UPDATE_TASK.
CLEARCALL_TRANSACTION_DONE."CallTransactionisnotused.
IFSUBRC<>0."Erroroccurred
WORKFLOW_RESULT=C_WF_RESULT_ERROR.
RETURN_VARIABLES-WF_PARAM=C_WF_PAR_ERROR_IDOCS.
RETURN_VARIABLES-DOC_NUMBER=IDOC_CONTRL-DOCNUM.
APPENDRETURN_VARIABLES.
ELSE."IDocprocessedsuccessfully
WORKFLOW_RESULT=C_WF_RESULT_OK.
RETURN_VARIABLES-WF_PARAM=C_WF_PAR_PROCESSED_IDOCS.
RETURN_VARIABLES-DOC_NUMBER=IDOC_CONTRL-DOCNUM.
APPENDRETURN_VARIABLES.
RETURN_VARIABLES-WF_PARAM=C_WF_PAR_APPL_OBJECTS.
RETURN_VARIABLES-DOC_NUMBER=OBJECT_NUMBER.
APPENDRETURN_VARIABLES.
ENDIF.
*>>>>>>>>>>>>>Customerexit3(Start)<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
*Thisexitgivesthecustomeraccesstotheexportparameters.
CALLCUSTOMER-FUNCTION'003'
EXPORTING

SUBRC=SUBRC
WORKFLOW_RESULT_IN=WORKFLOW_RESULT
APPLICATION_VARIABLE_IN=APPLICATION_VARIABLE
IN_UPDATE_TASK_IN=IN_UPDATE_TASK
IMPORTING
WORKFLOW_RESULT_OUT=WORKFLOW_RESULT
APPLICATION_VARIABLE_OUT=APPLICATION_VARIABLE
IN_UPDATE_TASK_OUT=IN_UPDATE_TASK
TABLES
RETURN_VARIABLES=RETURN_VARIABLES.
*>>>>>>>>>>>>>Customerexit3(End)<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
ENDFUNCTION.
*---------------------------------------------------------------------*
*FORMIDOC_PROCESS_XAMPLE3*
*---------------------------------------------------------------------*
*ThisroutinecreatesanapplicationdocumentbasedontheIDoc's*
*contents.Object_Numbercontainsthenewdocument'snumber.*
Ifanerroroccurs,subrcisnon-zero,t_idoc_statusisfilled.*
*Note:ifmorethanoneerrorisdetected,t_idoc_statuscontains*
*morethanonestatusrecord.*
*---------------------------------------------------------------------*
*-->F_IDOC_CONTRLIDoccontrolrecord*
*-->T_IDOC_DATAIDocdatarecords*
*<--T_IDOC_STATUSIDocstatusrecords*
*<--OBJECT_NUMBERCreateddocument'snumber*
*<--SUBRCReturncode*
*---------------------------------------------------------------------*
FORMIDOC_PROCESS_XAMPLE3
TABLEST_IDOC_DATASTRUCTUREEDIDD
T_IDOC_STATUSSTRUCTUREBDIDOCSTAT
USINGF_IDOC_CONTRLSTRUCTUREEDIDC
CHANGINGOBJECT_NUMBERLIKEXHEAD-DOCMNT_NO
SUBRCLIKESY-SUBRC.
*Internalfieldstringforthedocumentheader.
DATA:F_XHEADLIKEXHEAD.
*Internaltableforthedocumentitems.
DATA:T_XITEMLIKEXITEMOCCURS0WITHHEADERLINE.
*Numbergiventothecreateddocument
DATA:DOCUMENT_NUMBERLIKEF_XHEAD-DOCMNT_NO.
*MovethedataintheIDoctotheinternalstructures/tables
*f_xheadandt_xitem.
PERFORMIDOC_INTERPRET3TABLEST_IDOC_DATA
T_XITEM
T_IDOC_STATUS
USINGF_IDOC_CONTRL
CHANGINGF_XHEAD
SUBRC.

*Createtheapplicationobjectifnoerroroccurredsofar.
IFSUBRC=0.
*Thisfictitiousfunctionmodulecreatesanewobjectbasedonthe
*datathatwasreadfromtheIDoc.Thenewobject'sIDisreturned
*intheparameter'document_number'.
*Thefunctionmodulechecksthatthedataiscorrect,andraises
*anexceptionifanerrorisdetected.
CALLFUNCTION'XAMPLE_OBJECT_CREATE'
EXPORTING
XHEAD=F_XHEAD
IMPORTING
DOCUMENT_NUMBER=DOCUMENT_NUMBER
TABLES
XITEM=T_XITEM
EXCEPTIONS
OTHERS=1.
IFSY-SUBRC<>0.
SUBRC=1.
*Puttheerrormessageinto't_idoc_status'
PERFORMSTATUS_FILL_SY_ERROR
TABLEST_IDOC_STATUS
USINGT_IDOC_DATA
SY
''"Fieldname
'idoc_process_xample'."Formroutine
ELSE.
*Filltheremainingexportparameters
OBJECT_NUMBER=DOCUMENT_NUMBER."Newdocument'snumber
t_idoc_status-docnum=f_idoc_contrl-docnum.
t_idoc_status-status=c_idoc_status_ok.
t_idoc_status-msgty='S'.
t_idoc_status-msgid=your_msgid."Globalvariable.
t_idoc_status-msgno=msgno_success."Globalvariable.
t_idoc_status-msgv1=object_number.
APPENDT_IDOC_STATUS.
ENDIF."ifsy-subrc<>0.
ENDIF."ifsubrc=0.
ENDFORM.
*---------------------------------------------------------------------*
*FORMIDOC_INTERPRET3*
*---------------------------------------------------------------------*
*Thisroutinechecksthatthecorrectmessagetypeisbeingused,*
*thenchecksthattheIDochasnotbeenovertaken(serialization),*
*andthenconvertsandmovesthedatafromtheIDocsegmentstothe*
*internalstructuref_xheadandinternaltablet_xitem.*
*Ifanerroroccurs,t_idoc_statusisfilledansubrc<>0.*
*---------------------------------------------------------------------*
*-->T_IDOC_STATUS*
*-->T_XITEM*
*-->F_IDOC_DATA*
*-->F_XHEAD*

*-->SUBRC*
*---------------------------------------------------------------------*
FORMIDOC_INTERPRET3TABLEST_IDOC_DATASTRUCTUREEDIDD
T_XITEMSTRUCTUREXITEM
T_IDOC_STATUSSTRUCTUREBDIDOCSTAT
USINGF_IDOC_CONTRLSTRUCTUREEDIDC
CHANGINGF_XHEADSTRUCTUREXHEAD
SUBRCLIKESY-SUBRC.
*CheckthattheIDoccontainsthecorrectmessagetype.
*Note:ifyourmessagetypeisreducible,checkfield'idoctp'
*(IDoctype)insteadof'mestyp'.
IFF_IDOC_CONTRL-MESTYP<>'XAMPLE'.
MESSAGEIDYOUR_MSGID"Globalvariable
TYPE'E'
NUMBERMSGNO_WRONG_FUNCTION"Globalvariable
WITHF_IDOC_CONTRL-MESTYP"messagetype
'IDOC_INPUT_XAMPLE'"Yourfunctionmodule.
F_IDOC_CONTRL-SNDPRT"Senderpartnertype
F_IDOC_CONTRL-SNDPRN"Sendernumber.
RAISINGWRONG_FUNCTION_CALLED.
ENDIF.
*LoopthroughtheIDoc'ssegmentsandconvertthedatafromtheIDoc
*formattotheinternalformat.
LOOPATT_IDOC_DATAWHEREDOCNUM=F_IDOC_CONTRL-DOCNUM.
CASET_IDOC_DATA-SEGNAM.
WHEN'E1XHEAD'.
PERFORME1XHEAD_PROCESSTABLEST_IDOC_STATUS
USINGT_IDOC_DATA
CHANGINGF_XHEAD
SUBRC.
WHEN'E1XITEM'.
PERFORME1XITEM_PROCESSTABLEST_XITEM
T_IDOC_STATUS
USINGF_XHEAD-CURRENCY
T_IDOC_DATA
CHANGINGSUBRC.
ENDCASE.
*>>>>>>>>>>>>>Customerexit2(Start)<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
*ThisexitiscalledaftereachSAPsegmenthasbeenprocessed,and
*itiscalledeverytimeacustomersegmentappears.
CALLCUSTOMER-FUNCTION'002'
EXPORTING
CURRENT_SEGEMENT=T_IDOC_DATA
XHEAD_IN=F_XHEAD
SUBRC_IN=SUBRC
IMPORTING
XHEAD_OUT=F_XHEAD

TABLES
XITEM=T_XITEM
EXCEPTIONS
OTHERS=1.
IFSY-SUBRC<>0.
SUBRC=1.
PERFORMSTATUS_FILL_SY_ERRORTABLEST_IDOC_STATUS
USINGT_IDOC_DATA
SY
''
'customer-function001'.
ENDIF.
*>>>>>>>>>>>>>Customerexit2(End)<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
ENDLOOP.
ENDFORM.

Example Program to Process an IDoc


FUNCTIONIDOC_INPUT_XAMPLE.
*"--------------------------------------------------------------------*"
*"Localinterface:
*"IMPORTING
*"VALUE(INPUT_METHOD)LIKEBDWFAP_PARINPUTMETHD
*"VALUE(MASS_PROCESSING)LIKEBDWFAP_PARMASS_PROC
*"EXPORTING
*"VALUE(WORKFLOW_RESULT)LIKEBDWF_PARAMRESULT
*"VALUE(APPLICATION_VARIABLE)LIKEBDWF_PARAM
-APPL_VAR
*"VALUE(IN_UPDATE_TASK)LIKEBDWFAP_PARUPDATETASK
*"VALUE(CALL_TRANSACTION_DONE)LIKEBDWFAP_PA
R-CALLTRANS
*"TABLES
*"IDOC_CONTRLSTRUCTUREEDIDC
*"IDOC_DATASTRUCTUREEDIDD
*"IDOC_STATUSSTRUCTUREBDIDOCSTAT
*"RETURN_VARIABLESSTRUCTUREBDWFRETVAR

*"SERIALIZATION_INFOSTRUCTUREBDI_SER
*"EXCEPTIONS
*"WRONG_FUNCTION_CALLED
*"--------------------------------------------------------------------*--------------------------------------------------------------------*---------------------05July1996---------------------------------*--------------------------------------------------------------------*ExamplefunctionmoduleforprocessinginboundIDocsfor
ALEorEDI.
*Thisexampleappliesforprocessing
*
*with-oneIDocatatime
*
*without-serialization
*-customer-exits
*-callinganALE-enabledtransaction
*massprocessing(morethanoneIDocatatime)
*-------------------Namingconventions-----------------------------*Internaltablesstartwith't_'
*Internalfieldstringsstartwith'f_'
*--------------------------------------------------------------------*>>Thefollowinglinemustappearintheglobalpartofy
our
*>>functiongroup:
*includembdconwf."ReportcontainingtheAL
Econstants.
*TheALEconstantsstartwith'c_'.
DATA:SUBRCLIKESY-SUBRC,
OBJECT_NUMBERLIKEXHEAD-DOCMNT_NO.
*Initializevariables
SUBRC=0.
*ReadtheIDoc'scontrolrecord

READTABLEIDOC_CONTRLINDEX1.
*ProcesstheIDocandpostthedatatothedatabase
PERFORMIDOC_PROCESS_XAMPLETABLESIDOC_DATA
IDOC_STATUS
USINGIDOC_CONTRL
CHANGINGOBJECT_NUMBER
SUBRC.
*FilltheALEexportparameters
CLEARIN_UPDATE_TASK.
CLEARCALL_TRANSACTION_DONE."CallTransactionis
notused.
IFSUBRC<>0."Erroroccurred
WORKFLOW_RESULT=C_WF_RESULT_ERROR.
RETURN_VARIABLES-WF_PARAM=C_WF_PAR_ERROR_IDOCS.
RETURN_VARIABLES-DOC_NUMBER=IDOC_CONTRL-DOCNUM.
APPENDRETURN_VARIABLES.
ELSE."IDocprocessedsucc
essfully
WORKFLOW_RESULT=C_WF_RESULT_OK.
RETURN_VARIABLES-WF_PARAM=C_WF_PAR_PROCESSED_IDOCS.
RETURN_VARIABLES-DOC_NUMBER=IDOC_CONTRL-DOCNUM.
APPENDRETURN_VARIABLES.
RETURN_VARIABLES-WF_PARAM=C_WF_PAR_APPL_OBJECTS.
RETURN_VARIABLES-DOC_NUMBER=OBJECT_NUMBER.
APPENDRETURN_VARIABLES.
ELSE.
ENDFUNCTION.
*--------------------------------------------------------------------*
*FORMIDOC_PROCESS_XAMPLE
*
*--------------------------------------------------------------------*
*Thisroutinecreatesanapplicationdocumentbasedonth
eIDoc's*
*contents.Object_Numbercontainsthenewdocument'snumb
er.*Ifanerroroccurs,subrcisnon-

zero,t_idoc_statusisfilled.*Note:ifmorethanon
eerrorisdetected,t_idoc_statuscontains*
*morethanonestatusrecord.
*
*--------------------------------------------------------------------*
*->F_IDOC_CONTRLIDoccontrolrecord
*
*->T_IDOC_DATAIDocdatarecords
*
*<-T_IDOC_STATUSIDocstatusrecords
*
*<-OBJECT_NUMBERCreateddocument'snumber
*
*<-SUBRCReturncode
*
*--------------------------------------------------------------------*
FORMIDOC_PROCESS_XAMPLE
TABLEST_IDOC_DATASTRUCTUREEDIDD
T_IDOC_STATUSSTRUCTUREBDIDOCSTAT
USINGF_IDOC_CONTRLSTRUCTUREEDIDC
CHANGINGOBJECT_NUMBERLIKEXHEAD-DOCMNT_NO
SUBRCLIKESY-SUBRC.
*Internalfieldstringforthedocumentheader.
DATA:F_XHEADLIKEXHEAD.
*Internaltableforthedocumentitems.
DATA:T_XITEMLIKEXITEMOCCURS0WITHHEADERLINE.
*NumbergiventothecreateddocumentDOCUMENT_NUMBERLIKE
F_XHEAD-DOCMNT_NO.
*MovethedataintheIDoctotheinternalstructures/tabl
es
*f_xheadandt_xitem.
PERFORMIDOC_INTERPRETTABLEST_IDOC_DATA
T_XITEM
T_IDOC_STATUS
USINGF_IDOC_CONTRL

CHANGINGF_XHEAD
SUBRC.
*Createtheapplicationobjectifnoerroroccurredsofar.
IFSUBRC=0.
*Thisfictitiousfunctionmodulecreatesanewobjectba
sedonthe
*datathatwasreadfromtheIDoc.Thenewobject'sIDi
sreturned
*intheparameter'document_number'.
*Thefunctionmodulechecksthatthedataiscorrect,an
draises
*anexceptionifanerrorisdetected.
CALLFUNCTION'XAMPLE_OBJECT_CREATE'
EXPORTING
XHEAD=F_XHEAD
IMPORTING
DOCUMENT_NUMBER=DOCUMENT_NUMBER
TABLES
XITEM=T_XITEM
EXCEPTIONS
OTHERS=1.
IFSY-SUBRC<>0.
SUBRC=1.
*Puttheerrormessageinto't_idoc_status'
PERFORMSTATUS_FILL_SY_ERROR
TABLEST_IDOC_STATUS
USINGT_IDOC_DATA
SY
''"Fieldname
'idoc_process_xample'."Fo
rmroutine
ELSE.
*Filltheremainingexportparameters
OBJECT_NUMBER=DOCUMENT_NUMBER."Newdocume
nt'snumber
t_idoc_status-docnum=f_idoc_contrl-docnum.
t_idoc_status-status=c_idoc_status_ok.
t_idoc_status-msgty='S'.
t_idoc_status-msgid=your_msgid."Globalvariable.
t_idoc_status-msgno=msgno_success."Globalvariable.
t_idoc_status-msgv1=object_number.
APPENDT_IDOC_STATUS.
ENDIF."ifsy-subrc<>0.

ENDIF."ifsubrc=0.
ENDFORM.
*--------------------------------------------------------------------*
*FORMIDOC_INTERPRET
*
*--------------------------------------------------------------------*
*Thisroutinechecksthatthecorrectmessagetypeisbei
ngused,*
*andthenconvertsandmovesthedatafromtheIDocsegme
ntstothe*
*internalstructuref_xheadandinternaltablet_xitem.
*
*Ifanerroroccurs,t_idoc_statusisfilledansubrc<>
0.*
*--------------------------------------------------------------------*
*->T_IDOC_STATUS
*
*->T_XITEM
*
*->F_IDOC_DATA
*
*->F_XHEAD
*
*->SUBRC
*
*--------------------------------------------------------------------*
FORMIDOC_INTERPRETTABLEST_IDOC_DATASTRUCTUREEDIDD
T_XITEMSTRUCTUREXITEM
T_IDOC_STATUSSTRUCTUREBDIDO
CSTAT
USINGF_IDOC_CONTRLSTRUCTUREEDIDC
CHANGINGF_XHEADSTRUCTUREXHEAD
SUBRCLIKESY-SUBRC.
*CheckthattheIDoccontainsthecorrectmessagetype.

*Note:ifyourmessagetypeisreducible,checkfield'id
octp'
*(IDoctype)insteadof'mestyp'.
IFF_IDOC_CONTRL-MESTYP<>'XAMPLE'.
MESSAGEIDYOUR_MSGID"Globalvariab
le
TYPE'E'
NUMBERMSGNO_WRONG_FUNCTION"Globalvariab
le
WITHF_IDOC_CONTRL-MESTYP"messagetype
'IDOC_INPUT_XAMPLE'"Yourfunction
module.
F_IDOC_CONTRLSNDPRT"Senderpartnertype
F_IDOC_CONTRL-SNDPRN"Sendernumber.
RAISINGWRONG_FUNCTION_CALLED.
ENDIF.
*LoopthroughtheIDoc'ssegmentsandconvertthedatafro
mtheIDoc
*formattotheinternalformat.
LOOPATT_IDOC_DATAWHEREDOCNUM=F_IDOC_CONTRL-DOCNUM.
CASET_IDOC_DATA-SEGNAM.
WHEN'E1XHEAD'.
PERFORME1XHEAD_PROCESSTABLEST_IDOC_STATUS
USINGT_IDOC_DATA
CHANGINGF_XHEAD
SUBRC.
WHEN'E1XITEM'.
PERFORME1XITEM_PROCESSTABLEST_XITEM
T_IDOC_STATUS
USINGF_XHEAD-CURRENCY
T_IDOC_DATA
CHANGINGSUBRC.
ENDCASE.
ENDLOOP.
ENDFORM.

*--------------------------------------------------------------------*
*FORME1XHEAD_PROCESS
*
*--------------------------------------------------------------------*
*Thisroutinefills'f_xhead'outofsegmente1xhead.
*Ifanerroroccurs,subrcisnonzero,t_idoc_statusisfilled.*
*--------------------------------------------------------------------*
*->F_IDOC_DATAIDocsegmentcontaininge1xheadfields
*
*<-F_XHEADInternalstructurecontainingdoc.head
er*
*<-T_IDOC_STATUSStatusfieldsforerrorhandling
*
*<--SUBRCReturncode:nonzeroifanerroroccurred*
*--------------------------------------------------------------------*
FORME1XHEAD_PROCESSTABLEST_IDOC_STATUSSTRUCTUREBDID
OCSTAT
USINGF_IDOC_DATASTRUCTUREEDIDD
CHANGINGF_XHEADSTRUCTUREXHEAD
SUBRCLIKESY-SUBRC.
DATA:F_E1XHEADLIKEE1XHEAD.
F_E1XHEAD=F_IDOC_DATA-SDATA.
*ProcessfieldsthatneedconversionfromISOcodestoSAP-codes
PERFORME1XHEAD_CODES_ISO_TO_SAP
TABLEST_IDOC_STATUS
USINGF_E1XHEAD
F_IDOC_DATA
CHANGINGF_XHEAD
SUBRC.
*Processfieldscontainingdatesortimes
PERFORME1XHEAD_DATE_TIMEUSINGF_E1XHEAD
CHANGINGF_XHEAD.

ENDFORM."e1xhead_process
*--------------------------------------------------------------------*
*FORME1XITEM_PROCESS
*
*--------------------------------------------------------------------*
*Thisroutineconvertsthedatainthesegment'e1xitem'
for*
*totheformatoftable't_xitem'andappendsittothet
able.*Ifanerroroccurs,subrcisnonzero,t_idoc_statusisfilled.*
*--------------------------------------------------------------------*
*->F_IDOC_DATAIDocsegment
*
*<-T_XITEMDocumentitemstobeupdatedtodatabase
*
*<-T_IDOC_STATUSStatusfieldsfilledifanerroroccurre
d*
*<-SUBRCReturncode:0ifallOK
*
*--------------------------------------------------------------------*
FORME1XITEM_PROCESSTABLEST_XITEMSTRUCTUREXITEM
T_IDOC_STATUSSTRUCTUREBDIDO
CSTAT
USINGCURRENCYLIKEXHEADCURRENCY
F_IDOC_DATASTRUCTUREEDIDD
CHANGINGSUBRCLIKESY-SUBRC.
DATA:F_E1XITEMLIKEE1XITEM.
F_E1XITEM=F_IDOC_DATA-SDATA.
*FieldsoftypeCHAR,NUMC,QUANneednoconversion.
T_XITEM-ITEM_NO=F_E1XITEM-ITEM_NO.
T_XITEM-MATERIALID=F_E1XITEM-MATERIALID.

T_XITEM-DESCRIPT=F_E1XITEM-DESCRIPT.
T_XITEM-QUANTITY=F_E1XITEM-QUANTITY.
*ProcessfieldsthatneedconversionfromISOcodestoSAP-codes
PERFORME1XHEAD_CODES_ISO_TO_SAP
TABLEST_IDOC_STATUS
USINGF_E1XHEAD
F_IDOC_DATA
CHANGINGF_XHEAD
SUBRC.
*Processfieldsthatcontainmonetaryvalues
PERFORME1XITEM_VALUE_IDOC_TO_SAPTABLEST_IDOC_STATUS
USINGF_E1XITEM
CURRENCY
F_IDOC_DATA
CHANGINGT_XITEM
SUBRC.
APPENDT_XITEM.
ENDFORM.
*--------------------------------------------------------------------*
*FORME1XHEAD_CODES_ISO_TO_SAP
*
*--------------------------------------------------------------------*
*ConvertsISO-Codesinf_e1xheadtoSAPcodesinf_xhead.*f_idoc_data,t_idoc_statusa
ndsubrcareusedforerrorhandling.*
*--------------------------------------------------------------------*
FORME1XHEAD_CODES_ISO_TO_SAP
TABLEST_IDOC_STATUSSTRUCTUREBDIDOCSTAT
USINGF_E1XHEADSTRUCTUREE1XHEAD
F_IDOC_DATASTRUCTUREEDIDD
CHANGINGF_XHEADSTRUCTUREXHEAD
SUBRC.
*f_xhead-currencyTypeCUKY=>convertISO-CodetoSAPCode.
PERFORMCURRENCY_CODE_ISO_TO_SAP
TABLEST_IDOC_STATUS
USINGF_E1XHEAD-CURRENCY

F_IDOC_DATA
'CURRENCY'
CHANGINGF_XHEAD-CURRENCY
SUBRC.
CHECKSUBRC=0.
*f_xheadcountryContainsacountry=>convertfromISOtoSAPcod
e.
PERFORMCOUNTRY_CODE_ISO_TO_SAP
TABLEST_IDOC_STATUS
USINGF_E1XHEAD-COUNTRY
F_IDOC_DATA
'COUNTRY'
CHANGINGF_XHEAD-COUNTRY
SUBRC.
ENDFORM.
*--------------------------------------------------------------------*
*FORME1XITEM_CODES_ISO_TO_SAP
*
*--------------------------------------------------------------------*
*ConvertsISO-Codesinf_e1xitemtoSAPcodesinf_xitem*
*f_idoc_data,t_idoc_statusandsubrcareusedforerror
handling.*
*--------------------------------------------------------------------*
FORME1XITEM_CODES_ISO_TO_SAP
TABLEST_IDOC_STATUSSTRUCTUREBDIDOCSTAT
USINGF_E1XITEMSTRUCTUREE1XITEM
F_IDOC_DATASTRUCTUREEDIDD
CHANGINGF_XITEMSTRUCTUREXITEM
SUBRCLIKESY-SUBRC.
*f_xitem-unitTypeUNIT=>convertISO-CodetoSAPCode.
PERFORMUNIT_OF_MEASURE_ISO_TO_SAP
TABLEST_IDOC_STATUS
USINGF_E1XITEM-UNIT
F_IDOC_DATA
'unit'
CHANGINGF_XITEM-UNIT

SUBRC.
*f_xitemship_instContainsshippinginstructions=>ISOtoSAPcod
e.
PERFORMSHIPPING_INSTRUCT_ISO_TO_SAP
TABLEST_IDOC_STATUS
USINGF_E1XITEM-SHIP_INST
F_IDOC_DATA
'ship_inst'
CHANGINGF_XITEM-SHIP_INST
SUBRC.
ENDFORM.
*--------------------------------------------------------------------*
*FORME1XITEM_VALUE_IDOC_TO_SAP
*
*--------------------------------------------------------------------*
*Convertsfieldscontainingmonetaryvaluesinf_e1xitem
to*
*theinternalrepresentationinf_xitem.
*f_idoc_data,t_idoc_statusandsubrcareused
forerrorhandling.*
*--------------------------------------------------------------------*
FORME1XITEM_VALUE_IDOC_TO_SAP
TABLEST_IDOC_STATUSSTRUCTUREBDIDOCSTAT
USINGF_E1XITEMSTRUCTUREE1XITEM
CURRENCYLIKEXHEAD-CURRENCY
F_IDOC_DATASTRUCTUREEDIDD
CHANGINGF_XITEMSTRUCTUREXITEM
SUBRCLIKESY-SUBRC.
*f_xitemvalueTypeCURR=>convertIDocamounttointernalamoun
t.
*N.B.thecurrencycodeusedheremustbetheSAPinternalone,not
*theonecontainedintheIDoc!
CALLFUNCTION'CURRENCY_AMOUNT_IDOC_TO_SAP'
EXPORTING
CURRENCY=CURRENCY
IDOC_AMOUNT=F_E1XITEM-VALUE

IMPORTING
SAP_AMOUNT=F_XITEM-VALUE
EXCEPTIONS
OTHERS=1.
IFSY-SUBRC<>0.
SUBRC=1.
*Puttheerrormessageinto't_idoc_status'
PERFORMSTATUS_FILL_SY_ERROR
TABLEST_IDOC_STATUS
USINGF_IDOC_DATA
SY
'value'"Fieldname
'e1xitem_value_idoc_to_sap'."F
ormroutine
ENDIF."ifsy-subrc<>0.
ENDFORM.
*--------------------------------------------------------------------*
*FORME1XHEAD_DATE_TIME
*
*--------------------------------------------------------------------*
*Movesdateandtimefieldsinf_e1xheadtothefieldsin
f_xhead.*
*--------------------------------------------------------------------*
FORME1XHEAD_DATE_TIMEUSINGF_E1XHEADSTRUCTUREE1XHEAD
CHANGINGF_XHEADSTRUCTUREXHEAD.
*f_xhead-dateTypeDATS=>initialvalueisnot'blank'.
IFE1XHEAD-DATEISINITIAL.
CLEARF_XHEAD-DATE.
F_XHEAD-DATE=F_E1XHEAD-DATE.
ENDIF.
ENDFORM.
*--------------------------------------------------------------------*
*FORMCURRENCY_CODE_ISO_TO_SAP
*
*----------------------------------------------------------

-----------*
*ConvertsISOcurrencycode'iso_currency_code'toSAPco
dein*
*'sap_currency_code'
*
*f_idoc_data,field_name,t_idoc_statusandsubrcareuse
dfor*
*forerrorhandling.
*
*--------------------------------------------------------------------*
FORMCURRENCY_CODE_ISO_TO_SAP
TABLEST_IDOC_STATUSSTRUCTUREBDIDOCSTAT
USINGISO_CURRENCY_CODELIKETCURC-ISOCD
F_IDOC_DATASTRUCTUREEDIDD
FIELD_NAMELIKEBDIDOCSTAT-SEGFLD
CHANGINGSAP_CURRENCY_CODELIKETCURC-WAERS
SUBRCLIKESY-SUBRC.
IFISO_CURRENCY_CODEISINITIAL.
CLEARSAP_CURRENCY_CODE.
ELSE.
CALLFUNCTION'CURRENCY_CODE_ISO_TO_SAP'
EXPORTING
ISO_CODE=ISO_CURRENCY_CODE
IMPORTING
SAP_CODE=SAP_CURRENCY_CODE
EXCEPTIONS
OTHERS=1.
IFSY-SUBRC<>0.
SUBRC=1.
*Puttheerrormessageinto't_idoc_status'
PERFORMSTATUS_FILL_SY_ERROR
TABLEST_IDOC_STATUS
USINGF_IDOC_DATA
SY
FIELD_NAME
'currency_code_iso_to_sap'."F
ormroutine
ENDIF."ifsy-subrc<>0.
ENDIF."ifiso_currency_cod
eisinitial.
ENDFORM.

*--------------------------------------------------------------------*
*FORMCURRENCY_CODE_ISO_TO_SAP
*
*--------------------------------------------------------------------*
*ConvertsISOcurrencycode'iso_currency_code'toSAPco
dein*
*'sap_currency_code'
*
*f_idoc_data,field_name,t_idoc_statusandsubrcareuse
dfor*
*forerrorhandling.
*
*--------------------------------------------------------------------*
FORMCOUNTRY_CODE_ISO_TO_SAP
TABLEST_IDOC_STATUSSTRUCTUREBDIDOCSTAT
USINGISO_COUNTRY_CODELIKET005-INTCA
F_IDOC_DATASTRUCTUREEDIDD
FIELD_NAMELIKEBDIDOCSTAT-SEGFLD
CHANGINGSAP_COUNTRY_CODELIKET005-LAND1
SUBRCLIKESY-SUBRC.
*Onlyconvertifthefieldisnotinitial.
IFISO_COUNTRY_CODEISINITIAL.
CLEARSAP_COUNTRY_CODE.
ELSE.
CALLFUNCTION'COUNTRY_CODE_ISO_TO_SAP'
EXPORTING
ISO_CODE=ISO_COUNTRY_CODE
IMPORTING
SAP_CODE=SAP_COUNTRY_CODE
EXCEPTIONS
OTHERS=1.
IFSY-SUBRC<>0.
SUBRC=1.
*Puttheerrormessageinto't_idoc_status'
PERFORMSTATUS_FILL_SY_ERROR
TABLEST_IDOC_STATUS
USINGF_IDOC_DATA
SY
FIELD_NAME
'country_code_iso_to_sap'."F
ormroutine

ENDIF."ifsy-subrc<>0.
ENDIF."ifiso_country_code
isinitial.
ENDFORM.
*--------------------------------------------------------------------*
*FORMUNIT_OF_MEASURE_ISO_TO_SAP
*
*--------------------------------------------------------------------*
*ConvertsISOunitofmeasurecode'iso_unit_of_measure'
toSAP*
*codein'sap_unit_of_measure'.
*
*f_idoc_data,field_name,t_idoc_statusandsubrcareuse
dfor*
*forerrorhandling.
*
*--------------------------------------------------------------------*
FORMUNIT_OF_MEASURE_ISO_TO_SAP
TABLEST_IDOC_STATUSSTRUCTUREBDIDOCSTAT
USINGISO_UNIT_OF_MEASURELIKET006-ISOCODE
F_IDOC_DATASTRUCTUREEDIDD
FIELD_NAMELIKEBDIDOCSTAT-SEGFLD
CHANGINGSAP_UNIT_OF_MEASURELIKET006-MSEHI
SUBRCLIKESY-SUBRC.
*Onlyconvertthefieldifitisnotempty.
IFISO_UNIT_OF_MEASUREISINITIAL.
CLEARSAP_UNIT_OF_MEASURE.
ELSE.
CALLFUNCTION'UNIT_OF_MEASURE_ISO_TO_SAP'
EXPORTING
ISO_CODE=ISO_UNIT_OF_MEASURE
IMPORTING
SAP_CODE=SAP_UNIT_OF_MEASURE
EXCEPTIONS
OTHERS=1.
IFSY-SUBRC<>0.
SUBRC=1.
*Puttheerrormessageinto't_idoc_status'
PERFORMSTATUS_FILL_SY_ERROR

TABLEST_IDOC_STATUS
USINGF_IDOC_DATA
SY
FIELD_NAME
'unit_of_measure_iso_to_sap'."Fo
rmroutine
ENDIF."ifsy-subrc<>0.
ENDIF."ifiso_unit_of_measure_codeisi
nitial.
ENDFORM.
*--------------------------------------------------------------------*
*FORMSHIPPING_INSTRUCT_ISO_TO_SAP
*
*--------------------------------------------------------------------*
*ConvertsISOpackagecode'iso_package_type'toSAPcode
for*
*purchasingshippinginstructionsin'sap_shipping_instru
ctions'.*
*f_idoc_data,field_name,t_idoc_statusandsubrcareuse
dfor*
*forerrorhandling.
*
*--------------------------------------------------------------------*
FORMSHIPPING_INSTRUCT_ISO_TO_SAP
TABLEST_IDOC_STATUSSTRUCTUREBDIDOCS
TAT
USINGISO_PACKAGE_TYPELIKET027A-IVERS
F_IDOC_DATASTRUCTUREEDIDD
FIELD_NAMELIKEBDIDOCSTATSEGFLD
CHANGINGSAP_SHIPPING_INSTRUCTIONSLIKET027A-EVERS
SUBRCLIKESY-SUBRC.
*Onlyconvertthefieldifitisnotempty.
IFISO_PACKAGE_TYPEISINITIAL.
CLEARSAP_SHIPPING_INSTRUCTIONS.
ELSE.
CALLFUNCTION'ISO_TO_SAP_PACKAGE_TYPE_CODE'
EXPORTING
ISO_CODE=ISO_PACKAGE_TYPE
IMPORTING

SAP_CODE=SAP_SHIPPING_INSTRUCTIONS
EXCEPTIONS
OTHERS=1.
IFSY-SUBRC<>0.
SUBRC=1.
*Puttheerrormessageinto't_idoc_status'
PERFORMSTATUS_FILL_SY_ERROR
TABLEST_IDOC_STATUS
USINGF_IDOC_DATA
SY
FIELD_NAME
'shipping_instruct_iso_to_sap'."F
ormrout.
ENDIF."ifsy-subrc<>0.
ENDIF."ifiso_unit_of_measure_codeisi
nitial.
ENDFORM.
*--------------------------------------------------------------------*
*FORMSTATUS_FILL_SY_ERROR
*
*--------------------------------------------------------------------*
*Fillsthestructuret_idoc_statuswiththeimportparame
ters*
*plustherelevantsyfields.
*
*--------------------------------------------------------------------*
*->IDOC_NUMBERIDocnumber
*
*->SEGNUMSegmentnumber
*
*->SEGFLDFieldinsegment
*
*->ROUTIDNameofroutine
*
*<--

T_IDOC_STATUSStatusfields
*
*--------------------------------------------------------------------*
FORMSTATUS_FILL_SY_ERRORTABLEST_IDOC_STATUSSTRUCTURE
BDIDOCSTAT
USINGF_IDOC_DATASTRUCTURE
EDIDD
VALUE(F_SY)STRUCTURE
SY
SEGFLDLIKEBDIDO
CSTAT-SEGFLD
ROUTIDLIKEBDIDO
CSTAT-ROUTID.
t_idoc_status-docnum=f_idoc_data-docnum.
t_idoc_status-status=c_idoc_status_error.
t_idoc_status-msgty=f_sy-msgty.
t_idoc_status-msgid=f_sy-msgid.
T_IDOC_STATUS-MSGNO=F_SY-MSGNO.
t_idoc_status-msgv1=f_sy-msgv1.
t_idoc_status-msgv2=f_sy-msgv2.
t_idoc_status-msgv3=f_sy-msgv3.
t_idoc_status-msgv4=f_sy-msgv4.
t_idoc_status-segnum=f_idoc_data-segnum.
t_idoc_status-segfld=segfld.
t_idoc_status-repid=f_sy-repid.
t_idoc_status-routid=routid.
APPENDT_IDOC_STATUS.
ENDFORM.

Example Program for Serialization


FUNCTIONIDOC_INPUT_XAMPLE2.
*"---------------------------------------------------------------------*"
*"Localinterface:
*"IMPORTING
*"VALUE(INPUT_METHOD)LIKEBDWFAP_PAR-INPUTMETHD
*"VALUE(MASS_PROCESSING)LIKEBDWFAP_PAR-MASS_PROC
*"EXPORTING
*"VALUE(WORKFLOW_RESULT)LIKEBDWF_PARAM-RESULT
*"VALUE(APPLICATION_VARIABLE)LIKEBDWF_PARAM-APPL_VAR
*"VALUE(IN_UPDATE_TASK)LIKEBDWFAP_PAR-UPDATETASK
*"VALUE(CALL_TRANSACTION_DONE)LIKEBDWFAP_PAR-CALLTRANS

*"TABLES
*"IDOC_CONTRLSTRUCTUREEDIDC
*"IDOC_DATASTRUCTUREEDIDD
*"IDOC_STATUSSTRUCTUREBDIDOCSTAT
*"RETURN_VARIABLESSTRUCTUREBDWFRETVAR
*"SERIALIZATION_INFOSTRUCTUREBDI_SER
*"EXCEPTIONS
*"WRONG_FUNCTION_CALLED
*"---------------------------------------------------------------------*---------------------------------------------------------------------*----------------------05July1996---------------------------------*---------------------------------------------------------------------*ExamplefunctionmoduleforprocessinginboundIDocsforALEorEDI.
*Thisexampleappliesforprocessing
*
*with-oneIDocatatime
*-serialization
*
*without-customer-exits
*-callinganALE-enabledtransaction
*-massprocessing(morethanoneIDocatatime)
*--------------------Namingconventions-----------------------------*Internaltablesstartwith't_'
*Internalfieldstringsstartwith'f_'
*---------------------------------------------------------------------*>>Thefollowinglinemustappearintheglobalpartofyour
*>>functiongroup:
*includembdconwf."ReportcontainingtheALEconstants.
*TheALEconstantsstartwith'c_'.
DATA:SUBRCLIKESY-SUBRC,
OBJECT_NUMBERLIKEXHEAD-DOCMNT_NO.
*Initializevariables
SUBRC=0.
*ReadtheIDoc'scontrolrecord
READTABLEIDOC_CONTRLINDEX1.
PERFORMIDOC_PROCESS_XAMPLE2TABLESIDOC_DATA
SERIALIZATION_INFO
IDOC_STATUS
USINGIDOC_CONTRL
CHANGINGOBJECT_NUMBER
SUBRC.
*FilltheALEexportparameters
*Inthisexampleweassumethat'callfunction'xxx'inupdatetask'is
*notusedtoupdatethedatabase.
CLEARIN_UPDATE_TASK.
CLEARCALL_TRANSACTION_DONE."CallTransactionisnotused.

IFSUBRC<>0."Erroroccurred
WORKFLOW_RESULT=C_WF_RESULT_ERROR.
RETURN_VARIABLES-WF_PARAM=C_WF_PAR_ERROR_IDOCS.
RETURN_VARIABLES-DOC_NUMBER=IDOC_CONTRL-DOCNUM.
APPENDRETURN_VARIABLES.
ELSE."IDocprocessedsuccessfully
WORKFLOW_RESULT=C_WF_RESULT_OK.
RETURN_VARIABLES-WF_PARAM=C_WF_PAR_PROCESSED_IDOCS.
RETURN_VARIABLES-DOC_NUMBER=IDOC_CONTRL-DOCNUM.
APPENDRETURN_VARIABLES.
RETURN_VARIABLES-WF_PARAM=C_WF_PAR_APPL_OBJECTS.
RETURN_VARIABLES-DOC_NUMBER=OBJECT_NUMBER.
APPENDRETURN_VARIABLES.
ENDIF.
ENDFUNCTION.
*---------------------------------------------------------------------*
*FORMIDOC_PROCESS_XAMPLE2*
*---------------------------------------------------------------------*
*ThisroutinecreatesanapplicationdocumentbasedontheIDoc's*
*contents.Object_Numbercontainsthenewdocument'snumber.*
Ifanerroroccurs,subrcisnon-zero,t_idoc_statusisfilled.*
*Note:ifmorethanoneerrorisdetected,t_idoc_statuscontains*
*morethanonestatusrecord.*
*---------------------------------------------------------------------*
*-->F_IDOC_CONTRLIDoccontrolrecord*
*-->T_IDOC_DATAIDocdatarecords*
*<--T_IDOC_STATUSIDocstatusrecords*
*<--OBJECT_NUMBERCreateddocument'snumber*
*<--SUBRCReturncode*
*---------------------------------------------------------------------*
FORMIDOC_PROCESS_XAMPLE2
TABLEST_IDOC_DATASTRUCTUREEDIDD
T_SERIALIZATION_INFOSTRUCTUREBDI_SER
T_IDOC_STATUSSTRUCTUREBDIDOCSTAT
USINGF_IDOC_CONTRLSTRUCTUREEDIDC
CHANGINGOBJECT_NUMBERLIKEXHEAD-DOCMNT_NO
SUBRCLIKESY-SUBRC.
*Internalfieldstringforthedocumentheader.
DATA:F_XHEADLIKEXHEAD.
*Internaltableforthedocumentitems.
DATA:T_XITEMLIKEXITEMOCCURS0WITHHEADERLINE.
*Numbergiventothecreateddocument
DATA:DOCUMENT_NUMBERLIKEF_XHEAD-DOCMNT_NO.
*MovethedataintheIDoctotheinternalstructures/tables

*f_xheadandt_xitem.
PERFORMIDOC_INTERPRET2TABLEST_IDOC_DATA
T_SERIALIZATION_INFO
T_XITEM
T_IDOC_STATUS
USINGF_IDOC_CONTRL
CHANGINGF_XHEAD
SUBRC.
*Createtheapplicationobjectifnoerroroccurredsofar.
IFSUBRC=0.
*Thisfictitiousfunctionmodulecreatesanewobjectbasedonthe
*datathatwasreadfromtheIDoc.Thenewobject'sIDisreturned
*intheparameter'document_number'.
*Thefunctionmodulechecksthatthedataiscorrect,andraises
*anexceptionifanerrorisdetected.
CALLFUNCTION'XAMPLE_OBJECT_CREATE'
EXPORTING
XHEAD=F_XHEAD
IMPORTING
DOCUMENT_NUMBER=DOCUMENT_NUMBER
TABLES
XITEM=T_XITEM
EXCEPTIONS
OTHERS=1.
IFSY-SUBRC<>0.
SUBRC=1.
*Puttheerrormessageinto't_idoc_status'
PERFORMSTATUS_FILL_SY_ERROR
TABLEST_IDOC_STATUS
USINGT_IDOC_DATA
SY
''"Fieldname
'idoc_process_xample'."Formroutine
ELSE.
*Filltheremainingexportparameters
OBJECT_NUMBER=DOCUMENT_NUMBER."Newdocument'snumber
t_idoc_status-docnum=f_idoc_contrl-docnum.
t_idoc_status-status=c_idoc_status_ok.
t_idoc_status-msgty='S'.
t_idoc_status-msgid=your_msgid."Globalvariable.
t_idoc_status-msgno=msgno_success."Globalvariable.
t_idoc_status-msgv1=object_number.
APPENDT_IDOC_STATUS.
ENDIF."ifsy-subrc<>0.
ENDIF."ifsubrc=0.
ENDFORM.
*---------------------------------------------------------------------*
*FORMIDOC_INTERPRET2*
*---------------------------------------------------------------------*

*Thisroutinechecksthatthecorrectmessagetypeisbeingused,*
*thenchecksthattheIDochasnotbeenovertaken(serialization),*
*andthenconvertsandmovesthedatafromtheIDocsegmentstothe*
*internalstructuref_xheadandinternaltablet_xitem.*
*Ifanerroroccurs,t_idoc_statusisfilledansubrc<>0.*
*---------------------------------------------------------------------*
*-->T_IDOC_STATUS*
*-->T_XITEM*
*-->F_IDOC_DATA*
*-->F_XHEAD*
*-->SUBRC*
*---------------------------------------------------------------------*
FORMIDOC_INTERPRET2TABLEST_IDOC_DATASTRUCTUREEDIDD
T_SERIALIZATION_INFOSTRUCTUREBDI_SER
T_XITEMSTRUCTUREXITEM
T_IDOC_STATUSSTRUCTUREBDIDOCSTAT
USINGF_IDOC_CONTRLSTRUCTUREEDIDC
CHANGINGF_XHEADSTRUCTUREXHEAD
SUBRCLIKESY-SUBRC.
DATA:BEGINOFT_IDOC_CONTRLOCCURS1.
INCLUDESTRUCTUREEDIDC.
DATA:ENDOFT_IDOC_CONTRL.
APPENDF_IDOC_CONTRLTOT_IDOC_CONTRL.
*CheckthattheIDoccontainsthecorrectmessagetype.
*Note:ifyourmessagetypeisreducible,checkfield'idoctp'
*(IDoctype)insteadof'mestyp'.
IFF_IDOC_CONTRL-MESTYP<>'XAMPLE'.
MESSAGEIDYOUR_MSGID"Globalvariable
TYPE'E'
NUMBERMSGNO_WRONG_FUNCTION"Globalvariable
WITHF_IDOC_CONTRL-MESTYP"messagetype
'IDOC_INPUT_XAMPLE'"Yourfunctionmodule.
F_IDOC_CONTRL-SNDPRT"Senderpartnertype
F_IDOC_CONTRL-SNDPRN"Sendernumber.
RAISINGWRONG_FUNCTION_CALLED.
ENDIF.
*>>>>>>>>>>>>>Serializationcheck(Start)<<<<<<<<<<<<<<<<<<<<<<<<<<<<
APPENDF_IDOC_CONTRLTOT_IDOC_CONTRL.
CALLFUNCTION'IDOC_SERIALIZATION_CHECK'
TABLES
IDOC_SERIAL=T_SERIALIZATION_INFO
IDOC_DATA=T_IDOC_DATA
IDOC_CONTROL=T_IDOC_CONTRL
EXCEPTIONS
OTHERS=1.
IFSY-SUBRC<>0.
SUBRC=1.

*Puttheerrormessageinto'idoc_status'
PERFORMSTATUS_FILL_SY_ERROR
TABLEST_IDOC_STATUS
USINGT_IDOC_DATA
SY
'materialid'"Fieldname
'e1xitem_process'."Formroutine
EXIT."Leavetheroutine.
ENDIF."ifsy-subrc<>0.
*GettheserializationinfoforyourIDoc.
READTABLET_SERIALIZATION_INFO
WITHKEYDOCNUM=F_IDOC_CONTRL-DOCNUM.
*CheckwhethertheIDochasbeenflaggedashavingbeenovertaken.
IFNOTT_SERIALIZATION_INFO-SERFLAGISINITIAL.
*IDochasbeenovertaken:inthisexample,flagasanerrorandquit.
SUBRC=1.
*Puttheerrormessageinto't_idoc_status'
t_idoc_status-docnum=f_idoc_contrl-docnum.
t_idoc_status-status=c_idoc_status_error.
t_idoc_status-msgty='E'.
T_IDOC_STATUS-MSGID=YOUR_MSGID."Globalvariable
T_IDOC_STATUS-MSGNO=MSGNO_IDOC_OVERTAKEN."Globalvariable
APPENDT_IDOC_STATUS.
EXIT."Leavetheroutine.
ENDIF."ifnott_serialization_info-serflagisinitial.
*>>>>>>>>>>>>>Serializationcheck(End)<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
*LoopthroughtheIDoc'ssegmentsandconvertthedatafromtheIDoc
*formattotheinternalformat.
LOOPATT_IDOC_DATAWHEREDOCNUM=F_IDOC_CONTRL-DOCNUM.
CASET_IDOC_DATA-SEGNAM.
WHEN'E1XHEAD'.
PERFORME1XHEAD_PROCESSTABLEST_IDOC_STATUS
USINGT_IDOC_DATA
CHANGINGF_XHEAD
SUBRC.
WHEN'E1XITEM'.
PERFORME1XITEM_PROCESSTABLEST_XITEM
T_IDOC_STATUS
USINGF_XHEAD-CURRENCY
T_IDOC_DATA
CHANGINGSUBRC.
ENDCASE.
ENDLOOP.
ENDFORM.

You might also like