SAP INSTANCE OF ABEXA



Get Example source ABAP code based on a different SAP table
  



ABAP_RELEXP - Predicate Expression IS INSTANCE OF
This example demonstrates the predicate expression IS INSTANCE OF.

ABAP_SOURCE_CODE
DEMO CL_DEMO_IS_INSTANCE_OF

ABAP_DESCRIPTION
A class c1 contains the interface intf and is the superclass of a class c2. For reference variables of the static types object, intf, c1, and c2, this example demonstrates the behavior of the predicate expression IS INSTANCE OF if these variables point to instances of c1 or c2 or are initial.
If the object reference variable is non-initial, the predicate expression is always true if a downcast to the comparison type is possible. If the object reference variable is initial, the predicate expression is true only if an upcast is possible. This example checks a generically typed field symbol for which this can only be determined at runtime.
For an initial reference variable with the static type object, the result of the expression for all comparison types except for object is false. For an initial reference variable with the static type intf, the result of the expression for all comparison types except for the interface intf is itself false.