Classical Report

There are multiple types of reports in SAP ABAP language like Classical Report, Interactive Report and ALV Report. In this article, we will be knowing about Classical Report.

Classical Report

Classical Reports are used in scenario where you want to display the entire output in a single list called basic list. There are multiple events used in Classical Report -

1) INITIALIZATION.

This is the first event to trigger in ABAP report. This allows the user to maintain default values in the selection-screen.

Syntax:

INITIALIZATION.

2) AT SELECTION-SCREEN.

This event works only if you have added selection-screen in your program. It triggers once the selection-screen is displayed and used for validation for the pre-defined values in the selection-screen.

Syntax :

AT SELECTION-SCREEN ON <FIELDNAME>.

3) START-OF-SELECTION.

This event is default in any ABAP program. But if you have used INITIALIZATION and AT SELECTION-SCREEN in your program you need to declared it manually. This event is used to extract data from the database and thus is an important event.

START-OF-SELECTION.

4) END-OF-SELECTION.

This event triggers after the data is being is extracted and after that the first record in the output list is displayed.

Syntax :

END-OF-SELECTION.

5) TOP-OF-PAGE.

This event helps in giving heading to the report.

Syntax :

TOP-OF-PAGE.

6) END-OF-PAGE.

This event helps in maintaining the footer.

Syntax :

END-OF-PAGE.

To understand more about classical report let's take a requirement and display the output.

REQUIREMENT: From the LFA1 table, display the fields - LIFNR, NAME1, ORT01 and PSTLZ.

Every report in SAP ABAP start with REPORT keyword. Here YCLASSICAL_LFA1 is the name of the program.

REPORT YCLASSICAL_LFA1 NO STANDARD PAGE HEADING.

Name of the table or tables you want in the program.

TABLES: LFA1.


Select-Options is used to define a range.
L_LIFNR is the variable to store the range.

SELECTION-SCREEN: BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-000.
SELECT-OPTIONS: L_LIFNR FOR LFA1-LIFNR.
SELECTION-SCREEN: END OF BLOCK B1.

Creating structure for LFA1 table with the name TY_STR.

TYPES: BEGIN OF TY_STR,
       LIFNR TYPE LIFNR,
       NAME1 TYPE NAME1_GP,
       ORT01 TYPE ORT01_GP,
       PSTLZ TYPE PSTLZ,
END OF TY_STR.

Creating Internal Table with name "IT" and Work Area with "WA".

DATA: IT TYPE TABLE OF TY_STR,
      WA TYPE          TY_STR.

Performing Initialization.

INITIALIZATION.
L_LIFNR-SIGN = 'I'.
L_LIFNR-OPTION = 'BT'.
L_LIFNR-LOW = '1000'.
L_LIFNR-HIGH = '3000'.
APPEND L_LIFNR.

At selection-screen for Validation.

AT SELECTION-SCREEN ON L_LIFNR.
IF L_LIFNR-LOW = ' ' OR L_LIFNR-HIGH = ' '.
MESSAGE TEXT-111 TYPE 'E'.
ENDIF.

To get data from the database.

START-OF-SELECTION.


SELECT LIFNR NAME1 ORT01 PSTLZ
FROM LFA1 INTO TABLE IT
WHERE LIFNR IN L_LIFNR.

END-OF-SELECTION.

Displaying the data.

WRITE:/ 'LIFNR' COLOR 5, 10 'NAME1' COLOR 5, 40 'ORT01' COLOR 5, 60 'PSTLZ' COLOR 5.
ULINE.

LOOP AT IT INTO WA.
WRITE:/ WA-LIFNR,
10 WA-NAME1,
40 WA-ORT01,
60 WA-PSTLZ.
ENDLOOP.

 To give the heading at the top of page.

TOP-OF-PAGE.
WRITE:/20 'CLASSICAL REPORT - LFA1 TABLE' COLOR 4.
ULINE.
END-OF-PAGE.

The whole program should look like the following-



REPORT YCLASSICAL_LFA1 NO STANDARD PAGE HEADING.

TABLES: LFA1.

SELECTION-SCREEN: BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-000.
SELECT-OPTIONS: L_LIFNR FOR LFA1-LIFNR.
SELECTION-SCREEN: END OF BLOCK B1.

TYPES: BEGIN OF TY_STR,
       LIFNR TYPE LIFNR,
       NAME1 TYPE NAME1_GP,
       ORT01 TYPE ORT01_GP,
       PSTLZ TYPE PSTLZ,
END OF TY_STR.

DATA: IT TYPE TABLE OF TY_STR,
       WA TYPE          TY_STR.

INITIALIZATION.
L_LIFNR-SIGN = 'I'.
L_LIFNR-OPTION = 'BT'.
L_LIFNR-LOW = '1000'.
L_LIFNR-HIGH = '3000'.
APPEND L_LIFNR.

AT SELECTION-SCREEN ON L_LIFNR.
IF L_LIFNR-LOW = ' ' OR L_LIFNR-HIGH = ' '.
MESSAGE TEXT-111 TYPE 'E'.
ENDIF.

START-OF-SELECTION.
SELECT LIFNR NAME1 ORT01 PSTLZ
FROM LFA1 INTO TABLE IT
WHERE LIFNR IN L_LIFNR.
END-OF-SELECTION.

WRITE:/ 'LIFNR' COLOR 5, 
10  'NAME1' COLOR 5, 
40  'ORT01' COLOR 5, 
60  'PSTLZ' COLOR 5.
ULINE.


LOOP AT IT INTO WA.

WRITE:/ WA-LIFNR,
10  WA-NAME1,
40  WA-ORT01,
60  WA-PSTLZ.


ENDLOOP.

TOP-OF-PAGE.


WRITE:/20 'CLASSICAL REPORT - LFA1 TABLE' COLOR 4.
ULINE.


END-OF-PAGE.

The output will be as follows-

Fig1. Selection-Screen



Fig2. Output

Follow this blog for more such posts.

Comments