You are on page 1of 14

3/22/2011

SELECTION SCREENS AND


LIST PROCESSING EVENTS

Spring 2011

Enterprise Programming

Getting Data from User at Runtime


PARAMETERS is the most basic type of input acceptance.
Using Parameters generates a default selection screenscreen
1000.
If the type of item prompted is based on a global type this allows
input help (F1) and entry selection help (F4) are shown as defined in
the ABAP dictionary.
PARAMETERS: carrier TYPE sflight-carrid,
fltdate TYPE sflight-fldate.

3/22/2011

Event blocks
An ABAP program is a collection of processing blocks.
Event blockscalled by runtime environment when related event
has been triggered through natural program flow of control or
when triggered by a user action.
action
Our initial programsone blockso no need to declare event blocks.
Program event blocks:
LOAD-OF-PROGRAM (called at initial program setup)
START-OF-SELECTION (beginning of main processing)
Example use: PARAMETERS triggered at beginning of main
processing. If want to set a default value for field based on
processing (calculation, data retrieval), must do this before
START-OF-SELECTION.

Example
PARAMETERS date LIKE sy-datum DEFAULT sy-datum.
WRITE date.
DATA pastdate LIKE sy-datum.
pastdate = pastdate - 7.
PARAMETERS date LIKE sy-datum DEFAULT pastdate.
WRITE date.
LOAD-OF-PROGRAM.
DATA pastdate LIKE sy-datum.
pastdate = sy-datum - 7.
PARAMETERS date LIKE sy-datum DEFAULT pastdate.
START-OF-SELECTION.
WRITE date.

3/22/2011

Selection Screen Input


Selection screen display and control can incorporate additional
elements beyond PARAMETERS to provide additional GUI controls.
Covered previously:
S l ti TTexts
Selection
t ((changes
h
prompting
ti associated
i t d with
ith PARAMETERS)
PARAMETERS).

More on Parameters--checkboxes
PARAMETERS can be designated AS CHECKBOX.
PARAMETERS: myvar AS CHECKBOX.

Use DEFAULT 'X' to have it toggled on initially.


PARAMETERS: myvar AS CHECKBOX DEFAULT 'X'.
Test if user selected by seeing if variable set to 'X'.
IF myvar = 'X'.
'X'
"code here.
ENDIF.

3/22/2011

More on Parameters--checkboxes
PARAMETERS: male AS CHECKBOX, female AS CHECKBOX.
IF male =
WRITE /
ENDIF.
IF female
WRITE /
ENDIF.

'X'.
'You are male!'.
= 'X'.
'You are female!'.

More on Parameters--radio buttons


PARAMETERS can be designated as part of a radiobutton group.
PARAMETERS: choice1 RADIOBUTTON GROUP grpa,
choice2 RADIOBUTTON GROUP grpa,
choice3 RADIOBUTTON GROUP grpa.
grpa
Maximum group name length--4 characters
Use DEFAULT 'X' to have it toggled on initially.
PARAMETERS: choice1 RADIOBUTTON GROUP grpa DEFAULT 'X'.
Test if user selected by seeing if variable set to 'X' or use a CASE
statement.
CASE 'X'
'X'.
WHEN choice1.
WHEN choice2.

ENDCASE.

3/22/2011

More on Parameters--radio buttons


PARAMETERS: male RADIOBUTTON GROUP gen,
female RADIOBUTTON GROUP gen.
IF male = 'X'.
WRITE / 'You are male!'.
ENDIF.
IF female = 'X'.
WRITE / 'You are female!'.
ENDIF.
PARAMETERS: male RADIOBUTTON GROUP gen,
female RADIOBUTTON GROUP gen.
CASE 'X'.
WHEN male.
WRITE / 'You are male!'.
WHEN female.
WRITE / 'You are female!'.
ENDCASE.

PARAMETERS: myvar AS CHECKBOX.


PARAMETERS: choice1 RADIOBUTTON GROUP grpa,
choice2 RADIOBUTTON GROUP grpa,
choice3 RADIOBUTTON GROUP grpa.
IF myvar = 'X'.
WRITE / 'You chose the checkbox'.
ELSE.
ELSE
WRITE / 'You did not choose the checkbox'.
ENDIF.
CASE 'X'.
WHEN choice1.
WRITE / 'You picked choice1'.
WHEN choice2.
WRITE / 'You picked choice2'.
WHEN choice3.
WRITE / 'You picked choice3'.
WHEN OTHERS.
WRITE / 'You did not pick a choice!'.
ENDCASE.

3/22/2011

Selection Screen refinements


To exert further control over selection screen use SELECTION-SCREEN
statement.
Can add 1 or more framed blocks with optional title.
SELECTION SCREEN BEGIN OF BLOCK name WITH FRAME TITLE title.
SELECTION-SCREEN
title
PARAMETERS: male RADIOBUTTON GROUP gen,
female RADIOBUTTON GROUP gen.
SELECTION-SCREEN END OF BLOCK name.
CASE 'X'.
WHEN male.
WRITE / 'You are male!'.
WHEN female.
WRITE / 'You are female!'.
ENDCASE.
LOAD-OF-PROGRAM.
title = 'Choose a gender'.

Multiple items on a line


To place multiple items on a single output line, place control
definitions within a SELECTION-SCREEN BEGIN OF LINE/ SELECTIONSCREEN END OF LINE block.
SELECTION-SCREEN
SELECTION
SCREEN BEGIN OF BLOCK name WITH FRAME
TITLE title.
SELECTION-SCREEN BEGIN OF LINE.
PARAMETERS: var1 TYPE i,
var2 TYPE i,
var3 TYPE i.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN END OF BLOCK name.
LOAD-OF-PROGRAM.
title = 'Enter choices'.

3/22/2011

Supplemental Text
COMMENT can be used to place text on the form.
Must use column and length format specifier.
SELECTION-SCREEN BEGIN OF BLOCK name WITH FRAME
TITLE title.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 1(40) comment.
PARAMETERS: var1 TYPE i,
var2 TYPE i,
var3 TYPE i.
SELECTION SCREEN END OF LINE.
SELECTION-SCREEN
LINE
SELECTION-SCREEN END OF BLOCK name.
LOAD-OF-PROGRAM.
title = 'Enter choices'.
comment = 'Enter your three favorite numbers'.

SELECTION-SCREEN BEGIN OF BLOCK name WITH FRAME TITLE title.


SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 1(5) comment.
PARAMETERS: male RADIOBUTTON GROUP gen.
SELECTION-SCREEN COMMENT 12(6) comment2.
PARAMETERS: female RADIOBUTTON GROUP gen.
SELECTION-SCREEN
SELECTION
SCREEN END OF LINE.
SELECTION-SCREEN END OF BLOCK name.
CASE 'X'.
WHEN male.
WRITE / 'You are male!'.
WHEN female.
WRITE / 'You are female!'.
ENDCASE.
ENDCASE
LOAD-OF-PROGRAM.
title = 'Choose a gender'.
comment = 'Male'.
comment2 = 'Female'.

3/22/2011

Allowing range of values selection


Allows user to select a range of values.
SELECT-OPTIONS itabname FOR dataobject.
User entry stored in internal table itabname. 4 fields:
Sign either I or Eindicating
Signeither
E indicating whether values specified are
included or excluded from selection
Lowthe lower limit or a single value (if only one specified)
Highthe upper limit
Optiontext such as EQ, NE, GE, GT, LE, LT (if only Low
specified). [Other options not presented here]
Control typically used with database query operations and WHERE
clause particularly adjusted to correspond with this resource.
SELECT fields FROM table WHERE value IN itabname.
(Used as a field limiter if selected, so if not populated all values
returned.)

Allowing range of values selection


DATA str TYPE spfli.
SELECT-OPTIONS userair FOR str-carrid.
SELECT carrid connid cityfrom cityto FROM spfli INTO
CORRESPONDING FIELDS OF str WHERE carrid IN userair.
WRITE: / str-carrid, str-connid, str-cityfrom,
str-cityto.
ENDSELECT.

3/22/2011

SELECTION-SCREEN BEGIN OF BLOCK name WITH FRAME TITLE title.


SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 1(40) comment.
PARAMETERS: var1 TYPE i,
var2 TYPE i.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 1(40) comment2.
PARAMETERS var3 TYPE i.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN END OF BLOCK name.
LOAD-OF-PROGRAM.
title = 'Enter choices'.
comment = 'Enter your three favorite numbers'.
comment2 = 'Put your most favorite here'.

SELECTION-SCREEN BEGIN OF BLOCK name WITH FRAME TITLE title.


SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 1(40) comment.
PARAMETERS: var1 TYPE i.
SELECTION-SCREEN COMMENT 60(1) comment3.
PARAMETERS: var2 TYPE i.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 1(40) comment2.
PARAMETERS var3 TYPE i.
SELECTION-SCREEN END OF LINE.
SELECTION SCREEN END OF BLOCK name.
SELECTION-SCREEN
LOAD-OF-PROGRAM.
title = 'Enter choices'.
comment = 'Enter your three favorite numbers'.
comment2 = 'Put your most favorite here'.

3/22/2011

Data Validity Testing


Validation of screen input can be done on the AT SELECTION-SCREEN
event.
Useful if want to require user data entry before main processing.
AT SELECTION-SCREEN
SELECTION SCREEN ON fieldname
fieldname.
Triggered if fieldname was submitted.
If an error or warning is issued, the field is highlighted.
AT SELECTION-SCREEN ON RADIOBUTTON GROUP grpnam.
If an error or warning is issued, the group is highlighted.

Data Validity Testing


SELECTION-SCREEN BEGIN OF BLOCK name WITH FRAME TITLE title.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 1(40) comment.
PARAMETERS: var1 TYPE i,
i var2 TYPE i,
i var3 TYPE i.
i
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN END OF BLOCK name.
AT SELECTION-SCREEN ON var2.
IF var2 = 7.
MESSAGE 'Sevens are bad!' TYPE 'W'.
ENDIF.

10

3/22/2011

Let's Practice

Let's Practice

11

3/22/2011

List output events


We now move from input and related events to output and a related
event.

AT LINE-SELECTION EVENT
When outputting a list, the AT LINE-SELECTION event is triggered
when a line is double clicked or the user chooses the choose icon.
SY-LSIND starts out at 0 for the initial list output and is incremented
each time the event fires.
fires It is decremented as the user moves
BACK.
START-OF-SELECTION.
WRITE: /'hello', 'sy-lsind', sy-lsind.
AT LINE-SELECTION.
WRITE: /'Now at selection level', sy-lsind.

When writing in AT LINE-SELECTION, this is called a detail list and


its output appears as a new list.

12

3/22/2011

Retrieving values from selected line


When list is output, HIDE can be used to designate values that will be
passed on (called a data transport) when line is selected.
The data object to be hidden may or may not be a part of the output
that is displayed
displayed.

TYPES spfli_table_type TYPE STANDARD TABLE OF spfli.


DATA itable_spfli TYPE spfli_table_type.
DATA str LIKE LINE OF itable_spfli.
DATA str2 TYPE sflight.

SELECT carrid connid airpfrom airpto deptime FROM spfli INTO


CORRESPONDING FIELDS OF TABLE itable_spfli.
LOOP AT itable_spfli INTO str.
WRITE: / str-carrid, str-connid, str-airpfrom, str-airpto,
str-deptime.
HIDE: str-carrid, str-connid.
ENDLOOP.
AT LINE-SELECTION.
IF sy-lsind = 1.
WRITE: 'Flights
li h
f
for connection',
i
str-carrid,
id str-connid.
id
SELECT fldate seatsmax seatsocc FROM sflight INTO CORRESPONDING
FIELDS OF str2 WHERE carrid = str-carrid AND connid =
str-connid.
WRITE: / str2-fldate, str2-seatsmax, str2-seatsocc.
ENDSELECT.
ENDIF.

13

3/22/2011

Copyrights
Presentation prepared by and copyright of Dr. Tony
Pittarese, East Tennessee State University, Computer and
Information Sciences Dept. (pittares@etsu.edu)
Podcast lecture related to this presentation available via
ETSU iTunesU.
Microsoft, Windows, Excel, Outlook, and PowerPoint are registered trademarks of Microsoft Corporation.
IBM, DB2, DB2 Universal Database, System i, System i5, System p, System p5, System x, System z, System z10, System z9, z10, z9, iSeries, pSeries,
xSeries, zSeries, eServer, z/VM, z/OS, i5/OS, S/390, OS/390, OS/400, AS/400, S/390 Parallel Enterprise Server, PowerVM, Power Architecture, POWER6+,
POWER6, POWER5+, POWER5, POWER, OpenPower, PowerPC, BatchPipes, BladeCenter, System Storage, GPFS, HACMP, RETAIN, DB2 Connect, RACF,
Redbooks, OS/2, Parallel Sysplex, MVS/ESA, AIX, Intelligent Miner, WebSphere, Netfinity, Tivoli and Informix are trademarks or registered trademarks of
IBM Corporation.
Linux is the registered trademark of Linus Torvalds in the U.S. and other countries.
Oracle is a registered trademark of Oracle Corporation.
HTML, XML, XHTML and W3C are trademarks or registered trademarks of W3C, World Wide Web Consortium, Massachusetts Institute of Technology.
Java is a registered trademark of Sun Microsystems,
Microsystems Inc
Inc.
JavaScript is a registered trademark of Sun Microsystems, Inc., used under license for technology invented and implemented by Netscape.
SAP, R/3, SAP NetWeaver, Duet, PartnerEdge, ByDesign, SAP Business ByDesign, and other SAP products and services mentioned herein as well as their
respective logos are trademarks or registered trademarks of SAP AG in Germany and other countries.
Business Objects and the Business Objects logo, BusinessObjects, Crystal Reports, Crystal Decisions, Web Intelligence, Xcelsius, and other Business
Objects products and services mentioned herein as well as their respective logos are trademarks or registered trademarks of Business Objects S.A. in the
United States and in other countries. Business Objects is an SAP company.
Other products mentioned in this presentation are trademarks of their respective owners.

14

You might also like