Search code examples
cobolnested-if

Dot rules in nested conditional statements - COBOL


I'm wondering if anybody can explain to me the dot ruling in nested IF statements in COBOL. Example:

*The first if statement*
 IF SUCCESSFUL-STATUS 
     PERFORM 8300-REPL-LNNTBI00 
        THRU 8300-REPL-LNNTBI00-EXIT 
*The second if statement*
        IF SUCCESSFUL-STATUS 
            DISPLAY 'RECORD ALREADY UPDATED :' WS-INF-REC
        ELSE 
            DISPLAY 'UPDATE ERROR : ' WS-INF-REC ' / ' 
            WS-RETURN-STATUS 
 READ INFILE INTO WS-INF-REC.   

Which if statement does the dot placed after "WS-INF-REC" belong to? The first IF or the second IF-ELSE? I know that in most programming, it should be for the last if statement but just to make sure, is it the same for COBOL?


Solution

  • The period character "." ends all if statements. Remember that spacing is ignored by the compiler so therefore the READ statement is part of the ELSE of the second IF statement.

    Us humans want to see the indentation used logically. And, if it were me, I would make the end-if's be explicit. I tend to have one period per paragraph:

    * The first if statement *
         IF SUCCESSFUL-STATUS 
           PERFORM 8300-REPL-LNNTBI00 
             THRU 8300-REPL-LNNTBI00-EXIT 
    * The second if statement*
           IF SUCCESSFUL-STATUS 
             DISPLAY 'RECORD ALREADY UPDATED :' WS-INF-REC
           ELSE 
             DISPLAY 'UPDATE ERROR : ' WS-INF-REC ' / ' 
               WS-RETURN-STATUS 
             READ INFILE INTO WS-INF-REC
           END-IF
         END-IF
         .