Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When to use dots in COBOL?

I'm completely new to COBOL, and I'm wondering:

There seems to be no difference between

DISPLAY "foo"

and

DISPLAY "foo".

What does the dot at the end of a line actually do?

When should I use/avoid it?

like image 228
Philip Avatar asked Nov 06 '12 11:11

Philip


4 Answers

The period ends the "sentence." It can have an effect on your logic. Consider...

IF A = B
    PERFORM 100-DO
    SET I-AM-DONE TO TRUE.

...and...

IF A = B
    PERFORM 100-DO.
    SET I-AM-DONE TO TRUE

The period ends the IF in both examples. In the first, the I-AM-DONE 88-level is set conditionally, in the second it is set unconditionally.

Many people prefer to use explicit scope terminators and use only a single period, often on a physical line by itself to make it stand out, to end a paragraph.

like image 189
cschneid Avatar answered Sep 30 '22 20:09

cschneid


I'm typing this from memory, so if anyone has corrections, I'd appreciate it.

Cobol 1968 required the use of a period to end a division name, procedure division paragraph name, or procedure division paragraph. Each data division element ended with a period.

There were no explicit scope terminators in Cobol 68, like END-IF. A period was also used to end scope. Cobol 1974 brought about some changes that didn't have anything to do with periods.

Rather than try to remember the rules for periods, Cobol programmers tended to end every sentence in a Cobol program with a period.

With the introduction of scope terminators in Cobol 1985, Cobol coders could eliminate most of the periods within a procedure division paragraph. The only periods required in the procedure division of a Cobol 85 program are the to terminate the PROCEDURE DIVISION statement, to terminate code (if any) prior to first paragraph / section header, to terminate paragraph / section header, to terminate a paragraph / section and to terminate a program (if no paragraphs / sections).

Unfortunately, this freaked out the Cobol programmers that coded to the Cobol 68 and 74 standard. To this day, many Cobol shops enforce a coding rule about ending every procedure division sentence with a period.

like image 38
Gilbert Le Blanc Avatar answered Sep 30 '22 19:09

Gilbert Le Blanc


Where to use!

There are 2 forms to use point.

You can use POINT after every VERB in a SECTION. EXAMPLE:

0000-EXAMPLE SECTION.

MOVE 0 TO WK-I.

PERFORM UNTIL WK-I GREATER THAN 100 DISPLAY WK-I ADD 1 TO WK-I END-PERFORM.

DISPLAY WK-I.

IF WK-I EQUAL ZEROS DISPLAY WK-I END-IF.

0000-EXAMEPLE-END. EXIT.

Note that we are using point after every VERB, EXCEPT inside a PERFORM, IF, ETC...

Another form to use is: USING ONLY ONE POINT AT THE END OF SECTION, like here:

0000-EXAMPLE SECTION.

MOVE 0 TO WK-I

PERFORM UNTIL WK-I GREATER THAN 100 DISPLAY WK-I ADD 1 TO WK-I END-PERFORM

DISPLAY WK-I

IF WK-I EQUAL ZEROS DISPLAY WK-I END-IF

. <======== point here!!!!!!! only HERE!

0000-EXAMEPLE-END. EXIT.

BUT, we ALWAYS have after EXIT and SECTION.....

like image 20
Sergio Costa Avatar answered Sep 30 '22 19:09

Sergio Costa


When it is my choice, I use full-stop/period only where necessary. However, local standards often dictate otherwise: so be it.

The problems caused by full-stops/periods are in the accidental making of something unconditional when code "with" is copied into code "without" whilst coder's brain is left safely in the carpark.

One extra thing to watch for is (hopefully) "old" programs which use NEXT SENTENCE in IBM Mainframe Cobol. "NEXT SENTENCE" means "after the next full-stop/period" which, in "sparse full-stop/period" code is the end of the paragraph/section. Accident waiting to happen. Get a spec-change to allow "NEXT SENTENCE" to be changed to "CONTINUE".

like image 44
Bill Woodger Avatar answered Sep 30 '22 20:09

Bill Woodger