Tuesday, June 24, 2025

🧾 SAP ABAP Reports – A Quick Guide

What is a Report in SAP ABAP?

report is an executable ABAP program used to read, process, and output data from SAP database tables using Open SQL.

Common Use Cases:

  • Generating invoices using data from billing tables (e.g., VBRK, VBRP)
  • Listing sales/purchase orders from tables like VBAK, EKPO
  • Tracking deliveries using documents (LIKP, LIPS)
  • Displaying master data such as:
    • Materials (MARA)
    • Vendors (LFA1)
    • Customers (KNA1)

In short: A report is an executable ABAP program that fetches data using Open SQL, processes it via loops/internal tables, and outputs the result using text output or ALV grids.

 

Types of Reports in SAP ABAP

Report Type

Description

Output Style

Interaction Level

Best For

Classical Report

Line-by-line output using WRITE statements

Text List

None

Simple, quick data display

Interactive Report

Allows drill-down into detailed data

Text List + Events

Medium

Master-detail navigation

ALV Report

Rich output with sorting/filtering/export

Grid/List/Table

High

Business-critical reports

Modern (Fiori/CDS)

Browser/mobile-based UI using CDS/OData

Web/Mobile UI

Very High

Real-time analytics and Fiori apps


1. Classical Report

  • Oldest form, uses WRITE statements.
  • Best used for: quick internal testing or non-formatted outputs.

 

2. Interactive Report

  • Enables user interaction like clicking a line to see more details.
  • Uses events like AT LINE-SELECTION.
  • Best used for: hierarchical views like Customer → Orders.

 

3. ALV Report (ABAP List Viewer)

  • Most popular in real-time projects.
  • Offers sorting, filtering, Excel export, layout saving.
  • Uses: REUSE_ALV_GRID_DISPLAY, CL_GUI_ALV_GRID, CL_SALV_TABLE.
  • Best used for: all major business reports.

 

4. Modern Reports (Fiori, WebDynpro, CDS)

  • Based on SAPUI5/Fiori/WebDynpro.
  • Backend: CDS Views + OData + Annotations.
  • Best used for: role-based apps and mobile/web dashboards.

 

Comparison of Report Types

Feature

Classical

Interactive

ALV

Modern (UI)

Drill-down

Export to Excel

Filter/Sort Columns

Modern UI

Layout Save

Ease of Development

Medium

Complex

Usage in Real Projects

Rare

Rare

Increasing

Conclusion: ALV Reports are the most used and practical in real-time and interview scenarios.

 

Events in ABAP Reports

Events are predefined execution blocks triggered automatically by SAP during report runtime.

Common Events Table:

Event

When It Runs

Purpose

INITIALIZATION

Before selection screen

Set default values

AT SELECTION-SCREEN

After user input

Input validation

START-OF-SELECTION

After validation

Core processing and data retrieval

END-OF-SELECTION

After processing

Display results (in classical reports)

TOP-OF-PAGE

On first output page

Show headers/titles

AT LINE-SELECTION

On line click (interactive)

Drill-down into detailed data

AT USER-COMMAND

On user button/action

Handle custom actions (e.g., ALV buttons)

AT NEW / AT END OF

During loop processing

Group-wise subtotal/headers

 

Simple Report Flow Example:

  1. INITIALIZATION – Set default selection values (e.g., customer = 1000)
  2. AT SELECTION-SCREEN – Validate inputs
  3. START-OF-SELECTION – Fetch data from tables
  4. GET <table> – Row-level processing
  5. END-OF-SELECTION – Show results
  6. TOP-OF-PAGE / END-OF-PAGE – Page titles/footers
  7. AT LINE-SELECTION – Line click for detail view
  8. AT USER-COMMAND – Button event handling

 

System Fields in SAP ABAP

System fields are predefined variables prefixed with SY- that provide system state details.

Common System Fields:

Field

Description

Example

SY-DATUM

Current date

20250503

SY-UZEIT

Current time

134510

SY-UNAME

Logged-in user

SAPUSER1

SY-SUBRC

Return code of last operation (0 = success)

0, 4, 8

SY-TCODE

Transaction code

SE38, ME21N

SY-REPID

Current program name

ZMY_REPORT

SY-TABIX

Current internal table index

1, 2...

SY-UCOMM

Function code (button action)

'BACK', 'SAVE'

SY-MSGID/NO

Last message ID and number

Z1, 101

SY-MSGTY

Message type

S (Success)

Example Code Using System Fields:

WRITE: / 'Date: ', sy-datum,

       / 'Time: ', sy-uzeit,

       / 'User: ', sy-uname.

SELECT SINGLE * FROM mara INTO wa_mara WHERE matnr = '1000'.

 IF sy-subrc = 0.

  WRITE: 'Material Found'.

ELSE.

  WRITE: 'Material Not Found'.

ENDIF.

Why System Fields Matter

1. Debugging & Troubleshooting

  • SY-SUBRC shows operation result (success/failure).
  • SY-UNAME helps track user-specific errors.

2. Flow Control

  • SY-UCOMM supports button handling.
  • SY-TCODE allows reuse in multiple transactions.

3. Personalization

  • SY-LANGU, SY-ZONLO support user-specific behavior.

4. Interactivity

  • SY-LISEL, SY-CUROW, SY-CUCOL enable interactive reports.

No comments:

Post a Comment