ABAP - Keyword Documentation →  ABAP - Reference →  Program Flow Logic →  Control Structures →  Branches → 

CASE TYPE OF

Quick Reference

Syntax

CASE TYPE OF oref
  [WHEN TYPE class|intf [INTO target1].
    [statement_block1]]
  [WHEN TYPE class|intf [INTO target2].
    [statement_block2]]
  ...
  [WHEN OTHERS.
    [statement_blockn]]
ENDCASE.

Addition:

... INTO target

Effect

Special case distinction for object reference variables. This form of a control structure introduced using CASE checks the dynamic type of a non-initial object reference variable and the static type of an initial object reference variable oref. oref expects an object reference variable with the static type of a class or of an interface. oref is a general expression position.

A class class or an interface intf valid in this place must be specified after WHEN TYPE. The first statement block statement_block is executed for which the class class or the interface intf is more general than or equal to the

If this does not apply to any class class or interface intf, the statement block is executed after WHEN OTHERS. No object type class or intf can be specified if it is possible to identify statically that it does not meet the condition.

Notes

IF oref IS INSTANCE OF class|intf.
  [statement_block1]
ELSEIF oref IS INSTANCE OF class|intf.
  [statement_block2]
...
ELSE.
  [statement_blockn]
ENDIF.

Example

See Case Distinction CASE TYPE OF for Exceptions.

Addition

... INTO target

Effect

For every statement WHEN TYPE of a case distinction introduced using CASE TYPE OF, a target variable target can be specified after the optional addition INTO as follows:

If the addition INTO is specified in the first WHEN statement that meets the condition, the reference oref is assigned to ref before the statement block is executed. Here, both up casts and down casts can be performed.

Note

A statement

WHEN TYPE class|intf INTO ref.

is a semantically identically short form of

WHEN TYPE class|intf.
  ref = oref.

A statement

WHEN TYPE class|intf INTO DATA(ref).

is a semantically identically short form of

WHEN TYPE class|intf.
  DATA(ref) = CAST class|intf( oref ).


Example

See Case Distinction CASE TYPE OF for RTTI.



Continue
WHEN TYPE
Case Distinction CASE TYPE OF for Exceptions
Case Distinction CASE TYPE OF for RTTI