Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

To Upload xml file to Internal Table

Former Member
0 Kudos
1,071

Hi friends

Given the following xml file .

The requirementis to upload the xml file to internal table using gui_upload and simple transformation .If any one having simple code on this please send .

And also suggest the steps to be followed to write source code using simple transformation.

<?xml version="1.0" encoding="utf-8" ?>

- <Negara>

- <item>

- <COUNTRY>

<MANDT>600</MANDT>

<ZCODE>500</ZCODE>

<ZDESC>Pening Lalat</ZDESC>

<ZSAPCD>T1</ZSAPCD>

</COUNTRY>

</item>

- <item>

- <COUNTRY>

<MANDT>600</MANDT>

<ZCODE>600</ZCODE>

<ZDESC>Pening Lalat2</ZDESC>

<ZSAPCD>T2</ZSAPCD>

</COUNTRY>

</item>

</Negara>

Thaking You

3 REPLIES 3

Former Member
0 Kudos
144

Hi sairam,

1. itab --- > xml

xml ---> itab.

2. This program will do both.

(just copy paste in new program)

3.

REPORT abc.

*----


DATA

DATA : t001 LIKE TABLE OF t001 WITH HEADER LINE.

DATA : BEGIN OF itab OCCURS 0,

a(100) TYPE c,

END OF itab.

DATA: xml_out TYPE string .

DATA : BEGIN OF upl OCCURS 0,

f(255) TYPE c,

END OF upl.

DATA: xmlupl TYPE string .

                                                              • FIRST PHASE

                                                              • FIRST PHASE

                                                              • FIRST PHASE

*----


Fetch Data

SELECT * FROM t001 INTO TABLE t001.

*----


XML

CALL TRANSFORMATION ('ID')

SOURCE tab = t001[]

RESULT XML xml_out.

CALL FUNCTION 'SCMS_STRING_TO_FTEXT'

EXPORTING

TEXT = xml_out

  • IMPORTING

  • LENGTH =

TABLES

FTEXT_TAB = itab.

.

*----


Download

CALL FUNCTION 'GUI_DOWNLOAD'

EXPORTING

filetype = 'BIN'

filename = 'd:\xx.xml'

TABLES

data_tab = itab.

                                                              • SECOND PHASE

                                                              • SECOND PHASE

                                                              • SECOND PHASE

BREAK-POINT.

REFRESH t001.

CLEAR t001.

CALL FUNCTION 'GUI_UPLOAD'

EXPORTING

filename = 'D:\XX.XML'

filetype = 'BIN'

TABLES

data_tab = upl.

LOOP AT upl.

CONCATENATE xmlupl upl-f INTO xmlupl.

ENDLOOP.

*----


XML

CALL TRANSFORMATION ('ID')

SOURCE XML xmlupl

RESULT tab = t001[]

.

BREAK-POINT.

regards,

amit m.

0 Kudos
144

Hi Amit

How to write transformation code for that xml data.. Please let me know immedately if any one know..

I have written as following but i encountered an eror staating -


The exception, which is assigned to class 'CX_ST_MATCH_ELEMENT', was not caught

and

therefore caused a runtime error.

The reason for the exception is:

XML matching error

Expected was element-start: "Negara" [ ] Read was invalid: " " [ ].

Go through my xml file , the code and code in simple transformation.. Please reply(transformation code) me as soon as possible

- <Negara>

- <item>

- <COUNTRY>

<MANDT>600</MANDT>

<ZCODE>500</ZCODE>

<ZDESC>Pening Lalat</ZDESC>

<ZSAPCD>T1</ZSAPCD>

</COUNTRY>

</item>

- <item>

- <COUNTRY>

<MANDT>600</MANDT>

<ZCODE>600</ZCODE>

<ZDESC>Pening Lalat2</ZDESC>

<ZSAPCD>T2</ZSAPCD>

</COUNTRY>

</item>

</Negara>

DATA : BEGIN OF XDATA OCCURS 0,

STR(255) TYPE C,

END OF XDATA.

DATA: XMLUPL TYPE string .

DATA : BEGIN OF ITAB OCCURS 0,

MANDT(3) TYPE C,

ZCODE(3) TYPE C,

ZDESC(15) TYPE C,

ZSAPCD(2) TYPE C,

END OF ITAB.

CALL FUNCTION 'GUI_UPLOAD'

EXPORTING

FILENAME = 'C:\country.xml'

FILETYPE = 'BIN'

TABLES

DATA_TAB = XDATA.

LOOP AT XDATA.

CONCATENATE XMLUPL XDATA-STR INTO XMLUPL.

ENDLOOP.

CALL TRANSFORMATION ('Y_XMLCTRY')

SOURCE XML XMLUPL

result xml = ITAB[].

BREAK-POINT.

<?sap.transform simple?>

<tt:transform template="temp1"

xmlns:tt="http://www.sap.com/transformation-templates">

<tt:root name="ROOT1"/>

<tt:root name="ROOT2"/>

<tt:template name="temp1">

<Negara>

<tt:loop ref=".ROOT1" name="i">

<item>

<tt:loop ref=".ROOT2" name="c">

<COUNTRY>

<MANDT>

<tt:value ref="$c.nummer" />

</MANDT>

<ZCODE>

<tt:value ref="$c.nummer" />

</ZCODE>

<ZDESC>

<tt:value ref="$c.name" />

</ZDESC>

<ZSAPCD>

<tt:value ref="$c.name" />

</ZSAPCD>

</COUNTRY>

</tt:loop>

</item>

</tt:loop>

</Negara>

</tt:template>

</tt:transform>

Thanking You

Devi

Former Member
0 Kudos
144

hi friends

DATA : BEGIN OF xdata OCCURS 0,

str(255) TYPE c,

END OF xdata.

DATA: xmlupl TYPE string .

DATA : BEGIN OF itab OCCURS 0,

mandt(3) TYPE c,

zcode(3) TYPE c,

zdesc(15) TYPE c,

zsapcd(2) TYPE c,

END OF itab.

CALL FUNCTION 'GUI_UPLOAD'

EXPORTING

filename =

'C:\Documents and Settings\User\Desktop\pauldharma.xml'

filetype = 'BIN'

TABLES

data_tab = xdata.

LOOP AT xdata.

CONCATENATE xmlupl xdata-str INTO xmlupl.

ENDLOOP.

CALL TRANSFORMATION ('Y_XMLCTRY')

SOURCE XML xmlupl

RESULT XML = itab[].

*----


Runtime Error should be raised

Runtime errors TRANSFORMATION_NOT_FOUND

Exception CX_XSLT_RUNTIME_ERROR

Occurred on 22.04.2008 at 11:43:05

Error analysis

An exception occurred. This exception is dealt with in more detail below

. The exception, which is assigned to the class 'CX_XSLT_RUNTIME_ERROR', was

neither

caught nor passed along using a RAISING clause, in the procedure "XML_TO_SAP"

"(FORM)"

.

pls correct me.

with luv

pauldharma