Вы находитесь на странице: 1из 27

ABAP Keyword Documentation

SAP NetWeaver AS ABAP Release 731, ©Copyright 2015 SAP AG. All rights reserved.

• ABAP Statements
ABAP words
• Operands
• Operators and Expressions

ABAP Statements
ABAP statements consist of the following tokens and end with a period (.).

 ABAP words

 Operands

 Operators

Certain ABAP words, operands and operators form

 expressions,

which can be specified at certain operand positions.

The tokens of a statement must be separated by at least one blank or a line break. Otherwise, blanks and line
breaks between tokens are not significant. An ABAP statement is not restricted to a line in the source text.

No distinction is made between upper and lowercase letters. Apart from ABAP words, operands and operators,
you can also use the following special characters:

 If a number of expressions of the same type with operators are linked to an expression, the priority of
the individual operations can be defined usig round brackets (()).

 For the purpose of calling functions and methods, round brackets (()) can sometimes be used.

 Lists of operands are expressed by round brackets (()) and commas (,) in certain positions.

 When forming a chained statement, a colon (:) and commas (,) can be used.

A number of free-standing special characters, such as round brackets for setting the priority, need to be
separated from other tokens by an empty character. Other special characters - as well as the period at the end
- do not have to be separated by an empty character.

Note
Obsolete syntax forms can still occur in all objects apart from classes. In such cases, you can omit the
separators between the tokens.

Example

ABAP statement with the keyword DELETE, the addition WHERE, the operators =, <, >, AND, OR, the operands
itab, col1, op1, col2, op2, col3, op3and round brackets.

DELETE itab
WHERE ( col1 = op1 AND ( col2 > op2 OR col3 < op3 ) ).

ABAP words
ABAP words are the vocabulary of the ABAP language. ABAP statements are composed of ABAP words,
operands, and operators according to defined syntax rules. ABAP words are taken from the English language
and are grouped into ABAP language elements and ABAP language element additions that express the
semantics of a statement. In addition to letters, ABAP words can also contain hyphens (-) to form multi-word
expressions. As well as ABAP words, some operators are also made up of letters.

The first ABAP word of a statement is the ABAP key word. The remaining ABAP words are additions to a key
word. A single ABAP word can be used both as a keyword and as a non-keyword. For example, DATA is used
as a keyword as well as an addition to other keywords.

ABAP words are not reserved names as in some programming languages. Although the use of an ABAP word
for naming conventions is not forbidden, it should be avoided if possible. As following this rule can itself lead to
such a situation by the introduction of new elements, suitable naming conventions should be observed for
reserved names to avoid a collision with language elements.

The following table contains all ABAP words, the names of predefined data types and the names (consisting of
letters) of operators. Names in ABAP programs are not case-sensitive.

ABAP-SOURCE ABBREVIATED ABSTRACT ACCEPT ACCEPTING


ADD-
ACCORDING ACTIVATION ACTUAL ADD CORRESPON
DING
ADJACENT AFTER ALIAS ALIASES ALIGN
ALL ALLOCATE ANALYSIS ANALYZER AND
APPLICATI
ANY APPEND APPENDAGE APPENDING
ON
ARCHIVE AREA ARITHMETIC AS ASCENDING
ASSERT ASSIGN ASSIGNED ASSIGNING AT
ATTRIBUTES AUTHORITY AUTHORITY-CHECK AVG BACK
BACKGROUND BACKUP BACKWARD BADI BEFORE
BEGIN BETWEEN BIG BINARY BIT
BIT-AND BIT-NOT BIT-OR BIT-XOR BLACK
BLANK BLANKS BLOB BLOCK BLOCKS
BLUE BOUND BOUNDARIES BOUNDS BOXED
BREAK-POINT BT BUFFER BY BYPASSING
BYTE BYTE-CA BYTE-CN BYTE-CO BYTE-CS
BYTE-NA BYTE-NS BYTE-ORDER CA CALL
CALLING CASE CASTING CATCH CENTER
CHAIN-
CENTERED CHAIN CHAIN-INPUT CHANGE
REQUEST
CHANGING CHAR-TO-HEX CHARACTER CHECK CHECKBOX
CLASS-
CI_ CIRCULAR CLASS CLASS-CODING
DATA
CLASS-EVENTS CLASS-METHODS CLASS-POOL CLEANUP CLEAR
CLIENT CLOB CLOCK CLOSE CN
COL_BACKGROU
CO CODE CODING COL_GROUP
ND
COL_POSIT
COL_HEADING COL_KEY COL_NEGATIVE COL_NORMAL
IVE
COL_TOTAL COLLECT COLOR COLUMN COLUMNS
COMMUNICA
COMMENT COMMENTS COMMIT COMMON
TION
COMPARING COMPONENT COMPONENTS COMPRESSION COMPUTE
CONNECTIO
CONCATENATE CONDENSE CONDITION CONNECT
N
CONSTANTS CONTEXT CONTEXTS CONTINUE CONTROL
CONTROLS CONVERSION CONVERT COPIES COPY
CORRESPONDING COUNT COUNTRY COVER CP
CPI CREATE CREATING CRITICAL CS
CURSOR-
CURRENCY CURRENT CURSOR CUSTOMER
SELECTION
CUSTOMER-FUNCTION DANGEROUS DATA DATABASE DATAINFO
DD/MM/YYY
DATASET DATE DAYLIGHT DD/MM/YY
Y
DDMMYY DEALLOCATE DECIMALS DEFAULT DEFERRED
DEFINE DEFINING DEFINITION DELETE DELETING
DESTINATI
DEMAND DEPARTMENT DESCENDING DESCRIBE
ON
DETAIL DIALOG DIRECTORY DISCONNECT DISPLAY
DISPLAY-MODE DISTANCE DISTINCT DIV DIVIDE
DIVIDE- DUPLICATE
DO DUMMY DUPLICATE
CORRESPONDING S
DURATION DURING DYNAMIC DYNPRO E
EDIT EDITOR-CALL ELSE ELSEIF ENABLED
END-
ENABLING ENCODING END ENHANCEMENT- END-LINES
SECTION
END-OF-
END-OF-DEFINITION END-OF-FILE END-OF-PAGE ENDAT
SELECTION
ENDCASE ENDCATCH ENDCHAIN ENDCLASS ENDDO
ENDENHANCEMENT ENDEXEC ENDFORM ENDFUNCTION ENDIAN
ENDIF ENDING ENDINTERFACE ENDLOOP ENDMETHOD
ENDMODULE ENDON ENDPROVIDE ENDSELECT ENDTRY
ENHANCEME
ENHANCEMENT-
ENDWHILE ENGINEERING ENHANCEMENT NT-
POINT
SECTION
ENHANCEMENTS ENTRIES ENTRY ENVIRONMENT EQ
EQUIV ERRORMESSAGE ERRORS ESCAPE ESCAPING
EXCEPTION
EVENT EVENTS EXACT EXCEPTION
-TABLE
EXCEPTIONS EXCLUDE EXCLUDING EXEC EXECUTE
EXPIRATIO
EXISTS EXIT EXIT-COMMAND EXPAND
N
EXPLICIT EXPONENT EXPORT EXPORTING EXTENDED
FIELD-
EXTENSION EXTRACT FETCH FIELD
GROUPS
FILTER-
FIELD-SYMBOLS FIELDS FILE FILTER
TABLE
FIRST-
FILTERS FINAL FIND FIRST
LINE
FIXED-POINT FKEQ FKGE FLUSH FONT
FOR FORM FORMAT FORWARD FOUND
FRAME FRAMES FREE FRIENDS FROM
FUNCTION FUNCTION-POOL FUNCTIONALITY FURTHER GAPS
GE GENERATE GET GIVING GKEQ
GKGE GLOBAL GREEN GROUP GROUPS
GT HANDLE HANDLER HARMLESS HASHED
HAVING HEAD-LINES HEADER HEADERS HEADING
HELP-ID HELP-REQUEST HIDE HIGH HINT
HOLD HOTSPOT I ICON ID
IDENTIFICATION IDENTIFIER IDS IF IGNORING
IMMEDIATELY IMPLEMENTATION IMPLEMENTATIONS IMPLICIT IMPORT
IMPORTING IN INACTIVE INCL INCLUDE
INDEX-
INCLUDES INCLUDING INCREMENT INDEX
LINE
INITIALIZ
INFOTYPES INHERITING INIT INITIAL
ATION
INNER INOUT *-INPUT INPUT INSERT
INTERFACE- INTERFACE
INSTANCES INTENSIFIED INTERFACE
POOL S
INVERTED-
INTERNAL INTERVALS INTO INVERSE
DATE
IS ISO JOB JOIN KEEP
KEEPING KERNEL KEY KEYS KEYWORDS
KIND LANGUAGE LAST LATE LAYOUT
LEFT-
LE LEADING LEAVE LEFT
JUSTIFIED
LEFTPLUS LEFTSPACE LEGACY LENGTH LEVEL
LINE-
LEVELS LIKE LINE LINE-COUNT
SELECTION
LIST-
LINE-SIZE LINEFEED LINES LIST PROCESSIN
G
LOAD-OF-
LISTBOX LITTLE LOAD LOB
PROGRAM
LOCAL LOCALE LOCATOR LOG-POINT LOGFILE
LOGICAL LONG LOOP LOW LOWER
LPI LT M MAIL MAIN
MAJOR-ID MARGIN MARK MASK MATCH
MATCHCODE MAX MAXIMUM MEDIUM MEMORY
MESSAGE MESSAGE-ID MESSAGES METHOD METHODS
MM/DD/YYY
MIN MINIMUM MINOR-ID MM/DD/YY
Y
MMDDYY MOD MODE MODIF MODIFIER
MOVE-
MODIFY MODULE MOVE CORRESPONDIN MULTIPLY
G
MULTIPLY-
NA NAME NAMETAB NATIVE
CORRESPONDING
NB NE NESTING NEW NEW-LINE
NO-
NEW-PAGE NEW-SECTION NEXT NO
DISPLAY
NO-
NO-EXTENSION NO-GAP NO-GAPS NO-GROUPING
HEADING
NO-SCROLLING NO-SIGN NO-TITLE NO-TOPOFPAGE NO-ZERO
NODE NODES NON-UNICODE NON-UNIQUE NOT
NP NS NULL NUMBER O
OCCURRENC
OBJECT OBJECTS OBLIGATORY OCCURRENCE
ES
OCCURS OF OFF OFFSET OLE
ON ONLY OPEN OPTION OPTIONAL
OPTIONS OR ORDER OTHER OTHERS
OUTPUT-
OUT OUTER OUTPUT OVERFLOW
LENGTH
OVERLAY PACK PACKAGE PAD PADDING
PARAMETER- PARAMETER
PAGE PAGES PARAMETER
TABLE S
PART PATTERN PERCENTAGE PERFORM PERFORMIN
G
PERSON PF PF-STATUS PINK PLACES
POOL POS_HIGH POS_LOW POSITION PRAGMAS
PRECOMPILED PREFERRED PRESERVING PRIMARY PRINT
PRINT-CONTROL PRIORITY PRIVATE PROCEDURE PROCESS
PROGRAM PROPERTY PROTECTED PROVIDE PUBLIC
RADIOBUTT
PUSHBUTTON PUT QUEUE-ONLY QUICKINFO
ON
RAISE RAISING RANGE RANGES RAW
READ READ-ONLY READER RECEIVE RECEIVED
RECEIVER RECEIVING RED REDEFINITION REDUCED
REF REFERENCE REFRESH REGEX REJECT
REMOTE RENAMING REPLACE REPLACEMENT REPLACING
REPORT REQUEST REQUESTED RESERVE RESET
RESOLUTION RESPECTING RESPONSIBLE RESULT RESULTS
RETURNCOD
RESUMABLE RESUME RETRY RETURN
E
RIGHTSPAC
RETURNING RIGHT RIGHT-JUSTIFIED RIGHTPLUS
E
RMC_COMMUNICATION RMC_SYSTEM_F
RISK RMC_INVALID_STATUS ROLLBACK
_FAILURE AILURE
ROUND ROWS RUN SAP SAP-SPOOL
SCALE_PRESERVING_SC SCIENTIFI
SAVING SCALE_PRESERVING SCAN
IENTIFIC C
SCIENTIFIC_WITH_LEA SCROLL-
SCREEN SCROLL SCROLLING
DING_ZERO BOUNDARY
SEARCH SECONDARY SECONDS SECTION SELECT
SELECTION- SELECTION
SELECT-OPTIONS SELECTION SELECTION-SCREEN
SET -SETS
SELECTION-TABLE SELECTIONS SEND SEPARATE SEPARATED
SHORTDUMP
SET SHARED SHIFT SHORT
-ID
SIGN SIGN_AS_POSTFIX SIMPLE SINGLE SIZE
SKIP SKIPPING SMART SOME SORT
SORTABLE SORTED SOURCE SPACE SPECIFIED
SPLIT SPOOL SPOTS SQL STABLE
STAMP STANDARD START-OF-SELECTION STARTING STATE
STATUSINF
STATEMENT STATEMENTS STATIC STATICS
O
STEP-LOOP STOP STRUCTURE STRUCTURES STYLE
SUBKEY SUBMATCHES SUBMIT SUBROUTINE SUBSCREEN
SUBTRACT-
SUBSTRING SUBTRACT SUFFIX SUM
CORRESPONDING
SUMMARY SUMMING SUPPLIED SUPPLY SUPPRESS
SWITCH SWITCHSTATES SYMBOL SYNCPOINTS SYNTAX-
CHECK
SYNTAX-TRACE SYSTEM-CALL SYSTEM-EXCEPTIONS SYSTEM-EXIT TAB
TABBED TABLE TABLES TABLEVIEW TABSTRIP
TASK TEST TESTING TEXT TEXTPOOL
THEN TIME TIMES TIMESTAMP TIMEZONE
TITLE TITLE-LINES TITLEBAR ?TO TO
TRACE-
TOKENIZATION TOKENS TOP-LINES TOP-OF-PAGE
FILE
TRANSFORM
TRACE-TABLE TRAILING TRANSACTION TRANSFER
ATION
TRUNCATIO
TRANSLATE TRANSPORTING TRMAC TRUNCATE
N
TRY TYPE TYPE-POOL TYPE-POOLS TYPES
ULINE UNASSIGN UNDER UNICODE UNIQUE
UNIT UNIX UNPACK UNTIL UNWIND
USER-
UP UPDATE UPPER USER
COMMAND
VALUE-
USING UTF-8 VALID VALUE
REQUEST
VERIFICATION
VALUES VARY VARYING VERSION
-MESSAGE
VIA VISIBLE WAIT WARNING WHEN
WHENEVER WHERE WHILE WIDTH WINDOW
WINDOWS WITH WITH-HEADING WITH-TITLE WITHOUT
WORD WORK WRITE WRITER XML
YELLOW YES YYMMDD Z ZERO
ZONE 1 2 3 4
5 6 7

Operands
Typical operands are:

 Data objects from the same ABAP program


Data objects in operand positions are changed (write positions) or evaluated (read positions). At
ceratin read positions you can also specify functions and expressions instead of data objects.

 Types from the same program or the Repository


Types such as data types, classes, or interfaces are specified in declarations, typings, or when
addressing components.
 Callable units from the same program or the Repository
Call units such as ABAP programs, procedures, or dynpros are called during the execution of the
statement.

Additional information:

 Labels for operands

 Specifying operands

 Operand type

 Data objects at operand positions

 Functions and expressions at operand positions

Names for Individual Operands


An individual operand, meaning an operand that is not an expression, can be elementary or made up of
components. Composite operands are:

 Structured data types or data objects (structure)

 Instances of classes (objects)

 Classes

 Interfaces

Accordingly, names for operands are either elementary names or names constructed from multiple names
separated by component selectors. An elementary name is used for addressing:

 elementary operands

 components that are unique in the current context

 superunits made up of components

Naming conventions apply to the elementary names. Composite names with component selectors are used for
addressing individual components. A component can itself be a superunit of further components.
Subcomponents can be addressed by chaining multiple names.

Structure Component Selector


A component comp of a structured data type or a structure struct is accessed using the name
struct-comp

In this case, the character - is the structure component selector. The name struct of a structured data type
or a structure must be to the left of the structure component selector. The name struct can itself be
composite. The name comp of the component must be to the right of the structure component selector.

Example

Declaration of a structure struc with the structured data type spfli from ABAP Dictionary and access to its
component carrid.

DATA struc TYPE spfli.

...

... struc-carrid ...

Object Component Selector


A component comp of an object is accessed using the name

ref->comp

In this case, the character -> is the object component selector. The name ref of a reference variable must be
to the left of the object component selector. The name ref can itself be composite. The name comp of the
component must be to the right of the object component selector. If an attempt is made to access an object
component with a reference variable that contains the null reference, a non-handleable exception is raised.
Dereferencing of a data reference in the statement ASSIGN is an exception to this.

The object component selector dereferences the reference variable ref and makes the components of the
referenced object accessible.

 If ref is an object reference variable, the components comp of the object (attributes and methods) to
which the object reference variable points are addressed using the object component selector.

 If ref is a data reference variable that is typed as a structure, the components comp of the structure to
which the data reference variable points are addressed using the object component selector.

Note

If ref is a data reference variable, the character * can be specified after the object component selector ->.
This creates the general dereferencing operator ->*. The expression ref->* labels the entire data object to
which the data reference variable points. The dereferencing operator is the only way to dereference data
references. In the case of untyped data reference variables, this was only possible using the statement
ASSIGN. The dereferencing operator cannot be specified after object reference variables. The instance
components of classes can only be accessed using the expression ref->comp.

Example

Access to the public attribute a1 of a class c1 by using the object reference variable oref.
CLASS c1 DEFINITION.
PUBLIC SECTION.
DATA a1 TYPE string READ-ONLY.
ENDCLASS.

...

DATA oref TYPE REF TO c1.

... oref->a1 ...

Example

The data reference variable dref is typed as a structure and the component carrid of the referenced
structure is accessed using the object component selector. The expression dref->carrid has the same
meaning as the chaining dref->*-carrid.

DATA dref TYPE REF TO sflight.

...

... dref->carrid ...

Class Component Selector


A static component comp of a class can be accessed using the name

class=>comp

In this case, no instance of the class needs to be created. The characters => are the class component selector.
The name class of a class must be to the left of the class component selector. The name comp of the
component must be to the right of the object component selector.

The class component selector can also be used to access the data types and constants of an interface.

intf=>type, intf=>const

The name intf of an interface must be to the left of the class component sector. The name type of a data
type defined using TYPES or the name const of a constant defined using CONSTANTS must be to the right of
the object component selector.

Note

It is also possible to access the static components of a class using the object component selector if an instance
of the class was created.

Example

Declaration of a class factory and access to its static attribute oref.

CLASS factory DEFINITION CREATE PRIVATE.


PUBLIC SECTION.
CLASS-DATA oref TYPE REF TO factory.
CLASS-METHODS class_constructor.
METHODS do_something.
ENDCLASS.

...

factory=>oref->do_something( ).

...

CLASS factory IMPLEMENTATION.


METHOD class_constructor.
CREATE OBJECT oref.
ENDMETHOD.
METHOD do_something.
...
ENDMETHOD.
ENDCLASS.

Interface component selector


A component comp of an interface is accessed using the name

intf~comp

In this case, the character ~ is the interface component selector. The name intf of an interface must be to the
left of the interface component selector. The name comp of the component must be to the right of the object
component selector.

The name intf~comp identifies the components of interfaces in classes or component interfaces in composite
interfaces.

Note

An interface contains each component exactly once, regardless of how it is composed of component interfaces.
All the interface components are at the same hierarchical level. The name of an interface component is
uniquely defined using intf~comp. intf is always the interface in which the component is declared. A direct
chaining of interface names intf1~...~intfn~comp is not possible.

Example

Declaration of interfaces and access to their components.

INTERFACE i1.
TYPES t1 TYPE string.
ENDINTERFACE.

INTERFACE i2.
INTERFACES i1.
METHODS m2 IMPORTING p1 TYPE i1~t1.
ENDINTERFACE.

CLASS c1 DEFINITION.
PUBLIC SECTION.
INTERFACES i2.
ENDCLASS.
...
DATA oref TYPE REF TO c1.

oref->i2~m2( ... ).

...

CLASS c1 IMPLEMENTATION.
METHOD i2~m2.
...
ENDMETHOD.
ENDCLASS.

Chainings
Whenever operands are grouped together from components, which themselves contain components, the
names of these components are composed from chains with multiple component selectors. The following rules
apply to these chained names:

 The names to the left of each structure component selector must, as a combined group, address a
structured data type or a structure.

 The names to the left of each object component selector must, as a combined group, address a
reference variable.

 The class component selector can occur in a name exactly once as the first selector.

 The interface component selector can only occur more than once in a label if other component
selectors are listed between the individual interface component selectors.

Example

Declaration of a nested structured data type struc2 in struc1 and a structure struc3 in an interface i1.

The component comp of struc3 is a data reference variable of the static type struc1. The i1 interface is the
component interface of i2 and the latter is implemented in c1. In c2, a static attribute is declared as the object
reference of the static type c1. The expression in the last line can be at an operand position that expects a data
object, and labels the component comp of the structure struc2 in a chaining that starts at class c2. A
prerequisite for use of the expression is that both reference variables, oref and dref, point to the respective
instances.

INTERFACE i1.
TYPES: BEGIN OF struc1,
...
BEGIN OF struc2,
...,
comp TYPE ...,
...,
END OF struc2,
...
END OF struc1.
DATA: BEGIN OF struc3,
...
dref TYPE REF TO struc1,
...
END OF struc3.
ENDINTERFACE.

INTERFACE i2.
INTERFACES i1.
ENDINTERFACE.

CLASS c1 DEFINITION.
PUBLIC SECTION.
INTERFACES i2.
ENDCLASS.

CLASS c2 DEFINITION.
PUBLIC SECTION.
CLASS-DATA oref TYPE REF TO c1.
ENDCLASS.

...

... c2=>oref->i1~struc3-dref->struc2-comp ...

Escape Character for Names


The character ! can be written directly before a name in order to distinguish it from an ABAP word with the
same name in a statement. With the exception of the first word, each word of a statement that is preceded by
the escape character is interpreted as an operand, and not as an ABAP word, when the program is generated.
The escape character itself is not part of a name and is ignored when the statement is executed.

Note

The escape character may be required on rare occasions in which the compiler cannot tell the difference
between an operand and a reserved word of the same name. Otherwise, it can be used for the documentation
of operands in the source code.

Example

Without the escape character ! before CHANGING after USING, the following program extract would have
incorrect syntax, because a formal parameter must be entered after USING. Although the second escape
character is not necessary, it serves to document USING after CHANGING as a formal parameter.

FORM test USING !CHANGING


CHANGING !USING.
using = changing.
ENDFORM.

Specifying Individual Operands


There are three ways to specify the names of operands:
Static Specification
The name of the operand must be specified directly. If the name of a data object is specified, the specified
name is used and not the content of the data object.

Example

SUBMIT report.

Dynamic specifications in parentheses


For some statements that are designed for static specification, there is a syntactic form that allows you to
specify the name of a character-type data object in parentheses at the operand position. At the time of
execution, the data object must contain the actual name of the operand.

Example

SUBMIT (dobj).

For statements that contain lists of operands or whole sections of statements, an internal table with a
character-type line type can often be specified in parentheses. The table lines must then contain the names of
the individual operands.

Example

SELECT ... WHERE (where_tab).

Dynamic specification
At many operand positions, the system expects character-type data objects that contain the actual names of
the individual operands at the time of execution. To enable static specification of these operands, you must use
literals.

Example

CALL FUNCTION dobj.

Note

In some rare cases, there may be exceptions to these rules, in which operands must be set in parentheses or
in inverted commas as literals, but no data objects can be specified. This is noted in the corresponding syntax
descriptions.

Operand type
An operand position is typed using an operand type, which is complete or generic and can also be dependent
on other operand positions, as is the case for statements, for example. When a statement is executed, an
operand with a suitable data type is expected. If a data object specified at an operand position has a different
data type than the operand type, the system generally tries to convert the content of the data object to the
operand type on the basis of the conversion rules at write positions, and vice versa at read positions. Note that
every conversion leads to a longer runtime. If no appropriate conversion rules have been defined, or the
content cannot be converted, a syntax error occurs or an exception is raised. Deviations from this rule, for
example that the data object must exactly match the operand type, or the data object is to be interpreted as an
operand type, regardless of its actual type (casting), are described in the individual statements.

Operand positions for elementary data objects


Depending on the operand type,

 character-like data objects

 numeric data objects

 byte-like data objects

must be specified at operand positions for elementary data objects when the statement is executed.

Generic, typed formal parameters or field symbols can also be specified statically if they are typed more
generally than the expected type.

Note

In non-Unicode programs, flat structures can also be used at all operand positions where elementary fields are
expected. In Unicode programs, this is only possible if the components of the structure are flat and character-
like. In both cases, the structure is handled in the same way as a single data object of type c (implicit casting).

Operand positions for structures


Structures must be specified at operand positions for structures when the statement is executed. Formal
parameters or field symbols of the generic types data and any can also be specified statically.

Operand positions for internal tables


Internal tables must be specified at operand positions for internal tables both statically and when the statement
is executed. Generic formal parameters and field symbols can only be specified if they are typed with at least
the generic type any table. Only index tables can be specified at operand positions that include index
access, and generic formal parameters and field symbols must be typed with at least the generic type index
table.

Operand positions for reference variables


Depending on the operand type, either data or object reference variables must be specified at operand
positions for reference variables when the statement is executed. Formal parameters or field symbols of
generic type data or any can also be specified statically.
Data Objects in Operand Positions
For data objects in operand positions, you must distinguish between read and write positions. The data type
and content of the specified data objects must also be appropriate for the operand position.

 Read positions

 Write positions

 Subfield access

Read Positions
At a read position, the content of an operand is only read, and not changed, when the statement is executed.
Data objects can be specified as followed at read positions:

 Specification of a literal.

 Specification of a data object visible at this point using a name dobj, a field symbol <fs>, or a data
reference dref->* dereferenced using the dereferencing operator ->* (providing dref is specified in
full). The names of data objects here include the specification of a text symbol using text-idf, where
idf is the three-character code of the text symbols, or concatenations of reference variables. If a field
symbol is used, it must be assigned to a memory area and a data reference must point to a data
object. Otherwise an unhandleable exception is raised.

As an alternative to specifying a text symbol using text-idf, you can append the three-character
code of a text symbol to the text field literal in parentheses:

... '...'(idf) ...

If the text symbol exists in the currently loaded text pool, then the content of the text symbol is used
instead of the text field literal, otherwise the literal is used.

 If the data object is an internal table, the expressions dobj[], <fs>[], or dref->*[] can also be
used. For dobj[], this ensures that the table body is addressed and no header lines. If an internal
table does not have a header line, its simple name dobj (without []) is interpreted as the table body
at all operand positions. However, if an internal table does have a header line, its simple name dobj
(without []) is interpreted as the header line and not the table body at almost all operand positions.
The operand positions, used to interpret an internal table name with a header as the internal table, are
listed under internal tables with headers. Field symbols <fs> and data references dref->*, on the
other hand, only ever refer to the table body or a possible header line.
 Specification of a subarea of a character-type or byte-type data object (or a character-type initial part
of a structure) by specifying an offset/length.

 In some positions, number values must be specified directly as digits, although it is often not possible
to specify a sign (which is not the case with numeric literals). Examples are numbers specified in
declarative statements for the length of elementary data objects or for the initial memory requirements
of internal tables.

Notes

 Text symbols cannot be listed at all read positions. For example, they are not permitted for specifying
the target of dynamic executions.

 A system field should only be specified as an operand at a read position if its content is not set by the
same statement, as otherwise undefined behavior may occur.

 At many operand positions, you can specify functions or expressions instead of data objects.

 The logical expressions IS ASSIGNED and IS BOUND can be used to check whether field symbols or
data references.

Write Positions
At a write position, the content of the operand is changed when the statement is executed. Only changeable
data objects - that is, no literals, text symbols, constants, or non-changeable formal parameters - can be
specified as follows at write positions:

 Specification of a visible data object at this point using a label dobj, a field symbol <fs>, or a
dereferenced data reference dref->* (if dref is typed completely). Similar to read items, you can
add [] for internal tables, to address the table body.

 Specify a subarea of a flat character-like or byte-like data object, by specifying an offset/length. An


offset or length specification is not possible for data objects of the deep data types string and
xstring.

Substring Access
In operand positions, you can access subareas of the following data objects using an offset/length
specification:

 Elementary byte-like data objects


 Elementary character-like data objects

 Flat structures, whereby one of the following prerequisites must be satisfied in Unicode programs:

o The structure contains flat character-like components only.

o The first Unicode fragment of the structure is flat and character-like, and the substring addressed
by the offset and length specifications is located within this fragment.

In write positions, only flat data objects are permitted; it is not possible to write to substrings of strings.

An offset or length specification is directly appended to either the dobj descriptor of the data object, an <fs>
field symbol, or a dereferenced data reference variable dref->* (only if the data reference variable is fully
typed):

dobj[+off][(len)]
<fs>[+off][(len)]
dref->*[+off][(len)]

The segment of the data object is used that has the offset specified in off and the length (in characters or
bytes) specified in len. For an offset specification without a length, the entire substring is addressed as of the
off character; for a length specification without an offset, the first len characters are addressed (different
rules apply for the ASSIGN statement).

The operands off and len expect data objects of the type i. These data objects must contain positive
integers, with the following exceptions.

 The length 0 can be specified for strings.

 A negative offset (but never length 0) can be specified if an <fs> field symbol is specified in the
ASSIGN statement for dobj.

 If off is smaller than the length of dobj, an asterisk (*) can be specified for len. The upper limit of
dobj then determines the upper limit of the memory area.

If the prerequisites are not met or if the subarea defined by off and len is not completely contained in the
data object, an exception of class CX_SY_RANGE_OUT_OF_BOUNDS occurs. If off is specified as a
numeric literal, then this literal cannot be prefixed with a sign.

The offset and length specifications are counted in characters for character-like data objects and in bytes for all
other data objects. A character is equivalent to a byte in non-Unicode systems.

A substring specified by an offset or length specification is treated like a data object of the specified length for
which the data type depends on the data type of the original data object, the field symbol, or the data reference
variable, as shown below:

Original data type Data type of substring


c c
d n
n n
t n
string string
x x
xstring xstring
Structure type c

The following restrictions apply:

 A memory area must not be addressed outside the field boundaries, except in the case of the ASSIGN
statement.

 No offset or length data can be specified if a literal or a text symbol is specified.

 In the case of dynamic operand specification in brackets, no length specifications can be made.

 If the length of the substring exactly corresponds to the length of the structure in a substring access to
a structure, the substring does not have data type c; instead, it is handled like the structure itself.

Notes

 For read access to substrings of character-like data objects, predefined substring functions that allow
you to search by substring and offset/length specifications are available.

 Obsolete syntax forms can still occur with substring access (apart from with classes).

 The statement MOVE PERCENTAGE indicates an obsolete form of substring access.

Functions and Expressions at Operand Positions


At certain read positions you can specify functions and expressions.

 functions and expressions for operand positions

 operand positions for functions and expressions

Note

The programDEMO_EXPRESSIONS shows examples of the usage of functions and expressions.


Functions and Expressions for Operand Positions
 Functions that can be executed in a read position are

o Predefined functions

... func( arg ) ...

o Functional methods

... meth( ) ...


... meth( a ) ...
... meth( p1 = a1 p2 = a2 ... ) ...

o Method chaining

Chained call of functional methods:

... {oref->}|{class=>}meth1(...)->meth2(...)->...->meth(...) ...

The return value of the last functional method meth is used as the operand. The return values of
the preceding functional methods must be reference variables that point to objects with the next
corresponding method. All methods must be called using the object component selector with the
exception of the first method meth1, which can be called using the class component selector if it
is a static method.

Chained attribute access:

... {oref->}|{class=>}meth1(...)->meth2(...)->...->attr ...

The instance attribute attr is used as the operand. Methods are called in the same way as
chained methods. The return value of the last method must point to an object that contains the
specified attribute.

 Expressions that can be executed in a read position are calculation expressions, which means:

o Arithmetic expressions

... arith_exp ...

o Bit expressions

... bit_exp ...

o String Expressions

... string_exp ...

Notes

 We combine functions with numerical return values and arithmetical expressions together in numeric
expressions.
 We combine functions with character-like return value and string expressions as character-like
expressions.

Example

Numerical expression as an index specified for an internal table.

DATA: itab TYPE STANDARD TABLE OF i,


wa LIKE LINE OF itab,
n TYPE i.

...

READ TABLE itab INDEX lines( itab ) - n


INTO wa.

Operand positions for functions and expressions


 General expression positions

 Numerical expression positions

 Character-like expression positions

 Functional operand positions

General Expression Positions


General expression positions are read positions in which suitable data objects, calculation expressions,
predefined functions, or functional methods and method chainings can be specified. The following general
expression positions exist:

 Right side of statement COMPUTE without the addition EXACT,

 Operands of arithmetic expressions and of bit expressions,

 Embedded expressions in string templates,

 Operands of logical expressions,


 Actual parameters for input parameters of methods in CALL METHOD, CREATE OBJECT, and RAISE
EXCEPTION.

 Arguments of predefined numerical functions if they are themselves executed in an arithmetic


expression.

The type restrictions defined by the operand type apply in the operand positions. For example, no numerical
functions can be specified in a bit expression.

Notes

Specifying functional methods as actual parameters of methods enables the nesting of method calls in an
operand position.

 The three types of calculation expression can be executed as operands of logical expressions, but
they cannot be mixed in one calculation expression.

numerical expression positions


Numerical expression positions are read positions in which numerical data objects, arithmetical expressions,
and predefined functions, or functional methods and method chains, whose return value has a numerical data
type, can be specified. The following numerical expression positions exist:

 Arguments of functions

o Numerical arguments of string functions

o Numeric arguments of extremum functions

 Counters and positions:

o Operand n in the statement


DO n TIMES

o Operand sec in the statement


WAIT UP TO sec SECONDS

o Operand num in the statement


SHIFT ... BY num PLACES

o Operands bitpos and val in the statement


SET BIT bitpos ... TO val.

o Operand bitpos in the statement


GET BIT bitpos ....

 Position specifications in statements FIND and REPLACE:


o Operands off and len in the statements
FIND ... IN SECTION ... OF
REPLACE ... IN SECTION ... OF

o Operands lin1, off1, lin2 and off2 in the statements


FIND ... IN TABLE ... FROM lin1 OFFSET off1 TO lin2 OFFSET off2 ...
REPLACE ... IN TABLE ... FROM lin1 OFFSET off1 TO lin2 OFFSET off2 ...

o Operands off and len in the statement


REPLACE SECTION OFFSET off LENGTH len OF ...

 Specification of the row number idx with reference to a table index during access to an internal table
in:

o READ TABLE itab INDEX idx ...

o LOOP AT itab ...FROM idx1 TO idx2 ...

o INSERT itab ... INDEX idx ...

o INSERT LINES OF jtab FROM idx1 TO idx2 ...

o APPEND LINES OF jtab FROM idx1 TO idx2 ...

o MODIFY itab INDEX idx ...

o DELETE itab INDEX idx ...

o DELETE itab FROM idx1 TO idx2 ...

Character-Type Expression Positions


Character-like expression positions are read positions in which character-like data objects, string expressions,
and predefined functions, or functional methods and method chainings whose return code has a character-like
data type, can be specified. The following character-like expression positions exist:

 Operand positions in string expressions

 Character-like arguments in processing functions

 Character-like arguments in description functions

 Regular expression regex in the statements


FIND ... REGEX regex ... IN ...
REPLACE ... REGEX regex ... IN ...
 Search pattern substring in the statements
FIND ... SUBSTRING substring ... IN ...
REPLACE ... SUBSTRING substring ... IN ...

 Operand dobj in the statement


FIND ... IN dobj ...

 Operand new in the statement


REPLACE ... WITH new ...
REPLACE ... IN TABLE ... WITH new ...

 Operand substring in the statement


SHIFT ... UP TO substring

 Operand mask in the statement


SHIFT ... DELETING ... mask

 Operands dobj and sep in the statement


SPLIT dobj AT sep INTO ...

 Operand text in the statement


CONVERT text INTO SORTABLE CODE ...

 Operands text2 and text2 in the statement


OVERLAY ... WITH text2 USING mask

 Operand mask in the statement


TRANSLATE ... USING mask

 Operand sub in the statement


ASSERT ... SUBKEY sub ...
LOG-POINT ... SUBKEY sub ...

Functional Operand Positions


Functional operand positions are read positions, in which suitable data objects, functional methods, or method
chains whose return values have a suitable data type, can be specified. The following functional operand
positions exist:

 Enhanced functional operand positions:

As well as functional methods, all predefined functions that have exactly one unnamed argument can
be specified in the following read positions (if nothing to the contrary is documented):

o Source field source of the statements


MOVE source TO ...
... = source
o Operand operand of the statement
CASE operand

o Operands operand of the statement


WHEN operand ...

 Functional operand positions in assignments:

o Operand struc1 of the statement


MOVE-CORRESPONDING struc1 TO ...

o Operand val of the statement


CLEAR ... WITH val

 Function Operand Positions in String Processing and Byte String Processing

o Character-like or byte-like arguments of the predefined functions


dbmaxlen, xstrlen

o Operand itab of the statement


CONCATENATE LINES OF itab INTO ...

o Operand itab of the statement


FIND ... IN TABLE itab ...

 Function operand positions in statements for internal tables:

o Work area wa of the statement


READ TABLE ... FROM wa ...

o Work area wa of the statement


INSERT wa INTO ...

o Internal table jtab of the statement


INSERT LINES OF jtab INTO ...

o Work area wa of the statement


COLLECT wa INTO ...

o Work area wa of the statement


APPEND wa TO ...

o Internal table jtab of the statement


APPEND LINES OF jtab TO ...

o Work area wa of the statement


MODIFY ... FROM wa ...

o Work area wa of the statement


DELETE TABLE ... FROM wa ...

 Function operand positions in statements for time stamps:


o Operands time_stamp and tz of the statement
CONVERT TIME STAMP time_stamp TIME ZONE tz INTO...

o Operands dat, tim, dst, and tz of the statement


CONVERT DATE dat TIME tim DAYLIGHT SAVING TIME dst INTO ... TIME ZONE tz

 Function operand positions in statements for checkpoints:

o Operands val1 val2 of the statement


ASSERT ... FIELDS val1 val2 ...

o Operands val1 val2 ... of the statement


LOG-POINT ... FIELDS val1 val2 ...

Operators and Expressions


Normally an operater links two operands with an expression or forms an expression with an operand. During
the execution of a statement containing such expressions, the result of the expression is determined
(operation) and used in the statement. Operators are represented either by special characters or reserved
indicators.

 Operators

 Expressions

Operators
ABAP contains the following operators:

 Assignment Operators
The assignment operators = and ?= associate the source and target field of an assignment. The
operator = also associates actual parameters with formal parameters, for example in procedure calls
or when working with data clusters.

 Arithmetic Operators
The arithmetic operators +, -, *, /, DIV, MOD, and ** associate two or more numeric operands with an
arithmetic expression. In addition, the characters + and - act as plus/minus signs in arithmetic
expressions.

 Bit Operators
The bit operators BIT-AND, BIT-OR, and BIT-XOR associate two or more byte-like operands with a
bit expression. The bit operator BIT-NOT negates a byte-like operand.
 String Operators
The string operator && chains two character-like operands to a string expression.

 Relational Operators
The relational operators =, <>, <, >, <=, >=, and so on associate two operands of any data type with a
logical expression. There are additional relational operators for specific data types.

 Boolean Operators
The Boolean operators AND, OR, and EQUIV associate the results of individual logical expressions with
a logical expression. The result of a logical expression is either true or false. The Boolean operator
NOT inverts the result of a logical expression.

 Literal Operator
The literal operator & associates two literals or two string templates with a literal or a string template.

Expressions
At certain operand positions the following expressions can be formed:

 Logical expressions

 Arithmetical expressions

 String expressions

 Bit expressions

An expression has a result that is used as an operand in the statement. Logical expressions can contain
calculation expressions, that is, arithmetical expressions, string expressions, and bit expressions. The three
different calculation expression types cannot be mixed in one calculation type at the moment.

Note

Although the calculation expression types cannot be mixed directly, a different type of expression can occur as
an argument of a permitted function in another expression. In the same way, logical expressions can occur as
arguments of Boolean functions in calculation expressions.

Вам также может понравиться