‎2007 Jul 03 5:23 AM
‎2007 Jul 03 5:28 AM
ABAP/4 programming language overview
-
This documentation describes the syntax and meaning of ABAP/4
key words (for Release 3.0). The contents are identical to the
online help function.
ADD
Variants:
1. ADD n TO m.
2. ADD n1 THEN n2 UNTIL nz GIVING m.
3. ADD n1 THEN n2 UNTIL nz TO m.
4. ADD n1 THEN n2 UNTIL nz
...ACCORDING TO sel ...GIVING m.
5. ADD n1 FROM m1 TO mz GIVING m.
Variant 1 ADD n TO m.
Effect Adds the contents of n to the contents of M and stores the
result in m.
This is equivalent to: m = m + n.
Example
DATA: NUMBER TYPE I VALUE 3,
SUM TYPE I VALUE 5.
ADD NUMBER TO SUM.
The field SUM now contains 8, whilst the contents of the field
NUMBER remains unchanged at 3.
Note The details about conversions and performance described under
COMPUTE are identical for ADD.
Note Runtime errors:
- BCD_BADDATA: P field contains incorrect BCD format.
- BCD_FIELD_OVERFLOW: Result field too small (type P).
- BCD_OVERFLOW: Overflow with arithmetic operation (type P.
- COMPUTE_INT_PLUS_OVERFLOW: Integer overflow when adding.
Related COMPUTE, ADD-CORRESPONDING.
Variant 2 ADD n1 THEN n2 UNTIL nz GIVING m.
Effect Adds the contents of the fields n1, n2, ..., nz together and
stores the result in m, where n1 is the first, n2 the second
and nz the last of a sequence of fields the same distance
apart. They can be either database fields or internal fields,
but they must all have the same type and length.
This is equivalent to: m = n1 + n2 + ... + nz.
Example
DATA: BEGIN OF NUMBERS,
ONE TYPE P VALUE 10,
TWO TYPE P VALUE 20,
THREE TYPE P VALUE 30,
FOUR TYPE P VALUE 40,
FIVE TYPE P VALUE 50,
SIX TYPE P VALUE 60,
END OF NUMBERS,
SUM TYPE I VALUE 1000.
ADD NUMBERS-ONE THEN NUMBERS-TWO
UNTIL NUMBERS-FIVE GIVING SUM.
The field SUM now contains 150 but its initial value is
unimportant. The fields within the field string NUMBERS remain
unchanged.
Variant 3 ADD n1 THEN n2 UNTIL nz TO m.
Effect Calculates the total as in variant 2 but then adds it to the
contents of the field m.
This is equivalent to: m = m + n1 + n2 + ... + nz
Example
DATA: BEGIN OF NUMBERS,
ONE TYPE P VALUE 10,
TWO TYPE P VALUE 20,
THREE TYPE P VALUE 30,
FOUR TYPE P VALUE 40,
FIVE TYPE P VALUE 50,
END OF NUMBERS,
SUM TYPE I VALUE 1000.
ADD NUMBERS-ONE THEN NUMBERS-TWO
UNTIL NUMBERS-FIVE TO SUM.
The field SUM now contains 1150.
Variant 4 ADD n1 THEN n2 UNTIL nz
...ACCORDING TO sel ...GIVING m.
Parts marked with " ..." are interchangeable
Effect Calculates the total as in variants 2 and 3. In this case,
however, the operands from a sequence of fields of the same
type are restricted to a partial sequence by the selection
specification sel generated by SELECT-OPTIONS or RANGES. The
partial sequence results from the indexes that satisfy the
condition IN sel (see IF).
Example
DATA: BEGIN OF NUMBERS,
ONE TYPE P VALUE 10,
TWO TYPE P VALUE 20,
THREE TYPE P VALUE 30,
FOUR TYPE P VALUE 40,
FIVE TYPE P VALUE 50,
END OF NUMBERS,
SUM TYPE I VALUE 1000,
INDEX TYPE I.
RANGES SELECTION FOR INDEX.
SELECTION-SIGN = 'I'.
SELECTION-OPTION = 'BT'.
SELECTION-LOW = 2.
SELECTION-HIGH = 4.
APPEND SELECTION.
ADD NUMBERS-ONE THEN NUMBERS-TWO
UNTIL NUMBERS-FIVE
ACCORDING TO SELECTION
GIVING SUM.
SUM now contains 90. Only the component fields TWO to FOUR were
selected from the field string NUMBERS and added together.
Variant 5 ADD n1 FROM m1 TO mz GIVING m.
Effect The field n1 must be the first in a sequence of consecutive
fields of the same type. m1 and mz should contain the numbers
of the first and last fields in this sequence to be added
together (whether fixed or variable). The total is stored in m.
Example
DATA: BEGIN OF NUMBERS,
ONE TYPE P VALUE 10,
TWO TYPE P VALUE 20,
THREE TYPE P VALUE 30,
FOUR TYPE P VALUE 40,
FIVE TYPE P VALUE 50,
END OF NUMBERS,
START TYPE I VALUE 2,
SUM TYPE I VALUE 1000.
ADD NUMBERS-ONE FROM START TO 4 GIVING SUM.
The field SUM now contains 90.
Note Performance:
The details for conversion and performance specified for
COMPUTE are equally valid for ADD.
The runtime required for adding two numbers of type I or F is
about 2 msn (standardized microseconds), for type P it is
roughly 8 msn.
Note Runtime errors:
Besides the runtime errors listed in variant 1, the error
ADDF_INT_OVERFLOW can occur instead of
COMPUTE_INT_PLUS_OVERFLOW in other variants.
ADD-CONDITIONAL is not an ABAP/4 key word (in R/3).
ADD-CORRESPONDING
Basic form ADD-CORRESPONDING rec1 TO rec2.
Effect Interprets rec1 and rec2 as field strings. If, for example,
rec1 and rec2 are tables, executes the statement for their
header lines.
Searches for all sub-fields which occur both in rec1 and rec2
and then, for all relevant field pairs corresponding to the
sub-fields ni, generates statements of the form
ADD rec1-ni TO rec2-ni.
The other fields remain unchanged.
With complex structures, the complete names of the
corresponding field
pairs must be textually identical.
Example
DATA: BEGIN OF VECTOR,
X TYPE I,
Y TYPE I,
LENGTH TYPE I,
END OF VECTOR,
BEGIN OF CIRCLE,
VOLUME TYPE P
Y TYPE P,
RADIUS TYPE I,
X TYPE I,
END OF CIRCLE.
...
ADD-CORRESPONDING VECTOR TO CIRCLE.
The sub-fields X and Y occur in both the field strings VECTOR
and CIRCLE. Therefore, the ADD-CORRESPONDING statement is
equivalent to both the following statements:
ADD VECTOR-X TO CIRCLE-X.
ADD VECTOR-Y TO CIRCLE-Y.
Note All fields with the same name are added, whether numeric or
not. The same conversions are performed as with ADD and similar
runtime errors to those possible with ADD can also occur.
Related ADD
MOVE-CORRESPONDING
SUBTRACT-CORRESPONDING
MULTIPLY-CORRESPONDING
DIVIDE-CORRESPONDING
ADD-SELECTIVE is not an ABAP/4 key word (in R/3).
APPEND
Variants:
1. APPEND [wa TO|INITIAL LINE TO] itab.
2. APPEND LINES OF itab1 [FROM idx1] [TO idx2] TO itab2.
3. APPEND [wa TO] itab SORTED BY f.
Variant 1 APPEND [wa TO|INITIAL LINE TO] itab.
Effect Appends a new line to the end of the internal table itab.
If you specify wa TO, the new line is taken from the contents
of the explicitly specified work area wa.
If you use INITIAL LINE TO, a line filled with the correct
value for the type is added.
If the specification before itab is omitted, the new line is
taken from the internal tbale itab.
After the APEND, the system field SY-TABIX contains the index
of the newly added table entry.
Examples Generate a list with customer numbers:
TABLES SCUSTOM.
DATA: CUSTOMER LIKE SCUSTOM-ID OCCURS 0.
APPEND SCUSTOM-ID TO CUSTOMER.
Append a blank line or a line with its initial value to the
above list:
APPEND INITIAL LINE TO CUSTOMER
Generate a compressed list with plane data
PARAMETERS: SEATS_LO LIKE SAPLANE-SEATSMAX DEFAULT 30,
SEATS_HI LIKE SAPLANE-SEATSMAX DEFAULT 50.
DATA: PLANE LIKE SAPLANE OCCURS 0,
PLANE_NEEDED LIKE SAPLANE WITH HEADER LINE.
LOOP AT PLANE INTO PLANE_NEEDED
WHERE SEATSMAX BETWEEN SEATS_LO AND SEATS_HI.
APPEND PLANE_NEEDED.
ENDLOOP.
Notes Performance:
1. When using internal tables with a header line, avoid
unnecessary assignments to the header line. Whenever
possible, use statements which have an explicit work area.
For example, "APPEND wa TO itab." is approximately twice as
fast as "itab = wa. APPEND itab.". The same applies to
COLLECT and INSERT.
2. In contrast to COLLECT, APPEND does not check whether an
entry with the same default key exists. Therefore, it is
considerably faster than COLLECT. If the COLLECT logic is
not needed or lines with an identical default key cannot
occur in a particular situation, you should always use
APPEND instead of COLLECT.
3. The runtime required for APPEND increases with the line
width of the table and depends on the number of fields.
Appending an entry to an internal table with a width of 111
bytes takes about 9 msn (standardized microseconds).
4. To append an internal table to another internal table, you
should use the variant APPEND LINES OF ... which is 3 to 4
times faster than using a LOOP to process the source table
and append the entries line-by-line to the target table.
Variant 2 APPEND LINES OF itab1 [FROM idx1] [TO idx2] TO itab2.
Effect Appends the internal table itab1 or an extract from itab1 to
the end of the internal table itab2.
By specifying FROM idx1 or TO idx2 you can restrict the line
area taken from the source table itab1. If there is no FROM
specification, it begins with the first line of itab1. If there
is no TO specification, it ends with the last line of itab1.
This means that the complete table is appended if neither a
FROM nor a TO is specified.
After the APPEND, the system field SY-TABIX contains the index
of the last table entry appended, i.e. the total number of
entries from both tables.
Note By comparing the values of SY-TABIX before and after the APPEND
statement, you can determine how many lines were appended to
the table.
Example Merge two tables with whole numbers:
DATA: ITAB1 TYPE I OCCURS 100,
ITAB2 TYPE I OCCURS 100.
APPEND 2 TO ITAB1.
APPEND 3 TO ITAB1.
APPEND 5 TO ITAB1.
APPEND 7 TO ITAB1.
APPEND 3 TO ITAB2.
APPEND INITIAL LINE TO ITAB2.
APPEND LINES OF ITAB1 FROM 2 TO 20 TO ITAB2.
The table ITAB2 now contains five lines with the values 3, 0,
3, 5 and 7.
Note Performance:
This variant is 3 to 4 times faster than using a LOOP to
process the source table and append the entries line-by-line to
the target table.
Variant 3 APPEND [wa TO] itab SORTED BY f.
Effect Inserts the new entry into table and re-sorts the table by the
sub-field f in descending order. This only makes sense if the
table was sorted beforehand. When the number of table entries
reaches the OCCURS parameter value, the last entry is deleted
if the value f of a new entry is greater (particularly suitable
for ranked lists). You can only sort by one sub-field.
If you specify wa TO, the new line is taken from the contents
of the explicitly specified work area wa. Otherwise, it comes
from the header line of the internal table itab.
Example
DATA: BEGIN OF COMPANIES OCCURS 3,
NAME(10), SALES TYPE I,
END OF COMPANIES.
COMPANIES-NAME = 'big'.
COMPANIES-SALES = 90.
APPEND COMPANIES.
COMPANIES-NAME = 'small'.
COMPANIES-SALES = 10.
APPEND COMPANIES.
COMPANIES-NAME = 'too small'.
COMPANIES-SALES = 5.
APPEND COMPANIES.
COMPANIES-NAME = 'middle'.
COMPANIES-SALES = 50.
APPEND COMPANIES SORTED BY SALES.
The table now has three (-> OCCURS 3) entries. The line with
the contents 'too small' in the sub-field NAME is deleted from
the table because the entry for 'middle' has a greater value in
the sub-field SALES. This entry now appears in the second table
line (after 'big' and before 'small').
Notes 1. Whenever an internal table is processed with APPEND SORTED
BY, it should always be filled in this way.
2. If you specify APPEND with the parameter SORTED BY, the
system always searches the entire table. Therefore, it is
sometimes better to create the table with a simple APPEND
and then use SORT to sort in descending ot ascending order
afterwards.
You can also sort in ascending order by first determining
the insert position with READ TABLE itab WITH KEY f = itab-f
BINARY SEARCH and then by inserting the new entry into the
table (perhaps read SY-SUBRC beforehand) with INSERT itab
INDEX SY-TABIX.
However, you should be aware that, in such cases, the table
may contain more entries than specified in the OCCURS
parameter.
3. If several lines with an identical value f are added, lines
added later are treated as smaller, i.e. they are inserted
after existing lines with the same value f.
4. If you use APPEND ... SORTED BY f with an explicitly
specified work area, this must be compatible with the line
type of the internal table.
5. If the sort criterion f is not known until runtime, you can
use SORTED BY (name) to specify it dynamically as the
contents of the field name. If name is blank at runtime or
contains an invalid component name, a runtime error occurs.
6. Regardless of whether you specify it statically or
dynamically, you can restrict the sort criterion f further
by defining an offset and/or length.
Related COLLECT itab, INSERT itab, SELECT / FETCH NEXT CURSOR ...
INTO/APPENDING TABLE itab, MODIFY itab, WRITE f TO itab INDEX
idx, SORT itab, READ TABLE itab, LOOP AT itab, DELETE itab
ASS-RPERF is not an ABAP/4 key word (in R/3).
ASSIGN
Variants:
1. ASSIGN f TO <fs>.
2. ASSIGN (f) TO <fs>.
3. ASSIGN TABLE FIELD (f) TO <fs>.
4. ASSIGN LOCAL COPY OF MAIN TABLE FIELD (f) TO <fs>.
5. ASSIGN COMPONENT idx OF STRUCTURE rec TO <fs>.
6. ASSIGN COMPONENT name OF STRUCTURE rec TO <fs>.
Variant 1 ASSIGN f TO <fs>.
Additions:
1. ... TYPE typ
2. ... DECIMALS dec
3. ... LOCAL COPY OF ...
Effect Assigns the field f to the field symbol <fs>. The field symbol
<fs> "points to" the contents of the field f at runtime, i.e.
every change to the contents of f is reflected in <fs> and vice
versa. If the field symbol <fs> is not typed (see
FIELD-SYMBOLS), the field symbol adopts the type and atrributes
of the field f at runtime, particularly the conversion exit.
Otherwise, when the assignment is made, the system checks
whether the type of the field f matches the type of the field
symbol <fs>.
Note With the ASSIGN statement, the offset and length specifications
in field f (i.e. foff, flen or f+off(len)) have a special
meaning:
- They may be variable and thus not evaluated until runtime.
- The system does not check whether the selected area still
lies within the field f.
- If an offset is specified, but no length, for the field f,
the field symbol <fs> adopts the length of the field f.
Caution: <fs> also points to an area behind the field f. If
you do not want this, the offset and length specifications
can be in the form ASSIGN f+off(*) TO <fs>.. This means that
the field symbol <fs> is set so that the field limits of f
are not exceeded.
- In the ASSIGN statement, you can also use offset and length
specifications to access field symbols, FORM and function
parameters.
- Warning: If the effect of the ASSIGN statement is to assign
parts of other fields beyond the limits of the field f, the
changing of the contents via the field symbol <fs> may mean
that the data written to these fields does not match the
data type of these fields and thus later results in a
runtime error.
Note Since the ASSIGN statement does not set any return code value
in the system field SY-SUBRC, subsequent program code should
not read this field.
Example
DATA NAME(4) VALUE 'JOHN'.
FIELD-SYMBOLS <F>.
ASSIGN NAME TO <F>.
WRITE <F>.
Output: JOHN
Example
DATA: NAME(12) VALUE 'JACKJOHNCARL',
X(10) VALUE 'XXXXXXXXXX'.
FIELD-SYMBOLS .
ASSIGN NAME+4 TO .
WRITE .
ASSIGN NAME+4(*) TO .
WRITE .
Output: JOHNCARLXXXX JOHNCARL
Example
DATA: NAME(12) VALUE 'JACKJOHNCARL',
X(10) VALUE 'XXXXXXXXXX'.
FIELD-SYMBOLS <F>.
ASSIGN NAME+4 TO <F>.
WRITE <F>.
ASSIGN NAME+4(*) TO <F>.
WRITE <F>.
Output: JOHNCARLXXXX JOHNCARL
Addition 1 ... TYPE typ
Effect With untyped field symbols, allows you to change the current
type of the field symbol to the type typ. The output length of
the field symbol is corrected according to its type.
With typed field symbols, this addition should only be used if
the type of the field f does not match the type of the field
symbol <fs>. The specified type type must be compatible with
the type of the field symbol. Since no conversion can be
performed (as with MOVE, the system must be able to interpret f
as a field with this type type.
The type specification is in the form of a literal or a field.
At present, only system types (C, D, T, P, X, N, F, I or W) are
allowed; you can also specify type 's' for 2-byte integer
fields with a sign and type 'b' for 1-byte integer fields
without a sign (see also DESCRIBE FIELD).
Note This statement results in a runtime error if the specified type
is unknown or does not match the field to be assigned (due to a
missing alignment or an inappropriate length).
Example
DATA LETTER TYPE C.
FIELD-SYMBOLS <F>.
ASSIGN LETTER TO <F>.
The field symbol has the type C and the output length 1.
ASSIGN LETTER TO <F> TYPE 'X'.
The field symbol has the type X and the output length 2.
Addition 2 ... DECIMALS dec
Effect This addition only makes sense when used with type P. The field
symbol contains dec decimal places.
Example Output sales in thousands:
DATA SALES_DEC2(10) TYPE P DECIMALS 2 VALUE 1234567.
FIELD-SYMBOLS <SALES_DEC5>.
ASSIGN SALES_DEC2 TO <SALES_DEC5> DECIMALS 5.
WRITE: / SALES_DEC2,
/ <SALES_DEC5>.
Output:
1,234,567.00
1,234.56700
Note This statement results in a runtime error if the field symbol
has a type other than P at runtime or the specified number of
decimal places is not in the range 0 to 14.
Addition 3 ... LOCAL COPY OF ...
Effect With LOCAL COPY OF, the ASSIGN</ > statement can only be used
in subroutines. This creates a copy of f which points to the
field symbol.
Note The field symbol <fs> must also be defined locally in the
subroutine.
Example
DATA X(4) VALUE 'Carl'.
PERFORM U.
FORM U.
FIELD-SYMBOLS <F>.
ASSIGN LOCAL COPY OF X TO <F>.
WRITE <F>.
MOVE 'John' TO <F>.
WRITE <F>.
WRITE X.
ENDFORM.
Output: Carl John Carl
Variant 2 ASSIGN (f) TO <fs>.
Additions:
1. ... TYPE typ
2. ... DECIMALS dec
3. ... LOCAL COPY OF ...
Effect Assigns the field whose name is stored in the field f to the
field symbol.
The statement "ASSIGN (f)+off(len) TO <fs>" is not allowed.
Notes - The search for the field to be assigned is performed as
follows:
1. If the statement is in a subroutine or function module, the
system first searches in this modularization unit.
2. If the statement lies outside any such modularization units
or if the field is not found there, the system searches for
the field in the global data of the program.
3. If the field is not found there, the system searches in the
table work areas of the main program of the current program
group declared with TABLES
- The name of the field to be assigned can also be the name of
a field symbol or formal parameter (or even a component of
one of these, if the field symbol or the parameter has a
structure).
- If the name of the field to be assigned is of the form
"(program name)field name", the system searches in the
global fields of the program with the name "Program name"
for the field with the name "Field name". However,it is only
found if the program has already been loaded.
Warning: This option is for internal use by specialists
only. Incompatible changes or developments may occur at any
time without warning or prior notice.
The return code value is set as follows:
SY-SUBRC = 0: The assignment was successful.
SY-SUBRC = 4: The field could not be assigned to the field
symbol.
Example
DATA: NAME(4) VALUE 'XYZ', XYZ VALUE '5'.
FIELD-SYMBOLS <F>.
ASSIGN (NAME) TO <F>.
WRITE <F>.
Output: 5
Addition 1 ... TYPE typ
Addition 2 ... DECIMALS dec
Addition 3 ... LOCAL COPY OF ...
Effect See similar additions of variant 1.
Variant 3 ASSIGN TABLE FIELD (f) TO <fs>.
Effect Identical to variant 2, except that the system searches for the
field f only in the data in the current program group declared
with TABLES.
The return code value is set as follows:
SY-SUBRC = 0: The assignment was successful.
SY-SUBRC = 4: The field could not be assigned to the field
symbol.
Example
TABLES TRDIR.
DATA NAME(10) VALUE 'TRDIR-NAME'.
FIELD-SYMBOLS <F>.
MOVE 'XYZ_PROG' TO TRDIR-NAME.
ASSIGN TABLE FIELD (NAME) TO <F>.
WRITE <F>.
Output: XYZ_PROG
Example
TABLES T100.
T100-TEXT = 'Global'.
PERFORM EXAMPLE.
FORM EXAMPLE.
DATA: BEGIN OF T100, TEXT(20) VALUE 'LOCAL', END OF T100,
NAME(30) VALUE 'T100-TEXT'.
FIELD-SYMBOLS <F>.
ASSIGN (NAME) TO <F>.
WRITE <F>.
ENDFORM.
Output: Local - although the global table field T100-TEXT has
"global" contents. (This kind of name assignment of work fields
is, of course, not recommended.)
Example
TABLES TRDIR.
DATA: F(8) VALUE 'F_global',
G(8) VALUE 'G_global'.
MOVE 'XYZ_PROG' TO TRDIR-NAME.
PERFORM U.
FORM U.
DATA: F(8) VALUE 'F_local',
NAME(30) VALUE 'F'.
FIELD-SYMBOLS <F>.
ASSIGN (NAME) TO <F>.
WRITE <F>.
MOVE 'G' TO NAME.
ASSIGN (NAME) TO <F>.
WRITE <F>.
MOVE 'TRDIR-NAME' TO NAME.
ASSIGN (NAME) TO <F>.
WRITE <F>.
ENDFORM.
Output: F_local G_global XYZ_PROG
Example
PROGRAM P1MAIN.
TABLES TRDIR.
DATA NAME(30) VALUE 'TFDIR-PNAME'.
FIELD-SYMBOLS <F>.
MOVE 'XYZ_PROG' TO TRDIR-NAME.
PERFORM U(P1SUB).
ASSIGN (NAME) TO <F>.
WRITE <F>.
CALL FUNCTION 'EXAMPLE'.
PROGRAM P1SUB.
TABLES TFDIR.
...
FORM U.
FIELD-SYMBOLS <F>.
DATA NAME(30) VALUE 'TRDIR-NAME'.
ASSIGN TABLE FIELD (NAME) TO <F>.
WRITE <F>.
MOVE 'FCT_PROG' TO TFDIR-PNAME.
ENDFORM.
FUNCTION-POOL FUN1.
FUNCTION EXAMPLE.
DATA NAME(30) VALUE 'TRDIR-NAME'.
FIELD-SYMBOLS <F>.
ASSIGN (NAME) TO <F>.
IF SY-SUBRC = 0.
WRITE <F>.
ELSE.
WRITE / 'TRDIR-NAME cannot be accessed'.
ENDIF.
ENDFUNCTION.
Output: XYZ_PROG FCT_PROG
TRDIR-NAME cannot be accessed
Example
TABLES TRDIR.
MOVE 'XYZ_PROG' to TRDIR-NAME.
PERFORM U USING TRDIR.
FORM U USING X STRUCTURE TRDIR.
FIELD-SYMBOLS <F>.
DATA NAME(30) VALUE 'X-NAME'.
ASSIGN (NAME) TO <F>.
WRITE <F>.
ENDFORM.
Output: XYZ_PROG
Variant 4 ASSIGN LOCAL COPY OF MAIN TABLE FIELD (f) TO <f>.
Additions:
1. ... TYPE typ
2. ... DECIMALS dec
Note This statement is for internal use only.
Incompatible changes or further developments may occur at any
time without warning or notice.
Effect Identical to variant 3, except that the system searches for the
field whose name is in f steht only in the data in the program
group of the main program declared with TABLES. However, the
field symbol then points not directly to the found field, but
to a copy of this field on theq value stack.
This variant therefore ensures that any access to Dictionary
fields of an external program group is read only and no changes
are made.
Example
PROGRAM P1MAIN.
TABLES TRDIR.
DATA NAME(30) VALUE 'TFDIR-PNAME'.
FIELD-SYMBOLS <F>.
MOVE 'XYZ_PROG' TO TRDIR-NAME.
CALL FUNCTION 'EXAMPLE'.
FUNCTION-POOL FUN1.
FUNCTION EXAMPLE.
DATA NAME(30) VALUE 'TRDIR-NAME'.
FIELD-SYMBOLS <F>.
ASSIGN LOCAL COPY OF MAIN
TABLE FIELD (NAME) TO <F>.
IF SY-SUBRC = 0.
WRITE <F>.
ELSE.
WRITE / 'TRDIR-NAME cannot be accessed'.
ENDIF.
ENDFUNCTION.
Output: XYZ_PROG
Addition 1 ... TYPE typ
Addition 2 ... DECIMALS dec
Effect See similar additions to variant 1.
Variant 5 ASSIGN COMPONENT idx OF STRUCTURE rec TO <fs>.
Variant 6 ASSIGN COMPONENT name OF STRUCTURE rec TO <fs>.
Additions:
1. ... TYPE typ
2. ... DECIMALS dec
Effect If the field name or idx has the type C or if it is a field
string with no internal table, it is treated as a component
name. Otherwise, it is considered as a component number. The
corresponding component of the field string rec is assigned to
the field symbol <fs>.
The return code value is set as follows:
SY-SUBRC = 0: The assignment was successful.
SY-SUBRC = 4: The field could not be assigned to the field
symbol.
Note If idx has the value 0, the entire field string is assigned to
the field symbol.
Example
PROGRAM P1MAIN.
DATA: BEGIN OF REC,
A VALUE 'a',
B VALUE 'b',
C VALUE 'c',
D VALUE 'd',
END OF REC,
CN(5) VALUE 'D'.
FIELD-SYMBOLS <FS>.
DO 3 TIMES.
ASSIGN COMPONENT SY-INDEX OF
STRUCTURE REC TO <FS>.
IF SY-SUBRC <> 0. EXIT. ENDIF.
WRITE <FS>.
ENDDO.
ASSIGN COMPONENT CN OF STRUCTURE REC TO <FS>.
WRITE <FS>.
Output: a b c d
Addition 1 ... TYPE typ
Addition 2 ... DECIMALS dec
Effect See similar additions to variant 1.
Note Runtime errors:
Depending on the operands, the ASSIGN statement can cause
runtime errors.
Note Performance:
For performance reasons, you are recommended to use typed field
symbols. The runtime for a typed ASSIGN statement amounts to
approx. 9 msn (standardized microseconds) against
approx. 13 msn for an untyped ASSIGN statement.
AT
Events in lists
- AT LINE-SELECTION.
- AT USER-COMMAND.
- AT PFn.
Events on selection screens
- AT SELECTION-SCREEN.
Control break with extracts
- AT NEW f.
- AT END OF f.
- AT FIRST.
- AT LAST.
- AT fg.
Control break with internal tables
- AT NEW f.
- AT END OF f.
- AT FIRST.
- AT LAST.
AT - control break
Variants:
1. AT NEW f.
2. AT END OF f.
3. AT FIRST.
4. AT LAST.
Variant 1 AT NEW f.
Variant 2 AT END OF f.
Effect f is a sub-field of an internal table or extract dataset
(EXTRACT) which is being processed with LOOP, i.e. the variants
1 and 2 only make sense within a LOOP.
Both "AT NEW f." and "AT END OF f." introduce processing blocks
which are concluded by "ENDAT.".
These processing blocks are processed whenever the contents of
a field f or a sub-field defined before f change as a result of
processing with LOOP. "AT NEW f." begins a new group of (table)
lines with the same contents as the field f while "AT END OF
f." concludes such a group.
Within the AT ... ENDAT processing of internal tables, all
argument fields following f are filled with "*".
Examples 1. AT for sub-fields of an internal table
DATA: BEGIN OF COMPANIES OCCURS 20,
NAME(30),
PRODUCT(20),
SALES TYPE I,
END OF COMPANIES.
...
LOOP AT COMPANIES.
AT NEW NAME.
NEW-PAGE.
WRITE / COMPANIES-NAME.
ENDAT.
WRITE: / COMPANIES-PRODUCT, COMPANIES-SALES.
AT END OF NAME.
SUM.
WRITE: / COMPANIES-NAME, COMPANIES-SALES.
ENDAT.
ENDLOOP.
The AT statements refer to the field COMPANIES-NAME.
Examples 2. AT for the field of an extract dataset
DATA: NAME(30),
SALES TYPE I.
FIELD-GROUPS: HEADER, INFOS.
INSERT: NAME INTO HEADER,
SALES INTO INFOS.
...
LOOP.
AT NEW NAME.
NEW-PAGE.
ENDAT.
...
AT END OF NAME.
WRITE: / NAME, SUM(SALES).
ENDAT.
ENDLOOP.
Notes 1. If the processing you want to perform on an internal table
is fairly restricted (i.e. a WHERE addition with the LOOP
statement), do not use the AT statements specified in
variants 1 to 5, since the interaction of the WHERE addition
and the AT statement is currently not defined.
2. When you use LOOP with an extract dataset, fields on hex
zero are ignored during control level checking with AT NEW
or AT END OF. This procedure is the same as the SORT
statement. When sorting extracted datasets, this statement
always sorts blank fields (i.e. fields on hex zero)
regardless of the sequence (ascending or descending) before
all fields that contain values.
3. Since fields addressed with AT are not set to an initial
value when you enter a LOOP, the first new group of (table)
lines in AT NEW f may not be processed, if f happens to be
set to this value.
Variant 3 AT FIRST.
Variant 4 AT LAST.
Effect The variants 3 and 4 only make sense within a LOOP.
The processing block between AT FIRST and ENDAT is executed
before the individual lines are processed; the processing block
between AT LAST and ENDAT is executed after all the individual
lines have been processed.
In AT FIRST or AT LAST ... ENDAT processing, all argument
fields are filled with "*" (internal tables).
When you are processing extract datasets, a control total
SUM(n) can only be processed with AT END OF or AT LAST.
Example
DATA: BEGIN OF COMPANIES OCCURS 20,
NAME(30),
PRODUCT(20),
SALES TYPE I,
END OF COMPANIES.
...
LOOP AT COMPANIES.
AT FIRST.
SUM.
WRITE: 'Sum of all SALES:',
55 COMPANIES-SALES.
ENDAT.
WRITE: / COMPANIES-NAME, COMPANIES-PRODUCT,
55 COMPANIES-SALES.
ENDLOOP.
AT - Control break with extracts
Variants:
1. AT NEW f.
2. AT END OF f.
3. AT FIRST.
4. AT LAST.
5. AT fg.
Effect In a LOOP which processes a dataset created with EXTRACT, you
can use special control structures for control break
processing. All these structures begin with AT and end with
ENDAT. The sequence of statements which lies between them is
then executed if a control break occurs.
You can use these key words for control break processing with
extract datasets only if the active LOOP statement is
proceesing an extract dataset.
The control level structure with extract datasets is dynamic.
It corresponds exactly to the sort key of the extract dataset,
i.e. to the order of fields in the field group HEADER by which
the extract dataset was sorted.
At the end of a control group (AT END OF, AT LAST), there are
two types of control level information between AT and ENDAT:
- If the sort key of the extract dataset contains a
non-numeric field h (particularly in the field group
HEADER), the field CNT(h) contains the number of control
breaks in the (subordinate) control level h.
- For extracted number fields g (see also ABAP/4 number
types), the fields SUM(g) contain the relevant control
totals.
Notes 1. The fields CNT(h) and SUM(g) can only be addressed after
they have been sorted. Otherwise, a runtime error may occur.
2. The fields CNT(h) and SUM(g) are filled with the relevant
values for a control level at the end of each control group
(AT END OF, AT LAST), not at the beginning (AT FIRST, AT
NEW).
3. When calculating totals with SUM(g), the system
automatically chooses the maximum field sizes so that an
overflow occurs only if the absolute value area limits are
exceeded.
4. You can also use special control break control structures
with LOOPs on internal tables.
Variant 1 AT NEW f.
Variant 2 AT END OF f.
Effect f is a field from the field group HEADER. The enclosed sequence
of statements is executed if
- the field f occurs in the sort key of the extract dataset
(and thus also in the field group HEADER) and
- the field f or a superior sort criterion has a different
value in the current LOOP line than in the prceding (AT NEW)
or subsequent (AT END OF) record of the extract dataset.
Example
DATA: NAME(30),
SALES TYPE I.
FIELD-GROUPS: HEADER, INFOS.
INSERT: NAME INTO HEADER,
SALES INTO INFOS.
...
LOOP.
AT NEW NAME.
NEW-PAGE.
ENDAT.
...
AT END OF NAME.
WRITE: / NAME, SUM(SALES).
ENDAT.
ENDLOOP.
Notes 1. If the extract dataset is not sorted before processing with
LOOP, no control level structure is defined and the
statements following AT NEW or AT END OF are not executed.
2. Fields which stand at hex zero are ignored by the control
break check with AT NEW or AT END OF. This corresponds to
the behavior of the SORT statement, which always places
unoccupied fields (i.e. fields which stand at hex zero)
before all occupied fields when sorting extract datasets,
regardless of whether the sort sequence is in ascending or
descending order.
Variant 3 AT FIRST.
Variant 4 AT LAST.
Effect Executes the relevant series of statements just once - either
on the first loop pass (with AT FIRST) or on the last loop pass
(with AT LAST).
Variant 5 AT fg.
Addition:
... WITH fg1
Effect This statement makes single record processing dependent on the
type of extracted record.
The sequence of statements following AT fg are executed
whenever the current LOOP record is created with EXTRACT fg (in
other words: when the current record is a fg record).
Addition ... WITH fg1
Effect Executes the sequence of statements belonging to AT fg WITH fg1
only if the record of the field group fg in the dataset is
immediately followed by a record of the field group fg1.
AT - field group definition
Basic form AT fg.
Addition:
... WITH fg1
Effect When you are processing an extract dataset (EXTRACT) in a LOOP,
this statement makes single record processing dependent on the
type of extracted record.
The processing block specified within AT fg ... ENDAT is
executed if the record just read was generated with EXTRACT fg
(i.e. if the record just read is an fg record).
Addition ... WITH fg1
Effect The processing block under AT fg WITH fg1. is executed only if
the record from the field group fg in the dataset is
immediately followed by a record from the field group fg1.
AT - Control break with internal tables
Variants:
1. AT NEW f.
2. AT END OF f.
3. AT FIRST.
4. AT LAST.
Effect In a LOOP which processes a dataset created with EXTRACT, you
can use special control structures for control break
processing. All these structures begin with AT and end with
ENDAT. The sequence of statements which lies between them is
then executed if a control break occurs.
You can use these key words for control break processing with
extract datasets only if the active LOOP statement is
proceesing an extract dataset.
The control level structure with extract datasets is dynamic.
It corresponds exactly to the sort key of the extract dataset,
i.e. to the order of fields in the field group HEADER by which
the extract dataset was sorted.
At the start of a new control level (i.e. immediately after
AT), the following occurs in the output area of the current
LOOP statement:
- All default key fields (on the right) are filled with "*"
after the current control level key.
- All other fields (on the right) are set to their initial
values after the current control level key.
Between AT and ENDAT, you can use SUM to insert the appropriate
control totals in the number fields (see also ABAP/4 number
types) of the LOOP output area (on the right) after the current
control level key. Summing is supported both at the beginning
of a control level (AT FIRST, AT NEW f) and also the end of a
control level (AT END OF f, AT LAST).
At the end of the control level processing (i.e. after ENDAT),
the old contents of the LOOP output area are restored.
Notes 1. When calculating totals, you must ensure that the totals are
inserted into the same sub-fields of the LOOP output area as
those where the single values otherwise occur. If there is
an overflow, processing terminates with a runtime error.
2. If an internal table is processed only in a restricted form
(using the additions FROM, TO and/or WHERE with the LOOP
statement), you should not use the control structures for
control level processing because the interaction of a
restricted LOOP with the AT statement is currenly not
properly defined.
3. With LOOPs on extracts, there are also special control break
control structures you can use.
Note Runtime errors:
- SUM_OVERFLOW: Overflow when calculating totals with SUM.
Variant 1 AT NEW f.
Variant 2 AT END OF f.
Effect f is a sub-field of an internal table processed with LOOP. The
sequence of statements which follow it is executed if the
sub-field f or a sub-field in the current LOOP line defined (on
the left) before f has a differnt value than in the preceding
(AT NEW) or subsequent (AT END OF) table line.
Example
DATA: BEGIN OF COMPANIES OCCURS 20,
NAME(30),
PRODUCT(20),
SALES TYPE I,
END OF COMPANIES.
...
LOOP AT COMPANIES.
AT NEW NAME.
NEW-PAGE.
WRITE / COMPANIES-NAME.
ENDAT.
WRITE: / COMPANIES-PRODUCT, COMPANIES-SALES.
AT END OF NAME.
SUM.
WRITE: / COMPANIES-NAME, COMPANIES-SALES.
ENDAT.
ENDLOOP.
The AT statements refer to the field COMPANIES-NAME.
Notes 1. If a control break criterion is not known until runtime, you
can use AT NEW (name) or AT END OF (name) to specify it
dynamically as the contents of the field name. If name is
blank at runtime, the control break criterion is ignored and
the sequence of statements is not executed. If name contains
an invalid component name, a runtime error occurs.
2. By defining an offset and/or length, you can further
restrict control break criteria - regardless of whether they
are specified statically or dynamically.
3. A field symbol pointing to the LOOP output area can also be
used as a dynamic control break criterion. If the field
symbol does not point to the LOOP output area, a runtime
error occurs.
Note Runtime errors:
- AT_BAD_PARTIAL_FIELD_ACCESS: Invalid sub-field access when
dynamically specifying the control break criterion.
- AT_ITAB_FIELD_INVALID: When dynamically specifying the
control break criterion via a field symbol, the field symbol
does not point to the LOOP output area.
- ITAB_ILLEGAL_COMPONENT: When dynamically specifying the
control break criterion via (name) the field name does not
contain a valid sub-field name.
Variant 3 AT FIRST.
Variant 4 AT LAST.
Effect Executes the appropriate sequence of statements once during the
first (AT FIRST) or last (AT LAST) loop pass.
Example
DATA: BEGIN OF COMPANIES OCCURS 20,
NAME(30),
PRODUCT(20),
SALES TYPE I,
END OF COMPANIES.
...
LOOP AT COMPANIES.
AT FIRST.
SUM.
WRITE: 'Sum of all SALES:',
55 COMPANIES-SALES.
ENDAT.
WRITE: / COMPANIES-NAME, COMPANIES-PRODUCT,
55 COMPANIES-SALES.
ENDLOOP.
AT - Events in lists
Variants:
1. AT LINE-SELECTION.
2. AT USER-COMMAND.
3. AT PFn.
Variant 1 AT LINE-SELECTION.
Effect Event in interactive reporting
This event is processed whenever the user chooses a valid line
in the list (i.e. a line generated by statements such as WRITE,
ULINE or SKIP) with the cursor and presses the function key
which has the function PICK in the interface definition. This
should normally be the function key F2, because it has the same
effect as double-clicking the mouse, or single-clicking in the
case of a hotspot.
The processing for the event AT LINE-SELECTION usually
generates further list output (the details list) which
completely covers the current list display. If the latter is
still visible (to aid user orientation), this may be due to the
key word WINDOW.
In most cases, the information is from the selected line is
used to retrieve more comprehensive information by direct
reading. When displaying the original list, you store the key
terms needed for this in the HIDE area of the output line.
Note You can choose a line and start new processing even in the
details lists.
The following system fields are useful for orientation
purposes, since their values change with each interactive event
executed.
SY-LSIND Index of list created by current event (basic
list = 0, 1st details list = 1, ...)
SY-PFKEY Status of displayed list (SET PF-STATUS)
SY-LISEL Contents of selected line
SY-LILLI Absolute number of this line in the displayed
list
SY-LISTI Index of this list - usually SY-LSIND - 1 (READ
LINE)
SY-CUROW Last cursor position: Line in window
SY-CUCOL Last cursor position: Column in window (GET
CURSOR)
SY-CPAGE 1st displayed page of displayed list
SY-STARO 1st displayed line of this page of displayed
list
SY-STACO 1st displayed column of displayed list (SCROLL
LIST)
The system field SY-LSIND defines the line selection level
(basic list: SY-LSIND = 0).
Example
DATA TEXT(20).
START-OF-SELECTION.
PERFORM WRITE_AND_HIDE USING SPACE SPACE.
AT LINE-SELECTION.
CASE TEXT.
WHEN 'List index'.
PERFORM WRITE_AND_HIDE USING 'X' SPACE.
WHEN 'User command'.
PERFORM WRITE_AND_HIDE USING SPACE 'X'.
WHEN OTHERS.
SUBTRACT 2 FROM SY-LSIND.
PERFORM WRITE_AND_HIDE USING SPACE SPACE.
ENDCASE.
CLEAR TEXT.
FORM WRITE_AND_HIDE USING P_FLAG_LSIND P_FLAG_UCOMM.
WRITE / 'SY-LSIND:'.
PERFORM WRITE_WITH_COLOR USING SY-LSIND P_FLAG_LSIND.
TEXT = 'List index'.
HIDE TEXT.
WRITE / 'SY-UCOMM:'.
PERFORM WRITE_WITH_COLOR USING SY-UCOMM P_FLAG_UCOMM.
TEXT = 'User command'.
HIDE TEXT.
IF SY-LSIND > 0.
WRITE / 'PICK here to go back one list level'.
ENDIF.
ENDFORM.
FORM WRITE_WITH_COLOR USING P_VALUE
P_FLAG_POSITIVE.
IF P_FLAG_POSITIVE = SPACE.
WRITE P_VALUE COLOR COL_NORMAL.
ELSE.
WRITE P_VALUE COLOR COL_POSITIVE.
ENDIF.
ENDFORM.
Depending on whether you choose the line at SY-LSIND or
SY-UCOMM, the next details list contains the corresponding
value with the color "positive". If the line is chosen without
HIDE information, the list level is reduced.
Variant 2 AT USER-COMMAND.
Effect Event in interactive reporting
This event is executed whenever the user presses a function key
in the list or makes an entry in the command field.
Some functions are executed directly by the system and thus
cannot be processed by programs. These include:
PICK See variant AT LINE-SELECTION
PFn See variant AT PFn
/... System command
%... System command
PRI Print
BACK Back
RW Cancel
P... Scroll function (e.g.: P, P-, PP3, PS-- etc.)
Instead of this functions, you can use the
SCROLL statement in programs.
Since many of these system functions begin with "P", you should
avoid using this letter to start your own function codes.
Otherwise, the effect is as for AT LINE-SELECTION; also, the
current function code is stored in the system field SY-UCOMM.
Example
DATA: NUMBER1 TYPE I VALUE 20,
NUMBER2 TYPE I VALUE 5,
RESULT TYPE I.
START-OF-SELECTION.
WRITE: / NUMBER1, '?', NUMBER2.
AT USER-COMMAND.
CASE SY-UCOMM.
WHEN 'ADD'.
RESULT = NUMBER1 + NUMBER2.
WHEN 'SUBT'.
RESULT = NUMBER1 - NUMBER2.
WHEN 'MULT'.
RESULT = NUMBER1 * NUMBER2.
WHEN 'DIVI'.
RESULT = NUMBER1 / NUMBER2.
WHEN OTHERS.
WRITE 'Unknown function code'.
EXIT.
ENDCASE.
WRITE: / 'Result:', RESULT.
After entry of a function code, the appropriate processing is
performed under the event AT USER-COMMAND and the result is
displayed in the details list.
Variant 3 AT PFn.
Effect Event in interactive reporting
Here, n stands for a numeric value between 0 and 99.
This event is executed whenever the user presses a function key
that contains the function code PFn in the interface
definition. The default status for lists contains some of these
functions.
Otherwise, the effect is as for the variant AT LINE-SELECTION.
The cursor can be on any line.
Notes 1. To ensure that the chosen function is executed only for
valid lines, you can check the current HIDE information.
2. This variant should be used only for test or prototyping
purposes, since the default status is not normally used.
Instead, you should set a program-specific status with SET
PF-STATUS. This should not contain any function codes
beginning with "PF".
Example
DATA NUMBER LIKE SY-INDEX.
START-OF-SELECTION.
DO 9 TIMES.
WRITE: / 'Row', (2) SY-INDEX.
NUMBER = SY-INDEX.
HIDE NUMBER.
ENDDO.
AT PF8.
CHECK NOT NUMBER IS INITIAL.
WRITE: / 'Cursor was in row', (2) NUMBER.
CLEAR NUMBER.
AT - Events on selection screens
Basic form AT SELECTION-SCREEN.
Additions:
1. ... ON psel
2. ... ON END OF sel
3. ... ON VALUE-REQUEST FOR psel_low_high.
4. ... ON HELP-REQUEST FOR psel_low_high
5. ... ON RADIOBUTTON GROUP radi
6. ... ON BLOCK block
7. ... OUTPUT
Effect This event only makes sense in reports, i.e. in programs set to
type 1 in the attributes. Type 1 programs are started via a
logical database and always have a selection screen where the
user can specify the database selections.
The event is processed when the selection screen has been
processed (at the end of PAI).
If an error message (MESSAGE Emnr) is sent during the event,
all fields on the selection screen become ready for input.
After further user input, AT SELECTION-SCREEN is executed
again.
Note You should only perform very expensive checks with AT
SELECTION-SCREEN if the program is then started (not every time
the user presses ENTER). Here, you can read the system field
SSCRFIELDS-UCOMM (provided a statement TABLES SSCRFIELDS
exists). If the field has one of the values 'ONLI' (= Execute)
or 'PRIN' (= Execute and Print), the report is then started,
i.e. the selection screen is closed and the processing
continues with START-OF-SELECTION. Remember that the selection
screen (and thus also AT SELECTION-SCREE N) is also processed
in variant maintenance and with SUBMIT VIA JOB. You can
determine which of these applies by calling the function module
RS_SUBMIT_INFO .
Addition 1 ... ON psel
Effect This event is assigned to the selection screen fields
corresponding to the report parameter or selection criterion
psel.
If the report starts an error dialog at this point, precisely
these fields become ready for input.
Addition 2 ... ON END OF sel
Effect For each selection criterion sel on the selection screen, you
can call a further screen by pressing a pushbutton. On this
screen, you can enter any number of single values and ranges
for the selection criterion sel.
When this screen has been processed (i.e. at the end of PAI for
this screen), the event AT SELECTION-SCREEN ON END OF sel is
executed.
At this point, all the values entered are available in the
internal table sel.
Addition 3 ... ON VALUE-REQUEST FOR psel_low_high
Effect With this addition, the field psel_low_high is either the name
of a report parameter or of the form sel-LOW or sel-HIGH, where
sel is the name of a selection criterion. The effect of this is
twofold:
1. The pushbutton for F4 (Possible entries) appears beside the
appropriate field.
2. When the user selects this pushbutton or presses F4 for the
field, the event is executed. You can thus implement a
self-programmed possible entries routine for the
input/output fields of the selection screen. If the program
contains such an event and the user presses F4, the system
processes this rather than displaying the check table or the
fixed values of the Dictionary field - even if the report
parameter or the selection option with LIKE or FOR points to
a Dictionary field. You can, for example, use the CALL
SCREEN statement to display a selection list of possible
values. The contents of the field psel_low_high at the end
of this processing block are copied to the appropriate
input/output field.
This addition is only allowed with report-specific parameters
(PARAMETERS) or selection options (SELECT-OPTIONS). For
database-specific parameters or selection options, you can
achieve the same effect by using the addition VALUE-REQUEST FOR
... with the key word PARAMETERS or SELECT-OPTIONS in the
include DBxyzSEL (where xyz = name of logical database). In
this case, you must program the value help in the database
program SAPDBxyz.
Addition 4 ... ON HELP-REQUEST FOR psel_low_high
Effect As with the addition ON VALUE-REQUEST the field psel_low_high
is either the name of a report parameter or of the form sel-LOW
or sel-HIGH, where sel is the name of a selection criterion.
When the user presses F1 on the relevant field, the subsequent
processing block is executed. You can thus implement a
self-programmed help for the input/output fields of the
selection screen. If the program contains such an event and the
user presses F1, the system processes this rather than
displaying the documentation of the Dictionary field - even if
the report parameter or the selection option with LIKE or FOR
points to a Dictionary field.
This addition is only allowed with report-specific parameters
(PARAMETERS) or selection options (SELECT-OPTIONS). For
database-specific parameters or selection options, you can
achieve the same effect by using the addition HELP-REQUEST FOR
... with the key word PARAMETERS or SELECT-OPTIONS in the
include DBxyzSEL (where xyz = name of logical database). In
this case, you must program the help in the database program
SAPDBxyz.
Addition 5 ... ON RADIOBUTTON GROUP radi
Effect This event is assigned to the radio button groups on the
selection screen defined by PARAMETERS par RADIOBUTTON GROUP
radi.
If the report starts an error dialog at this point, precisely
these fields of the radio button group radi become ready for
input again.
Addition 6 ... ON BLOCK block
Effect This event is assigned to the blocks on the selection screen
defined by SELECTION-SCREEN BEGIN/END OF BLOCK block.
If the report starts an error dialog at this point, precisely
these fields of the block block become ready for input again.
Note In which sequence are the events AT SELECTION-SCREEN ON psel
..., AT SELECTION-SCREEN ON RADIOBUTTON GROUP ..., AT
SELECTION-SCREEN ON BLOCK ..., AT SELECTION-SCREEN processed?
The AT SELECTION-SCREEN ON psel ... events assigned to the
parameters or selection options are executed in the sequence
they are declared in the program, i.e. in the sequence they
appear on the selection screen.
The events assigned to the radio button groups are executed
according to the first parameter of the radio button group.
The events assigned to the blocks are executed "from the inside
to the outside".
Example
SELECT-OPTIONS SEL0 FOR SY-TVAR0.
SELECTION-SCREEN BEGIN OF BLOCK BL0.
SELECT-OPTIONS SEL1 FOR SY-TVAR1.
SELECTION-SCREEN BEGIN OF BLOCK BL1.
PARAMETERS P0 RADIOBUTTON GROUP RADI.
PARAMETERS P1 RADIOBUTTON GROUP RADI.
SELECTION-SCREEN BEGIN OF BLOCK BL2.
PARAMETERS P3.
SELECTION-SCREEN END OF BLOCK BL2.
SELECT-OPTIONS SEL2 FOR SY-TVAR2.
SELECTION-SCREEN END OF BLOCK BL1.
SELECTION-SCREEN END OF BLOCK BL0.
Sequence:
AT SELECTION-SCREEN ON...
SEL0
SEL1
RADIOBUTTON GROUP RADI
P3
BLOCK BL2
SEL2
BLOCK BL1
BLOCK BL0
AT SELECTION-SCREEN is executed at the very end.
Addition 7 ... OUTPUT
Effect This event is executed at PBO of the selection screen every
time the user presses ENTER - in contrast to INITIALIZATION.
Therefore, this event is not suitable for setting selection
screen default values. Also, since AT SELECTION-SCREEN OUTPUT
is first executed after the variant is imported (if a variant
is used) and after adopting any values specified under SUBMIT
in the WITH clause, changing the report parameters or the
selection options in AT SELECTION-SCREEN OUTPUT would destroy
the specified values.
Here, however, you can use LOOP AT SCREEN or MODIFY SCREEN to
change the input/output attributes of selection screen fields.
Example Output all fields of the SELECT-OPTION NAME highlighted:
SELECT-OPTIONS NAME FOR SY-REPID MODIF ID XYZ.
...
AT SELECTION-SCREEN OUTPUT.
LOOP AT SCREEN.
CHECK SCREEN-GROUP1 = 'XYZ'.
SCREEN-INTENSIFIED = '1'.
MODIFY SCREEN.
ENDLOOP.
The addition MODIF ID XYZ to the key word SELECT-OPTIONS
assigns all fields of the selection option NAME to a group you
can read in the field SCREEN-GROUP1. At PBO of the selection
screen, all these fields are then set to highlighted.
Note In the context of event processing, the SET PF-STATUS statement
does not work. Instead, you must set a status using the
function module RS_SET_SELSCREEN_STATUS or
RS_EXTERNAL_SELSCREEN_STATUS.
AUTHORITY-CHECK
Basic form AUTHORITY-CHECK OBJECT object
ID name1 FIELD f1
ID name2 FIELD f2
...
ID name10 FIELD f10.
Effect Explanation of IDs:
object Field which contains the name of the object for
which the authorization is to be checked.
name1 ... Fields which contain the names of the
name10 authorization fields defined in the object.
f1 ... Fields which contain the values for which the
f10 authorization is to be checked.
AUTHORITY-CHECK checks for one object whether the user has an
authorization that contains all values of f (see SAP
authorization concept).
You must specify all authorizations for an object and a also a
value for each ID (or DUMMY).
The system checks the values for the IDs by AND-ing them
together, i.e. all values must be part of an authorization
assigned to the user.
If a user has several authorizations for an object, the values
are OR-ed together. This means that if the CHECK finds all the
specified values in one authorization, the user can proceed.
Only if none of the authorizations for a user contains all the
required values is the user rejected.
If the return code SY-SUBRC = 0, the user has the required
authorization and may continue.
The return code is modified to suit the different error
scenarios. The return code values have the following meaning:
4 User has no authorization in the SAP System for
such an action. If necessary, change the user
master record.
8 Too many parameters (fields, values). Maximum
allowed is 10.
12 Specified object not maintained in the user
master record.
16 No profile entered in the user master record.
24 The field names of the check call do not match
those of an authorization. Either the
authorization or the call is incorrect.
28 Incorrect structure for user master record.
32 Incorrect structure for user master record.
36 Incorrect structure for user master record.
If the return code value is 8 or possibly 24, inform the person
responsible for the program. If the return code value is 4, 12,
15 or 24, consult your system administrator if you think you
should have the relevant authorization. In the case of errors
28 to 36, contact SAP, since authorizations have probably been
destroyed.
Individual authorizations are assigned to users in their
respective user profiles, i.e. they are grouped together in
profiles which are stored in the user master record.
Note Instead of ID name FIELD f, you can also write ID name DUMMY.
This means that no check is performed for the field concerned.
The check can only be performed on CHAR fields. All other field
types result in 'unauthorized'.
Example Check whether the user is authorized for a particular plant. In
this case, the following authorization object applies:
Table OBJ: Definition of authorization object
M_EINF_WRK
ACTVT
WERKS
Here, M_EINF_WRK is the object name, whilst ACTVT and WERKS are
authorization fields. For example, a user with the
authorizations
M_EINF_WRK_BERECH1
ACTVT 01-03
WERKS 0001-0003 .
can display and change plants within the Purchasing and
Materials Management areas.
Such a user would thus pass the checks
AUTHORITY-CHECK OBJECT 'M_EINF_WRK'
ID 'WERKS' FIELD '0002'
ID 'ACTVT' FIELD '02'.
AUTHORITY-CHECK OBJECT 'M_EINF_WRK'
ID 'WERKS' DUMMY
ID 'ACTVT' FIELD '01':
but would fail the check
AUTHORITY-CHECK OBJECT 'M_EINF_WRK'
ID 'WERKS' FIELD '0005'
ID 'ACTVT' FIELD '04'.
To suppress unnecessary authorization checks or to carry out
checks before the user has entered all the values, use DUMMY> -
as in this example. You can confirm the authorization later
with another AUTHORITY-CHECK.
BACK
Basic form BACK.
Effect Returns output position to the first line of the current page
after the TOP-OF-PAGE processing.
When used in connection with RESERVE x LINES, the statement
returns the output position to the first output line after
RESERVE.
Example
DATA: TOWN(10) VALUE 'New York',
CUSTOMER1(10) VALUE 'Charly',
CUSTOMER2(10) VALUE 'Sam',
SALES1 TYPE I VALUE 1100,
SALES2 TYPE I VALUE 2200.
RESERVE 2 LINES.
WRITE: TOWN, CUSTOMER1,
/ CUSTOMER2 UNDER CUSTOMER1.
BACK.
WRITE: 50 SALES1,
/ SALES2 UNDER SALES1.
Using the positioning in WRITE in column 50, data not yet
output is not overwritten, but the sales volume is output after
the customer names.
Notes 1. If you use a '/' with the first WRITE after the BACK
statement, this starts a (usually unwanted) new line.
2. BACK in the TOP-OF-PAGE processing positions the cursor
after the standard header. Subsequent WRITE statements also
overwrite the lines output under TOP-OF-PAGE.
Note Performance:
The runtime required to execute a BACK statement is about 1 msn
(standardized microseconds).
BREAK-POINT
Variants:
1.BREAK-POINT.
2.BREAK-POINT f.
Variant 1 BREAK-POINT.
Effect The BREAK-POINT statement interrupts the processing and diverts
the system to debugging mode. You can then display the contents
of all the fields at runtime and also control the subsequent
program flow.
If the system is unable to branch to debugging for some reason
(due to a background job or update), it generates a system log
message.
Note - After the BREAK-POINT, the system automatically performs any
restart in the database, if no COMMIT WORK was executed.
Since debugging sometimes switches off COMMIT WORK, you
should not place a BREAK-POINT statement in a SELECT loop.
- In the editor, you can also set a breakpoint dynamically
without making any changes to the ABAP/4 program. These
dynamic breakpoints are valid only for the current user in
the current session.
Variant 2 BREAK-POINT f.
Effect Behaves like variation 1, except that the field contents of f
remain in the event of any system log messages.
CALL
Call a function module
- CALL FUNCTION func.
- CALL FUNCTION func STARTING NEW TASK taskname.
- CALL FUNCTION func IN UPDATE TASK.
- CALL FUNCTION func DESTINATION dest.
- CALL FUNCTION func IN BACKGROUND TASK.
- CALL CUSTOMER-FUNCTION func.
Call a screen
- CALL SCREEN scr.
Call a transaction
- CALL TRANSACTION tcod.
Call a dialog module
- CALL DIALOG dial.
Call a method of an external object
- CALL METHOD OF obj m.
Call a system function
- CALL cfunc.
CALL - Call a system function
Note This statement is for internal use only.
Incompatible changes or further developments may occur at any
time without warning or notice.
Basic form 6 CALL cfunc.
Addition:
... ID id1 FIELD f1 ... ID idn FIELD fn
Effect Calls the system function cfunc. The relevant function must
exist in the file sapactab.h. If you change or recreate a
function, you have to compile and link the SAP kernel again.
For this, you need the C source code files.
Normally, external programs should be called via RFC with CALL
FUNCTION ... DESTINATION.
Addition ... ID id1 FIELD f1 ... ID idn FIELD fn
Effect Passes fields to the called program by reference. With "ID
id1", you specify the name of a formal parameter, and with
"FIELD f1" the relevant field from the ABAP/4 program. If a
formal parameter expects an internal table, the latter is
passed in the form "FIELD tab[]".
Example
DATA RESULT(8).
CALL 'MULTIPLY' ID 'P1' FIELD '9999'
ID 'P2' FIELD '9999'
ID 'RES' FIELD RESULT.
Note Runtime errors:
CALL_C_FUNCTION_NOT_FOUND: Specified system function is
unknown.
CALL FUNCTION
Variant 6 CALL CUSTOMER-FUNCTION func.
Additions:
The same as for CALL FUNCTION func.
Effect Calls the function module func. func must be a 3-character
literal (e.g. '001')
In line with SAP's enhancement concept, function modules are
delivered empty and must be implemented by the customer (the
transactions used for this are SMOD at SAP and CMOD at the
customer's).
The interface and call location are both defined by SAP.
Note The customer can use Transaction CMOD to activate the function
module. The final name of the function module is compiled from
EXIT_, the name of the module pool where the function module is
called, and the name func. For example, the statement "CALL
CUSTOMER-FUNCTION '001'" in the module pool SAPMS38M calls the
function module EXIT_SAPMS38M_001.
CALL DIALOG - Call a dialog module
CALL DIALOG dial.
Additions:
1. ... AND SKIP FIRST SCREEN
2. ... EXPORTING f1 FROM g1 ... fn FROM gn
3. ... IMPORTING f1 TO g1 ... fn TO gn
4. ... USING itab ... MODE mode.
Effect Calls the dialog module dial; dial can be a literal or a
variable.
To edit dialog modules, select Tools -> ABAP/4 Workbench ->
Development -> Programming environ. -> Dialog modules.
Addition 1 ... AND SKIP FIRST SCREEN
Effect Processes the first screen of the dialog module in the
background, if all required entry fields have been filled.
Addition 2 ... EXPORTING f1 FROM g1 ... fn FROM gn
Effect Specifies all data objects (fields, field strings, internal
tables) to be passed to the dialog module. If the names in the
calling and called programs are identical, you can omit "FROM
g1". Otherwise, fi refers to the field in the dialog module,
while gi specifies the field in the calling program.
Addition 3 ... IMPORTING f1 TO g1 ... fn TO gn
Effect Specifies all data objects (fields, field strings, internal
tables) to be returned from the dialog module. If the names in
the calling and called programs are identical, you can omit "TO
g1". Otherwise, fi refers to the field in the dialog module,
while gi specifies the field in the calling program.
Examples
DATA: BEGIN OF ITAB,
LINE(72),
END OF ITAB,
TITLE LIKE SY-TITLE.
CALL DIALOG 'RS_EDIT_TABLE'
EXPORTING SOURCETAB FROM ITAB
TITLE
IMPORTING SOURCETAB TO ITAB.
Notes - The system field SY-SUBRC is automatically exported and
imported.
- The unknown export/import data in the dialog module is
ignored.
- The data objects passed should have the same type or
structure in the calling program and the dialog module.
Addition 4 ... USING itab ... MODE mode
Effect Calls the dialog module dial and also passes the internal table
itab which contains one or more screens in batch input format.
If required, the dialog module may return a message to the
system fields SY-MSGID, SY-MSGTY, SY-MSGNO, SY-MSGV1, ...,
SY-MSGV4.
The specified processing mode mode mode can accept the
following values:
'A' Display screen
'E' Display only if an error occurs
'N' No display
If the addition MODE is not specified, the processing mode is
'A'.
The return code value is set as follows:
SY-SUBRC = 0: The processing was successful.
SY-SUBRC <> 0: The dialog ended with an error.
Notes - All lock arguments are automatically exported and imported.
In contrast to a transaction, a dialog module does not form
its own LUW (see Transaction processing). Any update
requests which occur there are not processed until the
calling program executes a COMMIT WORK.
- To return from the dialog module, use the key word LEAVE
PROGRAM.
Note Runtime errors:
- CALL_DIALOG_NOT_FOUND: The called dialog module is unknown.
- CALL_DIALOG_WRONG_TDCT_MODE: The called dialopg module
contains errors (incorrect entry in table TDCT).
- CALL_DIALOG_NAME_TOO_LONG: The name of a parameter is longer
than permitted.
- CALL_DIALOG_NO_CONTAINER: No memory for parameter transfer.
Related CALL TRANSACTION, CALL FUNCTION
CALL - call a function module
Variants:
Call a function module:
1. CALL FUNCTION func.
Call a function module in a different mode (asynchronous Remote
Function Call):
2. CALL FUNCTION func STARTING NEW TASK taskname.
Call a function module in the update task:
3. CALL FUNCTION func IN UPDATE TASK.
Call a function module in a remote system (Remote Function
Call, RFC):
4. CALL FUNCTION func DESTINATION dest.
Asynchronous call to a function module with transactional
processing (transactional Remote Function Call):
5. CALL FUNCTION func IN BACKGROUND TASK.
Call a function module which can be activated in the context of
enhancements:
6. CALL CUSTOMER-FUNCTION func.
CALL FUNCTION
Variant 1 CALL FUNCTION func.
Additions:
1. ... EXPORTING p1 = f1 ... pn = fn
2. ... IMPORTING p1 = f1 ... pn = fn
3. ... TABLES p1 = itab1 ... pn = itabn
4. ... CHANGING p1 = f1 ... pn = fn
5. ... EXCEPTIONS except1 = rc1 ... exceptn = rcn
Effect Calls the function module func; func can be a literal or a
variable.
To edit function modules, select Tools -> ABAP/4 Workbench ->
Function Library.
The assignment of parameters is by name (p1, p2, etc.), not by
sequence.
To return from the function module, you use the key word EXIT,
unless EXIT occurs in a loop or a subroutine.
Note You can use the editor commands "SHOW FUNCTION func" and "SHOW
FUNCTION *" to get information about the function module func
or any other function module.
Addition 1 ... EXPORTING p1 = f1 ... pn = fn
Effect EXPORTING passes fields, field strings or internal tables to
the function module. You must declare the parameters p1 ... pn
in the function interface as import parameters. When you call
the function module, you must assign values to all import
parameters which are not flagged in the interface definition as
optional and do not have any default values.
Addition 2 ... IMPORTING p1 = f1 ... pn = fn
Effect IMPORTING passes fields, field strings or internal tables from
the function module back to the calling program. The parameters
p1 ... pn must be declared as export parameters in the function
interface.
Addition 3 ... TABLES p1 = itab1 ... pn = itabn
Effect TABLES passes references to internal tables. The parameters p1
... pn must be declared as table parameters in the function
interface. When you call the function module, you must assign
values to all table parameters which are not flagged as
optional in the interface definition.
Addition 4 ... CHANGING p1 = f1 ... pn = fn
Effect CHANGING passes fields, field strings or internal tables to the
function module and the changed values are returned. The
parameters p1 ... pn must be declared as CHANGING parameters in
the function interface. When you call the function module, you
must assign values to all CHANGING parameters of the function
module which are not flagged as optional in the interface
definition and have no default values.
Addition 5 ... EXCEPTIONS except1 = rc1 ...
exceptn = rcn
Effect EXCEPTIONS lists the exceptions to be handled by the calling
program itself. At the end of the exception list, you can use
OTHERS to refer to all the remaining exceptions.
If one of the listed exceptions occurs, SY-SUBRC is set to the
appropriate value rc (a number literal!) and control passes
back to the calling program. By specifying a return code, you
can divided the exceptions into classes. With the second form,
without "=rc", SY-SUBRC is set to a value other than 0 if an
exception occurs.
If the function module triggers an exception (with the
statements RAISE and MESSAGE ... RAISING) and the exception is
not to be handled by the calling program itself,
- RAISE terminates the program with a runtime error;
- MESSAGE ... RAISING outputs the message.
Note The following EXCEPTIONS are predefined by the system and have
a special meaning:
- OTHERS: Covers all user-defined exceptions in the called
function module.
- ERROR_MESSAGE: This exception instructs the system to ignore
S messages, I messages and W messages until return from the
function module (although they still appear in the log
during background processing). When an E message or an A
message occurs, the called function module terminates, as if
the exception ERROR_MESSAGE has been triggered.
Examples
DATA: FIELD(30) VALUE 'Example: This is a field.',
head(30).
CALL FUNCTION 'STRING_SPLIT'
EXPORTING DELIMITER = ':'
STRING = FIELD
IMPORTING HEAD = HEAD
TAIL = FIELD
EXCEPTIONS NOT_FOUND = 1
OTHERS = 2.
CASE SY-SUBRC.
WHEN 1. ...
WHEN 2. ....
ENDCASE.
...
DATA: BEGIN OF TAB1 OCCURS 10, X, END OF TAB1,
BEGIN OF TAB2 OCCURS 20, Y, END OF TAB2.
CALL FUNCTION 'ITAB_COPY'
TABLES TAB_IN = TAB1
TAB_OUT = TAB2.
Note Runtime errors:
- CALL_FUNCTION_NOT_FOUND: The called function is unknown.
- CALL_FUNCTION_NO_VB: Only update function modules can be
called in the update task.
- CALL_FUNCTION_NOT_ACTIVE: The called function is known, but
not active.
- CALL_FUNCTION_PARM_MISSING: The function expects a
parameter, but none was passed by the calling program.
- CALL_FUNCTION_PARM_UNKNOWN: The calling program passed a
parameter which the function does not recognize.
- CALL_FUNCTION_CONFLICT_LENG: The function expected a
different actual parameter length.
- CALL_FUNCTION_CONFLICT_TYPE
- CALL_FUNCTION_CONFLICT_GEN_TYP: The actual parameter type
does not satisfy the requirements of the function interface.
- CALL_FUNCTION_WRONG_ALIGNMENT: An actual parameter does not
satisfy the alignment requirements of the corresponding
formal parameter.
- CALL_FUNCTION_BASE_LITL: A literal was supposed to be passed
to a structured formal parameter.
CALL FUNCTION
Variants:
Call a function module
1. CALL FUNCTION func.
Call a function module in new mode (asynchronous Remote
Function Call)
2. CALL FUNCTION func STARTING NEW TASK taskname dest.
Call a function module in the update task
3. CALL FUNCTION func IN UPDATE TASK.
Call a function module in a remote system (Remote Function
Call)
4. CALL FUNCTION func DESTINATION dest.
Asynchronous call to function module with transaction-like
processing (transaction-like Remote Function Call)
5. CALL FUNCTION func IN BACKGROUND TASK.
Call a function module that can be activated within framework
of enhancement concept.
6. CALL CUSTOMER-FUNCTION func.
CALL FUNCTION
Variant 5 CALL FUNCTION func IN BACKGROUND TASK.
Additions:
1. ... DESTINATION dest
2. ... EXPORTING p1 = f1 ... pn = fn
3. ... TABLES p1 = itab1 ... pn = itabn
Effect Flags the function module func to be run asynchronously. It is
not executed at once, but the data passed with EXPORTING bzw.
TABLES is placed in a database table and the next COMMIT WORK
then executes the function module in another work process.
Note This variant applies only from R/3 Release 3.0. Both partner
systems (the client and the server systems) must have a Release
3.0 version of the R/3 System.
Addition 1 ... DESTINATION dest
Effect Executes the function module externally as a Remote Function
Call (RFC); dest can be a literal or a variable.
Depending on the specified destination, the function module is
executed either in another R/3 System or as a C-implemented
function module. Externally callable function modules must be
flagged as such in the function library (of the target system).
Since each destination defines its own program context, further
calls to the same or different function modules with the same
destination can access the local memory (global data) of these
function modules.
Addition 2 ... EXPORTING p1 = f1 ... pn = fn
Effect EXPORTING passes values of fields and field strings from the
calling program to the function module. In the function module,
the formal parameters are defined as import parameters. Default
values must be assigned to all import parameters of the
function module in the interface definition.
Addition 3 ... TABLES p1 = itab1 ... pn = itabn
Effect TABLES passes references to internal tables. All table
parameters of the function module must contain values.
Notes
If several function module calls with the same destination are
specified before COMMIT WORK, these form an LUW in the target
system.
Type 2 destinations (R/3 - R/2 connections) cannot be
specified.
CALL FUNCTION
Variant 6 CALL CUSTOMER-FUNCTION func.
Additions:
The same as with CALL FUNCTION func.
Effect Calls the function module func; this can be activated. func
must be a 3-character literal (e.g. '001').
The function modules are delivered empty within the framework
of the enhancement concept and must be implemented by the
customer. They are maintained with the Transactions SMOD (at
SAP) and CMOD (at the csutomer's).
SAP determines both the interface and the place where the call
is made.
Note By using the Transaction CMOD, the customer can activate the
function module. The final name of the function module
comprises EXIT_, the name of the module pool where the function
module is called, and the name func. For example, the statement
"CALL CUSTOMER-FUNCTION '001'" in the module pool SAPMS38M
calls the function module EXIT_SAPMS38M_001.
CALL FUNCTION
Variant 4 CALL FUNCTION func DESTINATION dest.
Additions:
1. The same as with CALL FUNCTION func
2. ... EXCEPTIONS syst_except = rc MESSAGE mess
Effect Executes the function module externally as a Remote Function
Call (RFC); dest can be a literal or a variable.
Depending on the specified destination, the function module is
executed in another R/3 or R/2 System. Externally callable
function modules must be flagged as such in the function
library (of the target system).
Since each destination defines its own program context, further
calls to the same or different function modules with the same
destination can access the local memory (global data) of these
function modules.
You can maintain existing destinations by selecting Tools ->
Administration -> Administration -> Network -> RFC
destinations.
Notes Special destinations:
- The destination NONE refers to the calling system. Function
modules called with
CALL FUNCTION func DESTINATION 'NONE' ...
are executed in the system of the calling program, but in
their own program context.
- You can use the destination BACK if the current program was
already called by RFC. The, BACK refers back to the calling
program:
CALL FUNCTION func DESTINATION 'BACK' ...
If the program is not called from a "remote" source, the
exception COMMUNICATION_FAILURE is triggered.
- Each R/3 System has a standard name. This is formed from the
host name (e.g. SY-HOST), the system name (SY-SYSID) and the
system nummer (two-character number assigned on installation
of the applications server).
You can use this name as a destination. For example, you can
call the function module func in the system C11 on the host
sapxyz with system number 00 as follows:
CALL FUNCTION func DESTINATION 'sapxyz_C11_00' ...
- You can also use saprouter path names as destinations (see
also saprouter documentation).
Note Parameter passing. When you pass data to an externally called
function module, there are some differences to the normal
function module call:
- With table parameters, only the table itself is passed, not
the header line.
- If one of the parameters of the interface of an externally
called function module is not specified when called, the
import parameters are set to their initial value. If no
default value was given in the interface definition, TABLES
parameters are defined as an empty table and unspecified
export parameters are lost.
Note Passing structured data objects. Since transport to another
system may require data conversion, the structure of field
strings and internal tables must be known to the runtime system
when the call is made. The structure of a field string or
internal table is not known if it was defined with
... LIKE structure,
if the structure passed was passed to the subroutine with the
explicit addition STRUCTURE, or if it is a parameter of a
function module.
In these cases, external calls can result in a conversion
error.
Note C interface. You can call externally callable function modules
from C programs. It is also possible to store function modules
in a C program and call them via CALL FUNCTION ... DESTINATION.
For this purpose, SAP provides a C interface.
Addition 2 ... EXCEPTIONS syst_except = rc MESSAGE mess
Effect Function module calls with the addition DESTINATION can handle
two special system exceptions:
SYSTEM_FAILURE
This is triggered if a system crash occurs on
the receiving side.
COMMUNICATION_FAILURE
This is triggered if there is a connection or
communication problem.
In both cases, you can use the optional addition
... MESSAGE mess
to receive a description of the error.
Note Runtime errors:
- CALL_FUNCTION_DEST_TYPE:Destination type not allowed.
- CALL_FUNCTION_NO_DEST:Destination does not exist.
- CALL_FUNCTION_NO_LB_DEST:Destination (in 'Load Balancing'
mode) does not exist.
- CALL_FUNCTION_TABINFO:Data error (info internal table)
during 'Remote Function Call'.
CALL FUNCTION
Variant 2 CALL FUNCTION func ...STARTING NEW TASK taskname.
Additions:
1. ... DESTINATION dest
2. ... PERFORMING form ON END OF TASK
3. ... EXPORTING p1 = f1 ... pn = fn
4. ... TABLES p1 = itab1 ... pn = itabn
5. ... EXCEPTIONS syst_except = rc MESSAGE mess
Effect Starts the function module func asynchronously in a new mode.
In contrast to normal function module calls, the calling
program resumes processing as soon as the function module is
started in the target system. It does not wait until the
function module has finished. Through CALL SCREEN, the called
function module can, for example, display a screen and thus
interact with the user.
Notes This variant applies only from R/3 Release 3.0. Both partner
systems (the client and the server systems) must have a Release
3.0 version of the R/3 System.
With this variant, the called function module must also be
flagged in the Function Library as externally callable, even if
it is executed locally (without the addition DESTINATION).
Addition 1 ... DESTINATION dest
Effect Executes the function module externally as a Remote Function
Call (RFC); dest can be a literal or a variable. The R/3 System
where the function module is executed depends on the specified
destination. Externally callable function modules must be
flagged as such in the Function Library (of the target system).
Addition 2 ... PERFORMING form ON END OF TASK
Whereas the parameters for receiving results (i.e. IMPORTING
and TABLES parameters) are specified directly as additions in
the case of "conventional" function modules (see variant 2),
these are logged in the FORM routine form when making an
asynchronous call (see RECEIVE).
Note If a function module returns no result, this addition (...
PERFORMING form ON END OF TASK) can be omitted.
Addition 3 ... EXPORTING p1 = f1 ... pn = fn
Effect EXPORTING passes values of fields and field strings from the
calling program to the function module. In the function module,
the formal parameters are defined as import parameters.
Addition 4 ... TABLES p1 = itab1 ... pn = itabn
Effect TABLES passes references to internal tables. All table
parameters of the function module must contain values.
Addition 5 ... EXCEPTIONS syst_except = rc MESSAGE mess
Effect While any exceptions arising in the called function module are
handled by the second addition (in the FORM routine), this
addition can handle two special system exceptions, as with
function module calls with the addition DESTINATION:
SYSTEM_FAILURE
is triggered, if a system crash occurs on the
receiving side.
COMMUNICATION_FAILURE
is triggered if there is a connection or
communication problem.
In both cases, you can get a description of the error with the
optional addition
... MESSAGE mess
Example
DATA: MSG_TEXT(80). "Message text
...
Asynchronous call to Transaction SM59 -->
Create a new session
CALL FUNCTION 'ABAP4_CALL_TRANSACTION' STARTING NEW TASK 'TEST'
DESTINATION 'NONE'
EXPORTING
TCODE = 'SM59'
EXCEPTIONS COMMUNICATION_FAILURE MESSAGE MSG_TEXT.
IF SY-SUBRC NE 0.
WRITE: MSG_TEXT.
ELSE.
WRITE: 'O.K.'.
ENDIF.
Note Runtime errors:
- CALL_FUNCTION_TASK_YET_OPEN: Task already open.
CALL FUNCTION
Variant 3 CALL FUNCTION func IN UPDATE TASK.
Additions:
1. ... EXPORTING p1 = f1 ... pn = fn
2. ... TABLES p1 = itab1 ... pn = itabn
Effect Flags the function module func for execution in the update
task. It is not executed at once, but the data passed with
EXPORTING or TABLES is placed in a database table and a
subsequent COMMIT WORK then causes the function module to be
executed by the update task. Update function modules must be
flagged as such in the function library.
Addition 1 ... EXPORTING p1 = f1 ... pn = fn
Effect Values of fields and field strings specified under EXPORTING
are passed from the calling program to the function module. In
the function module, the formal parameters are defined as
import parameters. In the interface definition, default values
must be assigned to all import parameters of the update
function module.
Addition 2 ... TABLES p1 = itab1 ... pn = itabn
Effect TABLES passes references to internal tables. All table
parameters of the function module must have values.
Note With update function modules, both import parameters and
exceptions are ignored when the call is made.
Administration transaction
CALL METHOD - Call a method of an external object
Basic form CALL METHOD OF obj m.
Additions:
1. ... = f
2. ... EXPORTING p1 = f1 ... pn = fn
3. ... NO FLUSH
Effect Calls the method m of the object obj. m can be a literal or a
variable.
Normally, all consecutive OLE statements are buffered by the
ABAP/4 processor and sent to the presentation server in bundled
form. This means that it is possible for a statement to refer
to the results of preceding statements.
In debugging, however, you should remember that the values of
the return parameters cannot be displayed until directly before
execution of the first ABAP/4 statement external to OLE.
Even a command which refers to an object not yet generated by
any OLE statement terminates the bundling.
The return code value of SY-SUBRC indicates whether all the
bundled commands have been successfully executed.
The return code value is set as follows:
SY-SUBRC = 0: All commands were successfully executed.
SY-SUBRC = 1: When communicating with the presentation
server, a system error occurred. The
system field SY-MSGLI contains a short
description of the error.
SY-SUBRC = 2: A method call resulted in an error.
SY-SUBRC = 3: Setting a property resulted in an error.
SY-SUBRC = 4: Reading a property resulted in an error.
In the last 3 cases, a dialog box containing an error note is
displayed on the presentation server.
CALL METHOD belongs to a group of key words which allow you to
process external objects with ABAP/4. At present, only the
object model OLE2 is supported, i.e. all objects must be of
type OLE2_OBJECT. This type and other necessary data are
defined in the include program OLE2INCL.
Addition 1 ... = f
Effect Stores the return value of the method in the variable f. The
return value can also be of type OLE2_OBJECT. This addition
must always come before other additions.
Addition 2 ... EXPORTING p1 = f1 ... pn = fn
Effect EXPORTING passes values of fields to the parameters of the
method. p1, p2, ... are either key word parameters or position
parameters.
If assignment of parameters is by sequence, p1, p2, ... must
begin with "#", followed by the position number of the
parameter. At present, only position parameters are supported.
The export parameters always come at the end of the statement.
Addition 3 ... NO FLUSH
The addition NO FLUSH continues the collection process, even if
the next command is not an OLE statement. This means that you
can set a series of properties in a loop and download them to
the presentation server in a single transport operation.
If you do not use NO FLUSH, you must ensure that you do not
rely on the contents of return parameters not yet filled.
Also, all objects must be initialized in a bundle, i.e. they
must be generated by an OLE call that has already been
executed.
Every FREE statement always causes a download of the buffer.
Example Open an EXCEL file with the method 'Open'.
INCLUDE OLE2INCL.
DATA EXCEL TYPE OLE2_OBJECT.
DATA WORKBOOK TYPE OLE2_OBJECT.
CREATE OBJECT EXCEL 'Excel.Application'.
CALL METHOD OF EXCEL 'Workbooks' = WORKBOOK.
CALL METHOD OF WORKBOOK 'Open' EXPORTING #1 = 'C:\EX1.XLS'.
Related SET PROPERTY
GET PROPERTY
CREATE OBJECT
FREE OBJECT
CALL SCREEN - Call a screen
Basic form CALL SCREEN scr.
Addition:
... STARTING AT x1 y1 ... ENDING AT x2 y2
Effect Calls the screen scr; scr is the number of a screen of the main
program. You use SET SCREEN 0. or LEAVE SCREEN. to define the
return from the CALL screen.
Addition ... STARTING AT x1 y1 ENDING AT x2 y2
Effect The coordinates x1, y1 (start column and start line in the
window) and x2, y2 (end column and end line in the window)
define the size and position of the CALL screen ("top left -
bottom right"). Besides these coordinates, you can also see the
contents of the primary window, but cannot perform any action
there.
Note - If "ENDING AT ..." is not specified, suitable values are
substituted for x2 and y2, taking into account the size of
the called screen.
Note Runtime errors:
DYNP_TOO_MANY_CALL_SCREENS: No further screen level (call
screen); the maximum number of nested screen levels is
restricted to 50 at present.
CALL TRANSACTION - Call a transaction
Basic form CALL TRANSACTION tcod.
Additions:
1. ... AND SKIP FIRST SCREEN
2. ... USING itab
2a. ... MODE mode
2b. ... UPDATE upd
2c. ... MESSAGES INTO messtab
Effect Calls the SAP Transaction tcod; tcod can be a literal or a
variable. To return from the called transaction, you use the
key word LEAVE PROGRAM.
Example
CALL TRANSACTION 'SP01'.
Addition 1 ... AND SKIP FIRST SCREEN
Effect Skips the first screen in the transaction (provided all the
required fields have been assigned values by the SPA/GPA
process).
Addition 2 ... USING itab
Effect Calls the Transaction tcod and passes the internal table itab,
which contains one or several screens in batch input format.
If necessary, one of the messages output by the Transaction is
returned to the fields SY-MSGID, SY-MSGTY SY-MSGNO, SY-MSGV1,
..., SY-MSGV4.
The return code value is set as follows:
SY-SUBRC = 0: Processing was successful.
SY-SUBRC <> 0: Transaction ended with an error.
Note A called Transaction ends successfully for the following
reasons:
1. COMMIT WORK
2. Next screen = 0
3. LEAVE TO TRANSACTION ' '
Addition 2a ... MODE mode
Effect The specified processing mode can accept the following values:
'A' Display screen
'E' Display screen only if an error occurs
'N' No display
If the addition MODE is not specified, the processing mode is
set to 'A'.
Addition 2b ... UPDATE upd
Effect The specified update mode upd defines the update type. This can
have one of the following values:
'A' Asynchronous update
'S' Synchronous update
If the addition UPDATE is not specified, the processing mode is
set to 'A'.
Addition 2c ... MESSAGES INTO messtab
Effect The specified internal table contains all system messages that
occur during CALL TRANSACTION USING ... . The internal table
messtab must have the structure BDCMSGCOLL.
Example
DATA BEGIN OF BDCDATA OCCURS 100.
INCLUDE STRUCTURE BDCDATA.
DATA END OF BDCDATA.
DATA BEGIN OF MESSTAB OCCURS 10.
INCLUDE STRUCTURE BDCMSGCOLL.
DATA END OF MESSTAB.
DATA REPORT(8).
BDCDATA-PROGRAM = 'SAPMS38M'.
BDCDATA-DYNPRO = '0100'.
BDCDATA-DYNBEGIN = 'X'.
APPEND BDCDATA.
CLEAR BDCDATA.
BDCDATA-FNAM = 'RS38M-PROGRAMM'.
BDCDATA-FVAL = REPORT.
APPEND BDCDATA.
...
CALL TRANSACTION 'SE38' USING BDCDATA MODE 'N'
MESSAGES INTO MESSTAB.
Notes Runtime errors:
- CALL_TRANSACTION_NOT_FOUND: Transaction is unknown.
- CALL_TRANSACTION_IS_MENU: Transaction is a menu.
- CALL_TRANSACTION_USING_NESTED: Recursive CALL TRANSACTION
USING
Related SUBMIT
CALL DIALOG
CASE
Basic form CASE f.
Effect Case distinction.
Depending on the current contents of a field, this statement
executes one of several alternative processing branches. The
field whose contents determine how the subsequent processing is
specified after CASE; the individual processing branches are
introduced by WHEN, followed by the value to be tested. The
entire block is concluded by ENDCASE.
The structure of the CASE statement is as follows:
CASE f.
WHEN f1.
...
WHEN f2.
...
...
ENDCASE.
On reaching such a CASE statement, the processor compares f
with f1.
If f = f1, it executes the processing block between "WHEN f1."
and the next WHEN statement. If there are no further WHEN
statements, it executes the processing block up to the ENDCASE
statement and then continues with any subsequent processing.
If f <> f1, the processor compares the field f2 in the next
WHEN statement with f and proceeds as with f1 and so on.
Although f should be a variable, f1 can be a variable or a
literal. For the comparison "f = f1", the rules are the same as
for IF.
There is a second variant of the WHEN statement:
WHEN OTHERS.
No more than one such WHEN statement is allowed within a CASE
block. The "WHEN OTHERS" processing block is always concluded
by ENDCASE, i.e. no further WHEN statements can follow.
The "WHEN OTHERS" processing block is executed only if none of
the preceding WHEN blocks have been executed, i.e. if all
previous comparisons ("f = ...) have returned a negative
result.
Example
DATA: ONE TYPE I VALUE 1,
THREE TYPE P VALUE 3.
DO 5 TIMES.
CASE SY-INDEX.
WHEN ONE.
WRITE / 'That is'.
WHEN 2.
WRITE 'a'.
WHEN THREE.
WRITE 'good'.
WRITE 'example'.
WHEN OTHERS.
WRITE '!'.
ENDCASE.
ENDDO.
Output: "That is a good example ! !"
Notes 1. You can nest several CASE statements and even combine them
with IF statements.
2. The statement "WHEN: f1, f2." does not make sense. The
example below shows that the block belonging to "WHEN f1" is
empty:
WHEN f1.
WHEN f2.
Related IF, ELSEIF
CHECK
Within loops and events
- CHECK logexp.
Special for reports with logical databases
- CHECK sel.
- CHECK SELECT-OPTIONS.
CHECK - within loops
Basic form CHECK logexp.
Effect CHECK evaluates the subsequent logical expression. If it is
true, the processing continues with the next statement.
In loop structures like
DO ... ENDDO
WHILE ... ENDWHILE
LOOP ... ENDLOOP
SELECT ... ENDSELECT
CHECK with a negative outcome terminates the current loop pass
and goes back to the beginning of the loop to start the next
pass, if there is one.
In structures like
FORM ... ENDFORM
FUNCTION ... ENDFUNCTION
MODULE ... ENDMODULE
AT
CHECK with a negative outcome terminates the routine or
modularization unit.
If CHECK is not in a loop or a routine or a modularization
unit, a negative logical expression terminates the current
event. In contrast, the statement REJECT terminates the current
event, even from loops or subroutines.
Note If a CHECK produces a negative result in a GET event, the GET
events in subordinate tables of the logical database are not
processed either.
Related CONTINUE, EXIT, REJECT, STOP
CHECK - special for reports with logical databases
Variants:
1. CHECK sel.
2. CHECK SELECT-OPTIONS.
Variant 1 CHECK sel.
Effect Checks the selection criterion requested by the statement
SELECT-OPTIONS sel ....
This statement is equivalent to f IN sel, if sel was defined by
SELECT-OPTIONS sel FOR f and can be used anywhere in logical
expressions
If the result of this check is negative, the processing in this
event is terminated and the GET events for any subordinate
database tables are not processed either.
This variant of the CHECK statement should be used only if the
logical database for the corresponding table does not support
dynamic selections (see CHECK SELECT-OPTIONS), or
SELECT-OPTIONS with the addition NO DATABASE SELECTION.
Otherwise, the relevant record is not read from the database
and made available to the program.
Variant 2 CHECK SELECT-OPTIONS.
Effect Called only after a GET event.
This statement checks all the selections for SELECT-OPTIONS
where the reference field after FOR belongs to the current
table dbtab (specified after GET. However, this applies only if
the logical database for dbtab does not support dynamic
selections. Otherwise, the selections are passed directly to
the logical database (with the exception: addition "NO DATABASE
SELECTION" to SELECT-OPTIONS).
This variant of the CHECK statement only makes sense if the
logical database does not support dynamic selections for the
corresponding table or SELECT-OPTIONS are defined with the
addition "NO DATABASE SELECTION".
You can determine from the ABAP/4 Development Workbench whether
dynamic selections are defined and, if so, for which logical
database tables by selecting Development -> Programming
environ. -> Logical databases followed by Extras -> Dynamic
selections.
Example The logical database F1S of the demo flight reservation system
contains the tables SPFLI with, and the table SFLIGHT without,
dynamic selections.
TABLES:
SPFLI, SFLIGHT.
SELECT-OPTIONS:
SF_PRICE FOR SFLIGHT-PRICE,
SP_CARR FOR SPFLI-CARRID,
SP_FROM FOR SPFLI-CITYFROM NO DATABASE SELECTION,
SP_DEPT FOR SPFLI-DEPTIME.
Since dynamic selections are defined with the table SPFLI, but
not with the table SFLIGHT, the following procedure applies:
...
GET SFLIGHT.
CHECK SELECT-OPTIONS.
This CHECK statement is equivalent to the following statement:
CHECK SF_PRICE.
With
GET SPFLI.
CHECK SELECT-OPTIONS.
the CHECK statement is equivalent to the following statement:
CHECK SP_FROM.
Note With CHECK SELECT-OPTIONS, fields from superior tables in the
database hierarchy are not checked.
Note Runtime errors:
- CHECK_SELOPT_ILLEGAL_OPTION: Wrong "OPTION" in
SELECT-OPTIONS or RANGES table
- CHECK_SELOPT_ILLEGAL_SIGN: Wrong "SIGN" in SELECT-OPTIONS or
RANGES table
Related CONTINUE, EXIT, REJECT, STOP
CLEAR
Basic form CLEAR f.
Additions:
1. ... WITH g
2. ... WITH NULL
Effect Resets the contents of f to its initial value.
For predefined types (see DATA), the following initial values
are used:
Type C: ' ... ' (blank character)
Type N: '00...0'
Type 😧 '00000000'
Type T: '000000'
Type I: 0
Type P: 0
Type F: 0.0E+00
Type X: 0
If f is a field string, each component field is reset to its
initial value. If it is an internal table without a header
line, the entire table is deleted together with all its
entries. If, however, f is an internal table with a header
line, only the sub-fields in the table header entry are reset
to their initial values.
Example
DATA: TEXT(10) VALUE 'Hello',
NUMBER TYPE I VALUE 12345,
ROW(10) TYPE N VALUE '1234567890',
BEGIN OF PLAYER,
NAME(10) VALUE 'John',
TEL(8) TYPE N VALUE '08154711',
MONEY TYPE P VALUE 30000,
END OF PLAYER.
...
CLEAR: TEXT, NUMBER, PLAYER.
The field contents are now as follows:
ROW = '1234567890'
TEXT = ' '
NUMBER = 0
PLAYER-NAME = ' '
PLAYER-TEL = '00000000'
PLAYER-MONEY = 0
Notes 1. When CLEAR references an internal table itab with a header
line, it only resets the sub-fields in the header entry to
their initial values (as mentioned above). The individual
table entries remain unchanged.
To delete the entire internal table together with all its
entries, you can use CLEAR itab[] or REFRESH itab.
2. Within a logical expression, you can use f IS INITIAL to
check that the field f contains the initial value
appropriate for its type.
3. Variables are normally initialized according to their type,
even if the specification of an explicit initial value
(addition "... VALUE lit" of the DATA statement) is missing.
For this reason, it is not necessary to initialize variables
again with CLEAR after defining them.
Addition 1 ... WITH g
Effect The field f is filled with the value of the first byte of the
field g.
Addition 2 ... WITH NULL
Effect Fills the field with hexadecimal zeros.
Note You should use this addition with particular care because the
fields of most data types thus receive values which are really
invalid.
Note Performance:
CLEAR requires about 3 msn (standardized microseconds) of
runtime to process a field of type C with a length of 10 and
about 2 msn to process a field of the type I. To delete an
internal table with 15 fields, it needs about 5 msn.
CLOSE
Basic form
1. CLOSE DATASET dsn.
2. CLOSE CURSOR c.
Basic form 1 CLOSE DATASET dsn.
Effect Closes the file dsn, ignoring any errors which may occur. CLOSE
is required only if you want to edit dsn several times. For
further details, see the documentation for OPEN DATASET.
Basic form 2 CLOSE CURSOR c.
Effect Closes the database cursor c. CLOSE CURSOR is only required if
you want to read sets of database records several times with c.
For further information, refer to the documentation on OPEN
CURSOR and FETCH.
CLOSE CURSOR belongs to the Open SQL command set.
CNT
Basic form ... CNT(h) ...
Effect CNT(h) is not a statement, but a field which is automatically
created and filled by the system if f is a sub-field of an
extract dataset.
CNT(h) can only be addressed from within a LOOP on a sorted
extract.
If h is a non-numeric field (see also ABAP/4 number types) from
the field group HEADER and part of the sort key of the extract
dataset, the end of a control level (AT END OF, AT LAST) is
such that CNT(h) contains the number of different values which
the field h has accepted in the group, i.e. the number of
records in the group for which the field f has changed its
value.
Related SUM(g)
COLLECT
Basic form COLLECT [wa INTO] itab.
Addition:
... SORTED BY f
Effect COLLECT is used to create unique or compressed datsets. The key
fields are the default key fields of the internal table itab.
If you use only COLLECT to fill an internal table, COLLECT
makes sure that the internal table does not contain two entries
with the same default key fields.
If, besides its default key fields, the internal table contains
number fields (see also ABAP/4 number types), the contents of
these number fields are added together if the internal table
already contains an entry with the same key fields.
If the default key of an internal table processed with COLLECT
is blank, all the values are added up in the first table line.
If you specify wa INTO, the entry to be processed is taken from
the explicitly specified work area wa. If not, it comes from
the header line of the internal table itab.
After COLLECT, the system field SY-TABIX contains the index of
the - existing or new - table entry with default key fields
which match those of the entry to be processed.
Notes 1. COLLECT can create unique or compressed datasets and should
be used precisely for this purpose. If uniqueness or
compression are unimportant, or two values with identical
default key field values could not possibly occur in your
particular task, you should use APPEND instead. However, for
a unique or compressed dataset which is also efficient,
COLLECT is the statement to use.
2. If you process a table with COLLECT, you should also use
COLLECT to fill it. Only by doing this can you guarantee
that
- the internal table will actually be unique or compressed, as
described above and
- COLLECT will run very efficiently.
3. If you use COLLECT with an explicitly specified work area,
it must be compatible with the line type of the internal
table.
Example Compressed sales figures for each company
DATA: BEGIN OF COMPANIES OCCURS 10,
NAME(20),
SALES TYPE I,
END OF COMPANIES.
COMPANIES-NAME = 'Duck'. COMPANIES-SALES = 10.
COLLECT COMPANIES.
COMPANIES-NAME = 'Tiger'. COMPANIES-SALES = 20.
COLLECT COMPANIES.
COMPANIES-NAME = 'Duck'. COMPANIES-SALES = 30.
COLLECT COMPANIES.
The table COMPANIES now has the following appearance:
NAME ! SALES
-
Duck ! 40
Tiger ! 20
Addition ... SORTED BY f
Effect COLLECT ... SORTED BY f is obsolete and should no longer be
used. Use APPEND ... SORTED BY f which has the same meaning.
Note Performance:
1. When using internal tables with a header line, avoid
unnecessary assignments to the header line. Whenever
possible, use statements which have an explicit work area.
For example, "APPEND wa TO itab." is approximately twice as
fast as "itab = wa. APPEND itab.". The same applies to
COLLECT and INSERT.
2. The cost of a COLLECT in terms of performance increases with
the width of the default key needed in the search for table
entries and the number of numeric fields with values which
have to be added up, if an entry is found in the internal
table to match the default key fields.
If no such entry is found, the cost is reduced to that
required to append a new entry to the end of the table.
A COLLECT statement used on a table which is 100 bytes wide
and has a key which is 60 bytes wide and seven numeric
fields is about approx. 50 msn (standardized microseconds).
Note Runtime errors:
- COLLECT_OVERFLOW: Overflow in integer field when calculating
totals.
- COLLECT_OVERFLOW_TYPE_P: Overflow in type P field when
calculating totals.
Related APPEND, WRITE ... TO, MODIFY, INSERT
COMMIT
Basic form COMMIT WORK.
Addition:
... AND WAIT
Effect Executes a database commit and thus closes a logical processing
unit or Logical Unit of Work (LUW) (see also Transaction
processing). This means that
- all database changes are made irrevocable and cannot be
reversed with ROLLBACK WORK and
- all database locks are released.
COMMIT WORK also
- calls the subroutines specified by PERFORM ... ON COMMIT,
- executes asynchronously any update requests (see CALL
FUNCTION ... IN UPDATE TASK) specified in these subroutines
or started just before,
- processes the function modules specified in CALL FUNCTION
... IN BACKGROUND TASK,
- cancels all existing locks (see SAP locking concept) if no
update requests exist,
- closes all open database cursors (see OPEN CURSOR) and
- resets the time slice counter to 0.
COMMIT WORK belongs to the Open SQL command set.
The return code value SY-SUBRC is set to 0.
Notes 1. All subroutines called with PERFORM ... ON COMMIT are
processed in the LUW concluded by the COMMIT WORK command.
All V1 update requests specified in CALL FUNCTION ... IN
UPDATE TASK are also executed in one LUW. When all V1 update
requests have been successfully concluded, the V2 update
requests ("update with start delayed") are processed, each
in one LUW. Parallel to this, the function modules specified
in CALL FUNCTION ... IN BACKGROUND TASK are each executed in
one LUW per destination.
2. COMMIT WORK commands processed within CALL DIALOG processing
- execute a database commit (see above),
- close all open database cursors,
- reset the time slice counter and
- call the function modules specified by CALL FUNCTION IN
BACKGROUND TASK in the CALL DIALOG processing.
However, subroutines and function modules called with
PERFORM ... ON COMMIT or CALL FUNCTION ... IN UPDATE TASK in
the CALL DIALOG processing are not executed in the calling
transaction until a COMMIT WORK occurs.
3. Since COMMIT WORK closes all open database cursors, any
attempt to continue a SELECT loop after a COMMIT WORK
results in a runtime error. For the same reason, a FETCH
after a COMMIT WORK on the now closed cursors also produces
a runtime error. You must therefore ensure that any open
cursors are no longer used after the COMMIT WORK.
4. With batch input and CALL TRANSACTION ... USING, COMMIT WORK
successfully concludes the processing.
Addition ... AND WAIT
Effect The addition ... AND WAIT makes the program wait until the type
V1 updates have been completed.
The return code value is set as follows:
SY-SUBRC = 0: The update was successfully performed.
SY-SUBRC <> 0: The update could not be successfully performed.
Note Runtime errors:
- COMMIT_IN_PERFORM_ON_COMMIT: COMMIT WORK is not allowed in a
FORM callled with PERFORM ... ON COMMIT.
- COMMIT_IN_POSTING: COMMIT WORK is not allowed in the update
task.
COMMUNICATION
Variants:
1. COMMUNICATION INIT DESTINATION dest ID id.
2. COMMUNICATION ALLOCATE ID id.
3. COMMUNICATION ACCEPT ID id.
4. COMMUNICATION SEND ID id BUFFER f.
5. COMMUNICATION RECEIVE ID id
...BUFFER f
...DATAINFO d
...STATUSINFO s.
6. COMMUNICATION DEALLOCATE ID id.
The COMMUNICATION statement allows you to develop applications
which perform direct program-to-program communication. The
basis for this is CPI-C (Common Programming Interface -
Coummunication), defined by IBM within the context of SAA
standards as a standardized communications interface.
The COMMUNICATION statement provides the essential parameters
for implementing simple communication. Its starter set covers
the following functionality:
Establishing a connection
Accepting a communication
Sending data
Receiving data
Closing a connection
The other essential part of such a communication is an ABAP/4
program containing a FORM routine which is executed when the
connection has been established. This program may be in an R/3
System or an R/2> System.
Here, you should be aware that the application programs
themselves declare a protocol. In particular, logon to the
partner SAP System must be performed in the calling program.
The partner programs must also manage different character sets,
e.g. ASCII - EBCDIC themselves. A facility known as the Remote
Function Call (RFC) has now been developed to save users from
having to deal with these problems.
External programs (e.g. a program written in C on a UNIX
workstation) can also be used as partner programs. For this
purpose, SAP provides a platform-specific development library.
For more detailed information about communication in the SAP
System, you can refer to the manual
SAP Communication: Programming
Further information about communication can be found in any of
the following literature:
IBM SAA
Common Programming Interface
Communication Reference
SC 26-4399
X/Open Developers' Specification CPI-C
X/Open Company Ltd.
ISBN 1 872630 02 2
Variant 1 COMMUNICATION INIT DESTINATION dest ID id.
Addition:
... RETURNCODE rc
Effect Initializes a program-to-program connection.
The partner system is specified in the dest field. You can use
any name you like, but it must be entered in the connection
table TXCOM and can be no more than 8 characters long. This
entry in TXCOM determines to which physical system a connection
is established using the symbolic name of the target system.
In the field id, the system assigns an eight-character ID
number of type C to the connection. The system field SY-SUBRC
contains an appropriate return code value.
All return codes can be read using their symbolic names. For
this purpose, you can use the program RSCPICDF which contains
these names and can be included, if required.
Addition ... RETURNCODE rc
Effect Stores the return code in the field rc.
Example
TYPES: CONVERSATION_ID(8) TYPE C,
DESTINATION(8) TYPE C,
RETURN_CODE LIKE SY-SUBRC.
DATA: CONVID TYPE CONVERSATION_ID,
DEST TYPE DESTINATION VALUE 'C00',
CPIC_RC TYPE RETURN_CODE.
INCLUDE RSCPICDF.
COMMUNICATION INIT DESTINATION DEST
ID CONVID
RETURNCODE CPIC_RC.
IF CPIC_RC NE CM_OK.
WRITE: /'COMMUNICATION INIT, RC = ', CPIC_RC.
EXIT.
ENDIF.
Variant 2 COMMUNICATION ALLOCATE ID id.
Addition:
As for variant 1.
Effect Sets up a program-to-program connection. The call must
immediately follow COMMUNICATION INIT.
Example
TYPES: CONVERSATION_ID(8) TYPE C,
DESTINATION(8) TYPE C,
RETURN_CODE LIKE SY-SUBRC.
DATA: CONVID TYPE CONVERSATION_ID,
DEST TYPE DESTINATION VALUE 'C00',
CPIC_RC TYPE RETURN_CODE.
INCLUDE RSCPICDF.
COMMUNICATION INIT DESTINATION DEST
ID CONVID
RETURNCODE CPIC_RC.
IF CPIC_RC NE CM_OK.
WRITE: /'COMMUNICATION INIT, RC = ', CPIC_RC.
EXIT.
ENDIF.
COMMUNICATION ALLOCATE ID CONVID RETURNCODE CPIC_RC.
IF CPIC_RC NE CM_OK.
WRITE: /'COMMUNICATION ALLOCATE, RC = ', CPIC_RC.
EXIT.
ENDIF.
Variant 3 COMMUNICATION ACCEPT ID id.
Addition:
As for variant 1.
Effect Accepts a connection requested by the partner program. id is a
field of type C which is 8 characters long and contains the ID
of the accepted connection after a successful call.
Example
FORM CPIC_EXAMPLE.
TYPES: CONVERSATION_ID(8) TYPE C,
RETURN_CODE LIKE SY-SUBRC.
DATA: CONVID TYPE CONVERSATION_ID,
CPIC_RC TYPE RETURN_CODE.
INCLUDE RSCPICDF.
COMMUNICATION ACCEPT ID CONVID
RETURNCODE CPIC_RC.
IF CPIC_RC NE CM_OK.
EXIT.
ENDIF.
ENDFORM.
Variant 4 COMMUNICATION SEND ID id BUFFER f.
Additions:
1. ... RETURNCODE rc
2. ... LENGTH len
Effect Sends data to the partner program. The data is stored in the
field f which follows the key word parameter BUFFER. It is sent
in the full length of the field f. If the partner program is
part of a system which has a different character set, you must
perform an appropriate conversion yourself. To do this, use the
TRANSLATE statement.
Addition 1 ... RETURNCODE rc
Effect Stores the return code in the field rc.
Addition 2 ... LENGTH leng
Effect Sends the contents of the field f to the partner program in the
specified length.
Example
TYPES: CONVERSATION_ID(8) TYPE C,
DESTINATION(8) TYPE C,
RETURN_CODE LIKE SY-SUBRC.
DATA: CONVID TYPE CONVERSATION_ID,
DEST TYPE DESTINATION VALUE 'C00',
CPIC_RC TYPE RETURN_CODE.
INCLUDE RSCPICDF.
COMMUNICATION INIT DESTINATION DEST
ID CONVID
RETURNCODE CPIC_RC.
IF CPIC_RC NE CM_OK.
WRITE: /'COMMUNICATION INIT, RC = ', CPIC_RC.
EXIT.
ENDIF.
COMMUNICATION ALLOCATE ID CONVID
RETURNCODE CPIC_RC.
IF CPIC_RC NE CM_OK.
WRITE: /'COMMUNICATION ALLOCATE, RC = ', CPIC_RC.
EXIT.
ENDIF.
RECORD = 'The quick brown fox jumps over the lazy dog'.
COMMUNICATION SEND ID CONVID
BUFFER RECORD
LENGTH LENG
RETURNCODE CPIC_RC.
IF CPIC_RC NE CM_OK.
WRITE: / 'COMMUNICATION SEND, RC = ', CPIC_RC.
EXIT.
ENDIF.
Since the length is specified explicitly in this example, only
the part 'The quick brown fox ' is transferred from the
contents of the field RECORD.
Variant 5 COMMUNICATION RECEIVE ID id ...BUFFER f ...DATAINFO d
...STATUSINFO s.
Parts marked with " ..." are interchangeable
Additions:
1. ... RETURNCODE rc
2. ... LENGTH leng
3. ... RECEIVED m
4. ... HOLD
Effect Receives data in the field f. If no length is explicitly
defined, the amount of data accepted depends on the length of
the field. The fields d and s contain information about the
receive process. You can address the contents of these using
symbolic names in the include program RSCPICDF. The field d
indicates whether the data was received in its entirety. The
status field s informs the RECEIVE user of the status of the
program. Here, it is important to know whether the program is
in receive status or send status. It is, for example, not
possible to send data if the program is in receive status.
For more detailed information about these protocol questions,
refer to the manuals listed above.
Addition 1 ... RETURNCODE rc
Effect Stores the return code in the field rc.
Addition 2 ... LENGTH leng
Effect Receives data only in the specified length leng.
Addition 3 ... RECEIVED m
Effect After the call, m contains the number of bytes received by the
partner program.
Addition 4 ... HOLD
Effect Normally, data is received asynchronously, i.e. the system
performs a rollout. However, this may not be desirable if, for
example, the data is received in a SELECT loop, the database
cursor is lost due to the rollout and the loop is terminated.
To prevent a rollout, you can use the addition HOLD. Then, the
SAP process waits until the data has been received and is thus
available for use by other users.
Note The fields d, s and m which contain information about the
outcome of the call must be of type X with length 4.
Example
FORM CPIC_EXAMPLE.
TYPES: CONVERSATION_ID(8) TYPE C,
RETURN_CODE LIKE SY-SUBRC,
C_INFO(4) TYPE X.
DATA: CONVID TYPE CONVERSATION_ID,
CPIC_RC TYPE RETURN_CODE,
RECORD(80) TYPE C,
DINFO TYPE C_INFO,
SINFO TYPE C_INFO.
INCLUDE RSCPICDF.
COMMUNICATION ACCEPT ID CONVID
RETURNCODE CPIC_RC.
IF CPIC_RC NE CM_OK.
EXIT.
ENDIF.
COMMUNICATION RECEIVE ID CONVID
BUFFER RECORD
STATUSINFO SINFO
DATAINFO DINFO
RETURNCODE CPIC_RC.
IF CPIC_RC NE CM_OK.
EXIT.
ENDIF.
ENDFORM.
Variant 6 COMMUNICATION DEALLOCATE ID id.
Addition:
As for variant 1
Effect Severs connection and releases all resources.
Example
TYPES: CONVERSATION_ID(8) TYPE C,
DESTINATION(8) TYPE C,
RETURN_CODE LIKE SY-SUBRC,
C_INFO(4) TYPE X.
DATA: CONVID TYPE CONVERSATION_ID,
CPIC_RC TYPE RETURN_CODE,
DEST TYPE DESTINATION VALUE 'C00'.
DATA: RECORD(80) TYPE C,
LENG TYPE I VALUE 20.
INCLUDE RSCPICDF.
COMMUNICATION INIT DESTINATION DEST
ID CONVID
RETURNCODE CPIC_RC.
IF CPIC_RC NE CM_OK.
WRITE: / 'COMMUNICATION INIT, RC = ', CPIC_RC.
EXIT.
ENDIF.
COMMUNICATION ALLOCATE ID CONVID
RETURNCODE CPIC_RC.
IF CPIC_RC NE CM_OK.
WRITE: / 'COMMUNICATION ALLOCATE, RC = ', CPIC_RC.
EXIT.
ENDIF.
RECORD = 'The quick brown fox jumps over the lazy dog'.
COMMUNICATION SEND ID CONVID
BUFFER RECORD
LENGTH LENG
RETURNCODE CPIC_RC.
IF CPIC_RC NE CM_OK.
WRITE: / 'COMMUNICATION SEND, RC = ', CPIC_RC.
EXIT.
ENDIF.
COMMUNICATION DEALLOCATE ID CONVID
RETURNCODE CPIC_RC.
IF CPIC_RC NE CM_OK.
WRITE: / 'COMMUNICATION DEALLOCATE, RC = ', CPIC_RC.
EXIT.
ENDIF.
Note The above examples illustrate the basic functionality of the
key words. However, the example program can only have an
external system as partner. If the partner is an SAP System,
the calling program must first logon to the SAP System and
receive an acknowledgement. Only then can you begin to transmit
the actual data. When logging on to an R2 System and an R3
System, the logon data must be converted to EBCDIC. All user
data should be converted according to the partner system. This
is in the concluding example of an R/3 - R/2 connection.
Example
PROGRAM ZCPICTST.
TYPES: CONVERSATION_ID(8) TYPE C,
DESTINATION(8) TYPE C,
RETURN_CODE LIKE SY-SUBRC,
C_INFO(4) TYPE X.
DATA: BEGIN OF CONNECT_STRING,
REQID(4) VALUE 'CONN',
TYPE(4) VALUE 'CPIC',
MODE(4) VALUE '1 ',
MANDT(3) VALUE '000',
NAME(12) VALUE 'CPICUSER',
PASSW(8) VALUE 'CPIC',
LANGU(1) VALUE 'D',
KORRV(1),
REPORT(8) VALUE 'ZCPICTST',
FORM(30) VALUE 'CPIC_EXAMPLE',
END OF CONNECT_STRING.
DATA: CONVID TYPE CONVERSATION_ID,
DEST TYPE DESTINATION VALUE 'R2-SYST',
CPIC_RC TYPE RETURN_CODE,
DINFO TYPE C_INFO,
SINFO TYPE C_INFO.
DATA: RECORD(80) TYPE C,
LENG TYPE I VALUE 20.
INCLUDE RSCPICDF.
COMMUNICATION INIT DESTINATION DEST
ID CONVID
RETURNCODE CPIC_RC.
IF CPIC_RC NE CM_OK.
WRITE: / 'COMMUNICATION INIT, RC = ', CPIC_RC.
EXIT.
ENDIF.
COMMUNICATION ALLOCATE ID CONVID
RETURNCODE CPIC_RC.
IF CPIC_RC NE CM_OK.
WRITE: / 'COMMUNICATION ALLOCATE, RC = ', CPIC_RC.
EXIT.
ENDIF.
Convert logon data to EBCDIC
TRANSLATE CONNECT_STRING TO CODE PAGE '0100'.
COMMUNICATION SEND ID CONVID BUFFER CONNECT_STRING.
IF CPIC_RC NE CM_OK.
WRITE: / 'COMMUNICATION ALLOCATE, RC = ', CPIC_RC.
EXIT.
ENDIF.
Receive acknowledgement of logon
COMMUNICATION RECEIVE ID CONVID
BUFFER RECORD
DATAINFO DINFO
STATUSINFO SINFO
RETURNCODE CPIC_RC.
IF CPIC_RC NE CM_OK.
WRITE: / 'COMMUNICATION RECEIVE, RC = ', CPIC_RC.
EXIT.
ENDIF.
Convert acknowledgement to ASCII
TRANSLATE RECORD FROM CODE PAGE '0100'.
Now begin user-specific data exchange
RECORD = 'The quick brown fox jumps over the lazy dog'.
Depending on the partner system, convert to another
character set
TRANSLATE RECORD TO CODE PAGE '0100'.
COMMUNICATION SEND ID CONVID
BUFFER RECORD
LENGTH LENG
RETURNCODE CPIC_RC.
IF CPIC_RC NE CM_OK.
WRITE: / 'COMMUNICATION SEND, RC = ', CPIC_RC.
EXIT.
ENDIF.
COMMUNICATION DEALLOCATE ID CONVID
RETURNCODE CPIC_RC.
IF CPIC_RC NE CM_OK.
WRITE: / 'COMMUNICATION DEALLOCATE, RC = ', CPIC_RC.
EXIT.
ENDIF.
PROGRAM ZCPICTST.
INCLUDE RSCPICDF.
The receiving procedure in the relevant partner program
follows
FORM CPIC_EXAMPLE.
TYPES: CONVERSATION_ID(8) TYPE C,
RETURN_CODE LIKE SY-SUBRC,
C_INFO(4) TYPE X.
DATA: CONVID TYPE CONVERSATION_ID,
CPIC_RC TYPE RETURN_CODE,
RECORD(80) TYPE C,
DINFO TYPE C_INFO,
SINFO TYPE C_INFO.
COMMUNICATION ACCEPT ID CONVID
RETURNCODE CPIC_RC.
IF CPIC_RC NE CM_OK.
EXIT.
ENDIF.
COMMUNICATION RECEIVE ID CONVID
BUFFER RECORD
STATUSINFO SINFO
DATAINFO DINFO
RETURNCODE CPIC_RC.
IF CPIC_RC NE CM_OK AND CPIC_RC NE CM_DEALLOCATED_NORMAL.
EXIT.
ENDIF.
ENDFORM.
COMPONENT-CHECK
Variations:
1. COMPONENT-CHECK NUMBER n.
2. COMPONENT-CHECK TRANSACTION tcod.
3. COMPONENT-CHECK PROGRAM prog.
Effect Determines whether a particular SAP price list component is
installed.
Variation 1 COMPONENT-CHECK NUMBER n.
Effect Determines whether the SAP price list component n is installed.
The return code in the system field SY-SUBRC may be set to
either of the following values:
0 SAP price list component active.
4 SAP price list component not active.
Variation 2 COMPONENT-CHECK TRANSACTION tcod.
Effect Determines whether the SAP price list component for Transaction
tcod is installed. The return code in the system field SY-SUBRC
may be set to any of the following values:
0 SAP price list component active.
4 SAP price list component not active.
8 Transaction tcod does not belong to any SAP
price list component (i.e. no entry in Table
DIR).
Variation 3 COMPONENT-CHECK PROGRAM prog.
Effect Determines whether the SAP price list component for the program
prog is installed. The return code in the system field SY-SUBRC
may be set to any of the following values:
0 SAP price list component active.
4 SAP price list component not active.
8 Program p does not belong to any SAP price list
component (i.e. no entry in Table DIR).
COMPUTE
Basic form COMPUTE n = arithexp.
Effect Evaluates the arithmetic expression arithexp and places the
result in the field n.
Allows use of the four basic calculation types +, -, * and /,
the whole number division operators DIV (quotient) and MOD
(remainder), the exponentiation operator ** (exponentiation "X
Y means X to the power of Y) as well as the functions listed
below.
When evaluating mixed expressions, functions have priority.
Then comes exponentiation, followoed by the "point operations"
*, /, DIV and MOD, and finally + and - . Any combination of
parentheses is also allowed.
The fields involved are usually of type I, F or P, but there
are exceptions to this rule (see below).
You can omit the key word COMPUTE.
Built-in functions
- Functions for all number types
ABS Amount (absolute value) |x| of x
SIGN Sign (preceding sign) of x;
1 x > 0
SIGN( x ) = 0 if x = 0
-1 x < 0
CEIL Smallest whole number value not less than x
FLOOR Greatest whole number value not greater than x
TRUNC Whole number part of x
FRAC Decimal part of x
- Floating point functions
ACOS Arc cosine(x) in the range [-pi/2, pi/2], x from
[-1, 1]
ASIN Arc cosine(x) in the range [0, pi], x aus [-1,
1]
ATAN Arc tangent(x) in the range [-pi/2, pi/2] (pi =
3.1415926535897932)
COS Cosine of an angle specified in the arc
SIN Sine of an angle specified in the arc
TAN Tangent of an angle specified in the arc
COSH Hyperbola cosine
SINH Hyperbola sine
TANH Hyperbola tangent
EXP Exponential function for base e =
2.7182818284590452
LOG Natural logarithm (i.e. base e) of a positive
number
LOG10 Logarithm of x for base 10, x > 0
SQRT Square root of a non-negative number
- String functions
STRLEN Length of a string up to the last non-blank
character (i.e. the occupied length)
Function expressions consist of three parts:
1. Function identifier directly followed by an opening
parenthesis
2. Argument
3. Closing parenthesis
All parts of an expression, particularly any parts of a
function expression, must be separated from each other by at
least one blank.
Example The following statements, especially the arithmetic
expressions, are syntactically correct:
DATA: I1 TYPE I, I2 TYPE I, I3 TYPE I,
F1 TYPE F, F2 TYPE F,
WORD1(10), WORD2(20).
...
F1 = ( I1 + EXP( F2 ) ) * I2 / SIN( 3 - I3 ).
COMPUTE F1 = SQRT( SQRT( ( I1 + I2 ) * I3 ) + F2 ).
I1 = STRLEN( WORD1 ) + STRLEN( WORD2 ).
Notes 1. When used in calculations, the amount of CPU time needed
depends on the data type. In very simple terms, type I is
the cheapest, type F needs longer and type P is the most
expensive.
Normally, packed numbers arithmetic is used to evaluate
arithmetic expressions. If, however, the expression contains
a floating point function, or there is at least one type F
operand, or the result field is type F, floating point
arithmetic is used instead for the entire expression. On the
other hand, if only type I fields or date and time fields
occur (see below), the calculation involves integer
operations.
2. You can also perform calculations on numeric fields other
than type I, F or P. Before executing calculations, the
necessary type conversions are performed (see MOVE). You
can, for instance, subtract one date field (type D) from
another, in order to calculate the number of days
difference. However, for reasons of efficiency, only
operands of the same number type should be used in one
arithmetic expression (apart from the operands of STRLEN).
This means that no conversion is necessary and special
optimization procedures can be performed.
3. Division by 0 results in termination unless the dividend is
also 0 (0 / 0). In this case, the result is 0.
4. As a string processing command, the STRLEN operator treats
operands (regardless of type) as character strings, without
triggering internal conversions. On the other hand, the
operands of floating point functions are converted to type F
if they have another type.
Example Date and time arithmetic
DATA: DAYS TYPE I,
DATE_FROM TYPE D VALUE '19911224',
DATE_TO TYPE D VALUE '19920101',
DAYS = DATE_TO - DATE_FROM.
DAYS now contains the value 8.
DATA: SECONDS TYPE I,
TIME_FROM TYPE T VALUE '200000',
TIME_TO TYPE T VALUE '020000'.
SECONDS = ( TIME_TO - TIME_FROM ) MOD 86400.
SECONDS now contains the value 21600 (i.e. 6 hours). The
operation "MOD 86400" ensures that the result is always a
positive number, even if the period extends beyond midnight.
Note Packed numbers arithmetic:
All P fields are treated as whole numbers. Calculations
involving decimal places require additional programming to
include multiplication or division by 10, 100, ... . The
DECIMALS specification with the DATA declaration is effective
only for output with WRITE.
If, however, fixed point arithmetic is active, the DECIMALS
specification is also taken into account. In this case,
intermediate results are calculated with maximum accuracy (31
decimal places). This applies particularly to division.
For this reason, you should always set the program attribute
"Fixed point arithmetic".
Example
DATA P TYPE P.
P = 1 / 3 * 3.
Without "fixed point arithmetic", P has the value 0, since "1 /
3" is rounded down to 0.
With fixed point arithmetic, P has the value 1, since the
intermediate result of "1 / 3" is
0.333333333333333333333333333333.
Note Floating point arithmetic
With floating point arithmetic, you must always expect some
loss of accuracy through rounding errors (ABAP/4 number types).
Note Exponentiation
The exponential expression "x*y" means xx...x y times,
provided that y is a natural number. For any value of y, x**y
is explained by exp(y*log(x)).
Operators of the same ranke are evaluated from left to right.
Only the exponential operator, as is usual in mathematics, is
evaluated from right to left. The expression "4 ** 3 ** 2" thus
corresponds to "4 ** ( 3 ** 2 )" and not "( 4 ** 3 ) ** 2", so
the result is 262144 and not 4096.
The following resrtictions apply for the expression "X ** Y":
If X is equal to 0, Y must be positive. If X is negative, Y
must be a whole number.
Note DIV and MOD
The whole number division operators DIV and MOD are defined as
follows:
- ndiv = n1 DIV n2
- nmod = n1 MOD n2
so that:
1. n1 = ndiv * n2 + nmod
2. ndiv is a whole number
3. 0 <= nmod < |n2|
A runtime error occurs if n2 is equal to 0 and n1 is not equal
to 0.
Example
DATA: D1 TYPE I, D2 TYPE I, D3 TYPE I, D4 TYPE I,
M1 TYPE P DECIMALS 1, M2 TYPE P DECIMALS 1,
M3 TYPE P DECIMALS 1, M4 TYPE P DECIMALS 1,
PF1 TYPE F VALUE '+7.3',
PF2 TYPE F VALUE '+2.4',
NF1 TYPE F VALUE '-7.3',
NF2 TYPE F VALUE '-2.4',
D1 = PF1 DIV PF2. M1 = PF1 MOD PF2.
D2 = NF1 DIV PF2. M2 = NF1 MOD PF2.
D3 = PF1 DIV NF2. M3 = PF1 MOD NF2.
D4 = NF1 DIV NF2. M4 = NF1 MOD NF2.
The variables now have the following values:
D1 = 3, M1 = 0.1,
D2 = - 4, M2 = 2.3,
D3 = - 3, M3 = 0.1,
D4 = 4, M4 = 2.3.
Example Functions ABS, SIGN, CEIL, FLOOR, TRUNC, FRAC
DATA: I TYPE I,
P TYPE P DECIMALS 2,
M TYPE F VALUE '-3.5',
D TYPE P DECIMALS 1.
P = ABS( M ). " 3,5
I = P. " 4 - commercially rounded
I = M. " -4
I = CEIL( P ). " 4 - next largest whole number
I = CEIL( M ). " -3
I = FLOOR( P ). " 3 - next smallest whole number
I = FLOOR( M ). " -4
I = TRUNC( P ). " 3 - whole number part
I = TRUNC( M ). " -3
D = FRAC( P ). " 0,5 - decimal part
D = FRAC( M ). " -0,5
Notes Floating point functions
1. Although the functions SIN, COS and TAN are defined for any
numbers, the results are imprecise if the argument is
greater than about 1E8, i.e. 10**8.
2. The logarithm for a base other than e or 10 is calculated as
follows:
Logarithm of b for base a = LOG( b ) / LOG( a )
Note Runtime errors:
Depending on the operands, the above operators and functions
can cause runtime errors (e.g. when evaluating the logarithm
with a negative argument).
Related ADD, SUBTRACT, MULTIPLY, DIVIDE, MOVE
CONCATENATE
Basic form CONCATENATE f1 ... fn INTO g.
Addition:
... SEPARATED BY h
Note As with any string processing statement, all the operands are
processed here as type C fields (regardless of tyep). No
internal conversion is performed.
Effect Places the fields f1 to fn after g.
With the fields fi (1 <= i <= n), trailing blanks are ignored,
i.e. these fields are considered only to have the length
STRLEN( fi).
The return code value is set as follows:
SY-SUBRC = 0: The result fits in g.
SY-SUBRC = 4: The result was too long for g and was only
copied to g in that length.
Example
DATA: ONE(10) VALUE 'John',
TWO(3) VALUE ' F.',
THREE(10) VALUE ' Kennedy',
NAME(20).
CONCATENATE ONE TWO THREE INTO NAME.
Then, NAME contains the value "John F. Kennedy".
Addition ... SEPARATED BY h
Effect Inserts the separator h between the fields fi.
Here, h is used in its defined length.
Examples
DATA: ONE(10) VALUE 'John',
TWO(3) VALUE 'F.',
THREE(10) VALUE 'Kennedy',
NAME(20).
CONCATENATE ONE TWO THREE INTO NAME SEPARATED BY SPACE.
Then, NAME has the value "John F. Kennedy".
DATA SEPARATOR(4) VALUE 'USA'.
CONCATENATE SPACE ONE TWO THREE INTO NAME
SEPARATED BY SEPARATOR.
Then, NAME has the value "USA JohnUSA F.USA Ke".
The return value of SY-SUBRC is set to 4.
Related SPLIT, SHIFT, REPLACE, TRANSLATE, CONDENSE
Note Performance:
You are recommended to use the key word CONCATENATE rather than
your own constructions because it is safer, more efficient and
clearer. The runtime required to append two 30-byte fields
amounts to approx. 14 msn (standardized microseconds).
CONDENSE
Basic form CONDENSE c.
Addition:
... NO-GAPS
Note As with any string processing statement, all the operands are
processed here as type C fields (regardless of tyep). No
internal conversion is performed.
Effect Shifts the contents of the field c to the left, so that each
word is separated by exactly one blank.
Example
DATA: BEGIN OF NAME,
TITLE(8), VALUE 'Dr.',
FIRST_NAME(10), VALUE 'Michael',
SURNAME(10), VALUE 'Hofmann',
END OF NAME.
CONDENSE NAME.
WRITE NAME.
produces the output:
Dr. Michael Hofmann
Addition ... NO-GAPS
Effect Suppresses all blanks from the field c
Example
DATA: BEGIN OF NAME,
TITLE(8), VALUE 'Dr.',
FIRST_NAME(10), VALUE 'Michael',
SURNAME(10), VALUE 'Hofmann',
END OF NAME.
CONDENSE NAME NO-GAPS.
The contents of NAME is now "Dr.MichaelHofmann".
Since the field string NAME is interpreted and handled like a
type C field, the CONDENSE statement treats it as a whole and
ignores any sub-fields. The contents of the component field
would therefore now be as follows:
NAME-TITLE = 'Dr.Micha'
NAME-FIRST_NAME = 'elHofmann '
NAME-SURNAME = ' '
Note Do not use CONDENSE to manipulate field strings that include
fields not of type C. This could result in these component
fields containing characters of a different (i.e. incorrect)
type.
Related SHIFT, CONCATENATE, REPLACE, SPLIT
Note Performance:
The runtime required to condense three fields is about 20 msn
(standardized micooseconds). The variant ... NO-GAPS needs
about 12 msn.
CONSTANTS
Variants:
1. CONSTANTS c. ... VALUE [ val | IS INITIAL ].
2. CONSTANTS c(len) ... VALUE [ val | IS INITIAL ].
3. CONSTANTS: BEGIN OF crec,
...
END OF crec.
Effect The CONSTANTS statement defines global and local constants.
Constants allow you to read statically declared data objects.
They always have a particular data type. Data types and data
objects are essential components of the ABAP/4 type concept.
In contrast to variables defined with the DATA statement, you
cannot change the value of a constant once it has been defined.
Apart from the additions ... TYPE typ OCCURS n, ... LIKE
f1OCCURS n and WITH HEADER LINE, all the additions used with
the DATA statement are allowed. However, in contrast to the
DATA statement, the addition ... VALUE val or VALUE IS INITIAL
obligatory with variants 1 and 2. See additions with DATA.
Example
CONSTANTS CHAR1 VALUE 'X'.
CONSTANTS INT TYPE I VALUE 99.
CONSTANTS: BEGIN OF CONST_REC,
C(2) TYPE I VALUE 'XX',
N(2) TYPE N VALUE '12',
X TYPE X VALUE 'FF',
I TYPE I VALUE 99,
P TYPE P VALUE 99,
F TYPE F VALUE '9.99E9',
D TYPE D VALUE '19950101',
T TYPE T VALUE '235959',
END OF CONST_REC.
CONTINUE
Basic form CONTINUE.
Effect Within loop structures like
- DO ... ENDDO
- WHILE ... ENDWHILE
- LOOP ... ENDLOOP
- SELECT ... ENDSELECT
CONTINUE terminates the current loop pass, returns the
processing to the beginning of the loop and starts the next
loop pass, if there is one.
Example DO loop: Omit an area (10 ... 20)
DO 100 TIMES.
IF SY-INDEX >= 10 AND SY-INDEX <= 20.
CONTINUE.
ENDIF.
...
ENDDO.
Related CHECK, EXIT
CONTROLS
Basic form CONTROLS ctrl TYPE ctrl_type.
Effect Defines a control
A control defines an ABAP/4 runtime object which displays data
in a particular visual format, depending on the type. It offers
the user standard processing options.
At present, the following types of control are supported:
Table control
Related REFRESH CONTROL
ABAP/4 table control
Basic form CONTROLS ctrl TYPE TABLEVIEW USING SCREEN scr.
Effect Creates a table control ctrl of the type TABLEVIEW. The
reference screen for the initialization is the screen scr.
Area of use
The table control (referred to here as TC ) facilitates the
display and entry of one-line, tabular data in dialog
transactions.
The functional scope has been defined so that you can implement
many typical set operations usually handled by an elementary
STEP-LOOP with the standard methods of a TC.
Functional scope
- Resizeable table grid for displaying and editing data.
- Column width and column position modifiable by user and by
program.
- Storing and loading of user-specific column layout.
- Selection column for line selection with color selection
display.
- Variable column headers as pushbuttons for column selection.
- Simple selection, multiple selection, Select/deselect all.
- Scrolling functions (horizontal and vertical) via scroll
bar.
- Fixing of any number of key columns.
- Setting attributes for each cell at runtime.
Programming
The data exchange between the application and the SAPgui is
achieved with a STEP-LOOP, i.e. an ABAP/4 module is called to
transfer data for each page.
Example Processing without an internal table
PROCESS BEFORE OUTPUT.
LOOP WITH CONTROL ctrl.
MODULE ctrl_pbo.
ENDLOOP.
PROCESS AFTER INPUT.
LOOP WITH CONTROL ctrl.
MODULE ctrl_pai.
ENDLOOP.
In this case, the module ctrl_pbo OUTPUT is called once for
each output line before the screen is displayed, in order to
fill the output fields.
After the user has entered data on the screen, the module
ctrl_pai INPUT is executed to check the input and copy the new
contents.
Example Processing with an internal table
PROCESS BEFORE OUTPUT.
LOOP AT itab WITH CONTROL ctrl CURSOR ctrl-CURRENT_LINE.
ENDLOOP.
PROCESS AFTER INPUT.
LOOP AT itab WITH CONTROL ctrl.
MODULE ctrl_pai.
ENDLOOP.
Here, the system fills the output fields before displaying the
screen by reading the internal table itab.
When the user has entered data, the module ctrl_pai INPUT must
be executed to check the input and to refresh the contents of
the internal table.
Vertical scrolling with the scroll bar is followed by the event
PAI for the displayed page. Then, cntl-TOP_LINE is increased
and PBO is processed for the next page.
Program-driven scrolling and the most of the functionality
described above is achieved by manipulating the control
attributes.
Attributes
The CONTROLS statement creates a complex data object of the
type CXTAB_CONTROL with the name of the control.
You maintain the initial values in the Screen Painter and
assign the screen with the initial values for a control using
the addition USING SCREEN.
Initialization is achieved automatically in the "1st access to
the control" (setting or reading values).
You can use the customizing button (in the top right corner) to
save the current setting (column widths and column positions)
and use it as the initial value for the next call.
All the initial values can be overwritten by the program using
the MOVE ... TO TC attributes statement.
Example ctrl-fixed_cols = 2. "2 columns fixed
The contents of the SCREEN structure (table Cols) acts as a
default value for each line of this column, but within LOOP ...
ENDLOOP (flow logic), it can be overwritten by LOOP AT SCREEN /
MODIFY SCREEN.
With the attributes listed below, you should be aware of the
following:
LINES This must always be set as the only attribute if
you are not using LOOP AT itab.
TOP_LINE Also set by the SAPgui through the vertical
scroll bar slider.
CURRENT_LINE Read only, set by the system (TOP_LINE +
SY-STEPL - 1)
LEFT_COL Also set by the SAPgui through the horizontal
scroll bar slider.
COLS-INDEX Also set by the SAPgui after moving columns.
COLS-SELECTED Also set by the SAPgui after column selection.
When displaying the control, the system uses the current
contents when the event DCO occurs (i.e. after all PBO modules
have run). The modified values (brought about by the user
making changes on the screen) are set immediately after DCI
(i.e. before the first PAI module runs).
CONVERT
Variants:
1. CONVERT DATE f1 INTO INVERTED-DATE f2.
2. CONVERT INVERTED-DATE f1 INTO DATE f2.
Effect Allows conversion between different formats which do not have
their own type (see also MOVE).
The field f1 is converted from the source format to the target
format and placed in f2.
At present, the following formats are supported:
1. DATE ==> INVERTED-DATE
2. INVERTED-DATE ==> DATE
Both formats form the nine's complement of internal date
representation, e.g. 19950511 ==> 80049488 or 80049488 ==>
19950511. In inverse date format, the most recent date has the
lowest numerical value. This is useful when sorting date
specifications.
Note The technique of modifying the sequence of dates by inverting
the internal date format is only used in very rare cases. For
example, you can sort internal tables in ascending or
descending date order much more elegantly with the additons ...
ASCENDING bzw. ... DESCENDING of the SORT statement.
Example
DATA DATE_INV LIKE SY-DATUM.
CONVERT DATE SY-DATUM INTO INVERTED-DATE DATE_INV.
If, for example, the internal representation of 11.05.95 in
SY-DATUM is 19950511, the value of DATE_INV after execution of
the CONVERT statement is 80049488.
Note Runtime errors:
- CONVERT_ILLEGAL_CONVERSION: Conversion not possible due to
incorrect field length.
CREATE
Basic form CREATE OBJECT obj class.
Addition:
... LANGUAGE langu
Effect Generates an object of the class class.
To address an OLE automation server (e.g. EXCEL) from ABAP/4,
the server must be registered with SAP. The transaction SOLE
allows you to assign an automation server to a class.
The CREATE statement generates the initial object and this can
be processed further with the relevant key words.
The return code value of SY-SUBRC indicates the result of the
generation:
The return code value is set as follows:
SY-SUBRC = 0: Object successfully generated.
SY-SUBRC = 1: SAPGUI communication error.
SY-SUBRC = 2: SAPGUI function call error. The OLE function
modules are implemented only under Windows.
SY-SUBRC = 3: The OLE API call resulted in an error; this is
possibly a storage space problem.
SY-SUBRC = 4: The object is not registered with SAP.
Addition ... LANGUAGE langu
Effect Determines the language chosen for method and attribute names
of the object class.
If no specification is made, English is the default.
CREATE OBJECT belongs to a group of key words which allow you
to process external objects with ABAP/4. At present, only the
object model OLE2 is supported, i.e. all objects must be of
type OLE2_OBJECT. This type and other necessary data are
defined in the include program OLE2INCL.
Example Generate an EXCEL object.
INCLUDE OLE2INCL.
DATA EXCEL TYPE OLE2_OBJECT.
CREATE OBJECT EXCEL 'Excel.Application'.
Related SET PROPERTY
GET PROPERTY
CALL METHOD
FREE OBJECT
This statement is not supported in the R/3 System. Use the
following function modules instead:
CONVERT_TO_FOREIGN_CURRENCY
CONVERT_TO_LOCAL_CURRENCY
DATA
Variants:
1.DATA f.
2.DATA f(len).
3.DATA: BEGIN OF rec,
...
END OF rec.
4. DATA: BEGIN OF itab OCCURS n,
...
END OF itab.
5. DATA: BEGIN OF COMMON PART c,
...
END OF COMMON PART.
Effect Defines global and local variables. Variables allow you to
address declared data objects. They always have a particular
data type. Data types and data objects are important components
of the ABAP/4 type concept.
Variant 1 DATA f.
Additions:
1. ... TYPE typ
2. ... LIKE f1
3. ... TYPE typ OCCURS n
4. ... LIKE f1 OCCURS n
5. ... TYPE LINE OF itabtyp
6. ... LIKE LINE OF itab
7. ... VALUE lit
8. ... DECIMALS n
9. ... WITH HEADER LINE
Effect Creates the internal field f in its standard length. If you do
not specify the type (using the addition TYPE), a field of type
C is assumed.
The field f can be up to 30 characters long. You can use any
characters you like except the special characters '(', ')',
'+', '-', ',' and ':'. Numeric characters are allowed but the
field name may not consist of numbers alone.
SPACE is a reserved word and therefore cannot be used. Also,
the field name cannot be the same as one of the additional
parameters of the introductory key word (e.g. PERFORM SUB USING
CHANGING.).
Recommendations for field names:
1. Always use a letter as the first character.
2. Use the underscore to join together words which are part of
the same name (e.g. NEW_PRODUCT). The hyphen should not be
used here, since it is reserved for the names of field
string components (see below).
Addition 1 ... TYPE typ.
Effect Creates a field f of the type typ. You can use either one of
the predefined types listed below or one of your own types
which you define with TYPES.
The standard length (SL) of the field depends on the type.
Type Description SL Initial value
C Text (character) 1 Blank
N Numeric text 1 '00...0'
D Date (YYYYMMDD) 8 '00000000'
T Time (HHMMSS) 6 '000000'
X Hexadecimal 1 X'00'
I Whole number (integer) 4 0
P Packed number 8 0
F Floating point no. 8 '0.0'
Example
DATA NUMBER TYPE I.
Creates the field NUMBER as type I. You can also use it in the
program, particularly if you want to assign number values and
perform calculations.
Notes - The data type I is the whole number type on which the
hardware is based. Its value range is from -2*31 to 2*31-1
(from -2.147.483.648 to 2.147.483.647).
You use type P for fields containing monetary amounts, but
type I is more suitable for number fields, index fields,
specifying positions and so forth.
- You can use type F for positive and negative numbers other
than zero in the range from 1E-307 to 1E+308 with a degree
of accuracy up to 15 decimal places. (The ABAP/4 processor
always uses the floating point operations of the hardware in
question rather than standardizing them.) Floating point
literals must be enclosed in quotation marks. The standard
output length is 22.
Entries in type F fields may be formatted in any of the
following ways:
As a decimal number with or without sign and with or without
a decimal point.
In the form <mantissa>e<exponent>, where you specify the
mantissa as above and the exponent with or without a sign.
(Examples of floating point literals: '1', '-12.34567',
'-765E-04', '1234E5', '12E34', '+12.3E-4'.
Since floating point arithmetic is fast on our hardware
platforms, you should use it when you need a greater value
range and you are able to tolerate rounding errors. Rounding
errors may occur when converting the external (decimal)
format to the corresponding internal format (base 2 or 16)
or vice-versa (ABAP/4 number types).
Addition 2 ... LIKE f1
Effect Creates the field f with the same field attributes as the field
F1 which is already known. Any data objects are valid (fields,
parameters, structures, ...) as long as types have been
assigned.
f1 can be any Dictionary reference.
Example
DATA TABLE_INDEX LIKE SY-TABIX.
The field TABLE_INDEX now has the same attributes as SY-TABIX
(the index for internal tables).
Note This addition is often useful, since the ABAP/4 runtime system
performs type changes on fields automatically. Any unnecessary
and/or unwanted conversions are thus avoided.
Addition 3 ... TYPE typ OCCURS n
Effect Defines an internal table without header line. Such a table
consists of any number of table lines with the type typ.
To fill and edit this table, you can use statements like
APPEND, READ TABLE, LOOP and SORT.
The OCCURS parameter n defines how many tables lines are
created initially. If necessary, you can increase the size
later. Otherwise, the OCCURS parameter is of no significance,
apart from the exception that applies with APPEND SORTED BY.
Example
TYPES: BEGIN OF LINE_TYPE,
NAME(20) TYPE C,
AGE TYPE I,
END OF LINE_TYPE.
DATA: PERSONS TYPE LINE_TYPE OCCURS 20,
PERSONS_WA TYPE LINE_TYPE.
PERSONS_WA-NAME = 'Michael'.
PERSONS_WA-AGE = 25.
APPEND PERSONS_WA TO PERSONS.
PERSONS_WA-NAME = 'Gabriela'
PERSONS_WA-AGE = 22.
APPEND PERSONS_WA TO PERSONS.
The internal table PERSONS now consists of two table entries.
Note Access to table entries not in main memory takes much longer.
On the other hand, there is not enough space in main memory to
hold such large tables because the roll area is resticted (see
above).
Addition 4 ... LIKE f1 OCCURS n
Effect Defines an internal table without header line. Such a table
consists of any number of table lines with the structure as
specified by the data object f1. Processing is the same as for
addition 3.
Example
DATA: BEGIN OF PERSON,
NAME(20),
AGE TYPE I,
END OF PERSON.
DATA: PERSONS LIKE PERSON OCCURS 20.
PERSON-NAME = 'Michael'.
PERSON-AGE = 25.
APPEND PERSON TO PERSONS.
PERSON-NAME = 'Gabriela'
PERSON-AGE = 22.
APPEND PERSON TO PERSONS.
The internal table PERSONS now consists of two table entries.
Addition 5 ... TYPE LINE OF itabtype
Effect The specified type itabtyp must be an internal table type. This
operation creates a data object with the same line type as the
table type specified.
Example
TYPES TAB_TYP TYPE I OCCURS 10.
DATA TAB_WA TYPE LINE OF TAB_TYP.
The data object TAB_WA now has the same attributes as a line of
the table type TAB_TYP and thus the type I.
Addition 6 ... LIKE LINE OF itab
Effect The data object tab must be an internal table with or without a
header line. This operation creates a data object with the same
line type as the table specified.
Example
DATA TAB TYP TYPE I OCCURS 10.
DATA TAB_WA TYPE LINE OF TAB.
The data object TAB_WA now has the same attributes as a line of
the table TAB and thus the type I.
Addition 7 ... VALUE lit
Effect The initial value of the field f is the literal lit instead of
that defined in the table above. You can also specify a
constant or even use IS INITIAL. In the latter case, the field
is preset to the type-specific initial value. This form is
particularly important in connection with the CONSTANTS
statement which always requires you to use the addition VALUES.
Example
DATA NUMBER TYPE I VALUE 123,
FLAG VALUE 'X',
TABLE_INDEX LIKE SY-TABIX VALUE 45.
When created, the field NUMBER of type I contains 123 rather
than the expected initial value of 0. The newly created field
FLAG of type C (length 1) contains 'X', while TABLE_INDEX
contains 45, since the system field SY-TABIX is a numeric
field.
Addition 8 ... DECIMALS n
Effect Only makes sense with field type P. When you perform
calculations and on output, the field has n decimal decimal
places, where n is a number between 0 and 14.
In the case of newly generated programs, you normally activate
fixed point arithmetic in the attributes. If it is not set, the
DECIMALS specification is taken into account on output, but not
when performing calculations. This means that the programmer
must take care of any decimal point calculations by multiplying
or dividing by powers of ten. (see COMPUTE)
Fixed point arithmetic should always be active when you are
performing calculations, since this enables intermediate
results (for division) to be calculated as accurately as
possible (in this case, to 31 decimal places).
To decide whether you should use the fixed point type P or the
floating point type F, see "ABAP/4 number types".
Addition 9 ... WITH HEADER LINE
Effect You can only use this addition with table types. When you
specify WITH HEADER LINE, you create a header line with the
same name type as a table line in addition to the table. With
non-table operations (e.g. MOVE), the name f refers to this
header line. With table operations (e.g. APPEND,
the name f refers to the table or the table and header line.
The notation f[] always denotes the table. The result of this
expression is a table without a header line and can be used as
such.
Example
DATA: BEGIN OF PERSON_TYPE,
NAME(20),
AGE TYPE I,
END OF PERSON_TYPE.
DATA: PERSONS LIKE PERSON_TYPE OCCURS 20 WITH HEADER LINE.
PERSON-NAME = 'Michael'.
PERSON-AGE = 25.
APPEND PERSONS.
PERSON-NAME = 'Gabriela'
PERSON-AGE = 22.
APPEND PERSONS.
Delete header line
CLEAR PERSONS.
Delete table
CLEAR PERSONS[].
Variant 2 DATA f(len).
Additions:
As for variant 1
Effect Creates the field f in the length len.
You can use this variant only for fields of type C, N, P and X.
Any other field types must have their standard lengths (see
table under effect of variant 1).
The lengths allowed depend on the field type:
Type Allowed lengths
C 1 - 65535
N 1 - 65535
P 1 - 16
X 1 - 65535
Note Each byte can contain (one character or) two decimal or
hexadecimal digits. Since one place in type P fields is
reserved for the sign, a type P field of length 3 can contain 5
digits, whereas a type X field of length 3 can hold 6 digits.
Both have an output length of 6.
Variant 3 DATA: BEGIN OF rec,
...
END OF rec.
Effect Defines the field string rec which groups together all the
fields defined for the field string rec between "BEGIN OF REC"
and "END OF rec". Each field carries the prefix "rec-". Field
strings can be nested to any depth. See Data objects.
When a field string needs the same fields as an already defined
field string in addition to its own fields, you can include
these fields in the field string with INCLUDE STRUCTURE. If no
additional fields are needed, it is better to use LIKE.
Example
DATA: BEGIN OF PERSON,
NAME(20) VALUE 'May',
AGE TYPE I,
END OF PERSON.
PERSON-AGE = 35.
The field PERSON-NAME now contains the contents "May".
DATA: BEGIN OF PERSON1,
FIRSTNAME(20) VALUE 'Michael'.
INCLUDE STRUCTURE PERSON.
DATA END OF PERSON1.
Notes - If you list a field string as a field, this field ("rec") is
type C, but you should not use a field string like a field,
if the field string contains number fields (i.e. type I, F
or F). The length of rec is derived from the sum of the
lengths of all components of rec. However, since some fields
(for example, to the limit of a word), they include padding
fields that also contribute to the overall length of rec;
for this reason, you cannot use the lengths of fields that
occur before a particular field string component to
calculate its offset to the start of the field string. On
the other hand, you can guarantee that two fields with the
same structure always have the same structure (even where
padding fields are concerned). This means that you can
compare and assign fields directly below each other (with
MOVE, IF, etc.) and do not have to work field by field (e.g.
with MOVE-CORRESPONDING).
INCLUDEs are aligned according to maxumum alignment of their
components. This applies both to INCLUDEs in ABAP/4 programs
and also INCLUDEs in Dictionary structures.
- The TABLES statement automatically defines a field string
(the work area. Even the header line belonging to an
internal table (see below) is a field string.
Variant 4 DATA: BEGIN OF itab OCCURS n,
...
END OF itab.
Additions:
... VALID BETWEEN f1 AND f2
Effect Defines the internal table itab.
An internal table includes a header line, which is a field
string containing the fields defined between "BEGIN OF itab
OCCURS n" and "END OF itab" (see variant 3), and any number of
table lines with the same structure as the header line.
To fill and edit an internal table, you use various statements
such as APPEND, READ TABLE, LOOP and SORT.
The OCCURS parameter n determines how many table lines are held
in main storage (the roll area). If you also generate table
entries, these are rolled out either to a main storage buffer
or to disk (the paging area).
Example
DATA: BEGIN OF PERSONS OCCURS 20,
NAME(20),
AGE TYPE I,
END OF PERSONS.
PERSONS-NAME = 'Michael'.
PERSONS-AGE = 25.
APPEND PERSONS.
PERSONS-NAME = 'Gabriela'.
PERSONS-AGE = 22.
APPEND PERSONS.
The internal table now consists of two table entries.
PERSONS also includes the header line (work area) through which
all operations on the actual table pass.
Note Access to table entries not in main storage is considerably
slower. Also, main storage cannot hold large tables in their
entirety, since the size of the roll area is restricted (see
above).
Addition ... VALID BETWEEN f1 AND f2
Effect Can appear only after "END OF itab".
The sub-fields f1 and f2 of the internal table itab must have
the line-related validity range (see PROVIDE).
Variant 5 DATA: BEGIN OF COMMON PART c,
.....
END OF COMMON PART.
Effect Defines one or more common data areas in programs linked by
external PERFORM calls. If only one common data area exists,
you can omit the name c. There may be just one unnamed COMMON
area or one or more named COMMON areas. You assign named COMMON
areas to each other by name. The structure of data areas must
always be the same for both the calling and the called program
(otherwise, the program terminates with an error message at
runtime).
- The table work areas are always in the common data area.
- In general, you define the area created as COMMON with a
common INCLUDE STRUCTURE. Occasionally, you use a INCLUDE
report which contains precisely the definition of the COMMON
PART.
- Field symbols cannot belong to a common data area, even if
the FIELD-SYMBOLS statement lies between DATA BEGIN OF
COMMON PART and DATA END OF COMMON PART.
DEFINE
Basic form DEFINE macro.
Effect Defines a program component (macro) under the name macro. It
must consist only of ABAP/4 statements and is expanded at
compilation time.
A macro should always be concluded with the END-OF-DEFINITION
statement.
In the definition, you can use &n to reference positional
parameters (n = 0 .. 9). When the macro is called, &n is
replaced by the n-th actual parameter.
Example Define a macro called "++" for use in the program.
DEFINE ++.
ADD 1 TO &1.
END-OF-DEFINITION.
DATA: NUMBER TYPE I VALUE 1.
...
++ NUMBER.
Notes - In general, it is better to use subroutines (FORM, FUNCTION)
rather than macros because subroutines - unlike macros - are
supported by all the ABAP/4 Development Workbench tools
(including debugging, runtime analysis, runtime error
handling, ...).
- You cannot nest macro definitions.
DELETE
Delete from a database table
- DELETE FROM dbtab WHERE condition.
DELETE FROM (dbtabname) WHERE condition.
- DELETE dbtab.
DELETE *dbtab.
DELETE (dbtabname) ... .
- DELETE dbtab FROM TABLE itab.
DELETE (dbtabname) FROM TABLE itab.
- DELETE dbtab VERSION vers.
DELETE *dbtab VERSION vers.
Delete from an internal table
- DELETE itab.
- DELETE itab INDEX idx.
- DELETE itab FROM idx1 TO idx2.
- DELETE itab WHERE condition.
- DELETE ADJACENT DUPLICATES FROM itab.
Delete a program
- DELETE REPORT prog.
Delete text elements
- DELETE TEXTPOOL prog LANGUAGE lg.
Delete a data cluster
- DELETE FROM DATABASE dbtab(ar) ...ID key.
Delete a file
- DELETE DATASET dsn.
Delete a screen
- DELETE DYNPRO f.
DELETE - delete a file
Basic form DELETE DATASET dsn.
Effect Deletes the file specified in the field dsn.
The return code value is set as follows:
SY-SUBRC = 0: File deleted.
SY-SUBRC = 4: File does not exist or could not be deleted.
Possible reasons:
1) The file does not exist.
2) The file is a directory.
3) The R/3 System has no search authorization
for a component of the file name.
4) The R/3 System has no search authorization
for the directory which contains the file.
5) A component of the search path is not a
directory.
6) The file is a symbolic link which cannot be
resolved (endless loop ?).
7) The file is a program which is currently
running.
Related OPEN DATASET, READ DATASET, CLOSE.
DELETE - Delete from a database table
Variants:
1. DELETE FROM dbtab WHERE condition.
DELETE FROM (dbtabname) WHERE condition.
2. DELETE dbtab.
DELETE *dbtab.
DELETE (dbtabname) ...
3. DELETE dbtab FROM TABLE itab.
DELETE (dbtabname) FROM TABLE itab.
4. DELETE dbtab VERSION vers.
DELETE *dbtab VERSION vers.
Effect Deletes lines in a database table. You can specify the name of
the database table either in the program itself with DELETE
FROM dbtab ... or at runtime as the contents of the field
dbtabname with DELETE FROM (dbtabname) .... In both cases, the
database table must be known in the ABAP/4 Dictionary. If you
specify the name in the program, there must also be an
appropriate TABLES statement. Only data from the current client
is usually deleted. You can delete data using a view only if
the view refers to a single table and was created in the ABAP/4
Dictionary with the maintenance status "No restriction".
DELETE belongs to the Open SQL command set.
Note The DELETE statement does not perform authorization checks: You
must program these yourself.
Variant 1 DELETE FROM dbtab WHERE condition.
DELETE FROM (dbtabname) WHERE condition.
Addition:
... CLIENT SPECIFIED
Effect Deletes lines in a database table that satisfy the WHERE clause
condition. With this variant, specification of a WHERE
condition is obligatory.
When the statement has been executed, the system field SY-DBCNT
contains the number of deleted lines.
The return code value is set as follows:
SY-SUBRC = 0: At least one line was deleted.
SY-SUBRC = 4: No lines were deleted, since no line was
selected.
Example Delete all bookings for the Lufthansa flight 0400 on 28.02.1995
(in the current client):
TABLES SBOOK.
DELETE FROM SBOOK WHERE CARRID = 'LH' AND
CONNID = '0400' AND
FLDATE = '19950228'.
Note To delete all the lines in a table, you must specify a WHERE
condition that is true for all lines. You can achieve this with
... WHERE f IN itab
If the internal table itab is empty, such a condition would
select all lines.
Addition ... CLIENT SPECIFIED
Effect Switches off automatic client handling. This allows you to
delete data across all clients in the case of client-specific
tables. The client field is then treated like a normal table
field, for which you can formulate suitable conditions in the
WHERE clause.
You must specify the addition CLIENT SPECIFIED immediately
after the name of the database table.
Variant 2 DELETE dbtab.
DELETE *dbtab.
DELETE (dbtabname) ...
Additions:
1. ... FROM wa
2. ... CLIENT SPECIFIED
Effect These are SAP-specific short forms used to delete a single line
of a database table. If the name of the database table is
specified in the program, the primary key of the line to be
deleted is taken from the specified work area - dbtab or
*dbtab. If the name of the database table is not determined
until runtime (DELETE (dbtabname) ...), the addition ... FROM
wa is obligatory.
When the statement has been executed, the system field SY-DBCNT
contains the number of deleted lines (0 or 1).
The return code value is set as follows:
SY-SUBRC = 0: The line was deleted.
SY-SUBRC = 4: No lines could be deleted, since no line exists
with the primary key specified.
Example Delete the booking with the booking number 3 for the Lufthansa
flight 0400 on 28.02.1995 (in the current client):
TABLES SBOOK.
SBOOK-CARRID = 'LH'.
SBOOK-CONNID = '0400'.
SBOOK-FLDATE = '19950228'.
SBOOK-BOOKID = '00000003'.
DELETE SBOOK.
Addition 1 ... FROM wa
Effect Takes the primary key for the line to be deleted not from the
table work area dbtab, but from the explicitly specified work
area wa. Here, the key values from left to right are taken from
wa according to the structure of the primary key in the table
work area dbtab (see TABLES). The structure of wa is not taken
into account. Therefore, the work area wa must be at least as
wide (see DATA) as the primary key in the table work area dbtab
and the alignment of the work area wa must correspond to the
alignment of the primary key in the table work area. Otherwise,
you get a runtime error.
Note If a work area is not explicitly specified, the values for the
line to be deleted are taken from the table work area dbtab,
even if the statement appears in a subroutine (see FORM) or
Funktionsbaustein (see FUNCTION) where the table work area is
stored in a formal parameter or a local variable of the same
name.
Addition 2 ... CLIENT SPECIFIED
Effect As with variant 1.
Variant 3 DELETE dbtab FROM TABLE itab.
DELETE (dbtabname) FROM TABLE itab.
Addition:
... CLIENT SPECIFIED
Effect Mass deletion: Deletes all database table lines for which the
internal table itab contains values for the primary key fields.
The lines of the internal table itab must satisfy the same
condition as the work area wa in addition 1 to variant.
The system field SY-DBCNT contains the number of deleted lines,
i.e. the number of lines of the internal table itab for whose
key values there were lines in the database table dbtab.
The return code value is set as follows:
SY-SUBRC = 0: All lines from itab could be used to delete
lines from dbtab.
SY-SUBRC = 4: For at least one line of the internal table in
the database table, there was no line with the
same primary key. All found lines are deleted..
Note If the internal table itab is empty, SY-SUBRC and SY-DBCNT are
set to 0.
Addition ... CLIENT SPECIFIED
Effect As with variant 1.
Variant 4 DELETE dbtab VERSION vers.
DELETE *dbtab VERSION vers.
Note This variant is obsolete, since variants 1 - 3 allow you to
specify the database table name dynamically.
Effect Deletes a line in a database table, the name of which is taken
from the field vers at runtime. The database table must be
known to the ABAP/4 Dictionary and its name must conform to the
following naming convention: It must begin with 'T' and can
consist of four additional characters. The field vers must
contain the table name without a leading 'T'. Only lines in the
current client are deleted. The line to be deleted is taken
from the statically specified table work area dbtab or *dbtab.
The return code value is set as follows:
SY-SUBRC = 0: The line was deleted.
SY-SUBRC = 4: No lines could be deleted because no line
existed with the specified primary key.
DELETE DYNPRO - delete a screen
Note This statement is for internal use only.
Incompatible changes or further developments may occur at any
time without warning or notice.
Basic form DELETE DYNPRO f.
Effect Deletes the screen specified in the field f.
The return code value is set as follows:
SY-SUBRC = 0: The screen was deleted.
SY-SUBRC = 4: The screen does not exist.
The contents of f consist of the 8-character program name and
the 4-character screen number.
Example
DELETE DYNPRO 'SAPTESTX0100'.
Related IMPORT DYNPRO, EXPORT DYNPRO, GENERATE DYNPRO, SYNTAX-CHECK FOR
DYNPRO.
DELETE - delete a data cluster
Basic form DELETE FROM DATABASE dbtab(ar) ID key.
Addition:
... CLIENT f
Effect Deletes the data cluster stored in the table dbtab under the
area ar (constant) and the ID key (field or literal) (EXPORT
... TO DATABASE ...).
Example
TABLES INDX.
DATA: BEGIN OF TAB OCCURS 1,
CONT(30),
END OF TAB.
DATA: FLD(30) TYPE C.
...
EXPORT TAB FLD TO DATABASE INDX(AR) ID 'TEST'.
You can delete this data cluster with the following statement:
DELETE FROM DATABASE INDX(AR) ID 'TEST'.
Addition 1 ... CLIENT f
Effect Deletes the data cluster in the client specified in the table f
(only with client-specific import/export databases).
Example
TABLES INDX.
DELETE FROM DATABASE INDX(AR) CLIENT '001' ID 'TEST'.
DELETE - Delete from an internal table
Variants:
1. DELETE itab.
2. DELETE itab INDEX idx.
3. DELETE itab FROM idx1 TO idx2.
4. DELETE itab WHERE condition.
5. DELETE ADJACENT DUPLICATES FROM itab.
Effect Deletes one or more lines from an internal table.
Note The deletion of lines within a LOOP ... ENDLOOP loop is
performed in a sequence of loop passes.
Variant 1 DELETE itab.
Effect The current entry of the internal table itab is
deleted in a LOOP loop.
The return code value is set to 0.
Note After deleting the current entry in an internal table in a LOOP
loop, the effect of further update operations on the current
entry without an INDEX specification is not guaranteed and may
changed in later Releases.
Variant 2 DELETE itab INDEX idx.
Effect Deletes the idx entry from the internal table itab.
The return code value is set as follows:
SY-SUBRC = 0: The entry was deleted.
SY-SUBRC = 4: The entry does not exist.
Variant 3 DELETE itab FROM idx1 TO idx2.
Effect Deletes the line area from index idx1 to idx2 from internal
table itab. At least one of the two parameters FROM idx1 or TO
idx2 should be specified. If parameter FROM is missing, the
area from the start of the table to line idx2 is deleted. If
parameter TO is missing, the area from line idx1 to the end of
the table is deleted. Start index idx1 must be greater than 0.
The return code value is set as follows:
SY-SUBRC = 0: At least one entry was deleted.
SY-SUBRC = 4: None of the entries were deleted.
Variant 4 DELETE itab WHERE condition.
Additions:
1. ... FROM idx1
2. ... TO idx2
Effect Deletes all entries from internal table itab, which satisfies
the condition condition.
The return code value is set as follows:
SY-SUBRC = 0: At least one entry was deleted.
SY-SUBRC = 4: None of the entries were deleted.
Addition 1 ... FROM idx1
Effect The line area to be investigated is restricted to the lines up
to index idx1. If the addition FROM idx1 is missing, a search
is carried out from the beginning of the table.
The addition FROM must come before the WHERE condition.
Addition 2 ... TO idx2
Effect Restricts the line area to be investigated to the lines up to
index idx2. If the addition TO idx2 is missing, a search is
carried out until the end of the table.
The addition TO must come before the WHERE condition.
Example Delete all lines in a name table between lines 5 and 36, if the
entry begins with one of the letters 'A' to 'C':
DATA: BEGIN OF NAMETAB OCCURS 100,
NAME(30) TYPE C, END OF NAMETAB.
...
DELETE NAMETAB FROM 5 TO 36 WHERE NAME CA 'ABC'.
Variant 5 DELETE ADJACENT DUPLICATES FROM itab.
Additions:
1. ... COMPARING f1 f2 ...
2. ... COMPARING ALL FIELDS
Effect Deletes neighboring, duplicate entries from the internal table
itab. If there are n duplicate entries, the first entry is
retained and the other n - 1 entries are deleted.
Two lines are considered to be duplicated if their default keys
match.
The return code value is set as follows:
SY-SUBRC = 0: At least one duplicate exists, at least one
entry deleted.
SY-SUBRC = 4: No duplicates exist, no entry deleted.
Addition 1 ... COMPARING f1 f2 ...
Effect Two lines of the internal table itab are considered to be
duplicates if the specified fields f1, f2, .... match.
Addition 2 ... COMPARING ALL FIELDS
Effect Two lines are considered to be duplicates if all fields of the
table entries match.
Notes 1. The DELETE ADJACENT DUPLICATES statement is especially
useful if the internal table itab is sorted by fields
(whether in ascending or descending order) which were
compared during duplicate determination. In this case, the
deletion of neighbouring duplicates is the same as the
deletion of all duplicates.
2. If a comparison criterion is only known at runtime, it can
be specified dynamically as the content of a field name by
using COMPARING ... (name) .... If name is blank at runtime,
the comparison criterion is ignored. If name contains an
invalid component name, a runtime error occurs.
3. Comparison criteria - statistically or dynamically specified
- can be further restriced by specifying the offset and/or
length.
Note Performance:
1. Deleting a line from an internal table incurs index
maintenance costs which depend on the index of the line to
be deleted. The runtime depends on the line width of the
table.
For example, deleting a line in the middle of an internal
table with 200 entries requires about 10 msn (standardized
microseconds).
Deleting a range of entries with "DELETE itab FROM idx1 TO
idx2." deleting a set of entries with "DELETE itab WHERE
..." only incur index maintenance costs once. Compared with
a LOOP, which deletes line-by-line, this is much faster.
2. To delete neighboring, duplicate entries from an internal
table, use the variant "DELETE ADJACENT DUPLICATES FROM
itab." instead of LOOP constructions.
Related INSERT itab, MODIFY itab
DELETE - delete a program
Note This statement is for internal use only.
Incompatible changes or further developments may occur at any
time without warning or notice.
Basic form DELETE REPORT prog.
Effect Deletes some components (source code, attributes, text elements
and generated version) of the program specified in the field
prog.
The return code value is set as follows:
SY-SUBRC = 0: The program was deleted.
SY-SUBRC = 4: The program does not exist.
Note This statement deletes neither the variants nor the
documentation.
Normally, you should use the function module RS_DELETE_PROGRAM
to delete a program.
Related INSERT REPORT, DELETE TEXTPOOL
DELETE - delete text elements
Note This statement is for internal use only.
Incompatible changes or further developments may occur at any
time without warning or notice.
Basic form DELETE TEXTPOOL prog LANGUAGE lg.
Effect Deletes all text elements of the program specified in the field
prog for the language specified in the field lg from the
library.
If you use the value '*' for lg, the text elements of all
languages are deleted.
Example Delete all text elements of the program PROGNAME in the
language "English":
DATA: PROGRAM(8) VALUE 'PROGNAME'.
DELETE TEXTPOOL PROGRAM LANGUAGE 'E'.
Related INSERT TEXTPOOL, READ TEXTPOOL
DEQUEUE is not an ABAP/4 key word (in R/3).
To unlock resources, you must use a function module.
DESCRIBE
Return attributes of a field
- DESCRIBE FIELD f.
Return attributes of an internal table
- DESCRIBE TABLE itab.
Determine distance between two fields
- DESCRIBE DISTANCE BETWEEN f1 AND f2 INTO f3.
Return attributes of a list
- DESCRIBE LIST NUMBER OF LINES lin.
- DESCRIBE LIST NUMBER OF PAGES n.
- DESCRIBE LIST LINE lin PAGE pag.
- DESCRIBE LIST PAGE pag.
DESCRIBE DISTANCE BETWEEN f1 AND f2 INTO f3
Effect Returns the distance between the fields f1 and f2 in f3.
Example
TABLES LFA1.
DATA DIS TYPE P.
DESCRIBE DISTANCE BETWEEN LFA1-LAND1
AND LFA1-NAME1
INTO DIS.
Result: DIS contains the value 14, since exactly two fields lie
between LAND1 and NAME1, namely LNRZA (10 bytes) and LOEVM (1
byte); additionally, the sub-field LAND1 is 3 bytes long.
Therefore, the start of the sub-field LAND1 is exactly 14 bytes
from the start of the sub-field NAME1.
DESCRIBE - determine distance between two fields
Basic form DESCRIBE DISTANCE BETWEEN f1 AND f2 INTO f3.
Effect Determines the distance between the fields f1 and f2 and places
the result (in bytes) in f3.
Example Determine the distance between two components of the demo table
SBOOK in the flight reservation system:
TABLES SBOOK.
DATA DIST TYPE I.
DESCRIBE DISTANCE BETWEEN SBOOK-CARRID
AND SBOOK-BOOKID
INTO DIST.
Result: DIST contains the value 15 because exactly two fields,
SFLIGHT-CONNID (4 bytes) and SBOOK-FLDATE (8 bytes), lie
between the SBOOK components CARRID and BOOKID; also,
SBOOK-CARRID is itself 3 bytes long. The sum of these values
gives the distance between the two components in bytes.
DESCRIBE - Supply attributes of a field
Basic form DESCRIBE FIELD f.
Effect Supplies the attributes of the field f. You must specify at
least one of the additions:
Additions:
1. ... LENGTH len
2. ... TYPE typ
3. ... TYPE typ COMPONENTS n
4. ... OUTPUT-LENGTH len
5. ... DECIMALS n
6. ... EDIT MASK mask
Addition 1 ... LENGTH len
Effect Returns the length of the field f in the field
len.
Example
DATA: FLD(8),
LEN TYPE P.
DESCRIBE FIELD FLD LENGTH LEN.
Result: LEN contains the value 8.
Addition 2 ... TYPE typ
Effect Returns the data type of f in the field typ
Example
DATA: FLD(8) TYPE N,
F_TYPE.
DESCRIBE FIELD FLD TYPE F_TYPE.
Result: F_TYPE contains the value 'N'.
Note Along with the elementary data types you can specify
under DATA (C, N, etc.), several other data types are created
either with reference to Dictionary fields or during
generation. These data types, which are also returned by
DESCRIBE, have the following type IDs:
h Internal table
s 2-byte integer with leading sign
b 1-byte integer without leading sign
u Structure without internal table
v Structure containing at least one internal table
For compatibility reasons, ... TYPE typ returns C rather than u
or v with structures.
Addition 3 ... TYPE typ COMPONENTS n
Effect Similar to ... TYPE typ except that, with structures in typ, u
or v are returned and in the number of structure components is
set in n. If f is not a structure, n is set to 0.
Example Recursive processing of the pages of an ABAP/4 data structure:
FORM TEST USING F.
DATA: TYP(1) TYPE C, N TYPE I.
FIELD-SYMBOLS: <F>.
DO.
ASSIGN COMPONENT SY-INDEX OF STRUCTURE F TO <F>.
IF SY-SUBRC <> 0. EXIT. ENDIF.
DESCRIBE FIELD <F> TYPE TYP COMPONENTS N.
IF N > 0. " Equivalent is TYP = 'u' OR TYP = 'v'
PERFORM TEST USING <F>.
ELSE.
PERFORM DO_SOMETHING USING <F>.
ENDIF.
ENDDO.
ENDFORM.
Addition 4 ... OUTPUT-LENGTH len
Effect Enters the output length of the field f in the variable len.
Example
DATA: FLD(4) TYPE P,
O_LEN TYPE P.
DESCRIBE FIELD FLD OUTPUT-LENGTH O_LEN.
Result: O_LEN contains the value 8.
Addition 5 ... DECIMALS n
Effect Enters the number of decimal places for the field f (defined in
addition ... DECIMALS of the DATA statement or in the ABAP/4
Dictionary) in the variable n.
Example
DATA: FLD(8) TYPE P DECIMALS 2,
DEC TYPE P.
DESCRIBE FIELD FLD DECIMALS DEC.
Resultat: DEC contains the value 2.
Addition 6 ... EDIT MASK mask
Effect If the field f has a conversion routine in the ABAP/4
Dictionary, this is placed in the field mask in the form
"==conv". "conv" stands for the name of the conversion routine,
e.g. "==ALPHA" in the conversion routine "ALPHA". In this form,
mask can then be used in the addition USING EDIT MASK mask of
the WRITE statement.
Example Check whether there is a conversion routine for the field
"customer number" in the table SBOOK:
TABLES SBOOK.
DATA: CONV_EXIT(10).
DESCRIBE FIELD SBOOK-CUSTOMID EDIT MASK CONV_EXIT.
IF CONV_EXIT <> SPACE. ... ENDIF.
Result: CONV_EXIT contains the value "==ALPHA".
Note If the required field is only known at runtime, this field can
also be assigned dynamically to a field symbol (see
FIELD-SYMBOLS, ASSIGN).
DESCRIBE - supply attributes of a list
Variants:
1. DESCRIBE LIST NUMBER OF LINES lin.
2. DESCRIBE LIST NUMBER OF PAGES n.
3. DESCRIBE LIST LINE lin PAGE pag.
4. DESCRIBE LIST PAGE pag.
Effect Returns the attributes of a list. All variants have the
addition ... INDEX idx allowing you to determine the attributes
of a particular list level (SY-LSIND = 0,1,2,3,... ).
Note 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.
Variant 1 DESCRIBE LIST NUMBER OF LINES lin.
Addition:
... INDEX idx
Effect Returns the number of lines in the list.
The return code value is set as follows:
SY-SUBRC = 0: OK
SY-SUBRC <> 0: List does not exist (only with the addition
INDEX)
Addition ... INDEX idx
Effect Returns the attributes of the list level idx (0, 1,2,3,...).
Example After line selection, determine the number of lines in the
displayed list:
DATA: LN LIKE SY-PAGNO. ...
AT LINE-SELECTION.
DESCRIBE LIST NUMBER OF LINES LN.
The variable LN now contains the number of lines in the
displayed list.
Variant 2 DESCRIBE LIST NUMBER OF PAGES n.
Addition:
... INDEX idx
Effect Returns the number of pages in the list.
The return code value is set as follows:
SY-SUBRC = 0: OK
SY-SUBRC <> 0: List does not exist (only with the addition
INDEX)
Addition ... INDEX idx
Effect Returns the attributes of the list level idx (0, 1,2,3,...).
Example After line selection, determine the number of pages in the
displayed list:
DATA: PN LIKE SY-PAGNO. ...
AT LINE-SELECTION.
DESCRIBE LIST NUMBER OF PAGES PN.
The variable PN now contains the number of pages in the
displayed list (i.e. the contents of the system field SY-PAGNO
after the list has been generated!).
Variant 3 DESCRIBE LIST LINE lin PAGE pag.
Addition:
... INDEX idx
Effect Returns the number of the page for the line lin in the list.
Note In interactive reporting, line selection causes a value to be
assigned to the system field SY-LILLI (absolute number of
selected list line). The system field SY-CPAGE contains the
page number for the first displayed line in the list. The
selected line does not have to belong to this page (in cases
where several pages are displayed at the same time). The page
number may be of interest even with direct reading of lines
(see READ LINE).
The return code value is set as follows:
SY-SUBRC = 0: OK
SY-SUBRC = 4: Line does not exist
SY-SUBRC = 8: List does not exist
Addition ... INDEX idx
Effect Returns the attributes of the list level idx (0, 1,2,3,...).
Example After line selection, determine the page number for the
selected line (SY-LILLI):
DATA: PAGENUMBER LIKE SY-PAGNO. ...
AT LINE-SELECTION.
DESCRIBE LIST LINE SY-LILLI PAGE PAGENUMBER.
The variable PAGENUMBER now contains the page number for the
line SY-LILLI (i.e. the contents of the system field SY-PAGNO
when outputting the line SY-LILLI!).
Variant 4 DESCRIBE LIST PAGE pag
Additions:
1. ... INDEX idx
2. ... LINE-SIZE col
3. ... LINE-COUNT lin
4. ... LINES lin
5. ... FIRST-LINE lin
6. ... TOP-LINES lin
7. ... TITLE-LINES lin
8. ... HEAD-LINES lin
9. ... END-LINES lin
Effect Returns the attributes of the page pag in the list.
The return code value is set as follows:
SY-SUBRC = 0: OK
SY-SUBRC = 4: Page does not exist
SY-SUBRC = 8: List does not exist
Addition 1 ... INDEX idx
Effect Returns the attributes of the list level idx (0, 1,2,3,...).
Addition 2 ... LINE-SIZE col
Effect Returns the line length for the page pag (see
NEW-PAGE...LINE-SIZE).
Addition 3 ... LINE-COUNT lin
Effect Returns the permitted number of lines for the page pag (see
NEW-PAGE...LINE-COUNT).
Addition 4 ... LINES lin
Effect Returns the number of lines output on the page pag.
Addition 5 ... FIRST-LINE lin
Effect Returns the absolute line number of the first line of the page
pag.
Addition 6 ... TOP-LINES lin
Effect Returns the number of lines output by page header processing
(i.e. standard title + column headers + TOP-OF-PAGE).
Addition 7 ... TITLE-LINES lin
Effect Returns the number of lines output as standard title lines by
page header processing (see NEW-PAGE...NO-TITLE/WITH-TITLE).
Note The value of TITLE-LINES is contained in TOP-LINES.
Addition 8 ... HEAD-LINES lin
Effect Returns the number of lines output as column headers by page
header processing (see NEW-PAGE...NO-HEADING/WITH-HEADING).
Note The value of HEAD-LINES is contained in TOP-LINES.
Addition 9 ... END-LINES lin
Effect Returns the number of lines reserved for end-of-page processing
(see END-OF-PAGE).
Example Determine the number of lines output on the third page of the
basic list (SY-LSIND = 0) in the event TOP-OF-PAGE:
DATA: TOP TYPE I,
HEAD TYPE I,
TITLE TYPE I,
REAL_TOP TYPE I.
DESCRIBE LIST INDEX 0 PAGE 3
TOP-LINES TOP
HEAD-LINES HEAD
TITLE-LINES TITLE.
REAL_TOP = TOP - TITLE - HEAD.
Examples Determine the absolute number of lines in the displayed list:
DATA: LN TYPE I, "number of lines on a page
FLN TYPE I, "number of first line on a page
PN TYPE I, "number of a page
LIST_LINES TYPE I. "total number of lines in list
Determine number of last page:
DESCRIBE LIST NUMBER OF PAGES PN.
Determine number of first line of last page and number of lines
on that page:
DESCRIBE LIST PAGE PN FIRST-LINE FLN LINES LN.
Number of list lines = number of first line of last page +
number of lines - 1.
LIST_LINES = FLN + LN - 1.
Or: Count lines of all pages in a loop:
CLEAR LIST_LINES.
DO PN TIMES.
DESCRIBE LIST PAGE SY-INDEX LINES LN.
ADD LN TO LIST_LINES.
ENDDO.
or:
DESCRIBE LIST NUMBER OF LINES LIST_LINES.
DESCRIBE - return attributes of an internal table
Basic form DESCRIBE TABLE itab.
Effect Returns the attributes of the internal table itab. You must use
at least one of the additions listed below.
Additions:
1.... LINES lin
2.... OCCURS n
Addition 1 ... LINES lin
Effect Places the number of filled lines of the table t in the field
lin.
Example
DATA: BEGIN OF TAB OCCURS 10,
X,
END OF TAB.
DATA: LIN TYPE P.
...
CLEAR TAB. REFRESH TAB.
MOVE '?' TO TAB-X.
APPEND TAB.
DESCRIBE TABLE TAB LINES LIN.
Result: LIN contains the value 1.
Addition 2 ... OCCURS n
Effect Transfers the size of the OCCURS parameter from the table
definition to the variable n.
Example
DATA: BEGIN OF TAB OCCURS 10,
X,
END OF TAB.
OCC TYPE P.
DESCRIBE TABLE TAB OCCURS OCC.
Result: OCC contains the value 10.
Note If the table is meant to accept more lines than specified by
the OCCURS parameter, the parameter value is roughly doubled as
long as the table size remains smaller than 8 KB; this table
area is held in the roll area. If the table exceeds the maximum
permitted size, the OCCURS parameter is not increased and the
remaining part of the table is rolled out to the paging area
(see DATA).
For this reason, the OCCURS value determined by the DESCRIBE
statement may differ from that in the DATA statement.
The runtime required to execute the DESCRIBE TABLE statement is
approx. 4 msn (standardized microseconds).
DETAIL
Basic form DETAIL.
This key word is the same as the statement
FORMAT INTENSIFIED OFF.
The latter is recommended due to better readability.
Note When outputting data to a list, you also use the addition
INTENSIFIED OFF of the WRITE statement to change the output
format for single fields.
Related FORMAT
DIVIDE
Basic form DIVIDE n1 BY n2.
Effect Divides the contents of n1 by n2 and places the result in n1.
This is equivalent to: n1 = n1 / n2.
Example
DATA: SUM TYPE P, NUMBER TYPE P.
DIVIDE SUM BY NUMBER.
Note The details regarding conversions and performance given under
COMPUTE apply equally to DIVIDE. Furthermore: Division by 0 is
not allowed, except where 0 / 0 results in 0.
Note Runtime errors:
- BCD_BADDATA: P field contains no correct BCD format
- BCD_FIELD_OVERFLOW: Result field is too small (type P)
- BCD_OVERFLOW: Overflow during arithmetic operation (type P)
- BCD_ZERODIVIDE: Division by 0 (type P)
- COMPUTE_FLOAT_ZERODIVIDE: Division by 0 (type F)
- COMPUTE_INT_DIV_OVERFLOW: Whole number overflow with
division
- COMPUTE_INT_ZERODIVIDE: Division by 0 (type I)
Related COMPUTE, DIVIDE-CORRESPONDING
DIVIDE-CORRESPONDING
Basic form DIVIDE-CORRESPONDING rec1 BY rec2.
Effect Interprets rec1 and rec2 as field strings, i.e. if rec1 and
rec2 are tables with header lines, the statement is executed
for their header lines.
Searches for all sub-fields that occur both in rec1 and rec2
and then generates, for all field pairs corresponding to the
sub-fields ni, statements similar in the following form:
DIVIDE rec1-ni BY rec2-ni.
The other fields remain unchanged.
With more complex structures, the complete names of the field
pairs must be identical.
Example
DATA: BEGIN OF MONEY,
VALUE_IN(20) VALUE 'German marks'.
USA TYPE I VALUE 100,
FRG TYPE I VALUE 200,
AUT TYPE I VALUE 300,
END OF MONEY,
BEGIN OF CHANGE,
DESCRIPTION(30)
VALUE 'DM to national currency'.
USA TYPE F VALUE '1.5',
FRG TYPE F VALUE '1.0',
AUT TYPE F VALUE '0.14286',
END OF CHANGE.
DIVIDE-CORRESPONDING MONEY BY CHANGE.
‎2007 Jul 03 5:25 AM
HI,
PLEASE CHECK OUT THE LINK BELOW IT WILL HELP YOU
http://help.sap.com/saphelp_nw2004s/helpdata/en/fc/eb2ed0358411d1829f0000e829fbfe/content.htm
**********PLEASE REWARD POINTS IF THE INFORMATION IS HELPFUL TO YOU************
‎2007 Jul 03 5:27 AM
Hi,
Goto ABAPDOCU there you can find syntax for all the keywords.
Regrds,
Sesh
‎2007 Jul 03 5:28 AM
ABAP/4 programming language overview
-
This documentation describes the syntax and meaning of ABAP/4
key words (for Release 3.0). The contents are identical to the
online help function.
ADD
Variants:
1. ADD n TO m.
2. ADD n1 THEN n2 UNTIL nz GIVING m.
3. ADD n1 THEN n2 UNTIL nz TO m.
4. ADD n1 THEN n2 UNTIL nz
...ACCORDING TO sel ...GIVING m.
5. ADD n1 FROM m1 TO mz GIVING m.
Variant 1 ADD n TO m.
Effect Adds the contents of n to the contents of M and stores the
result in m.
This is equivalent to: m = m + n.
Example
DATA: NUMBER TYPE I VALUE 3,
SUM TYPE I VALUE 5.
ADD NUMBER TO SUM.
The field SUM now contains 8, whilst the contents of the field
NUMBER remains unchanged at 3.
Note The details about conversions and performance described under
COMPUTE are identical for ADD.
Note Runtime errors:
- BCD_BADDATA: P field contains incorrect BCD format.
- BCD_FIELD_OVERFLOW: Result field too small (type P).
- BCD_OVERFLOW: Overflow with arithmetic operation (type P.
- COMPUTE_INT_PLUS_OVERFLOW: Integer overflow when adding.
Related COMPUTE, ADD-CORRESPONDING.
Variant 2 ADD n1 THEN n2 UNTIL nz GIVING m.
Effect Adds the contents of the fields n1, n2, ..., nz together and
stores the result in m, where n1 is the first, n2 the second
and nz the last of a sequence of fields the same distance
apart. They can be either database fields or internal fields,
but they must all have the same type and length.
This is equivalent to: m = n1 + n2 + ... + nz.
Example
DATA: BEGIN OF NUMBERS,
ONE TYPE P VALUE 10,
TWO TYPE P VALUE 20,
THREE TYPE P VALUE 30,
FOUR TYPE P VALUE 40,
FIVE TYPE P VALUE 50,
SIX TYPE P VALUE 60,
END OF NUMBERS,
SUM TYPE I VALUE 1000.
ADD NUMBERS-ONE THEN NUMBERS-TWO
UNTIL NUMBERS-FIVE GIVING SUM.
The field SUM now contains 150 but its initial value is
unimportant. The fields within the field string NUMBERS remain
unchanged.
Variant 3 ADD n1 THEN n2 UNTIL nz TO m.
Effect Calculates the total as in variant 2 but then adds it to the
contents of the field m.
This is equivalent to: m = m + n1 + n2 + ... + nz
Example
DATA: BEGIN OF NUMBERS,
ONE TYPE P VALUE 10,
TWO TYPE P VALUE 20,
THREE TYPE P VALUE 30,
FOUR TYPE P VALUE 40,
FIVE TYPE P VALUE 50,
END OF NUMBERS,
SUM TYPE I VALUE 1000.
ADD NUMBERS-ONE THEN NUMBERS-TWO
UNTIL NUMBERS-FIVE TO SUM.
The field SUM now contains 1150.
Variant 4 ADD n1 THEN n2 UNTIL nz
...ACCORDING TO sel ...GIVING m.
Parts marked with " ..." are interchangeable
Effect Calculates the total as in variants 2 and 3. In this case,
however, the operands from a sequence of fields of the same
type are restricted to a partial sequence by the selection
specification sel generated by SELECT-OPTIONS or RANGES. The
partial sequence results from the indexes that satisfy the
condition IN sel (see IF).
Example
DATA: BEGIN OF NUMBERS,
ONE TYPE P VALUE 10,
TWO TYPE P VALUE 20,
THREE TYPE P VALUE 30,
FOUR TYPE P VALUE 40,
FIVE TYPE P VALUE 50,
END OF NUMBERS,
SUM TYPE I VALUE 1000,
INDEX TYPE I.
RANGES SELECTION FOR INDEX.
SELECTION-SIGN = 'I'.
SELECTION-OPTION = 'BT'.
SELECTION-LOW = 2.
SELECTION-HIGH = 4.
APPEND SELECTION.
ADD NUMBERS-ONE THEN NUMBERS-TWO
UNTIL NUMBERS-FIVE
ACCORDING TO SELECTION
GIVING SUM.
SUM now contains 90. Only the component fields TWO to FOUR were
selected from the field string NUMBERS and added together.
Variant 5 ADD n1 FROM m1 TO mz GIVING m.
Effect The field n1 must be the first in a sequence of consecutive
fields of the same type. m1 and mz should contain the numbers
of the first and last fields in this sequence to be added
together (whether fixed or variable). The total is stored in m.
Example
DATA: BEGIN OF NUMBERS,
ONE TYPE P VALUE 10,
TWO TYPE P VALUE 20,
THREE TYPE P VALUE 30,
FOUR TYPE P VALUE 40,
FIVE TYPE P VALUE 50,
END OF NUMBERS,
START TYPE I VALUE 2,
SUM TYPE I VALUE 1000.
ADD NUMBERS-ONE FROM START TO 4 GIVING SUM.
The field SUM now contains 90.
Note Performance:
The details for conversion and performance specified for
COMPUTE are equally valid for ADD.
The runtime required for adding two numbers of type I or F is
about 2 msn (standardized microseconds), for type P it is
roughly 8 msn.
Note Runtime errors:
Besides the runtime errors listed in variant 1, the error
ADDF_INT_OVERFLOW can occur instead of
COMPUTE_INT_PLUS_OVERFLOW in other variants.
ADD-CONDITIONAL is not an ABAP/4 key word (in R/3).
ADD-CORRESPONDING
Basic form ADD-CORRESPONDING rec1 TO rec2.
Effect Interprets rec1 and rec2 as field strings. If, for example,
rec1 and rec2 are tables, executes the statement for their
header lines.
Searches for all sub-fields which occur both in rec1 and rec2
and then, for all relevant field pairs corresponding to the
sub-fields ni, generates statements of the form
ADD rec1-ni TO rec2-ni.
The other fields remain unchanged.
With complex structures, the complete names of the
corresponding field
pairs must be textually identical.
Example
DATA: BEGIN OF VECTOR,
X TYPE I,
Y TYPE I,
LENGTH TYPE I,
END OF VECTOR,
BEGIN OF CIRCLE,
VOLUME TYPE P
Y TYPE P,
RADIUS TYPE I,
X TYPE I,
END OF CIRCLE.
...
ADD-CORRESPONDING VECTOR TO CIRCLE.
The sub-fields X and Y occur in both the field strings VECTOR
and CIRCLE. Therefore, the ADD-CORRESPONDING statement is
equivalent to both the following statements:
ADD VECTOR-X TO CIRCLE-X.
ADD VECTOR-Y TO CIRCLE-Y.
Note All fields with the same name are added, whether numeric or
not. The same conversions are performed as with ADD and similar
runtime errors to those possible with ADD can also occur.
Related ADD
MOVE-CORRESPONDING
SUBTRACT-CORRESPONDING
MULTIPLY-CORRESPONDING
DIVIDE-CORRESPONDING
ADD-SELECTIVE is not an ABAP/4 key word (in R/3).
APPEND
Variants:
1. APPEND [wa TO|INITIAL LINE TO] itab.
2. APPEND LINES OF itab1 [FROM idx1] [TO idx2] TO itab2.
3. APPEND [wa TO] itab SORTED BY f.
Variant 1 APPEND [wa TO|INITIAL LINE TO] itab.
Effect Appends a new line to the end of the internal table itab.
If you specify wa TO, the new line is taken from the contents
of the explicitly specified work area wa.
If you use INITIAL LINE TO, a line filled with the correct
value for the type is added.
If the specification before itab is omitted, the new line is
taken from the internal tbale itab.
After the APEND, the system field SY-TABIX contains the index
of the newly added table entry.
Examples Generate a list with customer numbers:
TABLES SCUSTOM.
DATA: CUSTOMER LIKE SCUSTOM-ID OCCURS 0.
APPEND SCUSTOM-ID TO CUSTOMER.
Append a blank line or a line with its initial value to the
above list:
APPEND INITIAL LINE TO CUSTOMER
Generate a compressed list with plane data
PARAMETERS: SEATS_LO LIKE SAPLANE-SEATSMAX DEFAULT 30,
SEATS_HI LIKE SAPLANE-SEATSMAX DEFAULT 50.
DATA: PLANE LIKE SAPLANE OCCURS 0,
PLANE_NEEDED LIKE SAPLANE WITH HEADER LINE.
LOOP AT PLANE INTO PLANE_NEEDED
WHERE SEATSMAX BETWEEN SEATS_LO AND SEATS_HI.
APPEND PLANE_NEEDED.
ENDLOOP.
Notes Performance:
1. When using internal tables with a header line, avoid
unnecessary assignments to the header line. Whenever
possible, use statements which have an explicit work area.
For example, "APPEND wa TO itab." is approximately twice as
fast as "itab = wa. APPEND itab.". The same applies to
COLLECT and INSERT.
2. In contrast to COLLECT, APPEND does not check whether an
entry with the same default key exists. Therefore, it is
considerably faster than COLLECT. If the COLLECT logic is
not needed or lines with an identical default key cannot
occur in a particular situation, you should always use
APPEND instead of COLLECT.
3. The runtime required for APPEND increases with the line
width of the table and depends on the number of fields.
Appending an entry to an internal table with a width of 111
bytes takes about 9 msn (standardized microseconds).
4. To append an internal table to another internal table, you
should use the variant APPEND LINES OF ... which is 3 to 4
times faster than using a LOOP to process the source table
and append the entries line-by-line to the target table.
Variant 2 APPEND LINES OF itab1 [FROM idx1] [TO idx2] TO itab2.
Effect Appends the internal table itab1 or an extract from itab1 to
the end of the internal table itab2.
By specifying FROM idx1 or TO idx2 you can restrict the line
area taken from the source table itab1. If there is no FROM
specification, it begins with the first line of itab1. If there
is no TO specification, it ends with the last line of itab1.
This means that the complete table is appended if neither a
FROM nor a TO is specified.
After the APPEND, the system field SY-TABIX contains the index
of the last table entry appended, i.e. the total number of
entries from both tables.
Note By comparing the values of SY-TABIX before and after the APPEND
statement, you can determine how many lines were appended to
the table.
Example Merge two tables with whole numbers:
DATA: ITAB1 TYPE I OCCURS 100,
ITAB2 TYPE I OCCURS 100.
APPEND 2 TO ITAB1.
APPEND 3 TO ITAB1.
APPEND 5 TO ITAB1.
APPEND 7 TO ITAB1.
APPEND 3 TO ITAB2.
APPEND INITIAL LINE TO ITAB2.
APPEND LINES OF ITAB1 FROM 2 TO 20 TO ITAB2.
The table ITAB2 now contains five lines with the values 3, 0,
3, 5 and 7.
Note Performance:
This variant is 3 to 4 times faster than using a LOOP to
process the source table and append the entries line-by-line to
the target table.
Variant 3 APPEND [wa TO] itab SORTED BY f.
Effect Inserts the new entry into table and re-sorts the table by the
sub-field f in descending order. This only makes sense if the
table was sorted beforehand. When the number of table entries
reaches the OCCURS parameter value, the last entry is deleted
if the value f of a new entry is greater (particularly suitable
for ranked lists). You can only sort by one sub-field.
If you specify wa TO, the new line is taken from the contents
of the explicitly specified work area wa. Otherwise, it comes
from the header line of the internal table itab.
Example
DATA: BEGIN OF COMPANIES OCCURS 3,
NAME(10), SALES TYPE I,
END OF COMPANIES.
COMPANIES-NAME = 'big'.
COMPANIES-SALES = 90.
APPEND COMPANIES.
COMPANIES-NAME = 'small'.
COMPANIES-SALES = 10.
APPEND COMPANIES.
COMPANIES-NAME = 'too small'.
COMPANIES-SALES = 5.
APPEND COMPANIES.
COMPANIES-NAME = 'middle'.
COMPANIES-SALES = 50.
APPEND COMPANIES SORTED BY SALES.
The table now has three (-> OCCURS 3) entries. The line with
the contents 'too small' in the sub-field NAME is deleted from
the table because the entry for 'middle' has a greater value in
the sub-field SALES. This entry now appears in the second table
line (after 'big' and before 'small').
Notes 1. Whenever an internal table is processed with APPEND SORTED
BY, it should always be filled in this way.
2. If you specify APPEND with the parameter SORTED BY, the
system always searches the entire table. Therefore, it is
sometimes better to create the table with a simple APPEND
and then use SORT to sort in descending ot ascending order
afterwards.
You can also sort in ascending order by first determining
the insert position with READ TABLE itab WITH KEY f = itab-f
BINARY SEARCH and then by inserting the new entry into the
table (perhaps read SY-SUBRC beforehand) with INSERT itab
INDEX SY-TABIX.
However, you should be aware that, in such cases, the table
may contain more entries than specified in the OCCURS
parameter.
3. If several lines with an identical value f are added, lines
added later are treated as smaller, i.e. they are inserted
after existing lines with the same value f.
4. If you use APPEND ... SORTED BY f with an explicitly
specified work area, this must be compatible with the line
type of the internal table.
5. If the sort criterion f is not known until runtime, you can
use SORTED BY (name) to specify it dynamically as the
contents of the field name. If name is blank at runtime or
contains an invalid component name, a runtime error occurs.
6. Regardless of whether you specify it statically or
dynamically, you can restrict the sort criterion f further
by defining an offset and/or length.
Related COLLECT itab, INSERT itab, SELECT / FETCH NEXT CURSOR ...
INTO/APPENDING TABLE itab, MODIFY itab, WRITE f TO itab INDEX
idx, SORT itab, READ TABLE itab, LOOP AT itab, DELETE itab
ASS-RPERF is not an ABAP/4 key word (in R/3).
ASSIGN
Variants:
1. ASSIGN f TO <fs>.
2. ASSIGN (f) TO <fs>.
3. ASSIGN TABLE FIELD (f) TO <fs>.
4. ASSIGN LOCAL COPY OF MAIN TABLE FIELD (f) TO <fs>.
5. ASSIGN COMPONENT idx OF STRUCTURE rec TO <fs>.
6. ASSIGN COMPONENT name OF STRUCTURE rec TO <fs>.
Variant 1 ASSIGN f TO <fs>.
Additions:
1. ... TYPE typ
2. ... DECIMALS dec
3. ... LOCAL COPY OF ...
Effect Assigns the field f to the field symbol <fs>. The field symbol
<fs> "points to" the contents of the field f at runtime, i.e.
every change to the contents of f is reflected in <fs> and vice
versa. If the field symbol <fs> is not typed (see
FIELD-SYMBOLS), the field symbol adopts the type and atrributes
of the field f at runtime, particularly the conversion exit.
Otherwise, when the assignment is made, the system checks
whether the type of the field f matches the type of the field
symbol <fs>.
Note With the ASSIGN statement, the offset and length specifications
in field f (i.e. foff, flen or f+off(len)) have a special
meaning:
- They may be variable and thus not evaluated until runtime.
- The system does not check whether the selected area still
lies within the field f.
- If an offset is specified, but no length, for the field f,
the field symbol <fs> adopts the length of the field f.
Caution: <fs> also points to an area behind the field f. If
you do not want this, the offset and length specifications
can be in the form ASSIGN f+off(*) TO <fs>.. This means that
the field symbol <fs> is set so that the field limits of f
are not exceeded.
- In the ASSIGN statement, you can also use offset and length
specifications to access field symbols, FORM and function
parameters.
- Warning: If the effect of the ASSIGN statement is to assign
parts of other fields beyond the limits of the field f, the
changing of the contents via the field symbol <fs> may mean
that the data written to these fields does not match the
data type of these fields and thus later results in a
runtime error.
Note Since the ASSIGN statement does not set any return code value
in the system field SY-SUBRC, subsequent program code should
not read this field.
Example
DATA NAME(4) VALUE 'JOHN'.
FIELD-SYMBOLS <F>.
ASSIGN NAME TO <F>.
WRITE <F>.
Output: JOHN
Example
DATA: NAME(12) VALUE 'JACKJOHNCARL',
X(10) VALUE 'XXXXXXXXXX'.
FIELD-SYMBOLS .
ASSIGN NAME+4 TO .
WRITE .
ASSIGN NAME+4(*) TO .
WRITE .
Output: JOHNCARLXXXX JOHNCARL
Example
DATA: NAME(12) VALUE 'JACKJOHNCARL',
X(10) VALUE 'XXXXXXXXXX'.
FIELD-SYMBOLS <F>.
ASSIGN NAME+4 TO <F>.
WRITE <F>.
ASSIGN NAME+4(*) TO <F>.
WRITE <F>.
Output: JOHNCARLXXXX JOHNCARL
Addition 1 ... TYPE typ
Effect With untyped field symbols, allows you to change the current
type of the field symbol to the type typ. The output length of
the field symbol is corrected according to its type.
With typed field symbols, this addition should only be used if
the type of the field f does not match the type of the field
symbol <fs>. The specified type type must be compatible with
the type of the field symbol. Since no conversion can be
performed (as with MOVE, the system must be able to interpret f
as a field with this type type.
The type specification is in the form of a literal or a field.
At present, only system types (C, D, T, P, X, N, F, I or W) are
allowed; you can also specify type 's' for 2-byte integer
fields with a sign and type 'b' for 1-byte integer fields
without a sign (see also DESCRIBE FIELD).
Note This statement results in a runtime error if the specified type
is unknown or does not match the field to be assigned (due to a
missing alignment or an inappropriate length).
Example
DATA LETTER TYPE C.
FIELD-SYMBOLS <F>.
ASSIGN LETTER TO <F>.
The field symbol has the type C and the output length 1.
ASSIGN LETTER TO <F> TYPE 'X'.
The field symbol has the type X and the output length 2.
Addition 2 ... DECIMALS dec
Effect This addition only makes sense when used with type P. The field
symbol contains dec decimal places.
Example Output sales in thousands:
DATA SALES_DEC2(10) TYPE P DECIMALS 2 VALUE 1234567.
FIELD-SYMBOLS <SALES_DEC5>.
ASSIGN SALES_DEC2 TO <SALES_DEC5> DECIMALS 5.
WRITE: / SALES_DEC2,
/ <SALES_DEC5>.
Output:
1,234,567.00
1,234.56700
Note This statement results in a runtime error if the field symbol
has a type other than P at runtime or the specified number of
decimal places is not in the range 0 to 14.
Addition 3 ... LOCAL COPY OF ...
Effect With LOCAL COPY OF, the ASSIGN</ > statement can only be used
in subroutines. This creates a copy of f which points to the
field symbol.
Note The field symbol <fs> must also be defined locally in the
subroutine.
Example
DATA X(4) VALUE 'Carl'.
PERFORM U.
FORM U.
FIELD-SYMBOLS <F>.
ASSIGN LOCAL COPY OF X TO <F>.
WRITE <F>.
MOVE 'John' TO <F>.
WRITE <F>.
WRITE X.
ENDFORM.
Output: Carl John Carl
Variant 2 ASSIGN (f) TO <fs>.
Additions:
1. ... TYPE typ
2. ... DECIMALS dec
3. ... LOCAL COPY OF ...
Effect Assigns the field whose name is stored in the field f to the
field symbol.
The statement "ASSIGN (f)+off(len) TO <fs>" is not allowed.
Notes - The search for the field to be assigned is performed as
follows:
1. If the statement is in a subroutine or function module, the
system first searches in this modularization unit.
2. If the statement lies outside any such modularization units
or if the field is not found there, the system searches for
the field in the global data of the program.
3. If the field is not found there, the system searches in the
table work areas of the main program of the current program
group declared with TABLES
- The name of the field to be assigned can also be the name of
a field symbol or formal parameter (or even a component of
one of these, if the field symbol or the parameter has a
structure).
- If the name of the field to be assigned is of the form
"(program name)field name", the system searches in the
global fields of the program with the name "Program name"
for the field with the name "Field name". However,it is only
found if the program has already been loaded.
Warning: This option is for internal use by specialists
only. Incompatible changes or developments may occur at any
time without warning or prior notice.
The return code value is set as follows:
SY-SUBRC = 0: The assignment was successful.
SY-SUBRC = 4: The field could not be assigned to the field
symbol.
Example
DATA: NAME(4) VALUE 'XYZ', XYZ VALUE '5'.
FIELD-SYMBOLS <F>.
ASSIGN (NAME) TO <F>.
WRITE <F>.
Output: 5
Addition 1 ... TYPE typ
Addition 2 ... DECIMALS dec
Addition 3 ... LOCAL COPY OF ...
Effect See similar additions of variant 1.
Variant 3 ASSIGN TABLE FIELD (f) TO <fs>.
Effect Identical to variant 2, except that the system searches for the
field f only in the data in the current program group declared
with TABLES.
The return code value is set as follows:
SY-SUBRC = 0: The assignment was successful.
SY-SUBRC = 4: The field could not be assigned to the field
symbol.
Example
TABLES TRDIR.
DATA NAME(10) VALUE 'TRDIR-NAME'.
FIELD-SYMBOLS <F>.
MOVE 'XYZ_PROG' TO TRDIR-NAME.
ASSIGN TABLE FIELD (NAME) TO <F>.
WRITE <F>.
Output: XYZ_PROG
Example
TABLES T100.
T100-TEXT = 'Global'.
PERFORM EXAMPLE.
FORM EXAMPLE.
DATA: BEGIN OF T100, TEXT(20) VALUE 'LOCAL', END OF T100,
NAME(30) VALUE 'T100-TEXT'.
FIELD-SYMBOLS <F>.
ASSIGN (NAME) TO <F>.
WRITE <F>.
ENDFORM.
Output: Local - although the global table field T100-TEXT has
"global" contents. (This kind of name assignment of work fields
is, of course, not recommended.)
Example
TABLES TRDIR.
DATA: F(8) VALUE 'F_global',
G(8) VALUE 'G_global'.
MOVE 'XYZ_PROG' TO TRDIR-NAME.
PERFORM U.
FORM U.
DATA: F(8) VALUE 'F_local',
NAME(30) VALUE 'F'.
FIELD-SYMBOLS <F>.
ASSIGN (NAME) TO <F>.
WRITE <F>.
MOVE 'G' TO NAME.
ASSIGN (NAME) TO <F>.
WRITE <F>.
MOVE 'TRDIR-NAME' TO NAME.
ASSIGN (NAME) TO <F>.
WRITE <F>.
ENDFORM.
Output: F_local G_global XYZ_PROG
Example
PROGRAM P1MAIN.
TABLES TRDIR.
DATA NAME(30) VALUE 'TFDIR-PNAME'.
FIELD-SYMBOLS <F>.
MOVE 'XYZ_PROG' TO TRDIR-NAME.
PERFORM U(P1SUB).
ASSIGN (NAME) TO <F>.
WRITE <F>.
CALL FUNCTION 'EXAMPLE'.
PROGRAM P1SUB.
TABLES TFDIR.
...
FORM U.
FIELD-SYMBOLS <F>.
DATA NAME(30) VALUE 'TRDIR-NAME'.
ASSIGN TABLE FIELD (NAME) TO <F>.
WRITE <F>.
MOVE 'FCT_PROG' TO TFDIR-PNAME.
ENDFORM.
FUNCTION-POOL FUN1.
FUNCTION EXAMPLE.
DATA NAME(30) VALUE 'TRDIR-NAME'.
FIELD-SYMBOLS <F>.
ASSIGN (NAME) TO <F>.
IF SY-SUBRC = 0.
WRITE <F>.
ELSE.
WRITE / 'TRDIR-NAME cannot be accessed'.
ENDIF.
ENDFUNCTION.
Output: XYZ_PROG FCT_PROG
TRDIR-NAME cannot be accessed
Example
TABLES TRDIR.
MOVE 'XYZ_PROG' to TRDIR-NAME.
PERFORM U USING TRDIR.
FORM U USING X STRUCTURE TRDIR.
FIELD-SYMBOLS <F>.
DATA NAME(30) VALUE 'X-NAME'.
ASSIGN (NAME) TO <F>.
WRITE <F>.
ENDFORM.
Output: XYZ_PROG
Variant 4 ASSIGN LOCAL COPY OF MAIN TABLE FIELD (f) TO <f>.
Additions:
1. ... TYPE typ
2. ... DECIMALS dec
Note This statement is for internal use only.
Incompatible changes or further developments may occur at any
time without warning or notice.
Effect Identical to variant 3, except that the system searches for the
field whose name is in f steht only in the data in the program
group of the main program declared with TABLES. However, the
field symbol then points not directly to the found field, but
to a copy of this field on theq value stack.
This variant therefore ensures that any access to Dictionary
fields of an external program group is read only and no changes
are made.
Example
PROGRAM P1MAIN.
TABLES TRDIR.
DATA NAME(30) VALUE 'TFDIR-PNAME'.
FIELD-SYMBOLS <F>.
MOVE 'XYZ_PROG' TO TRDIR-NAME.
CALL FUNCTION 'EXAMPLE'.
FUNCTION-POOL FUN1.
FUNCTION EXAMPLE.
DATA NAME(30) VALUE 'TRDIR-NAME'.
FIELD-SYMBOLS <F>.
ASSIGN LOCAL COPY OF MAIN
TABLE FIELD (NAME) TO <F>.
IF SY-SUBRC = 0.
WRITE <F>.
ELSE.
WRITE / 'TRDIR-NAME cannot be accessed'.
ENDIF.
ENDFUNCTION.
Output: XYZ_PROG
Addition 1 ... TYPE typ
Addition 2 ... DECIMALS dec
Effect See similar additions to variant 1.
Variant 5 ASSIGN COMPONENT idx OF STRUCTURE rec TO <fs>.
Variant 6 ASSIGN COMPONENT name OF STRUCTURE rec TO <fs>.
Additions:
1. ... TYPE typ
2. ... DECIMALS dec
Effect If the field name or idx has the type C or if it is a field
string with no internal table, it is treated as a component
name. Otherwise, it is considered as a component number. The
corresponding component of the field string rec is assigned to
the field symbol <fs>.
The return code value is set as follows:
SY-SUBRC = 0: The assignment was successful.
SY-SUBRC = 4: The field could not be assigned to the field
symbol.
Note If idx has the value 0, the entire field string is assigned to
the field symbol.
Example
PROGRAM P1MAIN.
DATA: BEGIN OF REC,
A VALUE 'a',
B VALUE 'b',
C VALUE 'c',
D VALUE 'd',
END OF REC,
CN(5) VALUE 'D'.
FIELD-SYMBOLS <FS>.
DO 3 TIMES.
ASSIGN COMPONENT SY-INDEX OF
STRUCTURE REC TO <FS>.
IF SY-SUBRC <> 0. EXIT. ENDIF.
WRITE <FS>.
ENDDO.
ASSIGN COMPONENT CN OF STRUCTURE REC TO <FS>.
WRITE <FS>.
Output: a b c d
Addition 1 ... TYPE typ
Addition 2 ... DECIMALS dec
Effect See similar additions to variant 1.
Note Runtime errors:
Depending on the operands, the ASSIGN statement can cause
runtime errors.
Note Performance:
For performance reasons, you are recommended to use typed field
symbols. The runtime for a typed ASSIGN statement amounts to
approx. 9 msn (standardized microseconds) against
approx. 13 msn for an untyped ASSIGN statement.
AT
Events in lists
- AT LINE-SELECTION.
- AT USER-COMMAND.
- AT PFn.
Events on selection screens
- AT SELECTION-SCREEN.
Control break with extracts
- AT NEW f.
- AT END OF f.
- AT FIRST.
- AT LAST.
- AT fg.
Control break with internal tables
- AT NEW f.
- AT END OF f.
- AT FIRST.
- AT LAST.
AT - control break
Variants:
1. AT NEW f.
2. AT END OF f.
3. AT FIRST.
4. AT LAST.
Variant 1 AT NEW f.
Variant 2 AT END OF f.
Effect f is a sub-field of an internal table or extract dataset
(EXTRACT) which is being processed with LOOP, i.e. the variants
1 and 2 only make sense within a LOOP.
Both "AT NEW f." and "AT END OF f." introduce processing blocks
which are concluded by "ENDAT.".
These processing blocks are processed whenever the contents of
a field f or a sub-field defined before f change as a result of
processing with LOOP. "AT NEW f." begins a new group of (table)
lines with the same contents as the field f while "AT END OF
f." concludes such a group.
Within the AT ... ENDAT processing of internal tables, all
argument fields following f are filled with "*".
Examples 1. AT for sub-fields of an internal table
DATA: BEGIN OF COMPANIES OCCURS 20,
NAME(30),
PRODUCT(20),
SALES TYPE I,
END OF COMPANIES.
...
LOOP AT COMPANIES.
AT NEW NAME.
NEW-PAGE.
WRITE / COMPANIES-NAME.
ENDAT.
WRITE: / COMPANIES-PRODUCT, COMPANIES-SALES.
AT END OF NAME.
SUM.
WRITE: / COMPANIES-NAME, COMPANIES-SALES.
ENDAT.
ENDLOOP.
The AT statements refer to the field COMPANIES-NAME.
Examples 2. AT for the field of an extract dataset
DATA: NAME(30),
SALES TYPE I.
FIELD-GROUPS: HEADER, INFOS.
INSERT: NAME INTO HEADER,
SALES INTO INFOS.
...
LOOP.
AT NEW NAME.
NEW-PAGE.
ENDAT.
...
AT END OF NAME.
WRITE: / NAME, SUM(SALES).
ENDAT.
ENDLOOP.
Notes 1. If the processing you want to perform on an internal table
is fairly restricted (i.e. a WHERE addition with the LOOP
statement), do not use the AT statements specified in
variants 1 to 5, since the interaction of the WHERE addition
and the AT statement is currently not defined.
2. When you use LOOP with an extract dataset, fields on hex
zero are ignored during control level checking with AT NEW
or AT END OF. This procedure is the same as the SORT
statement. When sorting extracted datasets, this statement
always sorts blank fields (i.e. fields on hex zero)
regardless of the sequence (ascending or descending) before
all fields that contain values.
3. Since fields addressed with AT are not set to an initial
value when you enter a LOOP, the first new group of (table)
lines in AT NEW f may not be processed, if f happens to be
set to this value.
Variant 3 AT FIRST.
Variant 4 AT LAST.
Effect The variants 3 and 4 only make sense within a LOOP.
The processing block between AT FIRST and ENDAT is executed
before the individual lines are processed; the processing block
between AT LAST and ENDAT is executed after all the individual
lines have been processed.
In AT FIRST or AT LAST ... ENDAT processing, all argument
fields are filled with "*" (internal tables).
When you are processing extract datasets, a control total
SUM(n) can only be processed with AT END OF or AT LAST.
Example
DATA: BEGIN OF COMPANIES OCCURS 20,
NAME(30),
PRODUCT(20),
SALES TYPE I,
END OF COMPANIES.
...
LOOP AT COMPANIES.
AT FIRST.
SUM.
WRITE: 'Sum of all SALES:',
55 COMPANIES-SALES.
ENDAT.
WRITE: / COMPANIES-NAME, COMPANIES-PRODUCT,
55 COMPANIES-SALES.
ENDLOOP.
AT - Control break with extracts
Variants:
1. AT NEW f.
2. AT END OF f.
3. AT FIRST.
4. AT LAST.
5. AT fg.
Effect In a LOOP which processes a dataset created with EXTRACT, you
can use special control structures for control break
processing. All these structures begin with AT and end with
ENDAT. The sequence of statements which lies between them is
then executed if a control break occurs.
You can use these key words for control break processing with
extract datasets only if the active LOOP statement is
proceesing an extract dataset.
The control level structure with extract datasets is dynamic.
It corresponds exactly to the sort key of the extract dataset,
i.e. to the order of fields in the field group HEADER by which
the extract dataset was sorted.
At the end of a control group (AT END OF, AT LAST), there are
two types of control level information between AT and ENDAT:
- If the sort key of the extract dataset contains a
non-numeric field h (particularly in the field group
HEADER), the field CNT(h) contains the number of control
breaks in the (subordinate) control level h.
- For extracted number fields g (see also ABAP/4 number
types), the fields SUM(g) contain the relevant control
totals.
Notes 1. The fields CNT(h) and SUM(g) can only be addressed after
they have been sorted. Otherwise, a runtime error may occur.
2. The fields CNT(h) and SUM(g) are filled with the relevant
values for a control level at the end of each control group
(AT END OF, AT LAST), not at the beginning (AT FIRST, AT
NEW).
3. When calculating totals with SUM(g), the system
automatically chooses the maximum field sizes so that an
overflow occurs only if the absolute value area limits are
exceeded.
4. You can also use special control break control structures
with LOOPs on internal tables.
Variant 1 AT NEW f.
Variant 2 AT END OF f.
Effect f is a field from the field group HEADER. The enclosed sequence
of statements is executed if
- the field f occurs in the sort key of the extract dataset
(and thus also in the field group HEADER) and
- the field f or a superior sort criterion has a different
value in the current LOOP line than in the prceding (AT NEW)
or subsequent (AT END OF) record of the extract dataset.
Example
DATA: NAME(30),
SALES TYPE I.
FIELD-GROUPS: HEADER, INFOS.
INSERT: NAME INTO HEADER,
SALES INTO INFOS.
...
LOOP.
AT NEW NAME.
NEW-PAGE.
ENDAT.
...
AT END OF NAME.
WRITE: / NAME, SUM(SALES).
ENDAT.
ENDLOOP.
Notes 1. If the extract dataset is not sorted before processing with
LOOP, no control level structure is defined and the
statements following AT NEW or AT END OF are not executed.
2. Fields which stand at hex zero are ignored by the control
break check with AT NEW or AT END OF. This corresponds to
the behavior of the SORT statement, which always places
unoccupied fields (i.e. fields which stand at hex zero)
before all occupied fields when sorting extract datasets,
regardless of whether the sort sequence is in ascending or
descending order.
Variant 3 AT FIRST.
Variant 4 AT LAST.
Effect Executes the relevant series of statements just once - either
on the first loop pass (with AT FIRST) or on the last loop pass
(with AT LAST).
Variant 5 AT fg.
Addition:
... WITH fg1
Effect This statement makes single record processing dependent on the
type of extracted record.
The sequence of statements following AT fg are executed
whenever the current LOOP record is created with EXTRACT fg (in
other words: when the current record is a fg record).
Addition ... WITH fg1
Effect Executes the sequence of statements belonging to AT fg WITH fg1
only if the record of the field group fg in the dataset is
immediately followed by a record of the field group fg1.
AT - field group definition
Basic form AT fg.
Addition:
... WITH fg1
Effect When you are processing an extract dataset (EXTRACT) in a LOOP,
this statement makes single record processing dependent on the
type of extracted record.
The processing block specified within AT fg ... ENDAT is
executed if the record just read was generated with EXTRACT fg
(i.e. if the record just read is an fg record).
Addition ... WITH fg1
Effect The processing block under AT fg WITH fg1. is executed only if
the record from the field group fg in the dataset is
immediately followed by a record from the field group fg1.
AT - Control break with internal tables
Variants:
1. AT NEW f.
2. AT END OF f.
3. AT FIRST.
4. AT LAST.
Effect In a LOOP which processes a dataset created with EXTRACT, you
can use special control structures for control break
processing. All these structures begin with AT and end with
ENDAT. The sequence of statements which lies between them is
then executed if a control break occurs.
You can use these key words for control break processing with
extract datasets only if the active LOOP statement is
proceesing an extract dataset.
The control level structure with extract datasets is dynamic.
It corresponds exactly to the sort key of the extract dataset,
i.e. to the order of fields in the field group HEADER by which
the extract dataset was sorted.
At the start of a new control level (i.e. immediately after
AT), the following occurs in the output area of the current
LOOP statement:
- All default key fields (on the right) are filled with "*"
after the current control level key.
- All other fields (on the right) are set to their initial
values after the current control level key.
Between AT and ENDAT, you can use SUM to insert the appropriate
control totals in the number fields (see also ABAP/4 number
types) of the LOOP output area (on the right) after the current
control level key. Summing is supported both at the beginning
of a control level (AT FIRST, AT NEW f) and also the end of a
control level (AT END OF f, AT LAST).
At the end of the control level processing (i.e. after ENDAT),
the old contents of the LOOP output area are restored.
Notes 1. When calculating totals, you must ensure that the totals are
inserted into the same sub-fields of the LOOP output area as
those where the single values otherwise occur. If there is
an overflow, processing terminates with a runtime error.
2. If an internal table is processed only in a restricted form
(using the additions FROM, TO and/or WHERE with the LOOP
statement), you should not use the control structures for
control level processing because the interaction of a
restricted LOOP with the AT statement is currenly not
properly defined.
3. With LOOPs on extracts, there are also special control break
control structures you can use.
Note Runtime errors:
- SUM_OVERFLOW: Overflow when calculating totals with SUM.
Variant 1 AT NEW f.
Variant 2 AT END OF f.
Effect f is a sub-field of an internal table processed with LOOP. The
sequence of statements which follow it is executed if the
sub-field f or a sub-field in the current LOOP line defined (on
the left) before f has a differnt value than in the preceding
(AT NEW) or subsequent (AT END OF) table line.
Example
DATA: BEGIN OF COMPANIES OCCURS 20,
NAME(30),
PRODUCT(20),
SALES TYPE I,
END OF COMPANIES.
...
LOOP AT COMPANIES.
AT NEW NAME.
NEW-PAGE.
WRITE / COMPANIES-NAME.
ENDAT.
WRITE: / COMPANIES-PRODUCT, COMPANIES-SALES.
AT END OF NAME.
SUM.
WRITE: / COMPANIES-NAME, COMPANIES-SALES.
ENDAT.
ENDLOOP.
The AT statements refer to the field COMPANIES-NAME.
Notes 1. If a control break criterion is not known until runtime, you
can use AT NEW (name) or AT END OF (name) to specify it
dynamically as the contents of the field name. If name is
blank at runtime, the control break criterion is ignored and
the sequence of statements is not executed. If name contains
an invalid component name, a runtime error occurs.
2. By defining an offset and/or length, you can further
restrict control break criteria - regardless of whether they
are specified statically or dynamically.
3. A field symbol pointing to the LOOP output area can also be
used as a dynamic control break criterion. If the field
symbol does not point to the LOOP output area, a runtime
error occurs.
Note Runtime errors:
- AT_BAD_PARTIAL_FIELD_ACCESS: Invalid sub-field access when
dynamically specifying the control break criterion.
- AT_ITAB_FIELD_INVALID: When dynamically specifying the
control break criterion via a field symbol, the field symbol
does not point to the LOOP output area.
- ITAB_ILLEGAL_COMPONENT: When dynamically specifying the
control break criterion via (name) the field name does not
contain a valid sub-field name.
Variant 3 AT FIRST.
Variant 4 AT LAST.
Effect Executes the appropriate sequence of statements once during the
first (AT FIRST) or last (AT LAST) loop pass.
Example
DATA: BEGIN OF COMPANIES OCCURS 20,
NAME(30),
PRODUCT(20),
SALES TYPE I,
END OF COMPANIES.
...
LOOP AT COMPANIES.
AT FIRST.
SUM.
WRITE: 'Sum of all SALES:',
55 COMPANIES-SALES.
ENDAT.
WRITE: / COMPANIES-NAME, COMPANIES-PRODUCT,
55 COMPANIES-SALES.
ENDLOOP.
AT - Events in lists
Variants:
1. AT LINE-SELECTION.
2. AT USER-COMMAND.
3. AT PFn.
Variant 1 AT LINE-SELECTION.
Effect Event in interactive reporting
This event is processed whenever the user chooses a valid line
in the list (i.e. a line generated by statements such as WRITE,
ULINE or SKIP) with the cursor and presses the function key
which has the function PICK in the interface definition. This
should normally be the function key F2, because it has the same
effect as double-clicking the mouse, or single-clicking in the
case of a hotspot.
The processing for the event AT LINE-SELECTION usually
generates further list output (the details list) which
completely covers the current list display. If the latter is
still visible (to aid user orientation), this may be due to the
key word WINDOW.
In most cases, the information is from the selected line is
used to retrieve more comprehensive information by direct
reading. When displaying the original list, you store the key
terms needed for this in the HIDE area of the output line.
Note You can choose a line and start new processing even in the
details lists.
The following system fields are useful for orientation
purposes, since their values change with each interactive event
executed.
SY-LSIND Index of list created by current event (basic
list = 0, 1st details list = 1, ...)
SY-PFKEY Status of displayed list (SET PF-STATUS)
SY-LISEL Contents of selected line
SY-LILLI Absolute number of this line in the displayed
list
SY-LISTI Index of this list - usually SY-LSIND - 1 (READ
LINE)
SY-CUROW Last cursor position: Line in window
SY-CUCOL Last cursor position: Column in window (GET
CURSOR)
SY-CPAGE 1st displayed page of displayed list
SY-STARO 1st displayed line of this page of displayed
list
SY-STACO 1st displayed column of displayed list (SCROLL
LIST)
The system field SY-LSIND defines the line selection level
(basic list: SY-LSIND = 0).
Example
DATA TEXT(20).
START-OF-SELECTION.
PERFORM WRITE_AND_HIDE USING SPACE SPACE.
AT LINE-SELECTION.
CASE TEXT.
WHEN 'List index'.
PERFORM WRITE_AND_HIDE USING 'X' SPACE.
WHEN 'User command'.
PERFORM WRITE_AND_HIDE USING SPACE 'X'.
WHEN OTHERS.
SUBTRACT 2 FROM SY-LSIND.
PERFORM WRITE_AND_HIDE USING SPACE SPACE.
ENDCASE.
CLEAR TEXT.
FORM WRITE_AND_HIDE USING P_FLAG_LSIND P_FLAG_UCOMM.
WRITE / 'SY-LSIND:'.
PERFORM WRITE_WITH_COLOR USING SY-LSIND P_FLAG_LSIND.
TEXT = 'List index'.
HIDE TEXT.
WRITE / 'SY-UCOMM:'.
PERFORM WRITE_WITH_COLOR USING SY-UCOMM P_FLAG_UCOMM.
TEXT = 'User command'.
HIDE TEXT.
IF SY-LSIND > 0.
WRITE / 'PICK here to go back one list level'.
ENDIF.
ENDFORM.
FORM WRITE_WITH_COLOR USING P_VALUE
P_FLAG_POSITIVE.
IF P_FLAG_POSITIVE = SPACE.
WRITE P_VALUE COLOR COL_NORMAL.
ELSE.
WRITE P_VALUE COLOR COL_POSITIVE.
ENDIF.
ENDFORM.
Depending on whether you choose the line at SY-LSIND or
SY-UCOMM, the next details list contains the corresponding
value with the color "positive". If the line is chosen without
HIDE information, the list level is reduced.
Variant 2 AT USER-COMMAND.
Effect Event in interactive reporting
This event is executed whenever the user presses a function key
in the list or makes an entry in the command field.
Some functions are executed directly by the system and thus
cannot be processed by programs. These include:
PICK See variant AT LINE-SELECTION
PFn See variant AT PFn
/... System command
%... System command
PRI Print
BACK Back
RW Cancel
P... Scroll function (e.g.: P, P-, PP3, PS-- etc.)
Instead of this functions, you can use the
SCROLL statement in programs.
Since many of these system functions begin with "P", you should
avoid using this letter to start your own function codes.
Otherwise, the effect is as for AT LINE-SELECTION; also, the
current function code is stored in the system field SY-UCOMM.
Example
DATA: NUMBER1 TYPE I VALUE 20,
NUMBER2 TYPE I VALUE 5,
RESULT TYPE I.
START-OF-SELECTION.
WRITE: / NUMBER1, '?', NUMBER2.
AT USER-COMMAND.
CASE SY-UCOMM.
WHEN 'ADD'.
RESULT = NUMBER1 + NUMBER2.
WHEN 'SUBT'.
RESULT = NUMBER1 - NUMBER2.
WHEN 'MULT'.
RESULT = NUMBER1 * NUMBER2.
WHEN 'DIVI'.
RESULT = NUMBER1 / NUMBER2.
WHEN OTHERS.
WRITE 'Unknown function code'.
EXIT.
ENDCASE.
WRITE: / 'Result:', RESULT.
After entry of a function code, the appropriate processing is
performed under the event AT USER-COMMAND and the result is
displayed in the details list.
Variant 3 AT PFn.
Effect Event in interactive reporting
Here, n stands for a numeric value between 0 and 99.
This event is executed whenever the user presses a function key
that contains the function code PFn in the interface
definition. The default status for lists contains some of these
functions.
Otherwise, the effect is as for the variant AT LINE-SELECTION.
The cursor can be on any line.
Notes 1. To ensure that the chosen function is executed only for
valid lines, you can check the current HIDE information.
2. This variant should be used only for test or prototyping
purposes, since the default status is not normally used.
Instead, you should set a program-specific status with SET
PF-STATUS. This should not contain any function codes
beginning with "PF".
Example
DATA NUMBER LIKE SY-INDEX.
START-OF-SELECTION.
DO 9 TIMES.
WRITE: / 'Row', (2) SY-INDEX.
NUMBER = SY-INDEX.
HIDE NUMBER.
ENDDO.
AT PF8.
CHECK NOT NUMBER IS INITIAL.
WRITE: / 'Cursor was in row', (2) NUMBER.
CLEAR NUMBER.
AT - Events on selection screens
Basic form AT SELECTION-SCREEN.
Additions:
1. ... ON psel
2. ... ON END OF sel
3. ... ON VALUE-REQUEST FOR psel_low_high.
4. ... ON HELP-REQUEST FOR psel_low_high
5. ... ON RADIOBUTTON GROUP radi
6. ... ON BLOCK block
7. ... OUTPUT
Effect This event only makes sense in reports, i.e. in programs set to
type 1 in the attributes. Type 1 programs are started via a
logical database and always have a selection screen where the
user can specify the database selections.
The event is processed when the selection screen has been
processed (at the end of PAI).
If an error message (MESSAGE Emnr) is sent during the event,
all fields on the selection screen become ready for input.
After further user input, AT SELECTION-SCREEN is executed
again.
Note You should only perform very expensive checks with AT
SELECTION-SCREEN if the program is then started (not every time
the user presses ENTER). Here, you can read the system field
SSCRFIELDS-UCOMM (provided a statement TABLES SSCRFIELDS
exists). If the field has one of the values 'ONLI' (= Execute)
or 'PRIN' (= Execute and Print), the report is then started,
i.e. the selection screen is closed and the processing
continues with START-OF-SELECTION. Remember that the selection
screen (and thus also AT SELECTION-SCREE N) is also processed
in variant maintenance and with SUBMIT VIA JOB. You can
determine which of these applies by calling the function module
RS_SUBMIT_INFO .
Addition 1 ... ON psel
Effect This event is assigned to the selection screen fields
corresponding to the report parameter or selection criterion
psel.
If the report starts an error dialog at this point, precisely
these fields become ready for input.
Addition 2 ... ON END OF sel
Effect For each selection criterion sel on the selection screen, you
can call a further screen by pressing a pushbutton. On this
screen, you can enter any number of single values and ranges
for the selection criterion sel.
When this screen has been processed (i.e. at the end of PAI for
this screen), the event AT SELECTION-SCREEN ON END OF sel is
executed.
At this point, all the values entered are available in the
internal table sel.
Addition 3 ... ON VALUE-REQUEST FOR psel_low_high
Effect With this addition, the field psel_low_high is either the name
of a report parameter or of the form sel-LOW or sel-HIGH, where
sel is the name of a selection criterion. The effect of this is
twofold:
1. The pushbutton for F4 (Possible entries) appears beside the
appropriate field.
2. When the user selects this pushbutton or presses F4 for the
field, the event is executed. You can thus implement a
self-programmed possible entries routine for the
input/output fields of the selection screen. If the program
contains such an event and the user presses F4, the system
processes this rather than displaying the check table or the
fixed values of the Dictionary field - even if the report
parameter or the selection option with LIKE or FOR points to
a Dictionary field. You can, for example, use the CALL
SCREEN statement to display a selection list of possible
values. The contents of the field psel_low_high at the end
of this processing block are copied to the appropriate
input/output field.
This addition is only allowed with report-specific parameters
(PARAMETERS) or selection options (SELECT-OPTIONS). For
database-specific parameters or selection options, you can
achieve the same effect by using the addition VALUE-REQUEST FOR
... with the key word PARAMETERS or SELECT-OPTIONS in the
include DBxyzSEL (where xyz = name of logical database). In
this case, you must program the value help in the database
program SAPDBxyz.
Addition 4 ... ON HELP-REQUEST FOR psel_low_high
Effect As with the addition ON VALUE-REQUEST the field psel_low_high
is either the name of a report parameter or of the form sel-LOW
or sel-HIGH, where sel is the name of a selection criterion.
When the user presses F1 on the relevant field, the subsequent
processing block is executed. You can thus implement a
self-programmed help for the input/output fields of the
selection screen. If the program contains such an event and the
user presses F1, the system processes this rather than
displaying the documentation of the Dictionary field - even if
the report parameter or the selection option with LIKE or FOR
points to a Dictionary field.
This addition is only allowed with report-specific parameters
(PARAMETERS) or selection options (SELECT-OPTIONS). For
database-specific parameters or selection options, you can
achieve the same effect by using the addition HELP-REQUEST FOR
... with the key word PARAMETERS or SELECT-OPTIONS in the
include DBxyzSEL (where xyz = name of logical database). In
this case, you must program the help in the database program
SAPDBxyz.
Addition 5 ... ON RADIOBUTTON GROUP radi
Effect This event is assigned to the radio button groups on the
selection screen defined by PARAMETERS par RADIOBUTTON GROUP
radi.
If the report starts an error dialog at this point, precisely
these fields of the radio button group radi become ready for
input again.
Addition 6 ... ON BLOCK block
Effect This event is assigned to the blocks on the selection screen
defined by SELECTION-SCREEN BEGIN/END OF BLOCK block.
If the report starts an error dialog at this point, precisely
these fields of the block block become ready for input again.
Note In which sequence are the events AT SELECTION-SCREEN ON psel
..., AT SELECTION-SCREEN ON RADIOBUTTON GROUP ..., AT
SELECTION-SCREEN ON BLOCK ..., AT SELECTION-SCREEN processed?
The AT SELECTION-SCREEN ON psel ... events assigned to the
parameters or selection options are executed in the sequence
they are declared in the program, i.e. in the sequence they
appear on the selection screen.
The events assigned to the radio button groups are executed
according to the first parameter of the radio button group.
The events assigned to the blocks are executed "from the inside
to the outside".
Example
SELECT-OPTIONS SEL0 FOR SY-TVAR0.
SELECTION-SCREEN BEGIN OF BLOCK BL0.
SELECT-OPTIONS SEL1 FOR SY-TVAR1.
SELECTION-SCREEN BEGIN OF BLOCK BL1.
PARAMETERS P0 RADIOBUTTON GROUP RADI.
PARAMETERS P1 RADIOBUTTON GROUP RADI.
SELECTION-SCREEN BEGIN OF BLOCK BL2.
PARAMETERS P3.
SELECTION-SCREEN END OF BLOCK BL2.
SELECT-OPTIONS SEL2 FOR SY-TVAR2.
SELECTION-SCREEN END OF BLOCK BL1.
SELECTION-SCREEN END OF BLOCK BL0.
Sequence:
AT SELECTION-SCREEN ON...
SEL0
SEL1
RADIOBUTTON GROUP RADI
P3
BLOCK BL2
SEL2
BLOCK BL1
BLOCK BL0
AT SELECTION-SCREEN is executed at the very end.
Addition 7 ... OUTPUT
Effect This event is executed at PBO of the selection screen every
time the user presses ENTER - in contrast to INITIALIZATION.
Therefore, this event is not suitable for setting selection
screen default values. Also, since AT SELECTION-SCREEN OUTPUT
is first executed after the variant is imported (if a variant
is used) and after adopting any values specified under SUBMIT
in the WITH clause, changing the report parameters or the
selection options in AT SELECTION-SCREEN OUTPUT would destroy
the specified values.
Here, however, you can use LOOP AT SCREEN or MODIFY SCREEN to
change the input/output attributes of selection screen fields.
Example Output all fields of the SELECT-OPTION NAME highlighted:
SELECT-OPTIONS NAME FOR SY-REPID MODIF ID XYZ.
...
AT SELECTION-SCREEN OUTPUT.
LOOP AT SCREEN.
CHECK SCREEN-GROUP1 = 'XYZ'.
SCREEN-INTENSIFIED = '1'.
MODIFY SCREEN.
ENDLOOP.
The addition MODIF ID XYZ to the key word SELECT-OPTIONS
assigns all fields of the selection option NAME to a group you
can read in the field SCREEN-GROUP1. At PBO of the selection
screen, all these fields are then set to highlighted.
Note In the context of event processing, the SET PF-STATUS statement
does not work. Instead, you must set a status using the
function module RS_SET_SELSCREEN_STATUS or
RS_EXTERNAL_SELSCREEN_STATUS.
AUTHORITY-CHECK
Basic form AUTHORITY-CHECK OBJECT object
ID name1 FIELD f1
ID name2 FIELD f2
...
ID name10 FIELD f10.
Effect Explanation of IDs:
object Field which contains the name of the object for
which the authorization is to be checked.
name1 ... Fields which contain the names of the
name10 authorization fields defined in the object.
f1 ... Fields which contain the values for which the
f10 authorization is to be checked.
AUTHORITY-CHECK checks for one object whether the user has an
authorization that contains all values of f (see SAP
authorization concept).
You must specify all authorizations for an object and a also a
value for each ID (or DUMMY).
The system checks the values for the IDs by AND-ing them
together, i.e. all values must be part of an authorization
assigned to the user.
If a user has several authorizations for an object, the values
are OR-ed together. This means that if the CHECK finds all the
specified values in one authorization, the user can proceed.
Only if none of the authorizations for a user contains all the
required values is the user rejected.
If the return code SY-SUBRC = 0, the user has the required
authorization and may continue.
The return code is modified to suit the different error
scenarios. The return code values have the following meaning:
4 User has no authorization in the SAP System for
such an action. If necessary, change the user
master record.
8 Too many parameters (fields, values). Maximum
allowed is 10.
12 Specified object not maintained in the user
master record.
16 No profile entered in the user master record.
24 The field names of the check call do not match
those of an authorization. Either the
authorization or the call is incorrect.
28 Incorrect structure for user master record.
32 Incorrect structure for user master record.
36 Incorrect structure for user master record.
If the return code value is 8 or possibly 24, inform the person
responsible for the program. If the return code value is 4, 12,
15 or 24, consult your system administrator if you think you
should have the relevant authorization. In the case of errors
28 to 36, contact SAP, since authorizations have probably been
destroyed.
Individual authorizations are assigned to users in their
respective user profiles, i.e. they are grouped together in
profiles which are stored in the user master record.
Note Instead of ID name FIELD f, you can also write ID name DUMMY.
This means that no check is performed for the field concerned.
The check can only be performed on CHAR fields. All other field
types result in 'unauthorized'.
Example Check whether the user is authorized for a particular plant. In
this case, the following authorization object applies:
Table OBJ: Definition of authorization object
M_EINF_WRK
ACTVT
WERKS
Here, M_EINF_WRK is the object name, whilst ACTVT and WERKS are
authorization fields. For example, a user with the
authorizations
M_EINF_WRK_BERECH1
ACTVT 01-03
WERKS 0001-0003 .
can display and change plants within the Purchasing and
Materials Management areas.
Such a user would thus pass the checks
AUTHORITY-CHECK OBJECT 'M_EINF_WRK'
ID 'WERKS' FIELD '0002'
ID 'ACTVT' FIELD '02'.
AUTHORITY-CHECK OBJECT 'M_EINF_WRK'
ID 'WERKS' DUMMY
ID 'ACTVT' FIELD '01':
but would fail the check
AUTHORITY-CHECK OBJECT 'M_EINF_WRK'
ID 'WERKS' FIELD '0005'
ID 'ACTVT' FIELD '04'.
To suppress unnecessary authorization checks or to carry out
checks before the user has entered all the values, use DUMMY> -
as in this example. You can confirm the authorization later
with another AUTHORITY-CHECK.
BACK
Basic form BACK.
Effect Returns output position to the first line of the current page
after the TOP-OF-PAGE processing.
When used in connection with RESERVE x LINES, the statement
returns the output position to the first output line after
RESERVE.
Example
DATA: TOWN(10) VALUE 'New York',
CUSTOMER1(10) VALUE 'Charly',
CUSTOMER2(10) VALUE 'Sam',
SALES1 TYPE I VALUE 1100,
SALES2 TYPE I VALUE 2200.
RESERVE 2 LINES.
WRITE: TOWN, CUSTOMER1,
/ CUSTOMER2 UNDER CUSTOMER1.
BACK.
WRITE: 50 SALES1,
/ SALES2 UNDER SALES1.
Using the positioning in WRITE in column 50, data not yet
output is not overwritten, but the sales volume is output after
the customer names.
Notes 1. If you use a '/' with the first WRITE after the BACK
statement, this starts a (usually unwanted) new line.
2. BACK in the TOP-OF-PAGE processing positions the cursor
after the standard header. Subsequent WRITE statements also
overwrite the lines output under TOP-OF-PAGE.
Note Performance:
The runtime required to execute a BACK statement is about 1 msn
(standardized microseconds).
BREAK-POINT
Variants:
1.BREAK-POINT.
2.BREAK-POINT f.
Variant 1 BREAK-POINT.
Effect The BREAK-POINT statement interrupts the processing and diverts
the system to debugging mode. You can then display the contents
of all the fields at runtime and also control the subsequent
program flow.
If the system is unable to branch to debugging for some reason
(due to a background job or update), it generates a system log
message.
Note - After the BREAK-POINT, the system automatically performs any
restart in the database, if no COMMIT WORK was executed.
Since debugging sometimes switches off COMMIT WORK, you
should not place a BREAK-POINT statement in a SELECT loop.
- In the editor, you can also set a breakpoint dynamically
without making any changes to the ABAP/4 program. These
dynamic breakpoints are valid only for the current user in
the current session.
Variant 2 BREAK-POINT f.
Effect Behaves like variation 1, except that the field contents of f
remain in the event of any system log messages.
CALL
Call a function module
- CALL FUNCTION func.
- CALL FUNCTION func STARTING NEW TASK taskname.
- CALL FUNCTION func IN UPDATE TASK.
- CALL FUNCTION func DESTINATION dest.
- CALL FUNCTION func IN BACKGROUND TASK.
- CALL CUSTOMER-FUNCTION func.
Call a screen
- CALL SCREEN scr.
Call a transaction
- CALL TRANSACTION tcod.
Call a dialog module
- CALL DIALOG dial.
Call a method of an external object
- CALL METHOD OF obj m.
Call a system function
- CALL cfunc.
CALL - Call a system function
Note This statement is for internal use only.
Incompatible changes or further developments may occur at any
time without warning or notice.
Basic form 6 CALL cfunc.
Addition:
... ID id1 FIELD f1 ... ID idn FIELD fn
Effect Calls the system function cfunc. The relevant function must
exist in the file sapactab.h. If you change or recreate a
function, you have to compile and link the SAP kernel again.
For this, you need the C source code files.
Normally, external programs should be called via RFC with CALL
FUNCTION ... DESTINATION.
Addition ... ID id1 FIELD f1 ... ID idn FIELD fn
Effect Passes fields to the called program by reference. With "ID
id1", you specify the name of a formal parameter, and with
"FIELD f1" the relevant field from the ABAP/4 program. If a
formal parameter expects an internal table, the latter is
passed in the form "FIELD tab[]".
Example
DATA RESULT(8).
CALL 'MULTIPLY' ID 'P1' FIELD '9999'
ID 'P2' FIELD '9999'
ID 'RES' FIELD RESULT.
Note Runtime errors:
CALL_C_FUNCTION_NOT_FOUND: Specified system function is
unknown.
CALL FUNCTION
Variant 6 CALL CUSTOMER-FUNCTION func.
Additions:
The same as for CALL FUNCTION func.
Effect Calls the function module func. func must be a 3-character
literal (e.g. '001')
In line with SAP's enhancement concept, function modules are
delivered empty and must be implemented by the customer (the
transactions used for this are SMOD at SAP and CMOD at the
customer's).
The interface and call location are both defined by SAP.
Note The customer can use Transaction CMOD to activate the function
module. The final name of the function module is compiled from
EXIT_, the name of the module pool where the function module is
called, and the name func. For example, the statement "CALL
CUSTOMER-FUNCTION '001'" in the module pool SAPMS38M calls the
function module EXIT_SAPMS38M_001.
CALL DIALOG - Call a dialog module
CALL DIALOG dial.
Additions:
1. ... AND SKIP FIRST SCREEN
2. ... EXPORTING f1 FROM g1 ... fn FROM gn
3. ... IMPORTING f1 TO g1 ... fn TO gn
4. ... USING itab ... MODE mode.
Effect Calls the dialog module dial; dial can be a literal or a
variable.
To edit dialog modules, select Tools -> ABAP/4 Workbench ->
Development -> Programming environ. -> Dialog modules.
Addition 1 ... AND SKIP FIRST SCREEN
Effect Processes the first screen of the dialog module in the
background, if all required entry fields have been filled.
Addition 2 ... EXPORTING f1 FROM g1 ... fn FROM gn
Effect Specifies all data objects (fields, field strings, internal
tables) to be passed to the dialog module. If the names in the
calling and called programs are identical, you can omit "FROM
g1". Otherwise, fi refers to the field in the dialog module,
while gi specifies the field in the calling program.
Addition 3 ... IMPORTING f1 TO g1 ... fn TO gn
Effect Specifies all data objects (fields, field strings, internal
tables) to be returned from the dialog module. If the names in
the calling and called programs are identical, you can omit "TO
g1". Otherwise, fi refers to the field in the dialog module,
while gi specifies the field in the calling program.
Examples
DATA: BEGIN OF ITAB,
LINE(72),
END OF ITAB,
TITLE LIKE SY-TITLE.
CALL DIALOG 'RS_EDIT_TABLE'
EXPORTING SOURCETAB FROM ITAB
TITLE
IMPORTING SOURCETAB TO ITAB.
Notes - The system field SY-SUBRC is automatically exported and
imported.
- The unknown export/import data in the dialog module is
ignored.
- The data objects passed should have the same type or
structure in the calling program and the dialog module.
Addition 4 ... USING itab ... MODE mode
Effect Calls the dialog module dial and also passes the internal table
itab which contains one or more screens in batch input format.
If required, the dialog module may return a message to the
system fields SY-MSGID, SY-MSGTY, SY-MSGNO, SY-MSGV1, ...,
SY-MSGV4.
The specified processing mode mode mode can accept the
following values:
'A' Display screen
'E' Display only if an error occurs
'N' No display
If the addition MODE is not specified, the processing mode is
'A'.
The return code value is set as follows:
SY-SUBRC = 0: The processing was successful.
SY-SUBRC <> 0: The dialog ended with an error.
Notes - All lock arguments are automatically exported and imported.
In contrast to a transaction, a dialog module does not form
its own LUW (see Transaction processing). Any update
requests which occur there are not processed until the
calling program executes a COMMIT WORK.
- To return from the dialog module, use the key word LEAVE
PROGRAM.
Note Runtime errors:
- CALL_DIALOG_NOT_FOUND: The called dialog module is unknown.
- CALL_DIALOG_WRONG_TDCT_MODE: The called dialopg module
contains errors (incorrect entry in table TDCT).
- CALL_DIALOG_NAME_TOO_LONG: The name of a parameter is longer
than permitted.
- CALL_DIALOG_NO_CONTAINER: No memory for parameter transfer.
Related CALL TRANSACTION, CALL FUNCTION
CALL - call a function module
Variants:
Call a function module:
1. CALL FUNCTION func.
Call a function module in a different mode (asynchronous Remote
Function Call):
2. CALL FUNCTION func STARTING NEW TASK taskname.
Call a function module in the update task:
3. CALL FUNCTION func IN UPDATE TASK.
Call a function module in a remote system (Remote Function
Call, RFC):
4. CALL FUNCTION func DESTINATION dest.
Asynchronous call to a function module with transactional
processing (transactional Remote Function Call):
5. CALL FUNCTION func IN BACKGROUND TASK.
Call a function module which can be activated in the context of
enhancements:
6. CALL CUSTOMER-FUNCTION func.
CALL FUNCTION
Variant 1 CALL FUNCTION func.
Additions:
1. ... EXPORTING p1 = f1 ... pn = fn
2. ... IMPORTING p1 = f1 ... pn = fn
3. ... TABLES p1 = itab1 ... pn = itabn
4. ... CHANGING p1 = f1 ... pn = fn
5. ... EXCEPTIONS except1 = rc1 ... exceptn = rcn
Effect Calls the function module func; func can be a literal or a
variable.
To edit function modules, select Tools -> ABAP/4 Workbench ->
Function Library.
The assignment of parameters is by name (p1, p2, etc.), not by
sequence.
To return from the function module, you use the key word EXIT,
unless EXIT occurs in a loop or a subroutine.
Note You can use the editor commands "SHOW FUNCTION func" and "SHOW
FUNCTION *" to get information about the function module func
or any other function module.
Addition 1 ... EXPORTING p1 = f1 ... pn = fn
Effect EXPORTING passes fields, field strings or internal tables to
the function module. You must declare the parameters p1 ... pn
in the function interface as import parameters. When you call
the function module, you must assign values to all import
parameters which are not flagged in the interface definition as
optional and do not have any default values.
Addition 2 ... IMPORTING p1 = f1 ... pn = fn
Effect IMPORTING passes fields, field strings or internal tables from
the function module back to the calling program. The parameters
p1 ... pn must be declared as export parameters in the function
interface.
Addition 3 ... TABLES p1 = itab1 ... pn = itabn
Effect TABLES passes references to internal tables. The parameters p1
... pn must be declared as table parameters in the function
interface. When you call the function module, you must assign
values to all table parameters which are not flagged as
optional in the interface definition.
Addition 4 ... CHANGING p1 = f1 ... pn = fn
Effect CHANGING passes fields, field strings or internal tables to the
function module and the changed values are returned. The
parameters p1 ... pn must be declared as CHANGING parameters in
the function interface. When you call the function module, you
must assign values to all CHANGING parameters of the function
module which are not flagged as optional in the interface
definition and have no default values.
Addition 5 ... EXCEPTIONS except1 = rc1 ...
exceptn = rcn
Effect EXCEPTIONS lists the exceptions to be handled by the calling
program itself. At the end of the exception list, you can use
OTHERS to refer to all the remaining exceptions.
If one of the listed exceptions occurs, SY-SUBRC is set to the
appropriate value rc (a number literal!) and control passes
back to the calling program. By specifying a return code, you
can divided the exceptions into classes. With the second form,
without "=rc", SY-SUBRC is set to a value other than 0 if an
exception occurs.
If the function module triggers an exception (with the
statements RAISE and MESSAGE ... RAISING) and the exception is
not to be handled by the calling program itself,
- RAISE terminates the program with a runtime error;
- MESSAGE ... RAISING outputs the message.
Note The following EXCEPTIONS are predefined by the system and have
a special meaning:
- OTHERS: Covers all user-defined exceptions in the called
function module.
- ERROR_MESSAGE: This exception instructs the system to ignore
S messages, I messages and W messages until return from the
function module (although they still appear in the log
during background processing). When an E message or an A
message occurs, the called function module terminates, as if
the exception ERROR_MESSAGE has been triggered.
Examples
DATA: FIELD(30) VALUE 'Example: This is a field.',
head(30).
CALL FUNCTION 'STRING_SPLIT'
EXPORTING DELIMITER = ':'
STRING = FIELD
IMPORTING HEAD = HEAD
TAIL = FIELD
EXCEPTIONS NOT_FOUND = 1
OTHERS = 2.
CASE SY-SUBRC.
WHEN 1. ...
WHEN 2. ....
ENDCASE.
...
DATA: BEGIN OF TAB1 OCCURS 10, X, END OF TAB1,
BEGIN OF TAB2 OCCURS 20, Y, END OF TAB2.
CALL FUNCTION 'ITAB_COPY'
TABLES TAB_IN = TAB1
TAB_OUT = TAB2.
Note Runtime errors:
- CALL_FUNCTION_NOT_FOUND: The called function is unknown.
- CALL_FUNCTION_NO_VB: Only update function modules can be
called in the update task.
- CALL_FUNCTION_NOT_ACTIVE: The called function is known, but
not active.
- CALL_FUNCTION_PARM_MISSING: The function expects a
parameter, but none was passed by the calling program.
- CALL_FUNCTION_PARM_UNKNOWN: The calling program passed a
parameter which the function does not recognize.
- CALL_FUNCTION_CONFLICT_LENG: The function expected a
different actual parameter length.
- CALL_FUNCTION_CONFLICT_TYPE
- CALL_FUNCTION_CONFLICT_GEN_TYP: The actual parameter type
does not satisfy the requirements of the function interface.
- CALL_FUNCTION_WRONG_ALIGNMENT: An actual parameter does not
satisfy the alignment requirements of the corresponding
formal parameter.
- CALL_FUNCTION_BASE_LITL: A literal was supposed to be passed
to a structured formal parameter.
CALL FUNCTION
Variants:
Call a function module
1. CALL FUNCTION func.
Call a function module in new mode (asynchronous Remote
Function Call)
2. CALL FUNCTION func STARTING NEW TASK taskname dest.
Call a function module in the update task
3. CALL FUNCTION func IN UPDATE TASK.
Call a function module in a remote system (Remote Function
Call)
4. CALL FUNCTION func DESTINATION dest.
Asynchronous call to function module with transaction-like
processing (transaction-like Remote Function Call)
5. CALL FUNCTION func IN BACKGROUND TASK.
Call a function module that can be activated within framework
of enhancement concept.
6. CALL CUSTOMER-FUNCTION func.
CALL FUNCTION
Variant 5 CALL FUNCTION func IN BACKGROUND TASK.
Additions:
1. ... DESTINATION dest
2. ... EXPORTING p1 = f1 ... pn = fn
3. ... TABLES p1 = itab1 ... pn = itabn
Effect Flags the function module func to be run asynchronously. It is
not executed at once, but the data passed with EXPORTING bzw.
TABLES is placed in a database table and the next COMMIT WORK
then executes the function module in another work process.
Note This variant applies only from R/3 Release 3.0. Both partner
systems (the client and the server systems) must have a Release
3.0 version of the R/3 System.
Addition 1 ... DESTINATION dest
Effect Executes the function module externally as a Remote Function
Call (RFC); dest can be a literal or a variable.
Depending on the specified destination, the function module is
executed either in another R/3 System or as a C-implemented
function module. Externally callable function modules must be
flagged as such in the function library (of the target system).
Since each destination defines its own program context, further
calls to the same or different function modules with the same
destination can access the local memory (global data) of these
function modules.
Addition 2 ... EXPORTING p1 = f1 ... pn = fn
Effect EXPORTING passes values of fields and field strings from the
calling program to the function module. In the function module,
the formal parameters are defined as import parameters. Default
values must be assigned to all import parameters of the
function module in the interface definition.
Addition 3 ... TABLES p1 = itab1 ... pn = itabn
Effect TABLES passes references to internal tables. All table
parameters of the function module must contain values.
Notes
If several function module calls with the same destination are
specified before COMMIT WORK, these form an LUW in the target
system.
Type 2 destinations (R/3 - R/2 connections) cannot be
specified.
CALL FUNCTION
Variant 6 CALL CUSTOMER-FUNCTION func.
Additions:
The same as with CALL FUNCTION func.
Effect Calls the function module func; this can be activated. func
must be a 3-character literal (e.g. '001').
The function modules are delivered empty within the framework
of the enhancement concept and must be implemented by the
customer. They are maintained with the Transactions SMOD (at
SAP) and CMOD (at the csutomer's).
SAP determines both the interface and the place where the call
is made.
Note By using the Transaction CMOD, the customer can activate the
function module. The final name of the function module
comprises EXIT_, the name of the module pool where the function
module is called, and the name func. For example, the statement
"CALL CUSTOMER-FUNCTION '001'" in the module pool SAPMS38M
calls the function module EXIT_SAPMS38M_001.
CALL FUNCTION
Variant 4 CALL FUNCTION func DESTINATION dest.
Additions:
1. The same as with CALL FUNCTION func
2. ... EXCEPTIONS syst_except = rc MESSAGE mess
Effect Executes the function module externally as a Remote Function
Call (RFC); dest can be a literal or a variable.
Depending on the specified destination, the function module is
executed in another R/3 or R/2 System. Externally callable
function modules must be flagged as such in the function
library (of the target system).
Since each destination defines its own program context, further
calls to the same or different function modules with the same
destination can access the local memory (global data) of these
function modules.
You can maintain existing destinations by selecting Tools ->
Administration -> Administration -> Network -> RFC
destinations.
Notes Special destinations:
- The destination NONE refers to the calling system. Function
modules called with
CALL FUNCTION func DESTINATION 'NONE' ...
are executed in the system of the calling program, but in
their own program context.
- You can use the destination BACK if the current program was
already called by RFC. The, BACK refers back to the calling
program:
CALL FUNCTION func DESTINATION 'BACK' ...
If the program is not called from a "remote" source, the
exception COMMUNICATION_FAILURE is triggered.
- Each R/3 System has a standard name. This is formed from the
host name (e.g. SY-HOST), the system name (SY-SYSID) and the
system nummer (two-character number assigned on installation
of the applications server).
You can use this name as a destination. For example, you can
call the function module func in the system C11 on the host
sapxyz with system number 00 as follows:
CALL FUNCTION func DESTINATION 'sapxyz_C11_00' ...
- You can also use saprouter path names as destinations (see
also saprouter documentation).
Note Parameter passing. When you pass data to an externally called
function module, there are some differences to the normal
function module call:
- With table parameters, only the table itself is passed, not
the header line.
- If one of the parameters of the interface of an externally
called function module is not specified when called, the
import parameters are set to their initial value. If no
default value was given in the interface definition, TABLES
parameters are defined as an empty table and unspecified
export parameters are lost.
Note Passing structured data objects. Since transport to another
system may require data conversion, the structure of field
strings and internal tables must be known to the runtime system
when the call is made. The structure of a field string or
internal table is not known if it was defined with
... LIKE structure,
if the structure passed was passed to the subroutine with the
explicit addition STRUCTURE, or if it is a parameter of a
function module.
In these cases, external calls can result in a conversion
error.
Note C interface. You can call externally callable function modules
from C programs. It is also possible to store function modules
in a C program and call them via CALL FUNCTION ... DESTINATION.
For this purpose, SAP provides a C interface.
Addition 2 ... EXCEPTIONS syst_except = rc MESSAGE mess
Effect Function module calls with the addition DESTINATION can handle
two special system exceptions:
SYSTEM_FAILURE
This is triggered if a system crash occurs on
the receiving side.
COMMUNICATION_FAILURE
This is triggered if there is a connection or
communication problem.
In both cases, you can use the optional addition
... MESSAGE mess
to receive a description of the error.
Note Runtime errors:
- CALL_FUNCTION_DEST_TYPE:Destination type not allowed.
- CALL_FUNCTION_NO_DEST:Destination does not exist.
- CALL_FUNCTION_NO_LB_DEST:Destination (in 'Load Balancing'
mode) does not exist.
- CALL_FUNCTION_TABINFO:Data error (info internal table)
during 'Remote Function Call'.
CALL FUNCTION
Variant 2 CALL FUNCTION func ...STARTING NEW TASK taskname.
Additions:
1. ... DESTINATION dest
2. ... PERFORMING form ON END OF TASK
3. ... EXPORTING p1 = f1 ... pn = fn
4. ... TABLES p1 = itab1 ... pn = itabn
5. ... EXCEPTIONS syst_except = rc MESSAGE mess
Effect Starts the function module func asynchronously in a new mode.
In contrast to normal function module calls, the calling
program resumes processing as soon as the function module is
started in the target system. It does not wait until the
function module has finished. Through CALL SCREEN, the called
function module can, for example, display a screen and thus
interact with the user.
Notes This variant applies only from R/3 Release 3.0. Both partner
systems (the client and the server systems) must have a Release
3.0 version of the R/3 System.
With this variant, the called function module must also be
flagged in the Function Library as externally callable, even if
it is executed locally (without the addition DESTINATION).
Addition 1 ... DESTINATION dest
Effect Executes the function module externally as a Remote Function
Call (RFC); dest can be a literal or a variable. The R/3 System
where the function module is executed depends on the specified
destination. Externally callable function modules must be
flagged as such in the Function Library (of the target system).
Addition 2 ... PERFORMING form ON END OF TASK
Whereas the parameters for receiving results (i.e. IMPORTING
and TABLES parameters) are specified directly as additions in
the case of "conventional" function modules (see variant 2),
these are logged in the FORM routine form when making an
asynchronous call (see RECEIVE).
Note If a function module returns no result, this addition (...
PERFORMING form ON END OF TASK) can be omitted.
Addition 3 ... EXPORTING p1 = f1 ... pn = fn
Effect EXPORTING passes values of fields and field strings from the
calling program to the function module. In the function module,
the formal parameters are defined as import parameters.
Addition 4 ... TABLES p1 = itab1 ... pn = itabn
Effect TABLES passes references to internal tables. All table
parameters of the function module must contain values.
Addition 5 ... EXCEPTIONS syst_except = rc MESSAGE mess
Effect While any exceptions arising in the called function module are
handled by the second addition (in the FORM routine), this
addition can handle two special system exceptions, as with
function module calls with the addition DESTINATION:
SYSTEM_FAILURE
is triggered, if a system crash occurs on the
receiving side.
COMMUNICATION_FAILURE
is triggered if there is a connection or
communication problem.
In both cases, you can get a description of the error with the
optional addition
... MESSAGE mess
Example
DATA: MSG_TEXT(80). "Message text
...
Asynchronous call to Transaction SM59 -->
Create a new session
CALL FUNCTION 'ABAP4_CALL_TRANSACTION' STARTING NEW TASK 'TEST'
DESTINATION 'NONE'
EXPORTING
TCODE = 'SM59'
EXCEPTIONS COMMUNICATION_FAILURE MESSAGE MSG_TEXT.
IF SY-SUBRC NE 0.
WRITE: MSG_TEXT.
ELSE.
WRITE: 'O.K.'.
ENDIF.
Note Runtime errors:
- CALL_FUNCTION_TASK_YET_OPEN: Task already open.
CALL FUNCTION
Variant 3 CALL FUNCTION func IN UPDATE TASK.
Additions:
1. ... EXPORTING p1 = f1 ... pn = fn
2. ... TABLES p1 = itab1 ... pn = itabn
Effect Flags the function module func for execution in the update
task. It is not executed at once, but the data passed with
EXPORTING or TABLES is placed in a database table and a
subsequent COMMIT WORK then causes the function module to be
executed by the update task. Update function modules must be
flagged as such in the function library.
Addition 1 ... EXPORTING p1 = f1 ... pn = fn
Effect Values of fields and field strings specified under EXPORTING
are passed from the calling program to the function module. In
the function module, the formal parameters are defined as
import parameters. In the interface definition, default values
must be assigned to all import parameters of the update
function module.
Addition 2 ... TABLES p1 = itab1 ... pn = itabn
Effect TABLES passes references to internal tables. All table
parameters of the function module must have values.
Note With update function modules, both import parameters and
exceptions are ignored when the call is made.
Administration transaction
CALL METHOD - Call a method of an external object
Basic form CALL METHOD OF obj m.
Additions:
1. ... = f
2. ... EXPORTING p1 = f1 ... pn = fn
3. ... NO FLUSH
Effect Calls the method m of the object obj. m can be a literal or a
variable.
Normally, all consecutive OLE statements are buffered by the
ABAP/4 processor and sent to the presentation server in bundled
form. This means that it is possible for a statement to refer
to the results of preceding statements.
In debugging, however, you should remember that the values of
the return parameters cannot be displayed until directly before
execution of the first ABAP/4 statement external to OLE.
Even a command which refers to an object not yet generated by
any OLE statement terminates the bundling.
The return code value of SY-SUBRC indicates whether all the
bundled commands have been successfully executed.
The return code value is set as follows:
SY-SUBRC = 0: All commands were successfully executed.
SY-SUBRC = 1: When communicating with the presentation
server, a system error occurred. The
system field SY-MSGLI contains a short
description of the error.
SY-SUBRC = 2: A method call resulted in an error.
SY-SUBRC = 3: Setting a property resulted in an error.
SY-SUBRC = 4: Reading a property resulted in an error.
In the last 3 cases, a dialog box containing an error note is
displayed on the presentation server.
CALL METHOD belongs to a group of key words which allow you to
process external objects with ABAP/4. At present, only the
object model OLE2 is supported, i.e. all objects must be of
type OLE2_OBJECT. This type and other necessary data are
defined in the include program OLE2INCL.
Addition 1 ... = f
Effect Stores the return value of the method in the variable f. The
return value can also be of type OLE2_OBJECT. This addition
must always come before other additions.
Addition 2 ... EXPORTING p1 = f1 ... pn = fn
Effect EXPORTING passes values of fields to the parameters of the
method. p1, p2, ... are either key word parameters or position
parameters.
If assignment of parameters is by sequence, p1, p2, ... must
begin with "#", followed by the position number of the
parameter. At present, only position parameters are supported.
The export parameters always come at the end of the statement.
Addition 3 ... NO FLUSH
The addition NO FLUSH continues the collection process, even if
the next command is not an OLE statement. This means that you
can set a series of properties in a loop and download them to
the presentation server in a single transport operation.
If you do not use NO FLUSH, you must ensure that you do not
rely on the contents of return parameters not yet filled.
Also, all objects must be initialized in a bundle, i.e. they
must be generated by an OLE call that has already been
executed.
Every FREE statement always causes a download of the buffer.
Example Open an EXCEL file with the method 'Open'.
INCLUDE OLE2INCL.
DATA EXCEL TYPE OLE2_OBJECT.
DATA WORKBOOK TYPE OLE2_OBJECT.
CREATE OBJECT EXCEL 'Excel.Application'.
CALL METHOD OF EXCEL 'Workbooks' = WORKBOOK.
CALL METHOD OF WORKBOOK 'Open' EXPORTING #1 = 'C:\EX1.XLS'.
Related SET PROPERTY
GET PROPERTY
CREATE OBJECT
FREE OBJECT
CALL SCREEN - Call a screen
Basic form CALL SCREEN scr.
Addition:
... STARTING AT x1 y1 ... ENDING AT x2 y2
Effect Calls the screen scr; scr is the number of a screen of the main
program. You use SET SCREEN 0. or LEAVE SCREEN. to define the
return from the CALL screen.
Addition ... STARTING AT x1 y1 ENDING AT x2 y2
Effect The coordinates x1, y1 (start column and start line in the
window) and x2, y2 (end column and end line in the window)
define the size and position of the CALL screen ("top left -
bottom right"). Besides these coordinates, you can also see the
contents of the primary window, but cannot perform any action
there.
Note - If "ENDING AT ..." is not specified, suitable values are
substituted for x2 and y2, taking into account the size of
the called screen.
Note Runtime errors:
DYNP_TOO_MANY_CALL_SCREENS: No further screen level (call
screen); the maximum number of nested screen levels is
restricted to 50 at present.
CALL TRANSACTION - Call a transaction
Basic form CALL TRANSACTION tcod.
Additions:
1. ... AND SKIP FIRST SCREEN
2. ... USING itab
2a. ... MODE mode
2b. ... UPDATE upd
2c. ... MESSAGES INTO messtab
Effect Calls the SAP Transaction tcod; tcod can be a literal or a
variable. To return from the called transaction, you use the
key word LEAVE PROGRAM.
Example
CALL TRANSACTION 'SP01'.
Addition 1 ... AND SKIP FIRST SCREEN
Effect Skips the first screen in the transaction (provided all the
required fields have been assigned values by the SPA/GPA
process).
Addition 2 ... USING itab
Effect Calls the Transaction tcod and passes the internal table itab,
which contains one or several screens in batch input format.
If necessary, one of the messages output by the Transaction is
returned to the fields SY-MSGID, SY-MSGTY SY-MSGNO, SY-MSGV1,
..., SY-MSGV4.
The return code value is set as follows:
SY-SUBRC = 0: Processing was successful.
SY-SUBRC <> 0: Transaction ended with an error.
Note A called Transaction ends successfully for the following
reasons:
1. COMMIT WORK
2. Next screen = 0
3. LEAVE TO TRANSACTION ' '
Addition 2a ... MODE mode
Effect The specified processing mode can accept the following values:
'A' Display screen
'E' Display screen only if an error occurs
'N' No display
If the addition MODE is not specified, the processing mode is
set to 'A'.
Addition 2b ... UPDATE upd
Effect The specified update mode upd defines the update type. This can
have one of the following values:
'A' Asynchronous update
'S' Synchronous update
If the addition UPDATE is not specified, the processing mode is
set to 'A'.
Addition 2c ... MESSAGES INTO messtab
Effect The specified internal table contains all system messages that
occur during CALL TRANSACTION USING ... . The internal table
messtab must have the structure BDCMSGCOLL.
Example
DATA BEGIN OF BDCDATA OCCURS 100.
INCLUDE STRUCTURE BDCDATA.
DATA END OF BDCDATA.
DATA BEGIN OF MESSTAB OCCURS 10.
INCLUDE STRUCTURE BDCMSGCOLL.
DATA END OF MESSTAB.
DATA REPORT(8).
BDCDATA-PROGRAM = 'SAPMS38M'.
BDCDATA-DYNPRO = '0100'.
BDCDATA-DYNBEGIN = 'X'.
APPEND BDCDATA.
CLEAR BDCDATA.
BDCDATA-FNAM = 'RS38M-PROGRAMM'.
BDCDATA-FVAL = REPORT.
APPEND BDCDATA.
...
CALL TRANSACTION 'SE38' USING BDCDATA MODE 'N'
MESSAGES INTO MESSTAB.
Notes Runtime errors:
- CALL_TRANSACTION_NOT_FOUND: Transaction is unknown.
- CALL_TRANSACTION_IS_MENU: Transaction is a menu.
- CALL_TRANSACTION_USING_NESTED: Recursive CALL TRANSACTION
USING
Related SUBMIT
CALL DIALOG
CASE
Basic form CASE f.
Effect Case distinction.
Depending on the current contents of a field, this statement
executes one of several alternative processing branches. The
field whose contents determine how the subsequent processing is
specified after CASE; the individual processing branches are
introduced by WHEN, followed by the value to be tested. The
entire block is concluded by ENDCASE.
The structure of the CASE statement is as follows:
CASE f.
WHEN f1.
...
WHEN f2.
...
...
ENDCASE.
On reaching such a CASE statement, the processor compares f
with f1.
If f = f1, it executes the processing block between "WHEN f1."
and the next WHEN statement. If there are no further WHEN
statements, it executes the processing block up to the ENDCASE
statement and then continues with any subsequent processing.
If f <> f1, the processor compares the field f2 in the next
WHEN statement with f and proceeds as with f1 and so on.
Although f should be a variable, f1 can be a variable or a
literal. For the comparison "f = f1", the rules are the same as
for IF.
There is a second variant of the WHEN statement:
WHEN OTHERS.
No more than one such WHEN statement is allowed within a CASE
block. The "WHEN OTHERS" processing block is always concluded
by ENDCASE, i.e. no further WHEN statements can follow.
The "WHEN OTHERS" processing block is executed only if none of
the preceding WHEN blocks have been executed, i.e. if all
previous comparisons ("f = ...) have returned a negative
result.
Example
DATA: ONE TYPE I VALUE 1,
THREE TYPE P VALUE 3.
DO 5 TIMES.
CASE SY-INDEX.
WHEN ONE.
WRITE / 'That is'.
WHEN 2.
WRITE 'a'.
WHEN THREE.
WRITE 'good'.
WRITE 'example'.
WHEN OTHERS.
WRITE '!'.
ENDCASE.
ENDDO.
Output: "That is a good example ! !"
Notes 1. You can nest several CASE statements and even combine them
with IF statements.
2. The statement "WHEN: f1, f2." does not make sense. The
example below shows that the block belonging to "WHEN f1" is
empty:
WHEN f1.
WHEN f2.
Related IF, ELSEIF
CHECK
Within loops and events
- CHECK logexp.
Special for reports with logical databases
- CHECK sel.
- CHECK SELECT-OPTIONS.
CHECK - within loops
Basic form CHECK logexp.
Effect CHECK evaluates the subsequent logical expression. If it is
true, the processing continues with the next statement.
In loop structures like
DO ... ENDDO
WHILE ... ENDWHILE
LOOP ... ENDLOOP
SELECT ... ENDSELECT
CHECK with a negative outcome terminates the current loop pass
and goes back to the beginning of the loop to start the next
pass, if there is one.
In structures like
FORM ... ENDFORM
FUNCTION ... ENDFUNCTION
MODULE ... ENDMODULE
AT
CHECK with a negative outcome terminates the routine or
modularization unit.
If CHECK is not in a loop or a routine or a modularization
unit, a negative logical expression terminates the current
event. In contrast, the statement REJECT terminates the current
event, even from loops or subroutines.
Note If a CHECK produces a negative result in a GET event, the GET
events in subordinate tables of the logical database are not
processed either.
Related CONTINUE, EXIT, REJECT, STOP
CHECK - special for reports with logical databases
Variants:
1. CHECK sel.
2. CHECK SELECT-OPTIONS.
Variant 1 CHECK sel.
Effect Checks the selection criterion requested by the statement
SELECT-OPTIONS sel ....
This statement is equivalent to f IN sel, if sel was defined by
SELECT-OPTIONS sel FOR f and can be used anywhere in logical
expressions
If the result of this check is negative, the processing in this
event is terminated and the GET events for any subordinate
database tables are not processed either.
This variant of the CHECK statement should be used only if the
logical database for the corresponding table does not support
dynamic selections (see CHECK SELECT-OPTIONS), or
SELECT-OPTIONS with the addition NO DATABASE SELECTION.
Otherwise, the relevant record is not read from the database
and made available to the program.
Variant 2 CHECK SELECT-OPTIONS.
Effect Called only after a GET event.
This statement checks all the selections for SELECT-OPTIONS
where the reference field after FOR belongs to the current
table dbtab (specified after GET. However, this applies only if
the logical database for dbtab does not support dynamic
selections. Otherwise, the selections are passed directly to
the logical database (with the exception: addition "NO DATABASE
SELECTION" to SELECT-OPTIONS).
This variant of the CHECK statement only makes sense if the
logical database does not support dynamic selections for the
corresponding table or SELECT-OPTIONS are defined with the
addition "NO DATABASE SELECTION".
You can determine from the ABAP/4 Development Workbench whether
dynamic selections are defined and, if so, for which logical
database tables by selecting Development -> Programming
environ. -> Logical databases followed by Extras -> Dynamic
selections.
Example The logical database F1S of the demo flight reservation system
contains the tables SPFLI with, and the table SFLIGHT without,
dynamic selections.
TABLES:
SPFLI, SFLIGHT.
SELECT-OPTIONS:
SF_PRICE FOR SFLIGHT-PRICE,
SP_CARR FOR SPFLI-CARRID,
SP_FROM FOR SPFLI-CITYFROM NO DATABASE SELECTION,
SP_DEPT FOR SPFLI-DEPTIME.
Since dynamic selections are defined with the table SPFLI, but
not with the table SFLIGHT, the following procedure applies:
...
GET SFLIGHT.
CHECK SELECT-OPTIONS.
This CHECK statement is equivalent to the following statement:
CHECK SF_PRICE.
With
GET SPFLI.
CHECK SELECT-OPTIONS.
the CHECK statement is equivalent to the following statement:
CHECK SP_FROM.
Note With CHECK SELECT-OPTIONS, fields from superior tables in the
database hierarchy are not checked.
Note Runtime errors:
- CHECK_SELOPT_ILLEGAL_OPTION: Wrong "OPTION" in
SELECT-OPTIONS or RANGES table
- CHECK_SELOPT_ILLEGAL_SIGN: Wrong "SIGN" in SELECT-OPTIONS or
RANGES table
Related CONTINUE, EXIT, REJECT, STOP
CLEAR
Basic form CLEAR f.
Additions:
1. ... WITH g
2. ... WITH NULL
Effect Resets the contents of f to its initial value.
For predefined types (see DATA), the following initial values
are used:
Type C: ' ... ' (blank character)
Type N: '00...0'
Type 😧 '00000000'
Type T: '000000'
Type I: 0
Type P: 0
Type F: 0.0E+00
Type X: 0
If f is a field string, each component field is reset to its
initial value. If it is an internal table without a header
line, the entire table is deleted together with all its
entries. If, however, f is an internal table with a header
line, only the sub-fields in the table header entry are reset
to their initial values.
Example
DATA: TEXT(10) VALUE 'Hello',
NUMBER TYPE I VALUE 12345,
ROW(10) TYPE N VALUE '1234567890',
BEGIN OF PLAYER,
NAME(10) VALUE 'John',
TEL(8) TYPE N VALUE '08154711',
MONEY TYPE P VALUE 30000,
END OF PLAYER.
...
CLEAR: TEXT, NUMBER, PLAYER.
The field contents are now as follows:
ROW = '1234567890'
TEXT = ' '
NUMBER = 0
PLAYER-NAME = ' '
PLAYER-TEL = '00000000'
PLAYER-MONEY = 0
Notes 1. When CLEAR references an internal table itab with a header
line, it only resets the sub-fields in the header entry to
their initial values (as mentioned above). The individual
table entries remain unchanged.
To delete the entire internal table together with all its
entries, you can use CLEAR itab[] or REFRESH itab.
2. Within a logical expression, you can use f IS INITIAL to
check that the field f contains the initial value
appropriate for its type.
3. Variables are normally initialized according to their type,
even if the specification of an explicit initial value
(addition "... VALUE lit" of the DATA statement) is missing.
For this reason, it is not necessary to initialize variables
again with CLEAR after defining them.
Addition 1 ... WITH g
Effect The field f is filled with the value of the first byte of the
field g.
Addition 2 ... WITH NULL
Effect Fills the field with hexadecimal zeros.
Note You should use this addition with particular care because the
fields of most data types thus receive values which are really
invalid.
Note Performance:
CLEAR requires about 3 msn (standardized microseconds) of
runtime to process a field of type C with a length of 10 and
about 2 msn to process a field of the type I. To delete an
internal table with 15 fields, it needs about 5 msn.
CLOSE
Basic form
1. CLOSE DATASET dsn.
2. CLOSE CURSOR c.
Basic form 1 CLOSE DATASET dsn.
Effect Closes the file dsn, ignoring any errors which may occur. CLOSE
is required only if you want to edit dsn several times. For
further details, see the documentation for OPEN DATASET.
Basic form 2 CLOSE CURSOR c.
Effect Closes the database cursor c. CLOSE CURSOR is only required if
you want to read sets of database records several times with c.
For further information, refer to the documentation on OPEN
CURSOR and FETCH.
CLOSE CURSOR belongs to the Open SQL command set.
CNT
Basic form ... CNT(h) ...
Effect CNT(h) is not a statement, but a field which is automatically
created and filled by the system if f is a sub-field of an
extract dataset.
CNT(h) can only be addressed from within a LOOP on a sorted
extract.
If h is a non-numeric field (see also ABAP/4 number types) from
the field group HEADER and part of the sort key of the extract
dataset, the end of a control level (AT END OF, AT LAST) is
such that CNT(h) contains the number of different values which
the field h has accepted in the group, i.e. the number of
records in the group for which the field f has changed its
value.
Related SUM(g)
COLLECT
Basic form COLLECT [wa INTO] itab.
Addition:
... SORTED BY f
Effect COLLECT is used to create unique or compressed datsets. The key
fields are the default key fields of the internal table itab.
If you use only COLLECT to fill an internal table, COLLECT
makes sure that the internal table does not contain two entries
with the same default key fields.
If, besides its default key fields, the internal table contains
number fields (see also ABAP/4 number types), the contents of
these number fields are added together if the internal table
already contains an entry with the same key fields.
If the default key of an internal table processed with COLLECT
is blank, all the values are added up in the first table line.
If you specify wa INTO, the entry to be processed is taken from
the explicitly specified work area wa. If not, it comes from
the header line of the internal table itab.
After COLLECT, the system field SY-TABIX contains the index of
the - existing or new - table entry with default key fields
which match those of the entry to be processed.
Notes 1. COLLECT can create unique or compressed datasets and should
be used precisely for this purpose. If uniqueness or
compression are unimportant, or two values with identical
default key field values could not possibly occur in your
particular task, you should use APPEND instead. However, for
a unique or compressed dataset which is also efficient,
COLLECT is the statement to use.
2. If you process a table with COLLECT, you should also use
COLLECT to fill it. Only by doing this can you guarantee
that
- the internal table will actually be unique or compressed, as
described above and
- COLLECT will run very efficiently.
3. If you use COLLECT with an explicitly specified work area,
it must be compatible with the line type of the internal
table.
Example Compressed sales figures for each company
DATA: BEGIN OF COMPANIES OCCURS 10,
NAME(20),
SALES TYPE I,
END OF COMPANIES.
COMPANIES-NAME = 'Duck'. COMPANIES-SALES = 10.
COLLECT COMPANIES.
COMPANIES-NAME = 'Tiger'. COMPANIES-SALES = 20.
COLLECT COMPANIES.
COMPANIES-NAME = 'Duck'. COMPANIES-SALES = 30.
COLLECT COMPANIES.
The table COMPANIES now has the following appearance:
NAME ! SALES
-
Duck ! 40
Tiger ! 20
Addition ... SORTED BY f
Effect COLLECT ... SORTED BY f is obsolete and should no longer be
used. Use APPEND ... SORTED BY f which has the same meaning.
Note Performance:
1. When using internal tables with a header line, avoid
unnecessary assignments to the header line. Whenever
possible, use statements which have an explicit work area.
For example, "APPEND wa TO itab." is approximately twice as
fast as "itab = wa. APPEND itab.". The same applies to
COLLECT and INSERT.
2. The cost of a COLLECT in terms of performance increases with
the width of the default key needed in the search for table
entries and the number of numeric fields with values which
have to be added up, if an entry is found in the internal
table to match the default key fields.
If no such entry is found, the cost is reduced to that
required to append a new entry to the end of the table.
A COLLECT statement used on a table which is 100 bytes wide
and has a key which is 60 bytes wide and seven numeric
fields is about approx. 50 msn (standardized microseconds).
Note Runtime errors:
- COLLECT_OVERFLOW: Overflow in integer field when calculating
totals.
- COLLECT_OVERFLOW_TYPE_P: Overflow in type P field when
calculating totals.
Related APPEND, WRITE ... TO, MODIFY, INSERT
COMMIT
Basic form COMMIT WORK.
Addition:
... AND WAIT
Effect Executes a database commit and thus closes a logical processing
unit or Logical Unit of Work (LUW) (see also Transaction
processing). This means that
- all database changes are made irrevocable and cannot be
reversed with ROLLBACK WORK and
- all database locks are released.
COMMIT WORK also
- calls the subroutines specified by PERFORM ... ON COMMIT,
- executes asynchronously any update requests (see CALL
FUNCTION ... IN UPDATE TASK) specified in these subroutines
or started just before,
- processes the function modules specified in CALL FUNCTION
... IN BACKGROUND TASK,
- cancels all existing locks (see SAP locking concept) if no
update requests exist,
- closes all open database cursors (see OPEN CURSOR) and
- resets the time slice counter to 0.
COMMIT WORK belongs to the Open SQL command set.
The return code value SY-SUBRC is set to 0.
Notes 1. All subroutines called with PERFORM ... ON COMMIT are
processed in the LUW concluded by the COMMIT WORK command.
All V1 update requests specified in CALL FUNCTION ... IN
UPDATE TASK are also executed in one LUW. When all V1 update
requests have been successfully concluded, the V2 update
requests ("update with start delayed") are processed, each
in one LUW. Parallel to this, the function modules specified
in CALL FUNCTION ... IN BACKGROUND TASK are each executed in
one LUW per destination.
2. COMMIT WORK commands processed within CALL DIALOG processing
- execute a database commit (see above),
- close all open database cursors,
- reset the time slice counter and
- call the function modules specified by CALL FUNCTION IN
BACKGROUND TASK in the CALL DIALOG processing.
However, subroutines and function modules called with
PERFORM ... ON COMMIT or CALL FUNCTION ... IN UPDATE TASK in
the CALL DIALOG processing are not executed in the calling
transaction until a COMMIT WORK occurs.
3. Since COMMIT WORK closes all open database cursors, any
attempt to continue a SELECT loop after a COMMIT WORK
results in a runtime error. For the same reason, a FETCH
after a COMMIT WORK on the now closed cursors also produces
a runtime error. You must therefore ensure that any open
cursors are no longer used after the COMMIT WORK.
4. With batch input and CALL TRANSACTION ... USING, COMMIT WORK
successfully concludes the processing.
Addition ... AND WAIT
Effect The addition ... AND WAIT makes the program wait until the type
V1 updates have been completed.
The return code value is set as follows:
SY-SUBRC = 0: The update was successfully performed.
SY-SUBRC <> 0: The update could not be successfully performed.
Note Runtime errors:
- COMMIT_IN_PERFORM_ON_COMMIT: COMMIT WORK is not allowed in a
FORM callled with PERFORM ... ON COMMIT.
- COMMIT_IN_POSTING: COMMIT WORK is not allowed in the update
task.
COMMUNICATION
Variants:
1. COMMUNICATION INIT DESTINATION dest ID id.
2. COMMUNICATION ALLOCATE ID id.
3. COMMUNICATION ACCEPT ID id.
4. COMMUNICATION SEND ID id BUFFER f.
5. COMMUNICATION RECEIVE ID id
...BUFFER f
...DATAINFO d
...STATUSINFO s.
6. COMMUNICATION DEALLOCATE ID id.
The COMMUNICATION statement allows you to develop applications
which perform direct program-to-program communication. The
basis for this is CPI-C (Common Programming Interface -
Coummunication), defined by IBM within the context of SAA
standards as a standardized communications interface.
The COMMUNICATION statement provides the essential parameters
for implementing simple communication. Its starter set covers
the following functionality:
Establishing a connection
Accepting a communication
Sending data
Receiving data
Closing a connection
The other essential part of such a communication is an ABAP/4
program containing a FORM routine which is executed when the
connection has been established. This program may be in an R/3
System or an R/2> System.
Here, you should be aware that the application programs
themselves declare a protocol. In particular, logon to the
partner SAP System must be performed in the calling program.
The partner programs must also manage different character sets,
e.g. ASCII - EBCDIC themselves. A facility known as the Remote
Function Call (RFC) has now been developed to save users from
having to deal with these problems.
External programs (e.g. a program written in C on a UNIX
workstation) can also be used as partner programs. For this
purpose, SAP provides a platform-specific development library.
For more detailed information about communication in the SAP
System, you can refer to the manual
SAP Communication: Programming
Further information about communication can be found in any of
the following literature:
IBM SAA
Common Programming Interface
Communication Reference
SC 26-4399
X/Open Developers' Specification CPI-C
X/Open Company Ltd.
ISBN 1 872630 02 2
Variant 1 COMMUNICATION INIT DESTINATION dest ID id.
Addition:
... RETURNCODE rc
Effect Initializes a program-to-program connection.
The partner system is specified in the dest field. You can use
any name you like, but it must be entered in the connection
table TXCOM and can be no more than 8 characters long. This
entry in TXCOM determines to which physical system a connection
is established using the symbolic name of the target system.
In the field id, the system assigns an eight-character ID
number of type C to the connection. The system field SY-SUBRC
contains an appropriate return code value.
All return codes can be read using their symbolic names. For
this purpose, you can use the program RSCPICDF which contains
these names and can be included, if required.
Addition ... RETURNCODE rc
Effect Stores the return code in the field rc.
Example
TYPES: CONVERSATION_ID(8) TYPE C,
DESTINATION(8) TYPE C,
RETURN_CODE LIKE SY-SUBRC.
DATA: CONVID TYPE CONVERSATION_ID,
DEST TYPE DESTINATION VALUE 'C00',
CPIC_RC TYPE RETURN_CODE.
INCLUDE RSCPICDF.
COMMUNICATION INIT DESTINATION DEST
ID CONVID
RETURNCODE CPIC_RC.
IF CPIC_RC NE CM_OK.
WRITE: /'COMMUNICATION INIT, RC = ', CPIC_RC.
EXIT.
ENDIF.
Variant 2 COMMUNICATION ALLOCATE ID id.
Addition:
As for variant 1.
Effect Sets up a program-to-program connection. The call must
immediately follow COMMUNICATION INIT.
Example
TYPES: CONVERSATION_ID(8) TYPE C,
DESTINATION(8) TYPE C,
RETURN_CODE LIKE SY-SUBRC.
DATA: CONVID TYPE CONVERSATION_ID,
DEST TYPE DESTINATION VALUE 'C00',
CPIC_RC TYPE RETURN_CODE.
INCLUDE RSCPICDF.
COMMUNICATION INIT DESTINATION DEST
ID CONVID
RETURNCODE CPIC_RC.
IF CPIC_RC NE CM_OK.
WRITE: /'COMMUNICATION INIT, RC = ', CPIC_RC.
EXIT.
ENDIF.
COMMUNICATION ALLOCATE ID CONVID RETURNCODE CPIC_RC.
IF CPIC_RC NE CM_OK.
WRITE: /'COMMUNICATION ALLOCATE, RC = ', CPIC_RC.
EXIT.
ENDIF.
Variant 3 COMMUNICATION ACCEPT ID id.
Addition:
As for variant 1.
Effect Accepts a connection requested by the partner program. id is a
field of type C which is 8 characters long and contains the ID
of the accepted connection after a successful call.
Example
FORM CPIC_EXAMPLE.
TYPES: CONVERSATION_ID(8) TYPE C,
RETURN_CODE LIKE SY-SUBRC.
DATA: CONVID TYPE CONVERSATION_ID,
CPIC_RC TYPE RETURN_CODE.
INCLUDE RSCPICDF.
COMMUNICATION ACCEPT ID CONVID
RETURNCODE CPIC_RC.
IF CPIC_RC NE CM_OK.
EXIT.
ENDIF.
ENDFORM.
Variant 4 COMMUNICATION SEND ID id BUFFER f.
Additions:
1. ... RETURNCODE rc
2. ... LENGTH len
Effect Sends data to the partner program. The data is stored in the
field f which follows the key word parameter BUFFER. It is sent
in the full length of the field f. If the partner program is
part of a system which has a different character set, you must
perform an appropriate conversion yourself. To do this, use the
TRANSLATE statement.
Addition 1 ... RETURNCODE rc
Effect Stores the return code in the field rc.
Addition 2 ... LENGTH leng
Effect Sends the contents of the field f to the partner program in the
specified length.
Example
TYPES: CONVERSATION_ID(8) TYPE C,
DESTINATION(8) TYPE C,
RETURN_CODE LIKE SY-SUBRC.
DATA: CONVID TYPE CONVERSATION_ID,
DEST TYPE DESTINATION VALUE 'C00',
CPIC_RC TYPE RETURN_CODE.
INCLUDE RSCPICDF.
COMMUNICATION INIT DESTINATION DEST
ID CONVID
RETURNCODE CPIC_RC.
IF CPIC_RC NE CM_OK.
WRITE: /'COMMUNICATION INIT, RC = ', CPIC_RC.
EXIT.
ENDIF.
COMMUNICATION ALLOCATE ID CONVID
RETURNCODE CPIC_RC.
IF CPIC_RC NE CM_OK.
WRITE: /'COMMUNICATION ALLOCATE, RC = ', CPIC_RC.
EXIT.
ENDIF.
RECORD = 'The quick brown fox jumps over the lazy dog'.
COMMUNICATION SEND ID CONVID
BUFFER RECORD
LENGTH LENG
RETURNCODE CPIC_RC.
IF CPIC_RC NE CM_OK.
WRITE: / 'COMMUNICATION SEND, RC = ', CPIC_RC.
EXIT.
ENDIF.
Since the length is specified explicitly in this example, only
the part 'The quick brown fox ' is transferred from the
contents of the field RECORD.
Variant 5 COMMUNICATION RECEIVE ID id ...BUFFER f ...DATAINFO d
...STATUSINFO s.
Parts marked with " ..." are interchangeable
Additions:
1. ... RETURNCODE rc
2. ... LENGTH leng
3. ... RECEIVED m
4. ... HOLD
Effect Receives data in the field f. If no length is explicitly
defined, the amount of data accepted depends on the length of
the field. The fields d and s contain information about the
receive process. You can address the contents of these using
symbolic names in the include program RSCPICDF. The field d
indicates whether the data was received in its entirety. The
status field s informs the RECEIVE user of the status of the
program. Here, it is important to know whether the program is
in receive status or send status. It is, for example, not
possible to send data if the program is in receive status.
For more detailed information about these protocol questions,
refer to the manuals listed above.
Addition 1 ... RETURNCODE rc
Effect Stores the return code in the field rc.
Addition 2 ... LENGTH leng
Effect Receives data only in the specified length leng.
Addition 3 ... RECEIVED m
Effect After the call, m contains the number of bytes received by the
partner program.
Addition 4 ... HOLD
Effect Normally, data is received asynchronously, i.e. the system
performs a rollout. However, this may not be desirable if, for
example, the data is received in a SELECT loop, the database
cursor is lost due to the rollout and the loop is terminated.
To prevent a rollout, you can use the addition HOLD. Then, the
SAP process waits until the data has been received and is thus
available for use by other users.
Note The fields d, s and m which contain information about the
outcome of the call must be of type X with length 4.
Example
FORM CPIC_EXAMPLE.
TYPES: CONVERSATION_ID(8) TYPE C,
RETURN_CODE LIKE SY-SUBRC,
C_INFO(4) TYPE X.
DATA: CONVID TYPE CONVERSATION_ID,
CPIC_RC TYPE RETURN_CODE,
RECORD(80) TYPE C,
DINFO TYPE C_INFO,
SINFO TYPE C_INFO.
INCLUDE RSCPICDF.
COMMUNICATION ACCEPT ID CONVID
RETURNCODE CPIC_RC.
IF CPIC_RC NE CM_OK.
EXIT.
ENDIF.
COMMUNICATION RECEIVE ID CONVID
BUFFER RECORD
STATUSINFO SINFO
DATAINFO DINFO
RETURNCODE CPIC_RC.
IF CPIC_RC NE CM_OK.
EXIT.
ENDIF.
ENDFORM.
Variant 6 COMMUNICATION DEALLOCATE ID id.
Addition:
As for variant 1
Effect Severs connection and releases all resources.
Example
TYPES: CONVERSATION_ID(8) TYPE C,
DESTINATION(8) TYPE C,
RETURN_CODE LIKE SY-SUBRC,
C_INFO(4) TYPE X.
DATA: CONVID TYPE CONVERSATION_ID,
CPIC_RC TYPE RETURN_CODE,
DEST TYPE DESTINATION VALUE 'C00'.
DATA: RECORD(80) TYPE C,
LENG TYPE I VALUE 20.
INCLUDE RSCPICDF.
COMMUNICATION INIT DESTINATION DEST
ID CONVID
RETURNCODE CPIC_RC.
IF CPIC_RC NE CM_OK.
WRITE: / 'COMMUNICATION INIT, RC = ', CPIC_RC.
EXIT.
ENDIF.
COMMUNICATION ALLOCATE ID CONVID
RETURNCODE CPIC_RC.
IF CPIC_RC NE CM_OK.
WRITE: / 'COMMUNICATION ALLOCATE, RC = ', CPIC_RC.
EXIT.
ENDIF.
RECORD = 'The quick brown fox jumps over the lazy dog'.
COMMUNICATION SEND ID CONVID
BUFFER RECORD
LENGTH LENG
RETURNCODE CPIC_RC.
IF CPIC_RC NE CM_OK.
WRITE: / 'COMMUNICATION SEND, RC = ', CPIC_RC.
EXIT.
ENDIF.
COMMUNICATION DEALLOCATE ID CONVID
RETURNCODE CPIC_RC.
IF CPIC_RC NE CM_OK.
WRITE: / 'COMMUNICATION DEALLOCATE, RC = ', CPIC_RC.
EXIT.
ENDIF.
Note The above examples illustrate the basic functionality of the
key words. However, the example program can only have an
external system as partner. If the partner is an SAP System,
the calling program must first logon to the SAP System and
receive an acknowledgement. Only then can you begin to transmit
the actual data. When logging on to an R2 System and an R3
System, the logon data must be converted to EBCDIC. All user
data should be converted according to the partner system. This
is in the concluding example of an R/3 - R/2 connection.
Example
PROGRAM ZCPICTST.
TYPES: CONVERSATION_ID(8) TYPE C,
DESTINATION(8) TYPE C,
RETURN_CODE LIKE SY-SUBRC,
C_INFO(4) TYPE X.
DATA: BEGIN OF CONNECT_STRING,
REQID(4) VALUE 'CONN',
TYPE(4) VALUE 'CPIC',
MODE(4) VALUE '1 ',
MANDT(3) VALUE '000',
NAME(12) VALUE 'CPICUSER',
PASSW(8) VALUE 'CPIC',
LANGU(1) VALUE 'D',
KORRV(1),
REPORT(8) VALUE 'ZCPICTST',
FORM(30) VALUE 'CPIC_EXAMPLE',
END OF CONNECT_STRING.
DATA: CONVID TYPE CONVERSATION_ID,
DEST TYPE DESTINATION VALUE 'R2-SYST',
CPIC_RC TYPE RETURN_CODE,
DINFO TYPE C_INFO,
SINFO TYPE C_INFO.
DATA: RECORD(80) TYPE C,
LENG TYPE I VALUE 20.
INCLUDE RSCPICDF.
COMMUNICATION INIT DESTINATION DEST
ID CONVID
RETURNCODE CPIC_RC.
IF CPIC_RC NE CM_OK.
WRITE: / 'COMMUNICATION INIT, RC = ', CPIC_RC.
EXIT.
ENDIF.
COMMUNICATION ALLOCATE ID CONVID
RETURNCODE CPIC_RC.
IF CPIC_RC NE CM_OK.
WRITE: / 'COMMUNICATION ALLOCATE, RC = ', CPIC_RC.
EXIT.
ENDIF.
Convert logon data to EBCDIC
TRANSLATE CONNECT_STRING TO CODE PAGE '0100'.
COMMUNICATION SEND ID CONVID BUFFER CONNECT_STRING.
IF CPIC_RC NE CM_OK.
WRITE: / 'COMMUNICATION ALLOCATE, RC = ', CPIC_RC.
EXIT.
ENDIF.
Receive acknowledgement of logon
COMMUNICATION RECEIVE ID CONVID
BUFFER RECORD
DATAINFO DINFO
STATUSINFO SINFO
RETURNCODE CPIC_RC.
IF CPIC_RC NE CM_OK.
WRITE: / 'COMMUNICATION RECEIVE, RC = ', CPIC_RC.
EXIT.
ENDIF.
Convert acknowledgement to ASCII
TRANSLATE RECORD FROM CODE PAGE '0100'.
Now begin user-specific data exchange
RECORD = 'The quick brown fox jumps over the lazy dog'.
Depending on the partner system, convert to another
character set
TRANSLATE RECORD TO CODE PAGE '0100'.
COMMUNICATION SEND ID CONVID
BUFFER RECORD
LENGTH LENG
RETURNCODE CPIC_RC.
IF CPIC_RC NE CM_OK.
WRITE: / 'COMMUNICATION SEND, RC = ', CPIC_RC.
EXIT.
ENDIF.
COMMUNICATION DEALLOCATE ID CONVID
RETURNCODE CPIC_RC.
IF CPIC_RC NE CM_OK.
WRITE: / 'COMMUNICATION DEALLOCATE, RC = ', CPIC_RC.
EXIT.
ENDIF.
PROGRAM ZCPICTST.
INCLUDE RSCPICDF.
The receiving procedure in the relevant partner program
follows
FORM CPIC_EXAMPLE.
TYPES: CONVERSATION_ID(8) TYPE C,
RETURN_CODE LIKE SY-SUBRC,
C_INFO(4) TYPE X.
DATA: CONVID TYPE CONVERSATION_ID,
CPIC_RC TYPE RETURN_CODE,
RECORD(80) TYPE C,
DINFO TYPE C_INFO,
SINFO TYPE C_INFO.
COMMUNICATION ACCEPT ID CONVID
RETURNCODE CPIC_RC.
IF CPIC_RC NE CM_OK.
EXIT.
ENDIF.
COMMUNICATION RECEIVE ID CONVID
BUFFER RECORD
STATUSINFO SINFO
DATAINFO DINFO
RETURNCODE CPIC_RC.
IF CPIC_RC NE CM_OK AND CPIC_RC NE CM_DEALLOCATED_NORMAL.
EXIT.
ENDIF.
ENDFORM.
COMPONENT-CHECK
Variations:
1. COMPONENT-CHECK NUMBER n.
2. COMPONENT-CHECK TRANSACTION tcod.
3. COMPONENT-CHECK PROGRAM prog.
Effect Determines whether a particular SAP price list component is
installed.
Variation 1 COMPONENT-CHECK NUMBER n.
Effect Determines whether the SAP price list component n is installed.
The return code in the system field SY-SUBRC may be set to
either of the following values:
0 SAP price list component active.
4 SAP price list component not active.
Variation 2 COMPONENT-CHECK TRANSACTION tcod.
Effect Determines whether the SAP price list component for Transaction
tcod is installed. The return code in the system field SY-SUBRC
may be set to any of the following values:
0 SAP price list component active.
4 SAP price list component not active.
8 Transaction tcod does not belong to any SAP
price list component (i.e. no entry in Table
DIR).
Variation 3 COMPONENT-CHECK PROGRAM prog.
Effect Determines whether the SAP price list component for the program
prog is installed. The return code in the system field SY-SUBRC
may be set to any of the following values:
0 SAP price list component active.
4 SAP price list component not active.
8 Program p does not belong to any SAP price list
component (i.e. no entry in Table DIR).
COMPUTE
Basic form COMPUTE n = arithexp.
Effect Evaluates the arithmetic expression arithexp and places the
result in the field n.
Allows use of the four basic calculation types +, -, * and /,
the whole number division operators DIV (quotient) and MOD
(remainder), the exponentiation operator ** (exponentiation "X
Y means X to the power of Y) as well as the functions listed
below.
When evaluating mixed expressions, functions have priority.
Then comes exponentiation, followoed by the "point operations"
*, /, DIV and MOD, and finally + and - . Any combination of
parentheses is also allowed.
The fields involved are usually of type I, F or P, but there
are exceptions to this rule (see below).
You can omit the key word COMPUTE.
Built-in functions
- Functions for all number types
ABS Amount (absolute value) |x| of x
SIGN Sign (preceding sign) of x;
1 x > 0
SIGN( x ) = 0 if x = 0
-1 x < 0
CEIL Smallest whole number value not less than x
FLOOR Greatest whole number value not greater than x
TRUNC Whole number part of x
FRAC Decimal part of x
- Floating point functions
ACOS Arc cosine(x) in the range [-pi/2, pi/2], x from
[-1, 1]
ASIN Arc cosine(x) in the range [0, pi], x aus [-1,
1]
ATAN Arc tangent(x) in the range [-pi/2, pi/2] (pi =
3.1415926535897932)
COS Cosine of an angle specified in the arc
SIN Sine of an angle specified in the arc
TAN Tangent of an angle specified in the arc
COSH Hyperbola cosine
SINH Hyperbola sine
TANH Hyperbola tangent
EXP Exponential function for base e =
2.7182818284590452
LOG Natural logarithm (i.e. base e) of a positive
number
LOG10 Logarithm of x for base 10, x > 0
SQRT Square root of a non-negative number
- String functions
STRLEN Length of a string up to the last non-blank
character (i.e. the occupied length)
Function expressions consist of three parts:
1. Function identifier directly followed by an opening
parenthesis
2. Argument
3. Closing parenthesis
All parts of an expression, particularly any parts of a
function expression, must be separated from each other by at
least one blank.
Example The following statements, especially the arithmetic
expressions, are syntactically correct:
DATA: I1 TYPE I, I2 TYPE I, I3 TYPE I,
F1 TYPE F, F2 TYPE F,
WORD1(10), WORD2(20).
...
F1 = ( I1 + EXP( F2 ) ) * I2 / SIN( 3 - I3 ).
COMPUTE F1 = SQRT( SQRT( ( I1 + I2 ) * I3 ) + F2 ).
I1 = STRLEN( WORD1 ) + STRLEN( WORD2 ).
Notes 1. When used in calculations, the amount of CPU time needed
depends on the data type. In very simple terms, type I is
the cheapest, type F needs longer and type P is the most
expensive.
Normally, packed numbers arithmetic is used to evaluate
arithmetic expressions. If, however, the expression contains
a floating point function, or there is at least one type F
operand, or the result field is type F, floating point
arithmetic is used instead for the entire expression. On the
other hand, if only type I fields or date and time fields
occur (see below), the calculation involves integer
operations.
2. You can also perform calculations on numeric fields other
than type I, F or P. Before executing calculations, the
necessary type conversions are performed (see MOVE). You
can, for instance, subtract one date field (type D) from
another, in order to calculate the number of days
difference. However, for reasons of efficiency, only
operands of the same number type should be used in one
arithmetic expression (apart from the operands of STRLEN).
This means that no conversion is necessary and special
optimization procedures can be performed.
3. Division by 0 results in termination unless the dividend is
also 0 (0 / 0). In this case, the result is 0.
4. As a string processing command, the STRLEN operator treats
operands (regardless of type) as character strings, without
triggering internal conversions. On the other hand, the
operands of floating point functions are converted to type F
if they have another type.
Example Date and time arithmetic
DATA: DAYS TYPE I,
DATE_FROM TYPE D VALUE '19911224',
DATE_TO TYPE D VALUE '19920101',
DAYS = DATE_TO - DATE_FROM.
DAYS now contains the value 8.
DATA: SECONDS TYPE I,
TIME_FROM TYPE T VALUE '200000',
TIME_TO TYPE T VALUE '020000'.
SECONDS = ( TIME_TO - TIME_FROM ) MOD 86400.
SECONDS now contains the value 21600 (i.e. 6 hours). The
operation "MOD 86400" ensures that the result is always a
positive number, even if the period extends beyond midnight.
Note Packed numbers arithmetic:
All P fields are treated as whole numbers. Calculations
involving decimal places require additional programming to
include multiplication or division by 10, 100, ... . The
DECIMALS specification with the DATA declaration is effective
only for output with WRITE.
If, however, fixed point arithmetic is active, the DECIMALS
specification is also taken into account. In this case,
intermediate results are calculated with maximum accuracy (31
decimal places). This applies particularly to division.
For this reason, you should always set the program attribute
"Fixed point arithmetic".
Example
DATA P TYPE P.
P = 1 / 3 * 3.
Without "fixed point arithmetic", P has the value 0, since "1 /
3" is rounded down to 0.
With fixed point arithmetic, P has the value 1, since the
intermediate result of "1 / 3" is
0.333333333333333333333333333333.
Note Floating point arithmetic
With floating point arithmetic, you must always expect some
loss of accuracy through rounding errors (ABAP/4 number types).
Note Exponentiation
The exponential expression "x*y" means xx...x y times,
provided that y is a natural number. For any value of y, x**y
is explained by exp(y*log(x)).
Operators of the same ranke are evaluated from left to right.
Only the exponential operator, as is usual in mathematics, is
evaluated from right to left. The expression "4 ** 3 ** 2" thus
corresponds to "4 ** ( 3 ** 2 )" and not "( 4 ** 3 ) ** 2", so
the result is 262144 and not 4096.
The following resrtictions apply for the expression "X ** Y":
If X is equal to 0, Y must be positive. If X is negative, Y
must be a whole number.
Note DIV and MOD
The whole number division operators DIV and MOD are defined as
follows:
- ndiv = n1 DIV n2
- nmod = n1 MOD n2
so that:
1. n1 = ndiv * n2 + nmod
2. ndiv is a whole number
3. 0 <= nmod < |n2|
A runtime error occurs if n2 is equal to 0 and n1 is not equal
to 0.
Example
DATA: D1 TYPE I, D2 TYPE I, D3 TYPE I, D4 TYPE I,
M1 TYPE P DECIMALS 1, M2 TYPE P DECIMALS 1,
M3 TYPE P DECIMALS 1, M4 TYPE P DECIMALS 1,
PF1 TYPE F VALUE '+7.3',
PF2 TYPE F VALUE '+2.4',
NF1 TYPE F VALUE '-7.3',
NF2 TYPE F VALUE '-2.4',
D1 = PF1 DIV PF2. M1 = PF1 MOD PF2.
D2 = NF1 DIV PF2. M2 = NF1 MOD PF2.
D3 = PF1 DIV NF2. M3 = PF1 MOD NF2.
D4 = NF1 DIV NF2. M4 = NF1 MOD NF2.
The variables now have the following values:
D1 = 3, M1 = 0.1,
D2 = - 4, M2 = 2.3,
D3 = - 3, M3 = 0.1,
D4 = 4, M4 = 2.3.
Example Functions ABS, SIGN, CEIL, FLOOR, TRUNC, FRAC
DATA: I TYPE I,
P TYPE P DECIMALS 2,
M TYPE F VALUE '-3.5',
D TYPE P DECIMALS 1.
P = ABS( M ). " 3,5
I = P. " 4 - commercially rounded
I = M. " -4
I = CEIL( P ). " 4 - next largest whole number
I = CEIL( M ). " -3
I = FLOOR( P ). " 3 - next smallest whole number
I = FLOOR( M ). " -4
I = TRUNC( P ). " 3 - whole number part
I = TRUNC( M ). " -3
D = FRAC( P ). " 0,5 - decimal part
D = FRAC( M ). " -0,5
Notes Floating point functions
1. Although the functions SIN, COS and TAN are defined for any
numbers, the results are imprecise if the argument is
greater than about 1E8, i.e. 10**8.
2. The logarithm for a base other than e or 10 is calculated as
follows:
Logarithm of b for base a = LOG( b ) / LOG( a )
Note Runtime errors:
Depending on the operands, the above operators and functions
can cause runtime errors (e.g. when evaluating the logarithm
with a negative argument).
Related ADD, SUBTRACT, MULTIPLY, DIVIDE, MOVE
CONCATENATE
Basic form CONCATENATE f1 ... fn INTO g.
Addition:
... SEPARATED BY h
Note As with any string processing statement, all the operands are
processed here as type C fields (regardless of tyep). No
internal conversion is performed.
Effect Places the fields f1 to fn after g.
With the fields fi (1 <= i <= n), trailing blanks are ignored,
i.e. these fields are considered only to have the length
STRLEN( fi).
The return code value is set as follows:
SY-SUBRC = 0: The result fits in g.
SY-SUBRC = 4: The result was too long for g and was only
copied to g in that length.
Example
DATA: ONE(10) VALUE 'John',
TWO(3) VALUE ' F.',
THREE(10) VALUE ' Kennedy',
NAME(20).
CONCATENATE ONE TWO THREE INTO NAME.
Then, NAME contains the value "John F. Kennedy".
Addition ... SEPARATED BY h
Effect Inserts the separator h between the fields fi.
Here, h is used in its defined length.
Examples
DATA: ONE(10) VALUE 'John',
TWO(3) VALUE 'F.',
THREE(10) VALUE 'Kennedy',
NAME(20).
CONCATENATE ONE TWO THREE INTO NAME SEPARATED BY SPACE.
Then, NAME has the value "John F. Kennedy".
DATA SEPARATOR(4) VALUE 'USA'.
CONCATENATE SPACE ONE TWO THREE INTO NAME
SEPARATED BY SEPARATOR.
Then, NAME has the value "USA JohnUSA F.USA Ke".
The return value of SY-SUBRC is set to 4.
Related SPLIT, SHIFT, REPLACE, TRANSLATE, CONDENSE
Note Performance:
You are recommended to use the key word CONCATENATE rather than
your own constructions because it is safer, more efficient and
clearer. The runtime required to append two 30-byte fields
amounts to approx. 14 msn (standardized microseconds).
CONDENSE
Basic form CONDENSE c.
Addition:
... NO-GAPS
Note As with any string processing statement, all the operands are
processed here as type C fields (regardless of tyep). No
internal conversion is performed.
Effect Shifts the contents of the field c to the left, so that each
word is separated by exactly one blank.
Example
DATA: BEGIN OF NAME,
TITLE(8), VALUE 'Dr.',
FIRST_NAME(10), VALUE 'Michael',
SURNAME(10), VALUE 'Hofmann',
END OF NAME.
CONDENSE NAME.
WRITE NAME.
produces the output:
Dr. Michael Hofmann
Addition ... NO-GAPS
Effect Suppresses all blanks from the field c
Example
DATA: BEGIN OF NAME,
TITLE(8), VALUE 'Dr.',
FIRST_NAME(10), VALUE 'Michael',
SURNAME(10), VALUE 'Hofmann',
END OF NAME.
CONDENSE NAME NO-GAPS.
The contents of NAME is now "Dr.MichaelHofmann".
Since the field string NAME is interpreted and handled like a
type C field, the CONDENSE statement treats it as a whole and
ignores any sub-fields. The contents of the component field
would therefore now be as follows:
NAME-TITLE = 'Dr.Micha'
NAME-FIRST_NAME = 'elHofmann '
NAME-SURNAME = ' '
Note Do not use CONDENSE to manipulate field strings that include
fields not of type C. This could result in these component
fields containing characters of a different (i.e. incorrect)
type.
Related SHIFT, CONCATENATE, REPLACE, SPLIT
Note Performance:
The runtime required to condense three fields is about 20 msn
(standardized micooseconds). The variant ... NO-GAPS needs
about 12 msn.
CONSTANTS
Variants:
1. CONSTANTS c. ... VALUE [ val | IS INITIAL ].
2. CONSTANTS c(len) ... VALUE [ val | IS INITIAL ].
3. CONSTANTS: BEGIN OF crec,
...
END OF crec.
Effect The CONSTANTS statement defines global and local constants.
Constants allow you to read statically declared data objects.
They always have a particular data type. Data types and data
objects are essential components of the ABAP/4 type concept.
In contrast to variables defined with the DATA statement, you
cannot change the value of a constant once it has been defined.
Apart from the additions ... TYPE typ OCCURS n, ... LIKE
f1OCCURS n and WITH HEADER LINE, all the additions used with
the DATA statement are allowed. However, in contrast to the
DATA statement, the addition ... VALUE val or VALUE IS INITIAL
obligatory with variants 1 and 2. See additions with DATA.
Example
CONSTANTS CHAR1 VALUE 'X'.
CONSTANTS INT TYPE I VALUE 99.
CONSTANTS: BEGIN OF CONST_REC,
C(2) TYPE I VALUE 'XX',
N(2) TYPE N VALUE '12',
X TYPE X VALUE 'FF',
I TYPE I VALUE 99,
P TYPE P VALUE 99,
F TYPE F VALUE '9.99E9',
D TYPE D VALUE '19950101',
T TYPE T VALUE '235959',
END OF CONST_REC.
CONTINUE
Basic form CONTINUE.
Effect Within loop structures like
- DO ... ENDDO
- WHILE ... ENDWHILE
- LOOP ... ENDLOOP
- SELECT ... ENDSELECT
CONTINUE terminates the current loop pass, returns the
processing to the beginning of the loop and starts the next
loop pass, if there is one.
Example DO loop: Omit an area (10 ... 20)
DO 100 TIMES.
IF SY-INDEX >= 10 AND SY-INDEX <= 20.
CONTINUE.
ENDIF.
...
ENDDO.
Related CHECK, EXIT
CONTROLS
Basic form CONTROLS ctrl TYPE ctrl_type.
Effect Defines a control
A control defines an ABAP/4 runtime object which displays data
in a particular visual format, depending on the type. It offers
the user standard processing options.
At present, the following types of control are supported:
Table control
Related REFRESH CONTROL
ABAP/4 table control
Basic form CONTROLS ctrl TYPE TABLEVIEW USING SCREEN scr.
Effect Creates a table control ctrl of the type TABLEVIEW. The
reference screen for the initialization is the screen scr.
Area of use
The table control (referred to here as TC ) facilitates the
display and entry of one-line, tabular data in dialog
transactions.
The functional scope has been defined so that you can implement
many typical set operations usually handled by an elementary
STEP-LOOP with the standard methods of a TC.
Functional scope
- Resizeable table grid for displaying and editing data.
- Column width and column position modifiable by user and by
program.
- Storing and loading of user-specific column layout.
- Selection column for line selection with color selection
display.
- Variable column headers as pushbuttons for column selection.
- Simple selection, multiple selection, Select/deselect all.
- Scrolling functions (horizontal and vertical) via scroll
bar.
- Fixing of any number of key columns.
- Setting attributes for each cell at runtime.
Programming
The data exchange between the application and the SAPgui is
achieved with a STEP-LOOP, i.e. an ABAP/4 module is called to
transfer data for each page.
Example Processing without an internal table
PROCESS BEFORE OUTPUT.
LOOP WITH CONTROL ctrl.
MODULE ctrl_pbo.
ENDLOOP.
PROCESS AFTER INPUT.
LOOP WITH CONTROL ctrl.
MODULE ctrl_pai.
ENDLOOP.
In this case, the module ctrl_pbo OUTPUT is called once for
each output line before the screen is displayed, in order to
fill the output fields.
After the user has entered data on the screen, the module
ctrl_pai INPUT is executed to check the input and copy the new
contents.
Example Processing with an internal table
PROCESS BEFORE OUTPUT.
LOOP AT itab WITH CONTROL ctrl CURSOR ctrl-CURRENT_LINE.
ENDLOOP.
PROCESS AFTER INPUT.
LOOP AT itab WITH CONTROL ctrl.
MODULE ctrl_pai.
ENDLOOP.
Here, the system fills the output fields before displaying the
screen by reading the internal table itab.
When the user has entered data, the module ctrl_pai INPUT must
be executed to check the input and to refresh the contents of
the internal table.
Vertical scrolling with the scroll bar is followed by the event
PAI for the displayed page. Then, cntl-TOP_LINE is increased
and PBO is processed for the next page.
Program-driven scrolling and the most of the functionality
described above is achieved by manipulating the control
attributes.
Attributes
The CONTROLS statement creates a complex data object of the
type CXTAB_CONTROL with the name of the control.
You maintain the initial values in the Screen Painter and
assign the screen with the initial values for a control using
the addition USING SCREEN.
Initialization is achieved automatically in the "1st access to
the control" (setting or reading values).
You can use the customizing button (in the top right corner) to
save the current setting (column widths and column positions)
and use it as the initial value for the next call.
All the initial values can be overwritten by the program using
the MOVE ... TO TC attributes statement.
Example ctrl-fixed_cols = 2. "2 columns fixed
The contents of the SCREEN structure (table Cols) acts as a
default value for each line of this column, but within LOOP ...
ENDLOOP (flow logic), it can be overwritten by LOOP AT SCREEN /
MODIFY SCREEN.
With the attributes listed below, you should be aware of the
following:
LINES This must always be set as the only attribute if
you are not using LOOP AT itab.
TOP_LINE Also set by the SAPgui through the vertical
scroll bar slider.
CURRENT_LINE Read only, set by the system (TOP_LINE +
SY-STEPL - 1)
LEFT_COL Also set by the SAPgui through the horizontal
scroll bar slider.
COLS-INDEX Also set by the SAPgui after moving columns.
COLS-SELECTED Also set by the SAPgui after column selection.
When displaying the control, the system uses the current
contents when the event DCO occurs (i.e. after all PBO modules
have run). The modified values (brought about by the user
making changes on the screen) are set immediately after DCI
(i.e. before the first PAI module runs).
CONVERT
Variants:
1. CONVERT DATE f1 INTO INVERTED-DATE f2.
2. CONVERT INVERTED-DATE f1 INTO DATE f2.
Effect Allows conversion between different formats which do not have
their own type (see also MOVE).
The field f1 is converted from the source format to the target
format and placed in f2.
At present, the following formats are supported:
1. DATE ==> INVERTED-DATE
2. INVERTED-DATE ==> DATE
Both formats form the nine's complement of internal date
representation, e.g. 19950511 ==> 80049488 or 80049488 ==>
19950511. In inverse date format, the most recent date has the
lowest numerical value. This is useful when sorting date
specifications.
Note The technique of modifying the sequence of dates by inverting
the internal date format is only used in very rare cases. For
example, you can sort internal tables in ascending or
descending date order much more elegantly with the additons ...
ASCENDING bzw. ... DESCENDING of the SORT statement.
Example
DATA DATE_INV LIKE SY-DATUM.
CONVERT DATE SY-DATUM INTO INVERTED-DATE DATE_INV.
If, for example, the internal representation of 11.05.95 in
SY-DATUM is 19950511, the value of DATE_INV after execution of
the CONVERT statement is 80049488.
Note Runtime errors:
- CONVERT_ILLEGAL_CONVERSION: Conversion not possible due to
incorrect field length.
CREATE
Basic form CREATE OBJECT obj class.
Addition:
... LANGUAGE langu
Effect Generates an object of the class class.
To address an OLE automation server (e.g. EXCEL) from ABAP/4,
the server must be registered with SAP. The transaction SOLE
allows you to assign an automation server to a class.
The CREATE statement generates the initial object and this can
be processed further with the relevant key words.
The return code value of SY-SUBRC indicates the result of the
generation:
The return code value is set as follows:
SY-SUBRC = 0: Object successfully generated.
SY-SUBRC = 1: SAPGUI communication error.
SY-SUBRC = 2: SAPGUI function call error. The OLE function
modules are implemented only under Windows.
SY-SUBRC = 3: The OLE API call resulted in an error; this is
possibly a storage space problem.
SY-SUBRC = 4: The object is not registered with SAP.
Addition ... LANGUAGE langu
Effect Determines the language chosen for method and attribute names
of the object class.
If no specification is made, English is the default.
CREATE OBJECT belongs to a group of key words which allow you
to process external objects with ABAP/4. At present, only the
object model OLE2 is supported, i.e. all objects must be of
type OLE2_OBJECT. This type and other necessary data are
defined in the include program OLE2INCL.
Example Generate an EXCEL object.
INCLUDE OLE2INCL.
DATA EXCEL TYPE OLE2_OBJECT.
CREATE OBJECT EXCEL 'Excel.Application'.
Related SET PROPERTY
GET PROPERTY
CALL METHOD
FREE OBJECT
This statement is not supported in the R/3 System. Use the
following function modules instead:
CONVERT_TO_FOREIGN_CURRENCY
CONVERT_TO_LOCAL_CURRENCY
DATA
Variants:
1.DATA f.
2.DATA f(len).
3.DATA: BEGIN OF rec,
...
END OF rec.
4. DATA: BEGIN OF itab OCCURS n,
...
END OF itab.
5. DATA: BEGIN OF COMMON PART c,
...
END OF COMMON PART.
Effect Defines global and local variables. Variables allow you to
address declared data objects. They always have a particular
data type. Data types and data objects are important components
of the ABAP/4 type concept.
Variant 1 DATA f.
Additions:
1. ... TYPE typ
2. ... LIKE f1
3. ... TYPE typ OCCURS n
4. ... LIKE f1 OCCURS n
5. ... TYPE LINE OF itabtyp
6. ... LIKE LINE OF itab
7. ... VALUE lit
8. ... DECIMALS n
9. ... WITH HEADER LINE
Effect Creates the internal field f in its standard length. If you do
not specify the type (using the addition TYPE), a field of type
C is assumed.
The field f can be up to 30 characters long. You can use any
characters you like except the special characters '(', ')',
'+', '-', ',' and ':'. Numeric characters are allowed but the
field name may not consist of numbers alone.
SPACE is a reserved word and therefore cannot be used. Also,
the field name cannot be the same as one of the additional
parameters of the introductory key word (e.g. PERFORM SUB USING
CHANGING.).
Recommendations for field names:
1. Always use a letter as the first character.
2. Use the underscore to join together words which are part of
the same name (e.g. NEW_PRODUCT). The hyphen should not be
used here, since it is reserved for the names of field
string components (see below).
Addition 1 ... TYPE typ.
Effect Creates a field f of the type typ. You can use either one of
the predefined types listed below or one of your own types
which you define with TYPES.
The standard length (SL) of the field depends on the type.
Type Description SL Initial value
C Text (character) 1 Blank
N Numeric text 1 '00...0'
D Date (YYYYMMDD) 8 '00000000'
T Time (HHMMSS) 6 '000000'
X Hexadecimal 1 X'00'
I Whole number (integer) 4 0
P Packed number 8 0
F Floating point no. 8 '0.0'
Example
DATA NUMBER TYPE I.
Creates the field NUMBER as type I. You can also use it in the
program, particularly if you want to assign number values and
perform calculations.
Notes - The data type I is the whole number type on which the
hardware is based. Its value range is from -2*31 to 2*31-1
(from -2.147.483.648 to 2.147.483.647).
You use type P for fields containing monetary amounts, but
type I is more suitable for number fields, index fields,
specifying positions and so forth.
- You can use type F for positive and negative numbers other
than zero in the range from 1E-307 to 1E+308 with a degree
of accuracy up to 15 decimal places. (The ABAP/4 processor
always uses the floating point operations of the hardware in
question rather than standardizing them.) Floating point
literals must be enclosed in quotation marks. The standard
output length is 22.
Entries in type F fields may be formatted in any of the
following ways:
As a decimal number with or without sign and with or without
a decimal point.
In the form <mantissa>e<exponent>, where you specify the
mantissa as above and the exponent with or without a sign.
(Examples of floating point literals: '1', '-12.34567',
'-765E-04', '1234E5', '12E34', '+12.3E-4'.
Since floating point arithmetic is fast on our hardware
platforms, you should use it when you need a greater value
range and you are able to tolerate rounding errors. Rounding
errors may occur when converting the external (decimal)
format to the corresponding internal format (base 2 or 16)
or vice-versa (ABAP/4 number types).
Addition 2 ... LIKE f1
Effect Creates the field f with the same field attributes as the field
F1 which is already known. Any data objects are valid (fields,
parameters, structures, ...) as long as types have been
assigned.
f1 can be any Dictionary reference.
Example
DATA TABLE_INDEX LIKE SY-TABIX.
The field TABLE_INDEX now has the same attributes as SY-TABIX
(the index for internal tables).
Note This addition is often useful, since the ABAP/4 runtime system
performs type changes on fields automatically. Any unnecessary
and/or unwanted conversions are thus avoided.
Addition 3 ... TYPE typ OCCURS n
Effect Defines an internal table without header line. Such a table
consists of any number of table lines with the type typ.
To fill and edit this table, you can use statements like
APPEND, READ TABLE, LOOP and SORT.
The OCCURS parameter n defines how many tables lines are
created initially. If necessary, you can increase the size
later. Otherwise, the OCCURS parameter is of no significance,
apart from the exception that applies with APPEND SORTED BY.
Example
TYPES: BEGIN OF LINE_TYPE,
NAME(20) TYPE C,
AGE TYPE I,
END OF LINE_TYPE.
DATA: PERSONS TYPE LINE_TYPE OCCURS 20,
PERSONS_WA TYPE LINE_TYPE.
PERSONS_WA-NAME = 'Michael'.
PERSONS_WA-AGE = 25.
APPEND PERSONS_WA TO PERSONS.
PERSONS_WA-NAME = 'Gabriela'
PERSONS_WA-AGE = 22.
APPEND PERSONS_WA TO PERSONS.
The internal table PERSONS now consists of two table entries.
Note Access to table entries not in main memory takes much longer.
On the other hand, there is not enough space in main memory to
hold such large tables because the roll area is resticted (see
above).
Addition 4 ... LIKE f1 OCCURS n
Effect Defines an internal table without header line. Such a table
consists of any number of table lines with the structure as
specified by the data object f1. Processing is the same as for
addition 3.
Example
DATA: BEGIN OF PERSON,
NAME(20),
AGE TYPE I,
END OF PERSON.
DATA: PERSONS LIKE PERSON OCCURS 20.
PERSON-NAME = 'Michael'.
PERSON-AGE = 25.
APPEND PERSON TO PERSONS.
PERSON-NAME = 'Gabriela'
PERSON-AGE = 22.
APPEND PERSON TO PERSONS.
The internal table PERSONS now consists of two table entries.
Addition 5 ... TYPE LINE OF itabtype
Effect The specified type itabtyp must be an internal table type. This
operation creates a data object with the same line type as the
table type specified.
Example
TYPES TAB_TYP TYPE I OCCURS 10.
DATA TAB_WA TYPE LINE OF TAB_TYP.
The data object TAB_WA now has the same attributes as a line of
the table type TAB_TYP and thus the type I.
Addition 6 ... LIKE LINE OF itab
Effect The data object tab must be an internal table with or without a
header line. This operation creates a data object with the same
line type as the table specified.
Example
DATA TAB TYP TYPE I OCCURS 10.
DATA TAB_WA TYPE LINE OF TAB.
The data object TAB_WA now has the same attributes as a line of
the table TAB and thus the type I.
Addition 7 ... VALUE lit
Effect The initial value of the field f is the literal lit instead of
that defined in the table above. You can also specify a
constant or even use IS INITIAL. In the latter case, the field
is preset to the type-specific initial value. This form is
particularly important in connection with the CONSTANTS
statement which always requires you to use the addition VALUES.
Example
DATA NUMBER TYPE I VALUE 123,
FLAG VALUE 'X',
TABLE_INDEX LIKE SY-TABIX VALUE 45.
When created, the field NUMBER of type I contains 123 rather
than the expected initial value of 0. The newly created field
FLAG of type C (length 1) contains 'X', while TABLE_INDEX
contains 45, since the system field SY-TABIX is a numeric
field.
Addition 8 ... DECIMALS n
Effect Only makes sense with field type P. When you perform
calculations and on output, the field has n decimal decimal
places, where n is a number between 0 and 14.
In the case of newly generated programs, you normally activate
fixed point arithmetic in the attributes. If it is not set, the
DECIMALS specification is taken into account on output, but not
when performing calculations. This means that the programmer
must take care of any decimal point calculations by multiplying
or dividing by powers of ten. (see COMPUTE)
Fixed point arithmetic should always be active when you are
performing calculations, since this enables intermediate
results (for division) to be calculated as accurately as
possible (in this case, to 31 decimal places).
To decide whether you should use the fixed point type P or the
floating point type F, see "ABAP/4 number types".
Addition 9 ... WITH HEADER LINE
Effect You can only use this addition with table types. When you
specify WITH HEADER LINE, you create a header line with the
same name type as a table line in addition to the table. With
non-table operations (e.g. MOVE), the name f refers to this
header line. With table operations (e.g. APPEND,
the name f refers to the table or the table and header line.
The notation f[] always denotes the table. The result of this
expression is a table without a header line and can be used as
such.
Example
DATA: BEGIN OF PERSON_TYPE,
NAME(20),
AGE TYPE I,
END OF PERSON_TYPE.
DATA: PERSONS LIKE PERSON_TYPE OCCURS 20 WITH HEADER LINE.
PERSON-NAME = 'Michael'.
PERSON-AGE = 25.
APPEND PERSONS.
PERSON-NAME = 'Gabriela'
PERSON-AGE = 22.
APPEND PERSONS.
Delete header line
CLEAR PERSONS.
Delete table
CLEAR PERSONS[].
Variant 2 DATA f(len).
Additions:
As for variant 1
Effect Creates the field f in the length len.
You can use this variant only for fields of type C, N, P and X.
Any other field types must have their standard lengths (see
table under effect of variant 1).
The lengths allowed depend on the field type:
Type Allowed lengths
C 1 - 65535
N 1 - 65535
P 1 - 16
X 1 - 65535
Note Each byte can contain (one character or) two decimal or
hexadecimal digits. Since one place in type P fields is
reserved for the sign, a type P field of length 3 can contain 5
digits, whereas a type X field of length 3 can hold 6 digits.
Both have an output length of 6.
Variant 3 DATA: BEGIN OF rec,
...
END OF rec.
Effect Defines the field string rec which groups together all the
fields defined for the field string rec between "BEGIN OF REC"
and "END OF rec". Each field carries the prefix "rec-". Field
strings can be nested to any depth. See Data objects.
When a field string needs the same fields as an already defined
field string in addition to its own fields, you can include
these fields in the field string with INCLUDE STRUCTURE. If no
additional fields are needed, it is better to use LIKE.
Example
DATA: BEGIN OF PERSON,
NAME(20) VALUE 'May',
AGE TYPE I,
END OF PERSON.
PERSON-AGE = 35.
The field PERSON-NAME now contains the contents "May".
DATA: BEGIN OF PERSON1,
FIRSTNAME(20) VALUE 'Michael'.
INCLUDE STRUCTURE PERSON.
DATA END OF PERSON1.
Notes - If you list a field string as a field, this field ("rec") is
type C, but you should not use a field string like a field,
if the field string contains number fields (i.e. type I, F
or F). The length of rec is derived from the sum of the
lengths of all components of rec. However, since some fields
(for example, to the limit of a word), they include padding
fields that also contribute to the overall length of rec;
for this reason, you cannot use the lengths of fields that
occur before a particular field string component to
calculate its offset to the start of the field string. On
the other hand, you can guarantee that two fields with the
same structure always have the same structure (even where
padding fields are concerned). This means that you can
compare and assign fields directly below each other (with
MOVE, IF, etc.) and do not have to work field by field (e.g.
with MOVE-CORRESPONDING).
INCLUDEs are aligned according to maxumum alignment of their
components. This applies both to INCLUDEs in ABAP/4 programs
and also INCLUDEs in Dictionary structures.
- The TABLES statement automatically defines a field string
(the work area. Even the header line belonging to an
internal table (see below) is a field string.
Variant 4 DATA: BEGIN OF itab OCCURS n,
...
END OF itab.
Additions:
... VALID BETWEEN f1 AND f2
Effect Defines the internal table itab.
An internal table includes a header line, which is a field
string containing the fields defined between "BEGIN OF itab
OCCURS n" and "END OF itab" (see variant 3), and any number of
table lines with the same structure as the header line.
To fill and edit an internal table, you use various statements
such as APPEND, READ TABLE, LOOP and SORT.
The OCCURS parameter n determines how many table lines are held
in main storage (the roll area). If you also generate table
entries, these are rolled out either to a main storage buffer
or to disk (the paging area).
Example
DATA: BEGIN OF PERSONS OCCURS 20,
NAME(20),
AGE TYPE I,
END OF PERSONS.
PERSONS-NAME = 'Michael'.
PERSONS-AGE = 25.
APPEND PERSONS.
PERSONS-NAME = 'Gabriela'.
PERSONS-AGE = 22.
APPEND PERSONS.
The internal table now consists of two table entries.
PERSONS also includes the header line (work area) through which
all operations on the actual table pass.
Note Access to table entries not in main storage is considerably
slower. Also, main storage cannot hold large tables in their
entirety, since the size of the roll area is restricted (see
above).
Addition ... VALID BETWEEN f1 AND f2
Effect Can appear only after "END OF itab".
The sub-fields f1 and f2 of the internal table itab must have
the line-related validity range (see PROVIDE).
Variant 5 DATA: BEGIN OF COMMON PART c,
.....
END OF COMMON PART.
Effect Defines one or more common data areas in programs linked by
external PERFORM calls. If only one common data area exists,
you can omit the name c. There may be just one unnamed COMMON
area or one or more named COMMON areas. You assign named COMMON
areas to each other by name. The structure of data areas must
always be the same for both the calling and the called program
(otherwise, the program terminates with an error message at
runtime).
- The table work areas are always in the common data area.
- In general, you define the area created as COMMON with a
common INCLUDE STRUCTURE. Occasionally, you use a INCLUDE
report which contains precisely the definition of the COMMON
PART.
- Field symbols cannot belong to a common data area, even if
the FIELD-SYMBOLS statement lies between DATA BEGIN OF
COMMON PART and DATA END OF COMMON PART.
DEFINE
Basic form DEFINE macro.
Effect Defines a program component (macro) under the name macro. It
must consist only of ABAP/4 statements and is expanded at
compilation time.
A macro should always be concluded with the END-OF-DEFINITION
statement.
In the definition, you can use &n to reference positional
parameters (n = 0 .. 9). When the macro is called, &n is
replaced by the n-th actual parameter.
Example Define a macro called "++" for use in the program.
DEFINE ++.
ADD 1 TO &1.
END-OF-DEFINITION.
DATA: NUMBER TYPE I VALUE 1.
...
++ NUMBER.
Notes - In general, it is better to use subroutines (FORM, FUNCTION)
rather than macros because subroutines - unlike macros - are
supported by all the ABAP/4 Development Workbench tools
(including debugging, runtime analysis, runtime error
handling, ...).
- You cannot nest macro definitions.
DELETE
Delete from a database table
- DELETE FROM dbtab WHERE condition.
DELETE FROM (dbtabname) WHERE condition.
- DELETE dbtab.
DELETE *dbtab.
DELETE (dbtabname) ... .
- DELETE dbtab FROM TABLE itab.
DELETE (dbtabname) FROM TABLE itab.
- DELETE dbtab VERSION vers.
DELETE *dbtab VERSION vers.
Delete from an internal table
- DELETE itab.
- DELETE itab INDEX idx.
- DELETE itab FROM idx1 TO idx2.
- DELETE itab WHERE condition.
- DELETE ADJACENT DUPLICATES FROM itab.
Delete a program
- DELETE REPORT prog.
Delete text elements
- DELETE TEXTPOOL prog LANGUAGE lg.
Delete a data cluster
- DELETE FROM DATABASE dbtab(ar) ...ID key.
Delete a file
- DELETE DATASET dsn.
Delete a screen
- DELETE DYNPRO f.
DELETE - delete a file
Basic form DELETE DATASET dsn.
Effect Deletes the file specified in the field dsn.
The return code value is set as follows:
SY-SUBRC = 0: File deleted.
SY-SUBRC = 4: File does not exist or could not be deleted.
Possible reasons:
1) The file does not exist.
2) The file is a directory.
3) The R/3 System has no search authorization
for a component of the file name.
4) The R/3 System has no search authorization
for the directory which contains the file.
5) A component of the search path is not a
directory.
6) The file is a symbolic link which cannot be
resolved (endless loop ?).
7) The file is a program which is currently
running.
Related OPEN DATASET, READ DATASET, CLOSE.
DELETE - Delete from a database table
Variants:
1. DELETE FROM dbtab WHERE condition.
DELETE FROM (dbtabname) WHERE condition.
2. DELETE dbtab.
DELETE *dbtab.
DELETE (dbtabname) ...
3. DELETE dbtab FROM TABLE itab.
DELETE (dbtabname) FROM TABLE itab.
4. DELETE dbtab VERSION vers.
DELETE *dbtab VERSION vers.
Effect Deletes lines in a database table. You can specify the name of
the database table either in the program itself with DELETE
FROM dbtab ... or at runtime as the contents of the field
dbtabname with DELETE FROM (dbtabname) .... In both cases, the
database table must be known in the ABAP/4 Dictionary. If you
specify the name in the program, there must also be an
appropriate TABLES statement. Only data from the current client
is usually deleted. You can delete data using a view only if
the view refers to a single table and was created in the ABAP/4
Dictionary with the maintenance status "No restriction".
DELETE belongs to the Open SQL command set.
Note The DELETE statement does not perform authorization checks: You
must program these yourself.
Variant 1 DELETE FROM dbtab WHERE condition.
DELETE FROM (dbtabname) WHERE condition.
Addition:
... CLIENT SPECIFIED
Effect Deletes lines in a database table that satisfy the WHERE clause
condition. With this variant, specification of a WHERE
condition is obligatory.
When the statement has been executed, the system field SY-DBCNT
contains the number of deleted lines.
The return code value is set as follows:
SY-SUBRC = 0: At least one line was deleted.
SY-SUBRC = 4: No lines were deleted, since no line was
selected.
Example Delete all bookings for the Lufthansa flight 0400 on 28.02.1995
(in the current client):
TABLES SBOOK.
DELETE FROM SBOOK WHERE CARRID = 'LH' AND
CONNID = '0400' AND
FLDATE = '19950228'.
Note To delete all the lines in a table, you must specify a WHERE
condition that is true for all lines. You can achieve this with
... WHERE f IN itab
If the internal table itab is empty, such a condition would
select all lines.
Addition ... CLIENT SPECIFIED
Effect Switches off automatic client handling. This allows you to
delete data across all clients in the case of client-specific
tables. The client field is then treated like a normal table
field, for which you can formulate suitable conditions in the
WHERE clause.
You must specify the addition CLIENT SPECIFIED immediately
after the name of the database table.
Variant 2 DELETE dbtab.
DELETE *dbtab.
DELETE (dbtabname) ...
Additions:
1. ... FROM wa
2. ... CLIENT SPECIFIED
Effect These are SAP-specific short forms used to delete a single line
of a database table. If the name of the database table is
specified in the program, the primary key of the line to be
deleted is taken from the specified work area - dbtab or
*dbtab. If the name of the database table is not determined
until runtime (DELETE (dbtabname) ...), the addition ... FROM
wa is obligatory.
When the statement has been executed, the system field SY-DBCNT
contains the number of deleted lines (0 or 1).
The return code value is set as follows:
SY-SUBRC = 0: The line was deleted.
SY-SUBRC = 4: No lines could be deleted, since no line exists
with the primary key specified.
Example Delete the booking with the booking number 3 for the Lufthansa
flight 0400 on 28.02.1995 (in the current client):
TABLES SBOOK.
SBOOK-CARRID = 'LH'.
SBOOK-CONNID = '0400'.
SBOOK-FLDATE = '19950228'.
SBOOK-BOOKID = '00000003'.
DELETE SBOOK.
Addition 1 ... FROM wa
Effect Takes the primary key for the line to be deleted not from the
table work area dbtab, but from the explicitly specified work
area wa. Here, the key values from left to right are taken from
wa according to the structure of the primary key in the table
work area dbtab (see TABLES). The structure of wa is not taken
into account. Therefore, the work area wa must be at least as
wide (see DATA) as the primary key in the table work area dbtab
and the alignment of the work area wa must correspond to the
alignment of the primary key in the table work area. Otherwise,
you get a runtime error.
Note If a work area is not explicitly specified, the values for the
line to be deleted are taken from the table work area dbtab,
even if the statement appears in a subroutine (see FORM) or
Funktionsbaustein (see FUNCTION) where the table work area is
stored in a formal parameter or a local variable of the same
name.
Addition 2 ... CLIENT SPECIFIED
Effect As with variant 1.
Variant 3 DELETE dbtab FROM TABLE itab.
DELETE (dbtabname) FROM TABLE itab.
Addition:
... CLIENT SPECIFIED
Effect Mass deletion: Deletes all database table lines for which the
internal table itab contains values for the primary key fields.
The lines of the internal table itab must satisfy the same
condition as the work area wa in addition 1 to variant.
The system field SY-DBCNT contains the number of deleted lines,
i.e. the number of lines of the internal table itab for whose
key values there were lines in the database table dbtab.
The return code value is set as follows:
SY-SUBRC = 0: All lines from itab could be used to delete
lines from dbtab.
SY-SUBRC = 4: For at least one line of the internal table in
the database table, there was no line with the
same primary key. All found lines are deleted..
Note If the internal table itab is empty, SY-SUBRC and SY-DBCNT are
set to 0.
Addition ... CLIENT SPECIFIED
Effect As with variant 1.
Variant 4 DELETE dbtab VERSION vers.
DELETE *dbtab VERSION vers.
Note This variant is obsolete, since variants 1 - 3 allow you to
specify the database table name dynamically.
Effect Deletes a line in a database table, the name of which is taken
from the field vers at runtime. The database table must be
known to the ABAP/4 Dictionary and its name must conform to the
following naming convention: It must begin with 'T' and can
consist of four additional characters. The field vers must
contain the table name without a leading 'T'. Only lines in the
current client are deleted. The line to be deleted is taken
from the statically specified table work area dbtab or *dbtab.
The return code value is set as follows:
SY-SUBRC = 0: The line was deleted.
SY-SUBRC = 4: No lines could be deleted because no line
existed with the specified primary key.
DELETE DYNPRO - delete a screen
Note This statement is for internal use only.
Incompatible changes or further developments may occur at any
time without warning or notice.
Basic form DELETE DYNPRO f.
Effect Deletes the screen specified in the field f.
The return code value is set as follows:
SY-SUBRC = 0: The screen was deleted.
SY-SUBRC = 4: The screen does not exist.
The contents of f consist of the 8-character program name and
the 4-character screen number.
Example
DELETE DYNPRO 'SAPTESTX0100'.
Related IMPORT DYNPRO, EXPORT DYNPRO, GENERATE DYNPRO, SYNTAX-CHECK FOR
DYNPRO.
DELETE - delete a data cluster
Basic form DELETE FROM DATABASE dbtab(ar) ID key.
Addition:
... CLIENT f
Effect Deletes the data cluster stored in the table dbtab under the
area ar (constant) and the ID key (field or literal) (EXPORT
... TO DATABASE ...).
Example
TABLES INDX.
DATA: BEGIN OF TAB OCCURS 1,
CONT(30),
END OF TAB.
DATA: FLD(30) TYPE C.
...
EXPORT TAB FLD TO DATABASE INDX(AR) ID 'TEST'.
You can delete this data cluster with the following statement:
DELETE FROM DATABASE INDX(AR) ID 'TEST'.
Addition 1 ... CLIENT f
Effect Deletes the data cluster in the client specified in the table f
(only with client-specific import/export databases).
Example
TABLES INDX.
DELETE FROM DATABASE INDX(AR) CLIENT '001' ID 'TEST'.
DELETE - Delete from an internal table
Variants:
1. DELETE itab.
2. DELETE itab INDEX idx.
3. DELETE itab FROM idx1 TO idx2.
4. DELETE itab WHERE condition.
5. DELETE ADJACENT DUPLICATES FROM itab.
Effect Deletes one or more lines from an internal table.
Note The deletion of lines within a LOOP ... ENDLOOP loop is
performed in a sequence of loop passes.
Variant 1 DELETE itab.
Effect The current entry of the internal table itab is
deleted in a LOOP loop.
The return code value is set to 0.
Note After deleting the current entry in an internal table in a LOOP
loop, the effect of further update operations on the current
entry without an INDEX specification is not guaranteed and may
changed in later Releases.
Variant 2 DELETE itab INDEX idx.
Effect Deletes the idx entry from the internal table itab.
The return code value is set as follows:
SY-SUBRC = 0: The entry was deleted.
SY-SUBRC = 4: The entry does not exist.
Variant 3 DELETE itab FROM idx1 TO idx2.
Effect Deletes the line area from index idx1 to idx2 from internal
table itab. At least one of the two parameters FROM idx1 or TO
idx2 should be specified. If parameter FROM is missing, the
area from the start of the table to line idx2 is deleted. If
parameter TO is missing, the area from line idx1 to the end of
the table is deleted. Start index idx1 must be greater than 0.
The return code value is set as follows:
SY-SUBRC = 0: At least one entry was deleted.
SY-SUBRC = 4: None of the entries were deleted.
Variant 4 DELETE itab WHERE condition.
Additions:
1. ... FROM idx1
2. ... TO idx2
Effect Deletes all entries from internal table itab, which satisfies
the condition condition.
The return code value is set as follows:
SY-SUBRC = 0: At least one entry was deleted.
SY-SUBRC = 4: None of the entries were deleted.
Addition 1 ... FROM idx1
Effect The line area to be investigated is restricted to the lines up
to index idx1. If the addition FROM idx1 is missing, a search
is carried out from the beginning of the table.
The addition FROM must come before the WHERE condition.
Addition 2 ... TO idx2
Effect Restricts the line area to be investigated to the lines up to
index idx2. If the addition TO idx2 is missing, a search is
carried out until the end of the table.
The addition TO must come before the WHERE condition.
Example Delete all lines in a name table between lines 5 and 36, if the
entry begins with one of the letters 'A' to 'C':
DATA: BEGIN OF NAMETAB OCCURS 100,
NAME(30) TYPE C, END OF NAMETAB.
...
DELETE NAMETAB FROM 5 TO 36 WHERE NAME CA 'ABC'.
Variant 5 DELETE ADJACENT DUPLICATES FROM itab.
Additions:
1. ... COMPARING f1 f2 ...
2. ... COMPARING ALL FIELDS
Effect Deletes neighboring, duplicate entries from the internal table
itab. If there are n duplicate entries, the first entry is
retained and the other n - 1 entries are deleted.
Two lines are considered to be duplicated if their default keys
match.
The return code value is set as follows:
SY-SUBRC = 0: At least one duplicate exists, at least one
entry deleted.
SY-SUBRC = 4: No duplicates exist, no entry deleted.
Addition 1 ... COMPARING f1 f2 ...
Effect Two lines of the internal table itab are considered to be
duplicates if the specified fields f1, f2, .... match.
Addition 2 ... COMPARING ALL FIELDS
Effect Two lines are considered to be duplicates if all fields of the
table entries match.
Notes 1. The DELETE ADJACENT DUPLICATES statement is especially
useful if the internal table itab is sorted by fields
(whether in ascending or descending order) which were
compared during duplicate determination. In this case, the
deletion of neighbouring duplicates is the same as the
deletion of all duplicates.
2. If a comparison criterion is only known at runtime, it can
be specified dynamically as the content of a field name by
using COMPARING ... (name) .... If name is blank at runtime,
the comparison criterion is ignored. If name contains an
invalid component name, a runtime error occurs.
3. Comparison criteria - statistically or dynamically specified
- can be further restriced by specifying the offset and/or
length.
Note Performance:
1. Deleting a line from an internal table incurs index
maintenance costs which depend on the index of the line to
be deleted. The runtime depends on the line width of the
table.
For example, deleting a line in the middle of an internal
table with 200 entries requires about 10 msn (standardized
microseconds).
Deleting a range of entries with "DELETE itab FROM idx1 TO
idx2." deleting a set of entries with "DELETE itab WHERE
..." only incur index maintenance costs once. Compared with
a LOOP, which deletes line-by-line, this is much faster.
2. To delete neighboring, duplicate entries from an internal
table, use the variant "DELETE ADJACENT DUPLICATES FROM
itab." instead of LOOP constructions.
Related INSERT itab, MODIFY itab
DELETE - delete a program
Note This statement is for internal use only.
Incompatible changes or further developments may occur at any
time without warning or notice.
Basic form DELETE REPORT prog.
Effect Deletes some components (source code, attributes, text elements
and generated version) of the program specified in the field
prog.
The return code value is set as follows:
SY-SUBRC = 0: The program was deleted.
SY-SUBRC = 4: The program does not exist.
Note This statement deletes neither the variants nor the
documentation.
Normally, you should use the function module RS_DELETE_PROGRAM
to delete a program.
Related INSERT REPORT, DELETE TEXTPOOL
DELETE - delete text elements
Note This statement is for internal use only.
Incompatible changes or further developments may occur at any
time without warning or notice.
Basic form DELETE TEXTPOOL prog LANGUAGE lg.
Effect Deletes all text elements of the program specified in the field
prog for the language specified in the field lg from the
library.
If you use the value '*' for lg, the text elements of all
languages are deleted.
Example Delete all text elements of the program PROGNAME in the
language "English":
DATA: PROGRAM(8) VALUE 'PROGNAME'.
DELETE TEXTPOOL PROGRAM LANGUAGE 'E'.
Related INSERT TEXTPOOL, READ TEXTPOOL
DEQUEUE is not an ABAP/4 key word (in R/3).
To unlock resources, you must use a function module.
DESCRIBE
Return attributes of a field
- DESCRIBE FIELD f.
Return attributes of an internal table
- DESCRIBE TABLE itab.
Determine distance between two fields
- DESCRIBE DISTANCE BETWEEN f1 AND f2 INTO f3.
Return attributes of a list
- DESCRIBE LIST NUMBER OF LINES lin.
- DESCRIBE LIST NUMBER OF PAGES n.
- DESCRIBE LIST LINE lin PAGE pag.
- DESCRIBE LIST PAGE pag.
DESCRIBE DISTANCE BETWEEN f1 AND f2 INTO f3
Effect Returns the distance between the fields f1 and f2 in f3.
Example
TABLES LFA1.
DATA DIS TYPE P.
DESCRIBE DISTANCE BETWEEN LFA1-LAND1
AND LFA1-NAME1
INTO DIS.
Result: DIS contains the value 14, since exactly two fields lie
between LAND1 and NAME1, namely LNRZA (10 bytes) and LOEVM (1
byte); additionally, the sub-field LAND1 is 3 bytes long.
Therefore, the start of the sub-field LAND1 is exactly 14 bytes
from the start of the sub-field NAME1.
DESCRIBE - determine distance between two fields
Basic form DESCRIBE DISTANCE BETWEEN f1 AND f2 INTO f3.
Effect Determines the distance between the fields f1 and f2 and places
the result (in bytes) in f3.
Example Determine the distance between two components of the demo table
SBOOK in the flight reservation system:
TABLES SBOOK.
DATA DIST TYPE I.
DESCRIBE DISTANCE BETWEEN SBOOK-CARRID
AND SBOOK-BOOKID
INTO DIST.
Result: DIST contains the value 15 because exactly two fields,
SFLIGHT-CONNID (4 bytes) and SBOOK-FLDATE (8 bytes), lie
between the SBOOK components CARRID and BOOKID; also,
SBOOK-CARRID is itself 3 bytes long. The sum of these values
gives the distance between the two components in bytes.
DESCRIBE - Supply attributes of a field
Basic form DESCRIBE FIELD f.
Effect Supplies the attributes of the field f. You must specify at
least one of the additions:
Additions:
1. ... LENGTH len
2. ... TYPE typ
3. ... TYPE typ COMPONENTS n
4. ... OUTPUT-LENGTH len
5. ... DECIMALS n
6. ... EDIT MASK mask
Addition 1 ... LENGTH len
Effect Returns the length of the field f in the field
len.
Example
DATA: FLD(8),
LEN TYPE P.
DESCRIBE FIELD FLD LENGTH LEN.
Result: LEN contains the value 8.
Addition 2 ... TYPE typ
Effect Returns the data type of f in the field typ
Example
DATA: FLD(8) TYPE N,
F_TYPE.
DESCRIBE FIELD FLD TYPE F_TYPE.
Result: F_TYPE contains the value 'N'.
Note Along with the elementary data types you can specify
under DATA (C, N, etc.), several other data types are created
either with reference to Dictionary fields or during
generation. These data types, which are also returned by
DESCRIBE, have the following type IDs:
h Internal table
s 2-byte integer with leading sign
b 1-byte integer without leading sign
u Structure without internal table
v Structure containing at least one internal table
For compatibility reasons, ... TYPE typ returns C rather than u
or v with structures.
Addition 3 ... TYPE typ COMPONENTS n
Effect Similar to ... TYPE typ except that, with structures in typ, u
or v are returned and in the number of structure components is
set in n. If f is not a structure, n is set to 0.
Example Recursive processing of the pages of an ABAP/4 data structure:
FORM TEST USING F.
DATA: TYP(1) TYPE C, N TYPE I.
FIELD-SYMBOLS: <F>.
DO.
ASSIGN COMPONENT SY-INDEX OF STRUCTURE F TO <F>.
IF SY-SUBRC <> 0. EXIT. ENDIF.
DESCRIBE FIELD <F> TYPE TYP COMPONENTS N.
IF N > 0. " Equivalent is TYP = 'u' OR TYP = 'v'
PERFORM TEST USING <F>.
ELSE.
PERFORM DO_SOMETHING USING <F>.
ENDIF.
ENDDO.
ENDFORM.
Addition 4 ... OUTPUT-LENGTH len
Effect Enters the output length of the field f in the variable len.
Example
DATA: FLD(4) TYPE P,
O_LEN TYPE P.
DESCRIBE FIELD FLD OUTPUT-LENGTH O_LEN.
Result: O_LEN contains the value 8.
Addition 5 ... DECIMALS n
Effect Enters the number of decimal places for the field f (defined in
addition ... DECIMALS of the DATA statement or in the ABAP/4
Dictionary) in the variable n.
Example
DATA: FLD(8) TYPE P DECIMALS 2,
DEC TYPE P.
DESCRIBE FIELD FLD DECIMALS DEC.
Resultat: DEC contains the value 2.
Addition 6 ... EDIT MASK mask
Effect If the field f has a conversion routine in the ABAP/4
Dictionary, this is placed in the field mask in the form
"==conv". "conv" stands for the name of the conversion routine,
e.g. "==ALPHA" in the conversion routine "ALPHA". In this form,
mask can then be used in the addition USING EDIT MASK mask of
the WRITE statement.
Example Check whether there is a conversion routine for the field
"customer number" in the table SBOOK:
TABLES SBOOK.
DATA: CONV_EXIT(10).
DESCRIBE FIELD SBOOK-CUSTOMID EDIT MASK CONV_EXIT.
IF CONV_EXIT <> SPACE. ... ENDIF.
Result: CONV_EXIT contains the value "==ALPHA".
Note If the required field is only known at runtime, this field can
also be assigned dynamically to a field symbol (see
FIELD-SYMBOLS, ASSIGN).
DESCRIBE - supply attributes of a list
Variants:
1. DESCRIBE LIST NUMBER OF LINES lin.
2. DESCRIBE LIST NUMBER OF PAGES n.
3. DESCRIBE LIST LINE lin PAGE pag.
4. DESCRIBE LIST PAGE pag.
Effect Returns the attributes of a list. All variants have the
addition ... INDEX idx allowing you to determine the attributes
of a particular list level (SY-LSIND = 0,1,2,3,... ).
Note 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.
Variant 1 DESCRIBE LIST NUMBER OF LINES lin.
Addition:
... INDEX idx
Effect Returns the number of lines in the list.
The return code value is set as follows:
SY-SUBRC = 0: OK
SY-SUBRC <> 0: List does not exist (only with the addition
INDEX)
Addition ... INDEX idx
Effect Returns the attributes of the list level idx (0, 1,2,3,...).
Example After line selection, determine the number of lines in the
displayed list:
DATA: LN LIKE SY-PAGNO. ...
AT LINE-SELECTION.
DESCRIBE LIST NUMBER OF LINES LN.
The variable LN now contains the number of lines in the
displayed list.
Variant 2 DESCRIBE LIST NUMBER OF PAGES n.
Addition:
... INDEX idx
Effect Returns the number of pages in the list.
The return code value is set as follows:
SY-SUBRC = 0: OK
SY-SUBRC <> 0: List does not exist (only with the addition
INDEX)
Addition ... INDEX idx
Effect Returns the attributes of the list level idx (0, 1,2,3,...).
Example After line selection, determine the number of pages in the
displayed list:
DATA: PN LIKE SY-PAGNO. ...
AT LINE-SELECTION.
DESCRIBE LIST NUMBER OF PAGES PN.
The variable PN now contains the number of pages in the
displayed list (i.e. the contents of the system field SY-PAGNO
after the list has been generated!).
Variant 3 DESCRIBE LIST LINE lin PAGE pag.
Addition:
... INDEX idx
Effect Returns the number of the page for the line lin in the list.
Note In interactive reporting, line selection causes a value to be
assigned to the system field SY-LILLI (absolute number of
selected list line). The system field SY-CPAGE contains the
page number for the first displayed line in the list. The
selected line does not have to belong to this page (in cases
where several pages are displayed at the same time). The page
number may be of interest even with direct reading of lines
(see READ LINE).
The return code value is set as follows:
SY-SUBRC = 0: OK
SY-SUBRC = 4: Line does not exist
SY-SUBRC = 8: List does not exist
Addition ... INDEX idx
Effect Returns the attributes of the list level idx (0, 1,2,3,...).
Example After line selection, determine the page number for the
selected line (SY-LILLI):
DATA: PAGENUMBER LIKE SY-PAGNO. ...
AT LINE-SELECTION.
DESCRIBE LIST LINE SY-LILLI PAGE PAGENUMBER.
The variable PAGENUMBER now contains the page number for the
line SY-LILLI (i.e. the contents of the system field SY-PAGNO
when outputting the line SY-LILLI!).
Variant 4 DESCRIBE LIST PAGE pag
Additions:
1. ... INDEX idx
2. ... LINE-SIZE col
3. ... LINE-COUNT lin
4. ... LINES lin
5. ... FIRST-LINE lin
6. ... TOP-LINES lin
7. ... TITLE-LINES lin
8. ... HEAD-LINES lin
9. ... END-LINES lin
Effect Returns the attributes of the page pag in the list.
The return code value is set as follows:
SY-SUBRC = 0: OK
SY-SUBRC = 4: Page does not exist
SY-SUBRC = 8: List does not exist
Addition 1 ... INDEX idx
Effect Returns the attributes of the list level idx (0, 1,2,3,...).
Addition 2 ... LINE-SIZE col
Effect Returns the line length for the page pag (see
NEW-PAGE...LINE-SIZE).
Addition 3 ... LINE-COUNT lin
Effect Returns the permitted number of lines for the page pag (see
NEW-PAGE...LINE-COUNT).
Addition 4 ... LINES lin
Effect Returns the number of lines output on the page pag.
Addition 5 ... FIRST-LINE lin
Effect Returns the absolute line number of the first line of the page
pag.
Addition 6 ... TOP-LINES lin
Effect Returns the number of lines output by page header processing
(i.e. standard title + column headers + TOP-OF-PAGE).
Addition 7 ... TITLE-LINES lin
Effect Returns the number of lines output as standard title lines by
page header processing (see NEW-PAGE...NO-TITLE/WITH-TITLE).
Note The value of TITLE-LINES is contained in TOP-LINES.
Addition 8 ... HEAD-LINES lin
Effect Returns the number of lines output as column headers by page
header processing (see NEW-PAGE...NO-HEADING/WITH-HEADING).
Note The value of HEAD-LINES is contained in TOP-LINES.
Addition 9 ... END-LINES lin
Effect Returns the number of lines reserved for end-of-page processing
(see END-OF-PAGE).
Example Determine the number of lines output on the third page of the
basic list (SY-LSIND = 0) in the event TOP-OF-PAGE:
DATA: TOP TYPE I,
HEAD TYPE I,
TITLE TYPE I,
REAL_TOP TYPE I.
DESCRIBE LIST INDEX 0 PAGE 3
TOP-LINES TOP
HEAD-LINES HEAD
TITLE-LINES TITLE.
REAL_TOP = TOP - TITLE - HEAD.
Examples Determine the absolute number of lines in the displayed list:
DATA: LN TYPE I, "number of lines on a page
FLN TYPE I, "number of first line on a page
PN TYPE I, "number of a page
LIST_LINES TYPE I. "total number of lines in list
Determine number of last page:
DESCRIBE LIST NUMBER OF PAGES PN.
Determine number of first line of last page and number of lines
on that page:
DESCRIBE LIST PAGE PN FIRST-LINE FLN LINES LN.
Number of list lines = number of first line of last page +
number of lines - 1.
LIST_LINES = FLN + LN - 1.
Or: Count lines of all pages in a loop:
CLEAR LIST_LINES.
DO PN TIMES.
DESCRIBE LIST PAGE SY-INDEX LINES LN.
ADD LN TO LIST_LINES.
ENDDO.
or:
DESCRIBE LIST NUMBER OF LINES LIST_LINES.
DESCRIBE - return attributes of an internal table
Basic form DESCRIBE TABLE itab.
Effect Returns the attributes of the internal table itab. You must use
at least one of the additions listed below.
Additions:
1.... LINES lin
2.... OCCURS n
Addition 1 ... LINES lin
Effect Places the number of filled lines of the table t in the field
lin.
Example
DATA: BEGIN OF TAB OCCURS 10,
X,
END OF TAB.
DATA: LIN TYPE P.
...
CLEAR TAB. REFRESH TAB.
MOVE '?' TO TAB-X.
APPEND TAB.
DESCRIBE TABLE TAB LINES LIN.
Result: LIN contains the value 1.
Addition 2 ... OCCURS n
Effect Transfers the size of the OCCURS parameter from the table
definition to the variable n.
Example
DATA: BEGIN OF TAB OCCURS 10,
X,
END OF TAB.
OCC TYPE P.
DESCRIBE TABLE TAB OCCURS OCC.
Result: OCC contains the value 10.
Note If the table is meant to accept more lines than specified by
the OCCURS parameter, the parameter value is roughly doubled as
long as the table size remains smaller than 8 KB; this table
area is held in the roll area. If the table exceeds the maximum
permitted size, the OCCURS parameter is not increased and the
remaining part of the table is rolled out to the paging area
(see DATA).
For this reason, the OCCURS value determined by the DESCRIBE
statement may differ from that in the DATA statement.
The runtime required to execute the DESCRIBE TABLE statement is
approx. 4 msn (standardized microseconds).
DETAIL
Basic form DETAIL.
This key word is the same as the statement
FORMAT INTENSIFIED OFF.
The latter is recommended due to better readability.
Note When outputting data to a list, you also use the addition
INTENSIFIED OFF of the WRITE statement to change the output
format for single fields.
Related FORMAT
DIVIDE
Basic form DIVIDE n1 BY n2.
Effect Divides the contents of n1 by n2 and places the result in n1.
This is equivalent to: n1 = n1 / n2.
Example
DATA: SUM TYPE P, NUMBER TYPE P.
DIVIDE SUM BY NUMBER.
Note The details regarding conversions and performance given under
COMPUTE apply equally to DIVIDE. Furthermore: Division by 0 is
not allowed, except where 0 / 0 results in 0.
Note Runtime errors:
- BCD_BADDATA: P field contains no correct BCD format
- BCD_FIELD_OVERFLOW: Result field is too small (type P)
- BCD_OVERFLOW: Overflow during arithmetic operation (type P)
- BCD_ZERODIVIDE: Division by 0 (type P)
- COMPUTE_FLOAT_ZERODIVIDE: Division by 0 (type F)
- COMPUTE_INT_DIV_OVERFLOW: Whole number overflow with
division
- COMPUTE_INT_ZERODIVIDE: Division by 0 (type I)
Related COMPUTE, DIVIDE-CORRESPONDING
DIVIDE-CORRESPONDING
Basic form DIVIDE-CORRESPONDING rec1 BY rec2.
Effect Interprets rec1 and rec2 as field strings, i.e. if rec1 and
rec2 are tables with header lines, the statement is executed
for their header lines.
Searches for all sub-fields that occur both in rec1 and rec2
and then generates, for all field pairs corresponding to the
sub-fields ni, statements similar in the following form:
DIVIDE rec1-ni BY rec2-ni.
The other fields remain unchanged.
With more complex structures, the complete names of the field
pairs must be identical.
Example
DATA: BEGIN OF MONEY,
VALUE_IN(20) VALUE 'German marks'.
USA TYPE I VALUE 100,
FRG TYPE I VALUE 200,
AUT TYPE I VALUE 300,
END OF MONEY,
BEGIN OF CHANGE,
DESCRIPTION(30)
VALUE 'DM to national currency'.
USA TYPE F VALUE '1.5',
FRG TYPE F VALUE '1.0',
AUT TYPE F VALUE '0.14286',
END OF CHANGE.
DIVIDE-CORRESPONDING MONEY BY CHANGE.
‎2009 May 07 1:15 PM
Are you sure this is usefull for the requestor?
At least your entry will be found by using serch - and this is definitly not helpful.
I would prefere if you remove your entry.
Thanks, Horst
‎2009 May 07 1:19 PM
Good point. Theres more to this thread than a supposedly useful answer.
pk
PS: And they always hunt in packs too:
Edited by: kishan P on May 7, 2009 6:01 PM
‎2020 May 05 8:53 AM
‎2007 Jul 03 5:28 AM
HI,
see this link
http://www.sapbrainsonline.com/REFERENCES/ABAP_SYNTAX/SAP_ABAP_SYNTAX.html
http://help.sap.com/saphelp_nw2004s/helpdata/en/fc/eb2ed0358411d1829f0000e829fbfe/frameset.htm
<b>rewards if helpful.</b>
rgds,
bharat.