Ask whether a value belongs to one object or the class

Each parcel has its own tracking code. A service label may be shared by every tracker. ABAP’s instance components belong to an object; class components belong to the class itself.

Instance data varies per instance

DATA tracking_code TYPE string.

If this declaration is in the public section, each instance has its own value. In a well-encapsulated class it would usually be private and accessed through methods.

Class data and class methods are shared

CLASS-DATA service_label TYPE string VALUE 'Parcel desk'.
CLASS-METHODS label RETURNING VALUE(result) TYPE string.

Call a static/class method with class_name=>method( ). Class data has one shared value in the relevant class runtime context, not one value per instance. It can be appropriate for immutable metadata or carefully managed shared state.

Static is not automatically better

An instance is usually clearer when data belongs to a parcel, order, or request. Mutable class data introduces hidden coupling: one caller can change what another caller observes, which complicates parallel work and tests. Prefer constants for fixed shared values and dependency injection for collaborators; use mutable static state only when the design requires it.

Practice

Declare instance-level tracking_code, class-level service_label, and a class method that returns the label as result. Add the environment-appropriate output. The checker looks for patterns only.

Classic and Cloud: Core class syntax is broadly shared, but allowed APIs and language versions differ. For Cloud console output, the result must be written from the class-run method’s provided out reference; classic report output uses WRITE.

Sources

Developer practice · ABAP

Practice: separate parcel data from shared configuration

Declare one per-object tracking code and one class-wide service label, then set result from a class method.

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