SAP CONTENT - Guide
Get Example source ABAP code based on a different SAP table
Content of Comments
ABAP_BACKGROUND
It is usually sufficient to examine the ABAP statements to find out what happens in an implementation. However, it much more difficult to find out why something happens. This is often only possible in a much wider context and requires a great deal of effort.
ABAP_RULE
Write comments for your implementations that describe why something is done and not how.
ABAP_DETAILS
The best case scenario is where meaningful
Conversely, developers often tend to assume that their source code is sufficiently self-documenting and leave out descriptive comments. However, this assumption is often incorrect. This becomes apparent when a third party tries to understand the source code (either when attempting to enhance the source code or identify a problem). Even the authors of the code can often face this problem, if they are confronted with source code that they wrote a long time ago and have not seen the source code since.
Even if the identifier names allow readers to easily follow what happens in the code, the question
Latest notes:
This section mainly deals with commenting the implementation of functions..
ABAP_HINT_END
ABAP_EXAMPLE_BAD
The meaning of the comments in the following source code is actually already perfectly obvious due to the commented statements.
'into change_date, change_time
SELECT SINGLE udat, stime
FROM trdir
WHERE name = @prog_name
INTO (@change_date, @change_time).>
IF sy-subrc = 0.
IF change_date > version_date.
version_date = change_date.
version_time = change_time.
ELSEIF change_date = version_date AND
change_time > version_time.
version_time = change_time.
ENDIF.
ENDIF.>
ABAP_EXAMPLE_END
ABAP_EXAMPLE_GOOD
In the following source code, the comments in the above example have been replaced with a description of why something happens.
'be adjusted to program time stamp
SELECT SINGLE udat, stime
FROM trdir
WHERE name = @prog_name
INTO (@change_date, @change_time).>
IF change_date > version_date.
version_date = change_date.
version_time = change_time.
ELSEIF change_date = version_date AND
change_time > version_time.
version_time = change_time.
ENDIF.
ENDIF.>
ABAP_EXAMPLE_END