You are on page 1of 244

The Data Dictionary

ABAP Dictionary Concepts


The ABAP dictionary describes the logical structure of the objects
used in application development and shows how they are
mapped to the underlying relational database in tables or views.

The Data Dictionary

Components Of Data Dictionary

Database tables
Database views
Structures
Data elements
Domains
Search helps
Lock objects

The Data Dictionary

3 Levels of the Dictionary


Tables or structures
Composed of one or more fields

Data elements
Each field refers to a data element that describes the
meaning of the field

Domain
Determines the technical properties of the field
Data type and size (including number of decimal places)
Allowed data values
Output characteristics
The Data Dictionary

Data Elements & Domains

Domain
Provides the technical description

Element
Determines the role played
Create a domain called id_number
Create elements student_id and staff_id based on
the id_number domain

The Data Dictionary

Data Elements & Domains

The domain is the central object for describing the technical


characteristics of an attribute of a business object. It describes
the value range of a field. This is determined by specifying
formal characteristics such as external format, length and so
on.In addition specifying fixed values or a value table can
restrict the value range.
The data element is the semantic attribute for fields/domain. It
Defines exactly one role of a domain in a particular business
context for its dependent fields.It describes the technical
attributes and the meaning of the table field.It also contains the
semantic information of a field. Semantic information includes
field labels for displaying

The Data Dictionary

Data Elements & Domains

Customer Table
fields

Data
Elements

Domain

z_phonew
Label: work number
phone_w
phone_f

zphone
z_phonef
Label: fax number

phone_h

type: char

len: 12

z_phoneh

Label: home number

The Data Dictionary

Referential Integrity Check

Data Element
Definition

Field Information

The Data Dictionary

Define the text to be


displayed on screen or
report
Domain Definition

Range/Value Integrity Chec

Tables

Tables are made up of rows containing one or


more fields.
When a field is defined its data type is
determined by reference to a data element. A
data element stores a field label and online
documentation (F1 help) but also references a
domain.
A domain contains technical characteristics Data elements and domains are
data type/length.
reusable
The Data Dictionary

12

A table definition in the Dictionary

The Data Dictionary

13

Types Of Database Tables

Transparent table
Pooled table
Cluster table

The Data Dictionary

14

Pooled Table

The Data Dictionary

15

Clustered Table

The Data Dictionary

16

Viewing the Contents of a Database Table

From the
Data dictionary
Click on the table radio button & enter the table name
From the dictionary table: table/structure: display fields
screen choose utilitiestable contents

Data browser (from main menu item overview)


Enter the table name
Choose tabletable contents or press enter

Fill in the appropriate selection screen entries


Click on the execute icon on the application toolbar,
(or press F8)
The Data Dictionary
17

Number of Rows Selected

Sort Buttons

Table Name

Database Views

Different Types Of Views

DATABASE VIEWS : are implemented with an equivalent


view on the database.
PROJECTION VIEWS : are used to hide fields of a table (only
projection).
HELP VIEWS : can be used as selection method in search
helps.
MAINTENANCE VIEWS : permit you to maintain the data
distributed on several tables for one
application object at one time.

The Data Dictionary

20

Database Views

The Data Dictionary

21

Projection Views

The Data Dictionary

22

Help Views

The Data Dictionary

23

Maintenance View

The Data Dictionary

24

Search Helps & Lock Objects


The input help (F4 help) is a standard function of the
R/3 system. The user can display the list of all possible
input values for a screen field with the input help. The
possible input values can be enhanced with further
information.
The R/3 system synchronizes simultaneous access of
several users to the same data records with a lock
mechanism. When interactive transactions are
programmed, locks are set and released by calling
function modules. These function modules are
automatically generated from the definition of lock
objects in the ABAP dictionary.
25

Integrity Checking
Domain range/value integrity checks
Value table
Only values contained in the value table can be
entered in fields referring to this domain

Fixed values
Only values that match a value in the user specified
list of admissible values can be entered in fields
referring to this domain

The Data Dictionary

26

Integrity Checking
Referential integrity checking
Check table
Foreign key values must match an entry in the
specified check table
Check tables bound to input fields on data entry
screens
Position the cursor on input field and press F4 to
get a list of permissible values
The default check table for a field is the value table
of the underlying domain
From the dictionary: table/structure: display fields
screen, select GoToforeign
The Data Dictionary keys (F8)

27

Foreign Key value must match


Primary Key value of the check table

Cardinality Ratio of Foreign Key

Scroll Through Other Defined Foreign Keys

ABAP Commands

ABAP Commands Used In Assigning


Values

Move Statements

Write To Statements

Clear & Free

ABAP Commands

30

Move Statements
MOVE f TO g.
MOVE f+off1(len1) TO
g+off2(len2).

MOVE c1 TO c2 PERCENTAGE n.
Move-corresponding itab1 to
itab2.

ABAP Commands

31

Write To Statements
WRITE f TO g[+off][(len)].
WRITE f TO itab[+off][(len)] INDEX
idx.

ABAP Commands

32

Dos And Donts


DOS.

DONTS.

MOVE ITAB-F1 to ITAB-F2.


MOVE ITAB-F2 to ITAB-F3.

MOVE ITAB-F3 to ITAB-F4.

MOVE-CORRESPONDING
ITAB1 TO ITAB2.

MOVE ITAB-F4 to ITAB-F5.

ABAP Commands

33

ABAP Commands Used In String


Operations
Concatenate

Condense

Shift

Split

ABAP Commands

Replace

Translate

34

Translate STATMENTS
TRANSLATE c TO UPPER CASE.
TRANSLATE c TO LOWER CASE.
Example :
DATA letters(3) TYPE C.
MOVE xyz' TO letters.
TRANSLATE letters TO UPPER CASE.
TRANSLATE letters TO UPPER CASE.

ABAP Commands

35

Replace Statements
REPLACE f ...WITH g
...INTO h.
Example :
Data field(10).
Move XYZAB' to field.
REPLACE 'B' WITH 'string' INTO
Field.

ABAP Commands

36

Concatenate Statements
CONCATENATE f1 ... fn INTO g.
Additions :
.. Separated by h .
Example :
DATA: ONE(10) VALUE 'john',
TWO(3) VALUE 'F.',
THREE(10) VALUE 'Kennedy',
NAME(20).
Concatenate one two three into name separated by space.

ABAP Commands

37

Condense Statements
CONDENSE c.
Additions :
No-gaps.
Example :
DATA: BEGIN OF NAME,
TITLE(8)
VALUE ' dr.',
FIRST_NAME(10) VALUE 'Michael',
SURNAME(10) VALUE 'Hofmann',
END OF NAME.
Condense name no-gaps.
Output :
Dr.MichaelHofmann
ABAP Commands

38

Split Statements
SPLIT f AT g INTO h1 ... hn.
SPLIT f AT g INTO TABLE itab.

ABAP Commands

39

Example Of Split Statements


DATA : W_STRING(13 ) type c value
JOHN.F.KENEDY,
W_name1(4),
W_name2(1),
W_name3(6).
Split w_string at . into w_name1 w_name2
w_name3.

ABAP Commands

40

Contd
Types: begin of ITAB_type,
word(20),
end
of ITAB_type.
Data: ITAB type standard table of ITAB_type
with non-unique default key initial size 5.
SPLIT 'STOP two STOP three STOP
'STOP' INTO TABLE ITAB.

ABAP Commands

' AT

41

Shift Statements

SHIFT c.
SHIFT c BY n PLACES.
SHIFT c UP TO c1.
SHIFT c LEFT DELETING LEADING c1.
SHIFT c RIGHT DELETING TRAILING c1.

ABAP Commands

42

Example Of Shift Statements


Additions :
Right
.Left

Data: alpha1(10) type c value 'ABCDEFGHIJ',


alpha2 type string.
Alpha2 = alpha1.
Shift alpha1.
Shift alpha2.

ABAP Commands

43

Contd
Variants :
Shift c by n places
Example :
Data: alpha1(10) type c value
'ABCDEFGHIJ',
alpha2 type string,
five
type i value 5.
Alpha2 = alpha1.
Shift alpha1 by five places.
Shift alpha2 right by 2 places.
ABAP Commands

44

Contd

Other variants :
SHIFT c LEFT DELETING LEADING c1.
SHIFT c RIGHT DELETING TRAILING c1

ABAP Commands

45

Some Other Operations

CO --- contains only


CS --- contains string
CA --- contains any
Example :
ABCDE CS AB --- true
ABCDE CO XY --- false
ABCDE CA E --- true
ABAP Commands

46

ABAP Commands Used In


Mathematical Functions
Absolute values : ABS
Sign : SIGN
Truncate : TRUNC

ABAP Commands

47

ABAP Commands Used In Logical


Operations
EQ / =

GE / >=

LE / <=

GT / >

LT / <

NE / <>

ABAP Commands

48

Useful Keywords
Initial
If w_var1 is initial.
..
ENDIF.
Space
Data : w_var1 type c.
If w_var1 is space.
..
ENDIF.
ABAP Commands

49

ABAP Commands In Branch


Statements
IF VAR1 GT VAR2 .

IF VAR1 GT VAR2 .

WRITE : TEST1.

WRITE : TEST1.

ELSEIF VAR1 EQ VAR2.

ELSE.

WRITE : TEST2.

WRITE : TEST2.

ELSEIF VAR1 LE VAR2.


WRITE : TEST3.

ENDIF.

ENDIF.

ABAP Commands

50

ABAP Commands For Different


Loop Conditions
Loop on internal table
LOOP at ITAB.
LOOP at ITAB INTO WA_ITAB
Loop on screen fields
Loop at screen
ABAP Commands

51

Continue Statements
Continue
Effect :
CONTINUE terminates the current loop pass, return the processing to the
beginning of the loop and starts the next loop pass, if there is one
Example :
Do 100 times.
If SY-index >= 10 and SY-index <= 20.
Continue.
ENDIF.
...
Enddo.

ABAP Commands

52

Exit Statements
Exit :
Effect :
Within a loop structure:
terminates loop processing (DO, WHILE, LOOP,
SELECT).
Within subroutines and other modularization
units (but not in a loop structure):
leaves the subroutine or modularization unit
(FORM, MODULE, FUNCTION, TOP-OF-PAGE,
END-OF-PAGE).
ABAP Commands

53

More Looping
DO.

WHILE W_INDEX < 5 .

WRITE: / 'SY-INDEX

W_INDEX = W_INDEX + 1.

Begin:', (3) SY-INDEX.

WRITE: W_INDEX

IF SY-INDEX = 10.
EXIT.
ENDIF.

ENDWHILE.

WRITE: 'End:', (3) SYINDEX.


ENDDO.

ABAP Commands

54

DATABASE Commands

Update
Modify
Delete
Insert
Select

ABAP Commands

55

Database Update Statements


UPDATE dbtab SET f1 ... fn.
UPDATE dbtab. Or
UPDATE *dbtab. Or
UPDATE (dbtabname) ... .
UPDATE dbtab FROM TABLE itab. Or
UPDATE (dbtabname) FROM TABLE itab.
ABAP Commands

56

Database Delete Statements


DELETE FROM dbtab
WHERE cond.
DELETE FROM (dbtabname) WHERE cond.
DELETE dbtab.
DELETE *dbtab.
DELETE (dbtabname) ... .
DELETE dbtab
FROM TABLE itab.
DELETE (dbtabname) FROM TABLE itab.
ABAP Commands

57

Database Insert Statements

INSERT INTO dbtab [CLIENT SPECIFIED] VALUES wa.


INSERT INTO (dbtabname) [CLIENT SPECIFIED] VALUES wa.
INSERT dbtab
[CLIENT SPECIFIED].
INSERT *dbtab
[CLIENT SPECIFIED].
INSERT (dbtabname) [CLIENT SPECIFIED] ... .

INSERT dbtab

[CLIENT SPECIFIED] FROM TABLE itab.

INSERT (dbtabname)
FROM TABLE itab.

[CLIENT SPECIFIED]

ABAP Commands

58

Database Modify Statements

MODIFY dbtab.
MODIFY *dbtab.
MODIFY (dbtabname) ... .
MODIFY dbtab
FROM TABLE itab.
MODIFY (dbtabname) FROM TABLE itab.

ABAP Commands

59

Database Select Statements


SELECT Select Clause
[INTO Clause] FROM From Clause [WHERE Cond1]
[GROUP BY Fields1]
[HAVING Cond2]
[ORDER BY Fields2].

ABAP Commands

60

Example Of Select Statements


Data: WA_SBOOK type SBOOK.

Select * from SBOOK into WA_SBOOK


where
CARRID = 'LH ' and
CONNID = '0400' and
FLDATE = '19950228'
order by primary key.
Write: / WA_SBOOK-BOOKID, WA_SBOOK-CUSTOMID,

WA_SBOOK-CUSTTYPE, WA_SBOOK-smoker,
WA_SBOOK-LUGGWEIGHT, WA_SBOOK-WUNIT,
WA_SBOOK-invoice.
ENDSELECT.

ABAP Commands

61

Different Join Conditions


Inner join :
We only get the records of the crossproduct for which there is an entry in all
tables used in the view.
Outer join :
Records are also selected for which
there is no entry in some of the tables
used in the view.
ABAP Commands

62

Different Join Statements


Select ESLL~ktext1 ESLL~MENGE ESLL~MEINS
ESLL~NETWR
Into table I_ESLL
From ESLH inner join ESLH
On ( ESLH~PACKNO = ESLL~PACKNO )
Where ESLH~HPACKNO EQ
Gs_XEKPO-PACKNO
AND ESLH~DEL EQ c_space
AND ESLL~DEL EQ c_space
ABAP Commands

63

Contd ...
Select ESLL~ktext1 ESLL~MENGE ESLL~MEINS
ESLL~NETWR
Into table i_ESLL
From ESLH outer join ESLH
On ( ESLH~PACKNO = ESLL~PACKNO )
Where ESLH~HPACKNO EQ
GS_XEKPO-PACKNO
AND ESLH~DEL EQ c_space
AND ESLL~DEL EQ c_space
ABAP Commands

64

Join Conditions

ABAP Commands

65

Internal Tables

Topics of the Session:

Concept of internal table


Types of internal tables
Declaration of internal table
Commands related to internal tables
Exercise

Internal Tables

67

Internal Tables
Database tables store long-life data
Internal tables store temporary data
Table calculations on subsets of database tables
Implementing complex data structures
Reorganize the contents of database tables
according to specific processing needs
Generate ranked lists
Combine contents from more than one database table
into a single table for easier processing
Internal Tables

68

Internal Tables
Used as
Snapshots of database tables
Containers for volatile data

Exist only at runtime, (unlike database tables)


Consist of any number of records
Note that it is not necessary to declare the initial
size of the table: saps memory management
allows the table to be infinitely extensible.
Internal Tables

69

ABAP Internal Table


Types

Choose table type (and access method) by most frequently performed


operation
Standard tables
Access by linear table index or key
Response time proportional to table size
Sorted tables
Filled in sorted order
Access by linear index or sort key
Response time logarithmically proportional to table size
Hashed tables
Direct access (only) by table key
Constant, fast response time

Internal Tables

70

Internal Table Types


ABAP offers standard, sorted, & hashed types of internal
tables. The type of table that you should use (and hence the
access method) is determined by the operations that will be
performed most frequently with the table.
Standard tables
Most appropriate for general table operations. Accessed by
referring to the table index (which is the quickest access
method). Access time for standard table increases linearly
with respect to the number of table entries. New rows are
appended to the table. Individual rows are accessed by
reading the table at a specified index value.
Internal Tables

71

Internal Table Types


Sorted tables
Most appropriate where the table is to be filled in sorted order. Sorted
tables are filled using the INSERT statement. Inserted entries are sorted
according to a sort sequence defined by the table key. Illegal entries are
recognized as soon as you try to insert them into the table. Response time
is logarithmically proportional to the number of table entries (since the
system always uses a binary search). Sorted tables are particularly useful if
you wish to process row by row using a LOOP.
Hashed tables
Most appropriate when access to rows is by a key. (Cannot access hashed
tables via the table index)response time remains constant regardless of
the number of rows in the table.

Internal Tables

72

Hierarchy of Internal Table Types

Internal Tables

73

When to Use Which Table Type

Internal Tables

74

Standard Tables
(History)

Release 2.2

Only standard tables with header lines


Table structure determined with BEGIN OF
<itab> OCCURS <n> END OF <itab>.

Release 3.0
Header lines optional
Introduction of type concept

Release 4.0
Introduction of sorted & hashed table types
Allows key definition
& uniqueness attributes
Internal Tables

75

Declaring Internal Tables


DATA: <itab> TYPE <itabkind> of <linetpye>
[WITH [UNIQUE | NON-UNIQUE] <keydef>]
[INITIAL SIZE <n>]
[With header line].

<itabkind> [STANDARD] TABLE | SORTED TABLE |


Hashed table | any table
<keydef> KEY <f1><fn> |
Key table line |
Default key
Internal Tables

76

Tables With Header Line


Program Work Area

R/3 Database
Internal Tables

77

Tables Without Header Line


Program Work Area

R/3 Database
Internal Tables

78

Internal Tables - Header


Lines
Advantages of header lines
Convenient declaration
Table and header line structure declared in same statement

Ease of use
Dont have to explicitly move data into the work area
structure and then append the work area structure to the
table

Some statements require a table with header line

Disadvantages of header lines


Performance - I/O is faster
for tables without header79
Internal Tables

Internal Tables - Header Lines


Default declaration is without a header line
To declare a table with a header line
Data: itab type standard table of <type> with
header line
Types : Begin of GS_xtype,
var1 type c,
var2 type I,
.
.
Internal Tables

80

Internal Table Definition Syntax

Internal Tables

81

Standard Table Declaration


TYPES:

DATA:

begin of LineType,
F1,f2,
End of LineType.
itab TYPE STANDARD TABLE OF
LineType [WITH DEFAULT KEY]
Initial size 100
With header line.
Internal Tables

82

Sorted Table Declaration


TYPES:

DATA:

begin of LineType,
F1,f2,
End of LineType.
itab TYPE SORTED TABLE OF
LineType WITH {NONUNIQUE|UNIQUE} KEY f1
With header line.
Internal Tables

83

Hashed Table Declaration


TYPES:

DATA:

begin of LineType,
F1,f2,
End of LineType.
itab TYPE HASHED TABLE OF
LineType WITH UNIQUE KEY f1
Initial size 100
With header line.
Internal Tables

84

Declaring Internal
Tables

with reference to existing internal or database table type

DATA <itab> type <tabtypedef>


[WITH HEADER LINE].
with reference to an existing line structure

DATA <itab> like <tabtypedef>


[WITH HEADER LINE].

Internal Tables

85

Declaring Tables With a Header Line

Data: begin of itab occurs 1,


Field1(8),
Field2 type i,
End of itab.

Types: begin of itab_type,


Field1(8),
Field2 type c,
End of itab_type.
Data: itab type standard table of
itab_type
With header line.

Internal Tables

86

Declaring Tables Without a Header Line

Types: begin of itab_type,


Field1(8),
Field2 type c,
End of itab_type.
Data: itab1 type standard table of
itab_type.

Data:

itab2 like itab1.

Internal Tables

87

Do Not Declare Internal Table This


Way
Dont
Data: begin of INT_tab occurs 0,
EMP_code type i,
Name(20),
Join_date type d,
End of INT_tab.

Internal Tables

88

Accessing Internal
Tables table

work area
work area acts as interface for transferring data
read from table
contents of table line overwrite work area
program refers to work area

write to table
first enter data in the work area then transfer to table
Internal Tables

89

Generic Key Operations

Internal Tables

90

Clear, Refresh and Free Commands


Clear
Deletes the content of the header area of internal table
Does not delete the content of the internal table
Refresh
Deletes the content of the internal table
Does not delete the content of the header area
Free
Frees the memory space allocated to the internal table

Internal Tables

91

Data Transfer & Internal Tables


Filling line by line
Append, collect, insert

Copying the contents of another table


Append, insert, move

Reading line by line


Loop, read, search

Determining the attributes of an internal table


Describe
Internal Tables

92

Append
APPEND [ <wa> TO | INITIAL LINE TO] <itab>
Appends new line to itab
<wa> TO specifies the source area
<wa>
INITIAL LINE TO appends line with
each field set to default values
according to field type
To be used only with STANDARD
table

Data:

itab type standard table of


spfli ,
itab_wa like spfli.
Select * into itab_wa
From spfli.
Append itab_wa to itab.
endselect.

Internal Tables

93

Collect
COLLECT [ <wa> INTO] <itab>
used to fill an internal table which has unique table key (or
standard key for standard table if no key defined):
standard key is combination of non-numeric key fields

if table entry exists with the same table key values as the
work area <wa> or the header line of the table
COLLECT adds the contents of the numeric fields of the work
area to contents of the numeric fields in the existing entry

else
COLLECT is the same as APPEND
Internal Tables

94

Collect
Often used to generate summary
information

data:

itab type standard table of sflight,


wa like sflight.
select * into wa from sflight.
standard key fields
collect wa into itab.
endselect.
sflight-seatsocc
loop at itab into wa
write wa-carrid, wa-connid, wa_fldate, wa-seatsocc.
endloop.

Internal Tables

95

Internal Tables

96

Collect
database

header line

abc 1 6

abc 1 6

def 5 4

def 5 4

internal table
insert

abc 1 6

abc 1 6
def 5 4

abc 1 7
abc 1 7

accumulate

abc 1 13
def 5 4

Insert
INSERT [ <wa> INTO | INITIAL LINE INTO] <itab>
[INDEX <idx>].

New line is inserted before the line which has


index <idx>
If the table consists of <idx>-1 lines the new line is
inserted at the end of the table
If INSERT is used without the INDEX addition it can
be used only in a LOOPENDLOOP by adding the
new line before the current line
NB: insertion by index is not recommended for
Internal Tables
97
SORTED table nor permissible for HASHED table

System Fields Used in Table Processing

SY-TABIX
Holds the index of the current line in the table

SY-SUBRC
Return code for operation
SY-SUBRC = 0
Operation was sucessful

SY-SUBRC <> 0
Operation failed

SY-DBCNT
Number of lines that were affected by the operation
How many lines haveInternal
already
been processed
Tables

98

Copying Contents of an Internal Table


To append part or all of <itab1> to <itab2>
APPEND LINES OF <itab1> [FROM <n1>]
[TO
<n2>] TO <itab2>.
To insert part or all of <itab1> into <itab2>
INSERT LINES OF <itab1> [FROM <n1>]
[TO
<n2>] INTO <itab2> [INDEX <idx>].
To copy the entire contents of <itab1> into itab2>
MOVE <itab1> TO <itab2>.
NB: again, inserting by index will create problem with SORTED
table and not permitted with HASHED table

Internal Tables

99

Loop
LOOP AT <itab> [INTO <wa>] [FROM <n1>] [TO
<n2>] [WHERE <condition>].
Reads <itab> line by line
INTO <wa> specifies the target
area for tables without header
line
FROM & TO specify begin and
end index values (for
STANDARD and SORTED
table only)

data:

itab type standard table of


spfli,
wa like itab.

select * into table itab from spfli.


loop at itab into wa.
write: / wa-carrid, wa-connid.
endloop.

Internal Tables

100

Branching Out From the Loop


Exit:
Control goes to the end of the loop.

Continue:
Control goes to the beginning of the loop.

Internal Tables

101

READ - by INDEX
READ TABLE <itab> [INTO <wa>] INDEX <idx>.
Reads the line with index
data: itab type standard table of
<idx> from table <itab>
spfli,
faster than accessing the
wa like itab.
table with the key value
if <idx> < 0 a runtime error select * into table itab from spfli.
occurs
INDEX valid only for
read table itab into wa index 7.
STANDARD and SORTED write: / wa-carrid, wa-connid.
table
INTO <wa> specifies the target
area for tables without header
line
Internal Tables
102

READ - by TABLE KEY


READ TABLE <itab> FROM <wa2> [INTO <wa>]
READ TABLE <itab> WITH TABLE KEY <key> [INTO
<wa>]
1st variation: Reads the line
with key values matching those
in wa2
2nd variation: Reads the line
with explicit key values
specified in <key>
system reads the first entry
of itab which matches the
key value

data: begin of rectype,


f1 type I,
f2 type I,
end of rectype.
data: tab type SORTED TABLE of
rectype with unique key f1 with header
line.
Wa-f1 = 1.
read table tab from wa.

Internal Tables

103

READ - by KEY
READ TABLE <itab> [INTO <wa>]
KEY <key> [BINARY SEARCH].

WITH

Reads the line with key <key> data: itab type standard table of
from table <itab>
spfli,
system reads the first entry
wa like itab.
of itab which matches the
key value
select * into table itab from spfli.
INTO <wa> specifies the target read table itab into wa with key carrid
area for tables without header = LH connid = 0400.
line
write: / wa-carrid, wa-connid.
endloop.
Internal Tables

104

READ Variations
Defining a sequence of key fields
WITH KEY <k1> = <f1> <kn> = <fn>

Defining the entire line as key


WITH KEY = <value>

BINARY SEARCH (useful only in conjuction with


STANDARD table and HASHED table)
Table must be sorted in the order specified in the key
fields prior to the use of the READ statement with
BINARY SEARCH
Internal Tables

105

Describe
DESCRIBE TABLE <itab> [LINES <lin>] [OCCURS
<occ>].

Allows you to find out how many lines are


contained in your internal table or how large you
have defined the OCCURS parameter when you
declare <itab>

Internal Tables

106

Changing the Contents of an Internal Table

Changing lines
Modify
Write to
Not recommended. Does not recognise the structure of
a table line. Overwrites section of table line even across
fields from start pos for length len

Deleting lines
Selected lines in a loop
Using the index
Adjacent duplicate lines
Internal Tables

107

Modify
MODIFY [TABLE] <itab> [FROM <wa>] [INDEX <idx>]
[TRANSPORTING <f1><fn>] [WHERE <cond>].
Replaces a line in <itab> with
contents of <wa>
INDEX option specifies the target
line of <itab>
can be used only with standard
and sorted table
without index, the target line is
determined by search key
TRANSPORTING moves only the
named fields from <wa> to <itab>

data:

itab type standard table of


spfli,
wa like itab.

select * into table itab from spfli.


wa-fldate = 19982201.
wa-price = 1912.50.
modify itab from wa index 5
transporting fldate price.

Internal Tables

108

Delete
DELETE <itab>.
Deletes line from itab
can be used only in a loop

data:

itab type standard table of


spfli,
wa like itab.

select * into table itab from spfli.


loop at itab into wa.
if wa-carrid = LH.
delete itab.
endloop.

Internal Tables

109

Delete
DELETE <itab> INDEX <idx>.
deletes line from itab with
data: itab type standard table of
index <idx>
spfli.
after deleting the line the index
of the following lines is
select * into table itab from spfli.
decremented by one
delete itab index 5.
not allowed with hashed table

Internal Tables

110

Delete
DELETE ADJACENT DUPLICATES
<itab> [COMPARING <comp>].
deletes all adjacent duplicate
lines from itab
without COMPARING
uses table key to determine
duplicates
with COMPARING
uses the contents of the
specified fields in <comp>
to determine duplicates

data:

FROM

itab type standard table of


spfli.

select * into table itab from spfli.


delete adjacent duplicates from itab
comparing carrid.

Internal Tables

111

Delete
DELETE <itab> [FROM <n1>] [TO <n2>] [WHERE
<condition>].
deletes all lines from itab
where index is between n1 and
n2
without FROM
starts from first line
without TO
deletes to end of table
without WHERE
unconditional deletion of
lines between n1 and n2

data:

itab type standard table of


spfli.

select * into table itab from spfli.


delete itab from 2 to 12 where carrid
= LH.

Internal Tables

112

Sort
SORT <itab> [<order>] [AS TEXT] [BY <f1> [<order>]
[AS TEXT] ... [BY <f1> [<order>] [AS TEXT] .
without BY
data: itab type standard table of
uses table key to sort
spfli.
<order>
ASCENDING or
select * into table itab from spfli.
DESCENDING
as TEXT
sort itab by carrid connid descending.
char fields sorted
alphabetically rather than by
internal binary
representation
Internal Tables
113

Appendsorted By
APPEND [<wa> TO] <itab> SORTED BY <f>.
Uses only with standard table
builds itab sorted by <f>
descending sort order
it <itab> is less then 100 lines
use APPEND SORTED BY
otherwise use SORT after
table is populated
table can contain only the
number of lines specified in the
OCCURS clause

data:

itab type standard table of


spfli ,
itab_wa like spfli.

select * into itab_wa from spfli.


append itab_wa to itab sorted by
cityfrom.
endselect.

Internal Tables

114

Dos & Dont

Use read within a loop


Select before the loop and then
read the data or use for all
entries addition with the select
statement
Check whether itab is initial
before using for all entries

Do not use nested loop


Do not select data from
database table within a loop
Do not use binary search
without sorting

Internal Tables

115

Summary of Internal Table Operations

Standard Table
INSERT
COLLECT
MODIFY
DELETE
READ
LOOP
n
INSERT
APPEND
MODIFY
DELETE
READ
LOOP
SORT

Sorted Table

works like append

inserts in
correct position

sort sequence
may be broken

Internal Tables

see above

Hashed Table
works like append

No Index
Operations

116

Simple Reports

What Is a Report

Executable program with a three-stage


function:
Data input data processing data
output.
Reports: reading and processing of data
using data from database tables,
without actually changing it.

Reports

118

Report Programming Overview


Task of a report
Evaluate and display data from the database

Reports are stand alone programs


Reports are controlled by events
Program events are always triggered externally
React to events by
Programming the corresponding processing block
Ignore the event by not programming the corresponding
block
Reports

119

Report Programming - Overview


Reports can use logical databases
Special ABAP programs which define
Database tables that can be used by the program
Relationship between these tables (via primary key foreign key links)
Database accesses
Selection screen options

SAP provides logical databases for each


application area
Users can also defineReports
logical databases

120

Report Programming Overview


Report processing is controlled by events
Processing the selection screen
Presenting the selection screen, validating user inputs
Reading the database
Logical database events
Evaluating data and creating lists
Outputting the list
Interactive list events are triggered by user mouse clicks
If the program contains no event keywords
Entire program belongs to the standard event which is
121
triggered after selectionReports
screen processing

Purpose of Report

Reports are used by management as a tool


to monitor the day to day activity in the
organization.
Basically reports are used to provide data
to the user in a desired format.

Reports

122

Structure of Report

Report statement and report driven list


headings
Processing blocks
Control level statements
Subroutines
Includes

Reports

123

Concept of Flow Control in


ABAP
Internal control
Branching (IF, CASE)
Looping (DO, WHILE)
External control
Events
Runtime events
User events
System does not necessarily process the statement blocks in the
same order as they appear in the source code

Reports

124

Concept of Flow Control in


ABAP
event keyword

external control

event begin
processing block
internal control

event end

event keyword

external control

processing block
internal control
...
Reports

125

Internal Control
Statements
If

IF statements can be
nested to any level.
All IF statements must
be terminated with
ENDIF in the same
processing block.

IF logexpr1.
Processing1.

ELSEIF logexpr2.
Processing2.

Else.
processingN.

ENDIF.
Reports

126

Internal Control
Statements
Case
CASE f.
WHEN f11 or f12 or f1n.
Processing f1.
WHEN f21 or f22 or f2n.
Processing f2.
When .
When others.
Processing others.
ENDCASE.

F is a variable name
F11..fnn may be variables or
literals
CASE statements can be
nested
No further WHENs can follow
WHEN OTHERS

Reports

127

Internal Control Statements

Iteration
Do ENDDO.
Loop ENDLOOP.
While ENDWHILE.
Select ENDSELECT.

Breaking out of a loop


Exit, stop, reject

Selective loop processing


Continue, check

Reports

128

Do ... Enddo
Variations
Do ... ENDDO.
DO n TIMES ... ENDDO.

Additions
VARYING f FROM f1 NEXT f2.

Basic form, DO...Enddo must contain a loop


termination statement
Exit, reject, stop

Can process/skip current loop pass


Reports

129

Do ... Enddo
Sum = 0.
Do
Sum = sum + sy-index.
Counter = counter + 1.
Write sum.
If counter > 10.
Exit.
endif.
Enddo.

Sum = 0.
Do 10 times
Sum = sum + sy-index.
Write sum.
Enddo.

Reports

130

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)
Conditional loops (WHILE...Endwhile)
Subroutine (FORM...ENDFORM)
Reports
Function (FUNCTION...ENDFUNCTION)

131

Stop
Cancels all data selection
No further tables are read
Followed immediately by the END-OFSELECTION event
IF logexp.
Stop.

ENDIF.
Reports

132

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.

Reports

133

Continue
Terminates the current loop pass and returns
processing to the beginning of the next loop
pass (if there is one)
Excludes lines where logexp is true from the list

IF logexp.
Continue.

ENDIF.
Reports

134

Check
CHECK logexp
Evaluates the subsequent logical expression
Expression is true
Processing continues with the next statement

Expression is false
Terminates the current loop pass and goes back to the
start of the next loop pass (if there is one)

Negative CHECK in a subroutine terminates the


subroutine
Negative CHECK not in loop or subroutine
Reports

135

While Endwhile
Variations
WHILE logexp ... ENDWHILE.

Additions
VARYING f FROM f1 NEXT f2.

Performs loop body statements while logexp is


true
Pretest loop

Can contain other nested loop structures


Reports

136

Select ENDSELECT
Used for processing lines of data returned
directly from a database table
Variations
SELECT < * | field list > [target]
FROM <table>
* Where +
* Group by +
* Order by +
ENDSELECT.
Reports

137

LOOP AT <itab> ENDLOOP


Used for processing internal tables
Variations
LOOP at itab.
Endloop.
LOOP at itab INTO wa.

Endloop.

Additions
From n1
To n2
Where logexp
Reports

138

The ABAP
Processor
ABAP program is a collection of processing
blocks which are executed in response to
specific events
Processing blocks do not have to occur in any
specific order
At program start time the system starts a process,
(the ABAP processor)
Calls these modules
Controls the external
program flow
Reports

139

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
Reports

AT PF<nn>
140

Events & Their


Keywords
Runtime events
Selection screen events
Initialization
At selection-screen

Events after selection criteria has been


processed
Start-of-selection
End-of-selection
Reports

141

Events & Their Keywords


During list processing
first line of new page
Top-of-page
last line of current page
End-of-page
During display of (interactive) list
At line-selection
user double clicks on a report line
At user-command
user clicks on command button or presses
AT pf<nn>
function key

Reports

142

Run-Time Events
Initialization
Processed before the presentation of the
selection screen
Can be used to initialise values in the selection
screen or to assign values to any parameters
that appear on the selection screen

Reports

143

Run-Time Events
At selection-screen
Processing block is started after the user has
specified all the criteria in the selection screen
If an error message is displayed from this
processing block the system displays the
selection screen again and all input fields can
be changed

Reports

144

Run-Time Events
Start-of-selection
Processing block that is executed after
processing the selection screen and before
accessing database tables using a logical
database
Use this processing block to set the value of
internal fields
All statements that are not attached to an
event keyword or in a subroutine are
processed in this event
Reports

145

Run-Time Events
End-of-selection
Processing block executed after the system has
read and processed all database table records

Reports

146

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
Reports

147

End Of Page

This event occurs to define a page


footer,if, while processing a list page,
the system reaches the lines reserved
for the page footer, or if the RESERVE
statement triggers a page break.

Reports

148

Control Level Statements


1.

At new <f> - beginning of a group of lines with the same contents in the field <f>
and in the fields left of <f>

2.

At end of <f> - end of a group of lines with the same contents in the field <f> and in
the fields left of <f>

3.

At first first line of internal table

4.

At last last line of internal table

, you can use special


control structures for control break
processing. All these structures begin with
AT and end with Endat. The sequence of
statements which lies between them is then
executed if a control break occurs.
In a loop which processes an internal table

Reports

149

Control Level Statements


If you have sorted an extract dataset by the fields <f1>, <f2>, ..., the
processing of the control levels should be written between the other
control statements as follows:
Loop.
At first.... ENDAT.
AT NEW <f1>....... ENDAT.
AT NEW <f2>....... ENDAT.
...

<Single line processing without

control statement>

...
at end of <f2>.... ENDAT.
AT END OF <f1>.... ENDAT.
At last..... ENDAT.
Endloop.
Reports

150

Control Level Statements - SUM


The ABAP statement SUM can be used only
within a loop.
When used in an AT ENDAT block, the
system calculates the totals for the numeric
fields of all lines in the current line group and
writes them to the corresponding fields of the
work area.
E.G.
Loop at ITAB into line.
At end of col1.
Reports

151

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
Reports

152

Report Statement

<Len> shows the length of the total report


length.
<N> will reserve n no of lines as space for
the page footer.
LINE-SIZE this specify the width of the
report.
MESSAGE-ID this contains the ID where
messages to be used are stored.
Reports

153

SELECT Overview
SELECT <result>

which columns?

FROM <table>

which table?

INTO <target>

where to?

WHERE <condition>

which entries?

GROUP BY <fields>

how are they grouped?

ORDER BY <fields>

how are they arranged?

Reports

154

Single or Multiple Entries


SELECT <result> FROM <table> ... ENDSELECT.
SELECT SINGLE <result> FROM <table> WHERE..
Select accesses all records
matching the selection criteria
Allows line by line processing
using SELECT...ENDSELECT
Select single returns first row that
matches the selection criteria

select * into wa
from spfli
where carrid = LH.
endselect.
select single * into wa
from spfli
where carrid = LH.

Reports

155

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
Reports

156

SELECT <result> INTO ...


<wa>
<result> fields placed left to right into components of <wa>

(<f1>, <f2>, ... <fn>)


<result> fields placed left to right into fields <f1> <f2> ... <fn>

TABLE <itab>
selected data not processed line by line but all at once

CORRESPONDING FIELDS OF <wa>


<result> fields placed into fields in <wa> which have the corresponding name

CORRESPONDING FIELDS OF TABLE <itab>


as above except selected data is placed in <itab> all at once

Reports

157

WHERE

<table field> <operator> <value>


<table field> BETWEEN <value> AND <value2>
<table field> LIKE <pattern>
<table field> CONTAINS <pattern>
<table field> IN ( <value1>, <value2> ... )
<table field> IN <seltab>

Reports

158

<operator>

EQ
GE
LE

=
>=
<=

NE
GT
LT

<>
>
<

=>
=<
><

Reports

159

<pattern>
special characters _ and %
_
represents a single character

%
represents any sequence of characters

Select * from SPFLI


Where Cityfrom Like S%.
Reports

160

GROUP BY <f1> <f2> ...


combines groups of entries into single entries
a group consists of entries that have identical
<f1> <f2> ...
SELECT list
must contain <f1> <f2> ...
fields other than <f1> <f2>... must be aggregate
functions , eg. SUM( LUGGWEIGHT )

Reports

161

ORDER BY
determines sort order of selected result table

...ORDER BY PRIMARY KEY

sorts entries by primary key of the database table

...ORDER BY <f1> [ASCENDING | DESCENDING]


<f2> [ASCENDING | DESCENDING] ...

default sort order is ascending

Select Carrid Connid CityFrom Cityto


From SPFLI
Order by Carrid Connid CityTo Descending.
Reports

162

Message & Message Class

Messages are grouped together into an


object called message class where
individual messages are identified by an
unique number.
Transaction code : SE91

Reports

163

Different Message Types


A

Termination

The message appears in a dialog box, and the program terminates. When the
user has confirmed the message, control returns to the next-highest area menu.

Error

Depending on the program context, an error dialog appears or the program


terminates.

Information

The message appears in a dialog box. Once the user has confirmed the
message, the program continues immediately after the MESSAGE statement.

Status

The program continues normally after the MESSAGE statement, and the
message is displayed in the status bar of the next screen.

Warning

Depending on the program context, an error dialog appears or the program


terminates.

Exit

No message is displayed, and the program terminates with a short dump.


Message type X allows you to force a program termination.

Reports

164

Messages in Reports
messages are stored in table T100

REPORT <reportname> MESSAGE-ID xx.


xx represents an application area
Reports

165

Messages in Reports
MESSAGE xnnn.
x is one of
I
Info
W Warning
list level
E
Error
list level
A
Abend
message
X
Exit
termination
S
Success

Displayed

Outcome

window
status line

resumes processing
terminates current

status line

terminates current

window

termination after

status line

immediate

status line

resumes processing

Reports
nnn is the message number

166

Messages in Reports
MESSAGE xnnn *WITH <f1><f4>+.
& characters serve as placeholders in a message
200 Level &1 not allowed here
WITH option allows contents of fields < fi > to replace the &i
according to the value of I
MESSAGE E200 WITH SY-LSIND.

Reports

167

Messages in Reports
MESSAGE ID <id> TYPE <x>
NUMBER <nnn> *WITH <f1> <f4>+.
allows a message to be specified dynamically at runtime
do not need the MESSAGE-ID xx option in the REPORT
statement
<id> is the message application area
<x> is the message type (I, W, E, A, X, S)
<nnn> is the message number

Reports

168

Write Statements
Write : / Var1 As Checkbox.
Write : / Var2 As Symbol.
Write : / Var3 As Icon.
Write : / Var4 As Line.

Reports

169

Several Options In Write


Statements

NO-ZERO
NO-SIGN
DD/MM/YY
LEFT-JUSTIFIED
RIGHT-JUSTIFIED
CENTERED
USING EDIT MASK mask
USING NO EDIT MASK
DECIMALS d
Reports

170

Several Options In Write


Statements
No-gap

No grouping
CURRENCY w

EXPONENT e
ROUND r

Reports

171

Formatting of Report

Report can be printed using various


statements like -:
Write
Write:[/][<pos>][(<len>)] <f>
E.G.
WRITE:
'one',
/ '
',
/ 'two'.
Reports

172

Output Format of Predefined Types


c

field length

left-justified

field length

left-justified

11

22

right-justified
right-justified

2*fieldlength (+1)

right-justified

left-justified

left-justified

2*field length
Reports

left-justified
173

Positioning Output
WRITE AT [/] [pos] [(len)] <f> .
/ Denotes new line
<Pos>
Horizontal position
Always output at that position regardless of whether there is
enough space or other fields overwritten
(<Len>)
Output length
If <len> is too short
Numeric fields truncated (left), asterisk displayed
All others truncated (right) with no indication
Reports

174

Some Examples of Pos (Len)


data: word(16)
value '0123456789ABCDEF',
col type i value 5,
len type i value 10.
write /5(12)
word.
0123456789AB
write at col(len) word.
0123456789
write /(3) 12345.
*45
write: /5(8) word, 25(2)word.
01234567

Reports

01

175

Formatting Options All Data


Types
WRITE <f> <option1> <option2> ....

LEFT-JUSTIFIED
RIGHT-JUSTIFIED
CENTERED
UNDER <g>
NO-GAP
USING EDIT MASK <m>
USING NO EDIT MASK
NO-ZERO
COLOR <c>

Output is left justified


Output is right justified
Output is centered
Output starts under field <g>
Blank after field <f> is omitted
Specifies a format template <m>
Deactivates a template
All zero field replaced by blanks
Color of output specified by <c>
Reports

176

Formatting Options - Examples


data c(10) value text.
write: / Left Just :, c left-justified.
write: / Right Just:, c right-justified.
write: / Centered :, c centered.
write: / aaa , bbb , ccc , ddd.

Left Just : text


Right Just: text
Centered : text
aaa bbb ccc ddd

write: / c under bbb

text
write: / c using edit mask _:_%_8_!. t:e%x8t!
Reports

177

Formatting Options - Numeric


Fields

NO-SIGN
DECIMALS <d>
EXPONENT <e>
ROUND <r>

CURRENCY <c>
UNIT <u>

Leading sign is not output


Output has <d> digits after decimal
Type f fields exponent defined in <e>
Type p fields are divided by 10**(r)
and then rounded
According to definition of <c> in table
TCURX
Number of decimal places is fixed
according to the definition of <u> in
table T006 for type p fields
Reports

178

Formatting Options - Date Fields


WRITE <f>

DD/MM/YY
MM/DD/YY
DD/MM/YYYY
MM/DD/YYYY
DDMMYY
MMDDYY
YYMMDD
Reports

179

Formatting Options - Examples


Data

X type p value -12345.678,


F type f value -12345.678,
D type d value 19980323.
Write: / X decimals 2.
12,346.000Write: / F decimals 2.
-1.235e+04
Write: / X exponent 2.
12,346Write: / F exponent 2.
-123.4567800000000e+02
Write: / D DD/MM/YY
23/03/99

Reports

180

Format
formatting options used in a WRITE statement overwrite the
corresponding settings of a previously issued FORMAT
statement for the current output
for each new event the system resets all formatting options to
their default values
all options have a default value of OFF except the
INTENSIFIED option
FORMAT RESET
sets all formatting options to OFF in one go

Reports

181

COLOURS IN LISTS
FORMAT COLOR = <c>
INTENSIFIED = <int>
INVERSE =<inv>

COLOR sets colour of line background


INVERSE influences the foreground colour
INVERSE ON sets the foreground to the selected COLOR option
INTENSIFIED determines the colour palette for the line background

Reports

182

LIST COLOUR OPTIONS


<n>

<c>

Colour

Intended For

OFF or COL_BACKGROUND

depends on GUI background

1 or COL_HEADING

grey-blue

headings

2 or COL_NORMAL

light grey

list bodies

3 or COL_TOTAL

yellow

totals

4 or COL_KEY

blue-green key columns

5 or COL_POSITIVE

green

pos threshold value

6 or COL_NEGATIVE

red

neg threshold value

7 or COL_GROUP

violet

group levels

Reports

183

Color Examples
Data:
I type i value 0, col(15).
While I < 8.
Case I.
When 0. Col = COL_BACKGROUND.
When 1. Col = COL_HEADING.
When ...
endcase.
Format intensified color = I.
Reports

184

Output of Color: Example

Reports

185

On Screen Lines & Blank


Lines
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>.

Reports

186

Creating Blank Lines


SET BLANK LINES [ON | OFF]
OFF
system suppresses blank lines created by WRITE
SKIP [<n>]
if <n> greater than lines remaining on page
produces page footer, throws to new page
at the beginning of a new page
ignored except if page created by NEW-PAGE or if page is the
first of a list level
last output statement of last list page

ignored

Reports

187

Formatting Options - RESERVE


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).
Reports

188

System Fields for Lists


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
Reports

189

System Fields for Lists


SY-title
Title that appears in the title bar of the display window
Can be manipulated by
Maintaining text elements
Using SET TITLEBAR <titlestring>.
SY-SROWS
Current number of lines in display window
SY-SCOLS
Current number of columns in display window
Reports

190

Selection Screens

Objective
Concepts associated with

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


Radio button groups, checkboxes

Executing reports with variants

Selection Screen

192

Selection Screens
Used to allow the user to control the database
selections of the report
Allows interactive
Assignment of values to variables
With the PARAMETERS statement

Determine selection criteria for database fields


Single values, range of values, sets of values, ...
With the SELECT-OPTIONS statement

Selection Screen

193

Defining Selection Screen


3 ABAP statements for defining selection
screens
PARAMETERS for single fields
SELECT-OPTIONS for complex selections
SELECTION-SCREEN for formatting the
selection screen and defining user-specific
Selection Screen

194

Parameters
Used to enable user to enter values for single
fields on the selection screen
Define variables in the program using
PARAMETERS statement.
Basic form of PARAMETERS statement:
PARAMETERS <p>[(<length>)] [TYPE
<type>|like <obj>] [DECIMALS <d>].
Selection Screen

195

Parameters Variants
PARAMETERS <p> ...... DEFAULT <f> ......
PARAMETERS <p> ...... OBLIGATORY ......

PARAMETERS <p> ...... LOWER CASE ......


PARAMETERS <p> ...... AS CHECKBOX ......
PARAMETERS <p> ...... RADIOBUTTON GROUP
<radi>......
Selection Screen

196

The Parameters Keyword


PARAMETERS <field> TYPE <type> [DEFAULT <value>].

PARAMETERS: P1 TYPE P,
P2(6) TYPE C DEFAULT ITB255.

P1
P2

ITB255
Selection Screen
Selection Screen

197

Select-options
Allow the user to easily handle complex
selections
Basic form of the SELECT-OPTIONS statement :
SELECT-OPTIONS <seltab> for <f>.

<F> is a column of a database table or an


internal field in the program.
Selection Screen

198

Select-options Contd..
Structure of selection tables
SIGN type C length 1
Values I or E
OPTION type c length 2
Values EQ, NE, LT, BT, etc.

LOW data type same as of <f>


HIGH data type same as of <f>
Selection Screen

199

Select-options Variants
SELECT-OPTIONS <seltab> FOR <f> DEFAULT
<g> [TO <h>] ....
SELECT-OPTIONS <seltab> FOR <f> ...
LOWERCASE ..............
SELECT-OPTIONS <selcrit> FOR <f> ...
OBLIGATORY ..............
SELECT-OPTIONS <seltab> FOR <f> ..... NOEXTENSION .....
SELECT-OPTIONS <seltab> FOR <f> ..... NO
INTERVALS .....
Selection Screen

200

REPORT ZSAPTEST.
TABLES: SFLIGHT.
SELECT-OPTIONS: AIRLINE FOR SFLIGHT-CARRID,
CONN
FOR SFLIGHT-CONNID.

multiple selection screen


Selection Screen

201

Selection-screen
SELECTION-SCREEN SKIP [<n>].
SELECTION-SCREEN ULINE [[/]<pos(len)>]
SELECTION-SCREEN COMMENT [/]<pos(len)>
<comm> [FOR FIELD <f>]

Selection Screen

202

Selection-screen Elements on a
Single Line
Several Elements in a Single line
SELECTION-SCREEN BEGIN OF LINE.
...
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN POSITION <pos>.
E.g.
SELECTION-SCREEN BEGIN OF LINE.
Selection Screen

203

Selection-screen Blocks of
Elements
Create logical block of elements on selection
screen
SELECTION-SCREEN BEGIN OF BLOCK <block>
[WITH FRAME [TITLE <title>]]
[NO INTERVALS].
...
Selection-screen end of block <block>.
E.G.
Selection-screen begin of block rad1
with frame title text-002.
Selection Screen

204

Calling Selection-screen
Standard selection screen
Called automatically between the INITIALIZATION
and START-OF-SELECTION events.

User-defined selection screen


CALL SELECTION-SCREEN <numb> [STARTING AT
<x1> <y 1>]
[ENDING AT <x2> <y 2>].

Selection Screen

205

Modifying Screens Dynamically


The screen table
Screen is like an internal table with header line
Do not need to declare it in your program
Cannot use any work area other than its header line to
address it
Some components of screen table
Name
Input
Output
Required
Intensified
Selection Screen
Invisible

206

Loop at Screen
You can modify screen in your ABAP program
The only statements that can be used with
SCREEN are

Loop at screen.
...
Modify screen.
...
Endloop.
No further additions are allowed in the LOOP
AT SCREEN statement
Selection Screen

207

Loop at Screen Contd..


E.G.
Loop at screen.
IF screen-group1 = 'MOD'.
IF flag = ' '.
Screen-input = '0'.
ELSEIF flag = 'X'.
Screen-input = '1'.
ENDIF.
Modify screen.
Selection Screen

208

Selection Screen Events

At selection-screen
At selection-screen output
At selection-screen on
At selection-screen on block
At selection-screen on help-request
At selection-screen on RADIOBUTTON
At selection-screen on value-request
Selection Screen

209

At Selection-screen
Basic form of a series of events
These events are called between
INITIALIZATION and START-OF-SELECTION.
Defined to change selection screen or process
user input, i.E. Validations, etc.
Selection Screen

210

Contd..
At selection-screen output
Allows you to modify selection-screen directly before it is displayed.
E.G.
Parameters: test1(10),
test2(10),
test3(10),
test4(10).
At selection-screen output.
Loop at screen.
If screen-name = test1'.
Screen-intensified = '1'.
Modify screen.
Continue.
ENDIF.
If screen-name = test3'.
Screen-input = '0'.
Modify screen.
ENDIF.
Endloop.
Selection Screen

211

Contd..
AT SELECTION-SCREEN ON <field>
Is triggered when the contents of the field are
passed from the selection screen to the ABAP
program.
E.G.
At selection-screen on test1.
IF TEST1 = not OK.
Message e001.
ENDIF.
Selection Screen

212

Contd..
AT SELECTION-SCREEN ON BLOCK <block>
Is triggered when the contents of all of the fields in a block are passed from the
selection screen to the ABAP program
E.G.
Selection-screen begin of block part1 with frame.
Parameters: number1 type i,
number2 type i,
number3 type i.
Selection-screen end of block part1.
At selection-screen on block part1.
If number3 LT number2 or
number3 LT number1 or
number2 LT number1.
Message e020.
ENDIF.
Selection Screen

213

Contd..
AT SELECTION-SCREEN ON HELP-REQUEST FOR <field>
Is triggered when the user calls the F1 help for the
field <field>.

E.G.
At selection-screen on help-request for p_CARR_2.
Call screen 100 starting at 10 5
ending at 60 10.

Selection Screen

214

Contd..
AT SELECTION-SCREEN ON RADIOBUTTON GROUP <radi>
Is triggered when the contents of all of the fields in a radio
button group are passed from the selection screen to the
ABAP program
E.G.
At selection-screen on RADIOBUTTON group rad1.
If r1 = 'x'.
Message w040.
ENDIF.

Selection Screen

215

Contd..
AT SELECTION-SCREEN ON VALUE-REQUEST FOR <field>
Is triggered when the user calls the F4 help for the
field <field>
E.G.
At selection-screen on value-request for p_CARR_2.
Call screen 100 starting at 10 5
ending at 50 10.
Module value_list output.

Selection Screen

216

<seltab>
<seltab> is an internal table with 4 fields
SIGN
I
E

OPTION

LOW

HIGH

EQ
NE
LT
GT
LE
GE
BT
NB
CP
NP
Selection Screen

217

<seltab> and Database Selections


If the <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
Selection Screen

218

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


Selection Screen

219

REPORT ZSAPTEST.
TABLES: SFLIGHT.
SELECT-OPTIONS: AIRLINE FOR SFLIGHT-CARRID
DEFAULT AA TO LH
OPTION NB
SIGN I.

Selection Screen

220

Assigning Default Values to Selection Criteria


REPORT ZSAPTEST.
TABLES: SPFLI, SFLIGHT, SBOOK.
SELECT-OPTIONS:AIRLINE FOR SPFLI-CARRID,
CONN FOR SPFLI-CONNID.
INITIALIZATION.
MOVE LH TO AIRLINE-LOW.
MOVE UA TO AIRLINE-HIGH.
MOVE I TO AIRLINE-SIGN.
MOVE BT TO AIRLINE-OPTION.
APPEND AIRLINE.
CLEAR AIRLINE.
MOVE 0400 TO CONN-LOW.
MOVE I
TO CONN-SIGN.
MOVE EQ TO CONN-OPTION.
APPEND CONN.
Selection Screen

221

Selection Screen

222

Restricting the Selection Screen to One Line

SELECT-OPTIONS <seltab> FOR <f> NOEXTENSION .


right arrow
does not
appear on the selection screen
user cannot access the
multiple succession screen

REPORT ZSAPTEST.
TABLES: SFLIGHT.
SELECT-OPTIONS AIRLINE
FOR SFLIGHTCARRID
NO-EXTENSION.

Selection Screen

223

Restricting the Selection Screen to Single Value Selection

SELECT-OPTIONS <seltab> FOR <f> NO INTERVALS


.
TO field does not appear on
the selection screen
user can access the multiple
succession screen

REPORT ZSAPTEST.
TABLES: SFLIGHT.
SELECT-OPTIONS AIRLINE
FOR SFLIGHTCARRID
NO INTERVALS.

Selection Screen

224

Further Selection Screen Options


NO-DISPLAY
suppresses display of selection screen criterion
LOWER CASE
enables acceptance of upper & lower case letters
OBLIGATORY
makes selection for FROM field mandatory
MEMORY ID <pid>
uses default values from SAP memory for FROM field
MODIF ID <key>
assigns fields of a selection criterion to a modification group
MATCHCODE OBJECT <obj>
assigns a matchcode object to the FROM & TO fields of a selection
criterion
Selection Screen

225

Selection Tables in WHERE


Conditions
WHERE <f> IN <seltab>
<f> is a database column (without a prefix)
<seltab> is the selection table atached to <f>
REPORT ZSAPTEST.
TABLES: SFLIGHT.
SELECT-OPTIONS AIRLINE FOR SFLIGHT-CARRID.
SELECT * FROM SFLIGHT
WHERE CARRID IN AIRLINE.
Selection Screen

226

Checkboxes on the Selection


Screen
PARAMETERS <p> AS CHECKBOX ...
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
Selection Screen

227

Checkboxes on the Selection


Screen
REPORT ZSAPTEST.
TABLES: SPFLI, SFLIGHT, SBOOK.
SELECT-OPTIONS:
SDEPART FOR SPFLI-DEPTIME,
PARAMETERS: CURRENCY LIKE SFLIGHT-CURRENCY,
LUGGAGE AS CHECKBOX.

Dep.Time

to

Price

to
Show Luggage Weight

Selection Screen

228

Radiobuttons on the Selection


Screen
PARAMETERS <p>
RADIOBUTTON GROUP <radi> ...
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

<radi> string of max length 4


must assign at least 2 parameters to each <radi> group

user click on radiobutton


respective parameter is activated, ie, assigned X
only one parameter in each group can be activated
Selection Screen

229

Radiobuttons on the Selection Screen


PARAMETERS: DISCOUNT RADIOBUTTON GROUP R1,
ECONOMY RADIOBUTTON GROUP R1,
BUSINESS RADIOBUTTON GROUP R1,
FIRST
RADIOBUTTON GROUP R1
DEFAULT X.

DISCOUNT
ECONOMY
BUSINESS
FIRST
Selection Screen

230

Formatting the Selection Screen


SELECTION-SCREEN statement allows
insertion of texts/comments
underlines
insertion of blank lines

SELECTION-SCREEN BEGIN OF BLOCK


combine logically related fields
draw a box around them using WITH FRAME
Selection Screen

231

Formatting the Selection


Screen
SELECTION-SCREEN
BEGIN OF LINE
COMMENT <format> <name>
POSITION <n>
SELECTION-SCREEN
END OF LINE.

REPORT ZSAPTEST.
TABLES: SPFLI, SFLIGHT, SBOOK.
SELECTION-SCREEN: BEGIN OF LINE,
COMMENT 1(11) TEXT-002,
POSITION 33.
PARAMETERS: PRICE LIKE SFLIGHT-PRICE OBLIGATORY.
SELECTION-SCREEN: COMMENT 55(8) TEXT-003,
POSITION 65.
PARAMETERS: CURRENCY LIKE SFLIGHT-CURRENCY OBLIGATORY.
SELECTION-SCREEN END OF LINE.
Selection Screen

232

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

Selection Screen

233

Formatting the Selection Screen


SELECTION-SCREEN BEGIN OF BLOCK <block>
WITH FRAME
TITLE title
SELECTION-SCREEN END OF BLOCK <block>.

REPORT ZSAPTEST.
TABLES: SPFLI, SFLIGHT, SBOOK.
SELECTION-SCREEN BEGIN OF BLOCK SPFLI
WITH FRAME TITLE TEXT-001.
SELECT-OPTIONS CARR FOR SPFLI-CARRID DEFAULT LH.
SELECT-OPTIONS CITY FOR SPFLI-CITYFROM
DEFAULT BERLIN.
SELECT-OPTIONS DEPART FOR SPFLI-DEPTIME
DEFAULT 100000 TO 130000.
SELECTION-SCREEN END OF BLOCK SPFLI.
Selection Screen

234

Formatting Selection Text


default text on the selection screen
PARAMETERS <pname>
SELECT-OPTIONS <seltab>

more explanative text


Text Maintenance Selection Texts
SELECT-OPTIONS BEGIN OF LINE COMMENT ...

Selection Screen

235

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.
...
Selection Screen

236

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
Selection Screen

237

Save as Variant

Selection Screen

238

Setting Attributes of a Variant


Variant Attributes
protected
only creator can change it
do not display variant
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
Selection Screen

239

Running a Report With a Variant


Execute the report
Click on the 'Get Variant' button of the selection
screen
Select a variant from the next dialog box

Selection Screen

240

Running a Report With a


System Services ReportingVariant
Click on
select a

variant from the next dialog box

SUBMIT <reportname> USING


SELECTION-SET <variantname>
Selection Screen

241

Conclusio
n

Examined methods of providing the user with


some measure of control over database
selections via the provision of a selection
screen
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
Selection Screen

242

Conclusion
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
Selection Screen

243

Conclusion
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
Selection Screen

244