ABAP Keyword Documentation → ABAP − Reference → ABAP Syntax
Comments
A comment is an explanation that is added to the source text of a program to help the person reading the program to understand it. Comments are ignored when the program is generated by the ABAP Compiler. From a technical perspective, a comment can have any type of content. Two language elements are available for creating comments:
- The
*
character at the start of a program line indicates that the entire line is a comment.
- The
"
character, which can be entered at any position in the line, indicates that the remaining content in the line is a comment. This rule does not apply to the"
character in character literals and pseudo comments.
These language elements enable you to create two types of comment:
- Comment lines
*
character at the start of the program line or by the "
character at any point of an otherwise blank program line.
- End of line comments
"
character and that appears after an ABAP statement or part of an ABAP statement.
Other versions: 7.31 | 7.40 | 7.54
Programming Guidelines
- Arrange comments correctly
- Write program comments in English
- Make meaningful comments
-
Character set in source code
Note
A special category of line end comments are
ABAP Doc comments introduced using "!
. These comments can be evaluated by an ABAP development environment and support
ABAP Doc.
Example
The following example shows how you should use comments. Comment lines added with *
are used to structure the program. Line decomments are added after declarations and statements at the end of blocks. All other comments appear before the statements described and are indented accordingly.
* Class implementations *
*----------------------------------------------------------*
CLASS application IMPLEMENTATION.
METHOD main.
DATA: items TYPE STANDARD TABLE
OF REF TO item, "Item table
item_ref LIKE LINE OF items. "Item reference
DATA: amount TYPE i, "Amount per item
total_amount TYPE i. "Total amount of items
...
"Loop over all items to compute total amount
LOOP AT items INTO item_ref.
IF item_ref IS BOUND AND
item_ref->is_valid( ) = abap_true.
"Compute total amount for valid items
amount = item_ref->get_amount( ).
ADD amount TO total_amount.
...
ELSE.
...
ENDIF. "item_ref IS BOUND AND...
ENDLOOP.
...
ENDMETHOD. "main
ENDCLASS. "application