SAP transformation
Hi,
Is there any standard SAP transformation to convert XML string to ABAP internal table.
Thanks,
Shiva
Are you looking for the "ID" transformation : http://help.sap.com/abapdocu/en/ABENABAP_XSLT_ASXML.htm
For example:
DATA : BEGIN OF l_x2,
AAAA type string,
END OF l_x2.
DATA l_xml TYPE string.
l_xml = '<?xml version="1.0" encoding="iso-8859-1"?><asx:ab'
& 'ap xmlns:asx="http://www.sap.com/abapxml" ver'
& 'sion="1.0"><asx:values><ZZZ><AAAA>Value1</AAAA></ZZZ>'
& '</asx:values></asx:abap>'.
CALL TRANSFORMATION id
SOURCE XML l_xml
RESULT zzz = l_x2.
ASSERT l_x2-aaaa = 'Value1'.
Similar Messages
-
ABAP SYNTAX ERROR IN STANDARD SAP TRANSFORMATION
Hi experts, I am facing a problem while activating a transformation for the cube 0CCA_C11. I installed the flow in 3.5 and wen i was migrating the flow, i first migrated the update rule. At that time, the transformation is giving me " syntax error in the routine" for the infoobject 0CO_REPLINE. The eroor message is given below:
E:The type "_TY_S_SC_1_FULL" is unknown, but there is a type with the similar name "_TY_S_TG_1_FULL". "_TY_S_TG_1_FULL".Hi,
Please check routine if any for 0CO_REPLINE and also expert routine.
Regards,
Rema. -
ABAP transformation to XML for sap chart engine with internal table
Hello.
I am new to the SAP chart engine, XML and transformations so please be patient with me from an ABAP-program I am trying to call a Z-transformation and attach an internal table with two columns. In the ST program I want to loop through the table and for each row insert the two values from the table in the XML.
In an ABAP-program I have an internal table containing datacoordinates for a scattered chart.
The table looks like this:
DATA: BEGIN OF coordinate,
x_value TYPE f,
y_value TYPE f,
END OF coordinate,
polygon_data LIKE STANDARD TABLE OF coordinate with header line.
As a prototype I just add a few coordinates like this:
polygon_data-x_value = '700'.
polygon_data-y_value = '8'.
APPEND polygon_data.
polygon_data-x_value = '1400'.
polygon_data-y_value = '3'.
APPEND polygon_data.
polygon_data-x_value = '1400'.
polygon_data-y_value = '10'.
APPEND polygon_data.
polygon_data-x_value = '700'.
polygon_data-y_value = '10'.
APPEND polygon_data.
polygon_data-x_value = '700'.
polygon_data-y_value = '3'.
APPEND polygon_data.
I have created a Z-transformation and I call it like this (I also have a separate transformation for all the customizing generated with SAP chart designer but that one works fine):
DATA: data_xml TYPE xstring.
CALL TRANSFORMATION ztest_ce_tables2xml
SOURCE polygon_data = polygon_data
RESULT XML data_xml.
Since I am trying to create a scattered chart I need to insert an X and Y value for each coordinate.In the manual SAP Chart engine - XML format description it looks like this:
<ChartData>
<Series>
<Point>
<Value type="x">1</Value>
<Value type="y">1</Value>
</Point>
<Point>
<Value type="x">2</Value>
<Value type="y">2</Value>
</Point>
My ST-program that I cannot get to work looks like below. How can I loop through my internal table and get the X and thy Y value for each row in my internal table?
BR Tommy (Sweden)
<?sap.transform simple?>
<tt:transform xmlns:tt="http://www.sap.com/transformation-templates">
<tt:root name="POLYGON_DATA"/>
<tt:template>
<ChartData>
<Series>
<tt:loop ref=".POLYGON_DATA">
<Point>
<Value type="x"><tt:copy ref=".POLYGON_DATA.X_VALUE"/></Value>
<Value type="y"><tt:copy ref=".POLYGON_DATA.Y_VALUE"/></Value>
</Point>
</tt:loop>
</Series>
</ChartData>
</tt:template>
</tt:transform>Hello again.
I found the solution and would like to share it with the forum, maybe it could help someone.
My first error was in the call transformation statement:
CALL TRANSFORMATION ztest_ce_tables2xml
SOURCE polygon_data = polygon_data [] <----
Do not forget these
RESULT XML data_xml.
I also had an error in the ST program, it should look like this:
<?sap.transform simple?>
<tt:transform xmlns:tt="http://www.sap.com/transformation-templates">
<tt:root name="POLYGON_DATA"/>
<tt:template>
<ChartData>
<Series>
<tt:loop ref=".POLYGON_DATA">
<Point>
<Value type="x"><tt:value ref="$ref.X_VALUE"/></Value>
<Value type="y"><tt:value ref="$ref.Y_VALUE"/></Value>
</Point>
</tt:loop>
</Series>
</ChartData>
</tt:template>
</tt:transform> -
Xslt transformation using SAP BC 47
Hi,
I'm trying to do a transformation using the sap transformation package in the SAP BC ( rel 47 )
I'm transforming an IDOC into a cXML order for example...
The transformed xml contains some rather odd characters...
Even a very simple xslt has these odd characters...
directly after the DOCTYPE
I'm using MapForce to create the xslt..
Has anyone else experienced these issues?
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE cXML SYSTEM "....."[
]>
<cXML payloadID="2005081645000002780916170000000000004039" timestamp="2005-08-16T09:16:17+0.00">
<Header>
<From>Hi,
according to:
>
Michal_Krawczyk_PIXI wrote:
> as per:
> http://help.sap.com/saphelp_470/helpdata/EN/84/2e4d3ce624b800e10000000a114084/frameset.htm
> "The href attribute no longer applies in this case."
it appears the include element only works with the repository.... I tried
<xsl:include sap:name="<Name_of_the_Transformation_in_Repository>"/>
and it works.
However this would mean, all includes i have to make have to be imported to the repository. If that's really the case, it'll be a huge problem, because the xsl-files i want to include are outside of my reference
Regards, Lukas -
Using Simple Transformations with Objects tt:copy .. results in Exception
Question:
How can I serialize an ABAP-Object-Instanz with my own simple transformation?
In the sap-documentation I found the following solution for the serialisation of any data-objects.
"z_steffens_simple_transf":
<?sap.transform simple?>
<tt:transform xmlns:tt="http://www.sap.com/transformation-templates">
<tt:root name="ROOT"/>
<tt:template>
<root>
<tt:copy ref="ROOT"/>
</root>
</tt:template>
</tt:transform>
Following the example I wrote this report:
report zspahr_test_simple_transf.
class serializable definition.
public section.
interfaces if_serializable_object.
data attr type string value 'Attribute'.
endclass.
method main_serializable.
data: oref type ref to serializable,
xmlstr type xstring.
create object oref.
call transformation id
source root = oref
result xml xmlstr.
call function 'DISPLAY_XML_STRING'
exporting
xml_string = xmlstr.
call transformation z_steffens_simple_object
source root = oref
result xml xmlstr.
call function 'DISPLAY_XML_STRING'
exporting
xml_string = xmlstr.
endmethod. "main_
start-of-selection.
demo=>main_serializable( ).
Executing this report leads to an exception "CX_SY_REF_NOT_SUPPORTED".
The "standard" transformation "ID" ist working an translates my object-instance into an asXML representation:
<?xml version="1.0" encoding="utf-8" ?>
- <asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
- <asx:values>
<ROOT href="#o3" />
</asx:values>
- <asx:heap xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:abap="http://www.sap.com/abapxml/types/built-in" xmlns:cls="http://www.sap.com/abapxml/classes/global" xmlns:dic="http://www.sap.com/abapxml/types/dictionary">
- <prg:SERIALIZABLE xmlns:prg="http://www.sap.com/abapxml/classes/program/ZSPAHR_TEST_SIMPLE_TRANSF" id="o3">
- <local.SERIALIZABLE>
<ATTR>Attribute</ATTR>
</local.SERIALIZABLE>
</prg:SERIALIZABLE>
</asx:heap>
</asx:abap>
How can I do this with my own Simple Transformation "ZSPAHR_TEST_SIMPLE_TRANSF" ?
I want to serialize my object using my own xml-structure, not the asXML-structure !
Regards
SteffenHi,
try like this,i think it may help you.
ABAP:
CALL TRANSFORMATION ztrans_test
SOURCE
root = partab
RESULT XML lv_xstring.
Trnsformation:
<tt:root name="ROOT" type="?"/>
<tt:template>
<VALUES>
<VALUE_SOURCE>
<tt:value ref=".ROOT"/>
</VALUE_SOURCE>
<VALUE_PARAM>
<tt:value ref="NAME"/>
<tt:value ref="VALUE"/>
</VALUE_PARAM>
</VALUES>
Thanks,
Rajesh. -
How to escape special characters in Simple Transformation
Hi Experts,
I have got a problem to get a well formed xml document from the below simple transformation. The content of maktx contains
special characters like & <, which are not allowed in a well formed XML-Document. But the result of the Simple Transformation
contains this charcters even after the transformation as you can the in the result below. Has anyone a hint how to escape the
characters included in the maktx.
The transformation for maktx, should be something like
Before: Material & < TEST
After: Material & < TEST
Report wihich calls the simple transformation
types:
BEGIN OF t_mat,
matnr type matnr,
maktx type maktx,
end of t_mat.
Data:
mat type t_mat,
xml_stream type xstring.
START-OF-SELECTION.
mat-matnr = '4711'.
mat-maktx = 'Material & < Test'.
CALL TRANSFORMATION ztest_st2
SOURCE mat = mat
RESULT XML xml_stream.
CALL FUNCTION 'DISPLAY_XML_STRING'
EXPORTING xml_string = xml_stream.
Simple Transformation
<?sap.transform simple?>
<tt:transform xmlns:tt="http://www.sap.com/transformation-templates">
<tt:root name="MAT"/>
<tt:template>
<Leistungsschild>
<CHARACT> MATNR </CHARACT>
<CHARACT_DESCR> Materialnummer </CHARACT_DESCR>
<VALUE tt:value-ref="MAT.MATNR"/>
<CHARACT> MAKTX </CHARACT>
<CHARACT_DESCR> Materialkurztext </CHARACT_DESCR>
<VALUE tt:value-ref="MAT.MAKTX" />
</Leistungsschild>
</tt:template>
</tt:transform>
RESULT
<?xml version="1.0" encoding="utf-8" ?>
<Leistungsschild>
<CHARACT>MATNR</CHARACT>
<CHARACT_DESCR>Materialnummer</CHARACT_DESCR>
<VALUE>4711</VALUE>
<CHARACT>MAKTX</CHARACT>
<CHARACT_DESCR>Materialkurztext</CHARACT_DESCR>
<VALUE>Material & < Test</VALUE> </Leistungsschild>Hi Sandra,
First of all thaks for your quick answer to my problem.
I see what you mean and get the same result, if I am using data-type string instead of xstring. But the recommendation in the XML-Books of SAP is to use XSTRING to save memory and circumflex problems between Codepages, when writing the XML-Stream to a filesystem.
As you can see in the code abvoe I am using a SAP-FM to display the XML-Stream and this FM works only with XSTRING´s,
that is one reason why I don´t understand that it displays it in the wrong way.
Even the Debugger shows me for the XSTRING the wrong result. Does all that mean that the escaping will not be applyed if you are working with XSTING´s?? -
Simple Transformation ST, upload xml file to internal table
Hi.
I want to upload some parts of an xml file into an sap internal table, especially the part "trackingnumber" which can occur several times.
the xml looks like this:
<?xml version="1.0" encoding="windows-1252"?>
<OpenShipments xmlns="x-schema:OpenShipments.xdr">
<OpenShipment ProcessStatus="Processed">
<ShipTo>
</ShipTo>
<ShipFrom>
</ShipFrom>
<ShipmentInformation>
</ShipmentInformation>
<Package>
</Package>
<InternationalDocumentation>
</InternationalDocumentation>
<Goods>
</Goods>
<ProcessMessage>
<TrackingNumbers>
<TrackingNumber>1Z1234563330702444</TrackingNumber>
<TrackingNumber>1Z1234566644402555</TrackingNumber>
</TrackingNumbers>
</ProcessMessage>
</OpenShipment>
</OpenShipments>
The ST looks like this:
<?sap.transform simple?>
<tt:transform xmlns:tt="http://www.sap.com/transformation-templates">
<tt:root name="ROOT"/>
<tt:template>
<OpenShipments xmlns="x-schema:OpenShipments.xdr">
<OpenShipment>
<ShipTo>
<tt:skip/>
</ShipTo>
<ShipFrom>
<tt:skip/>
</ShipFrom>
<ShipmentInformation>
<tt:skip/>
</ShipmentInformation>
<tt:group>
<tt:cond frq="*">
<Package>
<tt:skip/>
</Package>
</tt:cond>
</tt:group>
<InternationalDocumentation>
<tt:skip/>
</InternationalDocumentation>
<tt:group>
<tt:cond frq="*">
<Goods>
<tt:skip/>
</Goods>
</tt:cond>
</tt:group>
<ProcessMessage>
<ShipmentRates>
<tt:skip/>
</ShipmentRates>
<TrackingNumbers>
<tt:group>
<tt:cond frq="*">
<TrackingNumber>
<tt:loop ref="ROOT">
<tt:value ref="ROOT" />
</tt:loop>
</TrackingNumber>
</tt:cond>
</tt:group>
</TrackingNumbers>
<ImportID>
<tt:skip/>
</ImportID>
<Reference1>
<tt:skip/>
</Reference1>
<Reference2>
<tt:skip/>
</Reference2>
</ProcessMessage>
</OpenShipment>
</OpenShipments>
</tt:template>
</tt:transform>
The ABAP Code looks like this:
REPORT z_xml_to_abap_test.
TYPES: t_xmllin_src(4096) TYPE x,
t_xmltab_src TYPE STANDARD TABLE OF t_xmllin_src.
DATA: xmlstr_src TYPE xstring,
xmltab_src TYPE t_xmltab_src,
result1(254) TYPE c,
BEGIN OF ROOT,
TrackingNumber(254) type c,
END OF ROOT.
FIELD-SYMBOLS: <xmlline> LIKE LINE OF xmltab_src.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = 'e:\20100601_132212.Out'
filetype = 'BIN'
has_field_separator = ''
header_length = 0
read_by_line = 'X'
IMPORTING
FILELENGTH =
HEADER =
TABLES
data_tab = xmltab_src
EXCEPTIONS
file_open_error = 1
file_read_error = 2
no_batch = 3
gui_refuse_filetransfer = 4
invalid_type = 5
no_authority = 6
unknown_error = 7
bad_data_format = 8
header_not_allowed = 9
separator_not_allowed = 10
header_too_long = 11
unknown_dp_error = 12
access_denied = 13
dp_out_of_memory = 14
disk_full = 15
dp_timeout = 16
OTHERS = 17.
LOOP AT xmltab_src ASSIGNING <xmlline>.
CONCATENATE xmlstr_src <xmlline> INTO xmlstr_src IN BYTE MODE.
ENDLOOP.
CALL TRANSFORMATION z_ups_xml_upload
SOURCE XML xmlstr_src
RESULT ROOT = ROOT.
When i run the program i got the following error message:
"The goal was to access variable "ROOT". However, this access was not possible.
Anybody has an idea, why this happens, this is my first ST and have no clue at the moment why this happens?Hi.
I want to upload some parts of an xml file into an sap internal table, especially the part "trackingnumber" which can occur several times.
the xml looks like this:
<?xml version="1.0" encoding="windows-1252"?>
<OpenShipments xmlns="x-schema:OpenShipments.xdr">
<OpenShipment ProcessStatus="Processed">
<ShipTo>
</ShipTo>
<ShipFrom>
</ShipFrom>
<ShipmentInformation>
</ShipmentInformation>
<Package>
</Package>
<InternationalDocumentation>
</InternationalDocumentation>
<Goods>
</Goods>
<ProcessMessage>
<TrackingNumbers>
<TrackingNumber>1Z1234563330702444</TrackingNumber>
<TrackingNumber>1Z1234566644402555</TrackingNumber>
</TrackingNumbers>
</ProcessMessage>
</OpenShipment>
</OpenShipments>
The ST looks like this:
<?sap.transform simple?>
<tt:transform xmlns:tt="http://www.sap.com/transformation-templates">
<tt:root name="ROOT"/>
<tt:template>
<OpenShipments xmlns="x-schema:OpenShipments.xdr">
<OpenShipment>
<ShipTo>
<tt:skip/>
</ShipTo>
<ShipFrom>
<tt:skip/>
</ShipFrom>
<ShipmentInformation>
<tt:skip/>
</ShipmentInformation>
<tt:group>
<tt:cond frq="*">
<Package>
<tt:skip/>
</Package>
</tt:cond>
</tt:group>
<InternationalDocumentation>
<tt:skip/>
</InternationalDocumentation>
<tt:group>
<tt:cond frq="*">
<Goods>
<tt:skip/>
</Goods>
</tt:cond>
</tt:group>
<ProcessMessage>
<ShipmentRates>
<tt:skip/>
</ShipmentRates>
<TrackingNumbers>
<tt:group>
<tt:cond frq="*">
<TrackingNumber>
<tt:loop ref="ROOT">
<tt:value ref="ROOT" />
</tt:loop>
</TrackingNumber>
</tt:cond>
</tt:group>
</TrackingNumbers>
<ImportID>
<tt:skip/>
</ImportID>
<Reference1>
<tt:skip/>
</Reference1>
<Reference2>
<tt:skip/>
</Reference2>
</ProcessMessage>
</OpenShipment>
</OpenShipments>
</tt:template>
</tt:transform>
The ABAP Code looks like this:
REPORT z_xml_to_abap_test.
TYPES: t_xmllin_src(4096) TYPE x,
t_xmltab_src TYPE STANDARD TABLE OF t_xmllin_src.
DATA: xmlstr_src TYPE xstring,
xmltab_src TYPE t_xmltab_src,
result1(254) TYPE c,
BEGIN OF ROOT,
TrackingNumber(254) type c,
END OF ROOT.
FIELD-SYMBOLS: <xmlline> LIKE LINE OF xmltab_src.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = 'e:\20100601_132212.Out'
filetype = 'BIN'
has_field_separator = ''
header_length = 0
read_by_line = 'X'
IMPORTING
FILELENGTH =
HEADER =
TABLES
data_tab = xmltab_src
EXCEPTIONS
file_open_error = 1
file_read_error = 2
no_batch = 3
gui_refuse_filetransfer = 4
invalid_type = 5
no_authority = 6
unknown_error = 7
bad_data_format = 8
header_not_allowed = 9
separator_not_allowed = 10
header_too_long = 11
unknown_dp_error = 12
access_denied = 13
dp_out_of_memory = 14
disk_full = 15
dp_timeout = 16
OTHERS = 17.
LOOP AT xmltab_src ASSIGNING <xmlline>.
CONCATENATE xmlstr_src <xmlline> INTO xmlstr_src IN BYTE MODE.
ENDLOOP.
CALL TRANSFORMATION z_ups_xml_upload
SOURCE XML xmlstr_src
RESULT ROOT = ROOT.
When i run the program i got the following error message:
"The goal was to access variable "ROOT". However, this access was not possible.
Anybody has an idea, why this happens, this is my first ST and have no clue at the moment why this happens? -
Upload xml file to internal table only using simple transformation
Hi Friends
How to write transformation code for the following xml data.. Please let me know immedately if any one know..
I have written as following but i encountered an eror staating -
Iam facing the following error
An exception occurred that is explained in detail below.
The exception, which is assigned to class 'CX_ST_REF_ACCESS', was not caught in
procedure "UPLOAD_XML" "(FORM)", nor was it propagated by a RAISING clause.
Since the caller of the procedure could not have anticipated that the
exception would occur, the current program is terminated.
The reason for the exception is:
The goal was to access variable "ROOT1". However, this access was not
possible.
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
DeviHi Friends
How to write transformation code for the following xml data.. Please let me know immedately if any one know..
I have written as following but i encountered an eror staating -
Iam facing the following error
An exception occurred that is explained in detail below.
The exception, which is assigned to class 'CX_ST_REF_ACCESS', was not caught in
procedure "UPLOAD_XML" "(FORM)", nor was it propagated by a RAISING clause.
Since the caller of the procedure could not have anticipated that the
exception would occur, the current program is terminated.
The reason for the exception is:
The goal was to access variable "ROOT1". However, this access was not
possible.
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 -
Simple transformation : deserialize
Hi,
I have a simple transformation that works if I serialize table data, but it doesn't work when I wan't to deserialize.
Here is my ABAP program that calls the transformation:
TYPES: BEGIN OF flight,
f_id TYPE p LENGTH 5,
data TYPE c LENGTH 40,
END OF flight,
tt_flight TYPE STANDARD TABLE OF flight
WITH DEFAULT KEY.
DATA: data1 TYPE flight.
DATA: data2 TYPE flight.
DATA: xml_string TYPE string.
DATA: tab_data TYPE tt_flight.
data1-f_id = '00001'.
data1-data = 'before'.
APPEND data1 to tab_data.
data2-f_id = '00002'.
data2-data = 'before'.
APPEND data2 to tab_data.
concatenate '<?xml version="1.0" encoding="iso-8859-2"?><XY><flights>'
'<flight><id>11111</id><data>data1</data></flight>'
'<flight><id>22222</id><data>data2</data></flight>'
'</flights></XY>'
into xml_string.
CALL TRANSFORMATION ...
SOURCE XML xml_string
RESULT root = tab_data.
And the transformation:
<?sap.transform simple?>
<tt:transform xmlns:tt="http://www.sap.com/transformation-templates" template="temp_main">
<tt:root name="ROOT"/>
<tt:template name="temp_main">
<XY>
<flights>
<tt:loop name="line" ref="ROOT">
<flight>
<id>
<tt:value ref="f_id"/>
</id>
<data>
<tt:value ref="data">
</data>
</flight>
</tt:loop>
</flights>
</XY>
</tt:template>
</tt:transform>
It won't update or append the content of the xml to my table.
I would like to read many "<flight><id>.....</id><data>......</data></flight>" lines and write them into the table "tab_data".
Could somebody please help me?
Thanks in advance,
GregHi Greg,
try to address the root node with a period. Instead of
<tt:loop name="line" ref="ROOT">
use
<tt:loop name="line" ref=".ROOT">
Regards
Stephan -
Simple Transformation - ABAP 2 XML
Dear all,
Finally I was able to transform an internal table to xml using ST. The question is: Can I create different structured XML-files using the same (structured) internal table. Or is there some kind of a 1:1 relationship (between an ITAB structure + XML structure)?
1) Data declaration
TYPES: BEGIN OF ty_curr,
tcurr TYPE tcurr_curr,
gdatu TYPE gdatu_inv,
ukurs TYPE ukurs_curr.
TYPES: END OF ty_curr.
DATA: gt_tcurr TYPE TABLE OF ty_curr.
2) Data selection
Select * into corresponding fields of table gt_tcurr from tcurr where...
3) Transformation ABAP 2 XML
CALL TRANSFORMATION z_tcurr
SOURCE root = gt_tcurr
RESULT XML g_xml_string.
<?sap.transform simple?>
<tt:transform xmlns:tt="http://www.sap.com/transformation-templates">
<tt:root name="ROOT"/>
<tt:template>
<tt:serialize>
<rates>
<tt:loop name="line" ref=".ROOT">
<currency>
<tt:value ref="$line.tcurr"/>
</currency>
<date>
<tt:value ref="$line.gdatu"/>
</date>
<rate>
<tt:value ref="$line.ukurs"/>
</rate>
</tt:loop>
</rates>
</tt:serialize>
</tt:template>
</tt:transform>
Result (XML)
<?xml version="1.0" encoding="utf-8" ?>
- <rates>
<currency>USD</currency>
<date>01.01.2010</date>
<rate>-1.1868</rate>
<currency>EUR</currency>
<date>01.01.2010</date>
<rate>-1.1791</rate>
<currency>USD</currency>
<date>02.01.2010</date>
<rate>-1.1864</rate>
<currency>EUR</currency>
<date>02.01.2010</date>
<rate>-1.1864</rate>
</rates>:
so far so good... BUT; if I want to get another XML structure
Example 1) -> sorted by currency
<?xml version="1.0" encoding="utf-8" ?>
- <rates>
<currency>USD
<date>01.01.2010</date>
<rate>-1.1868</rate>
<date>02.01.2010</date>
<rate>-1.1868</rate>
</currency>
<currency>EUR
<date>01.01.2010</date>
<rate>-1.1868</rate>
<date>02.01.2010</date>
<rate>-1.1868</rate>
</currency>
</rates>
Example 2) -> sored by date
<?xml version="1.0" encoding="utf-8" ?>
- <rates>
<date>01.01.2010</date>
<currency>USD</currency>
<rate>-1.1868</rate>
<currency>EUR</currency>
<rate>-1.1868</rate>
<date>02.01.2010</date>
<currency>USD</currency>
<rate>-1.1868</rate>
<currency>EUR</currency>
<rate>-1.1868</rate>
</rates>
How can I achieve output example 1+2 using the same internal table as a source? Is this possible? I guess this can be solved within the transformation, right? Any help appreciated.
Best regards
BennoThanks for all answers so far. Changing the sequence is not a "problem". What I want to achieve is to change hierarchy of the xml. I'll try to explain again with a simple example:
ITAB (structure):
name; birthday; ***; first name
ITAB (content):
Smith; 01.01.1970; M; Paul
Smith; 01.01.1970; F; Stefanie
Smith; 01.02.1980; F; Barbara
White; 01.02.1980; M; Steve
I want to pass the itab exactly the way it is (ok, sorting is allowed). Question: Can I achieve the following XML's using ST? I guess/hope this can be solved with variables/groups/condition statements within the transformation coding?
Example xml- 1) Sorted/Grouped by Name/***
<person>
<name>Smith
<***>M
<birthday>01.01.1970</birthday><first name>Paul</first name>
</***>
<***>F
<birthday>01.01.1970</birthday><first name>Stefanie</first name>
<birthday>01.02.1980</birthday><first name>Barbara</first name>
</***>
</name>
<name>White
<***>M
<birthday>01.02.1980</birthday><first name>Steve</first name>
</***>
</name>
</person>
Exampe xml-2 ) Sorted/Grouped by Birthday (Names only)
<person>
<birthday>01.01.1970
<first name>Paul</first name>
<first name>Stefanie</first name>
</birthday>
<birthday>01.02.1980
<first name>Barbara</first name>
<first name>Steve</first name>
</birthday>
</person> -
Simple Transformation - XML to Internal Table Error
I have a webservice call that returns XML. I need to transform a portion of the response to an internal table, but my simple transformation is not working with loop processing. I have read through most posts regarding the topic but they're either too old or related to serialization. There aren't any exceptions thrown, but I don't get any data in the internal table (PAPERWORK root). Below are some code snippets. Any ideas on the problem with the XSLT template? Thanks.
Sample XML:
<?xml version="1.0" encoding="utf-8" ?>
<PrintVersionDataSet>
<Result>
<ReturnCode>W</ReturnCode>
<ReturnMessage>There are reports with later version(s)</ReturnMessage>
</Result>
<Paperwork>
<ReportCode>CVR</ReportCode>
<ReportName>Cover Sheet</ReportName>
<Version>2</Version>
<PrintedDateTime>2009-05-01T09:54:04.1-05:00</PrintedDateTime>
</Paperwork>
<Paperwork>
<ReportCode>SPS</ReportCode>
<ReportName>Sponsor Summary</ReportName>
<Version>2</Version>
<PrintedDateTime>2009-05-01T09:54:04.99-05:00</PrintedDateTime>
</Paperwork>
</PrintVersionDataSet>
XSLT Code:
<?sap.transform simple?>
<tt:transform xmlns:tt="http://www.sap.com/transformation-templates">
<tt:root name="RESULT"/>
<tt:root name="PAPERWORK"/>
<tt:template>
<PrintVersionDataSet>
<Result tt:ref="RESULT">
<ReturnCode>
<tt:value ref="RETURNCODE"/>
</ReturnCode>
<ReturnMessage>
<tt:value ref="RETURNMESSAGE"/>
</ReturnMessage>
</Result>
<tt:deserialize>
<tt:loop ref=".PAPERWORK">
<Paperwork>
<ReportCode>
<tt:value ref="REPORTCODE"/>
</ReportCode>
<ReportName>
<tt:value ref="REPORTNAME"/>
</ReportName>
<Version>
<tt:value ref="VERSION"/>
</Version>
<PrintedDateTime>
<tt:value ref="PRINTEDDATETIME"/>
</PrintedDateTime>
</Paperwork>
</tt:loop>
</tt:deserialize>
</PrintVersionDataSet>
</tt:template>
</tt:transform>
ABAP Call to Transform Data:
TRY.
CALL TRANSFORMATION Z_GA_PAPERWORK_VERS_WEBSVC
SOURCE XML LS_RESPONSE-VERIFY_PRINT_VERSION_RESULT
RESULT RESULT = LS_RESULT
PAPERWORK = LT_PAPERWORK.
CATCH CX_ROOT INTO ROOT_EXCEPTION.
CALL METHOD ROOT_EXCEPTION->IF_MESSAGE~GET_TEXT
RECEIVING
RESULT = LV_MESSAGE.
ENDTRY.Upon further inspection and testing with a simple file and program, I can see that the XML structure isn't quite correct for the loop process. There needs to be a single <PAPERWORK> node, instead of one for each table line in the file. This should allow the loop to execute properly after a slight adjustment to the XSLT template.
-
Simple Transformation from ABAP to XML and back
Hi experts,
Can anyone provide me a simple example of a 'simple transformation' that will convert and internal table with more than one column into XML via a simple transformation.
I've spend days now reading SAP help and e-learning examples, but this just won't work and I am getting short dumps saying 'The goal was to access variable "ROOT". However, this access was notv possible.'
Here is my ABAP:
data: begin of struc,
counter type i,
aname type string,
aname2 type string,
end of struc.
data: cnt_c type c.
data: itab like table of struc with HEADER LINE,
xml_string type xstring.
do 3 times.
move sy-index to: itab-counter, cnt_c.
concatenate 'nameA' cnt_c into itab-aname.
concatenate 'nameB' cnt_c into itab-aname2.
append itab.
enddo.
CALL TRANSFORMATION Z_ST_TEST5
SOURCE ROOT = itab
RESULT XML xml_string.
CALL FUNCTION 'DISPLAY_XML_STRING'
EXPORTING
XML_STRING = xml_string.
skip 1.
and here is my ST:
<?sap.transform simple?>
<tt:transform xmlns:tt="http://www.sap.com/transformation-templates">
<tt:root name="ROOT"/>
<tt:template>
<TABLE>
<tt:loop ref=".ROOT" name="line">
<ITEM>
<counter>
<tt:value ref="$line.aname" />
</counter>
<name>
<tt:value ref="$line.aname" />
</name>
<name2>
<tt:value ref="$line.aname2" />
</name2>
</ITEM>
</tt:loop>
</TABLE>
</tt:template>
</tt:transform>Figured it out. The interla tables used in teh call transformation statement can never have a header line.
-
Simple Transformation XML to ABAP - error CX_ST_MATCH_ELEMENT
Hi all,
I have a problem with a transformation from xml to abap. My XML file (taken from a pdf file) is
<?xml version="1.0" encoding="iso-8859-1" ?>
- <asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
- <asx:values>
<NETWORK>E60000000000</NETWORK>
<OPERAZIONE>0010</OPERAZIONE>
- <TABELLA>
- <ROW xmlns:xfa="http://www.xfa.org/schema/xfa-data/1.0/" xfa:dataNode="dataGroup">
<MANDT>300</MANDT>
<NETWORK>E60000000000</NETWORK>
<OPERAZIONE>0010</OPERAZIONE>
<ID_ACT>1</ID_ACT>
<DESC_ACT>ATTIVITÀ1</DESC_ACT>
<LONG_TXT></LONG_TXT>
<MAKE_BUY></MAKE_BUY>
<WP></WP>
<EVENTO_TECH></EVENTO_TECH>
<TIPO_LEGAME></TIPO_LEGAME>
<CONSEGNA></CONSEGNA>
</ROW>
- <ROW xmlns:xfa="http://www.xfa.org/schema/xfa-data/1.0/" xfa:dataNode="dataGroup">
<MANDT>300</MANDT>
<NETWORK>E60000000000</NETWORK>
<OPERAZIONE>0010</OPERAZIONE>
<ID_ACT>2</ID_ACT>
<DESC_ACT>ATTIVITÀ2</DESC_ACT>
<LONG_TXT>ATTIVITÀ2 ATTIVITÀ2 ATTIVITÀ2 ATTIVITÀ2 ATTIVITÀ2 ATTIVITÀ2 ATTIVITÀ2 ATTIVITÀ2 ATTIVITÀ2 ATTIVITÀ2 ATTIVITÀ2</LONG_TXT>
<MAKE_BUY>M</MAKE_BUY>
<WP></WP>
<EVENTO_TECH></EVENTO_TECH>
<TIPO_LEGAME></TIPO_LEGAME>
<CONSEGNA></CONSEGNA>
</ROW>
</TABELLA>
</asx:values>
</asx:abap>
my transformation is
<?sap.transform simple?>
<tt:transform xmlns:tt="http://www.sap.com/transformation-templates">
<tt:root name="ROOT"></tt:root>
<tt:root name="NETWORK"></tt:root>
<tt:root name="OPERAZIONE"></tt:root>
<tt:template>
<abap>
<values>
<network>
<tt:value ref="NETWORK"></tt:value>
</network>
<operazione>
<tt:value ref="OPERAZIONE"></tt:value>
</operazione>
<tabella>
<tt:loop ref=".ROOT" name="line">
<mandt>
<tt:value ref="$line.mandt"></tt:value>
</mandt>
<network>
<tt:value ref="$line.network"></tt:value>
</network>
<OPERAZIONE>
<tt:value ref="$line.OPERAZIONE"></tt:value>
</OPERAZIONE>
<ID_ACT>
<tt:value ref="$line.ID_ACT"></tt:value>
</ID_ACT>
<DESC_ACT>
<tt:value ref="$line.DESC_ACT"></tt:value>
</DESC_ACT>
<LONG_TXT>
<tt:value ref="$line.LONG_TXT"></tt:value>
</LONG_TXT>
<MAKE_BUY>
<tt:value ref="$line.MAKE_BUY"></tt:value>
</MAKE_BUY>
<WP>
<tt:value ref="$line.WP"></tt:value>
</WP>
<EVENTO_TECH>
<tt:value ref="$line.EVENTO_TECH"></tt:value>
</EVENTO_TECH>
<TIPO_LEGAME>
<tt:value ref="$line.TIPO_LEGAME"></tt:value>
</TIPO_LEGAME>
<CONSEGNA>
<tt:value ref="$line.CONSEGNA"></tt:value>
</CONSEGNA>
</tt:loop>
</tabella>
</values>
</abap>
</tt:template>
</tt:transform>
when I execute my code
the system dump with this error
ST_MATCH_FAIL
excep. CX_ST_MATCH_ELEMENT
TRY.
CALL TRANSFORMATION ('ZT_NETWORK')
SOURCE XML lv_xml_data_string
RESULT network = l_network
operazione = l_operazione
root = it_data_tmp.
CATCH cx_sy_conversion_data_loss .
CATCH cx_xslt_exception INTO xslt_error.
xslt_message = xslt_error->get_text( ).
WRITE:/ xslt_message .
ENDTRY.
Any help?
thanks
enzoEnzo Porcasi wrote:
> I have a problem with a transformation from xml to abap. My XML file (taken from a pdf file) is
>
<?xml version="1.0" encoding="iso-8859-1" ?>
> <asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
> <asx:values>
Your XML is strange, it looks like a mix of pdf form content (xfa) and identity transformation (asx).
Could you explain more ?
Anyway, I tried to find out the errors (not only cx_st_match_element, that was just a catch missing), it works with the following program. Here are the main issues I have found :
- always catch exception class cx_st_error when you use simple transformations (it contains cx_st_match_element and all other simple transformation exceptions)
- xml "asx:abap" and "asx:values" in your input XML are useless, they are only used by identity transformation ("ID"); you may keep them if you want, but I advise you to see why they are in the xml !
- Use same case in your tags (if xml contains in the transformation so that it corresponds to the input XML
- I renamed all abap names with prefix ABAP_ so that to clearly differentiate xml tags and abap field names (so that it is more easy to understand, for every sdn reader; I hope it will help as I didn't find many threads in the forum).
Simple transformation :
<?sap.transform simple?>
<tt:transform xmlns:tt="http://www.sap.com/transformation-templates">
<tt:root name="ABAP_NETWORK"></tt:root>
<tt:root name="ABAP_OPERAZIONE"></tt:root>
<tt:root name="ABAP_TABELLA"></tt:root>
<tt:template>
<ROOT>
<NETWORK>
<tt:value ref=".ABAP_NETWORK"></tt:value>
</NETWORK>
<OPERAZIONE>
<tt:value ref=".ABAP_OPERAZIONE"></tt:value>
</OPERAZIONE>
<TABELLA>
<tt:loop ref=".ABAP_TABELLA" name="line">
<ROW>
<MANDT>
<tt:value ref="$line.ABAP_MANDT"></tt:value>
</MANDT>
<NETWORK>
<tt:value ref="$line.ABAP_NETWORK"></tt:value>
</NETWORK>
<OPERAZIONE>
<tt:value ref="$line.ABAP_OPERAZIONE"></tt:value>
</OPERAZIONE>
<ID_ACT>
<tt:value ref="$line.ABAP_ID_ACT"></tt:value>
</ID_ACT>
<DESC_ACT>
<tt:value ref="$line.ABAP_DESC_ACT"></tt:value>
</DESC_ACT>
<LONG_TXT>
<tt:value ref="$line.ABAP_LONG_TXT"></tt:value>
</LONG_TXT>
<MAKE_BUY>
<tt:value ref="$line.ABAP_MAKE_BUY"></tt:value>
</MAKE_BUY>
<WP>
<tt:value ref="$line.ABAP_WP"></tt:value>
</WP>
<EVENTO_TECH>
<tt:value ref="$line.ABAP_EVENTO_TECH"></tt:value>
</EVENTO_TECH>
<TIPO_LEGAME>
<tt:value ref="$line.ABAP_TIPO_LEGAME"></tt:value>
</TIPO_LEGAME>
<CONSEGNA>
<tt:value ref="$line.ABAP_CONSEGNA"></tt:value>
</CONSEGNA>
</ROW>
</tt:loop>
</TABELLA>
</ROOT>
</tt:template>
</tt:transform>
Program and XML included :
REPORT zsro2.
DATA l_network TYPE string.
DATA l_operazione TYPE string.
DATA : BEGIN OF lt_data_tmp OCCURS 0,
abap_mandt TYPE string,
abap_network TYPE string,
abap_operazione TYPE string,
abap_id_act TYPE string,
abap_desc_act TYPE string,
abap_long_txt TYPE string,
abap_make_buy TYPE string,
abap_wp TYPE string,
abap_evento_tech TYPE string,
abap_tipo_legame TYPE string,
abap_consegna TYPE string,
END OF lt_data_tmp.
DATA xslt_error TYPE REF TO cx_xslt_exception.
DATA lo_st_error TYPE REF TO cx_st_error.
DATA lv_xml_data_string TYPE string.
DATA xslt_message TYPE string.
DEFINE conc.
concatenate lv_xml_data_string &1 into lv_xml_data_string.
END-OF-DEFINITION.
*conc '<?xml version="1.0" encoding="iso-8859-1" ?>'.
*conc '<asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">'.
*conc ' <asx:values>'.
conc ' <ROOT>'.
conc ' <NETWORK>E60000000000</NETWORK> '.
conc ' <OPERAZIONE>0010</OPERAZIONE> '.
conc ' <TABELLA>'.
conc ' <ROW xmlns:xfa="http://www.xfa.org/schema/xfa-data/1.0/" xfa:dataNode="dataGroup">'.
conc ' <MANDT>300</MANDT> '.
conc ' <NETWORK>E60000000000</NETWORK> '.
conc ' <OPERAZIONE>0010</OPERAZIONE> '.
conc ' <ID_ACT>1</ID_ACT> '.
conc ' <DESC_ACT>ATTIVITÀ1</DESC_ACT> '.
conc ' <LONG_TXT></LONG_TXT> '.
conc ' <MAKE_BUY></MAKE_BUY> '.
conc ' <WP></WP> '.
conc ' <EVENTO_TECH></EVENTO_TECH> '.
conc ' <TIPO_LEGAME></TIPO_LEGAME> '.
conc ' <CONSEGNA></CONSEGNA> '.
conc ' </ROW>'.
conc ' <ROW xmlns:xfa="http://www.xfa.org/schema/xfa-data/1.0/" xfa:dataNode="dataGroup">'.
conc ' <MANDT>300</MANDT> '.
conc ' <NETWORK>E60000000000</NETWORK> '.
conc ' <OPERAZIONE>0010</OPERAZIONE> '.
conc ' <ID_ACT>2</ID_ACT> '.
conc ' <DESC_ACT>ATTIVITÀ2</DESC_ACT> '.
conc ' <LONG_TXT>ATTIVITÀ2 ATTIVITÀ2 ATTIVITÀ2 ATTIVITÀ2 ATTIVITÀ2 ATTIVITÀ2 ATTIVITÀ2 ATTIVITÀ2 ATTIVITÀ2 ATTIVITÀ2 ATTIVITÀ2</LONG_TXT> '.
conc ' <MAKE_BUY>M</MAKE_BUY> '.
conc ' <WP></WP> '.
conc ' <EVENTO_TECH></EVENTO_TECH> '.
conc ' <TIPO_LEGAME></TIPO_LEGAME> '.
conc ' <CONSEGNA></CONSEGNA> '.
conc ' </ROW>'.
conc ' </TABELLA>'.
conc ' </ROOT>'.
*conc ' </asx:values>'.
*conc '</asx:abap>'.
DATA lv_xml_data_string_2 TYPE string.
TRY.
CALL TRANSFORMATION zsro
SOURCE
XML lv_xml_data_string
RESULT
abap_network = l_network
abap_operazione = l_operazione
abap_tabella = lt_data_tmp[].
CATCH cx_sy_conversion_data_loss .
CATCH cx_st_error INTO lo_st_error.
xslt_message = lo_st_error->get_text( ).
WRITE:/ xslt_message .
CATCH cx_xslt_exception INTO xslt_error.
xslt_message = xslt_error->get_text( ).
WRITE:/ xslt_message .
ENDTRY.
BREAK-POINT. -
Simple Transformation XML to ABAP Content of tag with subtrees to string field
Hi,
I have an requirement in which I have to do a transformation from an XML file to an structure.
I need get the value of a tag that have subtrees and move that to a field in my structure.
Example:
<TAG1>value1</TAG1>
<TAG2>value2</TAG2>
<TAG3>
<TAG4>value4</TAG4>
<TAG5>value5</TAG5>
</TAG3>
Result expected in ABAP Structure:
field1 -> tag1
field2 -> tag2
field3 -> <TAG4>value4</TAG4><TAG5>value5</TAG5>
The contents of the tag TAG3 is variable, so I want to store it as a string.
Can I make this with Simple Transformation?
In my tests I can move only the value of each child tag for the given field structure.
This syntax dont work:
<TAG3 tt:value-ref="STRUCTURE.FIELD3"/>
Thanks and Regards,
Miguel MottaHi Miguel
Have a look at below snippets. Here I have tried to escape the text inside TAG3 so that it gets treated as single node during transformation.
ABAP code
DATA: BEGIN OF result,
col1 TYPE string,
col2 TYPE string,
col3 TYPE string,
END OF result.
DATA: xml_string TYPE string VALUE
'<ROOT> <TAG1>value1</TAG1> <TAG2>value2</TAG2> <TAG3> <TAG4>value4</TAG4> <TAG5>value5</TAG5> </TAG3> </ROOT>',
part1 TYPE string,
part2 TYPE string,
part3 TYPE string.
* Escape the text inside TAG3 tag
FIND REGEX '(.*<TAG3>)(.*)(</TAG3>.*)' IN xml_string SUBMATCHES part1 part2 part3.
IF sy-subrc EQ 0.
part2 = escape( val = part2 format = cl_abap_format=>e_xml_text ).
* REPLACE ALL OCCURRENCES OF '<' IN part2 WITH '<'.
* REPLACE ALL OCCURRENCES OF '>' IN part2 WITH '>'.
xml_string = part1 && part2 && part3.
ENDIF.
TRY.
* Display xml
cl_abap_browser=>show_xml( EXPORTING xml_string = xml_string ).
* Deserialization
CALL TRANSFORMATION zmtest
SOURCE XML xml_string
RESULT para = result.
* Check result
WRITE:/ 'COL1=', result-col1,
/ 'COL2=', result-col2,
/ 'COL3=', result-col3.
CATCH cx_st_error.
* Error handling
MESSAGE 'Error in Simple Transformation'
TYPE 'I' DISPLAY LIKE 'E'.
ENDTRY.
Transformation code
<?sap.transform simple?>
<tt:transform xmlns:tt="http://www.sap.com/transformation-templates" template="temp" version="0.1">
<tt:root name="PARA"/>
<tt:template name="temp">
<ROOT>
<TAG1>
<tt:value ref="PARA.COL1"/>
</TAG1>
<TAG2>
<tt:value ref="PARA.COL2"/>
</TAG2>
<TAG3>
<tt:value ref="PARA.COL3"/>
</TAG3>
</ROOT>
</tt:template>
</tt:transform> -
Simple Transformation from Adobe Form XML document to Dictionary structures
I have an XML document that I am receiving via email (the XML document is generated from an Adobe Interactive form). I would like to write a simple transformation that will map that XML document to a structure and internal table in my ABAP program. I am new to Simple Transformations and I am having trouble working out how to write a simple transformation for this type of XML document. I would prefer to write a custom transformation rather than using the identity transformation (ID). I would appreciate any help you can provide.
Please refer to the below for an example of the XML file.
This maps directly to 2 dictionary structures that exist within our system containing all of the same components. PIM_REQUEST_HDR has a corresponding SAP dictionary structure Y_REQUEST_HDR and PIM_REQUEST_ITEMS has a corresponding SAP dictionary structure Y_REQUEST_ITEMS.
Can anyone help with some instructions or examples of how to create the simple transformation?
Thanks for your help! We are using ECC 6.0
Sample XML to be transformed:
<?xml version="1.0" encoding="UTF-8" ?>
<data>
<SFPSY>
<DATE>2007-07-03</DATE>
<TIME>07:25:21</TIME>
<USERNAME>TLCITY</USERNAME>
<SUBRC>0</SUBRC>
</SFPSY>
<PIM_REQUEST_HDR>
<MANDT />
<REQ_NUM />
<REQ_DESC>blah blah blah</REQ_DESC>
<PROC_AREA>CTC</PROC_AREA>
<REQUESTED>2007-07-03</REQUESTED>
<REQUIRED>2007-07-03</REQUIRED>
<REQUESTOR>TLCITY</REQUESTOR>
<MOD_TYPE>SAP Note manual changes</MOD_TYPE>
<SAPNOTE_NUM>59549656</SAPNOTE_NUM>
<SAPMSG_NUM>0000000000</SAPMSG_NUM>
<TECH_SCRIPT />
<REASON />
<DEV_ENV>ECC6</DEV_ENV>
<INSTALL_NO>2861655161</INSTALL_NO>
<BASIS_REL>700</BASIS_REL>
<REG_STATUS />
<REJ_REASON />
<APP_DATE />
<REJ_DATE />
<APPROVER />
<REGISTRATOR />
<REG_DATE />
</PIM_REQUEST_HDR>
<PIM_REQUEST_ITEMS>
<DATA>
<MANDT />
<REQ_NUM />
<PGMID>R3TR</PGMID>
<OBJECT>PROG</OBJECT>
<OBJ_NAME>RSDIJOIJSDOIF</OBJ_NAME>
<ACCESSKEY />
</DATA>
<DATA>
<MANDT />
<REQ_NUM />
<PGMID>R3TR</PGMID>
<OBJECT>PROG</OBJECT>
<OBJ_NAME>RRRSDIJOIJS03</OBJ_NAME>
<ACCESSKEY />
</DATA>
</PIM_REQUEST_ITEMS>
</data>I have solved this one with the help of another collegue.
To simplify, we changed the XML to be as follows:
[code]
<?xml version="1.0" encoding="UTF-8" ?>
<data>
<PIM_REQUEST>
<REQ_HDR>
<MANDT />
<REQ_NUM />
<REQ_DESC>Key required for pricing routines</REQ_DESC>
<PROC_AREA>SD</PROC_AREA>
<REQUESTED>2007-07-30</REQUESTED>
<REQUIRED>2007-08-02</REQUIRED>
<REQUESTOR>TLCITY</REQUESTOR>
<MOD_TYPE>SAP Note: Manual Changes</MOD_TYPE>
<SAPNOTE_NUM>0000000000</SAPNOTE_NUM>
<SAPMSG_NUM>0000000000</SAPMSG_NUM>
<TECH_SCRIPT>TS-2498 Pricing Routines</TECH_SCRIPT>
<REASON>New pricing routines required</REASON>
<DEV_ENV>ECC6</DEV_ENV>
<INSTALL_NO>029</INSTALL_NO>
<BASIS_REL>700</BASIS_REL>
<REG_STATUS />
<REJ_REASON />
<APP_DATE />
<REJ_DATE />
<APPROVER />
<REGISTRATOR />
<REG_DATE />
</REQ_HDR>
<KEY_DETAILS>
<DATA>
<MANDT />
<REQ_NUM />
<PGMID>R3TR</PGMID>
<OBJECT>PROG</OBJECT>
<OBJ_NAME>RVGHT902</OBJ_NAME>
<ACCESSKEY />
</DATA>
<DATA>
<MANDT />
<REQ_NUM />
<PGMID>R3TR</PGMID>
<OBJECT>PROG</OBJECT>
<OBJ_NAME>RVGHT901</OBJ_NAME>
<ACCESSKEY />
</DATA>
</KEY_DETAILS>
</PIM_REQUEST>
</data>
[/code]
This maps directly to 1 dictionary structure that exists within our system containing all of the same components. PIM_REQUEST has a corresponding SAP dictionary structure Y_REQUEST_HDR which is a deep structure and has within it a structure REQ_HDR and a table KEY_DETAILS.
The corresponding simple transformation we have then used is as follws:
[code]
<?sap.transform simple?>
<tt:transform xmlns:tt="http://www.sap.com/transformation-templates">
<tt:root name="root"/>
<tt:template>
<data>
<PIM_REQUEST>
<tt:copy ref="root"/>
</PIM_REQUEST>
</data>
</tt:template>
</tt:transform>
[/code]
Alternatively the following 2 options also work:
Option 2:
[code]
<?sap.transform simple?>
<tt:transform xmlns:tt="http://www.sap.com/transformation-templates">
<tt:root name="root"/>
<tt:template>
<data>
<PIM_REQUEST>
<REQ_HDR>
<tt:copy ref="root.REQ_HDR"/>
</REQ_HDR>
<KEY_DETAILS>
<tt:loop name="KEY_DETAILS" ref="root.KEY_DETAILS">
<DATA>
<tt:copy ref="$KEY_DETAILS"/>
</DATA>
</tt:loop>
</KEY_DETAILS>
</PIM_REQUEST>
</data>
</tt:template>
</tt:transform>
[/code]
Option 3:
[code]
<?sap.transform simple?>
<tt:transform xmlns:tt="http://www.sap.com/transformation-templates">
<tt:root name="root"/>
<tt:template>
<data>
<PIM_REQUEST>
<REQ_HDR>
<MANDT tt:value-ref="root.REQ_HDR.MANDT"/>
<REQ_NUM tt:value-ref="root.REQ_HDR.REQ_NUM"/>
<REQ_DESC tt:value-ref="root.REQ_HDR.REQ_DESC"/>
<PROC_AREA tt:value-ref="root.REQ_HDR.PROC_AREA"/>
<REQUESTED tt:value-ref="root.REQ_HDR.REQUESTED"/>
<REQUIRED tt:value-ref="root.REQ_HDR.REQUIRED"/>
<REQUESTOR tt:value-ref="root.REQ_HDR.REQUESTOR"/>
<MOD_TYPE tt:value-ref="root.REQ_HDR.MOD_TYPE"/>
<SAPNOTE_NUM tt:value-ref="root.REQ_HDR.SAPNOTE_NUM"/>
<SAPMSG_NUM tt:value-ref="root.REQ_HDR.SAPMSG_NUM"/>
<TECH_SCRIPT tt:value-ref="root.REQ_HDR.TECH_SCRIPT"/>
<REASON tt:value-ref="root.REQ_HDR.REASON"/>
<DEV_ENV tt:value-ref="root.REQ_HDR.DEV_ENV"/>
<INSTALL_NO tt:value-ref="root.REQ_HDR.INSTALL_NO"/>
<BASIS_REL tt:value-ref="root.REQ_HDR.BASIS_REL"/>
<REG_STATUS tt:value-ref="root.REQ_HDR.REG_STATUS"/>
<REJ_REASON tt:value-ref="root.REQ_HDR.REJ_REASON"/>
<APP_DATE tt:value-ref="root.REQ_HDR.APP_DATE"/>
<REJ_DATE tt:value-ref="root.REQ_HDR.REJ_DATE"/>
<APPROVER tt:value-ref="root.REQ_HDR.APPROVER"/>
<REGISTRATOR tt:value-ref="root.REQ_HDR.REGISTRATOR"/>
<REG_DATE tt:value-ref="root.REQ_HDR.REG_DATE"/>
</REQ_HDR>
<KEY_DETAILS>
<tt:loop ref="root.KEY_DETAILS" name="KEY_DETAILS">
<DATA>
<MANDT tt:value-ref="$KEY_DETAILS.MANDT"/>
<REQ_NUM tt:value-ref="$KEY_DETAILS.REQ_NUM"/>
<PGMID tt:value-ref="$KEY_DETAILS.PGMID"/>
<OBJECT tt:value-ref="$KEY_DETAILS.OBJECT"/>
<OBJ_NAME tt:value-ref="$KEY_DETAILS.OBJ_NAME"/>
<ACCESSKEY tt:value-ref="$KEY_DETAILS.ACCESSKEY"/>
</DATA>
</tt:loop>
</KEY_DETAILS>
</PIM_REQUEST>
</data>
</tt:template>
</tt:transform>
[/code]
Maybe you are looking for
-
I have just changed mt internet provider and cannot get my apple tv to work now!
-
Using Buys on other devices?
if you buy like a song or a music video from itunes can u like play the video with windows media player instead and put the song on another MP3 player instead of an ipod if u dont have one?
-
WebInterface Server - Error while opening the PDF file
Hello, We are using webinterface to display the MSDS genearated. Our customers use the link provided to them for displaying the msds. We imported a few MSDS ( CG36 ), which are in PDF format & displayed successfully on the webinterface server. Howeve
-
How to mail chart/graphics in abap
Hi there, I have some abap that creates great charts using GRAPH_MATRIX. I have also abaps that send emails with attachments. Now I want to email a chart, but I don't know what to specify inn the SO_CONTENT. Has anyone experince with this please? I d
-
I have a BB8310 that has given me great service for over a year. Two days ago the calender stopped synchronizing with the Outlook calendar. When syncing the device, the address list, task list, memo pad all sync perfectly. The calendar does not s