IDOC Posting Function Module
Posted on Apr. 1, 2010 at 04.01 PM - Kuala Lumpur, Malaysia
Copy from SAP standard inbound function module so that we can have the necessary signature in our custom IDOC posting function module.
1. Read the control record information. Verify the control information; if the message type is incorrect, raise the exception.
LOOP AT IDOC_CONTRL.
* make sure we have the correct message passed to us
IF IDOC_CONTRL−MESTYP NE 'ZXXX'.
RAISE WRONG_FUNCTION_CALLED.
ENDIF.
...
ENDLOOP.
2. Read the IDoc data for an IDoc. Remember that several IDocs can be passed together. Parse through each data record. If using the call transaction, build the BDC data table; if not, build internal tables as required by the direct−posting function module.
LOOP AT IDOC_DATA WHERE DOCNUM EQ IDOC_CONTRL−DOCNUM.
CASE IDOC_DATA−SEGNAM.
WHEN 'Z1XXX'. " employee header
FS_DATA = IDOC_DATA−SDATA.
MOVE−CORRESPONDING FS_DATA TO FS_XXX.
...
ENDLOOP.
3. Call the posting program and capture the results.
UPDATE ZXXX FROM TABLE IT_XXX.
IF SY-SUBRC = 0.
...
ELSE.
...
ENDIF.
4. Populate the return parameters.
IF SY−SUBRC EQ 0.
* populate return variables for success
RETURN_VARIABLES−WF_PARAM = 'Processed_IDOCs'.
RETURN_VARIABLES−DOC_NUMBER = IDOC_CONTRL−DOCNUM.
RETURN_VARIABLES−WF_PARAM = 'Appl_Objects'.
RETURN_VARIABLES−DOC_NUMBER = FS_XXX-XXX.
APPEND RETURN_VARIABLES.
* add status record indicating success
IDOC_STATUS−DOCNUM = IDOC_CONTRL−DOCNUM.
IDOC_STATUS−STATUS = '53'.
IDOC_STATUS−MSGTY = 'I'.
IDOC_STATUS−MSGID = 'ZE'.
IDOC_STATUS−MSGNO = '006'.
IDOC_STATUS−MSGV1 = FS_XXX-XXX.
APPEND IDOC_STATUS.
ELSE.
* populate return variables indicating error
WORKFLOW_RESULT = C_WF_RESULT_ERROR.
RETURN_VARIABLES−WF_PARAM = 'Error_IDOCs'.
RETURN_VARIABLES−DOC_NUMBER = IDOC_CONTRL−DOCNUM.
APPEND RETURN_VARIABLES.
* add status record indicating failure in updating
IDOC_STATUS−DOCNUM = IDOC_CONTRL−DOCNUM.
IDOC_STATUS−STATUS = '51'.
IDOC_STATUS−MSGTY = 'E'.
IDOC_STATUS−MSGID = 'ZE'.
IDOC_STATUS−MSGNO = '007'.
IDOC_STATUS−MSGV1 = FS_XXX-XX.
APPEND IDOC_STATUS.
ENDIF.
5. If more IDocs are present, return to Step 2
Caution: Do not perform commit work in your posting program. The ALE layer is responsible for the COMMIT command to ensure data integrity between the results of IDoc posting and the status table update.
Life is beautiful! Let's make it meaningful and colorful!