Skip to main content
SAP ABAP7.5

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

FeatureOld SyntaxNew Syntax (7.5)
Inline DeclarationDATA lv_var TYPE i.DATA(lv_var) = value.
Table DeclarationDATA lt_tab TYPE TABLE OF ty.DATA(lt_tab) = VALUE #( ).
Loop with Work AreaDATA ls_row TYPE ty. LOOP AT itab INTO ls_row.LOOP AT itab INTO DATA(ls_row).
String TemplateCONCATENATE 'Hello' name INTO text.|Hello { name }|
Exists CheckREAD TABLE itab ... TRANSPORTING NO FIELDS.IF line_exists( itab[ ... ] ).
About ABAP 7.5
ABAP 7.5 introduces modern, concise syntax that reduces code verbosity and improves readability. These features are available in SAP NetWeaver 7.5 and higher versions.

Inline Declarations

Declare variables at the point of use

DATA() - Inline Data Declaration
Type is inferred from the assigned value
" 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'.
Best Practice
Use inline declarations to reduce code and improve readability. The type is automatically inferred.

FIELD-SYMBOL Inline

Declare field symbols inline

FIELD-SYMBOL() Declaration
Define and assign field symbols in one step
" 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.
Performance Tip
Field symbols are more efficient than work areas for modifying internal table data.

Constructor Expressions - VALUE

Create and populate data objects inline

VALUE #() - Basic Usage
Initialize structures and tables
" 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 )
).
VALUE with DEFAULT and OPTIONAL
Set default values for optional parameters
" 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

CORRESPONDING #() Usage
Copy fields by name between different structure types
" 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 ).
Use Cases
CORRESPONDING is perfect for mapping between different structure types in APIs, BAPIs, or when working with different data models.

FOR Expressions

Iterate and transform data inline

FOR with VALUE
Build tables from iterations
" 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

REDUCE for Aggregation
Calculate sums, counts, and complex aggregations
" 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 |...|

Basic String Templates
Embed variables directly in strings
" 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|.
String Template Formatting
Format numbers, dates, and alignment
" 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 }|.
Migration Tip
Replace CONCATENATE, CONDENSE, and string formatting statements with string templates for cleaner, more readable code.

COND & SWITCH - Conditional Operators

Inline conditional expressions

COND #() - Conditional Expression
Inline IF-THEN-ELSE logic
" 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'
).
SWITCH #() - Switch Expression
Inline CASE logic
" 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

Host Variables with @ Escaping
Clear distinction between database and ABAP variables
" 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).
String Functions in SQL
Use SQL string functions directly
" 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 & Logic in SQL
Perform calculations in SELECT
" 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).
Performance
Perform calculations and filtering in the database layer when possible to reduce data transfer and improve performance.

Table Expressions

Direct table access with [ ... ] syntax

Table Access with [ ]
Access table lines directly without READ TABLE
" 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 ] ).
Best Practice
Use table expressions for concise table access. Use OPTIONAL or DEFAULT to prevent exceptions when entries might not exist.

Functional Method Calls

Use method results directly in expressions

Method Chaining
Chain multiple method calls
" 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 )
).
NEW Operator
Instantiate objects inline
" 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

FILTER Operator
Filter internal tables efficiently
" 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 ).
Performance
FILTER is optimized for large tables and can be more efficient than LOOP ... WHERE.

CONV Operator

Type conversion inline

CONV for Type Conversion
Convert between types explicitly
" 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

REF #() for References
Create data references
" 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

PracticeDescriptionExample
Use Field SymbolsModify tables efficientlyLOOP AT it ASSIGNING FIELD-SYMBOL(<fs>).
Database OperationsSelect only needed fieldsSELECT field1, field2 FROM table...
Batch ProcessingUse FOR ALL ENTRIESSELECT * FROM table FOR ALL ENTRIES IN it...
Avoid Nested LoopsUse READ TABLE or hashed tablesREAD TABLE it WITH KEY = value...
Use FILTEREfficient table filteringDATA(result) = FILTER #( it WHERE status = 'A' ).
String TemplatesReplace CONCATENATE|Value: { lv_var }|
Inline DeclarationsReduce memory overheadDATA(lv_temp) = value.
Code Reviews
Always consider performance implications. Use SAT (Runtime Analysis) and Code Inspector to identify optimization opportunities.

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
Compatibility
Ensure your system is on SAP NetWeaver 7.5 or higher before using these features. Check with transaction SVERS or system status.

Common Pitfalls & Solutions

Avoid these common mistakes

IssueProblemSolution
Table Expression ExceptionUsing [ ] without existence checkUse OPTIONAL or line_exists( ) first
Type MismatchInline declaration with wrong typeUse CONV #( ) for explicit conversion
PerformanceUsing REDUCE for simple sumConsider SUM in SQL or dedicated function
MemoryDeep copying large tablesUse field symbols or references when possible
ReadabilityNested COND/SWITCH too deepExtract to separate method for clarity
DebuggingComplex inline expressionsBreak down into steps during development
Additional Resources
For more ABAP learning resources, visit our ABAP Documentation and practice with our ABAP Exercises.