ABAP Cloud Cheat Sheet 2025: Complete Reference

Category
ABAP Cloud
Published
Author
Johannes

The ultimate ABAP Cloud Cheat Sheet with all important statements, modern expressions, and best practices for 2025. Perfect as a quick reference for daily development work.

Table of Contents

  1. Data Declaration
  2. Control Structures
  3. Internal Tables
  4. Database Access
  5. Modern Expressions
  6. String Operations
  7. OOP (Object Orientation)
  8. Exception Handling
  9. RAP (RESTful ABAP)
  10. CDS Views

Data Declaration

Elementary Data Types

" Classic (deprecated in ABAP Cloud)
DATA lv_name TYPE string.
DATA lv_count TYPE i.
" Modern: Inline declaration
DATA(lv_name) = 'Max Mustermann'.
DATA(lv_count) = 42.
" Constants
CONSTANTS gc_max_entries TYPE i VALUE 100.
" Field Symbols & Data References
FIELD-SYMBOLS <fs_data> TYPE any.
DATA(lo_ref) = NEW zcl_my_class( ).

Structures and Tables

" Structure
TYPES: BEGIN OF ty_customer,
id TYPE i,
name TYPE string,
email TYPE string,
END OF ty_customer.
" Internal table
DATA lt_customers TYPE TABLE OF ty_customer.
" Modern: TYPE TABLE OF with index
DATA lt_indexed TYPE STANDARD TABLE OF ty_customer WITH DEFAULT KEY.
DATA lt_sorted TYPE SORTED TABLE OF ty_customer WITH UNIQUE KEY id.
DATA lt_hashed TYPE HASHED TABLE OF ty_customer WITH UNIQUE KEY id.

Control Structures

IF Conditions

IF lv_status = 'ACTIVE'.
" Code
ELSEIF lv_status = 'PENDING'.
" Code
ELSE.
" Code
ENDIF.
" Modern: Inline with COND
DATA(lv_message) = COND string(
WHEN lv_status = 'ACTIVE' THEN 'Active'
WHEN lv_status = 'PENDING' THEN 'Pending'
ELSE 'Unknown'
).

CASE Statement

CASE lv_type.
WHEN 'A'.
" Code
WHEN 'B' OR 'C'.
" Code
WHEN OTHERS.
" Default
ENDCASE.
" Modern: SWITCH Expression
DATA(lv_result) = SWITCH string( lv_type
WHEN 'A' THEN 'Type A'
WHEN 'B' THEN 'Type B'
ELSE 'Unknown'
).

Loops

" DO loop
DO 10 TIMES.
" Code
ENDDO.
" WHILE loop
WHILE lv_count < 100.
lv_count = lv_count + 1.
ENDWHILE.
" LOOP AT (internal table)
LOOP AT lt_customers INTO DATA(ls_customer).
" Processing
ENDLOOP.
" Modern: FOR Expression
DATA(lt_names) = VALUE string_table(
FOR ls_cust IN lt_customers
( ls_cust-name )
).

Internal Tables

Adding Rows

" APPEND
APPEND VALUE #( id = 1 name = 'Max' ) TO lt_customers.
" INSERT
INSERT VALUE #( id = 2 name = 'Anna' ) INTO TABLE lt_customers.
" Modern: VALUE with multiple rows
lt_customers = VALUE #(
( id = 1 name = 'Max' email = '[email protected]' )
( id = 2 name = 'Anna' email = '[email protected]' )
).

Reading Rows

" READ TABLE classic
READ TABLE lt_customers INTO DATA(ls_customer)
WITH KEY id = 1.
" Modern: Table Expression
DATA(ls_cust) = lt_customers[ id = 1 ].
" Optional: Default when not found
DATA(ls_opt) = VALUE #( lt_customers[ id = 999 ] OPTIONAL ).
" Set default value
DATA(ls_def) = VALUE #( lt_customers[ id = 999 ]
DEFAULT VALUE #( id = 0 name = 'Unknown' ) ).

Modifying Rows

" MODIFY classic
MODIFY lt_customers FROM VALUE #( id = 1 name = 'Maximilian' )
TRANSPORTING name WHERE id = 1.
" Modern: Table Expression
lt_customers[ id = 1 ]-name = 'Maximilian'.

Deleting Rows

" DELETE classic
DELETE lt_customers WHERE id = 1.
" DELETE by index
DELETE lt_customers INDEX 1.
" CLEAR & FREE
CLEAR lt_customers. " Empties table (memory remains)
FREE lt_customers. " Releases memory

Table Operations

" Number of rows
DATA(lv_lines) = lines( lt_customers ).
" Sort
SORT lt_customers BY name ASCENDING.
" Filter
DATA(lt_active) = FILTER #( lt_customers WHERE status = 'ACTIVE' ).
" CORRESPONDING (Mapping)
DATA(lt_target) = CORRESPONDING #( lt_source ).

Database Access

SELECT

" Single Record
SELECT SINGLE id, name, email
FROM ztab_customers
WHERE id = @lv_id
INTO @DATA(ls_customer).
" Multiple rows
SELECT id, name, email
FROM ztab_customers
WHERE status = 'ACTIVE'
INTO TABLE @lt_customers.
" Modern: Inline with Joins
SELECT c~id, c~name, o~order_date
FROM ztab_customers AS c
INNER JOIN ztab_orders AS o
ON c~id = o~customer_id
WHERE c~status = 'ACTIVE'
INTO TABLE @DATA(lt_result).
" Aggregation
SELECT customer_id, COUNT( * ) AS order_count
FROM ztab_orders
GROUP BY customer_id
INTO TABLE @DATA(lt_stats).

INSERT, UPDATE, DELETE

" INSERT
INSERT ztab_customers FROM @ls_customer.
" UPDATE
UPDATE ztab_customers
SET status = 'INACTIVE'
WHERE id = @lv_id.
" DELETE
DELETE FROM ztab_customers WHERE id = @lv_id.
" MODIFY (INSERT or UPDATE)
MODIFY ztab_customers FROM @ls_customer.

COMMIT & ROLLBACK

" Save changes
COMMIT WORK.
" Undo changes
ROLLBACK WORK.

Modern Expressions

VALUE Constructor

" Structure
DATA(ls_data) = VALUE ty_customer(
id = 1
name = 'Max'
).
" Table
DATA(lt_data) = VALUE ty_customer_table(
( id = 1 name = 'Max' )
( id = 2 name = 'Anna' )
).
" BASE: Extend existing data
lt_data = VALUE #( BASE lt_data
( id = 3 name = 'Peter' )
).

CORRESPONDING

" Simple mapping
DATA(ls_target) = CORRESPONDING #( ls_source ).
" With MAPPING
DATA(ls_mapped) = CORRESPONDING #( ls_source MAPPING
target_field = source_field
).
" DEEP: Nested structures
DATA(ls_deep) = CORRESPONDING #( DEEP ls_source ).

COND & SWITCH

" COND (IF alternative)
DATA(lv_discount) = COND decfloat16(
WHEN lv_amount > 1000 THEN lv_amount * '0.1'
WHEN lv_amount > 500 THEN lv_amount * '0.05'
ELSE 0
).
" SWITCH (CASE alternative)
DATA(lv_category) = SWITCH string( lv_age
WHEN 0 THEN 'Baby'
WHEN 1 TO 12 THEN 'Child'
WHEN 13 TO 17 THEN 'Teenager'
ELSE 'Adult'
).

FILTER

" Simple filter
DATA(lt_active) = FILTER #( lt_customers WHERE status = 'ACTIVE' ).
" Filter with IN condition
DATA(lt_premium) = FILTER #( lt_customers USING KEY id
WHERE id IN lt_premium_ids ).

REDUCE

" Calculate sum
DATA(lv_total) = REDUCE i( INIT sum = 0
FOR ls_order IN lt_orders
NEXT sum = sum + ls_order-amount ).
" Concatenate strings
DATA(lv_names) = REDUCE string( INIT text = ||
FOR ls_cust IN lt_customers
NEXT text = text && ls_cust-name && ', ' ).

FOR Expression

" Transformation
DATA(lt_ids) = VALUE int4_table(
FOR ls_customer IN lt_customers
( ls_customer-id )
).
" With condition
DATA(lt_active_names) = VALUE string_table(
FOR ls_cust IN lt_customers
WHERE ( status = 'ACTIVE' )
( ls_cust-name )
).
" Nested FOR
DATA(lt_flat) = VALUE ty_table(
FOR ls_group IN lt_groups
FOR ls_item IN ls_group-items
( ls_item )
).

String Operations

String Templates

" Simple
DATA(lv_greeting) = |Hello { lv_name }!|.
" With formatting
DATA(lv_price) = |Price: { lv_amount CURRENCY = lv_currency }|.
DATA(lv_date) = |Date: { lv_timestamp TIMESTAMP = ISO }|.
" Alignment and padding
DATA(lv_padded) = |{ lv_text WIDTH = 20 ALIGN = LEFT PAD = '.' }|.

String Methods

" Length
DATA(lv_len) = strlen( lv_text ).
" Substring
DATA(lv_sub) = substring( val = lv_text off = 0 len = 5 ).
" Search & Replace
DATA(lv_pos) = find( val = lv_text sub = 'test' ).
DATA(lv_replaced) = replace( val = lv_text sub = 'old' with = 'new' ).
" Upper/Lower Case
DATA(lv_upper) = to_upper( lv_text ).
DATA(lv_lower) = to_lower( lv_text ).
" Trim
DATA(lv_trimmed) = condense( lv_text ).

CONCATENATE & SPLIT

" Modern: String Template instead of CONCATENATE
DATA(lv_full_name) = |{ lv_first_name } { lv_last_name }|.
" SPLIT
SPLIT lv_text AT ',' INTO TABLE DATA(lt_parts).

OOP (Object Orientation)

Class Definition

CLASS zcl_customer DEFINITION PUBLIC FINAL CREATE PUBLIC.
PUBLIC SECTION.
METHODS:
constructor
IMPORTING iv_id TYPE i,
get_name
RETURNING VALUE(rv_name) TYPE string,
set_status
IMPORTING iv_status TYPE string.
PRIVATE SECTION.
DATA:
mv_id TYPE i,
mv_name TYPE string,
mv_status TYPE string.
ENDCLASS.
CLASS zcl_customer IMPLEMENTATION.
METHOD constructor.
mv_id = iv_id.
ENDMETHOD.
METHOD get_name.
rv_name = mv_name.
ENDMETHOD.
METHOD set_status.
mv_status = iv_status.
ENDMETHOD.
ENDCLASS.

Instantiation

" NEW Operator
DATA(lo_customer) = NEW zcl_customer( iv_id = 1 ).
" Method call
DATA(lv_name) = lo_customer->get_name( ).
lo_customer->set_status( 'ACTIVE' ).

Interfaces

INTERFACE zif_processor.
METHODS process
IMPORTING iv_data TYPE string
RETURNING VALUE(rv_result) TYPE string.
ENDINTERFACE.
CLASS zcl_impl DEFINITION.
PUBLIC SECTION.
INTERFACES zif_processor.
ENDCLASS.
CLASS zcl_impl IMPLEMENTATION.
METHOD zif_processor~process.
rv_result = |Processed: { iv_data }|.
ENDMETHOD.
ENDCLASS.

Exception Handling

TRY-CATCH

TRY.
DATA(lv_customer) = lt_customers[ id = lv_id ].
CATCH cx_sy_itab_line_not_found INTO DATA(lx_error).
" Error handling
DATA(lv_msg) = lx_error->get_text( ).
ENDTRY.
" Multiple exceptions
TRY.
" Code
CATCH cx_sy_arithmetic_error.
" Division by zero
CATCH cx_sy_conversion_error.
" Conversion error
CATCH cx_root INTO DATA(lx_any).
" All others
ENDTRY.

CLEANUP

TRY.
" Code with resources
CATCH cx_error.
" Error handling
CLEANUP.
" Release resources (always executed)
lo_resource->close( ).
ENDTRY.

Exception Classes

CLASS zcx_my_exception DEFINITION
PUBLIC
INHERITING FROM cx_static_check
FINAL
CREATE PUBLIC.
PUBLIC SECTION.
METHODS constructor
IMPORTING textid TYPE sotr_conc OPTIONAL.
ENDCLASS.
" Usage
IF lv_invalid.
RAISE EXCEPTION TYPE zcx_my_exception.
ENDIF.

RAP (RESTful ABAP)

EML (Entity Manipulation Language)

" READ
READ ENTITIES OF zi_travel
ENTITY Travel
FIELDS ( TravelId AgencyId Status )
WITH VALUE #( ( TravelId = lv_id ) )
RESULT DATA(lt_travel).
" CREATE
MODIFY ENTITIES OF zi_travel
ENTITY Travel
CREATE FIELDS ( AgencyId CustomerId BeginDate )
WITH VALUE #( (
%cid = 'CID_1'
AgencyId = '000001'
CustomerId = '000010'
BeginDate = cl_abap_context_info=>get_system_date( )
) ).
" UPDATE
MODIFY ENTITIES OF zi_travel
ENTITY Travel
UPDATE FIELDS ( Status )
WITH VALUE #( ( TravelId = lv_id Status = 'A' ) ).
" DELETE
MODIFY ENTITIES OF zi_travel
ENTITY Travel
DELETE FROM VALUE #( ( TravelId = lv_id ) ).
" COMMIT
COMMIT ENTITIES.

Actions

" Execute action
MODIFY ENTITIES OF zi_travel
ENTITY Travel
EXECUTE acceptTravel FROM VALUE #( ( TravelId = lv_id ) )
RESULT DATA(lt_result).

CDS Views

Basic View

@AbapCatalog.sqlViewName: 'ZVCUSTOMER'
@AccessControl.authorizationCheck: #CHECK
@EndUserText.label: 'Customer View'
define view Z_Customer
as select from ztab_customers
{
key id as CustomerId,
name as CustomerName,
email as Email,
@Semantics.amount.currencyCode: 'Currency'
credit_limit as CreditLimit,
currency as Currency
}

Associations & Joins

define view Z_CustomerOrders
as select from ztab_customers as c
association [0..*] to ztab_orders as _Orders
on c.id = _Orders.customer_id
{
key c.id,
c.name,
c.email,
_Orders // Expose association
}

Annotations

@Analytics.dataCategory: #CUBE
@Analytics.query: true
@VDM.viewType: #CONSUMPTION
define view Z_SalesAnalytics
as select from ztab_sales
{
@Analytics.dimension: true
product_id,
@Aggregation.default: #SUM
@Semantics.amount.currencyCode: 'Currency'
revenue,
currency
}

Best Practices

DO

" Inline declarations
DATA(lv_result) = calculate_value( ).
" VALUE Constructor
DATA(lt_data) = VALUE ty_table( ( id = 1 ) ).
" String Templates
DATA(lv_msg) = |Error: { lv_error_code }|.
" Table Expressions
DATA(ls_customer) = lt_customers[ id = lv_id ].
" Method Chaining
DATA(lv_final) = lo_object->method1( )->method2( )->get_result( ).

DON’T

" Deprecated declaration
DATA lv_result TYPE string.
lv_result = calculate_value( ).
" CONCATENATE instead of String Template
CONCATENATE 'Error:' lv_error_code INTO lv_msg SEPARATED BY space.
" Unnecessary helper variables
DATA ls_customer TYPE ty_customer.
READ TABLE lt_customers INTO ls_customer WITH KEY id = lv_id.

ABAP Cloud Restrictions

Not Allowed in ABAP Cloud

  • FORM/PERFORM (Subroutines)
  • SELECT * without field list
  • Direct DB access to SAP tables (only Released APIs)
  • SUBMIT for report calls
  • Dynpro development (only Fiori)
  • CALL TRANSACTION

Use Instead

  • Methods instead of FORM
  • Explicit field list in SELECT
  • CDS Views with Released status
  • Business Events & RAP
  • SAP Fiori Elements
  • ABAP EML (Entity Manipulation Language)

Useful Classes & Interfaces

Class/InterfaceUsage
cl_abap_context_infoSystem date, user, client
cl_abap_randomGenerate random numbers
cl_abap_structdescrRuntime Type Info (RTTI)
cl_http_clientHTTP requests
cl_salv_tableCreate ALV lists
if_abap_behvRAP Behavior Constants
cx_rootBase of all exceptions

Summary

This cheat sheet covers the most important ABAP Cloud concepts for 2025:

  • Modern syntax with inline declarations
  • Constructor expressions (VALUE, CORRESPONDING, COND, etc.)
  • EML for RAP development
  • CDS Views for data modeling
  • Best practices for clean, maintainable code

Tip: Bookmark this page or print it out for quick access during development!


See also: