Documente Academic
Documente Profesional
Documente Cultură
Overview
Logical databases
Events
Interactive reporting
User messages
ABAP/4 Query
SAP AG
Chapter 11 Objectives
SAP AG
Overview of Reporting
REPORT
QUERY
SAP AG
An ABAP/4 report is a program which reads data from the database, sorts the data according to certain
criteria and outputs the data in form of a list on the screen.
To generate a list, you can use create a query with ABAP/4 Query or write your own ABAP/4 report.
ABAP/4 Query is a user-friendly tool which allows you to define the layout of a list without any
programming knowledge.
When programming an ABAP/4 report, you can use all the facilities available in the programming
language to evaluate complex data.
Queries and reports both use logical databases to retrieve data.
Reading Data
ABAP/4 Dictionary
1 2
REPORT ... . logical database
TABLES: ... . TABLES: ... .
SELECT... . SELECT... .
SELECT ... . SELECT ... .
... .
processing
ENDSELECT.
ENDSELECT. ENDSELECT.
ENDSELECT.
REPORT REPORT
TABLES: TABLES:
GET GET
processing processing
GET
processing
SAP AG
SPFLI
REPORT SAPDBF1S
. DEFINING DATABASE F1S. Report RSBBB01B.
. ...
.
SELECT * FROM SPFLI... .
. .
. .
.
ENDSELECT. GET SPFLI.
... W rite: SPFLI-CARRID,
...
SAP AG
When you start a report which is assigned to a logical database, the ABAP/4 runtime system instructs
the logical database to evaluate the user’s selection criteria. The logical database reads a data record
and, in the appropriate GET event, makes the table entry read with SELECT available to the report.
The data record is processed in the GET event and control then returns to the logical database.
Events I
Events used with
logical databases
INITIALIZATION.
AT SELECTION-SCREEN O UTPUT.
OUTPUT.
AT SELECTION-SCREEN.
START-OF-SELECTION.
GET .... .
END-OF-SELECTION.
TOP-O F-PAGE.
TOP-OF-PAGE.
END-OF-PAGE.
SAP AG
ABAP/4 is an event-driven programming language. Reports which are linked to logical databases are
not processed sequentially. Besides the GET event, the report can use a number of other event key
words to perform processing. These events are triggered by the ABAP/4 processor which determines
the sequence of events. If processing is scheduled in the logical database for these events, it is
executed before the event in the report is triggered. The processing block defined for a event key word
is executed procedurally and concludes when the next event occurs.
The START-OF-SELECTION event is executed before the logical database starts reading the data.
This event is set by default.
Events II
Events used in
interactive reporting
AT LINE-SELECTION.
AT PFxx.
AT USER-COMM AND.
USER-COMMAND.
SAP AG
You can define interactive events in ABAP/4 reports. These events are triggered when the user presses
a particular function key or pushbutton. They allow for the creation of secondary lists which display
detailed information.
Interactive Reporting: Overview
Secondary Windows
lists
Interactive
Reporting
SAP AG
Interactive reporting allows you to create secondary lists and windows. To call these and display them
on the screen, you use function keys. You can thus distribute all the information returned by the report
across several screens, gradually outputting more and more detailed information.
Using function keys, the user can also branch to:
a transaction
another report
Line Selection I
REPORT RSAAA11A.
Basic list
TABLES: SPFLI. CAR ID from to departure
SELECT-OPTIONS: SCARRID ... . LH 0400 Frankfurt New York 10:10:00
LH 0402 Frankfurt New York 13:30:00
START-OF-SELECTION. ...
SELECT * FROM SPFLI LH 3577 Rome Frankfurt 07:05:00
WHERE ... .
WRITE: /SPFLI-CARRID,
SPFLI-CONNID ... .
HIDE: SPFLI-CARRID, SPFLI-CONNID. Secondary list
ENDSELECT.
SAP AG
To enable the user to choose a line in a list and display detailed information for this line in a
secondary list, you can use the AT LINE-SELECTION event.
This event is processed when the user selects a valid line in the list with the cursor and activates the
function key assigned to the PICK function in the interface definition. If there is no interface defined,
the event is triggered by pressing F2 or by double-clicking.
The HIDE Area
HIDE <field>.
HIDE area
Carr. ID From To Depart
LH 0400 Frankfurt New York 10:10:00 Line SPFLI-CARRID SPFLI-CONNID
LH 0402 Frankfurt New York 13:30:00
... 1 LH 0400
LH 3577 Rom e Frankfurt 07:05:00
2 LH 0402
...
11 LH 3577
Choose
REPORT RSAAA11A
...
START-OF-SELECTION.
SELECT * FROM SPFLI WHERE ... .
WRITE: SPFLI-CARRID, SPFLI-CONNID, ... .
HIDE: SPFLI-CARRID, SPFLI-CONNID.
ENDSELECT.
SAP AG
By default, the data of the basic list is not available when you are in the secondary list.
However, the HIDE statement allows you to store field contents for a particular list line in a special
area. For each field, the system stores the field name and the value.
The HIDE command must immediately follow the WRITE statement since the information is stored
for each output line. You can also use the HIDE area to store fields which do not appear in the list.
Line Selection II
Hide area
REPORT RSAAA11A.
AT LINE-SELECTION.
WRITE: TEXT-001, SPFLI-CARRID,
SPFLI-CONNID, TEXT-002.
SAP AG
As soon as the user selects a line by double-clicking or positioning the cursor, and triggers an
interactive event (in this case AT LINE-SELECTION) by pressing a function key or pushbutton, the
system passes the values stored for this line in the HIDE area to the corresponding work area.
The contents of the selected line are also stored in the system field SY-LISEL.
Valid Line Selection
header lines Hide area
"SPFLI-CARRID" LH
"SPFLI-CONNID" 0400
"SPFLI-CARRID" LH
footer lines "SPFLI-CONNID" 3577
REPORT RSAAA11A.
START-OF-SELECTION.
SELECT * FROM SPFLI WHERE ... .
WRITE: SPFLI-CARRID, SPFLI-CONNID, ... .
HIDE: SPFLI-CARRID, SPFLI-CONNID.
ENDSELECT.
END-OF-SELECTION.
CLEAR SPFLI-CARRID.
AT LINE-SELECTION.
CHECK NOT SPFLI-CARRID IS INITIAL.
...
CLEAR SPFLI-CARRID.
SAP AG
It is up to you to program that the system does not generate a secondary list at invalid line selection.
There are several possibilities to recognize invalid line selection from the program.
In above programming example, each field whose contents is stored in the HIDE area is set to the
initial value. If the user selects an invalid line, the system does not find a corresponding value in the
HIDE area. With a negative result of the CHECK statement, the current processing block is
terminated. The system does not generate a secondary list.
User Messages: Overview
Table T100
S ID No. Message text
SAP AG
If the user has entered inconsistent values or has selected values without having the appropriate
authorization, you output a dialog message with the key word MESSAGE.
Dialog messages are stored in table T100. They are classified by language, two-character ID and three-
character name.
Messages can contain up to four variables (&1, &2, &3 and &4). If you want to output & in a message
it does not represent a variable, you must enter it twice. For example: '
This is a message with an &&'
.
In the long text of the message, you can use &v1&, &v2&, &v3& and &v4& instead of the
corresponding variables.
You can create your own messages using an ID which starts either with Y (head office) or Z (branch).
Syntax of the MESSAGE Statement
.
.
.
Annn
Xnnn
MESSAGE Ennn WITH <field1> <field2> <field3> <field4>.
W nnn
Innn
Snnn
SAP AG
You output messages with the MESSAGE statement. Here, the language used for table T100 is the
logon language. You specifiy the message ID after the MESSAGE-ID parameter of the REPORT
statement. This message ID applies to the entire report. You specify the message number in the
MESSAGE statement.
Immediately before the three-digit number, you specify the message type which determines how the
user is meant to react to the message (see next page).
After the WITH parameter, you enter the values for the variables (up to four). You can also specify
fields or literals here. The i-th field replaces the variable &i in the message. If the variables in the
message are only represented by & or $, these placeholders are supplied with the values of the fields in
the MESSAGE statement according to their position.
Unlike the message ID in the REPORT statement, you can enter a message ID in the MESSAGE
statement yourself by specifying the ID immediately after the message number in parentheses.
However, this ID applies only to the current message. For example: MESSAGE E004(UD).
If you want to send a dynamic message, you can use the following syntax:
MESSAGE ID <mid> TYPE <mtype> NUMBER <mno.> WITH <field1> <field2> <field3>
<field4>.
The system fields SY-MSGID, SY-MSGTY and SY-MSGNO contain the message ID, the message
type and the message number respectively, while the system fields SY-MSGV1 through SY-MSGV4
contain the fields for the placeholders.
Classification of Dialog Messages
Abend Error W arning Inform ation Success
A message
E message W m es sage I message
X message
SAP AG
AT SELECTION-SCREEN.
AUTHORITY-CHECK OBJEKT 'S_CARRID'
ID 'CARRID' FIELD P_CARRID
ID 'ACTVT' FIELD '03'.
IF SY-SUBRC NE 0.
MESSAGE E045 WITH P_CARRID.
ENDIF.
START-OF-SELECTION.
SELECT * FROM SPFLI WHERE CARRID = P_CARRID.
...
ENDSELECT.
SAP AG
If the user specifies an airline carrier as a parameter, an authorization check is performed in the event
AT SELECTION-SCREEN (in contrast to Chapter 9). As a result, the input has to be corrected before
the reports starts the data selection process.
Advantages:
There is no negative authorization check for any the records read from the database.
Authorization checks only have to be performed once for each airline carrier.
Users learn whether or not they are authorized at the selection stage.
Conventional Reporting vs. ABAP/4 Query
Logical database list
e.g. F1S
Report
(ABAP/4)
Reporting
ABAP/4 Query
report
report generator
generator
functional
functional area
area
list
list definition
definition
(ABAP/4
(ABAP/4 Query)
Query)
Creating
Creating lists
lists with
with
Report:
Report: ABAP/4
ABAP/4 statements
statements
ABAP/4
ABAP/4 Query: Description
Query: Description of
of desired
desired result
result
SAP AG
When you create a list with a report, the data is usually retrieved via a logical database, processed by
the report and then output as a list.
When you create a query, you first assign a functional area which is basically a special view of a
logical database. You choose the fields you require from this functional area and define the formatting
and type of processing.
When the query is started, an internal report generator creates a report in accordance with the list
definition and then reads, processes and outputs the data.
ABAP/4 Query
Functional areas
User groups
Choose logical database
Query
Define lists
Basic list
Statistic
Ranked list
Start queries
SAP AG
ABAP/4 Query allows you to generate non-standard ABAP/4 reports in R/3. It is primarily intended
for users with no programming knowledge in ABAP/4.
The queries are assigned to a user group. Any user belonging to this user group can access these
queries.
A functional area can be assigned to several user groups.
Several functional areas can be assigned to one user group.
The queries of a user group are shared by all the users in that user group.
A query is always created with reference to a particular functional area. This functional area must be
assigned to the user group.
In general, you can access all the queries assigned to your user group.
Chapter 11 Summary
SAP AG
Exercises Chapter 11: Reporting
Task:
Create a list of all flight connections for each airline carrier.
Output the following fields:
SPFLI-CARRID, SPFLI-CONNID, SPFLI-CITYFROM,
SPFLI-CITYTO, SPFLI-DEPTIME, SPFLI-ARRTIME.
Define a selection screen on which the user can enter
selections for the airline carrier (SPFLI-CARRID) and the
connection ID (SPFLI-CONNID). Read the data from table
SPFLI in accordance with this selection.
When the user selects a line, the system should display a
secondary showing the flights (table SFLIGHT) available for
the flight connection concerned (see example list). Output the
selected line as the header of the secondary list. Calculate and
output the number of vacant seats for each flight. Make sure
that the program can handle invalid line selection.
a) Example list
Task:
Copy your solution to Chapter 11, Exercise 1 or the example
solution and output an error message when no data is found
for the specified selection values.
Hint:
Read the table SPFLI in the event AT SELECTION-SCREEN
and store the records in an internal table to avoid repeated
database accesses.
Use message number 037 from the AT work area.
Solutions Chapter 11: Reporting
1. REPORT RSAAA111.
START-OF-SELECTION.
WRITE: / SPFLI-CARRID,
SPFLI-CONNID,
SPFLI-CITYFROM,
SPFLI-CITYTO,
SPFLI-DEPTIME,
SPFLI-ARRTIME.
HIDE: SPFLI-CARRID, SPFLI-CONNID.
ENDSELECT.
END-OF-SELECTION.
AT LINE-SELECTION.
WRITE SY-LISEL.
* D: TEXT-001: Date
* D: TEXT-002: Price
* D: TEXT-003: Seats
* D: TEXT-004: maximum
* Read data for secondary list using hidden key fields and output
* list
WRITE: / 5 SFLIGHT-FLDATE,
SFLIGHT-PRICE,
SFLIGHT-CURRENCY.
WRITE: SFLIGHT-SEATSMAX,
SFLIGHT-SEATSOCC,
SFREE.
ENDSELECT.
AT SELECTION-SCREEN
TABLES
SELTAB_CARRID = SELCARR.
* Read data corresponding to selection criteria
IF SY-SUBRC NE 0.
MESSAGE E037.
ENDIF.
START-OF-SELECTION.
LOOP AT TAB_FLI.
WRITE: / TAB_FLI-CARRID,
TAB_FLI-CONNID.
WRITE: TAB_FLI-CITYFROM,
TAB_FLI-CITYTO,
TAB_FLI-DEPTIME,
TAB_FLI-ARRTIME.
ENDLOOP.
END-OF-SELECTION.
SET PF-STATUS ´ ´.
* D: text-001 Date
* D: text-002 Price
* D: text-003 Seats
* D: text-004 max.
* D: TEXT-005 OCCUPIED
* D: text-006 free
ULINE.
* Read data for seocdary list using hidden key fields and output
* list
WRITE: /5 SFLIGHT-FLDATE,
SFLIGHT-PRICE,
SFIGHT-CURRENCY.
WRITE: SFLIGHT-SEATSMAX,
SFLIGHT-SEATSOCC,
SFREE.
ENSELECT.