- Create Table Type:
- Go to SE11.
- Create a structure of your internal table
- Create a table type based on the structure
- Make Sure to save and activate them
- Create Transformation:
- Go to tcode STRANS or XSLT_TOOL
- Create an S Simple Transformation
- Click the sparkling magic wand button a.k.a Edit Simple Transformation Graphically (Ctrl+Shift+F11)
- Insert New Root in Data Roots
- Fill in any root name of the xml for Root-Name and <Table_Type> created in first stage for Type-Name
- Then drag the data root into Simple Transformation
- You might want to change the Field name in the XML by double click the element
- You can make the field into an attribute.
- Save Activate the transformation
- Complete your Program:
- Make sure you already have the particular internal table filled with data
- Prepare the output location
- Insert, modify and perform the following FORM.
FORM f_xml_export.
DATA: lo_xml_doc TYPE ref TO CL_XML_DOCUMENT,
lv_string TYPE string,
lv_file TYPE string.
CHECK <YOUR_INTERNAL_TABLE>[] IS NOT INITIAL.
*File path
lv_file = '<YOUR_FILE_PATH>'.
*Transform internal table to XML DOM
CALL TRANSFORMATION <YOUR_TRANSFORMATION_NAME>
SOURCE <YOUR_ROOT_NAME> = <YOUR_INTERNAL_TABLE[]
RESULT XML lv_string.
CREATE OBJECT lo_xml_doc.
lo_xml_doc->parse_string( lv_string ).
* Render To XML Table
data it_xml TYPE DCXMLLINES.
CALL FUNCTION 'SDIXML_DOM_TO_XML'
EXPORTING
document = lo_xml_doc->m_document
PRETTY_PRINT = 'X'
* IMPORTING
* XML_AS_STRING =
* SIZE =
TABLES
XML_AS_TABLE = it_xml
* EXCEPTIONS
* NO_DOCUMENT = 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.
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
filename = lv_file
filetype = 'BIN'
TABLES
data_tab = it_xml
EXCEPTIONS
OTHERS = 1.
IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
ENDFORM. " F_XML_EXPORT