Show TOC

Example Program for SerializationLocate this document in the navigation structure

Use
FUNCTION IDOC_INPUT_XAMPLE2.
*"----------------------------------------------------------------------
*"
*"Lokale Schnittstelle:
*" IMPORTING
*" VALUE(INPUT_METHOD) LIKE BDWFAP_PAR-INPUTMETHD
*" VALUE(MASS_PROCESSING) LIKE BDWFAP_PAR-MASS_PROC
*" EXPORTING
*" VALUE(WORKFLOW_RESULT) LIKE BDWF_PARAM-RESULT
*" VALUE(APPLICATION_VARIABLE) LIKE BDWF_PARAM-APPL_VAR
*" VALUE(IN_UPDATE_TASK) LIKE BDWFAP_PAR-UPDATETASK
*" VALUE(CALL_TRANSACTION_DONE) LIKE BDWFAP_PAR-CALLTRANS
*" TABLES
*" IDOC_CONTRL STRUCTURE EDIDC
*" IDOC_DATA STRUCTURE EDIDD
*" IDOC_STATUS STRUCTURE BDIDOCSTAT
*" RETURN_VARIABLES STRUCTURE BDWFRETVAR
*" SERIALIZATION_INFO STRUCTURE BDI_SER
*" EXCEPTIONS
*" WRONG_FUNCTION_CALLED

*"----------------------------------------------------------------------

* Example function module for processing inbound IDocs for ALE or EDI.
* This example applies for processing
*
* with - one IDoc at a time
* - serialization
*
* without - customer-exits
* - calling an ALE-enabled transaction
* - mass processing (more than one IDoc at a time)

* -------------------- Naming conventions ------------------------------
* Internal tables start with 't_'
* Internal field strings start with 'f_'
* ----------------------------------------------------------------------


* >> The following line must appear in the global part of your
* >> function group:
* include mbdconwf. "Report containing the ALE constants.
* The ALE constants start with 'c_'.

DATA: SUBRC LIKE SY-SUBRC,
OBJECT_NUMBER LIKE XHEAD-DOCMNT_NO.

* Initialize variables
SUBRC = 0.

* Read the IDoc's control record
READ TABLE IDOC_CONTRL INDEX 1.

PERFORM IDOC_PROCESS_XAMPLE2 TABLES IDOC_DATA
SERIALIZATION_INFO
IDOC_STATUS
USING IDOC_CONTRL
CHANGING OBJECT_NUMBER
SUBRC.

* Fill the ALE export parameters

* In this example we assume that 'call function 'xxx' in update task' is
* not used to update the database.
CLEAR IN_UPDATE_TASK.
CLEAR CALL_TRANSACTION_DONE. "Call Transaction is not used.

IF SUBRC <> 0. "Error occurred

WORKFLOW_RESULT = C_WF_RESULT_ERROR.
RETURN_VARIABLES-WF_PARAM = C_WF_PAR_ERROR_IDOCS.
RETURN_VARIABLES-DOC_NUMBER = IDOC_CONTRL-DOCNUM.
APPEND RETURN_VARIABLES.

ELSE. "IDoc processed successfully

WORKFLOW_RESULT = C_WF_RESULT_OK.
RETURN_VARIABLES-WF_PARAM = C_WF_PAR_PROCESSED_IDOCS.
RETURN_VARIABLES-DOC_NUMBER = IDOC_CONTRL-DOCNUM.
APPEND RETURN_VARIABLES.
RETURN_VARIABLES-WF_PARAM = C_WF_PAR_APPL_OBJECTS.
RETURN_VARIABLES-DOC_NUMBER = OBJECT_NUMBER.
APPEND RETURN_VARIABLES.

ENDIF.

ENDFUNCTION.


*---------------------------------------------------------------------*
* FORM IDOC_PROCESS_XAMPLE2 *
*---------------------------------------------------------------------*
* This routine creates an application document based on the IDoc's *
* contents. Object_Number contains the new document's number. *
* If an error occurs, subrc is non-zero, t_idoc_status is filled. *
* Note: if more than one error is detected, t_idoc_status contains *
* more than one status record. *
*---------------------------------------------------------------------*
* --> F_IDOC_CONTRL IDoc control record *
* --> T_IDOC_DATA IDoc data records *
* <-- T_IDOC_STATUS IDoc status records *
* <-- OBJECT_NUMBER Created document's number *
* <-- SUBRC Return code *
*---------------------------------------------------------------------*
FORM IDOC_PROCESS_XAMPLE2
TABLES T_IDOC_DATA STRUCTURE EDIDD
T_SERIALIZATION_INFO STRUCTURE BDI_SER
T_IDOC_STATUS STRUCTURE BDIDOCSTAT
USING F_IDOC_CONTRL STRUCTURE EDIDC
CHANGING OBJECT_NUMBER LIKE XHEAD-DOCMNT_NO
SUBRC LIKE SY-SUBRC.

* Internal field string for the document header.
DATA: F_XHEAD LIKE XHEAD.

* Internal table for the document items.
DATA: T_XITEM LIKE XITEM OCCURS 0 WITH HEADER LINE.

* Number given to the created document
DATA: DOCUMENT_NUMBER LIKE F_XHEAD-DOCMNT_NO.


* Move the data in the IDoc to the internal structures/tables
* f_xhead and t_xitem.
PERFORM IDOC_INTERPRET2 TABLES T_IDOC_DATA
T_SERIALIZATION_INFO
T_XITEM
T_IDOC_STATUS
USING F_IDOC_CONTRL
CHANGING F_XHEAD
SUBRC.


* Create the application object if no error occurred so far.
IF SUBRC = 0.
* This fictitious function module creates a new object based on the
* data that was read from the IDoc. The new object's ID is returned
* in the parameter 'document_number'.
* The function module checks that the data is correct, and raises
* an exception if an error is detected.
CALL FUNCTION 'XAMPLE_OBJECT_CREATE'
EXPORTING
XHEAD = F_XHEAD
IMPORTING
DOCUMENT_NUMBER = DOCUMENT_NUMBER
TABLES
XITEM = T_XITEM
EXCEPTIONS
OTHERS = 1.

IF SY-SUBRC <> 0.
SUBRC = 1.
* Put the error message into 't_idoc_status'
PERFORM STATUS_FILL_SY_ERROR
TABLES T_IDOC_STATUS
USING T_IDOC_DATA
SY
'' "Field name
'idoc_process_xample'. "Form routine

ELSE.
* Fill the remaining export parameters
OBJECT_NUMBER = DOCUMENT_NUMBER. "New document's number

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. "Global variable.
t_idoc_status-msgno = msgno_success."Global variable.
t_idoc_status-msgv1 = object_number.
APPEND T_IDOC_STATUS.
ENDIF. "if sy-subrc <> 0.
ENDIF. "if subrc = 0.

ENDFORM.


*---------------------------------------------------------------------*
* FORM IDOC_INTERPRET2 *
*---------------------------------------------------------------------*
* This routine checks that the correct message type is being used, *
* then checks that the IDoc has not been overtaken (serialization), *
* and then converts and moves the data from the IDoc segments to the *
* internal structure f_xhead and internal table t_xitem. *
* If an error occurs, t_idoc_status is filled an subrc <> 0. *
*---------------------------------------------------------------------*
* --> T_IDOC_STATUS *
* --> T_XITEM *
* --> F_IDOC_DATA *
* --> F_XHEAD *
* --> SUBRC *
*---------------------------------------------------------------------*
FORM IDOC_INTERPRET2 TABLES T_IDOC_DATA STRUCTURE EDIDD
T_SERIALIZATION_INFO STRUCTURE BDI_SER
T_XITEM STRUCTURE XITEM
T_IDOC_STATUS STRUCTURE BDIDOCSTAT
USING F_IDOC_CONTRL STRUCTURE EDIDC
CHANGING F_XHEAD STRUCTURE XHEAD
SUBRC LIKE SY-SUBRC.

DATA: BEGIN OF T_IDOC_CONTRL OCCURS 1.
INCLUDE STRUCTURE EDIDC.
DATA: END OF T_IDOC_CONTRL.


APPEND F_IDOC_CONTRL TO T_IDOC_CONTRL.

* Check that the IDoc contains the correct message type.
* Note: if your message-type is reducible, check field 'idoctp'
* (IDoc type) instead of 'mestyp'.
IF F_IDOC_CONTRL-MESTYP <> 'XAMPLE'.

MESSAGE ID YOUR_MSGID "Global variable
TYPE 'E'
NUMBER MSGNO_WRONG_FUNCTION "Global variable
WITH F_IDOC_CONTRL-MESTYP "message type
'IDOC_INPUT_XAMPLE' "Your function module.
F_IDOC_CONTRL-SNDPRT "Sender partner type
F_IDOC_CONTRL-SNDPRN "Sender number.
RAISING WRONG_FUNCTION_CALLED.

ENDIF.


* >>>>>>>>>>>>> Serialization check (Start) <<<<<<<<<<<<<<<<<<<<<<<<<<<<
APPEND F_IDOC_CONTRL TO T_IDOC_CONTRL.

CALL FUNCTION 'IDOC_SERIALIZATION_CHECK'
TABLES
IDOC_SERIAL = T_SERIALIZATION_INFO
IDOC_DATA = T_IDOC_DATA
IDOC_CONTROL = T_IDOC_CONTRL
EXCEPTIONS
OTHERS = 1.

IF SY-SUBRC <> 0.
SUBRC = 1.
* Put the error message into 'idoc_status'
PERFORM STATUS_FILL_SY_ERROR
TABLES T_IDOC_STATUS
USING T_IDOC_DATA
SY
'materialid' "Field name
'e1xitem_process'. "Form routine
EXIT. "Leave the routine.
ENDIF. "if sy-subrc <> 0.

* Get the serialization info for your IDoc.
READ TABLE T_SERIALIZATION_INFO
WITH KEY DOCNUM = F_IDOC_CONTRL-DOCNUM.

* Check whether the IDoc has been flagged as having been overtaken.
IF NOT T_SERIALIZATION_INFO-SERFLAG IS INITIAL.
* IDoc has been overtaken: in this example, flag as an error and quit.
SUBRC = 1.
* Put the error message into '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. "Global variable
T_IDOC_STATUS-MSGNO = MSGNO_IDOC_OVERTAKEN. "Global variable
APPEND T_IDOC_STATUS.
EXIT. "Leave the routine.
ENDIF. "if not t_serialization_info-serflag is initial.
* >>>>>>>>>>>>> Serialization check (End) <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

* Loop through the IDoc's segments and convert the data from the IDoc
* format to the internal format.
LOOP AT T_IDOC_DATA WHERE DOCNUM = F_IDOC_CONTRL-DOCNUM.

CASE T_IDOC_DATA-SEGNAM.

WHEN 'E1XHEAD'.
PERFORM E1XHEAD_PROCESS TABLES T_IDOC_STATUS
USING T_IDOC_DATA
CHANGING F_XHEAD
SUBRC.
WHEN 'E1XITEM'.
PERFORM E1XITEM_PROCESS TABLES T_XITEM
T_IDOC_STATUS
USING F_XHEAD-CURRENCY
T_IDOC_DATA
CHANGING SUBRC.
ENDCASE.
ENDLOOP.
ENDFORM.