Skip to content

ABAP Keyword Documentation →  ABAP − Reference →  Program Flow Logic →  Iteration Expressions →  REDUCE - Reduction Operator 

REDUCE - Type Inference for Actual Parameter

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:

REDUCE #( ... INIT ... FOR ... )

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 first declaration after INIT matches the generic type of the formal parameter, this data type is used.
  • If the data type of the first declaration after INIT does not match the generic type of the formal parameter, the type is derived from the generic type as follows:
  • string for csequence and clike
  • xstring for xsequence
  • decfloat34 for numeric and decfloat
  • p with the length 8 and no decimal places if p is generic
  • The standard key for a standard table type with generic primary table key
Other generic data types (except for table types) that are explicitly generic with respect to their secondary table keys cannot be made more concrete and produce a syntax error. More specifically, this applies to the types c, n, and x with generic lengths.

Other versions: 7.31 | 7.40 | 7.54


Notes

  • The data type of the first declaration after INIT is always identified statically.

  • 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 REDUCE 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.

CLASS demo DEFINITION.
  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.
  demo=>main( REDUCE #( INIT s = 0
                        FOR  i = 1 UNTIL i > 10
                        NEXT s = s + i ) ).

Executable Example

Reduce Operator, Type Inference