SAP ST TT SWITCH-VAR



Get Example source ABAP code based on a different SAP table
  


• switch-var ABAP_ST_ELEMENT

ABAP_ST - tt:switch-var, Case Distinction for Variables

ABAP_SYNTAX
< tt:switch-var>
< tt:$[s-$|d-$]cond-var ...
< tt:$[s-$|d-$]cond-var ...
...
< /tt:switch-var>

What does it do?
The statement tt:switch-var allows case distinctions in which, unlike tt:switch, only cases for data content can be specified, not for data flow. In tt:switch, a list of cases can be shown where the syntax of each case is formulated by a condition for variables, namely a tt:cond-var subelement. Other direct subelements are not possible in tt:switch-var.
No more than one case can be specified that does not contain a check condition.

Serialization and Deserialization
Serialization and deserialization follow these rules: The first case tt:cond-var, whose explicitly specified condition check is met, is processed and the element tt:switch-var is exited. If no condition is met for any case with explicitly specified conditions, the case without condition is executed by default (if it e xists) and the element tt:switch-var is exited. If no case without condition exists, the element tt:switch-var is exited without any case being processed.

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

ABAP_EXAMPLE_VX5
The following transformation DEMO_ST_SWITCH_VAR expands the example from Conditions for Variables.
TRNS DEMO_ST_SWITCH_VAR
Depending on the value of the ABAP data object bound to ROOT, the serialization creates either of the following: < X val='small'>... < /X>
or < X val='medium'>... < /X>
or < X val='big'>... < /X>
is created. 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.
ABAP_EXAMPLE_END