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

Simple Transformation

Former Member
0 Likes
550

Dear All,

I tried to parse xml and failed to get the value. Would you mind tell me why. Here I paste the program:

ABAP Program:


REPORT  z_elp_coba.

DATA: BEGIN OF line,
  pernr(8) TYPE c,
  begda(8) TYPE c,
  endda(8) TYPE c,
  wage(4)  TYPE c,
  amnt(15) TYPE c.
DATA: END OF line.
DATA itab LIKE TABLE OF line.
DATA: xmldata TYPE string.

CONCATENATE
'  <DPG2010>'
'    <PIN>12345678</PIN>'
'    <BEGDA>20080828</BEGDA>'
'    <ENDDA>20080829</ENDDA>'
'    <WAGETYPE>1W06</WAGETYPE>'
'    <AMOUNT>1500</AMOUNT>'
'    <PIN>87654321</PIN>'
'    <BEGDA>20080701</BEGDA>'
'    <ENDDA>20080719</ENDDA>'
'    <WAGETYPE>1W00</WAGETYPE>'
'    <AMOUNT>34000</AMOUNT>'
'  </DPG2010>' INTO xmldata.

CALL TRANSFORMATION z_dpg2010_transformation
                        SOURCE XML xmldata
                        RESULT DPG2010 = itab.

LOOP AT itab INTO line.
    WRITE:/ 'PIN  :', line-pernr.
    WRITE:/ 'BEGDA:', line-begda.
    WRITE:/ 'ENDDA:', line-endda.
    WRITE:/ 'WTYPE:', line-wage.
    WRITE:/ 'AMNT :', line-amnt.
    ULINE.
ENDLOOP.

ST Program:


<?sap.transform simple?>
<tt:transform xmlns:tt="http://www.sap.com/transformation-templates">
  <tt:root name="dpg2010"/>
  <tt:template>
    <DPG2010>
      <tt:loop ref=".dpg2010">
        <PIN>
          <tt:value/>
        </PIN>
        <BEGDA>
          <tt:value/>
        </BEGDA>
        <ENDDA>
          <tt:value/>
        </ENDDA>
        <WAGETYPE>
          <tt:value/>
        </WAGETYPE>
        <AMOUNT>
          <tt:value/>
        </AMOUNT>
      </tt:loop>
    </DPG2010>
  </tt:template>
</tt:transform>

Click here for captured result:

[Simple transform result|http://picasaweb.google.com/erick.lawrence/UntitledAlbum/photo?authkey=w4M-CP6Ay8A#5241351437478431794]

Thank you all for answers.

Regards,

Erick L. Panjaitan

3 REPLIES 3
Read only

Former Member
0 Likes
494

Please, I would appreciate any input. Thanks.

Read only

0 Likes
494

Finally I found the answer

For all of you need ST program to parse XML to ABAP, this might be usefull.

I modified this:


      <tt:loop ref=".dpg2010">
        <PIN>
          <tt:value/>
        </PIN>
...

Into this:


      <tt:loop name="a" ref=".dpg2010">
        <PIN>
          <tt:value ref="$a.pernr"/>
        </PIN>
...

For multi fields table, we have to put explicit reference.

Read only

Former Member
0 Likes
494

In multi-fields table we need to explicitly assign the references.