| Feature | Old Syntax | New Syntax (7.5) |
|---|---|---|
| Inline Declaration | DATA lv_var TYPE i. | DATA(lv_var) = value. |
| Table Declaration | DATA lt_tab TYPE TABLE OF ty. | DATA(lt_tab) = VALUE #( ). |
| Loop with Work Area | DATA ls_row TYPE ty. LOOP AT itab INTO ls_row. | LOOP AT itab INTO DATA(ls_row). |
| String Template | CONCATENATE 'Hello' name INTO text. | |Hello { name }| |
| Exists Check | READ TABLE itab ... TRANSPORTING NO FIELDS. | IF line_exists( itab[ ... ] ). |
ABAP 7.5 Syntax Cheat Sheet
Comprehensive reference guide for modern ABAP 7.5 syntax including inline declarations, constructor expressions, Open SQL enhancements, and performance best practices.
Quick Reference
Most commonly used ABAP 7.5 features at a glance
Inline Declarations
Declare variables at the point of use
" Simple variable
DATA(lv_count) = 10.
DATA(lv_name) = 'John Doe'.
DATA(lv_date) = sy-datum.
" In loops
LOOP AT it_customers INTO DATA(ls_customer).
DATA(lv_total) = ls_customer-amount * ls_customer-quantity.
ENDLOOP.
" In SELECT statements
SELECT SINGLE carrid, connid
FROM sflight
INTO DATA(ls_flight)
WHERE carrid = 'AA'.FIELD-SYMBOL Inline
Declare field symbols inline
" Loop with field symbol
LOOP AT it_orders ASSIGNING FIELD-SYMBOL(<fs_order>).
<fs_order>-status = 'PROCESSED'.
ENDLOOP.
" Read table with field symbol
READ TABLE it_items ASSIGNING FIELD-SYMBOL(<fs_item>)
WITH KEY id = '001'.
IF sy-subrc = 0.
<fs_item>-quantity = <fs_item>-quantity + 1.
ENDIF.
" Modify table directly
LOOP AT it_data ASSIGNING FIELD-SYMBOL(<fs_data>)
WHERE status = 'PENDING'.
<fs_data>-processed = abap_true.
ENDLOOP.Constructor Expressions - VALUE
Create and populate data objects inline
" Structure initialization
DATA(ls_address) = VALUE ty_address(
street = 'Main St'
city = 'New York'
zip = '10001'
).
" Internal table initialization
DATA(lt_items) = VALUE ty_items(
( id = '001' name = 'Item A' price = 100 )
( id = '002' name = 'Item B' price = 200 )
( id = '003' name = 'Item C' price = 300 )
).
" With BASE keyword (preserve existing data)
lt_items = VALUE #( BASE lt_items
( id = '004' name = 'Item D' price = 400 )
)." Set default values
DATA(ls_config) = VALUE ty_config(
timeout = VALUE #( DEFAULT 30 )
retry = VALUE #( DEFAULT 3 )
active = abap_true
).
" Clear structure
CLEAR ls_customer.
" or use VALUE
ls_customer = VALUE #( ).
" Initialize with selected fields
DATA(ls_partial) = VALUE ty_customer(
id = '12345'
name = 'ABC Corp'
" other fields remain initial
).Constructor Expressions - CORRESPONDING
Map data between structures with different layouts
" Basic mapping (same field names)
DATA(ls_target) = CORRESPONDING ty_target( ls_source ).
" Mapping with BASE (preserve existing values)
ls_target = CORRESPONDING #( BASE ls_target ls_source ).
" Mapping with MAPPING clause
DATA(ls_result) = CORRESPONDING ty_result( ls_input
MAPPING dest_field = source_field
new_name = old_name ).
" CORRESPONDING for tables
DATA(lt_output) = CORRESPONDING ty_output_tab( lt_input ).
" Deep structures
DATA(ls_deep) = CORRESPONDING #( DEEP ls_source ).
" With EXCEPT
DATA(ls_partial) = CORRESPONDING #( ls_source
EXCEPT field1 field2 ).FOR Expressions
Iterate and transform data inline
" Simple transformation
DATA(lt_names) = VALUE stringtab(
FOR ls_customer IN lt_customers
( ls_customer-name )
).
" With condition (WHERE)
DATA(lt_active) = VALUE ty_tab(
FOR ls IN lt_items
WHERE ( status = 'ACTIVE' )
( ls )
).
" Transformation with calculation
DATA(lt_totals) = VALUE ty_totals(
FOR ls IN lt_orders
( order_id = ls-id
total = ls-quantity * ls-price )
).
" Nested FOR
DATA(lt_result) = VALUE ty_result(
FOR ls_order IN lt_orders
FOR ls_item IN ls_order-items
( order_id = ls_order-id
item_id = ls_item-id )
).REDUCE Expression
Accumulate values from iterations
" Sum calculation
DATA(lv_total) = REDUCE i(
INIT sum = 0
FOR ls IN lt_items
NEXT sum = sum + ls-amount
).
" Count with condition
DATA(lv_count) = REDUCE i(
INIT cnt = 0
FOR ls IN lt_orders
WHERE ( status = 'COMPLETED' )
NEXT cnt = cnt + 1
).
" String concatenation
DATA(lv_text) = REDUCE string(
INIT result = ''
FOR ls IN lt_names
NEXT result = |{ result }{ ls-name }, |
).
" Complex aggregation
DATA(ls_stats) = REDUCE ty_stats(
INIT stats = VALUE #( )
FOR ls IN lt_data
NEXT stats-count = stats-count + 1
stats-sum = stats-sum + ls-value
stats-max = COND #(
WHEN ls-value > stats-max
THEN ls-value
ELSE stats-max )
).String Templates
Modern string formatting with |...|
" Simple embedding
DATA(lv_msg) = |Hello { lv_name }|.
" Multiple variables
DATA(lv_text) = |Order { lv_id } for { lv_customer }|.
" With literals
DATA(lv_path) = |/sap/bc/ui5/{ lv_app }/index.html|.
" Expressions in templates
DATA(lv_info) = |Total: { lv_qty * lv_price }|.
" Nested templates
DATA(lv_nested) = |Result: { |Value: { lv_val }| }|.
" Line breaks
DATA(lv_multi) = |Line 1
Line 2
Line 3|." Number formatting
DATA(lv_formatted) = |{ lv_amount WIDTH = 10 ALIGN = RIGHT }|.
DATA(lv_decimal) = |{ lv_value DECIMALS = 2 }|.
DATA(lv_padded) = |{ lv_num WIDTH = 5 PAD = '0' }|.
" Date formatting
DATA(lv_date) = |{ lv_datum DATE = USER }|.
DATA(lv_iso) = |{ lv_datum DATE = ISO }|.
" Time formatting
DATA(lv_time) = |{ lv_uzeit TIME = ISO }|.
" Case conversion
DATA(lv_upper) = |{ lv_text CASE = UPPER }|.
DATA(lv_lower) = |{ lv_text CASE = LOWER }|.
" Alpha conversion
DATA(lv_alpha) = |{ lv_matnr ALPHA = OUT }|.COND & SWITCH - Conditional Operators
Inline conditional expressions
" Simple condition
DATA(lv_status) = COND string(
WHEN lv_amount > 1000 THEN 'HIGH'
WHEN lv_amount > 500 THEN 'MEDIUM'
ELSE 'LOW'
).
" With complex conditions
DATA(lv_discount) = COND decfloat16(
WHEN lv_customer_type = 'PREMIUM' AND
lv_amount > 5000
THEN lv_amount * '0.15'
WHEN lv_customer_type = 'REGULAR' AND
lv_amount > 2000
THEN lv_amount * '0.10'
ELSE lv_amount * '0.05'
).
" Assignment based on condition
lv_message = COND #(
WHEN sy-subrc = 0 THEN 'Success'
ELSE 'Error occurred'
)." Basic switch
DATA(lv_day_name) = SWITCH string( sy-datum+6(1)
WHEN '1' THEN 'Monday'
WHEN '2' THEN 'Tuesday'
WHEN '3' THEN 'Wednesday'
WHEN '4' THEN 'Thursday'
WHEN '5' THEN 'Friday'
WHEN '6' THEN 'Saturday'
WHEN '7' THEN 'Sunday'
ELSE 'Invalid'
).
" With complex result
DATA(lt_config) = SWITCH ty_config( lv_env
WHEN 'DEV' THEN VALUE #(
( param = 'DEBUG' value = 'X' )
( param = 'TRACE' value = 'X' )
)
WHEN 'PROD' THEN VALUE #(
( param = 'DEBUG' value = '' )
( param = 'TRACE' value = '' )
)
).Open SQL Enhancements
Modern database access with @host_variables and new clauses
" Basic SELECT with host variables
SELECT carrid, connid, fldate
FROM sflight
WHERE carrid = @lv_carrier
AND fldate > @lv_date
INTO TABLE @DATA(lt_flights).
" SELECT with inline declaration
SELECT bukrs, gjahr, belnr, blart
FROM bkpf
WHERE bukrs = @lv_company
AND gjahr = @lv_year
INTO TABLE @DATA(lt_docs)
UP TO 100 ROWS.
" Single record
SELECT SINGLE mandt, matnr, maktx
FROM makt
WHERE matnr = @lv_material
AND spras = @sy-langu
INTO @DATA(ls_text).
" Aggregate functions
SELECT carrid,
COUNT( * ) AS flight_count,
AVG( price ) AS avg_price
FROM sflight
WHERE carrid = @lv_carrier
GROUP BY carrid
INTO @DATA(ls_stats)." Concatenation
SELECT kunnr,
CONCAT( name1, name2 ) AS full_name
FROM kna1
WHERE kunnr = @lv_customer
INTO @DATA(ls_customer).
" Substring
SELECT matnr,
SUBSTRING( matnr, 0, 3 ) AS prefix
FROM mara
INTO TABLE @DATA(lt_materials).
" CASE expression
SELECT matnr,
CASE mtart
WHEN 'FERT' THEN 'Finished'
WHEN 'HALB' THEN 'Semi-finished'
ELSE 'Other'
END AS material_type
FROM mara
INTO TABLE @DATA(lt_types)." Arithmetic operations
SELECT vbeln,
posnr,
kwmeng * netpr AS item_total
FROM vbap
WHERE vbeln = @lv_order
INTO TABLE @DATA(lt_items).
" Division with CAST
SELECT vbeln,
CAST( kwmeng AS DECFLOAT16 ) /
CAST( umvkz AS DECFLOAT16 ) AS converted
FROM vbap
INTO TABLE @DATA(lt_converted).
" Logical operations
SELECT kunnr
FROM kna1
WHERE land1 = 'US'
AND ( ktokd = 'KUNA' OR ktokd = 'KUNB' )
INTO TABLE @DATA(lt_customers).Table Expressions
Direct table access with [ ... ] syntax
" Read by index
DATA(ls_first) = lt_items[ 1 ].
DATA(ls_third) = lt_items[ 3 ].
" Read with key
DATA(ls_customer) = lt_customers[ kunnr = '0000123456' ].
DATA(ls_item) = lt_items[ matnr = lv_material ].
" Read with multiple keys
DATA(ls_flight) = lt_flights[ carrid = 'AA' connid = '0017' ].
" Read component directly
DATA(lv_name) = lt_customers[ kunnr = lv_id ]-name1.
DATA(lv_price) = lt_items[ 2 ]-price.
" With OPTIONAL (prevents exception)
DATA(ls_optional) = VALUE #( lt_items[ id = '999' ] OPTIONAL ).
" With DEFAULT
DATA(lv_status) = lt_orders[ id = lv_id ]-status DEFAULT 'NEW'.
" Check existence
IF line_exists( lt_items[ matnr = lv_material ] ).
" Item exists
ENDIF.
" Get table line index
DATA(lv_index) = line_index( lt_items[ matnr = lv_material ] ).Functional Method Calls
Use method results directly in expressions
" Method chaining
DATA(lv_result) = lo_object->method1( )->method2( )->method3( ).
" With parameters
DATA(lv_value) = lo_calc->add( 5 )->multiply( 3 )->get_result( ).
" Constructor chaining
DATA(lo_instance) = NEW cl_my_class(
)->initialize( lv_config
)->set_parameter( 'PARAM1' lv_value1
)->set_parameter( 'PARAM2' lv_value2 ).
" String operations
DATA(lv_clean) = cl_abap_string_utilities=>to_upper(
cl_abap_string_utilities=>remove_whitespace( lv_input )
)." Basic instantiation
DATA(lo_instance) = NEW cl_my_class( ).
" With constructor parameters
DATA(lo_obj) = NEW cl_calculator(
iv_value1 = 10
iv_value2 = 20
).
" Direct method call
NEW cl_my_class( )->execute( ).
" In assignments
lo_ref = NEW cl_handler( lv_config ).
" With CAST
DATA(lo_specific) = CAST cl_specific_type(
NEW cl_factory( )->create_instance( 'TYPE1' )
).
" In table of objects
DATA(lt_objects) = VALUE ty_obj_tab(
( NEW cl_my_class( param = 'A' ) )
( NEW cl_my_class( param = 'B' ) )
).Filter & Grouping
Advanced table operations
" Basic filter
DATA(lt_active) = FILTER ty_tab( lt_items WHERE status = 'ACTIVE' ).
" Multiple conditions
DATA(lt_filtered) = FILTER ty_customers( lt_all
WHERE country = 'US'
AND status = 'A'
AND credit_limit > 10000 ).
" Filter with EXCEPT
DATA(lt_result) = FILTER ty_tab( lt_source EXCEPT
WHERE flag = 'X' ).
" Filter with table key
DATA(lt_selected) = FILTER ty_sorted( lt_data
USING KEY key_name
WHERE field1 = lv_value1 ).CONV Operator
Type conversion inline
" String to integer
DATA(lv_num) = CONV i( '12345' ).
" Integer to string
DATA(lv_text) = CONV string( lv_number ).
" Date conversion
DATA(lv_date) = CONV sy-datum( '20260117' ).
" Packed to float
DATA(lv_float) = CONV decfloat34( lv_packed ).
" In method calls
lo_object->set_value(
iv_amount = CONV decfloat16( lv_string )
).
" With calculation
DATA(lv_result) = CONV i( lv_value1 ) +
CONV i( lv_value2 ).REF Operator
Create references inline
" Create reference to variable
DATA(lr_value) = REF #( lv_amount ).
" Reference to table line
DATA(lr_line) = REF #( lt_items[ 1 ] ).
" In method calls requiring references
lo_handler->process(
ir_data = REF #( ls_structure )
).
" Create and modify via reference
REF #( lt_items[ id = '001' ] )->*-status = 'PROCESSED'.
" Reference to constant
DATA(lr_const) = REF #( '100' ).Performance Best Practices
Write efficient ABAP 7.5 code
| Practice | Description | Example |
|---|---|---|
| Use Field Symbols | Modify tables efficiently | LOOP AT it ASSIGNING FIELD-SYMBOL(<fs>). |
| Database Operations | Select only needed fields | SELECT field1, field2 FROM table... |
| Batch Processing | Use FOR ALL ENTRIES | SELECT * FROM table FOR ALL ENTRIES IN it... |
| Avoid Nested Loops | Use READ TABLE or hashed tables | READ TABLE it WITH KEY = value... |
| Use FILTER | Efficient table filtering | DATA(result) = FILTER #( it WHERE status = 'A' ). |
| String Templates | Replace CONCATENATE | |Value: { lv_var }| |
| Inline Declarations | Reduce memory overhead | DATA(lv_temp) = value. |
Migration Checklist
Converting legacy code to ABAP 7.5
Replace These Patterns:
✗ DATA lv_var TYPE i.
lv_var = 5.
✓ DATA(lv_var) = 5.
✗ CONCATENATE 'Hello' name INTO text.
✓ DATA(text) = |Hello { name }|.
✗ READ TABLE it INTO ls_row
WITH KEY id = '001'.
IF sy-subrc = 0.
✓ IF line_exists( it[ id = '001' ] ).
✗ LOOP AT it INTO ls_row.
ls_row-status = 'X'.
MODIFY it FROM ls_row.
ENDLOOP.
✓ LOOP AT it ASSIGNING FIELD-SYMBOL(<fs>).
<fs>-status = 'X'.
ENDLOOP.Key Benefits:
- Reduced code verbosity (up to 30-40% less lines)
- Improved readability and maintainability
- Better performance with optimized operations
- Type safety with inline declarations
- Modern, expressive syntax
- Easier debugging with clearer code flow
Common Pitfalls & Solutions
Avoid these common mistakes
| Issue | Problem | Solution |
|---|---|---|
| Table Expression Exception | Using [ ] without existence check | Use OPTIONAL or line_exists( ) first |
| Type Mismatch | Inline declaration with wrong type | Use CONV #( ) for explicit conversion |
| Performance | Using REDUCE for simple sum | Consider SUM in SQL or dedicated function |
| Memory | Deep copying large tables | Use field symbols or references when possible |
| Readability | Nested COND/SWITCH too deep | Extract to separate method for clarity |
| Debugging | Complex inline expressions | Break down into steps during development |