SAP ABAP Guide
SAP ABAP Guide
Old Syntax 📜:
New Syntax 💡:
DATA(lv_value) = 5.
With inline declarations, you can define and initialize variables in a single line, making your
code more readable and reducing clutter.
2. Table Expressions
Table expressions allow you to access table entries directly without using explicit READ
TABLE statements, streamlining your code.
Old Syntax 📜:
New Syntax 💡:
Old Syntax 📜:
3. String Templates
String templates simplify string handling by embedding expressions directly within a string. This
is especially useful for creating dynamic strings.
Old Syntax 📜:
New Syntax 💡:
Old Syntax 📜:
New Syntax 💡:
v_sum += v_amt.
Old Syntax 📜:
New Syntax 💡:
DATA(lt_result) = VALUE #( FOR lv_source IN lt_source ( lv_source ) ).
This syntax allows you to create and populate internal tables in a single statement, leading to
more efficient and readable code.
SWITCH Example:
Old Syntax 📜:
IF lv_value = 1.
lv_result = 'One'.
ELSEIF lv_value = 2.
lv_result = 'Two'.
ELSE.
lv_result = 'Other'.
ENDIF.
New Syntax 💡:
lv_result = SWITCH #( lv_value WHEN 1 THEN 'One' WHEN 2 THEN 'Two' ELSE 'Other' ).
COND Example:
Old Syntax 📜:
IF lv_value > 0.
lv_sign = 'Positive'.
ELSEIF lv_value < 0.
lv_sign = 'Negative'.
ELSE.
lv_sign = 'Zero'.
ENDIF.
Old Syntax 📜:
lv_sign = COND #( WHEN lv_value > 0 THEN 'Positive' WHEN lv_value < 0 THEN 'Negative'
ELSE 'Zero' ).
Old Syntax 📜:
These enhancements streamline database access code and make it more consistent with the rest
of the ABAP syntax.
The new syntax introduced in modern ABAP allows for a more concise and readable way to
populate internal tables. This is often referred to as inline declaration and value expressions.
Here’s the equivalent example using the new syntax:
Old Syntax 📜:
ls_data-id = 1.
ls_data-value = 'aaa'.
APPEND ls_data TO lt_data.
ls_data-id = 2.
ls_data-value = 'bbb'.
APPEND ls_data TO lt_data.
New Syntax 💡:
DATA(lt_data) = VALUE #(
( id = 1 value = 'aaa' )
( id = 2 value = 'bbb' )
).