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

Xml string to abap internal table

Former Member
0 Likes
1,383

HI Experts ,

I want to parse this XML file to abap internal table ,i read as usual the Help and i think

that something is missing on my code.

There is someone can help.

The fields is type string and the value is :

<Containers> <Container workitemid = "00000017" IsParent = "X"><Element name = "_WF" value = "USI029"/><Element name = "_WF_PRIOR" value = "5"/><Element name = "_WF_VERSION" value = "0000"/><Element name = "_WF_NESTING_LEVEL" value = ""/><Element name = "XUBNAME" value = ""/><Element name = "XUACCNT" value = ""/><Element name = "SHORTTEXT" value = ""/><Element name = 
.....

i use the call transformation code and there i put this code:

<?sap.transform simple?>
<tt:transform xmlns:tt="http://www.sap.com/transformation-templates">
<tt:root name="XML_TAB"/>
  <tt:template>
    <Containers>
      <tt:loop name="a" ref=".XML_TAB">
        <Container>
          <tt:attribute name="Element name" value-ref="$a.name"/>
          <tt:attribute name="value" value-ref="$a.value"/>
        </Container>
      </tt:loop>
    </Containers>
  </tt:template>
</tt:transform>

I think that i miss something with the line :<Container workitemid = "0000007" IsParent = "X">

the dump is:

An exception occurred that is explained in detail below.

The exception, which is assigned to class 'CX_ST_MATCH_ATTRIBUTE', was not

caught and

therefore caused a runtime error.

The reason for the exception is:

XML matching error

Expected was attribute: "Elementname" [ ] Read was element-start: "Container" [

].

Please help

Regards

Chris

Edited by: Chris Teb on Aug 6, 2009 9:57 AM

1 ACCEPTED SOLUTION
Read only

sivasatyaprasad_yerra
Product and Topic Expert
Product and Topic Expert
0 Likes
1,023

Your transformation is wrong:

<Element> tag is occured multiple times. But Your transformation says <Container> tag wil occur multiple times.

Try with this transformation:

<?sap.transform simple?>
<tt:transform xmlns:tt="http://www.sap.com/transformation-templates">
<tt:root name="XML_TAB"/>

  <tt:template>
    <Containers>
    <Container>
        <tt:loop name="a" ref=".XML_TAB">
        <Element >
          <tt:attribute name="name" value-ref="$a.name"/>
          <tt:attribute name="value" value-ref="$a.value"/>
          </Element>
          </tt:loop>
        </Container>
    </Containers>
  </tt:template>
</tt:transform>

8 REPLIES 8
Read only

Former Member
0 Likes
1,023

Hi,

Check this link.

Thanks

Read only

sivasatyaprasad_yerra
Product and Topic Expert
Product and Topic Expert
0 Likes
1,024

Your transformation is wrong:

<Element> tag is occured multiple times. But Your transformation says <Container> tag wil occur multiple times.

Try with this transformation:

<?sap.transform simple?>
<tt:transform xmlns:tt="http://www.sap.com/transformation-templates">
<tt:root name="XML_TAB"/>

  <tt:template>
    <Containers>
    <Container>
        <tt:loop name="a" ref=".XML_TAB">
        <Element >
          <tt:attribute name="name" value-ref="$a.name"/>
          <tt:attribute name="value" value-ref="$a.value"/>
          </Element>
          </tt:loop>
        </Container>
    </Containers>
  </tt:template>
</tt:transform>

Read only

0 Likes
1,023

H Siva,

Thanks ,

I try exactly like u tell and i get this dump:

An exception occurred that is explained in detail below.

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

and

therefore caused a runtime error.

The reason for the exception is:

XML matching error

Expected was element-end: "Containers" [ ] Read was element-start: "Container"

[ ].

<Containers>
    <Container>
        <tt:loop name="a" ref=".XML_TAB">
        <Element >
          <tt:attribute name="name" value-ref="$a.name"/>
          <tt:attribute name="value" value-ref="$a.value"/>
          </Element>
          </tt:loop>
        </Container>
    </Containers> ->**the dump in the debugger is here .**
  </tt:template>
</tt:transform>

Any Idea?

Regards

Chris

Read only

0 Likes
1,023

Check XML input which is getting passed to transformation. This should end with

</Container>
</Containers>

.

I think it is not like that.

Read only

0 Likes
1,023

HI Siva,

Thank you ,

since i upload the file from text file the string maybe is cutting somewhere ,

i check it and let u know.

Regards

Chris

Read only

0 Likes
1,023

Check if you have more than one <Container> tag in the XML input. If that is the case, then this transformation will not work as this transformation is considered only for one <Container> tag in <Containers> tag. Check this also

Read only

sivasatyaprasad_yerra
Product and Topic Expert
Product and Topic Expert
0 Likes
1,023

CHeck this link. There is a example for the same type of XML structure.

[http://help.sap.com/saphelp_nwpi71/helpdata/EN/3a/eefd3f0521c842e10000000a1550b0/content.htm]

Read only

Former Member
0 Likes
1,023

Hello Chris,

Try Identical transformation. It is easy and not required transformation template.

CALL TRANSFORMATION ID

SOURCE ...

RESULT...

So source and result are not going to change any ways only you have to remove transformation template and replace it with ID.

Also make sure the input XML is following the XSLT format.

Thanks,

Augustin.