5

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?

Philip
  • 5,795
  • 3
  • 33
  • 68

6 Answers6

10

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.

cschneid
  • 10,237
  • 1
  • 28
  • 39
7

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.

Bill Woodger
  • 12,968
  • 4
  • 38
  • 47
Gilbert Le Blanc
  • 50,182
  • 6
  • 67
  • 111
  • 3
    Since COBOL-85, the only 'dots' required in the PROCEDURE DIVISION are the ones that become before and after PARAGRAPH/SECTION headers. All the rest are just going to cause trouble! – NealB Nov 06 '12 at 18:37
  • @NealB: Thanks. I've added your comment to my answer. – Gilbert Le Blanc Nov 06 '12 at 19:25
4

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

glenn jackman
  • 238,783
  • 38
  • 220
  • 352
Sergio Costa
  • 610
  • 6
  • 14
1

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

Bill Woodger
  • 12,968
  • 4
  • 38
  • 47
0

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.  
Mak K
  • 1
  • 1
0

The "accidental making of something unconditional" is precisely why periods should be used. Omitting the periods creates the illusion of control and ease of use, when it is actually the exact opposite. Seeing periods tells you directly that you are not in conditional code anymore. Using periods is one of the unsung virtues of COBOL. When moving code in and out of conditional code, it is even more important to realize that you are changing the code in ways that effect the flow, without regard to indentation. The execution of those lines is potentially altered whether or not you change anything directly on the line. END scope indicators are also great, but so are periods.

JAS
  • 1