2. How do I upload an XML file to the IDoc and send it to the external system?
2. Uploading a file is either done via GUI_UPLOAD or via the usual way of reading a file from the application server...
By submitting your email address, you agree to receive emails regarding relevant topic offers from TechTarget and its partners. You can withdraw your consent at any time. Contact TechTarget at 275 Grove Street, Newton, MA.
(Open dataset. Read dataset) But what do you mean by "send to external system"? Do you want to convert an IDoc into XML? Then you simply define an XML port with WE21 to send the IDoc out.
Here is an example of code that loads an XML from file and posts it as an IDoc. Please keep in mind that the XML has to be in its canonical format as described in the interface repository: ifr.sap.com (choose the template of the desired IDoc from there as an example).
* data: data_tab type table of char1024. data: XML_STREAM type string. * CALL FUNCTION 'GUI_UPLOAD' EXPORTING FILENAME = 'D:test.xml' * FILETYPE = 'ASC' * HAS_FIELD_SEPARATOR = ' ' * HEADER_LENGTH = 0 * READ_BY_LINE = 'X' * DAT_MODE = ' ' * CODEPAGE = ' ' * IGNORE_CERR = ABAP_TRUE * REPLACEMENT = '#' * CHECK_BOM = ' ' * IMPORTING * FILELENGTH = * HEADER = TABLES DATA_TAB = DATA_TAB EXCEPTIONS FILE_OPEN_ERROR = 1 FILE_READ_ERROR = 2 NO_BATCH = 3 GUI_REFUSE_FILETRANSFER = 4 INVALID_TYPE = 5 NO_AUTHORITY = 6 UNKNOWN_ERROR = 7 BAD_DATA_FORMAT = 8 HEADER_NOT_ALLOWED = 9 SEPARATOR_NOT_ALLOWED = 10 HEADER_TOO_LONG = 11 UNKNOWN_DP_ERROR = 12 ACCESS_DENIED = 13 DP_OUT_OF_MEMORY = 14 DISK_FULL = 15 DP_TIMEOUT = 16 OTHERS = 17 . IF SY-SUBRC <> 0. * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO * WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4. ENDIF. * CALL FUNCTION 'CONVERT_TABLE_TO_STRING' EXPORTING I_TABLINE_LENGTH = '1024' IMPORTING E_STRING = XML_STREAM TABLES IT_TABLE = DATA_TAB. * write: / xml_stream color col_total. data: CONTENT_LENGTH type string. data: CONTENT_TYPE type string. data: REMOTE_ADDR type string. * CALL FUNCTION 'IDOC_INBOUND_XML_VIA_HTTP' EXPORTING XML_STREAM = XML_STREAM CONTENT_LENGTH = content_type CONTENT_TYPE = content_type REMOTE_ADDR = remote_addr EXCEPTIONS NO_IDOCS_SAVED = 1 TAG_ERROR = 2 NO_DATA_RECEIVED = 3 NO_IDOCS_RECEIVED = 4 SEGMENT_ERROR = 5 IDOC_WAS_SEND_SECOND_TIME = 6 OTHERS = 7 . IF SY-SUBRC <> 0. * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO * WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4. write: / sy-subrc color COL_NEGATIVE. ENDIF.
Dig Deeper on SAP interface technologies
Related Q&A from Axel Angeli
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
An SAP user is having difficulty with PERNR iDoc while transporting data from SAP to an external system.continue reading
Have a question for an expert?
Please add a title for your question
Get answers from a TechTarget expert on whatever's puzzling you.