When to use dots in COBOL?
Asked Answered
C

6

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?

Colt answered 6/11, 2012 at 11:40 Comment(0)
D
11

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.

Decennium answered 6/11, 2012 at 12:24 Comment(0)
D
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 division headers; procedure division section and paragraph headers; and procedure division paragraphs. 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 the 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 statement in a Cobol program with a period.

With the introduction of scope terminators in Cobol 1985, Cobol coders could eliminate most periods within procedure division paragraphs. The only periods required in the procedure division of a Cobol 85 program are to terminate the PROCEDURE DIVISION header; section and paragraph headers; and paragraphs.

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

Dorisdorisa answered 6/11, 2012 at 14:7 Comment(2)
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!Assumpsit
@NealB: Thanks. I've added your comment to my answer.Dorisdorisa
V
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.....

Verla answered 8/12, 2012 at 12:46 Comment(1)
The question was about when to use it, not what the options are.Airsick
C
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".

Candycecandystriped answered 19/1, 2013 at 23:55 Comment(0)
S
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.  
Sarazen answered 21/11, 2019 at 20:8 Comment(0)
E
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.

Enslave answered 20/7, 2023 at 16:7 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.