What are inline declarations in ABAP, and when would you not use them?
Say your answer out loud first.
Practise another way
Inline declarations let me declare a variable at the place where it first gets a value: DATA(x), FIELD-SYMBOL(<x>), and FINAL(x) for a variable that cannot change. The type comes from the right-hand side, so I skip the DATA block at the top of the method. I avoid them when the inferred type is wrong, for example from a short literal, when I need the variable outside the block where it was declared, or in an optional branch. FINAL needs release 7.57.
Inline declarations are declaration expressions placed at a write position. The compiler derives the type from the operand, so the code is shorter and the declaration sits next to its first use.
SELECT carrid, connid, price FROM sflight
WHERE carrid = 'LH' INTO TABLE @DATA(flights).
LOOP AT flights ASSIGNING FIELD-SYMBOL(<flight>).
<flight>-price = <flight>-price * '1.1'.
ENDLOOP.
FINAL(count) = lines( flights ).
DATA(note) = `done`. " string; 'done' would give type c length 4
Where they work: after INTO in SELECT and LOOP, after ASSIGNING, in CATCH ... INTO DATA(err), as result of constructor expressions and for output parameters of method calls.
FINAL declares an immutable variable. The declaring position is the only write position in that context; any other write is a syntax error. Inside a loop the declaration still runs once per pass.
If the variable is a reference, the reference is fixed, not the object behind it. FINAL arrived with ABAP release 7.57 (ABAP Cloud 2208).
When not to use them
- The inferred type is not the one you want.
DATA(total) = 0.gives typei, so later decimals are cut.DATA(text) = 'ab'.givesclength 2, sotext = 'abcdef'truncates. Use backquotes for strings or a typed DATA. - The variable is needed after the block. A variable declared inside IF or LOOP stays visible after it, which confuses readers. Clean ABAP says to declare it before the block.
- Optional branches. Declaring in only one branch of an IF leaves the other branch using a name that was never set.
- Public types. For a variable that becomes part of an API, state the type explicitly.
Clean ABAP prefers inline declarations because small methods make an up-front DATA section pointless. One more catch: if a data object named final already exists, FINAL(var) is read as a substring access.
Shows the type-inference traps (`DATA(x) = 0`, short literals), explains FINAL and its release, and names the scope rule.
Says 'it saves lines' and cannot name a case where inline declaration hurts.
Saying inline declarations are always better. The inferred type of a literal can silently truncate or round later values.
- What type does DATA(x) = 0 get, and why does it matter?
- What does FINAL change compared with DATA?
- Can you use inline declarations in a method call?
- How do you declare a variable inline for a SELECT result?
4 official pages and 1 prep guide. Confidence: high. Checked 21 Nov 2026.
- Official page Backs the answer.
- Official page Backs the answer.
- Official page Backs the answer.
- Official page Backs the answer.
- Prep guide Gives the question.