Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to add inline comments in Cobol

Tags:

comments

cobol

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}
like image 461
psychoslave Avatar asked Jul 12 '13 13:07

psychoslave


People also ask

How do you comment a line in COBOL?

A comment line is any line with an asterisk (*) or slash (/) in the indicator area (column 7) of the line. The comment can be written anywhere in Area A and Area B of that line, and can consist of any combination of characters from the character set of the computer.

How do you write inline comments?

Summary. Use comments to document your code when necessary. A block comment and inline comment starts with a hash sign ( # ).

What is the format of comment statement in COBOL?

Internal macro definition comment statements require a period in the begin column, followed by an asterisk. Internal macro comments are accepted as comment statements in open code. Any characters of the EBCDIC character set, or double-byte character set can be used (see Character set).

What does inline comment mean?

Inline comments are comments made by an instructor that appear directly on top of your paper. These comments are usually brief.


4 Answers

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.
like image 85
Bruce Martin Avatar answered Oct 13 '22 10:10

Bruce Martin


Enterprise COBOL V5.1 will support inline comments

From the Release Highlights

Introduces the floating comment indicator to create a comment anywhere in the program-text area Enterprise COBOL for z/OS, V5.1 introduces the floating comment indicator ('*>').

You can specify it anywhere in the program-text area to indicate that the ensuing text on a line is a comment line or an inline comment.

A floating comment indicator indicates a comment line if it is the first character string in the program-text area (Area A plus Area B, columns 8 - 72), or indicates an inline comment if it is after one or more character strings in the program-text area.

like image 41
sahhhm Avatar answered Oct 13 '22 11:10

sahhhm


No, but you can write a program to "WRAP" your code when you submit it to the compiler. We did this 20 years ago.

for example.

   SOME COBOL CODE  -- DOUBLE DASH INDICATES COMMENT TO END OF LINE

THEN write a program that looks for the double dashes and have it delete the -- and the text. Then in your compile jcl, input your source code to the program, and the output to the compiler. Simple. Use the INSPECT statement.

 INSPECT LINE, TALLYING CHARACTERS BEFORE INITIAL "--".
 MOVE SPACES TO LINE(TALLY:),

And that is it. Removes the comments and sends to compiler.

like image 30
Baruch Atta Avatar answered Oct 13 '22 10:10

Baruch Atta


COBOL documentation. Open, free.

  • http://opencobol.add1tocobol.com/ OpenCOBOL FAQ and how-to.
  • http://opencobol.add1tocobol.com/OpenCOBOL%20Programmers%20Guide.pdf (Awesome)

And for a limited time, while it remains Draft and open for comment

  • http://www.cobolstandard.info/j4/files/std.zip

That last link is almost guaranteed to expire when the COBOL 20xx Draft becomes a ratified ISO Standard, and is not really for redistribution, other than from the ISO PL22 WG4 source.

COBOL supports FIXED and FREE source code formats. FIXED is older, based on 80 column cards, with columns one to six for sequence numbers, 7 for directives and columns 8 thru 72 for program text.

Asterisk in column 7 is a FIXED form COBOL comment line.

OCOBOL* Sequence number field "OCOBOL" in this case, it can be anything
      * and comment line indicator

      *> inline comment, can be used for FREE format COBOL, as well as FIXED.

There is a trick; place the asterisk in column 7 with the greater than symbol in column 8 and you have a comment line that works in both fixed and free format COBOL.

For compilers that will follow draft 20xx and

>>

directives, there is another trick to assist in FIXED/FREE source compile support.

123456
    >>D free format debug line directives

if the D is in column 7, with the two greater thans in 5 and 6, you have mixed FIXED and FREE source text support for debug lines as well.

like image 37
Brian Tiffin Avatar answered Oct 13 '22 10:10

Brian Tiffin