Variables
Quick answer
Follow naming conventions (e.
Key takeaways
- Classic declaration uses DATA with a type.
- Variables declared in a program or method are local to it.
- Understanding how to declare them, their scope, and modern inline declaration is basic but essential ABAP craft.
- Watch out: Overusing global variables.
Declaring variables
Classic declaration uses DATA with a type. Constants use CONSTANTS. Variables can be typed from built-in types, dictionary types, or other data objects (LIKE). Modern ABAP supports inline declaration (DATA(...)) at the point of first use, which is cleaner and now preferred where it improves readability.
Classic vs inline declaration
" classic
DATA lv_total TYPE i.
lv_total = 10.
" inline (modern)
DATA(lv_total2) = 10. " type inferred as i
SELECT SINGLE * FROM mara INTO @DATA(ls_mara) WHERE matnr = @lv_matnr.Scope and lifetime
Variables declared in a program or method are local to it. Global data (declared at program top or in class attributes) lives for the program/object lifetime. Prefer local, narrowly-scoped variables, minimal shared state is easier to reason about and less error-prone.
Naming and clarity
Follow naming conventions (e.g. lv_ for local variable, ls_ for structure, lt_ for internal table) so code is readable at a glance. Clear names and tight scope make ABAP maintainable.
Common pitfalls
- Overusing global variables.
- Ignoring inline declarations that improve readability.
- Poor naming that obscures a variable’s type/role.
Want to learn this properly?
Our live, instructor-led SAP Training covers this hands-on, with real projects and a certification path.
Check your understanding
Which statement is true of Variables?
- A. SAP SD (Sales and Distribution) manages the selling process, from quotations and sales orders through…
- B. Constants use CONSTANTS.
- C. Fiori apps are the individual task-focused applications users run, transactional, analytical and fact-sheet…
Show answer
B. Constants use CONSTANTS.
Covered in the “Declaring variables” section of this lesson.
Which of these also applies to Variables?
- A. Never setting up favourites despite repeating tasks.
- B. Wrong movement type, incorrect stock/value.
- C. Variables can be typed from built-in types, dictionary types, or other data objects (LIKE).
Show answer
C. Variables can be typed from built-in types, dictionary types, or other data objects (LIKE).
Covered in the “Declaring variables” section of this lesson.
Which part of the Learn SAP curriculum covers Variables?
- A. SAP ABAP development
- B. SAP SD
- C. SAP FI
Show answer
A. SAP ABAP development
This lesson sits in the SAP ABAP development section of the Learn SAP course.