Ansicht
Dokumentation

ABENLOGEXP_INSTANCE_OF - LOGEXP INSTANCE OF

ABENLOGEXP_INSTANCE_OF - LOGEXP INSTANCE OF

CL_GUI_FRONTEND_SERVICES - Frontend Services   PERFORM Short Reference  
This documentation is copyright by SAP AG.
SAP E-Book

- IS INSTANCE OF

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

Effect

The predicate expression IS INSTANCE OF checks whether

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.

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.

Example

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.

Example

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.

Predicate Expression IS INSTANCE OF






General Data in Customer Master   ROGBILLS - Synchronize billing plans  
This documentation is copyright by SAP AG.

Length: 5841 Date: 20240425 Time: 175711     sap01-206 ( 79 ms )