SAP LOGEXP INSTANCE OF



Get Example source ABAP code based on a different SAP table
  


• IS INSTANCE OF ABAP_RELAT_EXPR
• IS NOT INSTANCE OF ABAP_RELAT_EXPR

ABAP_RELEXP - IS INSTANCE OF

ABAP_SYNTAX
ABAP_KEY ... oref IS $[NOT$] INSTANCE OF class$|intf

What does it do?
The predicate expression IS INSTANCE OF checks whether
for a non-initial object reference variable oref the dynamic type
for an initial object reference variable oref the static type
is more specific or equal to a comparison type. The comparison type must be an object type, that is, a class specified using class or an interface specified using intf that can be used here. oref expects an object reference variable with the static type of a class or of an interface. oref is a general expression position.
The expression is true in the following cases or false if NOT is specified:
The object reference variable oref is not initial and points to an object whose class either:
Is the class specified using class or one of its subclasses
Implements the interfaces specified using intf
The object reference variable oref is initial and the static type of oref either:
Is the same class or subclass of class
Contains the interface intf as a component
If a field symbol or a formal parameter is specified for oref, its type can be fully generic, which means it can be typed with any and it must be an object reference variable at runtime. If a generically typed field symbol or a generically typed formal parameter is specified for oref, the static type of the object reference variable is used that is represented by the field symbol or formal parameter at runtime.
A syntax error occurs if it is known statically that the result of the expression is false.



Latest notes:

The predicate expression IS INSTANCE OF checks whether a cast from oref to an object reference variable with the static type class or intf is possible.
If IS INSTANCE OF is true for a non-initial object reference variable oref, a downcast is possible. This means that the predicate expression IS INSTANCE OF can be used as condition for a downcast instead of the corresponding exception handler.
If a predicate expression IS INSTANCE OF is true for an initial object reference variable oref, an upcast is possible. Checks of this type are generally suitable for generically typed field symbols or formal parameters. In this way, it is possible to detect at runtime whether the field symbol or the formal parameter represents an object reference variable of a certain static type.
If the static type of oref is an interface and a class class is specified as the comparison type, the result of the expression is always false if the reference variable is initial.
When a subclass is instantiated, the predicate expression IS INSTANCE OF is false when the associated object reference to the subclass is checked until the instance constructors of all superclasses have been executed. When an instance constructor of a superclass is executed, IS INSTANCE OF is true for the current superclass.
The special case distinction CASE TYPE OF makes it possible to abbreviate consecutive predicate expressions IS INSTANCE OF.
NON_V5_HINTS
ABAP_HINT_END

ABAP_EXAMPLE_VX5
All of the following predicate expressions are true, since the dynamic type of the object reference variable oref is more specific than or equal to the specified object type.
ABEXA 01098
ABAP_EXAMPLE_END

ABAP_EXAMPLE_VX5
The following example shows how the predicate expression IS INSTANCE OF can be used to check the feasibility of a downcast. This makes the exception handler, which is also shown, superfluous.
ABEXA 01099
ABAP_EXAMPLE_END

ABAP_EXAMPLE_ABEXA
Predicate Expression IS INSTANCE OF
ABAP_EXAMPLE_END