Summary: in this tutorial, you will learn the basic ABAP syntax including statements, comments, and case sensitivity.
ABAP statements
Typically, an ABAP statement starts with a keyword and ends with a period. For example:
write 'Hello, World!'.
In this statement, the write
is a keyword. If a statement has multiple words, you need to separate words within a statement with a least one space.
ABAP doesn’t have any format restrictions. It means that you can:
- Write several statements on one line.
- Spread a single statement over multiple lines.
Even though ABAP has no format restrictions, you should always make your code readable.
Chain Statements
Suppose you have the following statements:
write 'Hi'.
write 'How are you?'.
ABAP allows you to group consecutive statements with the same first part into a chain statement like this:
write: 'Hi', 'How are you?'.
You can spread the above statement over two lines as follows:
write: 'Hi',
'How are you?'.
To chain statements, you write the identical part of all statements once and place a colon (:) after it. After the colon, you write the remaining parts of each statement.
In a chain statement, the first part is not just limited to keywords. Suppose you have the following statements:
counter = counter - 1;
counter = counter - 2;
counter = counter - 3;
You can chain the statements like this:
counter = counter - : 1, 2, 3.
Comments
In ABAP programs, comments help explain the purpose of the code. When the ABAP compiler compiles the program, it ignores the comments.
To comment on the entire line, you use the asterisk (*):
* Calculate the net price before tax
net_price_before_tax = price * ( 1 - discount).
To comment a part of a line, you use the double quotation mark (“) before the comment:
net_price = 0. " reset the net_price
Case sensitivity
Unlike other languages like Java or C#, ABAP is not case-sensitive. It means that you can use the ABAP keywords and identifiers in uppercase, lowercase, etc. For example:
write 'Welcome to '.
WRITE 'ABAP Programming'.
Write ' tutorial'.
In this example, the write keyword is in lowercase (write
), uppercase (WRITE
) and camel-case (Write
). All forms are valid.
In the past, the ABAP editor doesn’t have the syntax highlighting feature that uses colors for various elements of the source code like keywords, variables, etc. You typically find that most of ABAP code is in uppercase, which is quite difficult to read.
Nowadays, the ABAP editor supports syntax highlighting that makes the code much easier to read. It is your choice to use the format you want. It is important to make your format consistent throughout the code.
Summary
- A statement typically starts with a keyword and ends with a full stop (.)
- Use an asterisk (*) at the beginning of a line to comment on the whole line. To comment on a part of the line, place the double quotes (“) before the comment.
- Generally, ABAP is not case-sensitive.