ABAP Keyword Documentation → ABAP − Reference → Program Flow Logic → Conditional Expressions
COND, SWITCH - Type Inference for Actual Parameters
The following constructor expression can be passed to generically typed formal parameters as an actual parameter using the character #
as a symbol for the operand type:
is passed to generically typed formal parameters as an actual parameter using the character #
as a symbol for the operand type, the following type inference is performed for the character #
:
- If the data type of the operand after the first
THEN
is known statically and matches the generic type of the formal parameter, this data type is used.
- If the data type of the operand after the first
THEN
is known statically and does not match the generic type of the formal parameter or if it is not known statically, the type is derived from the generic type as follows:
string
forcsequence
andclike
xstring
forxsequence
decfloat34
fornumeric
anddecfloat
p
with the length 8 and no decimal places ifp
is generic
- The standard key for a standard table type with generic primary table key
c
, n
, and x
with generic lengths.
Other versions:
7.31 | 7.40 | 7.54
Note
Rules apply when deriving the type in cases where #
is specified for actual
parameters that can be passed to generically typed formal parameters. These rules prevent syntax errors
in programs that call a procedure and the procedure makes the full typing of a formal parameter type more general by switching to a generic type.
Example
The operator COND
generates a result of type string
in this case. The generic parameter p
has this type during the execution
of the method. This is shown by the value "g" returned by DESCRIBE FIELD
. The method call leads to a corresponding syntax warning.
PUBLIC SECTION.
CLASS-METHODS main IMPORTING p TYPE csequence.
ENDCLASS.
CLASS demo IMPLEMENTATION.
METHOD main.
DESCRIBE FIELD p TYPE DATA(t).
cl_demo_output=>display( |{ p } of type { t }| ).
ENDMETHOD.
ENDCLASS.
START-OF-SELECTION.
FIELD-SYMBOLS:
<fs1> TYPE any,
<fs2> TYPE any.
ASSIGN 'AM' TO <fs1>.
ASSIGN 'PM' TO <fs2>.
demo=>main( COND #( WHEN sy-timlo < '120000' THEN <fs1>
ELSE <fs2> ) ).