Application Development 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: 

Simple Transformation Problem

dmi
Participant
0 Kudos

hello

I got the requirement to export data from a sap table to a xml file. The xml file must be in the followed form:

<StoreMaterial>
  <Material Name="ArticleNb" Value="value from SAP"/>
  <Material Name="MatDesc" Value="value from SAP"/>
</StoreMaterial>

What is the correct syntax to create this node in one line:
<Material Name="ArticleNb" Value="value from SAP" />

value from SAP is e.g. a material number

many thanks Daniel

10 REPLIES 10

Sandra_Rossi
Active Contributor
0 Kudos

Did you try anything? What is the structure of your internal table?

Something like that:

<?sap.transform simple?>
<tt:transform xmlns:tt="http://www.sap.com/transformation-templates" xmlns:ddic="http://www.sap.com/abapxml/types/dictionary">
  <tt:root name="ROOT"/>
  <tt:template>
    <XMLROOT>
      <tt:loop ref=".ROOT">
        <StoreMaterial>
         <Material Name="ArticleNb">
          <tt:attribute name="Value" value-ref="$ref.ARTICLENB"/>
          </Material>
         <Material Name="MatDesc">
          <tt:attribute name="Value" value-ref="$ref.MATDESC"/>
          </Material>
        </StoreMaterial>
      </tt:loop>
    </XMLROOT>
  </tt:template>
</tt:transform>

?

EDIT 15 hours later: sorry, it was value-ref, not ref.

0 Kudos

Hello Sandra
Your propose helps me, but there is still a problem:

The first Node "ArticleNb" is not correct, the next nodes are correct
If I delete the first Node "ArticleNb", the next nodes are not correct
The result you can see in the printscreen. Do you have any idea for this problem?
Many thanks, Daniel

<StoreMaterial>
  <tt:loop name="data" ref="$line.data">
    <Material Value="ArticleNb">        " display wrong
      <tt:attribute name="Name">
        <tt:value ref="articlenb"/>
      </tt:attribute>
    </Material>
    <Material Name="ArticleNb">         " display correct
      <tt:attribute name="Value">
        <tt:value ref="articlenb"/>
      </tt:attribute>
    </Material>
    <Material Name="MatDesc">          " display correct
      <tt:attribute name="Value">
        <tt:value ref="matdesc"/>
      </tt:attribute>
    </Material>
  </tt:loop>
</StoreMaterial>


0 Kudos

I already answered on your same post 2 days ago. Why do you need to keep the first node? What is the expected result? (please, not in words, but in XML)

It's normal that with :

<Material Value="ArticleNb">
<tt:attribute name="Name">
<tt:value ref="articlenb"/>
</tt:attribute> </Material>

you get

<Material Name="8.28.005.210" Value="ArticleNb"/>

Look carefully your code.

0 Kudos

Hi Sandra
Sorry, I'm anyoing, but what is wrong with my code?
The expected result can you see in the print screen, I have only a specification, I can't show you in xml, only in word.
Sorry again and many thanks, Daniel
My ST:

sap-st.txt

My requirement

<?xml version="1.0" encoding="iso-8859-1" ?>
<StoreInventoryDataList>
<StoreMaterial>
<Material Name="ArticleNb" Value="DD11"/>
<Material Name="MatDesc" Value="mild steel"/>

My result:

dmi
Participant
0 Kudos

Hello Sandra
I tryed with text, it looks like what I need, but there is no cr between the nodes ArticleNb and MatDesc
It's possible to make a line feed?
Thank you in advance, Daniel

        <StoreMaterial>
          <tt:loop name="data" ref="$line.data">

            <tt:text>Material Name = "ArticleNb" Value="</tt:text>
            <tt:value ref="articlenb"/>
            <tt:text>"</tt:text>
            
            <tt:text>Material Name = "MatDesc" Value="</tt:text>
            <tt:value ref="matdesc"/>
            <tt:text>"</tt:text>

          </tt:loop>
        </StoreMaterial>

dmi
Participant
0 Kudos

Now I found the solution - but???
The first Node "ArticleNb" is not correct, the next nodes are correct
If I delete the first Node "ArticleNb", the next nodes are not correct
I can't find out the reason, thanks for any help
Daniel

<StoreMaterial>
  <tt:loop name="data" ref="$line.data">
    <Material Value="ArticleNb">        " display wrong
      <tt:attribute name="Name">
        <tt:value ref="articlenb"/>
      </tt:attribute>
    </Material>
    <Material Name="ArticleNb">         " display correct
      <tt:attribute name="Value">
        <tt:value ref="articlenb"/>
      </tt:attribute>
    </Material>
    <Material Name="MatDesc">          " display correct
      <tt:attribute name="Value">
        <tt:value ref="matdesc"/>
      </tt:attribute>
    </Material>
  </tt:loop>
</StoreMaterial>

Sandra_Rossi
Active Contributor
0 Kudos

I tried your example and have no issue if I remove the first <Material ... </Material>

0 Kudos

Hi Daniel,

Ideally Creating a node is important for correct output.please check with the node and the structure how your are refering in the coding part.Check with the screen shot may be this would helpful.You can also have test transformation T-Code : XSLT_TOOL give transformation name as SP12_TESTVECTOR2.

capture.png

Former Member
0 Kudos

Hi Daniel in ST you can create a corresponding DDIC structure and the base ST code is generated when u use it in STRANS.

Then you can improve it further. both for deserelization and serilization.

0 Kudos

Hi Prasenjit
Thanks for help, but all what I need is a solution to create a xml in this form:

Normal XML:
 <ArticleNb>123456789</ArticleNb>
  <MatDesc>somthing</Matdesc>
My requirement: <Material Name="ArticleNb" Value="123456789"/> <Material Name="MatDesc" Value="something"/>