Make the method contract visible
A caller of a delivery-summary method needs to know what it must provide and what it gets back. The parameter interface is that contract.
An input and one returned value
METHODS build
IMPORTING iv_code TYPE string
RETURNING VALUE(rv_text) TYPE string.
IMPORTING carries input into the method. RETURNING provides one result and makes a functional method call possible:
DATA(result) = summary->build( iv_code = 'PK-204' ).
Use meaningful names and complete types so the caller can understand the method without opening its implementation.
Parameter alternatives
IMPORTING: input values.RETURNING: one result value; often a clear choice for a calculation or transformation.EXPORTING: one or more output parameters, useful when a procedure returns several distinct outputs.CHANGING: an input value that the method may also update; use only when in/out behavior is intentional.
These are not interchangeable stylistic decorations. A method can have side effects, but a method that returns a value without surprising changes is often easier to test and reuse. Avoid using CHANGING merely to avoid declaring a result.
Practice
Implement build with an importing tracking code and returning text. Call it and set result; then add environment-specific output. The checker verifies fragments only.
Version note: Some expression-style method calls and inline declarations are modern syntax; confirm support in the target release and language version.
Sources
- SAP Samples, ABAP Object Orientation: methods and parameter interfaces
- SAP Help Portal, ABAP Objects overview
Developer practice · ABAP
Practice: return a delivery summary
Declare a summary method that accepts a tracking code and returns formatted text. Call it and assign the 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_summary DEFINITION.
PUBLIC SECTION.
METHODS build IMPORTING iv_code TYPE string RETURNING VALUE(rv_text) TYPE string.
ENDCLASS.
CLASS lcl_summary IMPLEMENTATION.
METHOD build.
rv_text = |Parcel { iv_code } is ready|.
ENDMETHOD.
ENDCLASS.
DATA(summary) = NEW lcl_summary( ).
DATA(result) = summary->build( iv_code = 'PK-204' ).
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.
Debug this code
Assume lcl_dispatch declares label as an instance method. Repair the call so it uses an object instance.
Edit the code, then check for the expected repair. This is a structure check, not an ABAP compiler.
Find the issue, repair it, and check your change.
Diagnosis and repair
Diagnosis: The class selector => calls static components. label is an instance method, so call it through the dispatch object with ->.
DATA(dispatch) = NEW lcl_dispatch( ).
DATA(label) = dispatch->label( ).