The statement tt:switch-var enables case distinctions in which, unlike tt:switch, you cannot specify cases for the data flow but only for data contents:
<tt:switch-var>
case1
case2
...
</tt:switch-var>
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, which does not contain a condition check.
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
Unlike the general case distinction with tt:switch, the contents of the cases are irrelevant.
The following transformation extends the example from Conditions for Variables.:
<tt:transform xmlns:tt="http://www.sap.com/transformation-templates">
<tt:root name="ROOT"/>
<tt:template>
<tt:apply
name="SUB">
<tt:with-parameter name="PARA" ref="ROOT"/>
</tt:apply>
</tt:template>
<tt:template name="SUB">
<tt:context>
<tt:parameter name="PARA"/>
</tt:context>
<tt:switch-var>
<tt:cond-var check="PARA<50">
<X val="small">...</X>
</tt:cond-var>
<tt:cond-var
check="PARA<100">
<X val="medium">...</X>
</tt:cond-var>
<tt:cond-var>
<X val="big">...</X>
</tt:cond-var>
</tt:switch-var>
</tt:template>
</tt:transform>
Depending on the value of the ABAP data object bound to ROOT, the serialization generates either of the following:
<X val="small">...</X>
<X val="medium">...</X>
<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.