Skip to Content
-2

Simple Transformation Problem

Dec 08, 2017 at 06:15 AM

144

avatar image

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 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

5 Answers

Daniel Mueller Dec 08, 2017 at 10:12 AM
-1

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>

Share
10 |10000 characters needed characters left characters exceeded
avatar image
Former Member Dec 09, 2017 at 07:42 AM
0

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.

Show 1 Share
10 |10000 characters needed characters left characters exceeded

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"/>
0
Sandra Rossi Dec 08, 2017 at 08:17 AM
0

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.

Show 3 Share
10 |10000 characters needed characters left characters exceeded

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>


98312-xml.png (38.3 kB)
0

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

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:

sap-st.txt (903 B)
result.png (26.1 kB)
0
Daniel Mueller Dec 08, 2017 at 12:14 PM
0

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>

xml.png (38.3 kB)
Show 1 Share
10 |10000 characters needed characters left characters exceeded

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

0
Naresh Raj Dec 08, 2017 at 02:44 PM
0

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


capture.png (273.2 kB)
Share
10 |10000 characters needed characters left characters exceeded