Skip to Content
-2

Simple Transformation Problem

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

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

5 Answers

  • 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>
    
    
    Add comment
    10|10000 characters needed characters exceeded

  • Dec 09, 2017 at 07:42 AM

    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.

    Add comment
    10|10000 characters needed 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"/>
  • Dec 08, 2017 at 08:17 AM

    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.

    Add comment
    10|10000 characters needed characters exceeded

    • 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)
  • Dec 08, 2017 at 12:14 PM

    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>
    
    Add comment
    10|10000 characters needed characters exceeded

  • Dec 08, 2017 at 02:44 PM

    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

    Add comment
    10|10000 characters needed characters exceeded