08 Basic Abap
08 Basic Abap
Definition:
The selection screen is the part of a report program that you can design
for interactive input of field values and selection criteria.
The user can enter field values and selection criteria on this screen.
PARAMETERS:
To declare a parameter and its data type, use the PARAMETERS
statement as follows:
Syntax
PARAMETERS <p>[(<length>)] <type> [<decimals>].
Caution
Parameters cannot have data type F. The data type F is not supported
on the selection screen.
ABAP/4 REPORTS
Example:
REPORT SAPMZTST.
TABLES SPFLI.
PARAMETERS : WORD(10) TYPE C,
DATE TYPE D,
NUMBER TYPE P DECIMALS 2,
CONNECT Like SPFLI-CONNID.
You can use parameters, for example, to control the program flow, or in
connection with SELECT statement to enable the report user to
determine selection criteria for database accesses .
Example:
TABLES SPFLI.
PARAMETERS : LOW LIKE SPFLI-CARRID,
HIGH LIKE SPFLI-CARRID.
In this example, the system reads all rows from the database table
SPFLI, where the contents of field CARRIED are between the limits LOW
and HIGH. The report user can enter the fields LOW and HIGH on the
selection screen.
ABAP/4 REPORTS
Variants of Parameters statements are:
REPORT ZTEST2 .
TABLES SPFLI.
PARAMETERS : value type i default 100,
name like sy-uname default sy-uname,
date like sy-datum default '20020110'.
Example :
REPORT ZTEST2 .
TABLES SPFLI.
PARAMETERS : A as Checkbox,
B as Checkbox Default 'X'.
The declared fields will appear on the selection screen as follows :
ABAP/4 REPORTS
Example :
REPORT ZTEST2 .
TABLES SPFLI.
PARAMETERS : R1 RADIOBUTTON GROUP RAD1,
R2 RADIOBUTTON GROUP RAD1,
R3 RADIOBUTTON GROUP RAD1 DEFAULT ‘X’,
S1 RADIOBUTTON GROUP RAD2,
S2 RADIOBUTTON GROUP RAD2,
S3 RADIOBUTTON GROUP RAD2 DEFAULT ‘X’.
•If you use the SELECT-OPTIONS statement, the report user can enter
the selection criteria on the selection screen.
SELECT-OPTIONS statement
Syntax
SELECT-OPTIONS <seltab> FOR <f>.
ABAP/4 REPORTS
•The field <f> cannot have data type F. The data type F is not supported
on the selection screen.
Selection table
It is an internal table(with name <seltab>) with a header line. Its line
structure is a field string of four components,
ABAP/4 REPORTS
* SIGN : The data type of SIGN is C with length 1. Possible values are
I and E.
* OPTION : The data type of OPTION is C with length 2. OPTION
contains the selection operator.
• If HIGH is empty, you can use EQ, NE, GT, LE, LT,CP, and NP.
• If HIGH is filled, you can use BT and NB.
* LOW : The data type of LOW is the same as the column type of the
database table, to which the selection criterion is attached.
* HIGH : The data type of HIGH is the same as the column type of the
Example:
REPORT SAPMZTST.
TABLES SPFLI.
SELECT-POTIONS AIRLINE FOR SPFLI-CARRID.
LOOP AT AIRLINE.
WRITE : / ‘SIGN:’, AIRLINE-SIGN,
‘OPTION:’, AIRLINE-OPTION,
‘LOW:’, AIRLINE-LOW,
‘HIGH:”, AIRLINE-HIGH.
ENDLOOP.
ABAP/4 REPORTS
Using Selection Tables in the WHERE Clause:
Syntax
......... WHERE <f> IN <seltab>.
Example :
REPORT SAPMZTST.
TABLES SPFLI.
SELECT-OPTIONS AIRLINE FOR SPFLI-CARRID.
SELECT * FROM SPFLI WHERE CARRID IN AIRLINE.
WRITE : SPFLI-CARRID.
ENDSELECT.
ABAP/4 REPORTS
In the SELECT-OPTIONS statement of this example, the selection
table AIRLINE is attached to the CARRIED column of the database
table SPFLI. The WHERE clause of the SELECT statement causes
the system to check if the contents of the CARRIED column meet
the selection criteria stored in AIRLINE.
Assume that the report user enters two lines in the selection table,
namely an interval selection and a single value selection,
as follows :
Syntax
... <f> IN <seltab> ....
The logical expression is true if the contents of the field <f> meet
the selection limits stored in the selection table <seltab>. <f> can
be any internal field or the column of a database table.
ABAP/4 REPORTS
Syntax : …<seltab>….
Example :
REPORT SAPMZTST.
TABLES SPFLI.
SELECT-OPTIONS AIRLINE FOR SPFLI-CARRID.
WRITE : ‘Inside’, ‘Outside’.
SELECT * FROM SPFLI.
IF SPFLI-CARRID IN AIRLINE.
WRITE : / SPFLI-CARRID UNDER ‘Inside’.
ELSE.
WRITE : / SPFLI-CARRID UNDER ‘Outside’.
ENDIF.
ENDSELECT.
ABAP/4 REPORTS
Assume that the report user enters two lines in the selection table,
namely an interval selection and a single value selection,
as follows :
Inside Outside
AA
DL
LH
SQ
UA
ABAP/4 REPORTS
In the SELECT loop, all lines are read from the database table
SPFLI. Using the IF statement, the program flow is branched into
two statement blocks according to the logical expression. The
short form IF AIRLINE is also possible in this program.
Blank Lines
To produce blank lines on the selection screen, use the SKIP option
with the SELECTION-SCREEN statement.
Syntax
Syntax
Comments
To write text on the selection screen, use the COMMENT option with
the SELECTION-SCREEN statement. The syntax is as follows:
Syntax
SELECTION-SCREEN COMMENT [/]<pos(len)> <name>
[MODIF ID <key>].
ABAP/4 REPORTS
Example of Blank Lines, Underlines, and Comments :
Syntax
SELECTION-SCREEN BEGIN OF LINE.
...
SELECTION-SCREEN END OF LINE.
Note that the selection text (name of the parameter or text element) is
not displayed when you use this option. To display a selection text you
must use SELECTION-SCREEN statement with the COMMENT option.
Positioning an Element
Syntax
SELECTION-SCREEN POSITION <pos>.
ABAP/4 REPORTS
Note:
Use the POSITION option only between the BEGIN OF LINE and
END OF LINE options.
Example:
REPORT SAPMZTST.
TABLES SPFLI.
SELECT-OPTIONS AIRLINE FOR SPFLI-CARRID.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN POSITION POS_HIGH.
PARAMETERS FIELD(5).
SELECTION-SCREEN END OF LINE.
ABAP/4 REPORTS
Syntax
SELECTION-SCREEN BEGIN OF BLOCK <block>
[WITH FRAME [TITLE <title>]] [NO INTERVALS].
...
SELECTION-SCREEN END OF BLOCK <block>.
•You must define a name <block> for each block. You can nest
blocks.
•If you add the WITH FRAME option, a frame will be drawn around
the block.
•You can add a title to each frame by using the TITLE option .
•If you use the NO INTERVALS option, the system processes all
SELECT-OPTIONS statements in this block as if they had this
option .
ABAP/4 REPORTS
Example :
On the selection screen, the three radio buttons R1, R2, R3 form a
block, which is surrounded by a frame and has the title specified in the
text symbol 002.
ABAP/4 REPORTS
Syntax
SELECTION-SCREEN FUNCTION KEY <i>.
• <i> must be between 1 and 5.
•You must specify the text to appear on the buttons during runtime in
ABAP/4 Dictionary fields SSCRFIELDS-FUNCTXT_0<i>.
ABAP/4 REPORTS
•When the user clicks this button, FC0<i> is entered in the field
SSCRFIELDS-UCOMM, which can be checked during the event AT
SELECTION-SCREEN.
Example:
TABLES SSCRFIELDS.
DATA FLAG.
PARAMETERS TEST:
SELECTION-SCREEN FUNCITON KEY 1.
SELECTION-SCREEN FUNCITON KEY 2.
INITIALIZATION.
SSCRFIELDS-FUNCTXT_01 = ‘Button 1’.
SSCRFIELDS-FUNCTXT_02 = ‘Button 2’.
ABAP/4 REPORTS
AT SELECTION-SCREEN.
IF SSCRFIELDS-UCOMM = ‘FC01’.
FLAG = ‘1’.
ELSEIF SSCRFIELDS-UCOMM = ‘FC02’.
FLAG = ‘2’.
ENDIF.
START-OF-SELECTION.
IF FLAG = ‘1’.
WRITE : / ’Button 1 was clicked’.
ELSEIF FLAG = ‘2’.
Write : / ‘Button 2 was clicked’.
This example causes two pushbuttons with the texts ‘Button 1’ and
‘Button 2’ to appear in the application toolbar on the selection screen.
ABAP/4 REPORTS
Syntax
The parameters [/]<pos(len)>, <name>, and the MODIF ID option are the
same as described for the COMMENT option in Comments.
TABLES SSCRFIELDS.
DATA FLAG.
PARAMETERS TEST:
SELECTION-SCREEN PUSHBUTTON /20(10) BUT1
USER-COMMAND CLI1.
SELECTION-SCREEN PUSHBUTTON /20(10) TEXT-020
USER-COMMAND CLI2.
INITIALIZATION.
BUT1 = ‘Button 1’.
AT SELECTION-SCREEN.
IF SSCRFIELDS-UCOMM = ‘FCI1’.
FLAG = ‘1’.
ELSEIF SSCRFIELDS-UCOMM = ‘CLI2’.
FLAG = ‘2’.
ENDIF.
ABAP/4 REPORTS
START-OF-SELECTION.
IF FLAG = ‘1’.
WRITE : / ’Button 1 was clicked’.
ELSEIF FLAG = ‘2’.
Write : / ‘Button 2 was clicked’.
ENDIF.
If the text symbol TEXT-020 is defined as ‘button 2’, this example
causes two pushbuttons with the texts ‘Button 1’ and ‘Button 2’ to
appear on the selection screen.
ABAP/4 REPORTS
•If you want to run the same report program with the same selections at
regular intervals (for example, for monthly sales statistics), you would
not want to enter the same values each time. ABAP/4 offers you a
possibility to combine the desired values for all these selections in one
selection set. Such a selection set is called a variant.
•You can create as many different selection sets as you like for each
report program and they remain assigned only to the report program in
question.
•Variants you use online may have different functions than those you
use in background processing.
ABAP/4 REPORTS
•Using Variants Online:
•Online, starting a report via variant saves the user work, since he does
not have to enter the same selection set again and again each time the
selection screen appears. In addition, using a variant minimizes input
errors.
To delete a variant, enter the report name and the variant name in the
variants initial screen. Then, choose Variants -> Delete.
PRINTING VARIANTS:
To print a variant, enter the name of the variant in the variants initial
screen, choose the values for display and click print. Note that you
cannot print the values if you are in change mode.
ABAP/4 REPORTS
Deleting Variants
ABAP/4 REPORTS
You must specify the MESSAGE-ID behind the REPORT statement of your
program.
ABAP/4 REPORTS
INITIALIZATION
EXAMPLE:
REPORT SAPMZTST.
TABLES SPFLI.
Example of Initialization
ABAP/4 REPORTS
AT SELECTION-SCREEN
START-OF-SELECTION
If you do not specify any event keywords in your program, all statements
of the program before a FORM statement form the START-OF-
SELECTION processing block.
NOTE:
•All statements between an ENDFORM statement and an event keyword
or between an ENDFORM statement and the end of the program form a
processing block that is never processed.
ABAP/4 REPORTS
•Do not place any statements there. Place all subroutines at the end of
your program.
•If you write statements between the REPORT statements and the first
event keyword or FORM statement, these statements are included in the
START-OF-SELECTION processing block.
END-OF-SELECTION
To define a processing block after the system has read and processed all
database tables of a logical database, use the keyword END-OF-
SELECTION.