SAP examples · LessonReviewed by Ravi M, SAP Trainer, 10 yrs · Updated · Published · SAP S/4HANA 2023 · all levels
SAP ABAP examples
These ABAP examples show the everyday patterns, a report, a class, database access and an ALV grid, that make up most custom SAP development, with commentary on doing them well.
Quick answer
Two runnable ABAP examples: a report that selects purchase order items from EKPO into an internal table and displays them with the SALV ALV class, and a FOR ALL ENTRIES select that reads material texts from MAKT once instead of inside a loop. They show the habits that matter: ALV for output, selective WHERE clauses, working in memory.
Key takeaways
- Watch out: SELECT in a loop, the classic performance killer.
- Worked examples: a simple report with alv, efficient database access, what the examples teach.
- How ABAP examples fits into SAP development and the wider SAP landscape
A simple report with ALV
REPORT z_open_pos.
SELECT ebeln, ebelp, matnr, menge FROM ekpo
INTO TABLE @DATA(lt_items) UP TO 100 ROWS.
cl_salv_table=>factory( IMPORTING r_salv_table = DATA(lo_alv)
CHANGING t_table = lt_items ).
lo_alv->display( ).Efficient database access
" read once into a table, then work in memory (never SELECT in a loop)
SELECT matnr, maktx FROM makt
FOR ALL ENTRIES IN @lt_items WHERE matnr = @lt_items-matnr
INTO TABLE @DATA(lt_texts).What the examples teach
These embody the core habits: use ALV for output, select only needed data with a WHERE, read into internal tables rather than looping the database, and write clear, typed code. Adapt them into your own reports and classes.
Common pitfalls
- SELECT in a loop, the classic performance killer.
- Hand-coded output instead of ALV.
- Untyped, unclear code.