sapdev logo background
sapdev logo sapdev logo
Comments

SAP CONDITIONAL EXPRESSION COND documentation, setup help and example usage



Return to SAP documentation index


ARTICLE

COND - Conditional Operator

Syntax
... COND type( WHEN log_exp1 THEN result1
[ WHEN log_exp2 THEN result2 ]
...
[ ELSE resultn ] ) ...

Effect
A conditional expression with the conditional operator COND has a result, result , that is specified by logical expressions. Either a value with the data type specified by type is produced or a class-based exception raised. The following can be specified for type :
In the parentheses, WHEN must be specified with at least once with any logical expression log_exp . This can be followed by any number of
WHEN s with further logical expressions. An ELSE can be specified at the end. The expression evaluates the logical expressions one after the other and selects the result specified after THEN of the first logical expression whose result is true. The selected result determines the result of the conditional expression. If none of the logical expressions are true, the result specified after ELSE is selected. If ELSE is not specified, the result is the initial value of the data type type .

Example
Transforms a time to 12 hour format using a conditional expression in an operand position. The type of the result is used by the operand after the first specified THEN , which makes it string .
CLASS cx_cant_be DEFINITION INHERITING FROM cx_no_check.
ENDCLASS.

cl_demo_output=>display(
COND #( WHEN sy-timlo <(><<)> '120000' THEN
|{ sy-timlo TIME = ISO } AM|
WHEN sy-timlo > '120000' AND sy-timlo <(><<)> '240000' THEN
|{ CONV t( sy-timlo - 12 * 3600 ) TIME = ISO } PM|
WHEN sy-timlo = '120000' THEN
|High Noon|
ELSE
THROW cx_cant_be( ) ) ).
Documentation extract taken from SAP system, � Copyright SAP AG. All rights reserved




CONDITIONAL_EXPRESSIONS
CONDITIONAL_EXPRESSION_GLOSRY




comments powered by Disqus