ITB258 ABAP Programming: Basics of Interactive Reporting Selection Screens

You might also like

Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1of 66

ITB258

ABAP Programming

Lecture 6 (Week 7)
Basics of Interactive Reporting
Selection Screens
Objectives
Interactive Reporting
– what are interactive lists
– basic & secondary lists
– the HIDE statement
– event control
• AT LINE-SELECTION
– SY-LSIND
• AT PFnn
• AT USER-COMMAND
– system fields for secondary lists
Objectives
Selection Screens
• the creation and use of Selection Screens in ABAP
reports:
• the SELECT-OPTIONS statement
• Selection tables
• Formatting the selection screen
• Selection texts, Lines, Comments, Frames
• the PARAMETERS statement
• Radiobuttons, Checkboxes

• executing reports with Variants


Interactive Reporting
Non-Interactive vs Interactive Lists
• Non-Interactive
– static structure
– single, extensive and detailed list
• user searches through the list to find the relevant parts
• Interactive
– user selectively retrieves and presents data
• select lines, enter commands from menus, function keys
or pushbuttons, type input
– detailed information presented in secondary lists
– ability to call transactions or other reports
Interactive Reporting

Secondary
List

Report
Interactive
List
Transaction
Interactive Reports are Event Driven
REPORT ZLIST.
*Basic List

START-OF-SELECTION. *Secondary List

END-OF-SELECTION. AT LINE-SELECTION.

TOP-OF-PAGE. AT USER-COMMAND.

END-OF-PAGE. AT PFnn.

TOP-OF-PAGE DURING
LINE-SELECTION.
The Basic List
• Contains the output of the data created while processing
either
– START-OF-SELECTION
– GET <dbtable>
• by default a basic list has a standard page header
– if TOP-OF-PAGE / END-OF-PAGE event occurs
• system writes data to page header / page footer and then displays basic
list data on the output screen
• system field SY-LSIND = 0
Secondary Lists
• basic list + up to 20 secondary lists can exist in
parallel
• on moving to (next) secondary list
– current list added to memory area
– SY-LSIND incremented by one
• using back or exit
– logically superior list is displayed again
– SY-LSIND decremented by one
• no standard heading for secondary lists
Basic List
SY-LSIND = 0
REPORT ZSAPTEST.

WRITE: / ‘Basic List’. choose

AT LINE-SELECTION. 1. Sec' List


CASE SY-LSIND. SY-LSIND = 1
WHEN ‘1’.
"<display 2nd list #1> choose

WHEN ‘2’. 2. Sec' List


"<display 2nd list #2> SY-LSIND = 2

WHEN ‘3’. choose


SY-LSIND = SY-LSIND-1.
"<display 2nd list #3>
3. Sec' List
SY-LSIND = 2
Page Headers for Secondary Lists

• On secondary lists
– system does not display a standard page header
– does not trigger the TOP-OF-PAGE event
• TOP-OF-PAGE DURING LINE-SELECTION
– triggered for each secondary list
– to create different page headers for each secondary
list you must program a processing block for each
value of SY-LSIND
REPORT ZRAL7001 .

START-OF-SELECTION.
WRITE: / 'Basic List. SY-LSIND = ', SY-LSIND.

AT LINE-SELECTION.
CASE SY-LSIND.
WHEN '1'.
FORMAT COLOR COL_HEADING.
WRITE: / '1st secondary list. SY-LSIND = ', SY-LSIND.
WHEN '2'.
FORMAT COLOR COL_NORMAL INTENSIFIED OFF.
WRITE: / '2nd secondary list. SY-LSIND = ', SY-LSIND.
WHEN '3'.
FORMAT COLOR COL_NEGATIVE INTENSIFIED ON.
WRITE: / '3rd secondary list. SY-LSIND = ', SY-LSIND.
SY-LSIND = SY-LSIND - 1.
ENDCASE.
TOP-OF-PAGE DURING LINE-SELECTION.
* Write the headings for the secondary lists
CASE SY-LSIND.
WHEN '1'.
WRITE 'Heading For 1st Secondary List'.
WRITE AT 90 SY-PAGNO. ULINE.
WHEN '2'.
WRITE 'Heading For 2nd Secondary List'.
WRITE AT 90 SY-PAGNO. ULINE.
WHEN '3'.
WRITE 'Heading For 3rd Secondary List'.
WRITE AT 90 SY-PAGNO. ULINE.
ENDCASE.
The HIDE Event
HIDE f
• stores the contents of f in relation to the
current output line in the HIDE area
– not necessary for f to appear on current line
– place the HIDE statement immediately after the
output statement for f
• user selection of a line for which HIDE fields
are available fills the variables in the program
with the values stored
REPORT ZSAPTEST.

SELECT * FROM SPFLI.


WRITE: / SPFLI-CARRID, SPFLI-CONNID,
SPFLI-CITYFROM, SPFLI-CITYTO.
HIDE: SPFLI-CARRID, SPFLI-CONNID.
ENDSELECT.

X HIDE Area
CARRID CONNID CITYFROM CITYTO CARRID CONNID
AA 0016 New York Denver AA 0016
LH 0400 Frankfurt New York LH 0400
LH 0357 Rome Frankfurt LH 0357
: :
* write basic list, hide fields for secondary list
SELECT * FROM SPFLI.
WRITE: / SPFLI-CARRID, SPFLI-CONNID,
SPFLI-CITYFROM, SPFLI-CITYTO.
HIDE: SPFLI-CARRID, SPFLI-CONNID.
ENDSELECT.

* write secondary list, hide field for next level


AT LINE-SELECTION.
SELECT * FROM SFLIGHT WHERE CARRID = SPFLI-CARRID.
WRITE: / SFLIGHT-CARRID, SFLIGHT-FLDATE,
SFLIGHT-SEATSMAX, SFLIGHT-SEATSOCC.
HIDE: SFLIGHT-FLDATE.
ENDSELECT.
AT Event Processing
• AT LINE-SELECTION
– triggered when user:
• double clicks on a valid line
• Selects line then either presses the Pick toolbar button, presses the F2 key, or
selects the Edit-Choose menu option
– increments SY-LSIND by 1.
• AT USER-COMMAND
– triggered when user:
• presses a function key
• clicks a toolbar button
• selects a menu entry
• makes an entry in the command field
– function code stored in SY-UCOMM
• AT PFnn
– triggered when user presses a function key
– also uses SY-UCOMM to store the selected code
AT Event Processing
• AT LINE-SELECTION AT LINE-SELECTION.
– determine what action to
take by checking the CASE SY-LSIND.
current list level in the WHEN '1'.
report select * from sflight
– code the appropriate where …
action write: / …
WHEN '2'.
select * from sbook
where …
write: / …
ENDCASE.
AT Event Processing
• AT USER-COMMAND
– determine what action to take by checking the current
function code value stored in SY-UCOMM
– code the appropriate action

AT USER-COMMAND.
CASE SY-UCOMM.
WHEN 'SORT'.
PERFORM Sort_List.
WHEN 'DELE'.
PERFORM Del_Record.
ENDCASE.
AT Event Processing
• AT PFnn
– nn is in the range of 0 to 99
– determine what action to take by:
• inserting an event header for that PF key; OR
• checking the current function code value stored in SY-UCOMM
– code the appropriate action

AT PF6.
PERFORM Sort_List.

AT PF8.
PERFORM Del_Record.
System Fields & Interactive Reports
SY-CUROW current cursor position (line)

SY-CUCOL current cursor position (column)

SY-CPAGE current page number

SY-LSIND index of the displayed list

SY-LISEL contents of the selected line

SY-UCOMM last user-initiated function code


Selection Screens
Selection Screens

• Used to allow the user to control the


database selections of the report
• Allows interactive
– assignment of values to data variables
• with the PARAMETERS statement
– determination of selection criteria for database
fields (criteria can be single values, range of
values, sets of values, …)
• with the SELECT-OPTIONS statement
The parameters Keyword
PARAMETERS field TYPE type [DEFAULT value].

PARAMETERS: P1 TYPE P,
P2(6) TYPE C DEFAULT ‘ITN258’.

P1
P2
Basic Form of select-options
SELECT-OPTIONS seltab FOR f.
1. creates a selection table seltab (an internal table with a
header line) which has a relation to table field f.
– the name for seltab, like parameter names, can be up to 8
characters only
– f cannot be of type f (floating point)
2. displays data input fields on a selection screen.
REPORT ZSAPTEST.
TABLES: SFLIGHT.
SELECT-OPTIONS: AIRLINE FOR SFLIGHT-CARRID,
CONN FOR SFLIGHT-CONNID.

AIRLINE CONN
SIGN OPTION LOW HIGH SIGN OPTION LOW HIGH

multiple selection screen


Multiple Selection Screen
Multiple Selection Screen
• icon on the main screen takes the user to the
multiple selection screen
– allows creation of more complex selection criteria

• pushbutton saves an extended selection


– the arrow icon on the main screen turns to green
indicating that the selection criteria is more complex
than shown in the To and From fields
seltab
• seltab is an internal table with 4 fields

SIGN OPTION LOW HIGH

I EQ
E NE
LT
GT
LE
GE
BT
NB
CP
NP
seltab and Table Selections
• If seltab contains more than one line:
– form the union of sets defined on the lines that have
SIGN = I
– subtract the union of sets defines on the lines that
have SIGN = E
– select the resulting set
• If seltab contains only lines with SIGN = E
– select all data outside the set specified in these lines
Assigning Default Values to
Selection Criteria
SELECT-OPTIONS seltab FOR f DEFAULT g
[TO h] OPTION op SIGN s.

• g and h may be
– literals (enclosed in single quotes)
– names of fields whose contents should be used as
default values
• op may be one of
– EQ,NE,GE,LE,GT,LT,CP,NP for single selections
– BT,NB for interval selections
• s may be either I or E
REPORT ZSAPTEST.
TABLES: SFLIGHT.
SELECT-OPTIONS: AIRLINE FOR SFLIGHT-CARRID
DEFAULT 'AA' TO 'LH'
OPTION NB
SIGN I.
Assigning Default Values to
Selection Criteria
SELECT-OPTIONS: Notes:
AIRLINE FOR SPFLI-CARRID,
CONN FOR SPFLI-CONNID. • Can also use (for example):
INITIALIZATION. AIRLINE-LOW = 'AA'.
MOVE ‘AA’ TO AIRLINE-LOW.
MOVE ‘DL’ TO AIRLINE-HIGH. • If SIGN is not given, 'I' is
MOVE ‘I’ TO AIRLINE-SIGN.
MOVE ‘BT’ TO AIRLINE-OPTION. assumed.
APPEND AIRLINE.
MOVE ‘LH’ TO AIRLINE-LOW. • If OPTION is not given,
MOVE ‘UA’ TO AIRLINE-HIGH. 'EQ' is assumed.
APPEND AIRLINE.
MOVE ‘QF’ TO AIRLINE-LOW.
MOVE ‘NE’ TO AIRLINE-OPTION.
• Only BT and NB use HIGH
APPEND AIRLINE. field.
MOVE ‘0400’ TO CONN-LOW. • SIGN & OPTION reused
MOVE ‘EQ’ TO CONN-OPTION.
APPEND CONN. for second append in this
example.
Restricting the Selection Screen
to One Line
SELECT-OPTIONS seltab FOR f
NO-EXTENSION … .
• right arrow
REPORT ZSAPTEST.
does not appear on
the selection screen TABLES: SFLIGHT.
• user cannot access
SELECT-OPTIONS AIRLINE
the multiple selection FOR SFLIGHT-CARRID
input screen NO-EXTENSION.
Restricting the Selection Screen
to Single Value Selection
SELECT-OPTIONS seltab FOR f … NO
INTERVALS … .
• TO field does not REPORT ZSAPTEST.
appear on the
TABLES: SFLIGHT.
selection screen
• user can access the SELECT-OPTIONS AIRLINE
multiple selection FOR SFLIGHT-CARRID
NO INTERVALS.
input screen
Further Select-Options Clauses

• NO-DISPLAY
• suppresses display of select-option

• LOWER CASE
• enables acceptance of upper & lower case letters

• OBLIGATORY
• makes selection for FROM field mandatory
TABLES SFLIGHT.
SELECT-OPTIONS: CARRIER FOR SFLIGHT-CARRID,
CONN FOR SFLIGHT-CONNID NO-EXTENSION,
FDATE FOR SFLIGHT-FLDATE NO INTERVALS,
CURR FOR SFLIGHT-CURRENCY NO-DISPLAY,
PLANE FOR SFLIGHT-PLANETYPE OBLIGATORY.
Using Selection Tables in
WHERE Conditions
SELECT … WHERE f IN seltab
• f is a database column (without a prefix)
• seltab is the selection table attached to f
REPORT ZSAPTEST.

TABLES: SFLIGHT.

SELECT-OPTIONS AIRLINE FOR SFLIGHT-CARRID.

SELECT * FROM SFLIGHT


WHERE CARRID IN AIRLINE.
Checkboxes on the Selection Screen
PARAMETERS p … AS CHECKBOX ...
[DEFAULT ' ' | 'X']
• parameter p is created with type C length 1
– options TYPE & LIKE are not allowed
– valid values for p are ' ' (false) and 'X' (true)
PARAMETERS: A AS CHECKBOX,
B AS CHECKBOX DEFAULT 'X'.

A
x B
Checkboxes on the Selection Screen
REPORT ZSAPTEST.
TABLES: SPFLI, SFLIGHT, SBOOK.
SELECT-OPTIONS: DepTime FOR SPFLI-DEPTIME.
PARAMETERS: Luggage AS CHECKBOX.

SELECT * FROM SFLIGHT.


SELECT * FROM SBOOK WHERE ...
WRITE: / SBOOK-BOOKID, ...
CHECK LUGGAGE NE SPACE.
WRITE 30 SBOOK-LUGGWEIGHT.
ENDSELECT.
ENDSELECT.
Radiobuttons on the Selection Screen
PARAMETERS p …
RADIOBUTTON GROUP rgrp ...
• parameter p is created with type C length 1
– can use LIKE option but must refer to a dictionary
object of type C length 1
• rgrp is a string of max length 4
– must assign at least 2 parameters to each rgrp group
• when user clicks on radiobutton
– respective parameter is activated, ie, assigned 'X'
– only one parameter in each group can be activated
Radiobuttons on the Selection Screen
PARAMETERS: DISCOUNT RADIOBUTTON GROUP R1,
ECONOMY RADIOBUTTON GROUP R1,
BUSINESS RADIOBUTTON GROUP R1,
FIRST RADIOBUTTON GROUP R1 DEFAULT ‘X’.
Radiobuttons on the Selection Screen
REPORT ZSAPTEST.

TABLES: SBOOK.

PARAMETERS: PRIVATE RADIOBUTTON GROUP CUST,


BUSINESS RADIOBUTTON GROUP CUST.

SELECT * FROM SBOOK.


IF PRIVATE NE SPACE.
CHECK SBOOK-CUSTTYPE = 'P'.
WRITE: / SBOOK-BOOKID, SBOOK-CUSTOMID.
ELSEIF BUSINESS NE SPACE.
CHECK SBOOK-CUSTTYPE = 'B'.
WRITE: 30 SBOOK-BOOKID, SBOOK-CUSTOMID.
ENDIF.
ENDSELECT.
Formatting the Selection Screen
• SELECTION-SCREEN statement allows
– insertion of texts/comments
– underlines
– insertion of blank lines
• SELECTION-SCREEN BEGIN OF BLOCK
– combines logically related fields
– draw a box around them using WITH FRAME
Formatting the Selection Screen
SELECTION-SCREEN BEGIN OF LINE
COMMENT format name
POSITION n
SELECTION-SCREEN END OF LINE.
TABLES: SFLIGHT.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN: COMMENT 1(14) TEXT-002, POSITION 18.
PARAMETERS: PRICE LIKE SFLIGHT-PRICE OBLIGATORY.
SELECTION-SCREEN: COMMENT 45(9) TEXT-003, POSITION 55.
PARAMETERS: CURRENCY LIKE SFLIGHT-CURRENCY.
SELECTION-SCREEN END OF LINE.
Formatting the Selection Screen

• SELECTION-SCREEN SKIP n.
– leaves n blank lines on the selection screen

• SELECTION-SCREEN ULINE
– draws an underline on the selection screen
Formatting the Selection Screen
SELECTION-SCREEN BEGIN OF BLOCK block
… WITH FRAME
… TITLE title
SELECTION-SCREEN END OF BLOCK block.
SELECTION-SCREEN BEGIN OF BLOCK SPFLI WITH FRAME TITLE TEXT-001.
SELECT-OPTIONS: CARR FOR SPFLI-CARRID DEFAULT 'LH',
CITY FOR SPFLI-CITYFROM DEFAULT 'BERLIN',
DEPART FOR SPFLI-DEPTIME DEFAULT '100000' TO
'130000'.
SELECTION-SCREEN END OF BLOCK SPFLI.
Formatting Selection Text

• default text on the selection screen


– PARAMETERS pname
– SELECT-OPTIONS seltab
• more explanative text
– Goto … Text Elements … Selection Texts
– SELECT-OPTIONS BEGIN OF LINE …
– COMMENT ...
Checking the Selection Screen
AT SELECTION-SCREEN
ON field
ON RADIOBUTTON GROUP grp
ON BLOCK block

REPORT ZSAPTEST MESSAGE-ID ....


TABLES: SPFLI, SFLIGHT, SBOOK.

SELECT-OPTIONS SPRICE FOR SFLIGHT-PRICE.


...
AT SELECTION-SCREEN ON SPRICE.
IF SPRICE-LOW LT ‘500’.
MESSAGE E001. “no flight available at that price
ENDIF.
...
Variants
Reports & Variants
• Variant
– set of values for all parameters and select-options
– when a report is executed with a variant the fields
of the selection screen are filled with the values
of the chosen variant
• Creating a Variant
– execute the report & fill in the selection screen
– GoTo … Variants … Save as Variant
– Enter a name and short description for the variant
– Fill in Variant Attributes as required
Save as Variant
Setting Attributes of a Variant
• Variant Attributes
– protected
• only creator can change it
– Only display in catalog:
• do not display variant on screen
• Field Attributes
– protected
• cannot be changed by the user when the report is run
– invisible
• does not show the user the parameter/select-options variable
• other selection screen items ‘shuffle up’ to leave no gap
– variable
• variant field takes the current value of the named variable
• variable is defined in the data dictionary
Running a Report With a Variant
• Execute the report
– Click on the button in the ABAP Editor:
Initial Screen dialog
– Select a variant from the next dialog box
Running a Report With a Variant
• System … Services … Reporting
– Click on
– select a variant from the next dialog box
Running a Report With a Variant
• SUBMIT reportname USING
SELECTION-SET variantname

REPORT ZB258REP602.

SUBMIT ZB258REP503 USING SELECTION-SET 'ZADAMSWK601'.


Summary
• Interactive Reporting
– non-static view of data for the user
• user selectively retrieves and displays data
• additional clearly structured information can be
presented to the user in secondary lists or windows
• up to 20 secondary lists may exist
– secondary lists generated by special events
• AT LINE-SELECTION, AT USER-COMMAND, AT
PFnn
• SY-LSIND contains index of current list level
Summary
• Interactive Lists
– to save data for the secondary list use HIDE
• system stores field names and field contents per line
(SY-LISEL)
• at an interactive event the values stored in HIDE
area are placed back into the original fields
– generally better performance through
interactive lists
• only lines relevant to the user are selected and
displayed as they are required
Summary
• Selection screens provide the user with some
measure of control over database selections
• PARAMETERS statement
– defines a variable which can hold a single value
– AS CHECKBOX
• provides a yes/no type selection
– RADIOBUTTON GROUP
• provides a one of the following type selection
Summary
• SELECT-OPTIONS
– defines an internal table which holds selection conditions
– internal table has 4 attributes
• SIGN, OPTION, LOW, HIGH
– rows of the internal table can be specified
• via the DEFAULT clause in the program (one row)
• via the INITIALIZATION event in the program (many rows)
• dynamically at runtime
Summary
• selection screen can be formatted with
– lines, comments, frames
• selection text can be maintained through the
Text Attributes screen
• variants provide a method of storing
commonly used selection conditions
• reports can be executed with a variant from the
workbench or from a program
Related Reading
• Textbook
– Ch 3.4.3 (p 213): Selections and Parameters
• Selection Screens
• Using Variants
– Ch 3.5 (p 243): Interactive Reports
• On-Line Help
– R/3 Library…BC..ABAP Workbench
• BC ABAP User’s Guide
– ABAP User Interfaces
• Lists … Interactive Lists
– ABAP User Interfaces … Selection Screens
• Working With Selection Screens, Defining Selection Screens,
Calling Selection Screens, Using Selection Criteria in Programs,
Presetting Selection Criteria in Variants
Pre-Reading for Next Week

• Textbook
– Ch 3.3 - The Interface (pp. 175 - 197)
• defining a GUI status
– Ch 3.2.16 – Messages (pp. 167 – 174)
– WINDOW statement (p. 248)

You might also like