Simple Reports
ABAP Training Reports 2
What Is a Report
Task of a report
Evaluate and display data from the database
React to events by
key links)
Database accesses
Purpose of Report
Structure of Report
Internal control
Branching (IF, CASE)
External control
Events
Runtime events
User events
processing block
internal control
…...
ABAP Training Reports 10
If IF statements can be
IF logexpr1.
nested to any level.
Processing1.
ELSEIF logexpr2.
All IF statements must
Processing2. be terminated with
… ENDIF in the same
Else. processing block.
processingN.
ENDIF.
ABAP Training Reports 11
Iteration
Do … ENDDO.
Loop … ENDLOOP.
While … ENDWHILE.
Select … ENDSELECT.
Do ... Enddo
Variations
Do ... ENDDO.
Additions
VARYING f FROM f1 NEXT f2.
Do ... Enddo
Sum = 0.
Do
Sum = 0.
Sum = sum + sy-index.
Do 10 times
Counter = counter + 1.
Sum = sum + sy-index.
Write sum.
Write sum.
If counter > 10.
Enddo.
Exit.
endif.
Enddo.
ABAP Training Reports 15
Exit
Always leaves the current unit and the program continues after that
unit
Context sensitive
Only leaves inner structure if structures are nested
Can be used in
Unconditional loops (DO...Enddo)
Subroutine (FORM...ENDFORM)
Function (FUNCTION...ENDFUNCTION)
Stop
Cancels all data selection
No further tables are read
Followed immediately by the END-OF-SELECTION event
IF logexp.
Stop.
ENDIF.
ABAP Training Reports 17
Reject
Used in logical database processing
Stops processing the current database table line and resumes with the
next line of the table on the same hierarchy level
IF logexp.
Reject.
ENDIF.
ABAP Training Reports 18
Continue
IF logexp.
Continue.
ENDIF.
ABAP Training Reports 19
Check
CHECK logexp
Evaluates the subsequent logical expression
Expression is true
Expression is false
Terminates the current loop pass and goes back to the start
While … Endwhile
Variations
WHILE logexp ... ENDWHILE.
Additions
VARYING f FROM f1 NEXT f2.
Select … ENDSELECT
To n2
Where logexp
ABAP Training Reports 23
processor)
Calls these modules
Controls the external program flow
Events
INITIALIZATION
AT SELECTION-SCREEN OUTPUT
AT SELECTION-SCREEN
TOP-OF-PAGE
END-OF-PAGE
START-OF-SELECTION
GET Events
END-OF-SELECTION
} TOP-OF-PAGE DURING
LINE-SELECTION
AT LINE-SELECTION
AT USER-COMMAND
Interactive Events
} AT PF<nn>
ABAP Training Reports 25
Runtime events
Selection screen events
Initialization
At selection-screen
Start-of-selection
End-of-selection
ABAP Training Reports 26
Run-Time Events
Initialization
Processed before the presentation of the selection screen
Run-Time Events
At selection-screen
Processing block is started after the user has specified all
the system displays the selection screen again and all input
fields can be changed
ABAP Training Reports 29
Run-Time Events
Start-of-selection
Processing block that is executed after processing the
Run-Time Events
End-of-selection
Processing block executed after the system has read and
Top Of Page
Under this event we can code the header of the page which is to be printed
on every page of the report.
The TOP-OF-PAGE event occurs as soon as the system starts processing a
new page of a list. The system processes the statements following TOP-
OF-PAGE before outputting the first line on a new page
ABAP Training Reports 32
End Of Page
Report Statement
REPORT keyword is used along with the name of the report as the
starting line of the report to introduce the program as a report the SAP
system.
Some additions which are used with this statement. Are as follows -:
NO STANDARD PAGE HEADING – this will suppress the page heading
which is taken as a default heading by SAP.
LINE-COUNT – to determine the page length of an output list.
REPORT <rep> LINE-COUNT <len>[(<n>)].
ABAP Training Reports 37
Report Statement
SELECT Overview
SELECT Clause
Select *
SELECT <f1> <f2> ... <fn>
• SELECT *
• returns all columns of the database table
• SELECT <f1> <f2> ... <fn>
• <f> can be either fields or aggregate functions
• MIN, MAX, AVG, SUM, COUNT
• NB. No commas between fields in field list
ABAP Training Reports 41
WHERE
<operator>
EQ =
GE >= =>
LE <= =<
NE <> ><
GT >
LT <
ABAP Training Reports 44
<pattern>
special characters ‘_’ and ‘%’
‘_’
represents a single character
‘%’
represents any sequence of characters
SUM( LUGGWEIGHT )
ABAP Training Reports 46
ORDER BY
E Error Depending on the program context, an error dialog appears or the program
terminates.
I Information The message appears in a dialog box. Once the user has confirmed the
message, the program continues immediately after the MESSAGE statement.
S Status The program continues normally after the MESSAGE statement, and the
message is displayed in the status bar of the next screen.
W Warning Depending on the program context, an error dialog appears or the program
terminates.
X Exit No message is displayed, and the program terminates with a short dump.
Message type X allows you to force a program termination.
ABAP Training Reports 49
Messages in Reports
Messages in Reports
MESSAGE xnnn.
x is one of Displayed Outcome
I Info window resumes processing
W Warning status line terminates current list level
E Error status line terminates current list level
A Abend window termination after message
X Exit status line immediate termination
S Success status line resumes processing
nnn is the message number
system variables
SY-MSGID message ID
SY-MSGTY message type
SY-MSGNO message number
ABAP Training Reports 51
Messages in Reports
WITH option allows contents of fields < fi > to replace the &i
according to the value of I
MESSAGE E200 WITH SY-LSIND.
ABAP Training Reports 52
Messages in Reports
Write Statements
NO-ZERO
NO-SIGN
DD/MM/YY
LEFT-JUSTIFIED
RIGHT-JUSTIFIED
CENTERED
USING EDIT MASK mask
USING NO EDIT MASK
DECIMALS d
ABAP Training Reports 55
No grouping
CURRENCY w
EXPONENT e
ROUND r
TIME ZONE tz
ABAP Training Reports 56
Formatting of Report
i 11 right-justified
f 22 right-justified
d 8 left-justified
t 6 left-justified
Positioning Output
WRITE <f>
• DD/MM/YY
• MM/DD/YY
• DD/MM/YYYY
• MM/DD/YYYY
• DDMMYY
• MMDDYY
• YYMMDD
ABAP Training Reports 64
Format
Format
option
FORMAT RESET
sets all formatting options to OFF in one go
ABAP Training Reports 67
COLOURS IN LISTS
Color Examples
Horizontal Lines
LINE [AT [/] [<pos>] [(len)] ].
WRITE [AT [/] [<pos>] [(len)] ] SY-ULINE.
Vertical Lines
WRITE [AT [/] [<pos>] ] SY-VLINE.
WRITE [AT [/] [<pos>] ] ‘|’.
Blank Lines
SKIP [<n>]
SKIP TO LINE <n>.
ABAP Training Reports 72
SKIP [<n>]
if <n> greater than lines remaining on page
ignored
ABAP Training Reports 73
RESERVE statement triggers a page break if less than <n> free lines are
left on the current list page between the last output and the page footer.
Before starting a new page, the system processes the END-OF-PAGE
event.
RESERVE only takes effect if output is written to the subsequent page
(the system will not generate an empty page).
ABAP Training Reports 75
SY-PAGNO
Number of current page of current list
SY-LINNI
Number of current line of current list
SY-COLNO
Number of column where cursor is positioned in the current
list
ABAP Training Reports 76
SY-title
Title that appears in the title bar of the display window
Can be manipulated by
SY-SROWS
Current number of lines in display window
SY-SCOLS
Current number of columns in display window