Beyond ABAPdesigned by@Tejoram97
Beyond ABAP / CORE ABAP / Report Programming & ALV

Report Programming & ALV

CORE ABAP · ABAP Development ·

Open the interactive lesson →
  1. ABAP program basics
  2. Internal tables
  3. Reading data: joins, FOR ALL ENTRIES, performance
  4. Report events
  5. Selection screens
  6. Classical reports (list output)
  7. Interactive reports and calling programs
  8. Control break statements
  9. ALV (SAP List Viewer)
  10. Background jobs
  11. Obsolete statements: quick reference
  12. Interview questions

Everything you need to write a classic ABAP report: data types and data objects, internal tables, reading data, report events, selection screens, classical and interactive lists, control breaks, ALV and background jobs. Classic statements are still everywhere in brownfield systems, so they are taught here; the modern 7.40+ syntax is on ABAP on HANA › 03 ABAP New Syntax 7.4/7.5+ and is used in the new examples.

Part 1 – ABAP program basics

1.1 Program types

The program type is set in the program attributes. Only type 1 can be started directly (F8, SUBMIT, transaction code); all others are called from somewhere else.

Type

Name

Started how

Details

1

Executable program (report)

F8, SUBMIT, report transaction

Event driven, can run in background – this page

M

Module pool

Dialog transaction code only

Screens + PBO/PAI modules – page 05 Dialog Programming

F

Function group

CALL FUNCTION

Container for function modules – page 04 Modularization

K

Class pool

Through its global class

One global class (SE24) – see the OOPS ABAP section

J

Interface pool

–

One global interface

I

Include

INCLUDE statement

Source code piece, not runnable alone – page 04

S

Subroutine pool

PERFORM … IN PROGRAM

FORM routines and local classes; FORMs are obsolete

T

Type group (type pool)

TYPE-POOLS (obsolete since 7.02)

Global types and constants, e.g. SLIS – page 02 DDIC

  • "Report program", "print program" and "driver program" are informal names, not program types. A print (driver) program is a type 1 program that reads data and calls a form – see page 11 Forms.
  • Editor shortcuts: Ctrl+S save, Ctrl+F2 syntax check, Ctrl+F3 activate, F8 execute, F3 back, Ctrl+F6 insert pattern (e.g. CALL FUNCTION), Shift+F1 pretty printer.

1.2 Data types

ABAP has three kinds of data types: elementary (predefined, single value), complex (structures and table types – built from other types, none are built in) and reference types (TYPE REF TO).

Type

Meaning

Length

Initial value

Notes

C

Character (text)

1–262,143 chars, default 1

' ' (blanks)

Fixed length, trailing blanks ignored

N

Numeric text

default 1

'0…0'

Digits only, no arithmetic meaning (postal code, IDs)

D

Date YYYYMMDD

8

'00000000'

Date arithmetic in days

T

Time HHMMSS

6

'000000'

Time arithmetic in seconds

X

Byte (hexadecimal)

default 1 byte

X'00'

Raw bytes

I

Integer (4 bytes)

4

0

Whole numbers ±2,147,483,647 – no decimals

INT8

Integer (8 bytes)

8

0

Large counters (7.50+)

P

Packed decimal

1–16 bytes, default 8

0

Up to 14 decimals – use for amounts and quantities

F

Binary floating point

8

0

~16 digits, rounding errors – never for money

DECFLOAT16/34

Decimal floating point

8 / 16

0

Exact decimal arithmetic with large ranges

STRING / XSTRING

Variable length text / bytes

dynamic

empty

Grows as needed

UTCLONG

UTC time stamp

8

empty

7.54+; replaces packed time stamps in new code

  • Integers do not hold decimals. lv_i = '2.5'. (lv_i TYPE i) stores 3 (commercial rounding). Use P (or DECFLOAT) when you need decimals.
  • Numeric types: I, INT8, P, F, DECFLOAT. Character-like: C, N, D, T, STRING. Byte-like: X, XSTRING.

Reference types and data references

A reference variable holds the address of a data object (or object). There are no predefined reference types – you declare them with TYPE REF TO. They are used for dynamic programming: create data whose type is known only at runtime. Dereference with ->*.

DATA lr_any TYPE REF TO data.                " generic: any type
CREATE DATA lr_any TYPE sflight.             " type decided at runtime (can be dynamic)
ASSIGN lr_any->* TO FIELD-SYMBOL(<ls_any>).  " generic refs need ASSIGN to access the data

DATA(lr_int) = NEW i( 5 ).  " fully typed reference, NEW operator
lr_int->* = lr_int->* + 1.  " typed refs can be dereferenced directly

1.3 Data objects: variables, constants, structures

A data object is a named piece of memory in a running program. Declarative keywords: DATA (variable), CONSTANTS (fixed value), TYPES (a type – no memory), PARAMETERS / SELECT-OPTIONS (screen fields + variables), TABLES (obsolete work area with a DDIC table's structure – today only for screen fields).

DATA lv_eid(10) TYPE n.          " predefined type with length (no space before "(10)")
DATA lv_eid2    TYPE zzeid.      " data element
DATA lv_eid3    TYPE zzemp-eid.  " component of a DDIC table / structure
DATA lv_eid4    LIKE lv_eid3.    " LIKE refers to another data object
CONSTANTS gc_max TYPE i VALUE 100.

TYPES: BEGIN OF ty_emp,  " local structure type – no memory yet
eid  TYPE zzemp-eid,
name TYPE zzemp-name,
END OF ty_emp,
tt_emp TYPE STANDARD TABLE OF ty_emp WITH EMPTY KEY.  " table type

TYPES BEGIN OF ty_emp_ext.     " include one structure in another
INCLUDE TYPE ty_emp.         " components of ty_emp (or INCLUDE STRUCTURE zstruc
TYPES dept TYPE c LENGTH 4.  "  for a DDIC structure / structured data object)
TYPES END OF ty_emp_ext.

DATA ls_emp TYPE ty_emp.  " work area = structure with memory
DATA lt_emp TYPE tt_emp.  " internal table
  • TYPE vs LIKE: TYPE refers to a type, LIKE to an existing data object. LIKE is not obsolete, does not copy data and costs no performance. Only LIKE with DDIC tables in some old contexts is obsolete.
  • Structure = several fields grouped as one unit (one record). Work area = a structure variable (DATA ls TYPE struc). Table type = the type of an internal table. Kinds of structures (flat, nested, deep, INCLUDE STRUCTURE) and global structures/table types in SE11: see page 02 DDIC.
  • Selecting fewer columns makes SELECT faster – not the use of structures. Structures just keep related fields together.

Important system fields (structure SY / SYST)

Field

Meaning

SY-SUBRC

Return code of the last statement; 0 = success

SY-TABIX

Current row index in LOOP AT itab and after READ TABLE (index tables)

SY-INDEX

Loop pass counter in DO and WHILE (not in LOOP AT)

SY-TFILL

Rows of an internal table after DESCRIBE TABLE – use lines( itab ) today

SY-DBCNT

Rows processed by the last SQL statement

SY-UNAME, SY-DATUM, SY-UZEIT

User, date, time (application server)

SY-REPID, SY-CPROG

Current program / calling program

SY-DYNNR, SY-UCOMM

Current screen number / function code

SY-LSIND, SY-LISEL

List index (0 = basic list) / contents of the selected list line

SY-BATCH

'X' when running in background

SY-MSGID, SY-MSGTY, SY-MSGNO, SY-MSGV1–4

Last message – page 04

1.4 Control structures

Construct

Syntax

Notes

Condition

IF … ELSEIF … ELSE … ENDIF / CASE … WHEN … WHEN OTHERS … ENDCASE

IFs can be nested

Unconditional loop

DO [n TIMES] … ENDDO

SY-INDEX = pass number; leave with EXIT

Conditional loop

WHILE cond … ENDWHILE

SY-INDEX = pass number

Table loop

LOOP AT itab … ENDLOOP

SY-TABIX = current row; control breaks in Part 8

  • CONTINUE – skip the rest of this pass, go to the next one. EXIT – leave the current loop.
  • CHECK cond – if the condition is false: inside a loop it ends the current pass, outside a loop it leaves the current processing block.
  • There is no FOR loop statement: FOR is an iteration expression inside VALUE, REDUCE, NEW – see ABAP on HANA › 03.

1.5 Field symbols

A field symbol is a placeholder that points to an existing data object – it stores no data of its own. After ASSIGN, every read or write through the field symbol works directly on the target. = assigns a value to the target; ASSIGN changes what it points to.

FIELD-SYMBOLS <lv_any> TYPE any.
DATA lv_num TYPE i VALUE 10.
ASSIGN lv_num TO <lv_any>.
<lv_any> = 20.  " lv_num is now 20

LOOP AT lt_emp ASSIGNING FIELD-SYMBOL(<ls_emp>).  " no copy into a work area – faster
<ls_emp>-name = to_upper( <ls_emp>-name ).      " changes the table row directly
ENDLOOP.

IF <lv_any> IS ASSIGNED.
UNASSIGN <lv_any>.
ENDIF.

Part 2 – Internal tables

An internal table is a temporary table in program memory. It holds any number of rows of the same line type and disappears when the program ends. You fill it from the database, process it, and display it.

2.1 Table kinds

Internal table kinds: generic ANY TABLE and INDEX TABLE, standard, sorted and hashed tables with key search cost, access and key

STANDARD

SORTED

HASHED

Key

Non-unique only (or empty)

Unique or non-unique

Unique only

Access by

Mainly index

Index or key

Key only

Key search cost

Linear (table scan) – slow

Logarithmic (binary search)

Constant (hash function)

Filled with

APPEND / INSERT

INSERT (kept in key order)

INSERT

Use when

Small tables, processed in order

Partial-key reads, ranges, LOOP … WHERE on key

Large tables, read by full key

DATA lt_std    TYPE STANDARD TABLE OF sflight WITH EMPTY KEY.
DATA lt_sorted TYPE SORTED TABLE OF sflight WITH NON-UNIQUE KEY carrid connid.
DATA lt_hashed TYPE HASHED TABLE OF scarr WITH UNIQUE KEY carrid.
DATA lt_sec    TYPE STANDARD TABLE OF sflight WITH EMPTY KEY
WITH NON-UNIQUE SORTED KEY by_date COMPONENTS fldate.  " secondary key

2.2 Operations

Single row

Several rows

Read

READ TABLE itab INTO wa WITH KEY k1 = v1 … kn = vn.

READ TABLE itab INTO wa INDEX n.

LOOP AT itab INTO wa WHERE cond. … ENDLOOP.

Insert

INSERT wa INTO TABLE itab.

APPEND wa TO itab.

INSERT LINES OF itab1 INTO TABLE itab2.

APPEND LINES OF itab1 TO itab2.

Change

MODIFY TABLE itab FROM wa. (by key)

MODIFY itab FROM wa INDEX n.

MODIFY itab FROM wa TRANSPORTING f1 f2 WHERE cond.

Delete

DELETE TABLE itab FROM wa.

DELETE TABLE itab WITH TABLE KEY k1 = v1 … kn = vn.

DELETE itab WHERE cond.

DELETE ADJACENT DUPLICATES FROM itab COMPARING f.

Statement

What it does – and the correct rules

APPEND

Adds a row at the end. Index tables only (standard; sorted only if the order stays correct). APPEND LINES OF itab1 [FROM n1] [TO n2] TO itab2.

INSERT

INSERT wa INTO TABLE itab – by key for sorted/hashed, at the end for standard. INSERT wa INTO itab INDEX n – at a position (index tables). INSERT LINES OF itab1 [FROM n1] [TO n2] INTO itab2 [INDEX n].

COLLECT

If no row with the same key exists, insert; otherwise add the numeric fields to the existing row. All non-key fields must be numeric. Best with sorted/hashed tables.

SORT

SORT itab BY f1 [DESCENDING] f2 … – default order ascending. Without BY it sorts by the primary table key (for a standard table with default key: all character-like fields – not "the first field"). STABLE keeps the order of equal rows. Sorted tables can't be sorted.

READ TABLE

READ TABLE itab INTO wa WITH KEY f = v [BINARY SEARCH] – BINARY SEARCH only on a table sorted ascending by f. TRANSPORTING NO FIELDS just checks existence (SY-SUBRC, SY-TABIX).

DESCRIBE TABLE

DESCRIBE TABLE itab LINES n → today lines( itab ).

CLEAR / FREE

CLEAR itab deletes all rows (keeps the initial memory). FREE itab deletes rows and releases memory. CLEAR also works on variables and structures.

Copy

itab2 = itab1. · APPEND LINES OF · MOVE-CORRESPONDING (by field name, also tables since 7.40) · itab2 = CORRESPONDING #( itab1 MAPPING new = old EXCEPT f ).

COLLECT step by step: new keys CUST_A and CUST_B are inserted, the second CUST_A row is added up (100 + 70 = 170)
TYPES: BEGIN OF ty_sales,
kunnr TYPE kunnr,
netwr TYPE netwr,
END OF ty_sales.
DATA lt_tot TYPE HASHED TABLE OF ty_sales WITH UNIQUE KEY kunnr.
DATA ls_tot TYPE ty_sales.

LOOP AT lt_items INTO DATA(ls_item).
ls_tot = VALUE #( kunnr = ls_item-kunnr netwr = ls_item-netwr ).
COLLECT ls_tot INTO lt_tot.
ENDLOOP.  " one row per customer with the total

SORT lt_items BY kunnr vbeln.
READ TABLE lt_items INTO ls_item WITH KEY kunnr = 'CUST_A' BINARY SEARCH.
IF sy-subrc = 0.
WRITE: / 'found at row', sy-tabix.
ENDIF.

" Modern equivalents (7.40): table expressions – see ABAP on HANA › 03
DATA(ls_hit) = VALUE #( lt_items[ kunnr = 'CUST_A' ] OPTIONAL ).  " no exception if missing
IF line_exists( lt_items[ kunnr = 'CUST_A' ] ). ENDIF.
  • SY-TABIX vs SY-INDEX: SY-TABIX = row number of the current internal-table row (LOOP AT, READ TABLE). SY-INDEX = pass counter of DO/WHILE loops.
  • A table expression itab[ … ] raises CX_SY_ITAB_LINE_NOT_FOUND if the row is missing – use OPTIONAL, DEFAULT or line_exists( ).

Legacy – header lines: DATA itab TYPE … WITH HEADER LINE / OCCURS n created a table and a work area with the same name (itab = header, itab[] = body). CLEAR itab then cleared only the header, REFRESH itab the body. Header lines are obsolete and forbidden in classes – always use a separate work area or field symbol, and CLEAR itab instead of REFRESH.

Part 3 – Reading data: joins, FOR ALL ENTRIES, performance

Typical report structure: declare types and data → selection screen → read data into internal tables (START-OF-SELECTION) → display. Read into a table in one statement and display from the table; don't WRITE inside a SELECT … ENDSELECT loop. ABAP SQL basics (SELECT, SELECT SINGLE, INTO TABLE, ABAP SQL vs native SQL, the database interface) are on page 02 DDIC, Part 14; the full modern syntax is on ABAP on HANA › 04 ABAP SQL. This part adds what reports need on top: several tables and speed.

START-OF-SELECTION.
SELECT carrid, connid, fldate, price, currency FROM sflight
WHERE carrid IN @s_carr AND fldate >= @p_date
INTO TABLE @DATA(lt_flights).
IF sy-subrc <> 0.  " nothing found: stay on the selection screen
MESSAGE 'No flights found' TYPE 'S' DISPLAY LIKE 'E'.
LEAVE LIST-PROCESSING.
ENDIF.

3.1 Reading several tables

Technique

When

Rules

INNER JOIN

Rows that have a partner in both tables

Preferred on HANA – one DB round trip

LEFT OUTER JOIN

All rows of the left table, partner fields empty if no match

e.g. all customers, with or without orders

FOR ALL ENTRIES (FAE)

Second table read for the keys in an internal table (driver)

Driver must not be empty (empty = no WHERE = reads all rows); select the full key (FAE removes duplicate result rows); same type/length in compared fields; remove duplicate driver keys first (performance)

Nested SELECT / SELECT in LOOP

Never

One DB call per row – very slow

SELECT h~vbeln, h~kunnr, i~posnr, i~matnr, i~netwr
FROM vbak AS h
INNER JOIN vbap AS i ON i~vbeln = h~vbeln
WHERE h~kunnr IN @s_kunnr
INTO TABLE @DATA(lt_orders).

IF lt_orders IS NOT INITIAL.  " FAE guard
SELECT matnr, maktx FROM makt
FOR ALL ENTRIES IN @lt_orders
WHERE matnr = @lt_orders-matnr AND spras = @sy-langu
INTO TABLE @DATA(lt_texts).
ENDIF.
  • The old rule "INNER JOIN for 2–3 tables, FAE for more" is dated. On HANA use joins or CDS views (code pushdown); since 7.52 you can even SELECT … FROM @itab or join an internal table. Details: ABAP on HANA › 04 ABAP SQL.
  • Database rules: no SELECT * unless you need every field; list only the needed columns (their order does not matter on modern databases); full key → SELECT SINGLE; no nested SELECTs; prefer joins / views / CDS; check buffering for small customizing tables (page 02).

3.2 Internal table performance

  • Avoid nested loops over two big tables (n × m passes). Use a sorted or hashed table (or secondary key) for the inner access, or READ … BINARY SEARCH on a sorted standard table.
  • Never SORT inside a loop. Use field symbols / references instead of copying big rows.
  • Parallel cursor – when a nested loop over header and item tables can't be avoided:
SORT lt_head BY vbeln.
SORT lt_item BY vbeln.
LOOP AT lt_head INTO DATA(ls_head).
READ TABLE lt_item TRANSPORTING NO FIELDS WITH KEY vbeln = ls_head-vbeln BINARY SEARCH.
CHECK sy-subrc = 0.  " no items for this order
LOOP AT lt_item INTO DATA(ls_item) FROM sy-tabix.  " start at the first matching item
IF ls_item-vbeln <> ls_head-vbeln.
EXIT.            " next order begins – leave the inner loop
ENDIF.
" process ls_head + ls_item
ENDLOOP.
ENDLOOP.
" Simpler today: lt_item TYPE SORTED TABLE … WITH NON-UNIQUE KEY vbeln
"                + LOOP AT lt_item … WHERE vbeln = ls_head-vbeln (optimised key access)
  • Tools to find slow code: ST05 (SQL trace), SAT (runtime analysis), ATC/SCI checks – see ABAP on HANA › 02.

Part 4 – Report events

An executable program is event driven: the ABAP runtime calls its event blocks in a fixed order. Each event block starts with its keyword and ends at the next event keyword. You don't call events yourself.

Order of report events from LOAD-OF-PROGRAM to secondary lists

Event

When it runs

Use it for

LOAD-OF-PROGRAM

Once, when the program is loaded (types 1, M, F, S)

Initialise global data – like a class constructor

INITIALIZATION

Type 1 only, before the selection screen is shown

Default values for parameters/select-options (e.g. dates)

AT SELECTION-SCREEN OUTPUT

Before every display of the selection screen (its PBO)

Hide / disable fields (LOOP AT SCREEN)

AT SELECTION-SCREEN ON VALUE-REQUEST FOR f

User presses F4 on f

Own value help

AT SELECTION-SCREEN ON HELP-REQUEST FOR f

User presses F1 on f

Own documentation

AT SELECTION-SCREEN ON f / ON BLOCK b / ON RADIOBUTTON GROUP g / ON END OF so

After input, per field / block / group

Validation – after an E message only that field/block is ready for input

AT SELECTION-SCREEN

After input, last selection-screen event (its PAI)

Cross-field validation – all fields ready for input again

AT SELECTION-SCREEN ON EXIT-COMMAND

User chooses Back/Exit/Cancel

Clean-up before leaving

START-OF-SELECTION

After the selection screen is processed

Read data. The default event

END-OF-SELECTION

After START-OF-SELECTION (with logical DBs: after all data is read)

Display – optional without logical DBs

TOP-OF-PAGE

First output statement on a new list page

Page header

END-OF-PAGE

When a page is full

Footer – needs REPORT … LINE-COUNT n(m) (m footer lines)

  • The default event is START-OF-SELECTION, not LOAD-OF-PROGRAM. Every statement that is not inside an event block (or after a FORM/METHOD) belongs to START-OF-SELECTION.
  • Order: F8 → LOAD-OF-PROGRAM → INITIALIZATION → AT SELECTION-SCREEN OUTPUT → screen shown → AT SELECTION-SCREEN ON … / AT SELECTION-SCREEN (repeat until valid) → START-OF-SELECTION → END-OF-SELECTION → basic list shown (TOP-OF-PAGE / END-OF-PAGE whenever a page starts / ends).
  • Interactive events (Part 7): AT LINE-SELECTION, AT USER-COMMAND, AT PFnn (obsolete), TOP-OF-PAGE DURING LINE-SELECTION.
  • Logical databases (GET node events, NODES) are obsolete but still appear in old HR and FI reports.
REPORT zr_flight_list NO STANDARD PAGE HEADING LINE-SIZE 120 LINE-COUNT 65(2).

TABLES sflight.  " only for SELECT-OPTIONS … FOR sflight-…
PARAMETERS p_date TYPE s_date.
SELECT-OPTIONS s_carr FOR sflight-carrid.
DATA gt_flights TYPE STANDARD TABLE OF sflight WITH EMPTY KEY.

INITIALIZATION.
p_date = sy-datum - 30.

AT SELECTION-SCREEN ON p_date.
IF p_date > sy-datum.
MESSAGE 'Date must not be in the future' TYPE 'E'.  " only p_date stays open
ENDIF.

START-OF-SELECTION.
SELECT * FROM sflight
WHERE carrid IN @s_carr AND fldate >= @p_date
INTO TABLE @gt_flights.

END-OF-SELECTION.
LOOP AT gt_flights INTO DATA(ls_f).
WRITE: / ls_f-carrid, ls_f-connid, ls_f-fldate, ls_f-price CURRENCY ls_f-currency.
ENDLOOP.

TOP-OF-PAGE.
WRITE: / 'Flights since', p_date, 50 'Page', sy-pagno.
ULINE.

END-OF-PAGE.
WRITE: / 'Confidential – internal use'.

Part 5 – Selection screens

The selection screen is the input (filter) screen of a report. The standard selection screen 1000 is generated automatically as soon as you declare PARAMETERS or SELECT-OPTIONS outside a user-defined screen. User-defined selection screens have any other 4-digit number and are defined with SELECTION-SCREEN BEGIN OF SCREEN nnnn and shown with CALL SELECTION-SCREEN nnnn.

5.1 PARAMETERS and SELECT-OPTIONS

  • One input value → PARAMETERS. Many values, intervals, exclusions → SELECT-OPTIONS. Names max 8 characters.
PARAMETERS: p_bukrs TYPE bukrs OBLIGATORY MEMORY ID buk,      " required, from SAP memory
p_name  TYPE string LOWER CASE,                   " keep lower case
p_max   TYPE i DEFAULT 100,
p_test  AS CHECKBOX DEFAULT 'X',                  " checkbox: ' ' or 'X'
p_list  RADIOBUTTON GROUP out DEFAULT 'X',        " radio buttons: one group
p_alv   RADIOBUTTON GROUP out,
p_land  TYPE land1 AS LISTBOX VISIBLE LENGTH 20,  " dropdown list
p_mat   TYPE matnr MATCHCODE OBJECT mat1,         " search help
p_hide  TYPE c LENGTH 1 NO-DISPLAY.               " hidden, set by SUBMIT

SELECT-OPTIONS: s_kunnr FOR gv_kunnr,               " gv_kunnr TYPE kunnr
s_erdat FOR gv_erdat NO-EXTENSION,  " no multiple selection
s_vkorg FOR gv_vkorg NO INTERVALS.  " single values, no "to" field

A SELECT-OPTION is a range table (an internal table with four columns) plus its screen fields. Use it in SQL with IN.

Column

Values

Example

SIGN

I = include, E = exclude

I

OPTION

EQ, NE, GT, GE, LT, LE, BT (between), NB, CP (pattern), NP

BT

LOW

Single value or lower limit

1000

HIGH

Upper limit (for BT / NB)

1999

DATA lr_kunnr TYPE RANGE OF kunnr.  " range table, no screen field (was RANGES)
lr_kunnr = VALUE #( ( sign = 'I' option = 'BT' low = '0000001000' high = '0000001999' )
( sign = 'E' option = 'EQ' low = '0000001500' ) ).
SELECT kunnr, name1 FROM kna1 WHERE kunnr IN @lr_kunnr INTO TABLE @DATA(lt_kna1).
" Careful: an EMPTY range / select-option means "no restriction" – all rows are read.
  • RANGES is not a UI element – it is an obsolete statement that declares a range table without any screen field. Use TYPE RANGE OF.

5.2 Layout: blocks, lines, buttons, tabs

SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE TEXT-001.
PARAMETERS p_bukrs TYPE bukrs.
SELECTION-SCREEN SKIP 1.
SELECTION-SCREEN ULINE.
SELECTION-SCREEN BEGIN OF LINE.                              " several elements on one line
SELECTION-SCREEN COMMENT 1(20) TEXT-002 FOR FIELD p_from.  " label
PARAMETERS: p_from TYPE datum, p_to TYPE datum.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN END OF BLOCK b1.

SELECTION-SCREEN PUSHBUTTON /2(20) gv_btn USER-COMMAND reset.  " button text in gv_btn

SELECTION-SCREEN BEGIN OF TABBED BLOCK tb FOR 5 LINES.  " tabs on a selection screen
SELECTION-SCREEN TAB (15) gv_tab1 USER-COMMAND tab1 DEFAULT SCREEN 101.
SELECTION-SCREEN TAB (15) gv_tab2 USER-COMMAND tab2 DEFAULT SCREEN 102.
SELECTION-SCREEN END OF BLOCK tb.

SELECTION-SCREEN BEGIN OF SCREEN 101 AS SUBSCREEN.
PARAMETERS p_vkorg TYPE vkorg.
SELECTION-SCREEN END OF SCREEN 101.
SELECTION-SCREEN BEGIN OF SCREEN 102 AS SUBSCREEN.
PARAMETERS p_werks TYPE werks_d.
SELECTION-SCREEN END OF SCREEN 102.

SELECTION-SCREEN BEGIN OF SCREEN 200 TITLE TEXT-003.  " own selection screen
PARAMETERS p_file TYPE string LOWER CASE.
SELECTION-SCREEN END OF SCREEN 200.
" later: CALL SELECTION-SCREEN 200 [STARTING AT 10 5].  SY-SUBRC = 4 if the user cancelled
  • NAME identifies a screen element; the function code (USER-COMMAND fc) identifies which button or tab was used. On selection screens read it from sscrfields-ucomm (declare TABLES sscrfields.) – SY-UCOMM is not reliable there.
TABLES sscrfields.
INITIALIZATION.
gv_btn  = 'Reset'.
gv_tab1 = 'Sales'.
gv_tab2 = 'Plant'.

AT SELECTION-SCREEN.
IF sscrfields-ucomm = 'RESET'.
CLEAR: p_from, p_to.
ENDIF.

5.3 Changing the screen at runtime (MODIF ID + LOOP AT SCREEN)

PARAMETERS: p_local RADIOBUTTON GROUP src DEFAULT 'X' USER-COMMAND src,  " Enter on change
p_appl  RADIOBUTTON GROUP src,
p_lfile TYPE string LOWER CASE MODIF ID loc,
p_afile TYPE string LOWER CASE MODIF ID app.

AT SELECTION-SCREEN OUTPUT.
LOOP AT SCREEN.
IF ( screen-group1 = 'LOC' AND p_local = abap_false )
OR ( screen-group1 = 'APP' AND p_appl  = abap_false ).
screen-active = '0'.  " also: input, invisible, required, intensified
MODIFY SCREEN.
ENDIF.
ENDLOOP.

5.4 Validation, F4 help and authority checks

  • Validate in AT SELECTION-SCREEN ON f (only f re-opens) or AT SELECTION-SCREEN (all fields). Error message type E keeps the user on the screen. Message types and their behaviour: page 04.
  • Own F4 help: AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_x + function module F4IF_INT_TABLE_VALUE_REQUEST (example on page 05). DDIC search helps: page 02.
  • AUTHORITY-CHECK – every report that shows or changes business data must check authorizations (objects in SU21, proposals in SU24, failed checks analysed with SU53).
AT SELECTION-SCREEN ON p_bukrs.
AUTHORITY-CHECK OBJECT 'F_BKPF_BUK'
ID 'BUKRS' FIELD p_bukrs
ID 'ACTVT' FIELD '03'.               " 03 = display
IF sy-subrc <> 0.
MESSAGE e001(zfi_msg) WITH p_bukrs.  " "No authorization for company code &1"
ENDIF.

5.5 Text elements and variants

  • Text elements (Goto → Text elements) are language-dependent texts shown in the user's logon language and translated with SE63:
    • Selection texts – labels for parameters and select-options (or take them from the DDIC).
    • Text symbols – TEXT-001 (3-character ID) for titles, comments and WRITE output; no hard-coded texts.
    • List headings – column and page headings for the standard page header.
  • A variant is a saved set of selection-screen values. A screen can have many variants.
    • Use in dialog: prefill fields, hide fields, protect fields, mark fields required.
    • Use in background: a job step needs a variant to supply the selection values (Part 10).
    • Selection variables make values dynamic, e.g. "today – 30" (date calculation) or a value from table TVARVC.
    • Variants starting with SAP& / CUS& are client-independent system variants, recorded on a transport request.

Part 6 – Classical reports (list output)

A classical report writes its output with WRITE into a list (the basic list). It is simple and still common for logs and quick tools; for user-facing reports use ALV (Part 9).

  • Standard page heading – line 1: program title + page number, line 2: an underline. Remove it with REPORT … NO STANDARD PAGE HEADING.
  • LINE-SIZE n – characters per line; LINE-COUNT n(m) – lines per page, m of them reserved for END-OF-PAGE.

Statement

Effect

WRITE / f

New line, then output. Options: position/length WRITE AT 10(15) f, CURRENCY w, UNIT u, NO-ZERO, NO-GAP, USING EDIT MASK, LEFT-JUSTIFIED

NEW-PAGE

Page break

SKIP [n]

Blank line(s)

ULINE / WRITE sy-uline

Horizontal line

WRITE sy-vline

Vertical line (for grid-like lists)

FORMAT COLOR n

Background colour 1–7 (COL_HEADING, COL_TOTAL, COL_NEGATIVE …) until FORMAT RESET

FORMAT INVERSE ON

Colour applied to the font instead of the background

FORMAT INTENSIFIED ON/OFF

Brighter / normal shade

FORMAT HOTSPOT ON

Single click triggers AT LINE-SELECTION

  • Record count after reading: sy-dbcnt (rows from the last SQL statement) or lines( itab ).
  • Lists can be sent to the spool (print, background) and viewed in SP01.

Sending a list or PDF by e-mail (CL_BCS, CL_DOCUMENT_BCS, SOST) is explained on page 11 Forms.

Part 7 – Interactive reports and calling programs

In an interactive report the user clicks a line of the basic list and gets a secondary (detail) list. The basic list has index 0 (only one per program); secondary lists have SY-LSIND 1 to 20 – a 21st level causes a runtime error. F3 returns to the previous level.

Event

Triggered by

AT LINE-SELECTION

Double-click (function code PICK) or single click on a HOTSPOT field

AT USER-COMMAND

A function code from your own GUI status (SET PF-STATUS 'ZLIST'), read SY-UCOMM

AT PFnn

Function key Fnn – obsolete (there is no event "AT PF-STATUS")

TOP-OF-PAGE DURING LINE-SELECTION

Header of secondary lists

7.1 Knowing which line was selected

  • HIDE f – after writing a line, store the value of f for that line. When the user selects the line, the runtime restores f automatically. Works for flat global fields and structures (variables yes); not for internal tables or references.
  • GET CURSOR FIELD f VALUE v – name of the field under the cursor (e.g. 'LS_ORD-VBELN') and its displayed value; lets you react only when a certain column was clicked.
  • SY-LISEL – the whole selected line as text; reading it with offsets is fragile – prefer HIDE or GET CURSOR. READ LINE / MODIFY LINE read or change list lines (e.g. checkboxes in a list).
START-OF-SELECTION.
SELECT vbeln, kunnr, netwr, waerk FROM vbak WHERE kunnr IN @s_kunnr INTO TABLE @gt_orders.
LOOP AT gt_orders INTO gs_order.  " global work area (needed by HIDE)
WRITE: / gs_order-vbeln HOTSPOT, gs_order-kunnr, gs_order-netwr CURRENCY gs_order-waerk.
HIDE gs_order-vbeln.
ENDLOOP.
CLEAR gs_order.

AT LINE-SELECTION.                 " SY-LSIND is already the new list's index
GET CURSOR FIELD gv_field.       " gv_field TYPE c LENGTH 30 (global)
CHECK sy-lsind = 1 AND gs_order-vbeln IS NOT INITIAL.  " only clicks on order lines
IF gv_field = 'GS_ORDER-VBELN'.  " order number clicked → open the order
SET PARAMETER ID 'AUN' FIELD gs_order-vbeln.
CALL TRANSACTION 'VA03' WITH AUTHORITY-CHECK AND SKIP FIRST SCREEN.
ELSE.                            " other column → detail list 1: items
SELECT posnr, matnr, kwmeng FROM vbap WHERE vbeln = @gs_order-vbeln
INTO TABLE @DATA(lt_items).
LOOP AT lt_items INTO DATA(ls_item).
WRITE: / ls_item-posnr, ls_item-matnr, ls_item-kwmeng.
ENDLOOP.
ENDIF.
CLEAR gs_order.  " a later click on a header line finds nothing

TOP-OF-PAGE DURING LINE-SELECTION.
WRITE: / 'Items of order', gs_order-vbeln.

7.2 Calling other programs and transactions

Statement

Effect

SUBMIT zprog [VIA SELECTION-SCREEN] [WITH p = v] [WITH s IN r] [USING SELECTION-SET 'VAR']

Start another report; the caller ends (without AND RETURN)

SUBMIT zprog … AND RETURN

Start it in a new internal session and come back afterwards

CALL TRANSACTION 'TC' [AND SKIP FIRST SCREEN]

Start a transaction and return; first screen filled from SAP memory (parameter IDs). Add WITH AUTHORITY-CHECK (7.40+)

LEAVE TO TRANSACTION 'TC'

Start a transaction; the current program ends, no return

SET / GET PARAMETER ID 'PID' FIELD f

Write / read SAP memory (see below)

7.3 Passing data between programs: ABAP memory and SAP memory

User logon, external and internal sessions, ABAP memory and SAP memory

ABAP memory

SAP memory

Scope

All internal sessions of one call chain (one window)

All external sessions of the user's logon

Statements

EXPORT … TO MEMORY ID / IMPORT … FROM MEMORY ID / FREE MEMORY ID

SET PARAMETER ID / GET PARAMETER ID

Data

Any data incl. internal tables (no object references)

Flat character-like values only

Names

Only the parameter name in EXPORT/IMPORT must match

Parameter ID (table TPARA, max 20 chars, linked via data element)

Typical use

Hand a table to a report called with SUBMIT … AND RETURN

Prefill screen fields, e.g. order number for VA03

" Caller
EXPORT orders = lt_orders TO MEMORY ID 'ZDEMO_ORDERS'.
SUBMIT zr_order_detail AND RETURN.

" Called program
IMPORT orders = lt_orders FROM MEMORY ID 'ZDEMO_ORDERS'.  " FROM, not TO
FREE MEMORY ID 'ZDEMO_ORDERS'.
  • Shared memory objects (SHMA) and shared buffers (EXPORT … TO SHARED BUFFER) exchange data across users on one application server – rarely needed in reports.

Part 8 – Control break statements

Control break statements (control level processing) react to group changes while you loop over a sorted internal table – headings per group, subtotals, grand totals. They are statements inside LOOP AT … ENDLOOP, not events, and they are not only for display.

Control break statements AT FIRST, AT NEW, AT END OF, AT LAST on a sorted flight table

Statement

Runs

Typical use

AT FIRST … ENDAT

Once, before the first row

Report title, initialisation

AT NEW f … ENDAT

When f (or any field left of f) gets a new value – first row of a group

Group heading

AT END OF f … ENDAT

Last row of a group

SUM → subtotal of the group

AT LAST … ENDAT

Once, after the last row

SUM → grand total

  • Rules: sort by the control fields first; the control field order follows the table's column order (left to right); write the blocks in the order AT FIRST → AT NEW → row processing → AT END OF → AT LAST; don't nest them.
  • Inside AT…ENDAT the fields to the right of the control field are initial (or *). Save the row before the AT block if you need them. Avoid LOOP … WHERE with control levels – group changes may be wrong.
  • Modern alternative: LOOP AT … GROUP BY with group-level processing – see ABAP on HANA › 03 Part 7.

Legacy – ON CHANGE OF: ON CHANGE OF f … ENDON is obsolete and is not a control level statement (it remembers the previous value even outside loops and ignores sorting). The old "items for one order" example built with ON CHANGE OF should be rewritten with AT NEW, a sorted table, the parallel cursor (Part 3.2) or GROUP BY.

Part 9 – ALV (SAP List Viewer)

ALV (ABAP List Viewer, today SAP List Viewer) displays an internal table as an interactive grid: the user can sort, filter, total, change columns, export to Excel and save layouts – without extra code.

This part is the overview. In-depth ALV (field catalog and layout fields, all grid events, editable ALV, colours, trees, full examples): OOPS ABAP › 04 ALV Reporting.

ALV kind

Shows

ALV list

One table as a list (simple, printable) – classic FM REUSE_ALV_LIST_DISPLAY

ALV grid

One table as a grid control: drag & drop, own toolbar buttons, editable cells – classic FM REUSE_ALV_GRID_DISPLAY

ALV tree

Hierarchical data as a tree (CL_SALV_TREE, CL_GUI_ALV_TREE)

ALV block list

Several independent tables one below the other (REUSE_ALV_BLOCK_LIST_*)

Hierarchical-sequential list

Two tables, two levels: header row + its item rows (CL_SALV_HIERSEQ_TABLE)

  • List vs grid: the grid has drag & drop, its own toolbar and edit mode; the list prints better. In background the grid is output as a list in the spool automatically.
ALV technologies: REUSE function modules, CL_GUI_ALV_GRID, CL_SALV_TABLE, ALV with IDA

9.1 Field catalog, layout, sort – the building blocks

The field catalog describes each output column (name, heading, position, colour, totals, hotspot, edit …). It is always needed – but it can be generated.

Way

How

Notes

Automatic

REUSE FMs: I_STRUCTURE_NAME = DDIC structure; SALV: factory( ) reads the internal table

No control over columns (REUSE)

Manual

Fill the field catalog table row by row

Full control, most code

Semi-automatic

Generate with REUSE_ALV_FIELDCATALOG_MERGE / LVC_FIELDCATALOG_MERGE, then change some rows

MERGE works only from DDIC structures or old-style declarations

Field (SLIS / LVC)

Meaning

col_pos

Column position (otherwise order of rows in the catalog)

fieldname, tabname

Column of the output table / name of the output table (REUSE)

seltext_s/m/l (SLIS) – scrtext_s/m/l, coltext (LVC)

Column headings short / medium / long

emphasize

Column colour 'Cxyz': x = colour 1–7, y = intensified 0/1, z = inverse 0/1

key

Key column (blue, fixed when scrolling)

do_sum

Total this column

hotspot, edit, no_out, outputlen

Single-click link, editable, hidden, width

  • Sort table (SLIS_T_SORTINFO_ALV / LVC_T_SORT): spos (sequence), fieldname, up / down, subtot = 'X' for subtotals (needs do_sum on the amount column).
  • Layout structure (SLIS_LAYOUT_ALV / LVC_S_LAYO): zebra stripes, optimised column width (colwidth_optimize / cwidth_opt), title, selection mode, box field.
  • Field catalog types differ: SLIS_T_FIELDCAT_ALV (type group SLIS) for REUSE FMs, LVC_T_FCAT for CL_GUI_ALV_GRID; SALV hides the catalog behind column objects.

9.2 Legacy: REUSE_ALV_GRID_DISPLAY

Classic ALV function modules – found in most old Z reports. Events are handled through callback FORMs: the classical TOP-OF-PAGE / END-OF-PAGE events don't work in ALV. REUSE_ALV_EVENTS_GET returns the available events (how many depends on the list type).

DATA: gt_fcat   TYPE slis_t_fieldcat_alv,
gs_layout TYPE slis_layout_alv,
gt_sort   TYPE slis_t_sortinfo_alv.

gs_layout-zebra             = abap_true.
gs_layout-colwidth_optimize = abap_true.
gt_fcat = VALUE #( ( col_pos = 1 fieldname = 'CARRID' seltext_m = 'Airline' key = abap_true )
( col_pos = 2 fieldname = 'CONNID' seltext_m = 'Flight' )
( col_pos = 3 fieldname = 'PRICE' seltext_m = 'Price'
do_sum = abap_true ) ).
gt_sort = VALUE #( ( spos = 1 fieldname = 'CARRID' up = abap_true subtot = abap_true ) ).

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program      = sy-repid
i_callback_top_of_page  = 'TOP_OF_PAGE'  " FORM names in upper case
i_callback_user_command = 'USER_COMMAND'
is_layout               = gs_layout
it_fieldcat             = gt_fcat
it_sort                 = gt_sort
TABLES
t_outtab                = gt_flights
EXCEPTIONS
program_error           = 1
OTHERS                  = 2.

FORM top_of_page.
DATA(lt_head) = VALUE slis_t_listheader( ( typ = 'H' info = 'Flight report' ) ).
CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
EXPORTING it_list_commentary = lt_head.
ENDFORM.

FORM user_command USING r_ucomm TYPE sy-ucomm rs_selfield TYPE slis_selfield.
IF r_ucomm = '&IC1'.  " double-click / hotspot
READ TABLE gt_flights INTO DATA(ls_f) INDEX rs_selfield-tabindex.
" … show details
ENDIF.
ENDFORM.
  • Own toolbar: i_callback_pf_status_set + a FORM that calls SET PF-STATUS (copy status STANDARD from program SAPLKKBL).

9.3 CL_SALV_TABLE – simple modern ALV

CLASS lcl_events DEFINITION.
PUBLIC SECTION.
CLASS-METHODS on_double_click FOR EVENT double_click OF cl_salv_events_table
IMPORTING row column.
ENDCLASS.
CLASS lcl_events IMPLEMENTATION.
METHOD on_double_click.
MESSAGE |Row { row }, column { column }| TYPE 'I'.
ENDMETHOD.
ENDCLASS.

START-OF-SELECTION.
SELECT carrid, connid, fldate, price, currency FROM sflight
INTO TABLE @DATA(gt_flights).
TRY.
cl_salv_table=>factory( IMPORTING r_salv_table = DATA(lo_alv)
CHANGING  t_table      = gt_flights ).
lo_alv->get_functions( )->set_all( abap_true ).  " standard toolbar
lo_alv->get_columns( )->set_optimize( abap_true ).
lo_alv->get_columns( )->get_column( 'PRICE' )->set_medium_text( 'Ticket price' ).
lo_alv->get_display_settings( )->set_striped_pattern( abap_true ).
lo_alv->get_sorts( )->add_sort( columnname = 'CARRID' subtotal = abap_true ).
lo_alv->get_aggregations( )->add_aggregation( columnname = 'PRICE' ).  " total
lo_alv->get_layout( )->set_key( VALUE #( report = sy-repid ) ).        " user layouts
lo_alv->get_layout( )->set_save_restriction( if_salv_c_layout=>restrict_none ).
DATA(lo_events) = lo_alv->get_event( ).
SET HANDLER lcl_events=>on_double_click FOR lo_events.
lo_alv->display( ).
CATCH cx_salv_msg cx_salv_not_found cx_salv_existing cx_salv_data_error INTO DATA(lx).
MESSAGE lx TYPE 'E'.
ENDTRY.
  • Hotspot column: cast the column to CL_SALV_COLUMN_TABLE and call set_cell_type( if_salv_c_cell_type=>hotspot ); handle event link_click.
  • Inside a screen: factory( r_container = lo_container … ) instead of full screen.

9.4 CL_GUI_ALV_GRID – grid control in a container

The grid control needs a container – usually a custom control area on a dynpro (page 05), or a docking container. Use it when cells must be editable, or when you need several ALVs on one screen.

" PBO module of screen 0100 (custom control area 'CC_ALV' drawn in the screen painter)
MODULE status_0100 OUTPUT.
SET PF-STATUS 'S0100'.
IF go_grid IS NOT BOUND.
go_container = NEW cl_gui_custom_container( container_name = 'CC_ALV' ).
go_grid      = NEW cl_gui_alv_grid( i_parent = go_container ).
CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
EXPORTING i_structure_name = 'SFLIGHT'
CHANGING  ct_fieldcat      = gt_fcat.
gt_fcat[ fieldname = 'PRICE' ]-edit = abap_true.  " editable column
SET HANDLER go_handler->on_data_changed FOR go_grid.
go_grid->register_edit_event( cl_gui_alv_grid=>mc_evt_modified ).
go_grid->set_table_for_first_display(
EXPORTING is_layout       = VALUE lvc_s_layo( zebra = abap_true cwidth_opt = abap_true )
CHANGING  it_outtab       = gt_flights
it_fieldcatalog = gt_fcat ).
ELSE.
go_grid->refresh_table_display( ).
ENDIF.
ENDMODULE.

" PAI: copy the user's changes from the grid into gt_flights before saving
MODULE user_command_0100 INPUT.
go_grid->check_changed_data( ).
CASE ok_code.
WHEN 'SAVE'.  " validate + update the database
WHEN 'BACK'. LEAVE TO SCREEN 0.
ENDCASE.
ENDMODULE.
  • Useful events: double_click, hotspot_click, toolbar (add buttons), user_command, data_changed (validate edited cells). Handlers are methods of a local class registered with SET HANDLER.

9.5 ALV with IDA and Fiori

  • CL_SALV_GUI_TABLE_IDA displays a DB table or CDS view without reading it into an internal table – for millions of rows on HANA. Full explanation and code: ABAP on HANA › 04 ABAP SQL, ADBC & ALV IDA.
  • In S/4HANA / clean core: new list apps are Fiori elements list reports on CDS views and OData/RAP (ABAP on HANA › 05 CDS Views, RAP section). SAP GUI ALV remains fine for back-office reports; prefer CL_SALV_TABLE or IDA over REUSE FMs.

Part 10 – Background jobs

Long-running reports run as background jobs in a background work process – no screen, no user interaction, output goes to the spool.

Transaction / statement

Use

SM36

Define a job: name, steps (program + variant), start condition (immediately, date/time, after event, after job, periodic)

SM37

Monitor jobs: scheduled → released → ready → active → finished / cancelled; job log, spool

SP01

Spool requests (list output)

SY-BATCH

= 'X' when the program runs in background (skip dialogs, popups, GUI downloads)

JOB_OPEN / SUBMIT … VIA JOB / JOB_CLOSE

Schedule a job from ABAP code

DATA lv_jobname  TYPE btcjob VALUE 'ZR_FLIGHT_LIST_NIGHTLY'.
DATA lv_jobcount TYPE btcjobcnt.

CALL FUNCTION 'JOB_OPEN'
EXPORTING jobname  = lv_jobname
IMPORTING jobcount = lv_jobcount
EXCEPTIONS OTHERS  = 1.
IF sy-subrc = 0.
SUBMIT zr_flight_list
USING SELECTION-SET 'NIGHTLY'  " variant with the selection values
VIA JOB lv_jobname NUMBER lv_jobcount
AND RETURN.
CALL FUNCTION 'JOB_CLOSE'
EXPORTING jobcount  = lv_jobcount
jobname   = lv_jobname
strtimmed = abap_true  " start immediately
EXCEPTIONS OTHERS   = 1.
ENDIF.
  • Messages in background go to the job log; type E/A messages cancel the job (page 04).
  • Debugging a background job (JDBG, SM50): page 04 Modularization & Debugging.
  • In S/4HANA / clean core: SM36/SM37 still work on-premise; ABAP Cloud uses application jobs (Fiori app Application Jobs, job catalog entries and templates).

Part 11 – Obsolete statements: quick reference

You will read these in old code and should recognise them in interviews – but don't write them.

Obsolete

Use instead

DATA itab … WITH HEADER LINE, OCCURS n

Separate work area / field symbol; TYPE STANDARD TABLE OF … WITH EMPTY KEY

TABLES dbtab as work area

DATA ls TYPE dbtab (TABLES only for screen fields, sscrfields)

REFRESH itab

CLEAR itab

MOVE a TO b

b = a.

RANGES r FOR f

DATA r TYPE RANGE OF …

ON CHANGE OF … ENDON

AT NEW / AT END OF, LOOP AT … GROUP BY

DESCRIBE TABLE itab LINES n

n = lines( itab )

READ TABLE … WITH KEY everywhere

Table expressions itab[ … ], line_exists( ), sorted/hashed keys

SELECT … ENDSELECT with WRITE inside

SELECT … INTO TABLE @…, then process the table

AT PFnn

GUI status + AT USER-COMMAND

REUSE_ALV_* function modules

CL_SALV_TABLE, CL_GUI_ALV_GRID, ALV IDA

TYPE-POOLS slis.

Not needed since 7.02 – type groups load automatically

Logical databases, GET events

Explicit SELECTs / CDS views

Part 12 – Interview questions

What is the order of events in a report, and which one is the default?

LOAD-OF-PROGRAM → INITIALIZATION → AT SELECTION-SCREEN OUTPUT → (screen) → AT SELECTION-SCREEN ON … / AT SELECTION-SCREEN → START-OF-SELECTION → END-OF-SELECTION; TOP-OF-PAGE / END-OF-PAGE during list output; AT LINE-SELECTION / AT USER-COMMAND after the list is shown. The default event is START-OF-SELECTION.

What is the difference between INITIALIZATION and AT SELECTION-SCREEN OUTPUT?

INITIALIZATION runs once before the first display – set default values. AT SELECTION-SCREEN OUTPUT runs before every display (also after Enter or an error) – change screen attributes with LOOP AT SCREEN.

AT SELECTION-SCREEN vs AT SELECTION-SCREEN ON field?

Both validate input. After an E message in ON field only that field is ready for input; after an E message in AT SELECTION-SCREEN all fields are open again. ON BLOCK / ON RADIOBUTTON GROUP work the same per group.

PARAMETERS vs SELECT-OPTIONS? What is a range table?

PARAMETERS = one input field and variable. SELECT-OPTIONS = multiple values, intervals and exclusions; it creates a range table with SIGN, OPTION, LOW, HIGH, used with IN in SQL. An empty select-option selects everything. A range without screen field is TYPE RANGE OF (old: RANGES).

Standard, sorted and hashed tables – when do you use which?

Standard: index access, small tables, appending in order (linear key search). Sorted: always sorted by key, binary search, good for partial keys and LOOP … WHERE on the key. Hashed: unique key only, constant access time, best for big lookup tables read by the full key.

What is the difference between SY-TABIX and SY-INDEX?

SY-TABIX is the current row index of an internal table (LOOP AT, READ TABLE). SY-INDEX counts the passes of DO and WHILE loops.

What does COLLECT do? What is the default of SORT?

COLLECT inserts a row or, if a row with the same key exists, adds up its numeric fields. SORT without BY sorts ascending by the primary table key (standard key = all character-like fields); use SORT … BY and STABLE to be explicit.

What are the rules for FOR ALL ENTRIES?

Check the driver table is not empty (otherwise all rows are read), select the full key (duplicates are removed from the result), compare fields of the same type, and remove duplicate driver entries for speed. On HANA prefer a join or CDS view.

What are control break statements and what do you need to watch?

AT FIRST, AT NEW f, AT END OF f, AT LAST inside a LOOP. The table must be sorted by the control fields; AT NEW / AT END OF also react to changes in fields left of f; fields to the right are initial inside the block; SUM gives totals. ON CHANGE OF is obsolete and not a control level.

How do you pass data from the basic list to a secondary list?

HIDE stores field values per list line and restores them in AT LINE-SELECTION; GET CURSOR returns the clicked field and value; SY-LISEL holds the line text; SY-LSIND tells the list level (max 20).

ABAP memory vs SAP memory?

ABAP memory (EXPORT/IMPORT … MEMORY ID) is shared by the internal sessions of one call chain and holds any data incl. tables. SAP memory (SET/GET PARAMETER ID) is shared by all sessions of the user's logon, holds only flat character values and prefills screen fields.

Which ALV would you use today, and what is a field catalog?

CL_SALV_TABLE for read-only lists, CL_GUI_ALV_GRID (in a container) for editable grids, ALV with IDA for huge HANA tables; REUSE_ALV_* only in old code. The field catalog describes each column (name, heading, position, colour, totals, edit); it can be generated automatically, semi-automatically or built manually.

🏠 Start Here · ◀ 02 · Data Dictionary · 04 · Modularization & Debugging ▶ · Sections: CORE ABAP | OOPS ABAP | ABAP on HANA | Clean Core | RAP | ABAP Points | SAP Fiori | SAPUI5 | Mobile Development (MDK) | BTP Foundations | BTP Development | CAP | SAP Build | ABAP on BTP | Integration Suite | SAP Business AI | SAP BASIS | Security | SAP SDLC

Functional: FICO ABAP | TRM ABAP | VIM | SAP BIS | SD ABAP | MM ABAP | PP ABAP | QM ABAP | PM ABAP | PS ABAP | EWM | TM ABAP | EHS ABAP | HR ABAP | BW | SAP MDG | SAP Analytics Cloud | SAP Ariba | SAP CX | SAP IBP