ABAP Example Programs
Read runnable ABAP sample reports, complete source code and selection parameters for the Zed Frame learning environment.
Greeting report
Print a personalized greeting a bounded number of times.
- P_NAME: STRING; default: ABAP learner. Name to greet.
- P_REPEATS: I; default: 2. Number of lines, 1 to 20.
REPORT ZED_EXAMPLE_GREETING.
PARAMETERS p_name TYPE string DEFAULT 'ABAP learner'.
PARAMETERS p_repeats TYPE i DEFAULT 2.
START-OF-SELECTION.
IF p_repeats < 1 OR p_repeats > 20.
MESSAGE 'P_REPEATS must be between 1 and 20.' TYPE 'E'.
ENDIF.
DO p_repeats TIMES.
WRITE: / 'Hello,', p_name.
ENDDO.
Open example programs in the workbenchText cleanup
Normalize whitespace and replace a literal word with a local helper module.
- P_TEXT: STRING; default: ABAP Playground . Text to normalize.
REPORT ZED_EXAMPLE_TEXT.
PARAMETERS p_text TYPE string DEFAULT ' ABAP Playground '.
DATA normalized TYPE string.
DATA result TYPE string.
START-OF-SELECTION.
CALL FUNCTION 'ZED_STRING_NORMALIZE'
EXPORTING input = p_text
IMPORTING output = normalized.
CALL FUNCTION 'ZED_STRING_REPLACE'
EXPORTING input = normalized
substring = 'Playground'
replacement = 'Workbench'
IMPORTING output = result.
WRITE: / result.
Open example programs in the workbenchDate and ISO week
Validate a date and display its ISO week number and weekday.
- P_DATE: D; default: 20261014. Internal date in YYYYMMDD format.
REPORT ZED_EXAMPLE_DATE.
PARAMETERS p_date TYPE d DEFAULT '20261014'.
DATA iso_week TYPE n LENGTH 6.
DATA weekday TYPE i.
START-OF-SELECTION.
CALL FUNCTION 'DATE_CHECK_PLAUSIBILITY'
EXPORTING date = p_date.
CALL FUNCTION 'DATE_GET_WEEK'
EXPORTING date = p_date
IMPORTING week = iso_week.
CALL FUNCTION 'DATE_COMPUTE_DAY'
EXPORTING date = p_date
IMPORTING day = weekday.
WRITE: / 'ISO week:', iso_week.
WRITE: / 'Weekday (Mon=1):', weekday.
Open example programs in the workbenchFunction-module ALV
Build a local table and render it using the supported ALV function module.
REPORT ZED_EXAMPLE_ALV.
TYPES: BEGIN OF ty_row,
category TYPE string,
amount TYPE i,
END OF ty_row.
DATA rows TYPE STANDARD TABLE OF ty_row WITH EMPTY KEY.
rows = VALUE #( ( category = 'Books' amount = 20 )
( category = 'Tools' amount = 35 ) ).
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'
EXPORTING i_grid_title = 'Example inventory'
TABLES t_outtab = rows.
Open example programs in the workbenchSALV class methods
Configure and display a local SALV table using supported class and instance methods.
REPORT ZED_EXAMPLE_SALV.
TYPES: BEGIN OF ty_row,
category TYPE string,
amount TYPE i,
END OF ty_row.
DATA rows TYPE STANDARD TABLE OF ty_row WITH EMPTY KEY.
DATA salv TYPE REF TO cl_salv_table.
DATA columns TYPE REF TO cl_salv_columns_table.
DATA amount_column TYPE REF TO cl_salv_column_table.
rows = VALUE #( ( category = 'Books' amount = 20 )
( category = 'Tools' amount = 35 ) ).
cl_salv_table=>factory(
IMPORTING r_salv_table = salv
CHANGING t_table = rows ).
columns = salv->get_columns( ).
columns->set_optimize( abap_true ).
amount_column = columns->get_column( 'AMOUNT' ).
amount_column->set_long_text( 'Amount' ).
salv->get_display_settings( )->set_list_header( 'Example inventory' ).
salv->get_display_settings( )->set_striped_pattern( abap_true ).
salv->get_aggregations( )->add_aggregation(
columnname = 'AMOUNT'
aggregation = 'TOTAL' ).
salv->display( ).
Open example programs in the workbenchSubmit a sample report
Run an allowlisted example report and pass its selection parameters.
REPORT ZED_EXAMPLE_SUBMIT_DRIVER.
SUBMIT ZED_EXAMPLE_GREETING
WITH p_name = 'Ada'
WITH p_repeats = 2
AND RETURN.
WRITE: / 'Returned to the calling report.'.
Open example programs in the workbench