Keep a decision’s input stable while you use it
Suppose one method records a dispatch decision and then passes its status to several checks. An accidental reassignment in the remaining method body could make those checks disagree. FINAL(...) declares an immutable variable: once initialized, the variable cannot be reassigned.
Capture the value once
FINAL(snapshot) = VALUE ty_snapshot(
dispatch_id = 'D-1001'
status = 'READY' ).
DATA(result) = snapshot-status.
Use immutability when a local value should stay fixed for the rest of its scope. It can make data flow easier to review, but it does not make the underlying business decision correct and is not a replacement for validation.
FINAL and other modern declaration features depend on the ABAP language version and release. Verify support in the target system, particularly on older classic landscapes. ABAP Cloud also requires any referenced global types to be released for the applicable use.
Sources
- SAP Samples: Structures — constant and immutable structures
- ABAP Keyword Documentation: FINAL declaration operator
Developer practice · ABAP
Practice: capture a read-only status snapshot
Create a FINAL shipment snapshot with status READY and copy that status into 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
TYPES: BEGIN OF ty_snapshot,
dispatch_id TYPE string,
status TYPE string,
END OF ty_snapshot.
FINAL(snapshot) = VALUE ty_snapshot( dispatch_id = 'D-1001' status = 'READY' ).
DATA(result) = snapshot-status.
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.