XML Simple Transformation with Name attribute
Current logic for reference:
ERS tag is presented in XML file as: <ERSFlag>X</ERSFlag>
Transformation logic to populate ERS flag value into PO_item structure is as:
<tt:cond><ERSFlag>
<tt:value ref="$po_item.ers_flag"/>
</ERSFlag></tt:cond>
New Changes:
XML template with New tag: TaxField1. New Tag included as:
- <TaxField1 name="GST" value="">
- <MultiCurrencyMoney>
<Transaction currency="CAD">400.0000000000000</Transaction>
<Base currency="USD">380.68</Base>
<Local currency="CAD">400.0000000000000</Local>
</MultiCurrencyMoney>
</TaxField1>
I have added new field Taxfield1 with Char1 in structure po_item. I would need to Populate 'Y' to new field Taxfield1 in po_item structure based on the above XML tag.
Could anyone please let me know the Tranformation code to populate 'Y' to new field Taxcode1 in po_item structure based on the above XML tag.
Thanks in advance.
Share solution with us. Thank you!!!
Similar Messages
-
Simple Transformation with very long XML element names
I am trying to write a program to deserialize XML documents using the Simple Transformation technique. There are many optional elements in the XML document, so I need to have conditional statements statements to avoid trying to process elements that are not in the document. The XML document, however, has several Element Names that are greater than 30 characters in length. The Simple Transformation technique seems to require ABAP data dictionary structures that mirror the schema of the XML document. But one cannot create structure component names that are greater than 30 characters in length. We don't have any control over the XML schema as the XML documents come from the US government. The ST fragment below shows the statement that I want to write, but since the ABAP Structure PlasticCardInformationGroup cannot have a component AuthorizationResponseInformation, the ST syntax checker yields an "Illegal Reference ADDITIONALPLASTICCARDINFORMATION" error message.
Does anyone know a way to avoid this error?
<tt:d-cond check="exist(TRS_TradingPartner_Agreement.TRS_FinancialTransaction.PlasticCardInformationGroup.AdditionalPlasticCardInformation)">
<ns2:AdditionalPlasticCardInformation>
<tt:attribute name="CardNetworkType" value-ref="TRS_TRADINGPARTNER_AGREEMENT.TRS_FINANCIALTRANSACTION.PLASTICCARDINFORMATIONGROUP.ADDITIONALPLASTICCARDINFORMATI.CARDNETWORKTYPE"/>
<tt:attribute name="DraftLocatorNumber" value-ref="TRS_TRADINGPARTNER_AGREEMENT.TRS_FINANCIALTRANSACTION.PLASTICCARDINFORMATIONGROUP.ADDITIONALPLASTICCARDINFORMATI.DRAFTLOCATORNUMBER"/>
</ns2:AdditionalPlasticCardInformation>could anyone help me?
-
Help with ABAP Structure to XML - Simple Transformation
Hi guys,
I need help with a Simple Transformation. I am trying to convert a structure in ABAP to XML String but i ma getting short dumps...
Can any of you help.
Thanks in advance.
*& Report ZTESTXML
REPORT ZTESTXML.
class demo DEFINITION.
PUBLIC SECTION.
CLASS-METHODS main.
ENDCLASS.
CLASS demo IMPLEMENTATION.
method main.
data : begin of account,
partner type bu_partner,
primary(1),
update(3),
email(50),
memberid(4),
telephone(12),
fax(10),
dept(20),
end of account.
data : xmlstr type xstring.
account-partner = '12345'.
account-primary = 'N'.
account-update = 'Yes'.
account-email = 'zz at hotmail.com'.
account-memberid = '555'.
account-telephone = '123-448-6710'.
account-fax = '345-123-7899'.
account-dept = 'Info Systems'.
call TRANSFORMATION ztest_inttable
SOURCE account = 'account'
result XML xmlstr.
call FUNCTION 'DISPLAY_XML_STRING'
EXPORTING xml_string = xmlstr.
ENDMETHOD.
ENDCLASS.
start-of-SELECTION.
demo=>main( ).
Transformation
<?sap.transform simple?>
<tt:transform xmlns:tt="http://www.sap.com/transformation-templates">
<tt:root name="account"/>
<tt:template>
<IGT_CRM_AccountInfo>
<Account>
<tt:ref name=".account">
<tt:attribute name="Id" value-ref="PARTNER"/>
<tt:attribute name="Primary" value-ref="primary"/>
<tt:attribute name="Update" value-ref="update"/>
<Contact>
<tt:attribute name="EMail" value-ref="email"/>
<tt:attribute name="Member Id" value-ref="memberid"/>
</Contact>
<Communications>
<tt:attribute name="Telephone" value-ref="telephone"/>
<tt:attribute name="Fax" value-ref="fax"/>
</Communications>
<IGT>
<tt:attribute name="Department" value-ref="dept"/>
</IGT>
</tt:ref>
</Account>
</IGT_CRM_AccountInfo>
</tt:template>
</tt:transform>
Dump message
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 "MAIN" "(METHOD)", 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 "PARTNER". However, this access was not
possible.to convert abap itab or variable into xml string use ABAP key word call transformation.
call transformation (`ID`)
source output = itab[]
result xml xml_out.
where itab is your internal table or any abap variable.
xml_out is type string which will hold the resulting xml.
ID is the transformation program. if you wanto use your own transformation, use your XSLT or ST program there.
Raja -
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. -
Simple transformation with reference to ddic structures
Hi, experts,
we decide to use xml as the format when exchanging massive data with other applications. and we want to use simple transformation because according to the document it's more fast.
actually our file structure is determined by certain ddic structures, one xml file main contain several ddic structures , and they are all flat one, not deep structure.
the xml file may look like this:
<data>
<ddic1>[components of ddic structure 1 ]</ddic1>
<ddic2>[components of ddic structure 2 ]</ddic2>
</data>
i am new to ST,i am wondering that is it possible to make the ST more easy with the help of ddic structure? do i still need to declare the components one by one in the ST program?
BR.
junIt only runs ok with 2 internal tables because of the way you set up the XML string. It will run ok with 3 internal tables too. If you strip out the '<C>' nodes or move the '<C>' nodes around, you'll see what I mean (move the C nodes to the last B node). Each time you start a loop in a simple transformation, the internal table is initialized. So, you need to form your sample XML string differently, declare your internal tables differently (nested), or use XSLT for a little more power.
-
Simple Transformations: How deserialize xmlns attributes?
Hello all,
during deserializing Simple Transformations ignore surplus attributes in the xml input stream. With one exception: u201Exmlnsu201C (namespace) attributes apparently are not ignored.
Take for example the xml file:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<CITIES someattribute="XYZ">
<CITY>Hamburg</CITY>
<CITY>Berlin</CITY>
</CITIES>
This file can be processed successfully by the simple transformation:
<?sap.transform simple?>
<tt:transform xmlns:tt="http://www.sap.com/transformation-templates">
<tt:root name="CITIES"></tt:root>
<tt:template>
<CITIES>
<tt:loop ref="CITIES">
<CITY tt:value-ref="CITY"></CITY>
</tt:loop>
</CITIES>
</tt:template>
</tt:transform>
When trying to process the following xml file by the same transformation, however, a CX_ST_MATCH_ELEMENT error is thrown.
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<CITIES xmlns="XYZ">
<CITY>Hamburg</CITY>
<CITY>Berlin</CITY>
</CITIES>
How can xmlns attributes be deserialized (ignored) with simple transformations?
Thanks for any hint!
Simon
PS:
To reproduce the error the following ABAP can be used in combination with the quoted simple transformation:
REPORT ztestsd13.
TYPES: BEGIN OF lty_cities,
city(20) TYPE c,
END OF lty_cities.
DATA: ls_cities TYPE lty_cities,
lt_cities TYPE TABLE OF lty_cities,
lv_xml TYPE string,
lv_cities_element TYPE string,
lv_error TYPE string,
lo_error TYPE REF TO cx_transformation_error.
PARAMETERS: lp_incns TYPE boolean DEFAULT ''.
CASE lp_incns.
WHEN 'X'.
lv_cities_element = '<CITIES xmlns="XYZ">'.
WHEN OTHERS.
lv_cities_element = '<CITIES someattribute="XYZ">'.
ENDCASE.
CONCATENATE:
'<?xml version="1.0" encoding="UTF-8" standalone="no"?>'
lv_cities_element
'<CITY>Hamburg</CITY>'
'<CITY>Berlin</CITY>'
'</CITIES>' INTO lv_xml.
TRY.
CALL TRANSFORMATION ('Z_CITIES')
SOURCE XML lv_xml
RESULT cities = lt_cities.
CATCH cx_transformation_error INTO lo_error.
lv_error = lo_error->get_text( ).
WRITE: 'Transformation not successful'.
SKIP.
WRITE: lv_error.
EXIT.
ENDTRY.
WRITE: 'Transformation successful'.
SKIP.
LOOP AT lt_cities INTO ls_cities.
WRITE: / ls_cities-city.
ENDLOOP.
Edited by: Simon Dähnhardt on Oct 20, 2009 6:04 PMfirst of all your xml isn't well formatted
root element must be only one like
<?xml version="1.0" encoding="UTF-8"?>
<root>
<result xmlns="http://xmlns.oracle.com/oracleas/schema/dbserver_audittrail-11_2.xsd">
<DB_User>DBSNMP</DB_User>
<Userhost>localhost.localdomain</Userhost>
</result>
<result xmlns="http://xmlns.oracle.com/oracleas/schema/dbserver_audittrail-11_2.xsd">
<DB_User>DBSNMP</DB_User>
<Userhost>localhost.localdomain</Userhost>
</result>
</root>or may be in your case
<?xml version="1.0" encoding="UTF-8"?>
<result xmlns="http://xmlns.oracle.com/oracleas/schema/dbserver_audittrail-11_2.xsd">
<DB_User>DBSNMP</DB_User>
<Userhost>localhost.localdomain</Userhost>
</result>for remove you can use xslt as example for xmltransform
SQL> select * from v$version where rownum=1;
BANNER
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
SQL>
SQL> with t as
2 (select xmltype(
3 '<?xml version="1.0" encoding="UTF-8"?>
4 <result xmlns="http://xmlns.oracle.com/oracleas/schema/dbserver_audittrail-11_2.xsd">
5 <DB_User xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">DBSNMP</DB_User>
6 <Userhost xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">localhost.localdomain</Userhost>
7 </result>') xml from dual)
8 --
9 select xmltransform(t.xml, xmltype('<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
10 <xsl:output method="xml" indent="no"/>
11 <xsl:template match="*">
12 <xsl:element name="{local-name()}">
13 <xsl:apply-templates select="node()"/>
14 </xsl:element>
15 </xsl:template>
16 </xsl:stylesheet>'))
17 from t
18 /
XMLTRANSFORM(T.XML,XMLTYPE('<X
<?xml version="1.0" encoding="utf-8"?>
<result><DB_User>DBSNMP</DB_User><Userhost>localhost.localdomain</Userhost></res
SQL> --add
or try add local-name() to your main xquery
Edited by: AlexAnd on Dec 12, 2012 12:05 AM -
Dynamically name the worksheet in a simple transformation
we have a workbook created through simple transformation with multiple worksheets and we are stuck because we could not name the work sheets dynamically. please help.
Temporarily see if the problem isn't due to too big an Office database file by quiting Outlook, and moving the Microsoft User Data folder out of the Users -> Documents folder to the desktop. Make sure to setup your e-mail as IMAP on server so it remains on server once you move the data back.
Also how big is your hard drive and how full is it?
Are you using any system maintenance tools? These can cause corruption. -
Installing XML::Simple Perl module on 10.4.8
Two of my friends today asked me to help them get XML::Simple working on their Mac's. Somthing that should be a simple cpan one-liner "install XML::Simple" doesnt work on OSX. It took me a half hour to figure all this out... here are the steps:
Prerequisites:
- X11 1.1.3 package from the OSX install disk (or Apple download site)
- Perl 5.8.x w/cpan (default on OSX)
- a terminal
- A reasonable working knowledge of Perl and Unix
Step 1:
Open terminal, type 'cpan' to enter the cpan installer.
cpan> install XML::Simple
It will ask you three times if you want to follow the prerequired modules. Hit enter every time. Eventually you will get a dozen test failures. These are in XML::Parser, a required module.
Step 2:
cpan> exit
$ cd ~/.cpan/build/XML-Parser-2.34 **Note the version may change
$ perl Makefile.PL EXPATLIBPATH=/usr/X11R6/lib EXPATINCPATH=/usr/X11R6/include
$ make test
$ make install
Step 3:
Back to cpan...
$ cpan
cpan> install XML::Parser
Already Installed
cpan> install XML::Parser::Expat
Already Installed
cpan> install XML::SAX::Expat
Installs with some silly warning about ParserDetails.ini. Lets fix that.
cpan> exit
Step 4:
Here is the command/code to add Expat to the ParserDetails.ini file. If we don't, we can't proceed past this point.
$ sudo perl -MXML::SAX -e "XML::SAX->addparser(q(XML::SAX::Expat))->saveparsers()"
Step 5:
Back to cpan to finish the install
$ cpan
cpan> install XML::Simple
Hit enter if it asks you anyting. The whole thing should work.
cpan> exit
Step 6:
Verify XML::Simple existance with:
$ perl -MXML::Simple -e '1;'
If you don't get an error, you're all done!
Enjoy.
Macbook Pro 15" C2D Mac OS X (10.4.8)Two of my friends today asked me to help them get XML::Simple working on their Mac's. Somthing that should be a simple cpan one-liner "install XML::Simple" doesnt work on OSX. It took me a half hour to figure all this out... here are the steps:
Prerequisites:
- X11 1.1.3 package from the OSX install disk (or Apple download site)
- Perl 5.8.x w/cpan (default on OSX)
- a terminal
- A reasonable working knowledge of Perl and Unix
Step 1:
Open terminal, type 'cpan' to enter the cpan installer.
cpan> install XML::Simple
It will ask you three times if you want to follow the prerequired modules. Hit enter every time. Eventually you will get a dozen test failures. These are in XML::Parser, a required module.
Step 2:
cpan> exit
$ cd ~/.cpan/build/XML-Parser-2.34 **Note the version may change
$ perl Makefile.PL EXPATLIBPATH=/usr/X11R6/lib EXPATINCPATH=/usr/X11R6/include
$ make test
$ make install
Step 3:
Back to cpan...
$ cpan
cpan> install XML::Parser
Already Installed
cpan> install XML::Parser::Expat
Already Installed
cpan> install XML::SAX::Expat
Installs with some silly warning about ParserDetails.ini. Lets fix that.
cpan> exit
Step 4:
Here is the command/code to add Expat to the ParserDetails.ini file. If we don't, we can't proceed past this point.
$ sudo perl -MXML::SAX -e "XML::SAX->addparser(q(XML::SAX::Expat))->saveparsers()"
Step 5:
Back to cpan to finish the install
$ cpan
cpan> install XML::Simple
Hit enter if it asks you anyting. The whole thing should work.
cpan> exit
Step 6:
Verify XML::Simple existance with:
$ perl -MXML::Simple -e '1;'
If you don't get an error, you're all done!
Enjoy.
Macbook Pro 15" C2D Mac OS X (10.4.8) -
Transformation with JDOM (off-topic)
Hi All,
I am wondering if anyone could advice me on how to carry out transformation in a JDOM enviornment. I am familiar with querrying data using XPath with JDOM.
Any tutorial or online reference material would be very much appreciated.
I am running Netbeans 6.1, J2EE 5 Glassfish on Windows XP platform.
Many thanks,
JackIt contains the [org.jdom.transform|http://www.jdom.org/docs/apidocs/org/jdom/transform/package-summary.html] package with classes to do basic transformation. As the documentation says:
Classes to help with transformations, based on the JAXP TrAX classes. JDOMTransformer supports simple transformations with one line of code. Advanced features are available with the JDOMSource and JDOMResult classes that interface with TrAX. -
Installing XML::Simple - CPAN
I need some help, I've been trying to install the CPAN module XML::Simple on OS X Lion 10.7.3 so far with no good results.
I installed this on my linux mint machine in no time but for some reason the simple task had turned onto a project on the Mac.
I found an old posting for setting up the CPAN modules on Mac but I haven't been able to applied to my environment.
------- this is the old post ---------------
Two of my friends today asked me to help them get XML::Simple working on their Mac's. Somthing that should be a simple cpan one-liner "install XML::Simple" doesnt work on OSX. It took me a half hour to figure all this out... here are the steps:
Prerequisites:
- X11 1.1.3 package from the OSX install disk (or Apple download site)
- Perl 5.8.x w/cpan (default on OSX)
- a terminal
- A reasonable working knowledge of Perl and Unix
Step 1:
Open terminal, type 'cpan' to enter the cpan installer.
cpan> install XML::Simple
It will ask you three times if you want to follow the prerequired modules. Hit enter every time. Eventually you will get a dozen test failures. These are in XML::Parser, a required module.
Step 2:
cpan> exit
$ cd ~/.cpan/build/XML-Parser-2.34 **Note the version may change
$ perl Makefile.PL EXPATLIBPATH=/usr/X11R6/lib EXPATINCPATH=/usr/X11R6/include
$ make test
$ make install
Step 3:
Back to cpan...
$ cpan
cpan> install XML::Parser
Already Installed
cpan> install XML::Parser::Expat
Already Installed
cpan> install XML::SAX::Expat
Installs with some silly warning about ParserDetails.ini. Lets fix that.
cpan> exit
Step 4:
Here is the command/code to add Expat to the ParserDetails.ini file. If we don't, we can't proceed past this point.
$ sudo perl -MXML::SAX -e "XML::SAX->addparser(q(XML::SAX::Expat))->saveparsers()"
Step 5:
Back to cpan to finish the install
$ cpan
cpan> install XML::Simple
Hit enter if it asks you anyting. The whole thing should work.
cpan> exit
Step 6:
Verify XML::Simple existance with:
$ perl -MXML::Simple -e '1;'
If you don't get an error, you're all done!
-------- end of old post ---------------------
This is where I have gotten so far:
to get in CPAN I use sudo cpan <enter>
cpan[6]> cpan[6]> install XML::Simple
Going to read '/Users/josephhandschu/.cpan/sources/authors/01mailrc.txt.gz'
............................................................................DONE
Going to read '/Users/josephhandschu/.cpan/sources/modules/02packages.details.txt.gz'
Database was generated on Mon, 13 Feb 2012 00:12:32 GMT
New CPAN.pm version (v1.9800) available.
[Currently running version is v1.9456]
You might want to try
install CPAN
reload cpan
to both upgrade CPAN.pm and run the new version without leaving
the current session.
..............................................................DONE
Going to read '/Users/josephhandschu/.cpan/sources/modules/03modlist.data.gz'
............................................................................DONE
Going to write /Users/josephhandschu/.cpan/Metadata
XML::Simple is up to date (2.18).
Then I get out of CPAN
cpan[11]> exit
Terminal does not support GetHistory.
Lockfile removed.
Josephs-MacBook-Air-2:/ josephhandschu$ cd ~/.cpan/build/XML-Parser*
Josephs-MacBook-Air-2:XML-Parser-2.41-2ew4TC josephhandschu$ perl^C
Try to run the Makefile.PL
Josephs-MacBook-Air-2:XML-Parser-2.41-2ew4TC josephhandschu$ perl Makefile.PL EXPATLIBPATH=/usr/X11R6/lib EXPATINCPATH=/usr/X11/include
Couldn't find your C compiler
Compilation failed in require at Makefile.PL line 5.
BEGIN failed--compilation aborted at Makefile.PL line 5.
Josephs-MacBook-Air-2:XML-Parser-2.41-2ew4TC josephhandschu$
or with a shorter version taking the default parameters
Josephs-MacBook-Air-2:XML-Parser-2.41-2ew4TC josephhandschu$ perl Makefile.PL
Couldn't find your C compiler
Compilation failed in require at Makefile.PL line 5.
BEGIN failed--compilation aborted at Makefile.PL line 5.
But this complains about not finding the C compiler
Any ideas?
Suggestions are greatly appreciated, I've hitted a wall....
Joseph.(I'm using the bash shell below. If you use csh, some of these commands won't work.)
It sounds like the compiler is not in your PATH. Test this by:
$ which cc
My guess is that nothing will be returned by that command.
You've already installed XCode, so it should be on your system. If your locate(1) database is up to date, the fastest way to find the compiler is this:
$ locate cc | grep /cc$
On my machine (OS X 10.7), the compiler is /Developer/usr/bin/cc so I added /Developer/usr/bin to my PATH:
$ export PATH="$PATH:/Developer/usr/bin"
And obviously add that to your ~.bashrc file. -
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> -
ABAP Simple Transformation - How to save XML to file with CL_FX_WRITER?
Hello!
When calling a Simple Transformation program for transformation from ABAP to XML, it is possible to specify RESULT XML rxml as a class reference variable of type CL_FX_WRITER, which points to an XML writer.
How to handle CL_FX_WRITER in order to save XML to a file?
Thanks and regards,
AndreyHallo Rainer!
Many thanks. I have checked the profile parameter ztta/max_memreq_MB and it is set to 2048 MB in the development system. I hope, that won't be less on the client's machine. The only thing I did not clearly explained, is that I need to write XML data to the server. I am so sorry. Downloading to the local PC is very helpful for me also, but only for the test purposes.
Regards,
Andrey -
Simple Transformation to deserialize an XML file into ABAP data structures?
I'm attempting to write my first simple transformation to deserialize
an XML file into ABAP data structures and I have a few questions.
My simple transformation contains code like the following
<tt:transform xmlns:tt="http://www.sap.com/transformation-templates"
xmlns:pp="http://www.sap.com/abapxml/types/defined" >
<tt:type name="REPORT" line-type="?">
<tt:node name="COMPANY_ID" type="C" length="10" />
<tt:node name="JOB_ID" type="C" length="20" />
<tt:node name="TYPE_CSV" type="C" length="1" />
<tt:node name="TYPE_XLS" type="C" length="1" />
<tt:node name="TYPE_PDF" type="C" length="1" />
<tt:node name="IS_NEW" type="C" length="1" />
</tt:type>
<tt:root name="ROOT2" type="pp:REPORT" />
<QueryResponse>
<tt:loop ref="ROOT2" name="line">
<QueryResponseRow>
<CompanyID>
<tt:value ref="$line.COMPANY_ID" />
</CompanyID>
<JobID>
<tt:value ref="$line.JOB_ID" />
</JobID>
<ExportTypes>
<tt:loop>
<ExportType>
I don't know what to do here (see item 3, below)
</ExportType>
</tt:loop>
</ExportTypes>
<IsNew>
<tt:value ref="$line.IS_NEW"
map="val(' ') = xml('false'), val('X') = xml('true')" />
</IsNew>
</QueryResponseRow>
</tt:loop>
</QueryResponse>
</tt:loop>
1. In a DTD, an element can be designated as occurring zero or one
time, zero or more times, or one or more times. How do I write the
simple transformation to accommodate these possibilities?
2. In trying to accommodate the "zero or more times" case, I am trying
to use the <tt:loop> instruction. It occurs several layers deep in the
XML hierarchy, but at the top level of the ABAP table. The internal
table has a structure defined in the ABAP program, not in the data
dictionary. In the simple transformation, I used <tt:type> and
<tt:node> to define the structure of the internal table and then
tried to use <tt:loop ref="ROOT2" name="line"> around the subtree that
can occur zero or more times. But every variation I try seems to get
different errors. Can anyone supply a working example of this?
3. Among the fields in the internal table, I've defined three
one-character fields named TYPE_CSV, TYPE_XLS, and TYPE_PDF. In the
XML file, I expect zero to three elements of the form
<ExportType exporttype='csv' />
<ExportType exporttype='xls' />
<ExportType exporttype='pdf' />
I want to set field TYPE_CSV = 'X' if I find an ExportType element
with its exporttype attribute set to 'csv'. I want to set field
TYPE_XLS = 'X' if I find an ExportType element with its exporttype
attribute set to 'xls'. I want to set field TYPE_PDF = 'X' if I find
an ExportType element with its exporttype attribute set to 'pdf'. How
can I do that?
4. For an element that has a value like
<ErrorCode>123</ErrorCode>
in the simple transformation, the sequence
<ErrorCode> <tt:value ref="ROOT1.CODE" /> </ErrorCode>
seems to work just fine.
I have other situations where the XML reads
<IsNew value='true' />
I wanted to write
<IsNew>
<tt:value ref="$line.IS_NEW"
map="val(' ') = xml('false'), val('X') = xml('true')" />
</IsNew>
but I'm afraid that the <tt:value> fails to deal with the fact that in
the XML file the value is being passed as the value of an attribute
(named "value"), rather than the value of the element itself. How do
you handle this?Try this code below:
data l_xml_table2 type table of xml_line with header line.
W_filename - This is a Path.
if w_filename(02) = '
open dataset w_filename for output in binary mode.
if sy-subrc = 0.
l_xml_table2[] = l_xml_table[].
loop at l_xml_table2.
transfer l_xml_table2 to w_filename.
endloop.
endif.
close dataset w_filename.
else.
call method cl_gui_frontend_services=>gui_download
exporting
bin_filesize = l_xml_size
filename = w_filename
filetype = 'BIN'
changing
data_tab = l_xml_table
exceptions
others = 24.
if sy-subrc <> 0.
message id sy-msgid type sy-msgty number sy-msgno
with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
endif. -
Problem with Simple Transformation
Hi to all
I am working with ST, and have the following issue:
I have a highly nested xml structure, and, when I execute a abap program with a myself ST, only the last one data is passed to internal tables.
I want to know: how can I do to get that all the information from xml file to store to internal tables but not only the latest information structure?
For example I have the following xml file, and only the last occurence of <PSMService> is update in internal tables.
Thank you very much for your help.
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<InvoicingInformation>
<Services>
<PSMServices>
<PSMService ContractCode="STF0996" InvoicePeriod="2011-01-31T00:00:00-06:00" ReceiptPointCode="347">
<Transactions>
<Transaction ReceiptPointCode="347" DeliveryPointCode="167" ExitTramoCode="15" SectorCode="SECTP_GNV">
</Transaction>
</Transactions>
<DailyCharges>
<DailyCharge ChargeCode="CHRGS_FIJO" Date="2011-01-01T00:00:00-06:00" Quantity="93" QuantityUnit="KPC">
</DailyCharge>
<DailyCharge ChargeCode="CHRGS_FIJO_COP" Date="2011-01-01T00:00:00-06:00" Quantity="93" QuantityUnit="KPC">
</DailyCharge>
</DailyCharges>
<AggregateCharges>
<AggregateCharge ChargeCode="CHRGS_DESVIO" IsTiered="false" Quantity="0" QuantityUnit="KPC" CurrencyCode="COP">
</AggregateCharge>
<AggregateCharge ChargeCode="CHRGS_DESVIO_US$" IsTiered="false" Quantity="0" QuantityUnit="KPC" CurrencyCode="USD">
</AggregateCharge>
</AggregateCharges>
</PSMService>
<PSMService ContractCode="STF0996" InvoicePeriod="2011-01-31T00:00:00-06:00" ReceiptPointCode="347">
<Transactions>
<Transaction ReceiptPointCode="347" DeliveryPointCode="192A" ExitTramoCode="16" SectorCode="SECTP_GNV">
</Transaction>
</Transactions>
<DailyCharges>
<DailyCharge ChargeCode="CHRGS_FIJO" Date="2011-01-01T00:00:00-06:00" Quantity="112" QuantityUnit="KPC">
</DailyCharge>
<DailyCharge ChargeCode="CHRGS_FIJO_COP" Date="2011-01-01T00:00:00-06:00" Quantity="112" QuantityUnit="KPC">
</DailyCharge>
</DailyCharges>
<AggregateCharges>
<AggregateCharge ChargeCode="CHRGS_FIJO" IsTiered="false" Quantity="560" QuantityUnit="KPC" CurrencyCode="USD">
</AggregateCharge>
<AggregateCharge ChargeCode="CHRGS_FIJO_COP" IsTiered="false" Quantity="560" QuantityUnit="KPC" CurrencyCode="COP">
</AggregateCharge>
</AggregateCharges>
</PSMService>
<PSMService ContractCode="STF0996" InvoicePeriod="2011-01-31T00:00:00-06:00" ReceiptPointCode="360">
<Transactions>
<Transaction ReceiptPointCode="260A" DeliveryPointCode="167" ExitTramoCode="15" SectorCode="SECTP_GNV">
</Transaction>
<Transaction ReceiptPointCode="260B" DeliveryPointCode="168" ExitTramoCode="15" SectorCode="SECTP_GNV">
</Transaction>
</Transactions>
<DailyCharges>
<DailyCharge ChargeCode="CHRGS_DESVIO" Date="2011-01-01T00:00:00-06:00" Quantity="0" QuantityUnit="KPC">
</DailyCharge>
<DailyCharge ChargeCode="CHRGS_DESVIO_US$" Date="2011-01-01T00:00:00-06:00" Quantity="0" QuantityUnit="KPC">
</DailyCharge>
</DailyCharges>
<AggregateCharges>
<AggregateCharge ChargeCode="CHRGS_DESVIO" IsTiered="false" Quantity="0" QuantityUnit="KPC" CurrencyCode="COP">
</AggregateCharge>
<AggregateCharge ChargeCode="CHRGS_DESVIO_US$" IsTiered="false" Quantity="0" QuantityUnit="KPC" CurrencyCode="USD">
</AggregateCharge>
</AggregateCharges>
</PSMService>
</PSMServices>
</Services>
</InvoicingInformation>
Edited by: Thomas Zloch on May 10, 2011 12:46 PM - code tags addedHi Charles.
Thank you.
This is a piece of the simple transformation:
<Services>
<!-- PSM Services -->
<PSMServices tt:extensible="deep-dynamic">
<tt:loop name="PSMService" ref="TABLA_PSM_SERVICES">
<PSMService tt:extensible="deep-dynamic">
<tt:attribute name="ContractCode" value-ref="$PSMService.ContractCode"/>
<tt:attribute name="InvoicePeriod" value-ref="$PSMService.InvoicePeriod"/>
<tt:attribute name="ReceiptPointCode" value-ref="$PSMService.ReceiptPointCode"/>
<tt:attribute name="DeliveryPointCode" value-ref="$PSMService.DeliveryPointCode"/>
<tt:attribute name="ExitTramoCode" value-ref="$PSMService.ExitTramoCode"/>
<tt:attribute name="SectorCode" value-ref="$PSMService.SectorCode"/>
<tt:attribute name="MarketCode" value-ref="$PSMService.MarketCode"/>
<tt:attribute name="TransportMarketCode" value-ref="$PSMService.TransportMarketCode"/>
<tt:attribute name="InvoiceBy" value-ref="$PSMService.InvoiceBy"/>
<tt:attribute name="MarketCapacity" value-ref="$PSMService.MarketCapacity"/>
<tt:attribute name="MarketCapacityUnitCode" value-ref="$PSMService.MarketCapacityUnitCode"/>
<tt:attribute name="SAPMaterialCode" value-ref="$PSMService.SAPMaterialCode"/>
<Transactions tt:extensible="deep-dynamic">
<tt:loop name="Transaction" ref=".TABLA_PSM_TRANSACTIONS">
<Transaction tt:extensible="deep-dynamic">
<tt:attribute name="ReceiptPointCode" value-ref="$Transaction.ReceiptPointCode"/>
<tt:attribute name="DeliveryPointCode" value-ref="$Transaction.DeliveryPointCode"/>
<tt:attribute name="ExitTramoCode" value-ref="$Transaction.ExitTramoCode"/>
<tt:attribute name="SectorCode" value-ref="$Transaction.SectorCode"/>
<tt:attribute name="MarketCode" value-ref="$Transaction.MarketCode"/>
<tt:attribute name="MarketCapacity" value-ref="$Transaction.MarketCapacity"/>
<tt:attribute name="Firm" value-ref="$Transaction.Firm"/>
<tt:attribute name="Overrun " value-ref="$Transaction.Overrun "/>
<tt:attribute name="UnitCode" value-ref="$Transaction.UnitCode"/>
<tt:attribute name="SAPMaterialCode" value-ref="$Transaction.SAPMaterialCode"/>
</Transaction>
</tt:loop>
</Transactions>
<DailyCharges tt:extensible="deep-dynamic">
<tt:loop name="DailyCharge" ref=".TABLA_PSM_DAILYCHARGES">
<DailyCharge tt:extensible="deep-dynamic">
<tt:attribute name="ChargeCode" value-ref="$DailyCharge.ChargeCode"/>
<tt:attribute name="Date" value-ref="$DailyCharge.Date"/>
<tt:attribute name="Quantity" value-ref="$DailyCharge.Quantity"/>
<tt:attribute name="QuantityUnit" value-ref="$DailyCharge.QuantityUnit"/>
</DailyCharge>
</tt:loop>
</DailyCharges>
<AggregateCharges tt:extensible="deep-dynamic">
<tt:loop name="AggregateCharge" ref=".TABLA_PSM_AGGREGATECHARGES">
<AggregateCharge tt:extensible="deep-dynamic">
<tt:attribute name="ChargeCode" value-ref="$AggregateCharge.ChargeCode"/>
<tt:attribute name="IsTiered" value-ref="$AggregateCharge.IsTiered"/>
<tt:attribute name="Quantity" value-ref="$AggregateCharge.Quantity"/>
<tt:attribute name="QuantityUnit" value-ref="$AggregateCharge.QuantityUnit"/>
<tt:attribute name="CurrencyCode" value-ref="$AggregateCharge.CurrencyCode"/>
<tt:attribute name="TariffRate" value-ref="$AggregateCharge.TariffRate"/>
<tt:attribute name="TariffRateUnit" value-ref="$AggregateCharge.TariffRateUnit"/>
</AggregateCharge>
</tt:loop>
</AggregateCharges>
</PSMService>
</tt:loop>
</PSMServices>
</Services>
Edited by: Thomas Zloch on May 10, 2011 12:47 PM - code tags added -
Create xml tag dynamically within simple transformation
Hi all together,
I'm faceing the following problem:
There is a internal table provided, consisting of name/value-pairs. Something like
ls_struc-name = 'NAME1'.
ls_struc-value = 'XYZ'.
append ls_struc to lt_struc
ls_struc-name = 'CITY1'.
ls_struc-value = 'Munich'.
append ls_struc to lt_struc
and so on.
I have to create this XML (with simple transformation):
<NAME1>XYZ</NAME1>
<CITY1>Munich</CITY1>
Everythings works fine so far (tables, values etc.), but I have problems with creating the XML-Tag, e.g <NAME1> from "$line.name" within the transformation. I don't have any information about the data structure (therefore "call transaction id" does not work).
Any hint is useful!!!
Best regards,
ThomasExaple program for creating XML file from abap
REPORT z_xit_xml_dom_create.
TYPE-POOLS: ixml.
TYPES: BEGIN OF xml_line,
data(256) TYPE x,
END OF xml_line.
DATA: l_ixml TYPE REF TO if_ixml,
l_streamfactory TYPE REF TO if_ixml_stream_factory,
l_ostream TYPE REF TO if_ixml_ostream,
l_renderer TYPE REF TO if_ixml_renderer,
l_document TYPE REF TO if_ixml_document.
DATA: l_element_flights TYPE REF TO if_ixml_element,
l_element_airline TYPE REF TO if_ixml_element,
l_element_flight TYPE REF TO if_ixml_element,
l_element_from TYPE REF TO if_ixml_element,
l_element_to TYPE REF TO if_ixml_element,
l_element_dummy TYPE REF TO if_ixml_element,
l_value TYPE string.
DATA: l_xml_table TYPE TABLE OF xml_line,
l_xml_size TYPE i,
l_rc TYPE i.
DATA: lt_spfli TYPE TABLE OF spfli.
DATA: l_spfli TYPE spfli.
START-OF-SELECTION.
* Fill the internal table
SELECT * FROM spfli INTO TABLE lt_spfli.
* Sort internal table
SORT lt_spfli BY carrid.
* Start filling xml dom object from internal table
LOOP AT lt_spfli INTO l_spfli.
AT FIRST.
* Creating a ixml factory
l_ixml = cl_ixml=>create( ).
* Creating the dom object model
l_document = l_ixml->create_document( ).
* Fill root node with value flights
l_element_flights = l_document->create_simple_element(
name = 'flights'
parent = l_document ).
ENDAT.
AT NEW carrid.
* Create element 'airline' as child of 'flights'
l_element_airline = l_document->create_simple_element(
name = 'airline'
parent = l_element_flights ).
* Create attribute 'code' of node 'airline'
l_value = l_spfli-carrid.
l_rc = l_element_airline->set_attribute( name = 'code' value = l_value ).
* Create attribute 'name' of node 'airline'
SELECT SINGLE carrname FROM scarr INTO l_value WHERE carrid EQ l_spfli-carrid.
l_rc = l_element_airline->set_attribute( name = 'name' value = l_value ).
ENDAT.
AT NEW connid.
* Create element 'flight' as child of 'airline'
l_element_flight = l_document->create_simple_element(
name = 'flight'
parent = l_element_airline ).
* Create attribute 'number' of node 'flight'
l_value = l_spfli-connid.
l_rc = l_element_flight->set_attribute( name = 'number' value = l_value ).
ENDAT.
* Create element 'from' as child of 'flight'
CONCATENATE l_spfli-cityfrom ',' l_spfli-countryfr INTO l_value.
l_element_from = l_document->create_simple_element(
name = 'from'
value = l_value
parent = l_element_flight ).
* Create attribute 'airport' of node 'from'
l_value = l_spfli-airpfrom.
l_rc = l_element_from->set_attribute( name = 'airport' value = l_value ).
* Create element 'to' as child of 'flight'
CONCATENATE l_spfli-cityto ',' l_spfli-countryto INTO l_value.
l_element_to = l_document->create_simple_element(
name = 'to'
value = l_value
parent = l_element_flight ).
* Create attribute 'airport' of node 'from'
l_value = l_spfli-airpto.
l_rc = l_element_to->set_attribute( name = 'airport' value = l_value ).
* Create element 'departure' as child of 'flight'
l_value = l_spfli-deptime.
l_element_dummy = l_document->create_simple_element(
name = 'departure'
value = l_value
parent = l_element_flight ).
* Create element 'arrival' as child of 'flight'
l_value = l_spfli-arrtime.
l_element_dummy = l_document->create_simple_element(
name = 'arrival'
value = l_value
parent = l_element_flight ).
* Create element 'type' as child of 'flight'
CASE l_spfli-fltype.
WHEN 'X'.
l_value = 'Charter'.
WHEN OTHERS.
l_value = 'Scheduled'.
ENDCASE.
l_element_dummy = l_document->create_simple_element(
name = 'type'
value = l_value
parent = l_element_flight ).
ENDLOOP.
IF sy-subrc NE 0.
MESSAGE 'No data into db table ''spfli'', please run program ''SAPBC_DATA_GENERATOR'' with transaction ''SA38''' TYPE 'E'.
ENDIF.
* Creating a stream factory
l_streamfactory = l_ixml->create_stream_factory( ).
* Connect internal XML table to stream factory
l_ostream = l_streamfactory->create_ostream_itable( table = l_xml_table ).
* Rendering the document
l_renderer = l_ixml->create_renderer( ostream = l_ostream
document = l_document ).
l_rc = l_renderer->render( ).
* Saving the XML document
l_xml_size = l_ostream->get_num_written_raw( ).
CALL METHOD cl_gui_frontend_services=>gui_download
EXPORTING
bin_filesize = l_xml_size
filename = 'c:\temp\flights.xml'
filetype = 'BIN'
CHANGING
data_tab = l_xml_table
EXCEPTIONS
OTHERS = 24.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
Maybe you are looking for
-
ITunes won't start on Windows 7
I'm running Windows 7 Ultimate x84 I have problem with iTunes. When I click the icon it wont open. It load something and nothing hepened. I read some articles here. Try to run it in Safe Mode by holding Shift and Ctrl when I start it and it says "iTu
-
Using the max function in a inner joined statement
I am trying to take from a database with two joined tables various datas from the record belonging to paul that has the highest entry number. String query = "SELECT Table1.name, Table1.idNumber, Table2.Address Table2.entryNum FROM Table1 INNER JOIN T
-
Get most recent backup completed within last week
Hi. I need your help with this... I want to get a list of the most recent .bak files created in the last week. I need to select [database_name] and [backup_finish_date] from msdb..backupset and [physical_device_name] from msdb..backupmediafamily ta
-
Why is it that after all these years Verity support in Coldfusion is still a black art when it comes to its errors and support. I have asked numerous places with regards to what Error (-1705), (-1703) and the dubious General Error(2) mean when search
-
Help,I can not open files
I have windows 7 and I can not open certain files,I am not very computer literate so please bare with me. I recieved a document which is file type DOC FILE (.doc),when I try to open it I get a message saying adobe reader is unable to open as it is no