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
2,078

Hello,

I have following transformation:


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

  <tt:root name="ROOT"/>

  <tt:template>

    <Payload tt:ref="ROOT">

              <Language>
                <tt:value ref="LANGUAGE"/>
              </Language>

              <Location>
                <tt:value ref="LOCATION_COUNTRY"/>
              </Location>

    </Payload>
  </tt:template>
</tt:transform>

I call the transformation with

CALL TRANSFORMATION zconvert_st

SOURCE root = struc1

RESULT XML xml_string.

struc1 is an internal table. but how have to I write the transformation when the internal table has more than 1 line? The transformation run only when I have 1 line, but I want to listed all lines in the xml

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,977

now I have this definition and see it works

TYPES: BEGIN OF ty_struc1,

name(29) TYPE c,

location_country(10) TYPE c,

stras(29) TYPE c,

code(29) TYPE c,

cityorsuburb(29) TYPE c,

stateorprovince(29) TYPE c,

postcode(29) TYPE c,

language(29) TYPE c,

END OF ty_struc1.

DATA: struc1 TYPE STANDARD TABLE OF ty_struc1,

gs_struc1 LIKE LINE OF struc1.

but why cannot I use the older definition of my itab?

16 REPLIES 16
Read only

naimesh_patel
Active Contributor
0 Likes
1,977

You can use the TT:LOOP tag to loop through your supplied internal table.


<?sap.transform simple?>
<tt:transform xmlns:tt="http://www.sap.com/transformation-templates">
 
  <tt:root name="ROOT"/>
 
  <tt:template>
 
   <tt:loop ref=".ROOT">
    <Payload tt:ref="ROOT">
 
              <Language>
                <tt:value ref="LANGUAGE"/>
              </Language>
 
              <Location>
                <tt:value ref="LOCATION_COUNTRY"/>
              </Location>
 
    </Payload>
  </tt:loop>
  </tt:template>
</tt:transform>

Regards,

Naimesh Patel

Read only

0 Likes
1,977

Hi,

now I always get a dump at line

<tt:loop ref=".ROOT">

Read only

0 Likes
1,977

I forgot to mention that we need to use the <TABLE> </TABLE> tag. This example works as intented:

Program:


TYPES: BEGIN OF ty_mara,
       matnr TYPE matnr,
       END   OF ty_mara.

DATA: itab TYPE STANDARD TABLE OF ty_mara,
      la_tab LIKE LINE OF itab,
      xmlstr TYPE xstring.

la_tab-matnr = 'TEST1'.
APPEND la_tab TO itab.

la_tab-matnr = 'TEST2'.
APPEND la_tab TO itab.


CALL TRANSFORMATION ztest_np
  SOURCE table = itab
  RESULT XML xmlstr.

CALL FUNCTION 'DISPLAY_XML_STRING'
  EXPORTING xml_string = xmlstr.

Transformation:


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

  <tt:root name="table"/>

  <tt:template>
    <table>
      <tt:loop ref=".table">
        <item>
          <MATNR>
            <tt:value ref="MATNR"/>
          </MATNR>
        </item>
      </tt:loop>

    </table>

  </tt:template>

</tt:transform>

Regards,

Naimesh Patel

Edited by: Naimesh Patel on Mar 3, 2009 8:39 AM

Read only

0 Likes
1,977

Hi Naimesh,

I test your program and it works perfect but when I edit my program depending on yours I always get the dump at the mentioned coding loop.

this is my current transformation


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

  <tt:root name="table"/>

  <tt:template>

    <Payload>

      <tt:loop ref=".table">
        <item>

          <Language>
            <tt:value ref="LANGUAGE"/>
          </Language>

          <Location>
            <tt:value ref="LOCATION_COUNTRY"/>
          </Location>


        </item>
      </tt:loop>

    </Payload>

  </tt:template>
</tt:transform>

Read only

0 Likes
1,977

Wierd, it works good for me. Do you have LANGUAGE & LOCATION_COUNTRY in your table?

Regards,

Naimesh Patel

Read only

0 Likes
1,977

this is my internal table :


DATA: BEGIN OF struc1 OCCURS 0,

        name(29)             TYPE c,
        location_country(10) TYPE c,
        stras(29)            TYPE c,
        code(29)             TYPE c,
        language(29)         TYPE c,

END OF struc1.

DATA: gs_struc1 LIKE LINE OF struc1.

gs_struc1-name             = 'name_2'.
gs_struc1-location_country = 'country_2'.
gs_struc1-stras            = 'Street_2'.
gs_struc1-code             = 'code_2'.
gs_struc1-language         = 'ENG_2'.

APPEND gs_struc1 TO struc1.

gs_struc1-name             = 'name'.
gs_struc1-location_country = 'country'.
gs_struc1-stras            = 'Street'.
gs_struc1-code             = 'code'.
gs_struc1-language         = 'ENG'.

APPEND gs_struc1 TO struc1.

CLEAR xml_string.

CALL TRANSFORMATION zconvert_st2
SOURCE table = struc1
RESULT XML xml_string.


Read only

0 Likes
1,977

when I change MATNR in your transformation with Location and Language I also get the dump.

Is the problem depending on my internal table?

Read only

0 Likes
1,977

did somenone has an idea?

Read only

0 Likes
1,977

no answers?

Read only

Former Member
0 Likes
1,978

now I have this definition and see it works

TYPES: BEGIN OF ty_struc1,

name(29) TYPE c,

location_country(10) TYPE c,

stras(29) TYPE c,

code(29) TYPE c,

cityorsuburb(29) TYPE c,

stateorprovince(29) TYPE c,

postcode(29) TYPE c,

language(29) TYPE c,

END OF ty_struc1.

DATA: struc1 TYPE STANDARD TABLE OF ty_struc1,

gs_struc1 LIKE LINE OF struc1.

but why cannot I use the older definition of my itab?

Read only

0 Likes
1,977

On line help on the CALL TRANSFORMATION says:

Addition 2a

... PARAMETERS {{p1 = e1 p2 = e2 ...}|(ptab)}

Effect

Use this addition to pass ABAP data objects e1 e2 ... as parameters p1 p2 ... to an XSL transformation. In Release 6.10, the data objects e1 e2 ... must be character-type, as of release 6.20 all elementary data objects and object references are allowed.

When you use your old table definition, system doesn't create the table witht he Character Type. With the new defintion (TYPE STANDARD TABLE OF ty... ) it is now the compitible with the CALL TRANSFORMATION.

Regards,

Naimesh Patel

Read only

Former Member
0 Likes
1,977

I have one further question

Read only

0 Likes
1,977

I have values in the original xml which are within the symbol " ".

How can I add a value from the internal table into the field symbol " " ?

The origin XML:


<Origin Code1="value1" Code2="value2">

when I write in the simple transformation :


<Origin Code1=" <tt:value ref="VALUE1"/> Code2=" <tt:value ref="VALUE2"/>>

It doesn't work. How do I have to write the syntax therefore?

Read only

0 Likes
1,977

I have the solution, you have to use attributes like

<Origin>

<tt:attribute name="Code1" value-ref="ROOT1" />

ROOT1 is the field of your internal table and the result is :

<Origin Code1="value1">

Read only

0 Likes
1,977

Hi,

I have a problem with the order of the namespaces.

I have following header in my transformation:


<?sap.transform simple?>
<tt:transform xmlns:tt="http://www.sap.com/transformation-templates" xmlns:xsi="http://www.w3.org" xmlns:xsd="http://www.w3.org/2001">

  <tt:root name="table"/>

  <tt:template>

    <XmlInterchange Version="1">
      <tt:namespace name="xsi" />
      <tt:namespace name="xsd" />

the problem is that I want to list Version="1" after the namespace xsd, but I don't know how it should work?

Read only

Former Member
0 Likes
1,976

a posted to a wrong place, sorry

Edited by: hoffmanng on Apr 24, 2009 12:41 PM