JavaScript Disabled

ABAP Syntax

The syntax of the ABAP programming language consists of the following elements:

Statements
An ABAP program consists of individual ABAP statements. Each statement begins with a keyword and ends 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 keyword determines the category of the statement. For an overview of the different categories, refer to ABAP Statements.

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
PROGRAM TEST.
WRITE 'This is a statement'.

could also be written as follows:
PROGRAM TEST. WRITE 'This is a statement'.

or as follows:
               PROGRAM 
TEST.
WRITE
'This is a statement'.

Use this free formatting to make your programs easier to understand.

Special Case: Text Literals


Text literals are sequences of alphanumeric characters in the program code that are enclosed in quotation marks. If a text literal in an ABAP statement extends across more than one line, the following difficulties can occur:

All spaces between the quotation marks are interpreted as belonging to the text literal.
Letters in text literals in a line that is not concluded with quotation marks are interpreted by the editor as uppercase.
If you want to enter text literals that do not fit into a single line, you can use the ‘&’ character to combine a succession of text literals into a single one.

The program fragment
PROGRAM TEST.
WRITE 'This
is
a statement'.

inserts all spaces between the quotation marks into the literal, and converts the letters to uppercase.

This program fragment
PROGRAM TEST.
WRITE 'This' &
' is ' &
'a statement'.

combines three text literals into one.

Chained Statements


The ABAP programming language allows you to concatenate consecutive statements with an identical first part into a chain statement.

To concatenate a sequence of separate statements, write the identical part 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.

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,
SPFLI-CITYTO,
SPFLI-AIRPTO.

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

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 KARL BYTE, 06/27/1995 *
* LAST CHANGED BY RITA DIGIT, 10/01/1995 *
* TASK: DEMONSTRATION *
************************************************

PROGRAM SAPMTEST.

************************************************
* DECLARATIONS *
************************************************

DATA: FLAG " GLOBAL FLAG
NUMBER TYPE I " COUNTER

......

************************************************
* PROCESSING BLOCKS *
************************************************

......


Sumber : SAP LIBRARY - BC - ABAP Programming

0 Whisper

Post a Comment

Please, your comment must related with current posting otherwise your comment will mark as Spam.