Module 16: ABAP 7.4 / 7.5 Syntax Enhancements
ABAP 7.4 and 7.5 introduced expression-oriented, concise, and readable syntax.
These enhancements shift ABAP from procedural-heavy code to Clean, functional-style ABAP.
1. Inline DATA Declarations
Inline declarations allow declaring variables at the point of use.
Legacy
DATA lv_sum TYPE i.
lv_sum = lv_a + lv_b.
Modern (7.4+):
DATA(lv_sum) = lv_a + lv_b.
Inline in SELECT
SELECT * FROM spfli
INTO TABLE @DATA(lt_spfli).
Declare variables as late as possible, as close as possible to their usage.
2. Constructor Expressions
Constructor expressions allow creating data without procedural statements.
2.1 VALUE – Create Structures & Internal Tables
Structure
DATA(ls_emp) = VALUE ty_employee(
emp_id = 1001
name = 'Developer'
).
Internal Table
DATA(lt_numbers) = VALUE i_tab( ( 1 ) ( 2 ) ( 3 ) ).
Eliminates multiple APPEND / CLEAR statements.
2.2 NEW – Create Objects
DATA(lo_emp) = NEW zcl_employee(
iv_name = 'Yogesh'
).
Always use NEW instead of CREATE OBJECT in modern ABAP.
3. Table Expressions (Extremely Important)
Table expressions allow direct access to internal table rows.
Legacy
READ TABLE gt_emp INTO gs_emp
WITH KEY emp_id = lv_id.
IF sy-subrc = 0.
...
ENDIF.
Modern (7.4+)
DATA(gs_emp) = gt_emp[ emp_id = lv_id ].
Safe Access
DATA(gs_emp) = gt_emp[ emp_id = lv_id ] OPTIONAL.
Without OPTIONAL, a missing entry raises an exception.
4. COND – Conditional Expression
Replaces multi-line IF/ELSE assignments.
Legacy
IF lv_score >= 60.
lv_status = 'PASS'.
ELSE.
lv_status = 'FAIL'.
ENDIF.
Modern
DATA(lv_status) = COND string(
WHEN lv_score >= 60 THEN 'PASS'
ELSE 'FAIL'
).
Use COND for value assignment, not for complex control flow.
5. SWITCH – Multi-Branch Expression
Replaces CASE when assigning values.
DATA(lv_text) = SWITCH string( lv_grade
WHEN 'A' THEN 'Excellent'
WHEN 'B' THEN 'Good'
WHEN 'C' THEN 'Average'
ELSE 'Unknown'
).
-
CASE → control flow
-
SWITCH → expression/value
6. REDUCE – Aggregation Expression
Used to reduce internal tables to single values.
Example: Sum of Values
DATA(lv_total) = REDUCE i(
INIT sum = 0
FOR lv_num IN lt_numbers
NEXT sum = sum + lv_num
).
-
Totals
-
Counters
-
Accumulators
7. FOR Expressions
FOR expressions replace LOOP + APPEND patterns.
7.1 FOR in VALUE (Table Construction)
DATA(lt_even) = VALUE i_tab(
FOR lv_num IN lt_numbers
WHERE ( lv_num MOD 2 = 0 )
( lv_num )
).
This is similar to map/filter in other languages.
7.2 FOR with Index
DATA(lt_indexed) = VALUE string_tab(
FOR idx = 1 THEN idx + 1 UNTIL idx > 5
( |Row { idx }| )
).
8. LET Expressions
LET allows defining local helper variables inside expressions.
DATA(lv_result) = LET lv_tax = 18
lv_price = 100
IN lv_price + ( lv_price * lv_tax / 100 ).
Avoids cluttering the outer scope with temporary variables.
9. Combining Expressions (Realistic Example)
DATA(lv_final_amount) =
REDUCE p(
INIT total = 0
FOR ls_item IN lt_items
NEXT total = total +
COND p(
WHEN ls_item-active = abap_true
THEN ls_item-amount
ELSE 0
)
).
This kind of code clearly signals modern ABAP expertise.
10. What NOT to Overdo
-
Do not create unreadable one-liners
-
Prefer clarity over cleverness
-
Use expressions where they improve readability
11. Summary
-
Inline DATA reduces boilerplate
-
VALUE & NEW simplify construction
-
Table expressions replace READ TABLE
-
COND / SWITCH replace IF / CASE assignments
-
REDUCE aggregates data
-
FOR replaces LOOP + APPEND
-
LET scopes helper variables cleanly
12. Practice Exercises
-
Replace READ TABLE with table expressions.
-
Convert LOOP + APPEND to FOR expression.
-
Replace IF assignment with COND.
-
Use REDUCE to calculate totals.
-
Combine FOR + COND + LET in one example.
13. What’s Next?
➡️ Module 17: Advanced Open SQL (HANA Optimized)
If you master this module, your ABAP code will immediately look senior-level.