A reference is a handle to an object

A parcel tracker object has its own status. A reference variable is the handle through which the program reaches that object; assigning one reference to another does not clone the object.

Create and use an instance

CLASS lcl_tracker DEFINITION.
  PUBLIC SECTION.
    DATA status TYPE string.
ENDCLASS.
CLASS lcl_tracker IMPLEMENTATION.
ENDCLASS.

DATA(tracker) = NEW lcl_tracker( ).
tracker->status = 'Packed'.
DATA(result) = tracker->status.

NEW creates an instance and returns a reference. The arrow -> accesses an instance component through that reference. A reference can also be declared first with TYPE REF TO; before it points to an object, it is initial/unbound.

An older construction form

Classic code may declare a reference and then use CREATE OBJECT tracker. Modern code commonly uses NEW, which expresses object creation in an expression and can fit inline declarations. Choose syntax supported by the target ABAP release and code style.

Aliasing is not copying

DATA(second_reference) = tracker.
second_reference->status = 'On the way'.

Now both references reach the same object. Updating through one reference is observable through the other. If you need a separate parcel, create a second object instead of copying the reference.

Practice

Instantiate a tracker, set its status, and assign that status to result; add the output statement appropriate to the selected program context. Structural validation is not ABAP execution.

Version note: Inline declarations and constructor operators depend on release/language version. Local classes are scoped to their containing program; global class creation is a separate repository design choice.

Sources

Developer practice · ABAP

Practice: instantiate a parcel tracker

Create an object with NEW, store its reference in tracker, and assign a readable status to result.

Choose your ABAP environment

This choice changes the output pattern checked here: WRITE belongs in a classic executable report, while out->write( ) uses the supplied output reference in an ABAP Cloud class-run method. It does not switch the language version of the other code; check release and API availability in your target system.

Complete the task and include the output statement shown for your selected environment. Variable names can differ if you use them consistently. This browser checker checks structure only; it does not compile or run ABAP.

0 required structures detected · 0 checks