‎2011 Jun 16 1:47 PM
Hello all,
I was trying to upload xml to internal table but failed i ma getting the value but in junk way.
How to upload xml to internal table.
the data in xml is like
<?xml version="1.0" standalone="yes" ?>
- <NewDataSet>
- <status xmlns="sap">
<Mandt>800</Mandt>
<Matnr>000000000000000038</Matnr>
<Werks>1000</Werks>
<Maktx>Classification test</Maktx>
<Type>1</Type>
<Stat>0</Stat>
</status>
- <status xmlns="sap">
<Mandt>800</Mandt>
<Matnr>000000000000000078</Matnr>
<Werks>1000</Werks>
<Maktx>Component Full Repair Service</Maktx>
<Type>2</Type>
<Stat>0</Stat>
</status>
- <status xmlns="sap">
<Mandt>800</Mandt>
<Matnr>000000000000000088</Matnr>
<Werks>1000</Werks>
<Maktx>AS-100 T-shirt</Maktx>
<Type>2</Type>
<Stat>0</Stat>
</status>
- <status xmlns="sap">
<Mandt>800</Mandt>
<Matnr>000000000000000089</Matnr>
<Werks>1000</Werks>
<Maktx>AS-100 T-shirt</Maktx>
<Type>2</Type>
<Stat>0</Stat>
</status>
- <status xmlns="sap">
<Mandt>800</Mandt>
<Matnr>000000000000000679</Matnr>
<Werks>1000</Werks>
<Maktx>Maxitec-R 375 Personal computer</Maktx>
<Type>2</Type>
<Stat>0</Stat>
</status>
- <status xmlns="sap">
<Mandt>800</Mandt>
<Matnr>WHEEL</Matnr>
<Werks>1000</Werks>
<Maktx>auto wheel</Maktx>
<Type>2</Type>
<Stat>0</Stat>
</status>
</NewDataSet>
how to upload this to internal table??
Pls help me out....
‎2011 Jun 16 3:20 PM
As mentioned above both approaches will lead you to the result. A snippet how this could be achieved by simple transformation
- create ST using STRANS tcode
<?sap.transform simple?>
<tt:transform xmlns:tt="http://www.sap.com/transformation-templates">
<tt:root name="data_tab" />
<tt:template>
<NewDataSet>
<tt:loop ref="data_tab" name="line">
<status xmlns="sap">
<Mandt><tt:value ref="$line.Mandt"/></Mandt>
<Matnr><tt:value ref="$line.Matnr"/></Matnr>
<Werks><tt:value ref="$line.Werks"/></Werks>
<Maktx><tt:value ref="$line.Maktx"/></Maktx>
<Type><tt:value ref="$line.Type"/></Type>
<Stat><tt:value ref="$line.Stat"/></Stat>
</status>
</tt:loop>
</NewDataSet>
</tt:template>
</tt:transform>
- and ABAP program to deserialize your xml file
DATA xmlbin_tab TYPE TABLE OF x255.
DATA xml_xstr TYPE xstring.
DATA len TYPE i.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = 'C:\Temp\test.xml'
filetype = 'BIN'
IMPORTING
filelength = len
TABLES
data_tab = xmlbin_tab.
CALL FUNCTION 'SCMS_BINARY_TO_XSTRING'
EXPORTING
input_length = len
IMPORTING
buffer = xml_xstr
TABLES
binary_tab = xmlbin_tab.
DATA: BEGIN OF itab OCCURS 0,
mandt TYPE mandt,
matnr TYPE matnr,
werks TYPE persa,
maktx TYPE maktx,
type TYPE i,
stat TYPE i,
END OF itab.
CALL TRANSFORMATION zpmi_st
SOURCE XML xml_xstr
RESULT data_tab = itab[].
Regards
Marcin
‎2011 Jun 16 2:33 PM
Hi,
Research classes that begin with CL_XML*. I used CL_XML_DOCUMENT & CL_XML_DOCUMENT_BASE and its methods to create an XML string from an internal table, parsed the string per business requirements and then using the string, build an internal table of the XML output. The internal table to hold hte XML output was defined as a table with one field that is 255 characters in length.
check methods:
create_with_data
render_2_string
parse_string
render_2_table
Hope this helps.
‎2011 Jun 16 3:04 PM
what is it you are trying to acheive in the end? an internal table containing the XML, or an internal table containing the fields mapped from the XML elements.
For the former, look at CL_GUI_FRONTEND_SERVICES=>GUI_UPLOAD
For the latter, look at the XML objects as stated above, or at the CALL TRANSFORMATION ABAP statement
You could use a simple transformation. There are several examples of the code.
‎2011 Jun 16 3:20 PM
As mentioned above both approaches will lead you to the result. A snippet how this could be achieved by simple transformation
- create ST using STRANS tcode
<?sap.transform simple?>
<tt:transform xmlns:tt="http://www.sap.com/transformation-templates">
<tt:root name="data_tab" />
<tt:template>
<NewDataSet>
<tt:loop ref="data_tab" name="line">
<status xmlns="sap">
<Mandt><tt:value ref="$line.Mandt"/></Mandt>
<Matnr><tt:value ref="$line.Matnr"/></Matnr>
<Werks><tt:value ref="$line.Werks"/></Werks>
<Maktx><tt:value ref="$line.Maktx"/></Maktx>
<Type><tt:value ref="$line.Type"/></Type>
<Stat><tt:value ref="$line.Stat"/></Stat>
</status>
</tt:loop>
</NewDataSet>
</tt:template>
</tt:transform>
- and ABAP program to deserialize your xml file
DATA xmlbin_tab TYPE TABLE OF x255.
DATA xml_xstr TYPE xstring.
DATA len TYPE i.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = 'C:\Temp\test.xml'
filetype = 'BIN'
IMPORTING
filelength = len
TABLES
data_tab = xmlbin_tab.
CALL FUNCTION 'SCMS_BINARY_TO_XSTRING'
EXPORTING
input_length = len
IMPORTING
buffer = xml_xstr
TABLES
binary_tab = xmlbin_tab.
DATA: BEGIN OF itab OCCURS 0,
mandt TYPE mandt,
matnr TYPE matnr,
werks TYPE persa,
maktx TYPE maktx,
type TYPE i,
stat TYPE i,
END OF itab.
CALL TRANSFORMATION zpmi_st
SOURCE XML xml_xstr
RESULT data_tab = itab[].
Regards
Marcin