* Calling the BAPI_SALESORDER_CREATEFROMDAT2 via RFC in the destination system
* Preparing an IDoc and sending the IDoc to the destination
The BAPI has several disadvantages. Mainly you need to collect all your data tediously in a program and then map it to the BAPI parameter structure. Unfortunately, the BAPI paramaters are not very compatible with the SAP R/3 database structure like VBAK and VBAP, namely the names of the fields differ heavily. In addition, all control of errors has to be handled by the sending program and a protocol is not written by the BAPI.
There is no standard way to send the data via ALE, but a simple trick helps us to distribute the order via ALE. SAP R/3 sends out order confirmations to a target system. The data in a sales order confirmation IDoc (ORDRSP) is the same as in an incoming sales order both sharing an ORDERS01 ... ORDERS05 IDoc type. What we have to do is to prepare an ORDRSP order confoirmation and send it to the target with an ORDERS message type.
The following shows a simple program that creates an IDoc and sends the IDoc via RFC to the destination system. For this example the only IDoc specific customizing would be to define an input partner profile in the target system.
report Z_LOGOS_ALE_ORDERS_DISTR_TEST. * parameters: VBELN type VBELN default '84'. * data: OBJECT like NAST. data: CONTROL_RECORD like EDIDC. data: INT_EDIDD type table of EDIDD with header line. data: OWN_LOGICAL_SYSTEM type TBDLS-LOGSYS. * data: INT_EDI_DC type EDI_DC. data: INT_EDI_DD type table of EDI_DD with header line. * CONTROL_RECORD-MESTYP = 'ORDERS'. CONTROL_RECORD-IDOCTP = 'ORDERS05'. * call function 'OWN_LOGICAL_SYSTEM_GET' importing OWN_LOGICAL_SYSTEM = OWN_LOGICAL_SYSTEM exceptions OWN_LOGICAL_SYSTEM_NOT_DEFINED = 1 others = 0. if SY-SUBRC <> 0. * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO * WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4. endif. * CONTROL_RECORD-SNDPRT = 'LS'. CONTROL_RECORD-SNDPRN = OWN_LOGICAL_SYSTEM. CONTROL_RECORD-SNDPOR = OWN_LOGICAL_SYSTEM. * CONTROL_RECORD-RCVPRT = 'LS'. CONTROL_RECORD-RCVPRN = OWN_LOGICAL_SYSTEM. CONTROL_RECORD-RCVPOR = SPACE. * OBJECT-OBJKY = VBELN. * *call function 'Z_OSCOL_ALE_IDOC_OUTPUT_ORDERS' call function 'IDOC_OUTPUT_ORDRSP' exporting OBJECT = OBJECT CONTROL_RECORD_IN = CONTROL_RECORD importing * OBJECT_TYPE = CONTROL_RECORD_OUT = CONTROL_RECORD tables INT_EDIDD = INT_EDIDD exceptions ERROR_MESSAGE_RECEIVED = 1 DATA_NOT_RELEVANT_FOR_SENDING = 2 others = 3. if SY-SUBRC <> 0. * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO * WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4. endif. * * --Clean up the IDoc from unwanted data delete INT_EDIDD where SEGNAM eq 'E1EDK18'. * * --- Must be filled after func call CONTROL_RECORD-OUTMOD = '2'. CONTROL_RECORD-DIRECT = '2'. * move-corresponding CONTROL_RECORD to INT_EDI_DC. INT_EDI_DC-IDOCTYP = CONTROL_RECORD-IDOCTP. * loop at INT_EDIDD. move-corresponding INT_EDIDD to INT_EDI_DD. append INT_EDI_DD. endloop. * call function 'IDOC_INBOUND_SYNCHRONOUS' destination 'NONE' exporting INT_EDIDC = INT_EDI_DC ONLINE = 'O' importing DOCNUM = CONTROL_RECORD-DOCNUM * ERROR_BEFORE_CALL_APPLICATION = tables INT_EDIDD = INT_EDI_DD exceptions IDOC_NOT_SAVED = 1 others = 2 . if SY-SUBRC <> 0. * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO * WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4. endif. write: / SY-SUBRC color col_normal, CONTROL_RECORD-DOCNUM color col_normal hotspot. hide: CONTROL_RECORD. * at line-selection. if not CONTROL_RECORD-DOCNUM is initial. call function 'EDI_DOCUMENT_TREE_DISPLAY' exporting DOCNUM = CONTROL_RECORD-DOCNUM * OPEN = exceptions NO_IDOC_FOUND = 1 others = 2 . if SY-SUBRC <> 0. * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO * WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4. endif. endif. *
Dig Deeper on SAP integration
Related Q&A from Axel Angeli
An SAP user is having difficulty with PERNR iDoc while transporting data from SAP to an external system. Continue Reading
An SAP user wants to know how to upload data into SAP R/3 when SAP Scripting is not enabled. Continue Reading
An SAP user is receiving an error message while integrating SAP iDoc PORDCR1 for a purchase order. Continue Reading