Ansicht
Dokumentation

ABENCOND_CONSTRUCTOR_INFERENCE - COND CONSTRUCTOR INFERENCE

ABENCOND_CONSTRUCTOR_INFERENCE - COND CONSTRUCTOR INFERENCE

CL_GUI_FRONTEND_SERVICES - Frontend Services   ROGBILLS - Synchronize billing plans  
This documentation is copyright by SAP AG.
SAP E-Book

COND, SWITCH, Type Inference for Actual Parameters

If the following constructor expression 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 #:

COND$|SWITCH #( ... THEN ... )

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: More specifically, this applies to the types c, n, and x with generic lengths.

Note



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, which is displayed 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.
  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> ) ).


Conditional Operator, Type Inference






Vendor Master (General Section)   CPI1466 during Backup  
This documentation is copyright by SAP AG.

Length: 2912 Date: 20240425 Time: 025635     sap01-206 ( 41 ms )