Skip to content

ABAP Keyword Documentation →  ABAP − Reference →  Program Flow Logic →  Control Structures →  Branches →  CASE TYPE OF 

Case Distinction CASE TYPE OF for RTTI

This example demonstrates the case distinction CASE TYPE OF for type description classes.

Other versions: 7.31 | 7.40 | 7.54

Source Code

    DATA(typedescr) = cl_abap_typedescr=>describe_by_data( param ).
    CASE TYPE OF typedescr.
      WHEN TYPE cl_abap_elemdescr INTO DATA(elemdescr).
        cl_demo_output=>write( elemdescr->type_kind ).
      WHEN TYPE cl_abap_structdescr INTO DATA(structdescr).
        cl_demo_output=>write( structdescr->components ).
      WHEN TYPE cl_abap_tabledescr INTO DATA(tabledescr).
        cl_demo_output=>write( tabledescr->table_kind ).
      WHEN OTHERS.
        cl_demo_output=>write( 'Not supported' ).
    ENDCASE.

Description

Actual parameters of various types are passed to the generically typed parameter param of the method main and an RTTI type description object is created that points to the general object reference variable typedescr. The case distinction CASE TYPE OF is used to define a more specific RTTI type description class that matches the type. An online declaration after the addition INTO of the statement WHEN TYPE is used to create an object reference variable of this static type and is assigned the reference to the type description object. Special attributes of the type description objects are accessed in the associated statement blocks.