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 call-method variable bindings

0 Likes
2,155

Hi,

In a simple transformation program (internal table data to XML string) is it possible to control the value of an XML's element with the call-method tag? What I'm trying to do, further explained.

Here's my attempt at changing the output value of an XML element using the call-method tag by following this example:

If I understood the documentation correctly, the tag <tt:root name="SPFLI_TAB"> is bound to the static attribute SPFLI_TAB of class CL_DEMO_CALL_FROM_ST and calling its method GET_FLIGHTS updates the value of said attribute which changes the root in the ST which is referenced in the tag <tt:loop ref=".SPFLI_TAB">.

The class ZTEST_SIMPLE_TRANSFORMATION is a copy of the example's class with a new static attribute CURRCODE_CHANGED and static method CONCAT_1 (concatenates '_1' to the given string). I want the value of element <CURRCODE_CHANGED> to be modified by the method.

<?sap.transform simple?>
<tt:transform xmlns:tt="http://www.sap.com/transformation-templates">
  <tt:root name="SCARR_TAB"/>
  <tt:root name="SPFLI_TAB"/>
  <tt:variable name="carrid"/>

  <!-- NEW -->
  <tt:root name="CURRCODE_CHANGED"/>
  <tt:variable name="currcode_og"/>
  <!-- NEW -->

  <tt:template>
    <FlightList>
      <tt:loop ref=".SCARR_TAB">
        <Flights>

          <!-- NEW -->
          <tt:call-method class="ZTEST_SIMPLE_TRANSFORMATION" s-name="CONCAT_1">
            <tt:with-parameter name="IV_STRING" var="currcode_og"/>
          </tt:call-method>
          <CURRCODE_CHANGED>
            <tt:value ref=".CURRCODE_CHANGED"/>
          </CURRCODE_CHANGED>
          <!-- NEW -->

          <tt:assign ref="carrid" to-var="carrid"/>
          <tt:call-method class="CL_DEMO_CALL_FROM_ST" s-name="GET_FLIGHTS">
            <tt:with-parameter name="CARRID" var="carrid"/>
          </tt:call-method>
          <tt:loop ref=".SPFLI_TAB">
            <Connection>
              <tt:attribute name="ID" value-ref="CONNID"/>
              <From>
                <tt:value ref="CITYFROM"/>
              </From>
              <To>
                <tt:value ref="CITYTO"/>
              </To>
            </Connection>
          </tt:loop>
        </Flights>
      </tt:loop>
    </FlightList>
  </tt:template>

</tt:transform>

But when I execute the MAIN method, I get reference error:

The exception CX_ST_REF_ACCESS was raised within the method call of the include ZTEST_ST_WITH_METHOD_CALL in ZTEST_ST_WITH_METHOD_CALL in line 18.

Am I missing something?

Thank you and kind regards,

Emiliano

3 REPLIES 3
Read only

Sandra_Rossi
Active Contributor
1,966

I don't really get what you're trying to do (please clarify), but as a starting point you can change it this way, so that the variable "currcode_og" contains "test_1" after calling the method:

<tt:call-method class="ZTEST_SIMPLE_TRANSFORMATION" s-name="CONCAT_1">
    <tt:with-parameter name="IV_STRING" val="'test'"/>
    <tt:with-parameter name="CURRCODE_CHANGED" var="currcode_og"/>
</tt:call-method>
Read only

0 Likes
1,966

Hi Sandra,

The internal table SCARR_TAB has the field CURRCODE. Within the loop <tt:loop ref=".SCARR_TAB">, if I remove the call-method and reference CURRCODE (like this <tt:value ref="CURRCODE"/>, for example) it shows its value for each entry of SCARR_TAB as expected. What I want to do is modify CURRCODE for each entry of SCARR_TAB during the transformation so that the resulting value of CURRCODE in the XML contains the concatenated '_1'.

I'm trying to see whether it's possible to manipulate the abap data during the transformation so that I could, for example, format a date in whatever way I wanted. I hope I can do this by calling a method and changing the string there.

As you've suggested, I've tried adding the attribute val="test" to the parameter tag but it wont compile; I get the error "illegal value".

BR,

Emiliano

Read only

0 Likes
1,966

sorry:

<tt:call-method class="ZTEST_SIMPLE_TRANSFORMATION" s-name="CONCAT_1">
    <tt:with-parameter name="IV_STRING" val="'test'"/>
    <tt:with-parameter name="CURRCODE_CHANGED" var="currcode_og"/>
</tt:call-method>