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:
*character at the start of a program line indicates that the entire line is a comment.
"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.
- Arrange comments correctly
- Write program comments in English
- Make meaningful comments
Character Set in Source Code
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.
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.
ENDIF. "item_ref IS BOUND AND...