Put a delivery rule in one small class
The dispatch program should not have to know every detail of how a parcel summary is assembled. A class can group data and behavior behind a clear name. In this example, a local class is declared inside one ABAP program and is used only there.
Declaration and implementation are two parts
CLASS lcl_dispatch_note DEFINITION.
PUBLIC SECTION.
METHODS summary RETURNING VALUE(result) TYPE string.
ENDCLASS.
CLASS lcl_dispatch_note IMPLEMENTATION.
METHOD summary.
result = 'Parcel PK-204 is packed'.
ENDMETHOD.
ENDCLASS.
The definition lists the method contract. The implementation supplies its behavior. Keeping those roles separate lets a reader see the class’s public surface before reading the details.
Local or global?
Use a local class when the helper belongs to one program, tutorial, or test. A global repository class is visible to other repository objects and is appropriate when a stable reusable API is needed. Broader visibility also means changes can affect other callers, so do not make a class global just to make a small example look more “object-oriented.”
Practice
Add the class definition and implementation, create an instance, and assign the returned text to result. Then use WRITE result. in a classic executable report, or out->write( result ). in the ABAP Cloud if_oo_adt_classrun~main context. The browser checker checks structure only; it does not compile or execute ABAP.
Context and release: The OO concepts are similar across Classic ABAP and ABAP Cloud, but available syntax/APIs and program entry points depend on release and language version. Local-class placement also depends on the program type. Validate in your target system.
Sources
- SAP Samples, ABAP Object Orientation
- SAP Help Portal, ABAP Objects overview
- SAP Samples, ABAP for Cloud Development
Developer practice · ABAP
Practice: define and implement a dispatch helper
Declare a local class with a summary method, implement the method, and assign its returned message to result.
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
Write your solution, then check its structure.
One possible solution
CLASS lcl_dispatch_note DEFINITION.
PUBLIC SECTION.
METHODS summary RETURNING VALUE(result) TYPE string.
ENDCLASS.
CLASS lcl_dispatch_note IMPLEMENTATION.
METHOD summary.
result = 'Parcel PK-204 is packed'.
ENDMETHOD.
ENDCLASS.
DATA(helper) = NEW lcl_dispatch_note( ).
DATA(result) = helper->summary( ).
WRITE result.out->write( result ).These are context-specific output examples. In your own program, use the result variable from your solution and the output mechanism available in that program.