Application Development Blog Posts
Learn and share on deeper, cross technology development topics such as integration and connectivity, automation, cloud extensibility, developing at scale, and security.
cancel
Showing results for 
Search instead for 
Did you mean: 
LaurensDeprost
Contributor
7,029
After coming into contact with ABAP, developers with experience in other programming languages often wonder if there is a ternary operator available in ABAP similar to the construct a ? b : c.

Unfortunately, there is not.

However, using 7.40 syntax, we can achieve something that comes pretty close with the conditional operator COND:
DATA(is_even) = COND #(
WHEN number MOD 2 EQ 0
THEN abap_true
ELSE abap_false ).





The code above is equivalent to the more conventional if-else statement below:
IF number MOD 2 EQ 0.
DATA(is_even) = abap_true.
ELSE.
is_even = abap_false.
ENDIF.





Finally, note that for this particular example, filling a boolean variable based on a condition, the more concise xsdbool function can be used:
DATA(is_even) = xsdbool( number MOD 2 EQ 0 ).
1 Comment
Labels in this area