IDoc handlers that support Create, Update and Delete operations receive business object data formatted as an IDoc. The role of these operations is to integrate the business object data with SAP's Call Transaction API and generate an object key. Only the object key is passed back to Y_XR_IDOC_HANDLER, not the business object data. Y_XR_IDOC_HANDLER stores the business object data in memory and inserts the object key into the first attribute marked isKey in the parent business object. Then, Y_XR_IDOC_HANDLER passes the business object data back to the connector.
The sample code below represents the following flow:
The following sample code supports SAP Sales Quote Create:
*- Initialize working variables and internal tables PERFORM INITIALIZE_IN. *- I01(MF): Begin IDoc interpretation PERFORM LOG_UPDATE(SAPLYXR1) USING C_INFORMATION_LOG TEXT-I01 SPACE SPACE SPACE. *- Interpret IDoc data structure IF NOT IDOC_DATA[] IS INITIAL. *- Move IDoc to internal tables PERFORM INTERPRET_IDOC. *- Check some of the input fields PERFORM CHECK_INPUT. *- If key values were missing, exit function IF RETURN_CODE NE 0. EXIT. ENDIF. *- E01(MF): No Idoc data lines sent for processing. ELSE. RETURN_CODE = 2. RETURN_TEXT = TEXT-E01. EXIT. ENDIF. *- Build the BDC session for transaction VA21. PERFORM BUILD_BDC_VA21. *- Call Transaction PERFORM LOG_UPDATE(SAPLYXR1) USING C_INFORMATION_LOG TEXT-I02 'VA21' C_BLANK C_BLANK. CALL TRANSACTION 'VA21' USING BDCDATA MODE INPUT_METHOD UPDATE 'S' MESSAGES INTO BDC_MESSAGES. *- Capture return code and object key from transaction PERFORM PREPARE_RETURNED_MESSAGE. ENDFUNCTION.
The Create logic has two main functions:
The first part of the Create logic is the task of translating data in the IDoc structure into working data structures. To do this, you need to create code similar to the following:
loop at idoc_data. case idoc_data-segnam. when 'ZSQVBAK'. " Header Data move idoc_data-sdata to zsqvbak. when 'ZSQVBUK'. " Status Segment move idoc_data-sdata to zsqvbuk. when 'ZSQVBP0'. " Partner Header Level move idoc_data-sdata to zsqvbp0. when 'ZSQVBAP'. " Item Detail move idoc_data-sdata to zsqvbap. when 'ZSQVBA2'. " Item Detail Part 2 move idoc_data-sdata to zsqvba2. when 'ZSQVBUP'. " Item Status move idoc_data-sdata to zsqvbup. when 'ZSQVBKD'. " Commerical data move idoc_data-sdata to zsqvbkd. when 'ZSQKONV'. " Condition move idoc_data-sdata to zsqkonv. when 'ZSQVBPA'. " Partner Item Level move idoc_data-sdata to zsqvbpa. endcase. endloop.