Ansicht
Dokumentation

ABENCONDITIONAL_EXPRESSION_SWITCH - CONDITIONAL EXPRESSION SWITCH

ABENCONDITIONAL_EXPRESSION_SWITCH - CONDITIONAL EXPRESSION SWITCH

Vendor Master (General Section)   Addresses (Business Address Services)  
This documentation is copyright by SAP AG.
SAP E-Book

SWITCH, Conditional Operator

... SWITCH type( $[let_exp$]
                 operand
                 WHEN const1 THEN $[ let_exp$] result1
               $[ WHEN const2 THEN $[ let_exp$] result2 $]
               ...
               $[ ELSE $[ let_exp$] resultn $] ) ...


Effect

A conditional expression with the conditional operator SWITCH has a result, result, that is dependent on a case distinction. Either a value with the data type specified by type is produced or a class-based exception is raised. The following can be specified for type:

The position operand in the parentheses is the value that is checked in the case distinction. This is a general expression position. It must be followed by at least one WHEN. Literals and constants can be specified for const after WHEN. It must be possible to compare them with operand. Substring access is not possible. This can be followed by any number of WHEN statements with further constant values. An ELSE can be specified at the end. This expression compares the values of the operand operand with the specified constant values one after another and chooses the result after THEN for which the values of operand and constant are identical for the first time. The selected result determines the result of the conditional expression. If no matches are found, the result specified after ELSE is selected. If ELSE is not specified, the result is the initial value of the data type type.

If a specification after THEN or ELSE can be selected, either the result is set or a class-based exception is raised, just as with a conditional expression COND.

To define local helper fields, an optional LET expression can be specified in front of the operand operand, after every THEN, and after ELSE.

Notes

  • A conditional expression with SWITCH has the same meaning as the following conditional expression with COND:
COND type( WHEN operand = const1 THEN result1
         $[ WHEN operand = const2 THEN result2 $]
         ...
         $[ ELSE resultn $] )

Example

Conditional operator SWITCH in an operand position in a loop. The loop is exited when the exception after ELSE is caught.






Vendor Master (General Section)   TXBHW - Original Tax Base Amount in Local Currency  
This documentation is copyright by SAP AG.

Length: 4837 Date: 20240427 Time: 043714     sap01-206 ( 72 ms )