Get Example source ABAP code based on a different SAP table
Conditional Operator, Type Inference This example demonstrates a type inference for the conversion operator COND>>.
ABAP_SOURCE_CODE DEMO CL_DEMO_COND_TYPE_INFERENCE
ABAP_DESCRIPTION Constructor expressions with the conditional operator COND>> are passed to differently typed formal parameters of methods. In the case of generic formal parameters, special rules> apply when determining the operand type. Replacing the conditional operator COND> with SWITCH>> produces the same results.
Completely typed formal parameter When the method meth1> is called with a completely typed formal parameter, the operand type for #> is determined using this parameter and the result of the conditional expression is converted to c> with length 10 in all three calls.
Formal parameter typed generically with c> The operand type for #> is determined from the data type of the operand after THEN>.
In the first call, the type c> with length 20 of the operand after THEN> matches the generic type and is used.
In the second call, the type i> of the operand after THEN> does not match the generic type and the call is not possible.
In the third call, no type can be derived from the generically typed field symbol <(><)>> after THEN>. No call is possible here, since there is no inference rule for the generic type c>.
Formal parameter typed generically with csequence>
In the first call, the type c> with length 20 of the operand after THEN> matches the generic type and is used.
In the second call, the type i> of the operand after THEN> does not match the generic type and the type string> is used, which is indicated by a syntax check warning.
In the third call, no type is derived from the generically typed field symbol <(><)>> after THEN> and the type string> is used, which is indicated by a syntax check warning.