Skip to content

ABAP Keyword Documentation →  ABAP − Reference →  Processing Internal Data →  Assignments →  CONV - Conversion Operator →  CONV - Type Inference for Actual Parameters 

Conversion Operator, Type Inference

This example demonstrates a type inference for the conversion operator CONV.

Other versions: 7.31 | 7.40 | 7.54

Source Code

    FIELD-SYMBOLS <fs> TYPE any.
    DATA txt TYPE c LENGTH 20.
    DATA num TYPE i.
    ASSIGN num TO <fs>.

    demo=>meth1( p = CONV #( txt  ) ) ##operator.
    demo=>meth1( p = CONV #( num  ) ).
    demo=>meth1( p = CONV #( <fs> ) ).
    cl_demo_output=>line( ).

    demo=>meth2( p = CONV #( txt  ) ) ##operator.
    demo=>meth2( p = CONV #( num  ) ).
   "demo=>meth2( p = CONV #( <fs> ) ). "not possible
    cl_demo_output=>line( ).

    demo=>meth3( p = CONV #( txt  ) ) ##operator.
    demo=>meth3( p = CONV #( num  ) ) ##type.
    demo=>meth3( p = CONV #( <fs> ) ) ##type.
    cl_demo_output=>display( ).

Description

Passes constructor expressions with the conversion operator CONV to differently typed formal parameters of methods. In the case of generic formal parameters, special rules apply when identifying the operand type.

  • Fully typed formal parameter
When the method meth1 is called with a fully typed formal parameter, the operand type for # is identified using this parameter and the result of the reduction is converted to c with length 10 in both calls. The first conversion is redundant here.
  • Formal parameter typed generically with c
The operand type for # is determined from the argument.
  • In the first call, the type c with length 20 of the argument matches the generic type and is used, which is why this conversion is redundant.
  • In the second call, the type i does not match the generic type and the type c with the predefined output length 11 of i is used.
  • Calls with the generically typed field symbol <fs> are not possible, since no type can be derived from the argument.
  • Formal parameter typed generically with csequence
  • In the first call, the type c with length 20 of the argument matches the generic type and is used, which is why this conversion is redundant.
  • In the second call, the type i does not match the generic type and the type string is used. This is indicated by a syntax check warning.
  • In the third call, no type can be determined from the generically typed field symbol <fs> and the type string is used. This is indicated by a syntax check warning.