Entering content frame

ABAP Syntax Locate the document in its SAP Library structure

The syntax of the ABAP programming language consists of ABAP statements and comments.

ABAP Statements

Normally, each ABAP statement begins with a keyword. A statement can contain operands and additions of the keyword and is always concluded with a period.


PROGRAM first_program.

WRITE 'My First Program'.


This example contains two statements, one on each line. The keywords are PROGRAM and WRITE. The program displays a list on the screen. In this case, the list consists of the line "My First Program".


The program you see in the following diagram shows the structure of ABAP statements.

This graphic is explained in the accompanying text

For some sample ABAP statements, grouped by category, see Overview of ABAP Statements and Introductory Statements for Programs.

Formatting ABAP Statements

ABAP has no format restrictions. You can enter statements in any format, so a statement can be indented, you can write several statements on one line, or spread a single statement over several lines.

You must separate words within a statement with at least one space. The system also interprets the end of line marker as a space.


The program fragment

WRITE 'This is a statement'.

could also be written as follows:

PROGRAM test. WRITE 'This is a statement'.

or as follows:

                         'This is a statement'.

As there are no format restrictions, you have the chance to enhance the readability of your programs.


If a character literal in an ABAP statement extends across more than one line, the system interprets all spaces between the quotation marks as being part of the character literal. As the number of spaces inserted depends on the line width of the editor, the syntax check issues a warning if you insert spaces outside classes. Inside classes, inserting spaces is generally not allowed.

If you want to enter character literals that do not fit into a single line, you can use the & character to combine a succession of character literals into a single one.

Chained Statements

The ABAP programming language allows you to concatenate consecutive statements with an identical first part into a chain statement. To do this, you write the identical part for all statements only once and place a colon (:) after it. After the colon, write the remaining parts of the individual statements, separating them with commas (,). Ensure that you place a period (.) after the last part to inform the system where the chain ends. When the program is executed, the chained statement is handled the same way as the single ABAP statements would be in their defined sequence.


Statement sequence:

WRITE spfli-cityfrom.
WRITE spfli-cityto.
WRITE spfli-airpto.


Chain statement:

WRITE: spfli-cityfrom, spfli-cityto, spfli-airpto.


In the chain, a colon separates the beginning of the statement from the variable parts. After the colon or commas, you can insert any number of spaces.


You could, for example, write the same statement like this:

WRITE:    spfli-cityfrom,


In a chain statement, the first part (before the colon) is not limited to the keyword of the statements.


Statement sequence:

sum = sum + 1.

sum = sum + 2.

sum = sum + 3.

sum = sum + 4.


Chain statement:

sum = sum + : 1, 2, 3, 4.


Comments are texts that you can write between the statements of your ABAP program to explain their purpose to a reader. Comments are distinguished by the preceding signs * (at the beginning of a line) and " (at any position in a line). If you want the entire line to be a comment, enter an asterisk (*) at the beginning of the line. The system then ignores the entire line when it generates the program. If you want part of a line to be a comment, enter a double quotation mark (") before the comment. The system interprets comments indicated by double quotation marks as spaces.


*  PROGRAM SAPMTEST                            *
*  WRITTEN BY CHARLIE BYTE, 06/27/1995            *
*  LAST CHANGED BY RITA DIGIT, 10/01/1995      *
*  TASK:    DEMONSTRATION                      *

PROGRAM sapmtest.

* DECLARATIONS                                 *

DATA: flag(1) TYPE c,   " global flag
      number TYPE i.    " counter


* PROCESSING BLOCKS                            *





Leaving content frame