0% found this document useful (0 votes)
2 views6 pages

1 - SAP ABAP - Basic Syntax

The document provides an overview of the basic syntax and structure of SAP ABAP programs, highlighting that every statement begins with a keyword and ends with a period. It covers key concepts such as the REPORT statement, the use of comments, chaining statements with colon notation, and commands for formatting output like SKIP and ULINE. Additionally, it explains the MESSAGE command for displaying messages with different types and consequences in the program execution.

Uploaded by

suraya1222t
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views6 pages

1 - SAP ABAP - Basic Syntax

The document provides an overview of the basic syntax and structure of SAP ABAP programs, highlighting that every statement begins with a keyword and ends with a period. It covers key concepts such as the REPORT statement, the use of comments, chaining statements with colon notation, and commands for formatting output like SKIP and ULINE. Additionally, it explains the MESSAGE command for displaying messages with different types and consequences in the program execution.

Uploaded by

suraya1222t
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Page 1 of 6

SAP ABAP - Basic Syntax


Statements
ABAP source program consists of comments and ABAP statements. Every statement in
ABAP begins with a keyword and ends with a period, and ABAP is ‘Not’ case sensitive.

The first non-comment line in a program begins with the word REPORT. The Report will
always be the first line of any executable program created. The statement is followed by
the program name which was created previously. The line is then terminated with a full
stop.

The syntax is −

REPORT [Program_Name].

[Statements…].

This allows the statement to take up as many lines in the editor as it needs. For
example, the REPORT may look like this −

REPORT Z_Test123_01.

Statements consist of a command and any variables and options, ending with a period.
As long as the period appears at the end of the statement, no problems will arise. It is
this period that marks where the statement finishes.

Let’s write the code.

On the line below the REPORT statement, just type this statement: Write ‘ABAP Tutorial’.

REPORT Z_Test123_01.

Write 'This is ABAP Tutorial'.

Four things to consider while writing statements −

The write statement writes whatever is in quotes to the output window.

The ABAP editor converts all text to uppercase except text strings, which are
surrounded by single quotation marks.

https://www.tutorialspoint.com/sap_abap/sap_abap_basic_syntax.htm 1/6
Page 2 of 6

Unlike some older programming languages, ABAP does not care where a
statement begins on a line. You may take advantage of this and improve the
readability of your program by using indentation to indicate blocks of code.

ABAP has no restrictions on the layout of statements. That is, multiple


statements can be placed on a single line, or a single statement may stretch
across multiple lines.

Colon Notation
Consecutive statements can be chained together if the beginning of each statement is
identical. This is done with the colon (:) operator and commas, which are used to
terminate the individual statements, much as periods end normal statements.

Following is an example of a program that could save some key stroking −

WRITE 'Hello'.
WRITE 'ABAP'.
WRITE 'World'.

Using the colon notation, it could be rewritten this way −

WRITE: 'Hello',
'ABAP',
'World'.

Like any other ABAP statement, the layout doesn’t matter. This is an equally correct
statement −

WRITE: 'Hello', 'ABAP', 'World'.

Explore our latest online courses and learn new skills at your own pace. Enroll and
become a certified expert to boost your career.

Comments
Inline comments may be declared anywhere in a program by one of the two methods −

https://www.tutorialspoint.com/sap_abap/sap_abap_basic_syntax.htm 2/6
Page 3 of 6

Full line comments are indicated by placing an asterisk (*) in the first
position of the line, in which case the entire line is considered by the system
to be a comment. Comments don’t need to be terminated by a period
because they may not extend across more than one line −

* This is the comment line

Partial line comments are indicated by entering a double quote (") after a
statement. All text following the double quote is considered by the system to
be a comment. You need not terminate partial line comments by a period
because they may not extend across more than one line −

WRITE 'Hello'. "Here is the partial comment

Note − Commented code is not capitalized by the ABAP editor.

Suppressing Blanks
The NO-ZERO command follows the DATA statement. It suppresses all leading zeros of a
number field containing blanks. The output is usually easier for the users to read.

Example

REPORT Z_Test123_01.

DATA: W_NUR(10) TYPE N.


MOVE 50 TO W_NUR.
WRITE W_NUR NO-ZERO.

The above code produces the following output −

50

Note − Without NO-ZERO command, the output is: 0000000050

Blank Lines
The SKIP command helps in inserting blank lines on the page.

https://www.tutorialspoint.com/sap_abap/sap_abap_basic_syntax.htm 3/6
Page 4 of 6

Example

The message command is as follows −

WRITE 'This is the 1st line'.


SKIP.
WRITE 'This is the 2nd line'.

The above message command produces the following output −

This is the 1st line


This is the 2nd line

We may use the SKIP command to insert multiple blank lines.

SKIP number_of_lines.

The output would be several blank lines defined by the number of lines. The SKIP
command can also position the cursor on a desired line on the page.

SKIP TO LINE line_number.

This command is used to dynamically move the cursor up and down the page. Usually, a
WRITE statement occurs after this command to put output on that desired line.

Inserting Lines
The ULINE command automatically inserts a horizontal line across the output. It’s also
possible to control the position and length of the line. The syntax is pretty simple −

ULINE.

Example

The message command is as follows −

WRITE 'This is Underlined'.


ULINE.

The above code produces the following output −

https://www.tutorialspoint.com/sap_abap/sap_abap_basic_syntax.htm 4/6
Page 5 of 6

This is Underlined (and a horizontal line below this).

Messages
The MESSAGE command displays messages defined by a message ID specified in the
REPORT statement at the beginning of the program. The message ID is a 2 character
code that defines which set of 1,000 messages the program will access when the
MESSAGE command is used.

The messages are numbered from 000 to 999. Associated with each number is a
message text up to a maximum of 80 characters. When message number is called, the
corresponding text is displayed.

Following are the characters for use with the Message command −

Message Type Consequences

The message appears and the application halts at its current


E Error point. If the program is running in background mode, the job
is canceled and the message is recorded in the job log.

The message appears and the user must press Enter for the
W Warning application to continue. In background mode, the message is
recorded in the job log.

A pop-up window opens with the message text and the user
I Information must press Enter to continue. In background mode, the
message is recorded in the job log.

This message class cancels the transaction that the user is


A Abend
currently using.

This provides an informational message at the bottom of the


screen. The information displayed is positive in nature and it
S Success
is just meant for user feedback. The message does not
impede the program in any way.

This message aborts the program and generates an ABAP


X Abort
short dump.

Error messages are normally used to stop users from doing things they are not supposed
to do. Warning messages are generally used to remind the users of the consequences of
their actions. Information messages give the users useful information.

Example

https://www.tutorialspoint.com/sap_abap/sap_abap_basic_syntax.htm 5/6
Page 6 of 6

When we create a message for message the ID AB, the MESSAGE command - MESSAGE
E011 gives the following output −

EAB011 This report does not support sub-number summarization.

https://www.tutorialspoint.com/sap_abap/sap_abap_basic_syntax.htm 6/6

You might also like