Is there a triple or conditional statement available in ABAP syntax? I did not find it, so I guess there is no answer, but is there an alternative that I can use to clear the usual "dumb" IF statements that I usually use?
For example, consider a method that logs a message with optional message parameters. To choose between an imported parameter or a default value, I have to check the value as follows:
IF iv_class IS INITIAL. lv_message_class = 'DEFAULT'. ELSE. lv_message_class = iv_class. ENDIF. IF iv_number IS INITIAL. lv_message_number = '000'. ELSE. lv_message_number = iv_number. ENDIF. IF iv_type IS INITIAL. lv_message_type = 'E'. ELSE. lv_message_type = iv_type. ENDIF.
The ternary operator will reduce each of these five-line operators to one line, as shown in the lower code block. This may even make the temporary variable unnecessary when the statement is used in a string.
lv_message_class = iv_class IS INITIAL ? 'DEFAULT' : iv_class. lv_message_number = iv_number IS INITIAL ? '000' : iv_number . lv_message_type = iv_type IS INITIAL ? 'E' : iv_type .
Is there any way to bring this programming style closer to ABAP or am I stuck with a mess?
sap abap
Lilienthal
source share