Ternary operator (alternatives)

No, in ABAP there is no operator similar to the construct a ? b : c known from other languages. In your concrete example, however, you could declare default values for your method parameters iv_class etc. in the method's signature.


Release 7.40 brings a whole bunch of ABAP improvements which I'm finding heaps interesting. The ternary style declaration (at least something that resembles it) is one of them

Syntax:

COND dtype|#( WHEN log_exp1 THEN result1 
            [ WHEN log_exp2 THEN result2 ] 
            ... 
            [ ELSE resultn ] ) ...

Example data declaration of a variable called 'bool' and a conditional value assignment in one line. Old skool ABAP this will take like 10 lines.

DATA(bool) = COND #( WHEN i * i > number THEN abap_true ELSE abap_false ).

More info: http://scn.sap.com/community/abap/blog/2013/07/22/abap-news-for-release-740

Tags:

Abap