Skip to Content
avatar image
Former Member

Simple Transformation

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

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

2 Answers

  • avatar image
    Former Member
    Sep 08, 2008 at 02:18 AM

    Please, I would appreciate any input. Thanks.

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member

      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.

  • avatar image
    Former Member
    Sep 21, 2008 at 06:03 AM

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

    Add comment
    10|10000 characters needed characters exceeded