We all know this fancy new pseudo-ternary operator as COND:
COND #( WHEN 1 = 1 THEN something ELSE everything ).
However, recently during the practices I noticed weird thing with typing of returned variable: it always get type of the first THEN operand and this had been confirmed by the ABAP help.
If the operand type is not fully identifiable, an operand with a statically identifiable type must be specified after the first THEN (except when passing the constructor parameter to an actual parameter with generically typed formal parameter). This type is then used.
DATA(val) = COND #( WHEN quantity NE '0.00' THEN CONV wrbtr( quantity ) ELSE '' )
In this example val
variable will always have packed type disregard of the value of quantity
.
How can we achieve conditional typing here? I.e. WRBTR
type with non-empty quantity and string type with empty quantity.
It is very often a requirement during passing internal data to external systems, external methods/FMS, as well as external formats (Excel, CSV).
Is there some syntax I am missing with COND
and CONV
operators? Can we achieve this with their help? Or maybe there is some more fancier syntax except
IF quantity NE '0.00'.
val = VALUE wrbtr( ).
ELSE.
val = VALUE string( ).
ENDIF.