Question

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?

Was it helpful?

Solution

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.

OTHER TIPS

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.

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.....

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".

Just tested that in my cobol 85 program by removing all of the periods in procedures and it worked fine.

example:

PROCEDURE DIVISION.                                                          
 MAIN-PROCESS.                                                    
    READ DISK-IN                                                  
     AT END                                                       
      DISPLAY "NO RECORDS ON INPUT FILE"                          
      STOP RUN                                                   
    ADD 1 TO READ-COUNT.                                          
    PERFORM PROCESS-1 UNTIL END-OF-FILE.                 

 WRITE-HEADER.                                                    
    MOVE HEADER-INJ-1 TO HEADER-OUT-1                             
    WRITE HEADER-OUT-1.                                           

 CLOSE-FILES.                                                     
    CLOSE DISK-IN                                                 
    CLOSE DISK-OUT                                                
    DISPLAY "READ: " READ-COUNT                                   
    DISPLAY "WRITTEN: " WRITE-COUNT                               

    SORT SORT-FILE ON ASCENDING SER-S                         
     USING DISK-OUT                                               
     GIVING DISK-OUT                                              

     STOP RUN.  
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top