he following sections describe the syntax of ABAP:

1. 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 code.

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

◉ If a number of expressions of the same type with operators are joined as an expression, the priority of the individual operations can be defined using parentheses (()).
◉ For the purpose of calling functions and methods, parentheses (()) can sometimes be used.
◉ Lists of operands are expressed by parentheses (()) and commas (,) in certain positions.
◉ When forming a chained statement, a colon (:) and commas (,) can be used.

A number of standalone special characters, such as parentheses for setting the priority, need to be separated from other tokens using a blank. Other special characters (as well as the period at the end) do not have to be separated by a blank.

Notes

◉ Obsolete syntax forms can still occur in all objects apart from classes. In such cases, the separators between the tokens can be omitted.
◉ The absolute maximum length of an ABAP statement is 128 x 1024 characters = 131072 characters. However, the actual maximum number of characters in a statement also depends on the number of tokens and the use of literals. A statement usually consists of almost 130,000 characters. In chained statements, however, it is only a maximum of 28400 characters per statement.

Example

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

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

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

If a statement is introduced using an ABAP word, the word is an ABAP keyword. The remaining ABAP words are additions of a keyword. 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 of other keywords. Not all statements are introduced using a keyword or contain ABAP words. Assignments with the assignment operator = or method calls, for example, do not contain a keyword and do have to contain any other ABAP word.

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. Even if this rule is followed, the introduction of new elements can cause similar situations and therefore suitable naming conventions should be observed for reserved names to avoid conflicts with language elements.

1.2 Operands

Typical operands are:

◉ Data objects from the same ABAP program 

Data objects in operand positions are modified ( writer positions) or read ( reader positions).

◉ Functions and expressions 

In many reader positions (and in some writer positions), functions and expressions can be specified instead of data objects. In these cases, the statement works with the return value of the function or the result of the expression.

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



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

Note: As well as the component selectors listed here, Open SQL has a column selector (~).

- - 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. A structured data type or a structure struct must be specified as follows on the left of the structure component selector:

◈ Name of a structure or a structured type (which can itself be composite).
◈ Functional method call or method chaining with a structured result.
◈ Single or chained table expression that returns a structured table row.

The name comp of the component must be on the right of the structure component selector.

Example

Declares a structure struc with the structured data type spfli from ABAP Dictionary and accesses 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. A reference variable ref must be specified on the left of the object component selector as follows

◈ Name of a reference variable (can itself be a composite).
◈ Functional method call or method chaining with reference variable as a result.
◈ Single or chained table expression whose result is a reference variable.
◈ Constructor expression with the instance operator NEW or the casting operator CAST.

The name comp of the component must be on 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->* names 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

Accesses 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 on the left of the class component selector. The name comp of the component must be on the right of the class 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 on 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 on 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

Declares a class factory and accesses 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.






Serkan AKKAVAK
Computer Engineer
ABAP Developer & SAP S/4 HANA Logistics Team Lead
Contact : serkurumsal@yandex.com