Skip to end of metadata
Go to start of metadata

Conversion of IDOC to XML File (Handy Tool)

Summary

This document is intended for all ABAP Developers who want to convert IDoc to XML and also gives complete step-by-step procedure by which we can convert IDoc to XML format file. For this purpose we need to create one function Group and copy the standard function module IDOC_XML_TRANSFORM and do changes accordingly so that we can store the XML files wherever we need.

Introduction

We can find lot of documents on IDoc - XML - FILE conversion but still there are many queries seen in SDN.
My whole idea is to give step-by-step procedure by which we can convert any given IDoc number into XML format. Or else we can also say like this will act as a handy tool to convert IDoc to XML file format as and when needed.

Procedure to Convert IDoc to XML.

Step-1 Create a function Group.

Go to txcode SE37 and create one function group as shown below.


 

After saving function group will look as below.

Step-2 - Copy Function Module IDOC_XML_TRANSFORM

Now we need to copy Function Module IDOC_XML_TRANSFORM for our purpose. For this go to SE80 and give function group as IDOC_XML1 and then click on display in that copy function module IDOC_XML_TRANSFORM.


 

 

 
Click on copy.

Step-3 Changes to be done in Custom Function Module ZIDOC_XML_TRANSFORM.

Now go to SE80 and give function group as ZIDOC2XML and click on Display you can see the standard function module is copied as custom function module into our function group.


 
Double click on the function module and paste the code in the source code of the function module as shown in the below screen.
 

Code you need to copy paste

SPLIT str AT SPACE INTO TABLE t_table.

*Note - I am storing my XML file in C: drive

concatenate 'C:\' docnum sy-datum sy-uzeit '.xml' into filename SEPARATED BY SPACE.

CALL FUNCTION 'GUI_DOWNLOAD'

EXPORTING

filename = FILENAME

tables
data_tab = t_table

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.

IF sy-subrc <> 0.

MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.

Step-4 Changes that need to be done in TOP include of the function Module.


 

Now double click on LZIDOC2XMLTOP and insert the piece of code as shown.

Code you need yo copy paste

TYPES: X_LINES TYPE STRING.

DATA: T_TABLE TYPE STANDARD TABLE OF X_LINES WITH HEADER LINE.

*Filename

DATA: FILENAME TYPE STRING.

Step-5 Check for any Syntax Errors


Finally Activate the whole function group.

Step-6 - Writing Code to call the Function Module.

Now go SE38 and write the code as shown below.

**Tables
Tables: EDIDC.
*Internal Table
DATA T_EDIDC LIKE EDIDC OCCURS 0 WITH HEADER LINE.
*Parameters
PARAMETERS: DOCNUM LIKE EDIDC-DOCNUM.
*F4 help
AT SELECTION-SCREEN ON VALUE-REQUEST FOR DOCNUM.
select * from EDIDC into table t_edidc up to 50 rows.
CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
EXPORTING
retfield = 'DOCNUM'
dynpprog = sy-repid
dynpnr = sy-dynnr
DYNPROFIELD = 'DOCNUM'
value_org = 'S'
TABLES
value_tab = T_EDIDC
EXCEPTIONS
parameter_error = 1
no_values_found = 2
OTHERS = 3.
*Start of Selection
START-OF-SELECTION.
CALL FUNCTION 'ZIDOC_XML_TRANSFORM'
EXPORTING
docnum = DOCNUM.

Save, check and activate the program.

Step-7 Execute the Program

After executing the Program we will get the input screen as shown below.


 
Now give the IDoc number that needed to be converted to XMl format and execute the program.
After executing the program we can see the information message as shown below saying the 'N'  number of bytes transferred.
 

Step-8 - Finding the IDoc which is converted to XML.

As I have given the path of storing the XML file in C drive in the function module all the IDoc's which are converted will be stored in the C: Drive.

Step-9 Sample XML file output

 

Now Enjoy converting IDoc's into XML files. Hope this document helps you all.

 

  • No labels