<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Converting XML string to ABAP types in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/converting-xml-string-to-abap-types/m-p/5627582#M1281487</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;thanks for your suggestion. actually my structure is not that simple. its header and line items..anyways this approach is also good..&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;regards&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;rajeev&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 21 May 2009 05:34:52 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2009-05-21T05:34:52Z</dc:date>
    <item>
      <title>Converting XML string to ABAP types</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/converting-xml-string-to-abap-types/m-p/5627577#M1281482</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am having a requirement where i wanted to parse incoming XML string and i checked few of examples of CALL TRANSFORMATION id.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;but whatever examples i checked those were simple transformation with no hierarchy. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;My source structure&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;&amp;lt;record&amp;gt;
&amp;lt;firstname&amp;gt;XYZ&amp;lt;/firstname&amp;gt;
&amp;lt;position&amp;gt;Testposition&amp;lt;/postion&amp;gt;
&amp;lt;/record&amp;gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;and i used&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;CALL transformation id
source xml lv_xml
result firstname = lv_firstname position = lv_position.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;but lv_firstname and lv_position were blank. any idea whether it can be acheived through such method?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;thanks in advance.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;regards&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;rajeev&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 19 May 2009 10:05:35 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/converting-xml-string-to-abap-types/m-p/5627577#M1281482</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-05-19T10:05:35Z</dc:date>
    </item>
    <item>
      <title>Re: Converting XML string to ABAP types</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/converting-xml-string-to-abap-types/m-p/5627578#M1281483</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You need to have the ROOT node in your XML transformation.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Try this Transformation:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
&amp;lt;?sap.transform simple?&amp;gt;
&amp;lt;tt:transform template="temp"
    xmlns:tt="http://www.sap.com/transformation-templates"
    version="0.1"&amp;gt;

  &amp;lt;tt:root name="IF_TEST"/&amp;gt;

  &amp;lt;tt:template name="temp"&amp;gt;
    &amp;lt;Test&amp;gt;
        &amp;lt;tt:value ref="IF_TEST" /&amp;gt;
    &amp;lt;/Test&amp;gt;
  &amp;lt;/tt:template&amp;gt;

&amp;lt;/tt:transform&amp;gt;
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Test program to generate the XML string and than back to the variable.&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
DATA: lf_string TYPE string.
DATA: xml_string TYPE string.

lf_string = 'This single variable test'.

TRY.

    CALL TRANSFORMATION ztest_np_xml2data
      SOURCE if_test = lf_string
      RESULT XML xml_string.

    CLEAR lf_string.

    CALL TRANSFORMATION ztest_np_xml2data
      SOURCE XML xml_string
      RESULT if_test = lf_string.

  CATCH cx_st_error.

ENDTRY.
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Naimesh Patel&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 19 May 2009 16:49:12 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/converting-xml-string-to-abap-types/m-p/5627578#M1281483</guid>
      <dc:creator>naimesh_patel</dc:creator>
      <dc:date>2009-05-19T16:49:12Z</dc:date>
    </item>
    <item>
      <title>Re: Converting XML string to ABAP types</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/converting-xml-string-to-abap-types/m-p/5627579#M1281484</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello Rajeev,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Try using the following simple transformation &lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
&amp;lt;?sap.transform simple?&amp;gt;
&amp;lt;tt:transform xmlns:tt="http://www.sap.com/transformation-templates"&amp;gt;
  &amp;lt;tt:root name="record"/&amp;gt;
  &amp;lt;tt:template name="record"&amp;gt;
    &amp;lt;record&amp;gt;
      &amp;lt;firstname&amp;gt;
        &amp;lt;tt:value ref="record.firstname"/&amp;gt;
      &amp;lt;/firstname&amp;gt;
      &amp;lt;position&amp;gt;
        &amp;lt;tt:value ref="record.position"/&amp;gt;
      &amp;lt;/position&amp;gt;
    &amp;lt;/record&amp;gt;
  &amp;lt;/tt:template&amp;gt;
&amp;lt;/tt:transform&amp;gt;
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In your code you could define a structure like the following:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
TYPES: BEGIN OF record,
              firstname TYPE char50,
              position  TYPE char50,
            END OF record.
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;And now you could use the CALL TRANSFORMATION in your code to convert the xml string into the structure and visa-versa.&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
CALL TRANSFORMATION zcl_test_rec
      SOURCE XML lv_string
      RESULT record = ls_test.
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Where lv_string holds the xml as a string and ls_test is defined as a structure of type record (defined above).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hope this helps.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you,&lt;/P&gt;&lt;P&gt;Ramneek&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 20 May 2009 06:55:03 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/converting-xml-string-to-abap-types/m-p/5627579#M1281484</guid>
      <dc:creator>Ramneek</dc:creator>
      <dc:date>2009-05-20T06:55:03Z</dc:date>
    </item>
    <item>
      <title>Re: Converting XML string to ABAP types</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/converting-xml-string-to-abap-types/m-p/5627580#M1281485</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks for your help..so we will have to write XSLT transformations in such cases. actually i was looking at options whether to go for such transformations or to have DOM parser APIs that are available in ABAP.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I thought this built-in transformation would go with simple XML and hence tried.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;regards&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;rajeev&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 20 May 2009 09:04:35 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/converting-xml-string-to-abap-types/m-p/5627580#M1281485</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-05-20T09:04:35Z</dc:date>
    </item>
    <item>
      <title>Re: Converting XML string to ABAP types</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/converting-xml-string-to-abap-types/m-p/5627581#M1281486</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I would suggest the using the DOM parser when you want to do more complex XML manipulation. If your requirement is just to read some XML and populate a data structure, then the simple transformations work just fine. All you have to do is define an xslt and the structure.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hope this helps.&lt;/P&gt;&lt;P&gt;Thank you,&lt;/P&gt;&lt;P&gt;Ramneek&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 20 May 2009 13:49:03 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/converting-xml-string-to-abap-types/m-p/5627581#M1281486</guid>
      <dc:creator>Ramneek</dc:creator>
      <dc:date>2009-05-20T13:49:03Z</dc:date>
    </item>
    <item>
      <title>Re: Converting XML string to ABAP types</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/converting-xml-string-to-abap-types/m-p/5627582#M1281487</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;thanks for your suggestion. actually my structure is not that simple. its header and line items..anyways this approach is also good..&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;regards&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;rajeev&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 21 May 2009 05:34:52 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/converting-xml-string-to-abap-types/m-p/5627582#M1281487</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2009-05-21T05:34:52Z</dc:date>
    </item>
  </channel>
</rss>

