IDoc XML file











mulesoft setup idoc
https://youtu.be/2cqcJvpmVEo

BD12 send customer (output type DEBMAS)

Test RFC function module
RFC_PING

Idoc auth
s_idoc_all
b_ale_all t

SM59
Assign user with idoc authorisation to rfc connection

we20
set parameter to trigger imediatly or vioa background job



So how do you produce an example XML payload for the inbound (and outbound idocs). You would think this would be a standard bit of functionality, click a button and out comes the XML which you can pass to mulesoft or whatever other middlewear you are workinbg with.. Well its not.


There are several methods, you can use standard program RCOD_DOWNLOAD_IDOC_AS_XML in newer systems. You can also use function module IDOC_XML_TRANSFORM but this add extra spaces to the close tag and just displays the data on screen, so is not easy to get if from there to a file.

Honestly the best way is to use a custom program like below which is basically a simply version of RCOD_DOWNLOAD_IDOC_AS_XML.

But even this does not get you a file that is correct to just send out, as the idoc contains adtional data that has been added post processing like IDOC number etc which is not relevant for the external system. It doesn't need this to send and doesn't get this sent back to it as IDoc communication is asyncronous.

Manipulate the XML file


So once you have produced the XML file using whatever method you you have to remove sections you don't required. The easiest way to do this is to use the exclipse editor.

Simply open up the file in eclipse
idoc xml file step 1



and you should see somthing like this
idoc xml file step 2



first step remove all the entries that contain data that wasn't part of the initial trigger data i.e. entries containing EDI_DS. to do this right click and select delete
idoc xml file step 3



Now check the initail section, you will see enteies for IDoc number, basically remove down to IDOCTYPE
idoc xml file step 4



So you end up with something like this
idoc xml file step 5





https://sapintegrationhub.com/abap/ale-idoc/how-to-download-idoc-to-xml-file/
https://www.opc-router.com/sap-interfaces/
https://docs.mulesoft.com/sap-connector/5.3/sap-connector-examples


*&---------------------------------------------------------------------*
*& Report Z_IDOC_XML
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT z_idoc_xml.

DATA: gt_string TYPE TABLE OF string WITH HEADER LINE.

DATA: gv_filename TYPE string VALUE 'idoc.xml',
gv_path TYPE string,
gv_result TYPE i,
gv_string TYPE string.

DATA: idoc TYPE REF TO cl_idoc_xml1. "IDocs in XML Format object class


******************************************************************
*SELECTION-SCREEN
SELECTION-SCREEN BEGIN OF BLOCK b2 WITH FRAME TITLE TEXT-002.
PARAMETERS: p_docnum LIKE edidc-docnum OBLIGATORY. "created idoc number
PARAMETERS: p_path TYPE string LOWER CASE OBLIGATORY. "file path
SELECTION-SCREEN END OF BLOCK b2.


******************************************************************
*AT SELECTION-SCREEN
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_path.

* Display save dialog window
CALL METHOD cl_gui_frontend_services=>file_save_dialog
EXPORTING
default_extension = 'xml'
default_file_name = gv_filename
initial_directory = 'C:'
CHANGING
filename = gv_filename
path = gv_path
fullpath = p_path
user_action = gv_result.


******************************************************************
*END-OF-SELECTION.
END-OF-SELECTION.

* Create IDOC_XML object
CREATE OBJECT idoc
EXPORTING
docnum = p_docnum
EXCEPTIONS
error_loading_idoc = 1
error_building_xml = 2
OTHERS = 3.
IF sy-subrc <> 0.
Write:/ 'Idoc Failed'.
ENDIF.

* Convert xml to string
CALL METHOD idoc->get_xmldata_as_string
IMPORTING
data_string = gv_string.

* append xml string to string tab
APPEND gv_string TO gt_string.

*Download string file
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
filename = p_path
TABLES
data_tab = gt_string
EXCEPTIONS
file_write_error = 1
no_batch = 2
gui_refuse_filetransfer = 3
invalid_type = 4
no_authority = 5
unknown_error = 6
header_not_allowed = 7
separator_not_allowed = 8
filesize_not_allowed = 9
header_too_long = 10
dp_error_create = 11
dp_error_send = 12
dp_error_write = 13
unknown_dp_error = 14
access_denied = 15
dp_out_of_memory = 16
disk_full = 17
dp_timeout = 18
file_not_found = 19
dataprovider_exception = 20
control_flush_error = 21
OTHERS = 22.
SAP Help