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 need help

Former Member
0 Likes
2,306

Hi all,

my provider sends me an XML document, which I try to parse with simple transformation

My problem is the following part:

<identifier>

     <key name="curvename" tt:value-ref="CURVENAME"/>
     <key name="group" tt:value-ref="GROUP"/>
</identifier>

Sometimes i get the line with curvename, sometimes the line with group, or I got both.

If curvename is missing I got an exception CX_ST_MATCH_TEXT

How can I prevent this.

Best regards Marcus

1 ACCEPTED SOLUTION
Read only

jeroen_verbrugge2
Active Participant
0 Likes
2,143

Hi,

You can use <tt:cond frq="?"> within <tt:group>.

More info: SAP Help on ST grouping

Have a look at attached examples, the ST will process them all filling a structure with two fields a and b.

Kind Regards,

Jeroen.

8 REPLIES 8
Read only

jeroen_verbrugge2
Active Participant
0 Likes
2,144

Hi,

You can use <tt:cond frq="?"> within <tt:group>.

More info: SAP Help on ST grouping

Have a look at attached examples, the ST will process them all filling a structure with two fields a and b.

Kind Regards,

Jeroen.

Read only

0 Likes
2,143

Hi Jeroen,

thanks, but it does not work

                <identifier>

              <tt:group>

                <tt:cond frq="?">
                  <key name="curvename" tt:value-ref="CURVENAME"/>
                </tt:cond>
                <tt:cond frq="?">
                  <key name="group" tt:value-ref="GROUP"/>
                </tt:cond>
              </tt:group>
              </identifier>

I tink the problem is caused by same tag <key> and only different attribut values for attribut name.

Kind regards

Marcus

Read only

0 Likes
2,143

Hi,

Sorry, I thought it was about optional elements.

For attributes of an element, it's similar.

Apply the grouping and the cond on the attributes.

Check example. Element a has two attributes, att1 and att2.

The simple transformation will process both without errors.

Kind Regards,

Jeroen

Read only

0 Likes
2,143

Hi,

FYI: the tt:cond is also working without tt:group. It is often just in a tt:group scenario but it's not mandatory...

This will also work:

<?sap.transform simple?>

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

   <tt:root name="ROOT"/>

   <tt:template>
     <identifier>
       <a>
           <tt:cond>
             <tt:attribute name="att1" value-ref="root.a"/>
           </tt:cond>
           <tt:cond>
             <tt:attribute name="att2" value-ref="root.b"/>
           </tt:cond>
       </a>
     </identifier>
   </tt:template>

</tt:transform>

Kind Regards,

Jeroen.

Read only

0 Likes
2,143

hi

it is a combintion of both i think

example 1

        <identifier>

          <key name="group">Test</key>

        </identifier>

example 2

        <identifier>

          <key name="curvename" ="Curve1"/>

          <key name="group">Test</key>

        </identifier>

example 3

        <identifier>

          <key name="curvename" ="Curve1"/>

        </identifier>

Every case is possible

I tried:

                <identifier>

                <tt:group>

                  <tt:cond frq="1">
                    <key>
                      <tt:group>
                        <tt:cond frq="?">
                          <tt:attribute name="curvename" value-ref="CURVENAME"/>
                        </tt:cond>
                        <tt:cond frq="?">
                          <tt:attribute name="group" value-ref="GROUP"/>
                        </tt:cond>
                      </tt:group>
                    </key>
                  </tt:cond>
                  <tt:cond frq="?">
                    <key>
                      <tt:group>
                        <tt:cond frq="?">
                          <tt:attribute name="curvename" value-ref="CURVENAME"/>
                        </tt:cond>
                        <tt:cond frq="?">
                          <tt:attribute name="group" value-ref="GROUP"/>
                        </tt:cond>
                      </tt:group>
                    </key>
                  </tt:cond>
                </tt:group>
              </identifier>

but in this catch I got the exception CX_ST_MATCH_ELEMENT

Kind regards

Marcus

Read only

0 Likes
2,143

Hi,

Are you saying that key is 1..n?

In that case, you'll need a <tt:loop>:

<?sap.transform simple?>

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

   <tt:root name="ROOT"/>

   <tt:template>
     <identifier>
       <tt:loop ref="ROOT">
         <a>
           <tt:cond>
             <tt:attribute name="att1" value-ref="a"/>
           </tt:cond>
           <tt:cond>
             <tt:attribute name="att2" value-ref="b"/>
           </tt:cond>
           <tt:skip/>
         </a>
       </tt:loop>
     </identifier>
   </tt:template>

</tt:transform>

If that's not the case, it's maybe easier if you attach a few example XML files to your message (use the advanced editor)

Kind Regards,

Jeroen

Read only

0 Likes
2,143

  <?sap.transform simple?>

<tt:transform xmlns:tt="http://www.sap.com/transformation-templates" xmlns:ddic="http://www.sap.com/abapxml/types/dictionary" xmlns:def="http://www.sap.com/abapxml/types/defined">
  <tt:root name="RESPONSE" type="ddic:ZMS_XML_PRICERESULT_SUBJECT"/>
  <tt:template>
    <response>
      <subject>
        <identifier>
          <key name="category" tt:value-ref=".RESPONSE.CATEGORY"/>
        </identifier>
        <identifier>
          <key>
            <tt:group>
              <tt:cond data="'curvename'=ref('.RESPONSE.CURVENAME_TXT')">

                <tt:attribute name="name">
                  <tt:value ref=".RESPONSE.CURVENAME_TXT"/>
                </tt:attribute>
                <tt:value ref=".RESPONSE.CURVENAME"/>
                <!--              &lt;/key&gt;-->
              </tt:cond>
              <tt:cond data="'hdbgroup'=ref('.RESPONSE.CURVENAME_TXT')">
                <!--              &lt;key&gt;-->
                <tt:attribute name="name">
                  <tt:value ref=".RESPONSE.CURVENAME_TXT"/>
                </tt:attribute>
                <tt:value ref=".RESPONSE.HDBGROUP"/>

              </tt:cond>
            </tt:group>
          </key>
        </identifier>
      </subject>
    </response>
  </tt:template>
</tt:transform>

The structure has only four elements type char 30

CATEGORY

CURVENAME

HDBGROUP

CURVENAME_TXT

Read only

0 Likes
2,143

Hi,

Im tot sure what you want to achieve but looking to your examples I think you mixup a few things or making it too difficult.


The structure of the XML is nested, multiple identifiers can exist and each can have multiple keys.

Each key element has only 1 attribute name. This is always the case. So there is no conditional processing needed. It's the values that are changing.

I think it's easier to first parse the XML content in a table having the same structure as the XML.
Then if needed you can transform this table to another structure in your program by looping over the result.

I think with the information you have your question is answered

Kind regards,
Jeroen