Show TOC

Syntax documentationCase Distinctions for Variables Locate this document in the navigation structure

The statement tt:switch-var allows case distinctions in which, unlike tt:switch, you can only specify cases for data content, not for data flow:

Syntax Syntax

  1. <tt:switch-var> 
  2.   case1
  3.   case2
  4.  </tt:switch-var>
End of the code.

In tt:switch, you can specify a list of cases case1, case2, ... Syntactically, every case case1, case2, ... is formulated by a condition for variables – that is, a subelement tt:cond-var. Other direct subelements are not possible in tt:switch-var.

You can specify no more than one case that does not contain a check condition.

Serialization and Deserialization

Serialization and deserialization follow these rules:

  1. The first case tt:cond-var, whose explicitly specified condition is met, is processed and the element tt:switch-var is left.

  2. If no condition is met for any case with explicitly specified conditions, the case without condition is executed by default (if it exists) and the element tt:switch-var is left.

  3. If no case without condition exists, the element tt:switch-var is left without any case being processed.

Note Note

Unlike the general case distinction with tt:switch, the content of the cases is irrelevant.

End of the note.
Example

The following transformation extends the example from Conditions for Variables.

Syntax Syntax

  1. <tt:transform xmlns:tt="http://www.sap.com/transformation-templates">
  2.   <tt:root name="ROOT"/>
  3.   <tt:template>
  4.     <tt:apply name="SUB">
  5.       <tt:with-parameter name="PARA" ref="ROOT"/>
  6.     </tt:apply>
  7.   </tt:template>
  8.   <tt:template name="SUB">
  9.     <tt:context>
  10.       <tt:parameter name="PARA"/>
  11.     </tt:context>
  12.     <tt:switch-var>
  13.       <tt:cond-var check="PARA<50">
  14.         <X val="small">...</X>
  15.       </tt:cond-var>
  16.       <tt:cond-var check="PARA<100">
  17.         <X val="medium">...</X>
  18.       </tt:cond-var>
  19.       <tt:cond-var>
  20.         <X val="big">...</X>
  21.       </tt:cond-var>
  22.     </tt:switch-var>
  23.   </tt:template>
  24. </tt:transform>
End of the code.

Depending on the value of the ABAP data object bound to ROOT, the serialization generates either of the following:

<X val="small">...</X>

or

<X val="medium">...</X>

or

<X val="big">...</X>

The position of the element tt:cond-var without explicit condition within tt:switch-var is irrelevant. However, the order of the elements tt:cond-var with explicit conditions is relevant.