05-17-2006 9:54 AM
Hello.
I am making a small and simple example of a XML transformation.
The transformation i am using is the following:
<?sap.transform simple?>
<tt:transform xmlns:tt="http://www.sap.com/transformation-templates">
<tt:root name="ROOT"/>
<tt:template name="tmpl1">
<tt:loop ref=".ROOT" name="a">
<A>
<name>
<tt:value ref="$a.name"/>
</name>
<ZLS>
<tt:loop ref="$a.zls" name="z">
<Z>
<tt:value ref="$z.nummer"/>
</Z>
</tt:loop>
</ZLS>
</A>
</tt:loop>
</tt:template>
</tt:transform>
I can do the transformation from XML to ABAP tables without any problems but when i try to to it the other way (ABAP tables to XML) i get the following dump: CX_INVALID_TRANSFORMATION --> "Type of source and target must always be different for transformation START-OF-SELECTION"
The program i am using is the following:
data: xml_string type string.
data: begin of z,
number type string,
end of z.
data: begin of a,
name type string,
zls like table of z,
end of a.
xml_string = `<A>` &
`<name>A1</name>` &
`<ZLS>` &
`<Z>01</Z>` &
`<Z>02</Z>` &
`</ZLS>` &
`</A>` &
`<A>` &
`<name>A2</name>` &
`<ZLS>` &
`<Z>03</Z>` &
`</ZLS>` &
`</A>`.
CALL TRANSFORMATION ZMY_FRIST1
SOURCE XML xml_string
RESULT ROOT = t_a.
CALL TRANSFORMATION ZMY_FRIST1
SOURCE ROOT = t_a
RESULT XML = xml_string.
I get the dump on the second CALL TRANSFORMATION.
Anyone knows why and what can i do to fix this?
Thank you
Nuno Silva
05-17-2006 9:57 AM
check out these excellent weblogs.
/people/r.eijpe/blog/2005/11/10/xml-dom-processing-in-abap-part-i--convert-an-abap-table-into-xml-file-using-sap-dom-approach
/people/r.eijpe/blog/2005/11/21/xml-dom-processing-in-abap-part-ii--convert-an-xml-file-into-an-abap-table-using-sap-dom-approach
05-17-2006 10:02 AM
05-17-2006 10:19 AM
05-17-2006 11:23 AM
why not use the standard XSLT program ID to convert to XML.
CALL TRANSFORMATION (`ID`)
SOURCE ROOT = t_a
RESULT XML = xml_string.
the simple tranformation you have written is for converting xml to abap not abap to xml
Regards
Raja
05-17-2006 11:28 AM
check out this excellent series of weblogs on Simple Transformation
intoduction
/people/horst.keller/blog/2004/10/27/abap-and-xml--introducing-st
details
/people/tobias.trapp/blog/2005/05/04/xml-processing-in-abap-part-1
/people/tobias.trapp/blog/2005/05/17/xml-processing-in-abap-part-2
/people/tobias.trapp/blog/2005/05/20/xml-processing-in-abap-part-3
/people/tobias.trapp/blog/2005/05/27/xml-processing-in-abap-part-4
/people/tobias.trapp/blog/2005/06/15/xml-processing-in-abap--part-5
/people/tobias.trapp/blog/2005/12/08/xml-processing-in-abap--part-6
Regards
Raja
i hope you are aware that XLM transformation can be done in two ways
1. Simple transofrmation (the weblogs i have mentioned refers to that as you have used ST in your example)
2. XSLT
05-17-2006 11:31 AM
Hello.
Thank you for all the links.
Durairaj you said this is only for converting xml to abap, but why cant i use it for the opposite? What needs to be different?
I tryed using ('ID') like u said but the xml_string came out empty.
Thank you
Nuno Silva
05-17-2006 11:43 AM
try this sample code to see whether it works.
( ihave tested and it works)
REPORT Y_TEST_XML.
data: xml_string type string .
data: itab type standard table of sflight .
select * from sflight into table itab .
CALL TRANSFORMATION (`ID`)
SOURCE flights = itab[]
RESULT XML xml_string.
<i>Durairaj you said this is only for converting xml to abap, but why cant i use it for the opposite? What needs to be different?</i>
you need a different ST for that
Regards
Raja
05-17-2006 12:23 PM
Hello.
Thank you for all the help.
You say i need a diferent ST, but different in what way? What do i need to change in this one so it will work?
I tested an example from help.sap wich is identical (the difference is it uses a table of i instead of a defined table) and it worked.
Thank you
Nuno Silva
05-17-2006 12:33 PM
Hi Nuno,
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.
*----
Convert to TABLE
CALL FUNCTION 'HR_EFI_CONVERT_STRING_TO_TABLE'
EXPORTING
i_string = xml_out
i_tabline_length = 100
TABLES
et_table = 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.
05-17-2006 1:02 PM
my knowledge on ST is limited, can you check the weblogs i have mentioned.
Regards
Raja
05-18-2006 6:41 PM
Can anyone help me figuring why am i getting that exception?
Thank you
Nuno Silva
10-12-2006 7:07 PM
Hi Nuno, This is little irrelevant. All I want to know is the use of the command <ZLS> as used by you.
Thanks n regards, Prerna
You can reply to me at prerna.tatia@pseg.com