Show TOC

Example Program for Mass Processing IDocsLocate this document in the navigation structure

Use
FUNCTION IDOC_INPUT_XAMPLE4.
*"----------------------------------------------------------------------
*"*"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
*"-------------------------------------------------------------------- *
---------------------------------------------------------------------- *
---------------------- 05 July 1996 ---------------------------------- *
---------------------------------------------------------------------- *
Example function module for processing inbound IDocs for ALE or EDI.
* This example applies for processing
*
* with    -  mass processing (more than one IDoc at a time)
*
*   without -  serialization
*           -  customer-exits
*           -  calling an ALE-enabled transaction
* -------------------- 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_'.

* Internal table for the document headers.
DATA: T_XHEAD LIKE XHEAD OCCURS 0 WITH HEADER LINE.

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

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

* Initialize variables
SUBRC = 0.

* Fill the ALE export parameters prior to loop through IDocs.
CLEAR IN_UPDATE_TASK.
CLEAR CALL_TRANSACTION_DONE. "Call Transaction is not used.
WORKFLOW_RESULT = C_WF_RESULT_OK.

* Loop through the IDocs' control records
LOOP AT IDOC_CONTRL.

*   Process the IDoc and check the data; no database updates!
PERFORM IDOC_PROCESS_XAMPLE4 TABLES IDOC_DATA
IDOC_STATUS
t_xhead
t_xitem
USING    IDOC_CONTRL
CHANGING OBJECT_NUMBER
SUBRC.

*   Fill the ALE export parameters.
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

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.

ENDLOOP.         "loop at idoc_contrl.

* Once all IDocs have been processed, insert the application data to
* the database (as long as there is some data to insert).

read table t_xitem index 1.
if sy-subrc = 0.        "i.e. at least one entry

*   This fictitious function module inserts the data in tables
*   t_xhead and t_xitem to the database tables xhead and xitem.
*   It has no exceptions, because a failed insert leads to a run-time 
*   error.
CALL FUNCTION 'XAMPLE_OBJECTS_INSERT_TO_DATABASE'
TABLES
XHEAD = T_XHEAD
XITEM = T_XITEM.

endif.       "if sy-subrc = 0.

ENDFUNCTION. 

         
*-----------------------------------------------------*
*FORM IDOC_PROCESS_XAMPLE4 *
*---------------------------------------------------------------------*
*  This routine adds an application document to tables t_xhead and  *
*  t_xitem 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_XHEAD          Application document's header records *
*  <--  T_XITEM          Application document's line item records *
*  <--  T_IDOC_STATUS    IDoc status records *
*  <--  OBJECT_NUMBER    Created document's number *
*  <--  SUBRC            Return code *
*---------------------------------------------------------------------*
FORM IDOC_PROCESS_XAMPLE4
TABLES   T_IDOC_DATA    STRUCTURE EDIDD
T_IDOC_STATUS  STRUCTURE BDIDOCSTAT
T_XHEAD        STRUCTURE XHEAD
T_XITEM        STRUCTURE XITEM
USING    F_IDOC_CONTRL  STRUCTURE EDIDC
CHANGING OBJECT_NUMBER  LIKE XHEAD-DOCMNT_NO
SUBRC          LIKE SY-SUBRC.

* Internal table string for the document headers.
DATA: F_XHEAD LIKE XHEAD OCCURS 0 WITH HEADER LINE.

* Internal table for one document's items.
DATA: T_ONE_XITEM LIKE XITEM OCCURS 0 WITH HEADER LINE.

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


* Move the data in the IDoc to the internal structures/tables
* f_xhead and t_xitem.
PERFORM IDOC_INTERPRET TABLES   T_IDOC_DATA
T_ONE_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 checks the new object based on the
*   data that was read from the IDoc.
*   If the checks succeed, the new object's ID is returned in the
*   parameter 'document_number'.
*   If the checks fail, an exception is raised.
*   Note: this function must not insert or modify database records!
CALL FUNCTION 'XAMPLE_OBJECT_CHECK'
EXPORTING 
XHEAD           = F_XHEAD
IMPORTING
DOCUMENT_NUMBER = DOCUMENT_NUMBER
TABLES
XITEM           = T_ONE_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
append f_xhead to t_xhead.
APPEND LINES OF T_ONE_XITEM TO T_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. "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.