Is it possible to add inline comments in Cobol
cobol, comments
Solution
Pre Cobol 2002 No
In Cobol 2002 *> was introduced. see Cobol 2002 and search in-line comment, which give this example:
05 Field-X Pic XX *> Used in calculating the current THINGY
...
MOVE ABC to XYZ *> Current-XYZ
LMN *> Saved XYZ
There are other some exceptions
- In Exec Sql - End-Exec. you are able to use in-line comments (/* */) for some SQL venders (e.g. Oracle). This is not true Cobol though but an embeded language, generally implemented via a pre-compiler. Othere Exec End-exec statement may also allow in-line comments.
- There may be other Cobols implementations that allow in line comments
- By default many pre Cobol 20002 compiler's only look at columns 7 to 72. So columns 1 to 6 and anything after column 71 can hold comments.
Problem
Most modern programming languages give a way to add inline comments, generally those that use a newline character to indicate the end of a comment, and an arbitrary delimiter or sequence of tokens to indicate the beginning of a comment, while letting the beginning of the line being an interpreted instruction. In COBOL, while commenting a whole line is well documented (it can be done by putting an asterisk symbol (`*`) in column 7), finding documentation on whether or not you can comment the rest of the line beginning at an arbitrary position is harder. The question is: can you comment the rest of a line beginning at an arbitrary position in COBOL? Imagining that `#` is the special character for this kind of comment, here is a fictive example of what is seeked: ``` *--- This structure is a dummy example 01 MY-STRUCTURE. 05 MY-VARIABLE PIC X VALUE '-'. # Valid values are in {-, a, b} ```