DATA

Variant 1

DATA f.


Addition:

... TYPE REF TO cif

Effect

Data object f is declared as reference variable within ABAP objects. cif is a class or an interface. Reference variables contain references (pointers) to objects.

Reference variables whose types are defined with reference to a class can contain references to objects of this class. Reference variables whose types are defined with reference to an intterface can contain references to objects whose class implements the interface.

Note

Objects, i.e.instances of classes, are only addressed with their reference variables. To create objects see CREATE OBJECT.

Example

INTERFACE i1.
  METHODS m1.
ENDINTERFACE.

CLASS c1 DEFINITION.
  PUBLIC SECTION.
    INTERFACES i1.
ENDCLASS.

CLASS c1 IMPLEMENTATION.
  METHOD i1~m1.
    ...
  ENDMETHOD.
ENDCLASS.

DATA: o1 TYPE REF TO c1,
      o2 TYPE REF TO c1,
      ir TYPE REF TO i1.

START-OF-SELECTION.

CREATE OBJECT o1.

o2 = o1.
ir = o1.

Additional help

Handling of Objects

Related

ALIASES Declaration of an alias name
CALL METHOD Call of a method
CLASS ... ENDCLASS Definition of a class
CLASS-DATA Declaration of a static attribute
CLASS-EVENTS Declaration of a static event
CLASS-METHODS Declaration of a static method
CREATE OBJECT Creation of an object
EVENTS Declaration of an instance event
INTERFACE ... ENDINTERFACE Definition of an interface
INTERFACES Including an interface
METHOD ... ENDMETHOD Definition of a method
METHODS Declaration of an Instance method
PRIVATE SECTION Start of private visibility section
PROTECTED SECTION Start of a protected visibility section
PUBLIC SECTION Start of the public visibility section
RAISE EVENT Triggering an event
SET HANDLER Registering an event