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

Need help with XML TRANSFORMATION dump

Former Member
0 Likes
2,809

HI Experts ,

I want to parse this XML file to abap internal table ,i use the ST below and i get dump .

The file is like that :

<Containers>
	<Container workitemid="0000001" IsParent="X">
		<Element name="__INITIATO" value="U295"/>
		<Element name="_W_PRITY" value="5"/>
		<Element name="_F_VERSION" value="0000"/>
</Container>
<Container workitemid="0000001">
		<Element name="EXTENDED" value="X"/>
		<Element name="NOTE_REFERENCE" value=""/>
	</Container>
</Containers>

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"

[ ].

this is the ciode that i put on the call transformation

<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>

the dump is because i don't refer to the </Container> in the middle

and when i try to add the tag container in the middle i get warning during complition

any idea please im stuck

Best Regards

Chris

Edited by: Chris Teb on Aug 14, 2009 6:25 PM

1 ACCEPTED SOLUTION
Read only

Sandra_Rossi
Active Contributor
0 Likes
1,729

could you provide the abap type and the call transformation too?

13 REPLIES 13
Read only

Sandra_Rossi
Active Contributor
0 Likes
1,730

could you provide the abap type and the call transformation too?

Read only

0 Likes
1,729

HI Sandra Rossi

Sure .:)

Here is the code .

DATA: BEGIN OF ty_data,
     name TYPE string,
     value TYPE string,
END OF ty_data.

DATA: lt_data TYPE  TABLE OF  ty_data.

CALL TRANSFORMATION zext_file
        SOURCE XML itab1
        RESULT xml_tab = lt_data.

in Itab 1 i have the string of the XML file .

One thing , i see in the debugger that the table XML_TAB are filled with value (U295 , 5 ....) with the structure i need but after the line :

<Element name="_F_VERSION" value="0000"/> it failed (dump)

i know that i dont refer to the container in the middle do the file but i dont know where to include it .

Best Regards & Thanks

Chris

Read only

0 Likes
1,729

okay, I see the point. In the input XML, the "container" tag has multiple occurrences, do you want to put store all occurrences in an internal table? If yes, then you have to wrap LT_DATA inside an other internal table LT_DATA2, like that (I rename LT_DATA into component T_DATA)::


TYPES: BEGIN OF ty_data2,
     workitemid TYPE n LENGTH 7,
     isparent   TYPE flag,
     t_data     TYPE TABLE OF ty_data WITH DEFAULT KEY,
END OF ty_data2.
DATA: lt_data2 TYPE TABLE OF ty_data2.

Then, in your ST transformation, you must add a tt:loop name="b" ... to fill lt_data2, and you must change tt:loop name="a" ref="$b.T_DATA"...

I let you fill the blanks

Read only

0 Likes
1,729

HI Sandra,

Can u please elaborate on the transformation .

I am stuck for two days ,i read the help on sdn and do some R&D and noting ....

I try like u tell with :

i sure that i dont do that well

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

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

Can You help please to reach the solution.

Thanks & Best Regards

Chris

Read only

0 Likes
1,729

I guess you'll better understand with the solution I found:

:

Simple transformation:


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

  <tt:root name="XML_TAB"/>

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

</tt:transform>

Program :


data itab1 type string.
concatenate '<Containers>'
'       <Container workitemid="0000001" IsParent="X">'
'   <Element name="__INITIATO" value="U295"/>'
'   <Element name="_W_PRITY" value="5"/>'
'   <Element name="_F_VERSION" value="0000"/>'
'</Container>'
'<Container workitemid="0000001">'
'   <Element name="EXTENDED" value="X"/>'
'   <Element name="NOTE_REFERENCE" value=""/>'
'       </Container>'
'</Containers>'
into itab1.
TYPES: BEGIN OF ty_data,
     name TYPE string,
     value TYPE string,
END OF ty_data.
DATA: lt_data TYPE TABLE OF ty_data.
TYPES: BEGIN OF ty_data2,
     workitemid TYPE n LENGTH 7,
     isparent   TYPE flag,
     t_data     TYPE TABLE OF ty_data WITH DEFAULT KEY,
END OF ty_data2.
DATA: lt_data2 TYPE TABLE OF ty_data2.
DATA lo_st_error TYPE REF TO cx_st_error.
DATA message TYPE string.
TRY.
CALL TRANSFORMATION zext_file
        SOURCE XML itab1
        RESULT xml_tab = lt_data2.
  CATCH cx_sy_conversion_data_loss .
* do something
  CATCH cx_st_error INTO lo_st_error.
    message = lo_st_error->get_text( ).
    WRITE:/ message .
ENDTRY.

By the way, I don't know what ITAB1 is in your case, it was more simple in my case to define it as a string. Anyway, if it's something else, it should work the same.

Read only

0 Likes
1,729

HI Sandra ,

The code u write is working great (in lt_data i get the table values) but there is one problem ,

i don't get in table LT_DATA2 the values of the work item id and is parent .

do u have an idea why ?

Thanks a lot you save me

Best Regards

Chris

Read only

0 Likes
1,729

in fact I added the component names in the DDIC but not in the Simple Transformation, but I guess that now you can do it by yourself.

I hope that you understand how the ST works, you may ask me precisions if it is not clear.

Read only

0 Likes
1,729

HI Sandra,

Thank you,

I read the sap help http://help.sap.com/saphelp_nw70/helpdata/en/e3/7d4719ca581441b6841f1054ff1326/frameset.htm

and other topic on ST

but i don't find anything that can help me to figure this issue ,

since this root <Container workitemid="0000001" IsParent="X">

can change all the transformation since it change the tree structure .

You are the expert maybe u can give me a clue how to handle this issue ?

Regards

Chris

Edited by: Chris Teb on Aug 16, 2009 2:37 PM

Read only

0 Likes
1,729

Here it is :


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

  <tt:root name="XML_TAB"/>

  <tt:template>
    <Containers>
      <tt:loop name="b" ref=".XML_TAB">
        <Container>
          <tt:attribute name="workitemid" value-ref="$b.WORKITEMID"/>
          <tt:cond check="not-initial($b.ISPARENT)">
            <tt:attribute name="IsParent" value-ref="$b.ISPARENT"/>
          </tt:cond>
          <tt:loop name="a" ref="$b.T_DATA">
            <Element>
              <tt:attribute name="name" value-ref="$a.name"/>
              <tt:attribute name="value" value-ref="$a.value"/>
            </Element>
          </tt:loop>
        </Container>
      </tt:loop>
    </Containers>
  </tt:template>

</tt:transform>

As you can see, I indicated here that ISPARENT is optional (in deserialization (xml to abap), and the attribut is not generated in serialization (abap to xml) if abap ISPARENT is empty).

Read only

0 Likes
1,729

hi Sandra ,

You are amazing!!!!!!

How did u do that ?

Please if there any place except the sap help that i can learn about the transformation please let me know .

Thanks a lot and Best Regards

Chris

Read only

0 Likes
1,729

That's great.

When you have time, I advise you to read this sdn library document : [ABAP u2013 XML Mapping, Peter McNulty, SAP Labs, SAP TechEd 2004|https://www.sdn.sap.com/irj/scn/index?rid=/library/uuid/a89312f8-0b01-0010-86b3-fdd7178e0534&overridelayout=true]

There are demo programs in packages SST_DEMO et SXSLT_DEMO :SSTDEMO_FLIGHTS (ST), STRANSDEMO_FLIGHTS (ST), SXSLTDEMO_FLIGHTS (XSLT). Call first program SAPBC_DATA_GENERATOR to fill tables.

Of course, train yourself on little cases and use the SAP library to get examples for each ST command.

Read only

0 Likes
1,729

Thanks Again Sandra ,

For your time and your effort !

Best Regards

Chris

Read only

0 Likes
1,729

Experts,

I am wondering if you can help me. I know abap (up to SAP 4.6c versions) but I know nothing about XML ( I am lterally zero on XML). I want to learn XML in the contexts of ABAP programs in SAP Netweaver versions. I tied to google XML tutorials but information is overwhelmingly too much. I do not intend to become an XML expert but want to be able to learn XML only to the level where where I can use them in ABAP programs.

Can you guide me if there is some step by step material / documents/ tutorial on internet?

Thanks

AP