Вы находитесь на странице: 1из 6

ABAP Classical Reports

SAP ABAP Classical Reports


ABAP supports two types of Programs - Report Programs & Dialog Programs. Report Programs are used
when large amounts of data needs to be displayed. A report is a presentation of data in an organized
structure.

SAP ABAP is an event driven programming language, ABAP programs executed based on events not line-
by-line. They are used when data from a number of tables have to be selected and processed before
presenting.

Important Points to Note about Report Program


 Report Programs attribute type are always Executable Programs. Program Type is always 1.

 The first line of a report program is always Report <report-name>.

 The line size for a particular report can be set by using the addition line-size <size>.

 The line count for a particular page can be set by using the addition line-count n (n1). N is the
number of lines for the page and N1 is the number of lines reserved for the page footer. Where
(Line Count 10 (2)) 10-2 = 8 Line for the page and 2 lines reserved for the page footer.

 To display any information or error message we add a message class to the program using the
addition: Message-id <message class name>. Message classes are maintained in SE91.

Ideal Report Program Should Start With:


Report <report name> no standard page heading

line-size <size>

line-count <n(n1)>

Message-id <message class>.

Example:
Report <ZEMPLOYEEINFO> no standard page heading

line-size <50>

line-count 15(2)

E001 (ZMESSAGE).

NITIN JADHAV 1
ABAP Classical Reports
2

Parameters:
Parameters is used to take input from end user or user.

Parameters help one to do dynamic selection. They can accommodate only one value for one cycle of
execution of the program.

Syntax: - Defining parameters as a data type.

Parameters: Name type char (10). It accepts 10 input characters.

Parameters can be Checkboxes as well as Radio buttons:

Parameters: p_id as checkbox.


Parameters: p_id1 radiobutton group <group name>.
Parameters: p_id2 radiobutton group <group name>.
EXAMPLE:

Parameters: SUBMIT as checkbox.


Parameters: ADD radiobutton group B1.
Parameters: SUB radiobutton group B1.

Parameters can be list box.

Parameter p_id like <table name>-<field name> as listbox


Example: Eployee ID like <Zempinfo>-<empid> as listbox.

Select Options:
A Select-Option is used to input a range of values or a set of values to a program. Select options is used
to take input from end user or user in range. Like 10 To 20.

Select-options: SMATNR for MARA-MATNR.

Events in Classical Reports


1 Load-of-program:

This event is used to load program into memory for execution and this is the first event in execution
sequence.
Triggered before displaying the selection screen.

NITIN JADHAV 2
ABAP Classical Reports
3

2 Initialization:

This event is used to initialize variables, screen default values and other default actions.
This event is executed before the selection screen is displayed.
Initialization of all the values.
You can assign different values other than the values defaulted on the selection screen.
You can fill your selection screen with some values at runtime.
After the ABAP selection screen code has been processed (i.e. parameters, select-options etc.) but
before these are displayed to the user. So you can use it to initialize input fields of the selection
screen or change the default values of these before the user gets to enter data into them.
Example:
INITIALIZATION.
CITY_FR = 'NEW YORK'.
CITY_TO = 'FRANKFURT'.
CARRID-SIGN = 'I'.
CARRID-OPTION = 'EQ'.
CARRID-LOW = 'AA'.
APPEND CARRID.
DATUM+6(2) = '01'.
3 At Selection-Screen output:

By using this event we can manipulate dynamic selection-screen changes.


TABLES: zemp_mstr.
DATA: ls_mstr TYPE zemp_mstr.
SELECTION-SCREEN: BEGIN OF BLOCK b1.
PARAMETERS: p_eid TYPE zemp_i.
SELECTION-SCREEN: END OF BLOCK b1.
SELECTION-SCREEN: BEGIN OF BLOCK b2.
PARAMETERS: p_ename TYPE zemp_n MODIF ID m1.
PARAMETERS: p_des TYPE zemp_d MODIF ID m1.
SELECTION-SCREEN: END OF BLOCK b2.
AT SELECTION-SCREEN OUTPUT.
LOOP AT SCREEN.
IF p_eid IS NOT INITIAL.
IF screen-group1 = 'M1'.
screen-active = 1.
screen-input = 0. "for input disable
CLEAR: ls_mstr.
SELECT SINGLE * FROM zemp_mstr INTO ls_mstr WHERE emp_id = p_eid.
p_ename = ls_mstr-emp_name.
p_des = ls_mstr-designation.
CLEAR: ls_mstr.
MODIFY SCREEN.
ENDIF.
ELSE.
IF screen-group1 = 'M1'.
screen-active = 0.
MODIFY SCREEN.

NITIN JADHAV 3
ABAP Classical Reports
4

ENDIF.
ENDIF.
ENDLOOP.
Triggered after processing of the user input on the selection screen. This event verifies the user input
prior to the execution of a program. After processing the user input, the selection screen remains in
the active mode.

4 At Selection-Screen on field:

This event is used to validate a single selection-screen input parameter.


Syntax: AT SELECTION-SCREEN ON <parameter name>. "Validate a input parameter
Example:
Parameters: Name type char (10).
Parameters: Number type char (10).
At Selection-screen on Name.
Message: ‘Please enter name’ type ‘E’. “ Where E is error message type.
At Selection-screen on Number.
Message: ‘Please enter Number’ type ‘E’.

5 At Selection-Screen:

This event is used to validate multiple input fields.


Syntax: AT SELECTION-SCREEN. "used to validate multiple input fields
Triggered after processing of the user input on the selection screen. This event verifies the user input
prior to the execution of a program. After processing the user input, the selection screen remains in
the active mode.
Example:
Parameters: Name type char (10).
Parameters: Number type char (10).
At Selection-screen.
If name is initial.
Message: ‘please enter name’ type ‘w’.
Endif.
If Number is initial.
Message: ‘please enter number’ type ‘w’.
Endif.

6 Start-of-Selection.

Here the program starts selecting values from tables.


This is default event which is used to write actual business logic.
Syntax: START-OF-SELECTION. "Default event
Triggered only after the processing of the selection screen is over; that is, when the user clicks the
Execute icon on the selection screen.

NITIN JADHAV 4
ABAP Classical Reports
5

7 End-of-Selection:

We can use this event just to state that start-of-selection is ended, this event is used with logical
databases, and logical databases are in HR ABAP only. In normal ABAP we don`t have much
importance.
Syntax: END-OF-SELECTION.
Triggered after the last statement in the START-OF-SELECTON event is executed.
After all the data has been selected this event writes the data to the screen.

8 TOP-OF-PAGE:

This event prints constant heading for all pages.


Syntax: TOP-OF-PAGE."Page heading
Note: - Triggered by the first WRITE statement to display the data on a new page.
Example:
Top-of-page.
Write : / ‘This is my first classical ’.

9 End-of-Page:

This event prints constant footer for all pages.


Syntax: END-OF-PAGE. "Page footer.
Triggered to display the text at the end of a page in a report.
Note: - This event is the last event while creating a report, and should be combined with the LINE-
COUNT clause of the REPORT statement.
Before using this event, we need to reserve some lines for displaying footer.
Example: -
END-OF-PAGE.
Write: ‘This report is generated on ’,sy-datum. “ Sy-datum is system variable use to print date.

Example:

*&---------------------------------------------------------------------*
*& Report ZCLASSICAL
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT ZCLASSICAL.

TABLES: MARA. “ Table Name

SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001.


PARAMETERS: S_MTART TYPE MARA-MTART. “take the input from end User
material type(FERT)

NITIN JADHAV 5
ABAP Classical Reports
6

SELECTION-SCREEN END OF BLOCK B1.


TYPES: BEGIN OF TY_MARA, “ Structure
MATNR TYPE MARA-MATNR, “ Material Number.
MTART TYPE MARA-MTART, “ Material Type.
MATKL TYPE MARA-MATKL, “ Material Group.
END OF TY_MARA.
DATA: IT_MARA TYPE TABLE OF TY_MARA. “Internal table of MARA Table.
DATA: WA_MARA TYPE TY_MARA. “Work-area of MARA Table.

START-OF-SELECTION.
SELECT MATNR MTART MATKL FROM MARA INTO TABLE IT_MARA WHERE
MTART = S_MTART. “Fetch data from MARA table into Internal table.

LOOP AT IT_MARA INTO WA_MARA. “Movie data from Internal table to Work-area.
WRITE: / WA_MARA-MATNR, WA_MARA-MTART, WA_MARA-MATKL. “ print data
ENDLOOP.

NITIN JADHAV 6

Вам также может понравиться