You are on page 1of 60

Here is very compact but full in details ABAP/4 Reference.

Content.
Preliminaries. Data Declaration. Data Processing. List Processing.
Internal Tables Processing. Selection Screens. Field Symbols. Modularization.

Preliminaries:

• Notation.
• Literals.
• Elementary Data Types.
• Correspondence between ABAP/4 Dictionary Data Types and Elementary Data
Types.
• Specifying Offset Values for Data Objects.
• Conversion Rules:
o Elementary Data Types.
o Field Strings.
o Internal Tables.
o Alignment of Data Objects.
• Formatting Options.

Declaring Data:

• Types Definition:
o TYPES.
 Elementary Types.
 Internal Tables.
 Lines of Internal Tables.
 Field Strings.
o TYPE-POOLS.
• Data Definition:
o TABLES.
o DATA.
o CONSTANTS.
o STATICS.
o Determining the Attributes of Data Objects (DESCRIBE FIELD|TABLE).

Data Processing:
• Assignment Operations:
o Assignment Operator.
o MOVE TO.
o MOVE-CORRESPONDING.
o WRITE TO.
o CLEAR.
o FREE.
• Numerical Operations:
o COMPUTE.
o Using Mathematical Functions.
o Basic Arithmetical Operations.
o Arithmetical Operations with Field Strings (-CORRESPONDING).
o Adding Sequences of Fields (ADD extensions).
o Operators Precedence.
• Character Strings Operations:
o SHIFT, REPLACE, TRANSLATE, CONVERT, OVERLAY, SEARCH,
CONDENSE, STRLEN, CONCATENATE, SPLIT, MOVE
PERCENTAGE.
• Logical Operations:
o Comparisons:,
 All Field Types.
 Character Strings and Numeric Strings.
 Bit Structures.
o Checking Whether a Field Belongs to a Range (BETWEEN).
o Checking for the Initial Value.
o Checking Selection Criteria.
o Combine Operators and Operators Precedence.

Lists Processing:

• Write Operation:
o WRITE.
o Type-Specific Output.
o Positioning Output on the Screen.
o Outputting Symbols and Icons.
o Lines and Blank Lines (ULINE, SKIP etc.)
o Outputting Field Content as Checkbox.
o Outputting Field Content as Line.
o FORMAT statement:
 COLOR.
 SUMMARY, DETAIL.
 HOTSPOT.
 INPUT.
 RESET.
• Define Structure of List:
o List Width (REPORT..).
o Page Length (REPORT..).
o Individual Page Header (REPORT.., TOP-OF-PAGE).
o Individual Page Footer (REPORT.., END-OF-PAGE).
o Page Break (NEW-PAGE).
 RESERVE.
o Scrolling.
o Displaying Lists in Dialog Window.
o Positioning the Output (POSITION, BACK).
o SET TITLE.
o Retrieving List Attributes (DESCRIBE LIST).
• Interactive Lists:
o HIDE.
o READ LINE, MODIFY LINE.
o GET CURSOR, SET CURSOR.
o Events Control in Interactive Lists:
 AT LINE-SELECTION.
 AT PFnn.
 AT USER-COMMAND.
 SET USER-COMMAND.
o SET PF-STATUS.
o Messages in Lists.
 Messages Types.
• Predefined System Codes.

Internal Tables Processing:

• Identifying Table Lines:


o Internal Table Index.
o Internal Table Key.
• Filling Table:
o APPEND, INSERT, COLLECT.
• Reading Table:
o READ TABLE.
o LOOP Processing.
 Calculating Totals (SUM).
 AT ... ENDAT Events.
• Modifying Table:
o MODIFY, WRITE TO, DELETE.
• Clearing Table:
o REFRESH, CLEAR, FREE.
• Other Operations With Internal Table:
o SORT.
o SEARCH FOR string.
oLogical Expressions.
oAssignment Operator.
• RANGES.

Selection Screens:

• Parameters
• Selection Options
• Selection Screen Formatting
• Selection Screen Events:
o INITIALIZATION,
o AT SELECTION-SCREEN,
o AT SELECTION-SCREEN ON ...,
o AT SELECTION-SCREEN ON END OF...,
o AT SELECTION-SCREEN ON BLOCK...,
o AT SELECTION-SCREEN ON RADIOBUTTON GROUP...,
o AT SELECTION-SCREEN ON VALUE-REQUEST FOR ....
o AT SELECTION-SCREEN ON HELP-REQUEST FOR ....
o AT SELECTION-SCREEN OUTPUT.
 LOOP AT SCREEN,
 MODIFY SCREEN,

Field Symbols:

• Defining Field Symbols:


o Concept,
o Defining Field Symbols for Internal Fields,
o Defining Structured Field Symbols,
o Defining Local Field Symbols,
• Assigning Data Objects to Field Symbols:
o Assigning Data Objects,
o Assigning Field Symbols to Other Field Symbols,
o Assigning Components of Field Strings.

Modularization:

• Branches and Loops:


o IF, CASE, DO, WHILE,
o Terminating Loops;
• Events:
o INITIALIZATION and Selection Screen Events, START-OF-
SELECTION, GET Events, END-OF-SELECTION;
o Events Control in Interactive Lists;
o Terminating Events Processing Blocks;
• Dialogs:
• Source Code Modules:
o Macros, Includes;
• Subroutines (FORMs):
o Defining and Calling Subroutines;
o Passing Data and Defining Local Data in Subroutines;
o Terminating Subroutines;
• Function Modules:
o Interfaces;
o Calling Function Modules;
o Programming Function Modules.

Preliminaries.

Notation.
Go to top...
Go to next...

<fn>, <f> Field of any type.


<o> Offset (Numeric variable or literal).
<l> Length (Numeric variable or literal).
<n>, <m>, <p> Numeric field.
<c>, <str> Character string.
<m> Argument.
<fstring> Field String (in other words - structure).
FSTRING-
Component of field string (in other words - field of structure).
<component>
<g> Code Page (Conversion table).
<sc> Sort code.
<N> Number format.
<itab> Internal table.
Separate work area (can be used instead of header line for internal
<wa>
table).
<idx> Index (for internal table).
<parm> Parameter (for selection screen).
<selopt> Selection Option (for selection screen).
<range> Range.
<sel> Selection (Selection Option or Range).
<pid> SAP memory ID (up to 3 characters).
<mobj> Matchcode object (Data Dictionary) (4 characters).
<FS> Field Symbol (angle brackets are part of the syntax).
<dbtab> Table of Logical Database.

Literals.
Go to top...
Go to next...

A literal is a fixed value.

Text Literals
Text literals are sequences of alphanumeric characters enclosed in single
quotation marks:

• 'Hello, world!'
• 'Victor''s Home Page.'

Can be up to 254 characters long. If a text literal contains a quotation mark, you
must repeat it to enable the system to recognize the contents as a text literal and
not as the end of the literal.
Numbers Literals
Number literals are sequences of digits that may contain a leading sign. They can
contain up to 15 digits:

• 151163
• -1917
• +4

Non-integer values or a longer numbers can be defined as text literals which are
converted to the correct type automatically (see Conversion Rules):

• '151163151163151163151163'
• '+4.5'

Likewise, text literal represents a floating-point value. This must have the
following format:
'[<mantissa>][E][<exponent>]'
• '1E77'
• '+1.5E-12'

Elementary Data Types.


Go to top...
Go to next...

Data Initial Valid Initial


Description Comments
type size size value
1-
C 1 SPACE Character
65535
1-
N 1 '00..0' Numeric text
65535
Date
D 8 8 '00000000'
YYYYMMDD
Time
T 6 6 '000000'
HHMMSS
Range from -2**31 to 2**31-1.
I 4 4 0 Integer
Rounded, not truncated.
F 8 8 0 Float Range is 1x10**-307 to 1x10**308.
Two decimal digits are packed into one
byte, while the last byte contains one
digit and the sign. Up to 14 digits are
allowed after the decimal point. If the
program attribute Fixed point arithmetic
P 8 1-16 0 Packed
is not set, type P fields are interpreted as
integers without decimal places. The
DECIMALS parameter of the DATA
statement only affects the format of the
WRITE output.
1-
X 1 X'00' Hexadecimal
65535
Correspondence between ABAP/4 Dictionary Data Types
and Elementary Data Types.
Go to top...
Go to next...

ABAP/4 Dictionary Data Type Derived Elementary Data Type Comments


ACCP N(6)
CHAR n C(n)
CLNT C(3)
CUKY C(5)
CURR n, m, s P((n+2)/2) DECIMALS m [NO-SIGN]
DEC n, m, s P((n+2)/2) DECIMALS m [NO-SIGN]
DATS D
FLTP F
INT1 No correspondence
INT2 No correspondence
INT4 I
LCHR n C(n)
LRAW n X(n)
LANG C(1)
NUMC n N(n)
PREC X(2)
QUAN n, m, s P((n+2)/2) DECIMALS m [NO-SIGN]
RAW n X(n)
TIMS T
UNIT n C(n)
VARC n C(n)

Specifying Offset Values for Data Objects.


Go to top...
Go to next...

Offset/Length Extensions for the Assignment/MOVE/WRITE TO Operators:


<f>[+<o>][(<l>)].
where o=offset and l=length of the field portion.
Can be on both the left and right parts of an operator.
Can be variables in MOVE or WRITE TO or assignment statement and must be
literals in mathematical expressions.
Can be used in WRITE, WRITE TO, MOVE TO, ASSIGN TO, COMPUTE,
PERFORM.

Conversion Rules.
Go to top...
Go to next...

Elementary Data Types:


Target:
Source:
C D F N P T
Source must
contain the
representation
of a decimal
number, i.e. a
sequence of
digits with an
optional sign
Only digits and no more
are copied. than one
Left-justified. Padded Only Only valid Compressed decimal point. Only
C
with blanks or truncated. 'YYYMMDD' F-literal on the right Source can 'HHMMS
and padded contain
with zeros. blanks. If the
target is too
short, an
overflow may
occur. This
may cause the
system to
terminate the
program.
D Left-justified. No No conversion. ->P->F. ->C->N. ->number of Not
conversion. days since supported
Syntax
check or
01.01.0001.
Runtime
error.
Converted to the
<mantissa>E<exponent>
format. Mantissa lies
between 1 and 10 unless
the number is zero. ->I and
No
F Exponent is always ->P->D. ->P->N. rounded, if ->P->T.
conversion.
signed. If the target field necessary.
is too short, the mantissa
is rounded. The length of
the character field should
be at least 6 bytes..
Packed, right-
justified with
Right-
a positive
justified.
sign. If the
N No conversion. ->C->D. ->P->F. Padded with ->C->T.
target field is
zeros or
too short, the
truncated.
program may
be terminated.
Right-justified to the
character field, if
required with a decimal
Rounded if
point. The first position
necessary,
is reserved for the sign.
unpacked, Represent
Leading zeros appear as
Represents the and then the numbe
blanks. If the target field
number of days transported Right- of second
is too short, the sign is
since right- justified. If the since
omitted for positive
01.01.0001 and Accepted as justified. target field is midnight
P numbers. If this is still
is converted to F. The sign is too short, an and is
not sufficient, the field is
a date in omitted. If overflow converted
truncated on the left.
YYYYMMDD required, the occurs. to a time i
ABAP/4 indicates the
format. target field HHMMSS
truncation with an
is padded format.
asterisk (*). If you want
with zeros
the leading zeros to
on the left.
appear in the character
field, use UNPACK
instead of MOVE.
T Right-justified. No Not supported. ->P->F. ->C->N. Converted to No
conversion. Syntax check the number of conversio
or Runtime seconds since
error. midnight.
Interpreted as
a hexadecimal
number. It is
converted to a
packed
decimal Represent
Represents the number and the numbe
number of days transported of second
since right-justified since
Left-justified. Padded 01.01.0001 and to the target midnight
X ->P->F. ->P->N.
with zeros. is converted to field. If the and is
a date in hexadecimal converted
YYYYMMDD field is longer to a time i
format. than 4 bytes, HHMMSS
only the last format.
four bytes are
converted. If it
is too short, a
runtime error
may occur.
Type I is always treated in the same way as type P without decimal places..
Field Strings:
Compatible:
Component by Component.
Non-Compatible Field Strings and Elementary Fields:
System first converts all the field strings concerned to type C fields and then
performs the conversion between the two remaining elementary fields.
Field Strings with Internal Tables as Components:
Field strings which contain internal tables as components are convertible only if
they are compatible.
Internal Tables:
Internal tables are only convertibles to other internal tables. Internal tables are not
convertibles to field strings or elementary fields. Internal tables are convertible if
their line types are convertible.

• Internal tables that have internal tables as line types are convertible if the
internal tables that define the line types are convertible.
• Internal tables that have line types that are field strings with internal tables
as components are convertible only if the field strings are compatible.

Alignment of Data Objects:


Fields of type I or F are aligned. Field strings containing type I or F components
are also aligned and filler fields may be inserted in front of them. The system
normally aligns fields and structures automatically during their declaration.
Formatting Options.
Go to top...
Go to next...

All Data Types Numeric Types Date


LEFT-JUSTIFIED NO-SIGN DD/MM/YY
CENTERED DECIMALS <n> MM/DD/YY
RIGHT-JUSTIFIED EXPONENT <n> DD/MM/YYYY
UNDER <f>
Starts outputting field
in the same column ROUND <n> MM/DD/YYYY
from which field <f>
was started.
CURRENCY <c>
Currency <c> in table TCURX. System sets the
number of decimal places according to the entry
NO-GAP DDMMYY
CURRDEC in TCURX, ignoring real decimal
places in the number. If <c> not found, default
setting of 2 used.
UNIT <unit>
<unit> in table T006 (column MSEHI) for type
P. The entry in column DECAN then determines
the number of decimal places of the field to be
displayed. If the system does not find the entry
<unit> in T006, it ignores the option.
Restrictions:
USING EDIT MASK
MMDDYY
<mask> • field to be displayed must be a packed
number (type P);
• If field has less decimal places than the
<unit>, option ignored;

• If field has more decimal places than the


<unit>, option used only, if the operation
does not truncate any digits unequal to 0.
USING NO EDIT
YYMMDD
MASK
NO-ZERO
(blanks instead of 0)
Mask: Meaning:
==mask ABAP/4 Dictionary Edit Mask
'_' one character or one digit
'V' leading sign for types I, P
'LL' left-justified (at beginnig of template)
'RR' right-justified (at beginnig of template)
':', ... Separator
all other characters
Date separators as defined in user's master record.
Can be used also the formatting options of the FORMAT statement (intensity and color).

Declaring Data.

Types Definition.
Go to top...
Go to next...

ABAP/4 Data Types:

• Elementary Predefined Types (C, N, D, T, I, F, P, X).


• User-Defined Types:
o Elementary User-Defined Types.
o Structured Types:
 Structure Types.

 Internal Table Types.


TYPES:
Introduces user-defined data types. Variants:

• TYPES <type>[<length>].
Default C(1). <length> should only be used with the types C, N, P and X.
Other types can only be created in the standard length. Additions:
o TYPE <knowntype>.
LIKE <f>.
Defines the new type. <f> - a database field or an already defined
internal field.
o TYPE <knowntype> OCCURS <n>.
LIKE <f> OCCURS <n>.
Defines the new type of an internal table without a header line.
This table consists of any number of table lines that have the same
structure as that specified by TYPE.
The OCCURS parameter <n> specifies how many table lines of
storage is required. This storage reservation process does not
happen until the first line is inserted in the table. The value <n> of
the OCCURS specification has no effect on type checking, i.e. data
objects which have types with different OCCURS specifications
are type-compatible.
o TYPE LINE OF <itabtype>.
LIKE LINE OF <itab>.
Creates a type corresponding to the line type of the specified table
type <itabtype> or of the specified table <itab>.
• TYPES BEGIN OF <rectype>
...
END OF <rectype>.
Defines the field string <rectype>.

TYPE-POOLS:
TYPE-POOLS <name>.
Allows using all the data types and constants defined in the type group <name>.
Type groups store user-defined data types or constants in the ABAP/4 Dictionary
for cross-program use.

Data Definition.
Go to top...
Go to next...

TABLES:
TABLES <databasetable>.
Makes the database table, view or structure known to the program. Defines the
identical field string - the table work area - in the program. The names and the
sequence of the fields of the table work area correspond exactly to the names and
the sequence of the fields when declaring the database table or view in the
ABAP/4 Dictionary. The ABAP/4 data type and the length of the fields are
derived from the data types in the ABAP/4 Dictionary as follows.
DATA:
the DATA statement has the same form as TYPES, plus optional additions:

• ... VALUE {<value>|IS INITIAL}.


<value> is literal or constant.
• ... WITH HEADER LINE.
May be used only for internal table objects. The internal table is created
with a table work area. If you want to create an internal table with a header
line, the line type cannot directly be an internal table. However, it can be a
structure that has internal tables as components.
To create an internal table data object without referring either to an existing object
or to an existing line structure, use the DATA statement as follows:

• DATA BEGIN OF <itab> OCCURS <n>


...
END OF <itab>.
This statement always creates a table work area (HEADER LINE).

CONSTANTS:
the CONSTANTS statement has the same form as DATA, but addition ...
VALUE <value> is obligatory.
STATICS:
the STATICS statement has the same form as DATA.
Retains the value of a variable beyond the runtime of a procedure (subroutine or
function module).
Determining the Attributes of Data Objects:
DESCRIBE FIELD <f> [LENGTH <l>] [TYPE <type> [COMPONENTS
<n>]] [OUTPUT-LENGTH <lo>] [DECIMALS <nd>] [EDIT MASK
<mask>].
The attributes of the data object <f> specified by the parameters of the statement
are written to the variables following the parameters:

• <l> - length of the field;


• <type> - type of the field:
<type> Meaning
C, N, D, T, I, F, P, X Elementary Data Type
h Internal table
s 2-byte integer with leading sign
b 1-byte integer without leading sign
u Field string without internal table
v Field string containing at least one internal table
• Note. If ... COMPONENTS <n> not present then ... TYPE <type>
returns C rather than u or v with structures.
• <n> - number of structure components or 0 if <f> is not a structure;
• <lo> - length required when outputting <f> with WRITE. A max value is
therefore defined by the maximum line length for lists. For internal tables
and structures which contain internal tables, the value 0 is returned
because these cannot be output with WRITE either.
• <nd> - number of decimal places;
• <mask> - if the field <f> has a conversion routine in the ABAP/4
Dictionary, this is placed in the field <mask> (a C(10) field) in the form
"==conv". "conv" stands for the name of the conversion routine, e.g.
"==ALPHA" in the conversion routine "ALPHA". The ABAP/4 conversion
routines have names CONVERSION_EXIT_name_OUTPUT (and
..._INPUT). In this form, <mask> can then be used in the addition USING
EDIT MASK mask of the WRITE statement.

DESCRIBE TABLE <itab> [LINES <nl>] [OCCURS <no>].

• <nl> - number of filled lines;


• <no> - value of OCCURS.

DESCRIBE DISTANCE BETWEEN <f1> AND <f2> INTO <n>.


Determines the distance between the fields <f1> and <f2> and places the result (in
bytes) in <n>.

Data Processing.

Assignment Operations.
Go to top...
Go to next...

Assignment Operator:
<fn> = ... <f3> = <f2> = <f1>.
Equivalent to MOVE. Executed from right to left.
MOVE TO:
MOVE <f1> TO <f2>.
Follows the Conversion Rules.
See also MOVE PERCENTAGE for character string.
MOVE-CORRESPONDING:
MOVE-CORRESPONDING <fstring1> TO <fstring2>.
This statement assigns the contents of components of field string fstring1 to those
components of field string fstring2 which have the same names.
WRITE TO:
WRITE <f1> TO <f2> [<options>].
Does NOT follow the Conversion Rules. The target field is interpreted as a type C
field.
Option - all Formatting Options except UNDER and NO-GAP.
Always checks the settings in the user's master record, e.g. whether the decimal
point appears as a period (.) or a comma (,).
Specifying the Source field at Runtime with WRITE TO:
WRITE (<f1>) TO <f2>.
The system places the value of the data object assigned to <f1> in <f2>.
Example:
DATA: NAME(10) VALUE 'SOURCE',
SOURCE(10) VALUE 'Antony',
TARGET(10).
...
WRITE (NAME) TO TARGET.
WRITE: TARGET.
This produces the output:
Antony

CLEAR:
CLEAR <f>|<fstring> [WITH <g>|NULL].
Resets the contents to initial values (or to a first byte of <g> or to X'00').
FREE:
FREE <f>|<fstring>.
Like CLEAR, resets the contents to initial values. Also releases any resources
connected with the data object.
This may be relevant with internal tables, structures with tabular components as
well as table work areas.

Numerical Operations.
Go to top...
Go to next...

COMPUTE:
[COMPUTE] <n> = <expression>.
Using Mathematical Functions:
[COMPUTE] <n> = <function>( <m> ).
The blanks between the parentheses and the argument <m> are obligatory.
Functions for all Numeric Data Types: ABS, SIGN, CEIL, FLOOR, TRUNC,
FRAC.
Floating-Point functions: COS, SIN, TAN, ACOS, ASIN, ATAN, COSH, SINH,
TANH, EXP, LOG, LOG10, SQRT.

Basic Arithmetic Operations:


Operation Using expression Using keyword
Addition <p> = <n> + <m>. ADD <n> TO <m>.
Subtraction <p> = <n> - <m>. SUBTRACT <n> FROM <m>.
Multiplication <p> = <n> * <m>. MULTIPLY <m> BY <n>.
Division <p> = <n> / <m>. DIVIDE <m> BY <n>.
Integer division <p> = <n> DIV <m>. -
Remainder of division <p> = <n> MOD <m>. -
Exponentiation <p> = <n> ** <m>. -
When using mathematical expressions, please note that the operators +, -, *, **,
and /, as well as opening and closing parentheses, are ABAP/4 words and must
therefore be preceded and followed by blanks.
ADD-CORRESPONDING <fstring1> TO <fstring2>,
SUBTRACT-CORRESPONDING <fstring1> FROM <fstring2>,
MULTIPLY-CORRESPONDING <fstring2> BY <fstring1>,
DIVIDE-CORRESPONDING <fstring2> BY <fstring1>:
See MOVE-CORRESPONDING.
Adding Sequences of Fields:

1. ADD <n1> THEN <n2> UNTIL <nz> GIVING <m>.


~ m = n1 + n2 + ... + nz.
2. ADD <n1> THEN <n2> UNTIL <nz> TO <m>.
~ m = m + n1 + n2 + ... + nz.
3. ADD <n1> THEN <n2> UNTIL <nz> ... ACCORDING TO <sel>
GIVING|TO <m>.
<sel> is generated by SELECT-OPTIONS or RANGE..
4. ADD <n1> FROM <m1> TO <mz> GIVING <m>.
<n1> is the first in a sequence of consecutive fields.
<m1> and <mz> contain the numbers of the first and last fields in this
sequence.

Operators Precedence:
The order of evaluation is:

1. expressions in parentheses
2. functions
3. ** (exponentiation)
4. *, / , MOD, DIV (multiplications, divisions)
5. +, - (additions, subtractions)

Character Strings Operations.


Go to top...
Go to next...

Note to the Character Strings Operations.


All the operations marked with '*' process the operands regardless of type as type C - no
internal conversion is performed.

SHIFT * :
SHIFT <c> [BY <n> PLACES] [LEFT|RIGHT|CIRCULAR].
<n> can be a variable, must be >0 (no actions if <0), default is 1. LEFT is default.
SHIFT <c> UP TO <str> [LEFT|RIGHT|CIRCULAR].
<str> is a substring to search in <str> and can be a variable. LEFT is default.
If <str> is not found in <c>, SY-SUBRC is set to 4 and <c> is not shifted.
Otherwise, SY-SUBRC is set to 0.
SHIFT <c> LEFT DELETING LEADING <str>.
SHIFT <c> RIGHT DELETING TRAILING <str>.
<str> can be a variable.
REPLACE * :
REPLACE <str1> WITH <str2> INTO <c> [LENGTH <len>].
Searches the field <c> for the first occurrence of the first <len> positions of the
pattern <str1>. If no length is specified, it searches for the pattern <str1> in its full
length. Then, the statement replaces the first occurrence of the pattern <str1> in
field <c> with the string <str2>. If a length <len> was specified, only the relevant
part of the pattern is replaced.
SY-SUBRC = 0: string replaced; SY-SUBRC = 4: string not replaced.. <str1>,
<str2>, and <len> can be variables.
TRANSLATE * :
TRANSLATE <c> TO UPPER CASE.
TRANSLATE <c> TO LOWER CASE.
To convert also umlauts the profile parameter abap/locale_ctype must be set and
character set must be found.
TRANSLATE <c> USING <str>.
<str> contains pairs of letters, where the 1st letter of each pair is replaced by the
2nd letter. Can be a variable.
TRANSLATE <c> FROM CODE PAGE <g1> TO CODE PAGE <g2>.
TRANSLATE <c> FROM CODE PAGE <g>.
TRANSLATE <c> TO CODE PAGE <g>.
Conversion tables <g1> and <g2> must exist, otherwise Runtime error. Use
transaction SPAD to maintain conversion tables TCP00 - TCP02. Some
conversion combinations maintained at Runtime for performance reason (e.g.
'1110' - HP, '0100' - EBCDIC (IBM 274)).
I, P, F, X fields remain unchanged.
TRANSLATE <c> FROM NUMBER FORMAT <N1> TO NUMBER
FORMAT <N2>.
TRANSLATE <c> FROM NUMBER FORMAT <N>.
TRANSLATE <c> TO NUMBER FORMAT <N>.
Number format <N> can be '0000' (HP, SINIX,IBM) or '0101' (DEC alpha OSF).
Function module SYSTEM_FORMAT displays system code page and number
format.

CONVERT:
CONVERT TEXT <c> INTO SORTABLE CODE <sc>.
Source <c> must be C or W type. Target <sc> should be of type X and at least 16
times (for C) or 4 times (for W) as long as source. The method of conversion
depends on the text environment of the running ABAP/4 program. The text
environment is defined in the user's master record or, as an exception, can be set
via SET LOCALE LANGUAGE.
The purpose of this statement is to create an accompanying field <sc> for a
character field <c>, which can serve as an alphabetical binary sort key for <c>,
which is NOT dependent of platform-specific internal coding of the individual
letters.
OVERLAY * :
OVERLAY <c1> WITH <c2> [ONLY <str>].
Overlays all positions in <c1> containing letters which occur in <str> with the
contents of <c2>. If omit ONLY <str>, only SPACEs are overwritten.
SY-SUBRC = 0 : at least one character was replaced; SY-SUBRC = 4 : other
cases.
SEARCH * :
SEARCH <c> FOR <str> [<options>].
Searches <c> for the character string in <str>. If successful, SY-SUBRC = 0 and
SY-FDPOS = offset. Otherwise SY-SUBRC = 4.
Pattern:

• 'str' : Character string (trailing blanks are ignored);


• '.str .' : Any character string between periods;
• '*str' : Word ending with "str";
• 'str*' : Word beginning with "str".

Options:

• ABBREVIATED : Searches for a word containing the character string


specified in <str>, where the characters might be separated by other
characters. The first letter of the word and the string <str> must be the
same;
• STARTING AT <n1> : Note. SY-FDPOS = offset starting at <n1> as
well;
• ENDING AT <n2>
• AND MARK : Marks converting to uppercase.

CONDENSE * :
CONDENSE <c> [NO-GAPS].
Removes leading blanks. Replaces other sequences of blanks with one blank or
removes all blanks if NO-GAPS.
STRLEN * :
[COMPUTE] <n> = STRLEN( <c> ).

CONCATENATE * :
CONCATENATE <c1> ... <cn> INTO <c> [SEPARATED BY <s>].
Trailing blanks ignored. SY-SUBRC = 0 : OK; SY-SUBRC = 4 : result has to be
truncated.
SPLIT * :
SPLIT <c> AT <delimiter> INTO <c1> ... <cn>.
To place all fragments in different target fields, you must specify enough target
fields. Otherwise, the last target field is filled with the rest of the field <c> and
still contains delimiters.
SY-SUBRC = 0 : All target fields are long enough and no fragment has to be
truncated. Otherwise SY-SUBRC = 4.
SPLIT <c> AT <delimiter> INTO TABLE <itab>.
For each part of the character string, the system adds a new table line.
MOVE PERCENTAGE:
MOVE <c1> TO <c2> PERCENTAGE <n> [RIGHT].
<n> = 0...100. PERCENTAGE ignored when either <c1> or <c2> are not C type.

Logical Operations.
Go to top...
Go to next...

Comparisons:
... <f1> <operator> <f2> ...
All Field Types:
Operators:
NE
EQ LT LE GT GE
<>
= < <= > >=
><
The operands can be database fields, internal fields, literals, or constants;
structured data types (compared component by component and nested structures
are broken down into elementary fields); internal tables. Fields of different data
types can be compared (if they are convertible) after an automatic Type
Conversions according to the following hierarchical rules:
One of the Other
Conversion
operands operand
F any to F
P any to P
to D or T.
D or T any Note. Comparison between D and T not supported
and causes program termination.
C X to C
C N both to P
Character Strings and Numeric Strings:
Only for types C and N.
Case- Trailing SY-FDPOS SY-FDPOS
Op. Meaning True if
sensitive Blanks if true if false
CO Contains yes included <f1> contains length of <f1> offset of the
Only only characters first character
from <f2> of <f1> that
does not occur
in <f2>
offset of the
<f1> contains
first character
contains characters other
CN yes included of <f1> that length of <f1>
Not Only than those in
does not occur
<f2>
in <f2>
offset of the
<f1> contains at
first character
Contains least one
CA yes ? of <f1> that length of <f1>
Any character from
occurs in
<f2>
<f2>
offset of the
<f1> contains no
contains first character
NA yes ? one character length of <f1>
Not Any of <f1> that
from <f2>
occurs in <f2>
Contains <f1> contains offset of <f2>
CS no ignored length of <f1>
String <f2> in <f1>
contains <f1> does not offset of <f2>
NS no ignored length of <f1>
No String contain <f2> in <f1>
CP Contains no ignored <f1> contains offset of <f2> length of <f1>
Pattern pattern <f2>: in <f1>

• * - any
character
string;
• + - any
single
character;
• #c - the
particular
character
(in upper
or lower
case);
• #* - the
"*"
symbol;
• #+ - the
"+"
symbol;
• ## - the
"#"
symbol
itself;

• #___ -
the
trailing
blanks.
<f1> does not
contains offset of <f2>
NP no ignored contain pattern length of <f1>
No Pattern in <f1>
<f2>
Bit Structures:
Compares first byte of the <f1> with <f2>, which should have length 1 byte
(recommended use as <f2> type X length 1).
Operator Meaning True if
O bits are one bits that are 1 in <f2>, are 1 in <f1> as well
Z bits are zero bits that are 1 in <f2>, are 0 in <f1>
from bits that are 1 in <f2>, at least one is 1 an one is 0 in
M bits are mixed
<f1>
Checking Whether a Field Belongs to a Range:
... <f1> BETWEEN <f2> AND <f3> ...
it is short form of
... <f1> GE <f2> AND <f1> LE <f3> ...
Checking for the Initial Value:
... <f> IS INITIAL ...
true if <f> contains the initial value for its type. In general, any field, elementary
or structured (field strings and internal tables), contains its initial value after a
CLEAR <f> statement is executed.
Checking Selection Criteria:
... <f> IN <sel> ...
If the selection criteria <sel> is attached to <f> with the SELECT-OPTIONS
statement the short form can be used:
... <sel> ...
Combine Operators and Operators Precedence:
Priority: NOT AND OR. Equal priority operations are processed from left to
right. If one of the component expressions is recognized as true or false, the
remaining part is not performing if total expression can be known. Therefore you
can improve performance by organizing logical expressions (for example, by
placing comparisons which are often false at the beginning of an AND chain and
expensive comparisons, such as searches for character strings, at the end).

Lists Processing.
Write Operation.
Go to top...
Go to next...

WRITE (see transaction LIBS for SAP guidelines using colors, symbols, icons etc. in
lists):
WRITE <f> [<formatting options>].
<f> can be:

• any data object (variable, literal, constant);


• field symbol or formal parameter;
• text symbol like text-<nnn> or 'default text'(<nnn>), where <nnn> is
text symbol's Id.

Type-specific output (len=field length):


Type Standard output length Justified
C len left
D 8 left
F 22 right
I 11 right
N len left
P 2*len[+1] right
T 6 left
X 2*len left
Positioning output on the screen:
WRITE AT [/][<pos>][(<len>)] <f>.
<f> can be:

• / - new line;
• <pos>, <len> - numbers or variables up to 3 digits;
• AT can be omitted if <pos>, <len> are not variables.

If <len> is too short, fewer characters are displayed. Numeric fields are truncated
on the left and prefixed with an asterisk (*). All other fields are truncated on the
right, but no indication is given that the field is shorter.

Outputting symbols and icons on the screen:


WRITE <symbol-name> AS SYMBOL.
WRITE <icon-name> AS ICON.
<symbol-name> and <icon-name> are system-defined constants which are
specified in the include programs <SYMBOL> and <ICON> (<LIST> replaces
both the above). The angle brackets are part of the name.
To browse all available icons and symbols use pattern for the WRITE statement in
the ABAP/4 Editor. All icons can be viewed using the ICON transaction as well.
Lines and blank lines the screen:
ULINE [AT [/][<pos>][(<len>)]] [NO-GAP].
this is equivalent to WRITE [AT [/][<pos>][(<len>)]] SY_ULINE [NO-GAP].
WRITE [AT [/][<pos>]] SY-VLINE.
or WRITE [AT [/][<pos>]] '|'.
SKIP [<n>].
SKIP TO LINE [<n>].
Note. WRITE / ' '. statement does not output blank line by default. To change
default setting use following statement:
SET BLANK LINES ON|OFF.
Outputting field content as checkbox:
WRITE <f> AS CHECKBOX.
If the first character of <f> is an "X", the checkbox is displayed filled. If the first
character is SPACE, the checkbox is displayed blank. The checkboxes that are
created by this statement are input enabled by default.
Outputting lines on the screen:
WRITE <f> AS LINE.
On list output, automatically links certain characters together to form continuous
lines or boxes, if there is no space between them:

• vertical lines, output with the system field SY-VLINE or using a field
with the contents "|" (vertical line);
• horizontal lines, output with the system field SY-ULINE or using a field
with at least 2 consecutive minus signs "--".

Exactly how each line segment is output (e.g. whether as straight line, corner, T-
piece or cross) depends on the adjoining characters.
The include <LINE> (or the more comprehensive include <LIST>) contains the
relevant identifiers for lines as constants, e.g. LINE_TOP_LEFT_CORNER,
LINE_BOTTOM_MIDDLE_CORNER.
FORMAT:
FORMAT <option1> [ON|OFF] <option2> [ON|OFF] ... .
FORMAT <option1>=<var1> <option2>=<var2> ... .
Effective from next output (WRITE or new line) operation until next event or
turning OFF. ON = default. <vari> should be of type I. If the <vari>=0, the
variable has the same effect as the OFF option. If WRITE statement follows the
FORMAT statement, the settings of the WRITE statement overwrite the
corresponding settings of the FORMAT statement for the current output.

• FORMAT COLOR <n> [ON] INTENSIFIED [ON|OFF] INVERSE


[ON|OFF].
Does not work for lines. If INVERSE is used, the INTENSIFIED has no
effect. Has no effect on input fields.
vari Symbol name Color
OFF COL_BACKGROUND Background (GUI-specific)
1 COL_HEADING Headers (grayish blue)
2 COL_NORMAL List body (bright gray)
3 COL_TOTAL Totals (yellow)
4 COL_KEY Key columns (bluish green)
5 COL_POSITIVE Positive threshold value (green)
6 COL_NEGATIVE Negative threshold value (red)
7 COL_GROUP Control levels (violet)


Call the SHOWCOLO report in any system for demonstration of colors
in lists.
• SUMMARY. this is equivalent to FORMAT INTENSIFIED ON.
DETAIL. this is equivalent to FORMAT INTENSIFIED OFF.
• FORMAT HOTSPOT [ON|OFF].
Affects the display format of the mouse pointer and the effect of the
mouse single click: If you drag the mouse pointer over list areas which are
output with the format ...HOTSPOT (lines or fields), the mouse pointer
switches from its standard display format (usually an arrow) to the format
of a hand with an outstretched index finger. If you then click once, the
effect is like double-clicking or pressing the function key F2 (AT LINE-
SELECTION). Has no effect on input fields.
• FORMAT INPUT [ON|OFF].
Determines whether the user can enter data. See READ LINE.
• FORMAT RESET.
The same as FORMAT COLOR OFF INTENSIFIED OFF INVERSE
OFF HOTSPOT OFF INPUT OFF.

Define Structure of List.


Go to top...
Go to next...
List Width:
REPORT <report> LINE-SIZE <n>.
n=0 : standard list. List cannot be wider than 255 (132 for most printers). SY-
LINSZ contains the current line size.
To adapt the line size to the current window width, set <n> to SY-SCOLS. SY-
SCOLS contains the number of characters of a line of the current window.
Page Length:
REPORT <report> LINE-COUNT <length>[(<n>)].
n - number of reserved for footer lines. length=0 : standard list. SY-LINCT
contains the current page length or 0 if standard page.
To adapt the page length to the current window length, set <length> to SY-
SROWS. SY-SROWS contains the number of lines of the current window.
Individual Page Header:
REPORT <report> [NO STANDARD PAGE HEADING].
....
TOP-OF-PAGE [DURING LINE-SELECTION].
WRITE... .
List processing event that is executed before the first data is output on a new page.
Without the addition ... DURING LINE-SELECTION, processed only when
generating basic lists, not when creating secondary lists. Only executed before
outputting the first line on a new page - not triggered by a NEW-PAGE statement.
During the event TOP-OF-PAGE, you can also fill the system fields SY-
TVAR0...SY-TVAR9 with values that should replace eventual placeholders
&0...&9 in the standard page header.
Individual Page Footer:
REPORT <report> LINE-COUNT <length>(<n>).
....
END-OF-PAGE.
WRITE... .
END-OF-PAGE processed only if n>0. If you explicitly specify a new page with
NEW-PAGE, END-OF-PAGE is ignored.
Page Break:
NEW-PAGE [PRINT ON ...].

• ends the current page and increased SY-PAGNO by 1;


• does not trigger the END-OF-PAGE event.

NEW-PAGE [NO-TITLE|WITH-TITLE] [NO-HEADING|WITH-


HEADING].

• used to suppress or display the standard header and/or columns headers on


all pages to come. default both: WITH for basic and NO for secondary
lists;
• does not affect the display of a page header defined at the event TOP-OF-
PAGE.
NEW-PAGE LINE-COUNT <length>.
length=0 : standard list. Can be variable.
NEW-PAGE LINE-SIZE <n>.
n=0 : standard list. Can be variable. Within a list level, that is, if the next page is
not the beginning of a new list level, the system ignores the LINE-SIZE option.
RESERVE <n> LINES.
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. <n> can be a variable. 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. No blank pages are
created.
Scrolling:
common notes.

• SCROLL works for completed lists only. If you use SCROLL before the
first output statement of a list, it does not affect this list. If you use
SCROLL after the first output statement of a list, it affects the entire list,
that is, all subsequent output statements as well;
• While creating a secondary list, a SCROLL statement without INDEX
option always refers to the previously displayed list on which the
interactive event occurred (index SY-LISTI);
• Only when creating the basic list does the SCROLL statement refer to the
currently created list;
• You can use the INDEX option to explicitly scroll on existing list levels.
To do this, the lists need not be displayed. When the user displays the list
again, it is scrolled to the specified position. If the specified list level does
not exist, the system sets SY-SUBRC to 8;
• If, during an interactive event, you want to scroll through the list you are
currently creating, use SY-LSIND as the index in the SCROLL statement.
Note that a manipulation of SY-LSIND takes effect only at the end of the
event on the created list, independent of where you place the statement in
the processing block. If you want to set the list level explicitly, you must
manipulate SY-LSIND in the last statement of the processing block to
make sure that a SCROLL statement within the processing block accesses
the correct list;
• Another way of scrolling interactive lists from within the program is to use
the SET USER-COMMAND statement in connection with the
corresponding system-defined function codes;
• SY-SUBRC = 0 : Ok; = 4 : scrolling was not possible (exit boundaries); =
8 : list level does not exist.

SCROLL LIST FORWARD|BACKWARD [INDEX <index>].


vertical scrolling window by window
SCROLL LIST TO {FIRST PAGE|LAST PAGE|PAGE <n>} [INDEX
<index>] [LINE <line>].
SCROLL LIST FORWARD|BACKWARD <n> PAGES [INDEX <index>].
vertical scrolling by pages
SCROLL LIST LEFT|RIGHT [INDEX <index>].
horizontal scrolling to margins
SCROLL LIST TO COLUMN <n> [INDEX <index>].
SCROLL LIST LEFT|RIGHT BY <n> PLACES [INDEX <index>].
horizontal scrolling by columns
SET LEFT SCROLL-BOUNDARY [COLUMN <n>].
Only the part to the right from {current column|column <n>} will be scrolled
horizontally. Applies to the entire current page, and only to it. To set the same
scrollable area for all pages of a list, use, for example, at the TOP-OF-PAGE
event.
NEW-LINE NO-SCROLLING.
Excludes the line following the statement from horizontal scrolling (for example,
title line).
NEW-LINE SCROLLING.
This statement makes sense only if after NEW-LINE NO-SCROLLING no line
was output.
Displaying Lists in Dialog Windows.
WINDOW STARTING AT <left> <upper> [ENDING AT <right> <lower>].
Causes the current list (index SY-LSIND) to be displayed in a dialog window. If
<upper> = 0, the list appears on a fullscreen. By default, the system uses the
values of the lower right corner of the window on which the event occurred. If the
width of the dialog window is smaller than the width of the preceding list, the
system creates a horizontal scroll bar on the dialog window. To prevent that, you
must adapt the width of the secondary list to the width of the dialog window by
using the following statement: NEW-PAGE LINE-SIZE <width>.
Dialog window has not a menu bar or a standard toolbar. Standard application
toolbar at the lower margin has functions PRI, %SC, %SC+, and RW.
Positioning the output
For the current output position, refer to the system fields

• SY-COLNO - the current column;


• SY-LINNO - the current line.

POSITION <column>.
Sets horizontal output position. Se also WRITE AT and SKIP TO LINE for
vertical output position.
BACK.
Subsequent output appears beneath the page header or to the first line of a block
of lines defined with the RESERVE, if used. If you specify BACK at the TOP-
OF-PAGE event, the system does not set the output position to beneath the entire
page header, but only to beneath the standard page header. Any output written
now overwrites the self-defined page header specified at TOP-OF-PAGE.
SET TITLEBAR:
SET TITLEBAR <titlebar> [WITH <f0> <f1> ... <f9>].
Sets a screen title. A set title remains valid within a transaction until you call SET
TITLEBAR again. SY-TITLE (can be up to 70 characters long) contains the
current screen title. Allows you to build up to 9 parameters into the header, using
the variables &1 to &9.
Retrieving List Attributes:
You should use this key word only in exceptional cases (e.g. when editing an
'anonymous' list in a program other than that which generated the list). In all other
cases, you should save the relevant values when you generate the list. Take care
when attempting to retrieve the list attributes being set up (...INDEX SY-LSIND),
since some attributes (number of pages, number of lines, ...) may not have been
updated yet.
DESCRIBE LIST NUMBER OF LINES|PAGES <n> [INDEX <index>].
Returns the number of lines|pages in the list. SY-SUBRC=0 : Ok, <>0 : list does
not exists.
DESCRIBE LIST LINE <nl> PAGE <n> [INDEX <index>].
Returns the number of the page for the line <nl> in the list. SY-SUBRC=0 : Ok, 4
: line does not exists, 8 : list does not exists.
DESCRIBE LIST PAGE <np> <options> [INDEX <index>].
Returns the attributes of the page <np> in the list. SY-SUBRC=0 : Ok, 4 : page
does not exists, 8 : list does not exists. <options>:

• LINE-SIZE <n> - page width;


• LINE-COUNT <n> - page length;
• LINES <n> - number of displayed lines;
• FIRST-LINE <n> - absolute number of the first line;
• TOP-LINES <n> - number of lines output by page header processing (i.e.
standard title + column headers + TOP-OF-PAGE);
• TITLE-LINES <n> - number of lines output as standard title lines by
page header processing (see NEW-PAGE).
Note. The value of TITLE-LINES is contained in TOP-LINES;
• HEAD-LINES <n> - number of lines output as column headers by page
header processing (see NEW-PAGE).
Note. The value of HEAD-LINES is contained in TOP-LINES;
• END-LINES <n> - number of lines output by page footer processing (see
END-OF-PAGE);

Interactive Lists.
Go to top...
Go to next...

HIDE:
HIDE <f>.
Stores the contents of variable <f> in relation to the current output line (system
field SY-LINNO) internally in the so-called HIDE area. <f> must not necessarily
appear on the current line.
READ LINE:
The system internally stores all lists created in succession by one report program.
Therefore, you can access any list from within the program that was created
during the current dialog session and has not been deleted by returning to a
previous list level.
READ LINE <n> [INDEX <index>]
[FIELD VALUE <f1> [INTO <g1>] ... <fn> [INTO <gn>]]
[OF CURRENT PAGE|OF PAGE <n>].
READ CURRENT LINE
[FIELD VALUE <f1> [INTO <g1>] ... <fn> [INTO <gn>]]
Stores the contents of line from the list on which the event was triggered (list
index SY-LISTI, line number SY-LILLI) in the SY-LISEL system field and fills
all HIDE information stored for this line back into the corresponding fields.
SY-SUBRC = 0 : Ok; = 4 : line does not exist.
FIELD VALUE uses Conversion Rules (see Source Type C). Fields that do not
appear in a line, do not affect the target field. If a field appears several times in a
line, the system uses only the first one.
MODIFY LINE:
MODIFY {LINE <n> | LINE <n> OF CURRENT PAGE | LINE <n> OF
PAGE <page> | CURRENT LINE}
[INDEX <index>] - index=SY-LSIND, applied only for LINE <n>
[LINE FORMAT <fmt1> ... <fmtn>] - applied for whole line
[FIELD FORMAT <f1> <fmt11> ... <fmt1m> [... <fn> <fmtn1> ...
<fmtnm>]]
[LINE VALUE FROM <wa>]
[FIELD VALUE <f1> [FROM <g1>] [... <fn> [FROM <gn>]]. - <f1>
means <f1> FROM <f1>
Changes the line of the list taking values from SY-LISEL (or from the <wa> or
<gn>). Usually after List Events: AT LINE-SELECTION, AT PFxx, AT USER-
COMMAND, where the SY-LISEL is filled. Fills HIDE information.
SY-SUBRC = 0 : Ok; <> 0 : line was not changed.

GET CURSOR:
GET CURSOR FIELD <f> [OFFSET <o>] [LINE <n>] [VALUE <val>]
[LENGTH <l>].
Transfers the name of the field on which the cursor is positioned during a user
action into the variable <f>. If the cursor is on a field, the SY-SUBRC is 0,
otherwise 4. The system transports the names of global variables, constants, field
symbols, or reference parameters of subroutines. For literals, local fields, and
VALUE parameters of subroutines, the system sets SY-SUBRC to 0, but transfers
SPACE as the name.
GET CURSOR LINE <n> [OFFSET <o>] [VALUE <val>] [LENGTH <l>].
Transfers the number of the line on which the cursor is positioned during a user
action into the variable <n>. If the cursor is on a list line, the SY-SUBRC is 0,
otherwise 4.
• <o> contains the position of the cursor within the field. If the cursor is on
the first column, <o> = 0;
• <n> contains the number of the list line on which the cursor is positioned
(SY-LILLI);
• <val> contains the character string output representation of the field|line
on which the cursor is positioned. The representation includes formatting
characters;
• <l> contains the output length of the field on which the cursor is
positioned.

SET CURSOR:
SET CURSOR FIELD <f> [OFFSET <o>] [LINE <n>].
Set cursor at begin of field <f> (should be in uppercase), or at column <o> (begin
is ). In step loop or in list processing (if the field is displayed on several lines)
<n> is needed. In list processing <n> means SY-LILLI.
SET CURSOR LINE <n> [OFFSET <o>].
In list processing <n> means SY-LILLI.
SET CURSOR <column> <line>.
<column> and <line> are absolute position on the current screen.
Event Control for Interactive Lists:

• AT LINE-SELECTION occurs after the user double-clicks on a line,


clicks once on a hotspot, or chooses Edit-Choose;
• AT PF<nn> occurs after the user presses the corresponding function key.
Predefined system functions have higher priority than self-defined events.
The system does not trigger an event AT PF<nn> for keys whose function
code is predefined:
Help F1 Choose F2 Back F3
Possible Entries F4 Cancel F12 First Page F21
Previous Page F22 Next Page F23 Last Page F24
• Recommended use AT PF for testing purposes only. In final version use
AT USER-COMMAND together with self-defined interfaces.
• AT USER-COMMAND occurs after the user chooses a self-defined
action. SY-UCOMM contains chosen function code.
• SET USER-COMMAND <command> triggers event from within the
program. Takes effect after the current list is completed. Before the system
displays the list, it triggers the event that corresponds to the function code
stored in <command>, independent of the applied user interface.

<command> Event
self-defined function code AT USER-COMAND
'PICK' AT LINE-SELECTION
'PF<nn>' AT PF<nn>
Predefined Function Code not event, but direct action
SET PF-STATUS:
SET PF-STATUS <status> [EXCLUDING <function>|<itab>]
[IMMEDIATELY].
Sets user-defined <status> for all subsequent list levels until you set another
status. SY-PFKEY - status of the current list. <status> is SPACE to set system
status. <function>, type C(4), (or list of functions in the <itab>) - function code(s)
to be deactivated in the <status>. IMMEDIATELY changes the status of the
currently displayed list (SY-LISTI) within the processing block of the interactive
event. Without this option, the system changes the status of the current secondary
list (SY-LSIND) that is displayed only at the end of the processing block.
Messages in Lists:
Messages are stored and maintained in the T100 "Messages" table by

1. Language key - type C(1);


2. Application area (or message Id) - type C(2);
3. Message number - type C(3).

REPORT <report> MESSAGE-ID <id>.


Specifies <id> for use in <report> statically.
MESSAGE <type><number>[(<id>)] [WITH <f1>...<f4>] [RAISING
<exception>].
MESSAGE ID <fid> TYPE <ftype> NUMBER <fnumber> [WITH
<f1>...<f4>] [RAISING <exception>].
Specifies message dynamically (2nd statement - at runtime: <fid>, <ftype>,
<fnumber> - variables). <f1>...<f4> replace placeholders in the message text: the
'&' - one after the other; the '&i' - according to the number. Use '&&' to display
the '&' symbol in the message. Up to 4 placeholders are allowed, each can place
up to 50 characters.
RAISING is allowed only for a function module.
When executing the statement, the following system variables are set: SY-
MSGID - message ID; SY-MSGTY - message type; SY-MSGNO - message
number.
Message Type:
Type Display Action
I - Info Dialog window 'Press Enter to continue'.
'Correction possible'.
W - Warning Status window
= E for Lists Processing
'Correction required'.
E - Error Status window = A for Processing of basic list,
returns to the previous list level for a secondary list.
A - Abend Dialog window 'Transaction terminated'.
= A, but transaction terminated with short dump
X - eXit Status window
MESSAGE_TYPE_X
S - Success Status window 'Message on next screen'.

Predefined System Codes.


Go to top...
Go to next...

Predefined and assigned to the different elements of the status.


Status
Element - Function
Code Menu Description
Standard Key
Toolbar
%PC List Shift-F8 Write list to file
PRI List Ctrl-P Print displayed list
%EX List Shift-F3 Exit processing
PICK Edit F2 Event AT LINE-SELECTION
RW Edit F12, Esc Cancel processing
%SC Edit Ctrl-F Search pattern
%SC+ Edit Ctrl-G Continue search
BACK Goto F3 Back one level
P-- F21 Scroll to first window page
P- F22 Scroll to previous window page
P+ F23 Scroll to next window page
P++ F24 Scroll to last window page
Places the cursor into the menu bar to
F10
select a menu function
Predefined, but not set as status functions.
Can be assigned to any empty status element.
Code Description
PF<nn> Event AT PF<nn>
PP<n> Scroll to top of list page <n>
PP-[<n>] Scroll backward 1 or <n> pages
PP+[<n>] Scroll forward 1 or <n> pages
PS<n> Scroll to column <n>
PS-- Scroll to first column of the list
PS-[<n>] Scroll left by 1 or <n> columns
PS+[<n>] Scroll right by 1 or <n> columns
PS++ Scroll to last column of the list
PZ<n> Scroll to line <n>
PL-[<n>] Scroll backward to first line of the page or by <n> lines
PL+[<n>] Scroll forward to last line of the page or by <n> lines
/.... For other system commands
Tips and tricks:

• Any other (own or predefined) function code cannot be assigned to F10;


• Replace function code PICK with your own function code to prevent the
AT LINE-SELECTION event from being triggered in the report. You can
then program all reactions to user actions in a single processing block (AT
USER-COMMAND).
• Delete predefined function codes whose functionality you do not want to
support. For example, you may not want the user to print a list directly or
to save a list in a file on the presentation server.
• Modify the standard key settings. For example, you can assign your own
function code to F3 to navigate within the lists according to your
requirements, instead of returning one list level (Back). This may be
important if you keep several lists on the same logical level and therefore
do not want to delete the displayed list as would the standard F3 setting.
Or you may want to display a warning before leaving a list level (see
Messages in Lists).

Internal Tables Processing.

Identifying Table Lines.


Go to top...
Go to next...

Internal Table Index:


The sequential number of a table line. Created and managed automatically by the
system. Can be used with the DELETE, INSERT, MODIFY, LOOP, and READ
TABLE statements, specified either as literal or as variable. After processing a
particular line of an internal table, the SY-TABIX generally contains the index of
that line.
Internal Table Key:

• Standard - by definition, the key fields of an internal table are those fields
which are not numeric (type F, I, and P) and are not internal tables. These
key fields form the standard key of an internal table. To obtain the
standard key of an internal tables with nested structures (table lines which
contain field strings as components), the system breaks down the sub-
structures to the level of elementary fields;
• Self-Defined - can be specified when reading lines from an internal table
using the READ TABLE.

Filling Table.
Go to top...
Go to next...

Appending Lines:
APPEND [{<wa>|INITIAL LINE} TO] <itab>.
Appends a new line to table. For tables with a header line the source area can be
omitted. After statement, the SY-TABIX contains the index of the appended line.
APPEND LINES OF <itab1> [FROM <idx1>] [TO <idx2>] TO <itab2>.
Appends lines from one table to another table. Default appends entire table. After
statement, the SY-TABIX contains the index of the last appended line. About 3 to
4 times faster than appending lines line by line in a loop.
APPEND [<wa> TO] <itab> SORTED BY <f>.
Inserts the new line so that the internal table <itab> is sorted in descending order
by the field <f>. If you use the SORTED BY option, the table can contain only the
number of lines specified in the OCCURS parameter. If you add more lines than
specified, the last line is discarded. This is useful for creating ranked lists of
limited length (e.g. "Top Ten"). For ranked lists containing more than 100 entries,
use instead the SORT for performance reasons.
Inserting Lines:
INSERT [{<wa>|INITIAL LINE} INTO] <itab> [INDEX <idx>].
Inserts a new line into table. For tables with a header line the source area can be
omitted. With INDEX option, the new line is inserted before the line which has
the index <idx>. After the insertion, the new entry has the index <idx> and the
index of the following lines is incremented by 1.
If the table consists of <idx> - 1 entries, the system appends the new entry after
the last existing table line. If the table has less than <idx> - 1 entries, the system
cannot insert the entry: SY-SUBRC = 4. If success, SY-SUBRC = 0.
Use INSERT without the INDEX option is allowed only within a LOOP -
ENDLOOP loop by inserting the new entry before the current line (i.e. the line
which has the index returned by SY-TABIX).
INSERT LINES OF <itab1> [FROM <idx1>] [TO <idx2>] INTO <itab2>
[INDEX <idx>].
Inserts lines from one table into another table. Default inserts entire table. Can be
up to 20 times faster than inserting lines line by line in a loop.
Collecting Lines:
COLLECT [<wa> INTO] <itab>.
If a table entry with the same standard key does not exists (all non-numeric
fields), the COLLECT has the same effect as the APPEND. If exists, the
COLLECT adds the contents of the numeric fields in the work area to the contents
of the numeric fields in the existing entry. SY-TABIX contains the index of the
processed line.

Reading Table.
Go to top...
Go to next...

Reading Single Lines:


READ TABLE <itab> [INTO <wa>] INDEX <idx>.
Reads the single line with index <idx> into <wa> (or into header line, if omitted).
This is the fastest method.

• <idx> <= 0 : runtime error;


• <idx> > table size : SY-SUBRC = 4;
• <idx> found : SY-SUBRC = 0, SY-TABIX = <idx>.

READ TABLE <itab> [INTO <wa>] [BINARY SEARCH].


Reads the first line with a particular standard key, which should be placed in the
table work area (works only for internal tables with header line).

• entry found : SY-SUBRC = 0, SY-TABIX = <idx>;


• entry not found : SY-SUBRC <> 0;.

READ TABLE <itab> [INTO <wa>] WITH KEY <key> [BINARY


SEARCH].
Reads the first line with <key>.

• entry found : SY-SUBRC = 0, SY-TABIX = <idx>;


• entry not found : SY-SUBRC <> 0;.

Key definition for internal tables:


....WITH KEY <k1> = <f1> ... <kn> = <fn> ...
The self-defined key consists of the table components <k1>...<kn>. If the data
type of <fi> is not compatible to the data type of <ki>, then <fi> is converted to
the type of <ki>. You can specify an offset and length for any component you use
in the key. You can set key fields at runtime by replacing <ki> with (<ni>). The
key field is the contents of the field <ni>. If <ni> is blank at runtime, the system
ignores this key field. If <ni> contains an invalid component name, a runtime
error occurs.
....WITH KEY = <value> ...
Defines entire line as key (will be converted if necessary).
....WITH KEY <value> ...
The system compares the (left-justified) beginning of a line with <value>.
<value> cannot contain an internal table or a structure containing an internal
table. In contrast to the above two options, the comparison is processed using the
data type of <value>.
Additions:

• BINARY SEARCH - performs a binary search instead of the standard


sequential search (much faster). Table must be sorted.
o SY-SUBRC = 0 : entry found, SY-TABIX = index of the found
entry;
o SY-SUBRC = 4 : entry not found, SY-TABIX = index of the next
largest entry, output area remains unchanged;
o SY-SUBRC = 8 : entry not found, the key is greater than last table
entry, SY-TABIX = (number of all entries + 1), output area
remains unchanged.
• TRANSPORTING {<f1> ... <fn>|NO FIELDS} - only transports
selected fields to the target area.
• COMPARING {<f1> ... <fn>|ALL FIELDS} - reads single line with key
or index into the target area. After reading the line, the components
specified in fields list are compared to the corresponding components of
the target area:
o SY-SUBRC = 0 : line is read and the contents of the compared
fields are the same;
o SY-SUBRC = 2 : line is read, but the contents of the compared
fields are not the same;
o SY-SUBRC = 4 : no line was read.

LOOP Processing:
LOOP AT <itab> [INTO <wa>] [FROM <n1>] [TO <n2>] [WHERE
<condition>].
...
ENDLOOP.
<itab> is read line by line into <wa> or into the table work area. For each line
read, processed the statement block between LOOP and ENDLOOP. Within the
statement block, SY-TABIX contains the index of the current line. The loop ends
as soon as all lines of the table have been processed. After the ENDLOOP
statement:

• SY-SUBRC = 0 : at least one line was read;


• SY-SUBRC = 4 : otherwise it is set to 4.

Restriction the number of lines to be processed:

• FROM <n1> - the index of the first line to be read.


• TO <n2> - the index of the last line to be read.
• WHERE <condition> - the first operand of the logical expression must be
a component of <itab>. Cannot be used together with the control keyword
AT inside the loop.

Note. The FROM and TO options restrict the number of lines which the system
has to read. The WHERE option only prevents unnecessary filling of the work
area. With the WHERE option, the system must read all lines. To improve
performance, you should use the FROM and TO options as much as possible. It
can be also beneficial to leave the loop with the EXIT statement instead of using
the WHERE option.
Calculating Totals:
SUM.
Can be used only in LOOP - ENDLOOP block. A component of an internal table
line may not be another table. In an AT - ENDAT block, calculates totals for the
numeric fields (I, F, P) of all lines in the current line group and writes them to the
corresponding fields in the work area. Outside an AT - ENDAT block - do it for
lines of the internal table in each loop pass. Therefore, SUM should be used only
in AT - ENDAT blocks.
Using Control Levels for Groups of Lines (AT ... ENDAT Events):
AT <line>.
...
ENDAT.
The <line> condition:
<line> Meaning
FIRST First line of the internal table
LAST Last line of the internal table
Beginning of a group of lines with the same contents in the field <f>
NEW <f>
and in the fields left of <f>
END OF End of a group of lines with the same contents in the field <f> and in
<f> the fields left of <f>
<f> can be:

• table field name;


• table field name with Offset/Length specification;
• field symbol. If it does not point to a valid component, a runtime error
occurs;
• (<name>) instead of <f> (See also). The <name> contains the name of the
field <f>. If <name> is empty at runtime, the system ignores the control
break criterion. If it contains an invalid component name, a runtime error
occurs.

Cannot be used together with the WHERE restriction of a LOOP.


Immediately after AT:

• All default key fields [on the right of <f>] are filled with '*';
• All other fields [on the right of <f>] are cleared;
• If SUM used then appropriate control totals are inserted in numeric fields;
• After AT the old contents of LOOP output area are restored.

Modifying Table.
Go to top...
Go to next...

MODIFY <itab> [FROM <wa>] [INDEX <idx>] [TRANSPORTING <f1> ... <fn>
[WHERE <condition>]].
Modifies the line in the table. For tables with a header line the source area can be
omitted. With INDEX option, will be modified the line which has the index
<idx>. In this case: SY-SUBRC = 4 if no line with <idx> exists; SY-SUBRC = 0
- success.
Use MODIFY without the INDEX option is allowed only within a LOOP -
ENDLOOP loop by modifying the current line (i.e. the line which has the index
returned by SY-TABIX).
With the TRANSPORTING option, the system transports only the components
<f1> ... <fn> from the work area into the internal table. Strongly recommended
suppress unnecessary transports of fields which are internal tables itself. You can
specify a component dynamically by writing (<name>). In this case, the system
reads the name of the component from field <name> at runtime. An invalid
component name leads to a runtime error.
WHERE <condition> with the TRANSPORTING option determines all the lines
of the table into which the components <f1> ... <fn> are to be transported. First
operand should be a component of the internal table's line structure. WHERE
cannot be used together with the INDEX option.
WRITE <f>[+<o1>][(<l1>)] TO <itab>[+<o2>][(<l2>)] INDEX <idx>.
Variant of WRITE TO. Overwrites the section of the line of the <itab> that has
index <idx>. Does not affect header line. Does not recognize the structure of table
lines. Return codes: SY-SUBRC = 4 - no line with <idx> exists; SY-SUBRC = 0
- success. If <idx> <= 0 - runtime error.
Deleting lines:
DELETE <itab>.
Deletes current line in LOOP - ENDLOOP (that is line which have index SY-
TABIX). After the first line has been deleted, the current line and its assignment
to the contents of SY-TABIX can be undefined. To process further lines within
this loop, use only statements with the INDEX option.
DELETE <itab> INDEX <idx>.
Deletes line with the index <idx>. Return codes: SY-SUBRC = 4 - no line with
<idx> exists; SY-SUBRC = 0 - success.
DELETE ADJACENT DUPLICATES FROM <itab> [COMPARING {<f1>
... <f1>|ALL FIELDS}].
Deletes adjacent duplicates entries. Return codes: SY-SUBRC = 0 - at least one
entry was deleted; SY-SUBRC = 4 - otherwise. Without the COMPARING
option, the contents of the standard key fields must be the same.
DELETE <itab> [FROM <n1>] [TO <n2>] [WHERE <condition>].
Deletes selected entries. At least one of three criteria should be used. First
operand in WHERE should be a component of the internal table's line structure.
Return codes: SY-SUBRC = 0 - at least one entry was deleted; SY-SUBRC = 4 -
otherwise.

Clearing Table.
Go to top...
Go to next...

You can check whether an internal table is empty using logical expression:
... <itab> IS INITIAL ...

REFRESH <itab>.
Empties internal table.
CLEAR <itab>[].
Empties internal table without clearing the table work area.
CLEAR <itab>.
Empties internal table that has no table work area (header line).
Clears the table work area if the table has it.
FREE <itab>.
Empties internal table and releases reserved memory without clearing the table
work area.

Other Operations With Internal Table.


Go to top...
Go to next...

SORT <itab> [<order>] [AS TEXT]


[BY <f1> [<order>] [AS TEXT] ... <fn> [<order>] [AS TEXT]].
<order>: ASCENDING (default) or DESCENDING. Sorts by standard or self-
defined (if BY defined) key. The system uses the options you specify before BY
as a default for all fields specified behind BY. The options that you specify after
individual fields overwrite for these fields the options specified before BY.
<f1> ... <fn> can be:

• of any type, including type P, I, and F fields, or tables;


• up to 250;
• (<name>) instead of <f> (See also). The <name> contains the name of the
field <f>. If <name> is empty at runtime, the system ignores it. If it
contains an invalid component name, a runtime error occurs.;
• table field name with Offset/Length specification;

Without the option AS TEXT, the system sorts character fields binarily and
according to their platform-dependent internal coding. With the option AS TEXT,
the system sorts character fields alphabetically according to the current text
environment. By default, the text environment is set in the user's master record.
As an exception, you can set the text environment with the SET LOCALE
LANGUAGE. The option AS TEXT frees you from converting a character field
into a sortable format before sorting. Such a conversion is only necessary, if you
want to

• sort an internal table alphabetically first and search it binarily afterwards.


The order of an internal table after alphabetical sorting differs from the
order after binary sorting.
• sort an internal table several times with alphabetical keys. In this case, the
performance is better, because the conversion is processed only once;
• create alphabetical indexes for database tables in your program.

AS TEXT before BY influences only the character fields in the sort key. If you
specify AS TEXT after a field name, this field must be of type C. Sorting is not
stable. This means that the old sequence of lines with the same sort key may not
necessarily be retained. If there is not enough space for sorting in the main
memory, the system writes data into a temporary external file. The name of this
file is defined in the SAP profile parameter DIR_SORTTMP.
Searching Internal Tables for Character String:
SEARCH <itab> FOR <str> [<options>].
Options and patterns like searching string for string. No type conversion is
performed also (the entire table line is treated as character string). <itab> is
always table, not header line, if even the table has header line. In addition to SY-
SUBRC and SY-FDPOS, SY-TABIX is set to found line index.
Logical Expressions:
... <itab1> {EQ|=|NE|<>|><|GE|>=|LE|<=|GT|>|LT|<} <itab2> ...
The first criterion for comparing internal tables is the number of lines they
contain. The more lines an internal table contains, the larger it is. If two internal
tables contain the same number of lines, they are compared line by line,
component by component. If components of the table lines are themselves internal
tables, they are compared recursively. If you use operators other than the equality
operator, the system stops the comparison as soon as it finds a pair of components
which are not equal and returns the result. In the case of internal tables with a
header line, you can use square brackets ([]) after the table name to distinguish the
table body from the table work area.
Assignment Operator:
MOVE <itab1> TO <itab2>.
[COMPUTE] <itab2> = <itab1>.
Copies entire contens of internal table that has not header line.
MOVE <itab1>[] TO <itab2>[].
[COMPUTE] <itab2>[] = <itab1>[].
Copies entire contens of internal table with header line.

RANGES.
Go to top...
Go to next...

RANGES <range> FOR <f>.


This is a short form of
DATA: BEGIN OF <range> OCCURS 10,
SIGN(1),
OPTION(2),
LOW LIKE <f>,
HIGH LIKE <f>,
END OF <range>.
Creates a selection table <range> which refers to the column of database field <f>
or to an internal field <f>. The <range> has the same structure as Selection
Options internal table, but the are not part of the selection screen and are not
linked to a database table.
SIGN OPTION LOW HIGH
Logical operators:
• I-
• Single value - if
inclusi • EQ, NE, GT, GE, LE,
HIGH is empty;
on; LT, CP, NP - if HIGH
Upper limit
is empty;
• Lower limit - if or empty
• E-
HIGH is not
exclusi • BT (between), NB
empty.
on. (not between) - if
HIGH is not empty.

Selection Screens.

Parameters.
Go to top...
Go to next...
PARAMETERS <parm>[(<length>)] <type> [<decimals>].
Creates a parameter <parm>. The additions length, type, and decimals are the
same as for DATA. Cannot have type F. Comments on the left side of the input
fields can be changed using Selection Texts.
Other additions:

• DEFAULT <f> - can be either a literal or a field name. Default values


transported before INITIALIZATION. Therefore, default can be only
fields which are already filled when the user starts the program (e.g.
SY-...);
• NO-DISPLAY - hides parameter. To hide a parameter only under certain
conditions declare it without NO-DISPLAY suppress its display by using
MODIFY SCREEN.
• LOWER CASE - allows accept lower case. Cannot be used if a parameter
references a dictionary fields which has its own attributes;
• OBLIGATORY
• AS CHECKBOX - creates a checkbox (type C(1)). Cannot have TYPE|
LIKE addition. Valid values are ' ' and 'X'.
Note. Using LIKE to refer to an ABAP/4 Dictionary field of type CHAR
of length 1 and valid values 'X' and ' ' (defined in the field's domain)
automatically creates a checkbox on the selection screen;
• RADIOBUTTON GROUP <radi> - creates a radiobutton and assigns it
to the group <radi> (length of the <radi> cannot be > 4). Can have LIKE
refering to C(1). Valid values are ' ' and 'X'. If no DEFAULT addition
exists then first radiobutton in group will be 'X';
• MEMORY ID <pid> - uses a default value from the global SAP memory
(SPA/GPA parameters). <pid> can be up to 3 characters long and must not
be enclosed in quotation marks. You use the global SAP memory to pass
values retained beyond transaction limits between programs. This memory
is available to a user for the entire duration of a terminal session and any
parallel sessions use the same memory. The SAP memory is thus more
comprehensive than the transaction-bound Data Clusters in ABAP/4
memory. See the TPARA table ("Directory of Memory IDs") for all
system Memory IDs. Parameters can be set user specific in the user's
master records with the name <pid>. See also SET/GET PARAMETER.
• MATCHCODE OBJECT <mobj> - assigns matchcode object from Data
Dictionary to the parameter. <mobj> should be 4 characters long and must
not be enclosed in quotation marks. If you use this option, the possible
entries pushbutton appears after the input field of the parameter (? not
always). When the user presses this button, the effect is to perform a
matchcode selection for the input field
• MODIF ID <key> - assigns the parameter to a modification group. <key>
should be 3 characters long and must not be enclosed in quotation marks.
The MODIF ID option always assigns <key> to the column SCREEN-
GROUP1 of the internal table SCREEN. Parameters assigned to a
modification group can be processed as an entire group with the LOOP AT
SCREEN/MODIFY SCREEN statements during the AT SELECTION-
SCREEN OUTPUT event;
• logical database specific additions.

Selection Options.
Go to top...
Go to next...

SELECT-OPTIONS <selopt> FOR <fgt;.


Creates a selection table <selopt> for the column <f> of a database table or for an
internal field <seltab>. The database table must be declared with TABLES. The
<selopt> name can be up to 8 characters. Cannot have type F. Comments on the
left side of the input fields can be changed using Selection Texts.
The <selopt> has the same format as RANGE tables. Additions the same as for
PARAMETERS:

• NO-DISPLAY
• LOWER CASE
• OBLIGATORY
• MEMORY ID <pid>
• MATCHCODE OBJECT <mobj>
• MODIF ID <key>

Specific additions:

• DEFAULT <f1> [TO <f2>] [OPTION <option>] [SIGN <sign>] - fills


1st line of <selopt> with default value or interval (if both <f1> and <f2>).
<f1> and <f2> can be either a literal or a field name. Default values
transported before INITIALIZATION. Therefore, default can be only
fields which are already filled when the user starts the program (e.g.
SY-...).
<option>:
o single values - EQ, NE, GE, GT, LE, LT, CP, or NP. The default
value is EQ;
o intervals - BT or NB. The default value is BT.

<sign> = I|E (Incllude|Exclude). The default value is I;

• NO-EXTENSION - forbids multiple selection( );


• NO INTERVALS - hides TO-field (but an interval is still can be selected
using the button. Use the function module
SELECT_OPTIONS_RESTRICT to completely forbid intervals);
• NO DATABASE SELECTION - if a logical database is attached to the
report program and a selection criterion is connected to a database table,
which is also part of the logical database, and if that database table is
designated for a dynamic selection, the system transfers the corresponding
selection criteria to the logical database. The logical database does not
read lines from the database table that do not meet these selection criteria.
If you want the logical database to read these lines anyway, for example,
when you use the selection criteria for other purposes than limiting
database accesses, use the NO DATABASE SELECTION.
• logical database specific additions.

Selection Screen Formatting.


Go to top...
Go to next...

SELECTION-SCREEN SKIP [<n>].


Generates <n> blank lines, where <n> = 1..9, 1 is default.
SELECTION-SCREEN ULINE [<format>] [MODIF ID <key>].
Generates an underline.
<format> is [[/]<pos>](<len>): "/" generates a new line and therefore is not
allowed inside BEGIN OF LINE...END OF LINE. (<len>) without <pos> uses
current position and only allowed inside BEGIN OF LINE...END OF LINE.
<pos> can be a number (in this case it is relative to the frame if inside BEGIN OF
BLOCK WITH FRAME...END OF BLOCK) or POS_LOW|POS_HIGH.
SELECTION-SCREEN COMMENT <format> <text> [FOR FIELD <f>|<selopt>]
[MODIF ID <key>].
Writes <text>:

• text symbol text-<nnn>;


• a field name with a maximum length of 8 characters. This character field
must not be declared with (for example) the DATA statement, but is
generated with length <len> automatically and must be filled dynamically
during the INITIALIZATION.

FOR FIELD option has as a result, if the user requests help on the comment on
the selection screen, the help text for the assigned field is displayed.
SELECTION-SCREEN BEGIN OF LINE.
...
SELECTION-SCREEN END OF LINE.
Places several elements on a single line. Note that the selection text (name of the
parameter or text element) is not displayed when this option used. To display a
selection text COMMENT option must be used.
SELECTION-SCREEN POSITION <pos>.
<pos> can be a number (in this case it is relative to the frame if inside BEGIN OF
BLOCK WITH FRAME...END OF BLOCK) or POS_LOW|POS_HIGH.
SELECTION-SCREEN BEGIN OF BLOCK <block> [WITH FRAME [TITLE
<text>]] [NO INTERVALS].
...
SELECTION-SCREEN END OF BLOCK <block>.
Creates a logical block. Blocks can be nested. Only 5 blocks with frames can be
nested. NO INTERVALS displays all SELECT-OPTIONS within the block as
with NO INTERVALS addition; inherited by subordinate blocks with frames and
does not by subordinates blocks without frames.

Selection Screen Events.


Go to top...
Go to next...

INITIALIZATION.
Executes a processing block before the selection screen is processed. In this block
you initialize the selection screen. This is also the only possibility to change the
default values of parameters or selection criteria defined in logical databases. You
can find out the names of the internal fields you want to change either by
examining the logical database SAPDB<ldb> itself (with the transaction SLDB or
by choosing Tools->ABAP/4 Development Workbench->Development-
>Programming environ.->Logical databases), or by retrieving the technical
information of that field.
AT SELECTION-SCREEN.
Executes a processing block after the system has finished processing the selection
screen. If an error|warning message is sent from this processing block, the system
displays the selection screen again and all input fields can be changed.
AT SELECTION-SCREEN ON <parm>|<selopt>.
Executes a processing block after the system has finished processing the <parm>|
<selopt>. If an error|warning message is sent from this processing block, the
system displays the selection screen again and only this input field can be
changed.
AT SELECTION-SCREEN ON END OF <selopt>.
Executes a processing block at the end of processing Multiple Selection Window
of the <selopt>. Can be used to check the entries in the internal table
<selopt>. Both the E and W messages are sent in dialog window.
AT SELECTION-SCREEN ON BLOCK <block>.
Executes a processing block after the system has finished processing the <block>.
If an error|warning message is sent from this processing block, the system
displays the selection screen again and only the input fields in the <block> can be
changed.
AT SELECTION-SCREEN ON RADIOBUTTON GROUP <radi>.
Executes a processing block after the system has finished processing the <radi>.
If an error|warning message is sent from this processing block, the system
displays the selection screen again and only the radiobutton group <radi> can be
changed.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR <parm>|<selopt>.
The possible entries button automatically appears next to the input field for
<parm>|<selopt> when it is selected on the selection screen. Executes a
processing block which allows user to choice a value from a list when user
presses the button or F4. Can be used only in report programs, not in a logical
database program.
AT SELECTION-SCREEN ON HELP-REQUEST FOR <parm>|<selopt>.
Executes a processing block which displays a help text when user presses F1 or
the button on the selected <parm>|<selopt>. Can be used only in report
programs, not in a logical database program.
AT SELECTION-SCREEN OUTPUT.
Executes a processing block during the PBO of a selection screen for each
ENTER. For example, here can be applied a modifications to the screen:
LOOP AT SCREEN.
....
MODIFY SCREEN.
ENDLOOP.
To change at runtime attributes of screen fields. SCREEN is memory table which
automatically created and maintained by system (with header line). The structure
of the SCREEN:
Name Length Description
NAME 30 Name of the screen field
GROUP1 3 Modification group 1
GROUP2 3 Modification group 2
GROUP3 3 Modification group 3
GROUP4 3 Modification group 4
ACTIVE 1 Visible and ready for input
REQUIRED 1 Mandatory
INPUT 1 Ready for input
OUTPUT 1 For display only
INTENSIFIED 1 Highlighted
INVISIBLE 1 Supressed
LENGTH 1 Output length is reduced
DISPLAY_3D 1 Displayed with 3D frames
VALUE_HELP 1 Displayed with value help
To activate a field attribute, set its value to 1. To deactivate it, set it to 0. If
ACTIVE = 0, then system sets INVISIBLE = 1 and INPUT = 0, and user can
neither see the field nor enter values into it.

Field Symbols.

Defining Field Symbols.


Go to top...
Go to next...

Concept.
Field symbols are placeholders for existing fields. A field symbol does not
physically reserve space for a field, but points (like a pointer in C) to a field
which is not known until runtime of the program. But Field Symbols are not real
equivalent to pointers in the sense of variables which contain a memory address
and can be used without the contents operator. You can only work with the data
object to which a field symbol points. A field must first be assigned to field
symbol before working with it in the program. Assignments to field symbols may
extend beyond field boundaries. This allows effective access to regularly stored
data. At runtime, the system performs checks to prevent erroneous assignments
outside the defined data areas:

• The table storage area for internal tables. Its size depends on the number
of table lines which is not fixed, but often extended dynamically at
runtime;
• The DATA storage area for other data objects. Its size is fixed during the
data declaration and equal to sum of all data objects sizes.

Field symbols cannot point to addresses outside these areas. If the system
encounters this at runtime, it stops processing the program.
Note. Certain system information, such as the control blocks of internal tables, is
also stored in the DATA storage area. Therefore, despite the runtime checks, you
may unintentionally overwrite some of these fields and cause subsequent errors
(e.g. destruction of the table header).
Defining Field Symbols for Internal Fields.
FIELD-SYMBOLS <FS> [<type>].
For field symbols, the angle brackets are part of the syntax.
<type> Syntax check for field assignment.
No type
System accepts any field type and uses all attributes and
specification,
structure of the field for the <FS>
TYPE ANY
System accepts only an internal table uses all attributes of the
TYPE TABLE
table for the <FS>
System accepts only an appropriate field type. The <FS>
TYPE C, N, P, X
inherits field length (and DECIMALS for P)
TYPE D, F, I, T
LIKE <f>
System accepts only completely compatible field type.
TYPE <user-defined-
type>
Defining Structured Field Symbols.
FIELD-SYMBOLS <FS> STRUCTURE <fstring> DEFAULT <f>.
Defines a structured <FS> which points initially to the field <f> (this assignment
can be changed later). The <FS> inherits the structure of <fstring>, which can be
any field string or a structure defined in the ABAP/4 Dictionary. <fstring> and
<f> must be specified without quotation marks. Specification at runtime is not
allowed. If <fstring> contains no components of type I or F, <f> can be any
internal field with at least the same length as the structure <fstring>. If <f> is
shorter than <fstring>, an error occurs during the syntax check. This will be also
while assigning later in program. Dynamic assignment causes a runtime error. If
<fstring> contains components of type I or F (that is this structure is aligned),
then the data object must also be aligned accordingly, otherwise a runtime error
occurs.
Defining Local Field Symbols.
If <fstring> id defined in a subroutine or function module then each time the
subroutine or function module is called, no field is assigned to the local field
symbol, even if an ASSIGN was executed the previous time.

Assigning Data Objects to Field Symbols.


Go to top...
Go to next...

Assigning Data Objects.


Static Assignment:

• ASSIGN [LOCAL COPY OF] <f>[+<o>][(<l>)] TO <FS> [TYPE


<type>] [DECIMALS <d>].
<o> and <l> can be variables. If no offset and length defined, then <FS>
points to the same memory area as <f>. <o> and <l> can refer to addresses
beyond <f>. Defaults: <o>=0, <l>=length of <f>. If <o> is smaller than
length of <f> then (*) can be used for <l> to prevent <FS> from referring
addresses beyond <f>.

Dinamic Assignment:
• ASSIGN [LOCAL COPY OF] (<n>) TO <FS> [TYPE <type>]
[DECIMALS <d>].
Offset cannot be specified. Order of search for the field's name <n>:
1. Local Data of the Subroutine or Function Module;
2. Global Data of the Program;
3. Table work areas declared with the TABLES statement in the main
program of the current program group. A program group consists
of a main program and all programs containing definitions of the
external subroutines called by the main program (including nested
ones).

This type of search has very adverse effect on response times. Return
code: SY-SUBRC=0 if success, otherwise SY-SUBRC=4.

• ASSIGN [LOCAL COPY OF] TABLE FIELD (<n>) TO <FS> [TYPE


<type>] [DECIMALS <d>].
Performs only Step 3 from previous operation. Return code: SY-
SUBRC=0 if success, otherwise SY-SUBRC=4.

Assigning Field Symbols to Other Field Symbols.


Static Assignment:

• ASSIGN [LOCAL COPY OF] <FS1>[+<o>][(<l>)] TO <FS2> [TYPE


<type>] [DECIMALS <d>].

Dinamic Assignment:

• ASSIGN [LOCAL COPY OF] [TABLE FIELD] (<n>) TO <FS2>


[TYPE <type>] [DECIMALS <d>].
The field <n> contains the name of field symbol <FS2>. <FS1> and
<FS2> can be identical.

Assigning Components of Field Strings.

• ASSIGN COMPONENT <component> OF STRUCTURE <fstring>


TO <FS> [TYPE <type>] [DECIMALS <d>].
If <component> is of type C or a field string which has no internal tables
as components - it specifies the name of the component. If <component>
has other type - it is converted to type I and specifies the number of the
component in the <fstring>. Return code: SY-SUBRC=0 if success,
otherwise SY-SUBRC=4.

Additions:

• TYPE <type> - <type> can be literal or variable. Overrides type of field


<f> for untyped field symbols (in this case <type> must be Elementary
Data Type). For typed field symbols used if the <f> is uncompatible with
type of <FS> and runtime error must be avoided. In this case <type> and
type of <FS> must be compatible.
• DECIMALS <d> - defines number of decimal places in <FS>. A runtime
error occurs if <f> is not of P type, or <d> is not between 0 and 14.
• LOCAL COPY OF - used in subroutines. The system places a copy of the
specified global data on the stack. In the subroutine, you can access and
change this copy without changing the global data.

Modularization.

Branches and Loops.


Go to top...
Go to next...

IF CASE
CASE <f>.
IF <condition1>.
WHEN <f1>.
<statement block>
<statement block>
ELSEIF <condition2>.
WHEN <f2>.
<statement block>
<statement block>
......
......
ELSE.
WHEN OTHERS.
<statement block>
<statement block>
ENDIF.
ENDCASE.

Unlimited nesting is allowed. An EVENT keyword may not be inside of block.

DO WHILE
DO [<n> TIMES] [VARYING <f> FROM WHILE <condition> [VARY <f> FROM
<f1> NEXT <f2>]. <f1> NEXT <f2>].
<statement block> <statement block>
...... ......
[CONTINUE.] [CONTINUE.]
[EXIT.] [EXIT.]
[CHECK <condition>. [CHECK <condition>.
<statement block>] <statement block>]
ENDDO. ENDWHILE.
Unlimited nesting is allowed. An EVENT keyword may not be inside of block.
<n> can be literal or a variable. If <n> <=0, the system does not process the loop.
SY-INDEX contains the number of times the loop has been processed.
<f>, <f1>, <f2> must be a series of equidistant fields of the same type and length in
memory. In the first loop pass, <f1> is assigned to <f>; in the second loop pass <f2> is
assigned to <f>; and so on. Several VARYING|VARY options can be used in one DO|
WHILE statement. If you change the control variable <f> inside the DO loop, the system
changes the corresponding field <fi> automatically. If loop processed more times than the
number of variables <fi>, this may result in a runtime error.

Terminating Loops.
CONTINUE.
Terminates a loop pass immediately without any condition, continues with the
next loop pass.
EXIT.
Acts in following sequence:

1. Terminates a loop entirely without any condition and continues the


processing after the closing statement (ENDDO, ENDWHILE,
ENDSELECT). Within nested loops, leaves the current loop;
2. Leaves the current AT processing block and branches to the processing
block of the next occurring event;
3. Leaves any processing block (except of AT events) immediately and
branch to the output screen;
4. Terminates a subroutine without any condition.

CHECK <condition>.
Acts in following sequence:

1. For a loop, if the condition is false, skips all the remaining statements in
the current statement block and continues with the next loop pass;
2. For GET event, if the condition is false, equivalent to REJECT. (Leaves
the processing block of a GET event and processes the next GET event at
the same hierarchical level of the logical database.);
3. For processing block, if the condition is false, leaves the processing block
and branches to the processing block of the next occurring event;
4. For a subroutine, if the condition is false, terminates the subroutine.

Events.
Go to top...
Go to next...

All statements between two event keywords or between an event keyword and a FORM
statement are a processing block. When an event occurs, the system processes the
processing block after the corresponding event keyword. Each statement in an ABAP/4
report program is part of a processing block or a subroutine. Statements which do not
follow an event keyword or a FORM-ENDFORM block are automatically part of the
processing block of the default event START-OF-SELECTION.
Note. All statements between an ENDFORM statement and an event keyword or between
an ENDFORM statement and the end of the program are never processed. Do not place
any statements there. Place all subroutines at the end of your program.

Events that occur at runtime of a report program which


uses logical databases, or
has selection screens and processes tables (exept GET events):
INITIALIZATION.
Point before the selection screen is displayed.
AT SELECTION-SCREEN.
Point after processing user input on the selection screen while the selection screen
is still active.
START-OF-SELECTION.
Point after processing the selection screen and before accessing database tables
using a logical database.
GET <table> [FIELDS <f1> <f2> ...].
Point at which the logical database (LDB) offers a line of the database table
<table>. The LDB reads all columns from all database tables which are not
designated for field selection in the LDB and which are superior to <table> on the
access path of the LDB, even if GET for these tables are not specified. However,
only the data of tables declared by TABLES can be accessed. From tables that are
not declared by TABLES system reads only the key fields (the LDB needs the key
fields to built up the access path).
GET <table> LATE [FIELDS <f1> <f2> ...].
Point after processing all tables which are hierarchically subordinate to the
database table <table> in the structure of the logical database.
END-OF-SELECTION.
Point after processing all lines offered by the logical database.
The following events occur during the processing of the output list of a report
program:
Events Control in Interactive Lists.
Terminating Events Processing Blocks:
STOP.
Leaves any processing block immediately and branches to the END-OF-
SELECTION processing block.
REJECT [<dbtab>].

• Leaves the processing block of a GET event and processes the next GET
event of a superior hierarchical level of the logical database <dbtab>
• Leaves the processing block of a GET event and processes the next GET
event at the same hierarchical level of the logical database.
See also:
EXIT, CHECK.

Dialogs.
Go to top...
Go to next...

Not ready yet...

Source Code Modules.


Go to top...
Go to next...

Using Macros.
DEFINE <macro>.
<statements>
END-OF-DEFINITION.
Defines <macro>. The <statements> can contain up to 9 placeholders: &1, &2, ...
&9.
<macro> [<p1> <p2> ... <p9>].
Calls <macro> (System replaced macro during generation of the program). Macro
can call another macro, but cannot call itself.
Using Include Programs.
INCLUDE <name_of_include_program>
Inserts the source code <name_of_include_program> into the ABAP/4 program
during the syntax check and during generation.

• INCLUDE statement must be whole on one line and only on this line;
• The INCLUDE program must consist of complete statements (and
comments);

Service report RSINCL00 can be used to generate reference list for included
programs.

Subroutines.
Go to top...
Go to next...

Defining Subroutines.
FORM <subroutine> [<parameters>].
<statements>
ENDFORM.
Calling Subroutines.
Internal subroutines have the source code in the calling ABAP/4 program:
PERFORM <subroutine> [<parameters>].
PERFORM (<subrname>) [<parameters>].
Specifies the subroutine name at runtime.
PERFORM <subroutine> ON COMMIT [LEVEL <n>].
Calls the subroutine later on a first encountered COMMIT WORK statement. The
subroitine is called only once even if call performed many times. LEVEL <n>
(literal or constant, default is 0) defines order of execution of subroutines on
COMMIT WORK. The subroutines are called in ascending level order, or in order
of calls if level the same.
External subroutines have the source code in another ABAP/4 program:
PERFORM <subroutine>(<program>) [<parameters>] [IF FOUND].
PERFORM <subroutine> IN PROGRAM <program> [<parameters>] [IF
FOUND].
IF FOUND - call subroutine only if found in program, otherwise skip call.
PERFORM (<subrname>) IN PROGRAM (<progname>) [<parameters>]
[IF FOUND].
Specifies the subroutine and/or program names at runtime.
PERFORM <idx> OF <form2> ... <formn>.
Calls a subroutine that has index <idx> (literal or variable) from the list.
Passing Data to/from Subroutines.
Declaring Data as Common Part.
DATA: BEGIN OF COMMON PART [<name>].
<data declaration>
END OF COMMON PART [<name>].
<name> is needed if several common parts used. It is better way to use common
parts placed in INCLUDE. Table work areas defined in TABLES are common
automatically.
Parameters.
[TABLES <list of internal tables with or without header line>]
[USING <list of parameters - all data types (including internal tables) and|or
field symbols>]
[CHANGING <list of parameters - all data types (including internal tables)
and|or field symbols>]
Actual parameters can be specified with variable offset and length specifications.
Methods of Passing Data Using Parameters:
By Reference.
FORM ... [USING <fi1> ... <fin>] [CHANGING <fo1> ... <fon>] ...
PERFORM ... [USING <ai1> ... <ain>] [CHANGING <ao1> ... <aon>] ...
In this case USING and CHANGING are equivalent.
By Value.
FORM ... USING ... VALUE(<fii>) ...
PERFORM ... USING ... <aii> ...
New local object <fii> created and processed for each call.
By Value and Result.
FORM ... CHANGING ... VALUE(<fii>) ...
PERFORM ... CHANGING ... <aii> ...
New local object <fii> created and processed for each call. Only when the
subroutine has completed successfully, system pass the current value of <fii> to
<aii>. If the subroutine processing is stopped because of a dialog message, the
actual parameter <aii> remains unchanged.
Typing Formal Parameters:
Type of a formal parameter can be specified in the FORM statement using TYPE
<type> or LIKE <object> after this parameter in the TABLES, USING, or
CHANGING lists. While PERFORM system checks types compatibility of the
actual and formal parameters. The compatibility rules are the same as for Field
Symbols assignment. There are no type conversions. If types are incompatible, the
system outputs an error message during the syntax check for internal subroutine
calls or reacts with a runtime error in the case of external subroutine calls.
Passing Fields Strings:
To pass a field string into subroutine and access components of this field string in
this subroutine - type of the field string must be specified. For internal subroutines
- directly, for external - also in the program where the called subroutine placed
(can be done using Type Groups, Includes or ABAP/4 Dictionary Structures).
Passing Internal Tables:
Can be passed after TABLES (always be Reference), USING or CHANGING.
Type must be specified also for access components separately (as for Field
Strings). If actual parameter table has no header line, but formal parameter table
with header line, the header line will be automatically created in the subroutine
for this table.
Defining Local Data in Subroutines.
Dynamic Local Data Types and Objects.
TYPES, DATA - define automatic objects that newly created for each call and
deleted after exit.
Static Local Data Types and Objects.
STATICS - defines static objects that initialized for first call and keep their values
after exit.
LOCAL <f>.
Preserves the value of a global data object from being changed inside a subroutine
(for example, a work area of a database table defined using TABLES). Instead a
local copy of the <f> used inside of subroutine.
Terminating Subroutines.
See EXIT, CHECK.

Function Modules.
Go to top...
Go to next...

• Function modules are special external subroutines stored in a central library.


• Can be created users own function modules.
• The main difference between a function module and a normal ABAP/4 subroutine
is a clearly defined interface for passing data.
• The calling program and the called function module have separate work areas for
ABAP/4 Dictionary tables.
• Several function modules can be combined to a function group in the program
library with the attribute type F with definition of global data that can be accessed
from all function modules of one function group.

Interfaces:
Import parameter:

Pass data from the calling program to the function module. Cannot be overwritten,
even when passed by reference.
Export parameters:

Pass data from the function module back to the calling program. Always optional.
CHANGING parameter:

Passed by reference or by value and result. Act simultaneously as import and


export parameters. They change the value passed to the function module and
return it to the calling program.
Table parameters:

Internal tables. Treated like changing parameters and are always passed by
reference.
Exception:

Used to handle error scenarios which can occur in function modules.


Proposal - default value for optional parameters.
Reference field|structure, Reference type - used for typing of
formal parameters.

Calling Function Modules:


CALL FUNCTION <module_name>
[EXPORTING <f1> = <a1> ... <fn> = <an>]
[IMPORTING <f1> = <a1> ... <fn> = <an>]
[CHANGING <f1> = <a1> ... <fn> = <an>]
[TABLES <f1> = <a1> ... <fn> = <an>]
[EXCEPTIONS <e1> = <r1> ... <en> = <rn> [ERROR_MESSAGE = <rE>]
[OTHER = <rO>]].
EXPORTING - the formal parameters must be declared as import parameters in
the function module.
IMPORTING - the formal parameters must be declared as export parameters in
the function module.
EXCEPTIONS - <ri> is a numeric literal that is assigned to SY-SUBRC if the
exception is raised. <rE> is used for additional exception ERROR_MESSAGE if
a message of types A, E was issued in the function module without RAISING
option.
OTHERS - used to handle all exceptions that are not specified explicitly in the
list. The same number <ri> can be used for several exceptions.
Programming Function Modules:
FUNCTION <module_name>
....
RAISE <exception>.
....
MESSAGE ... RAISING <exception>.
....
ENDFUNCTION.
If an internal subroutine is needed, the program code of internal subroutines can
be placed directly behind the ENDFUNCTION statement of a module. This
subroutines can be called from all modules of the function group, but for clarity,
should be called only from the function module behind which it is written.
To create internal subroutines that can be called from all modules of one function
group <fgrp>, use special INCLUDE programs L<fgrp>F<xx>. You can open
these INCLUDE programs easily by double clicking their names in the main
program SAPL<fgrp> after selecting Main program on the Function Library-
>Maintain Function Modules screen.

See also:

• Main Page.
• ABAP/4 compendium.
• SAP R/3 system fields.
• ABAP/4 functions.
• ABAP/4 obsolete statements and functions.
• ABAP/4 skeletons.
• ABAP in SAP R/3 ver 4.6 - Object Oriented Language.
• Object Oriented ABAP - Features and Restrictions.
• Object Oriented ABAP - Demos.
• ABAP/4 UNIX browser.
• ABAP Utilities.

• Main Page.

You might also like