Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nested Perform Loops in COBOL?

Why can I not do this nested perform loop in COBOL?

If I put END-PERFORM. in any line sooner than where I have the last one just before EXIT PROGRAM - it works. But I need the program to display the INPUT C value every time. in the outer perform loop. Its driving me nuts.

PROCEDURE DIVISION USING INPUTC CIPHER.
COMPUTE CIPHERMAX = CIPHER.
MULTIPLY -1 BY CIPHER
---> PERFORM VARYING CIPHER FROM 0 BY 1
UNTIL CIPHERMAX = CIPHER
    DISPLAY 'This is loop number: ' CIPHER
    INSPECT INPUTC CONVERTING
    "avcdefghijklmnopqrstuvwxyz" to "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
    COMPUTE CONVERTNUM = FUNCTION MOD (CIPHER, 26)
    INSPECT FUNCTION REVERSE(INPUTC) TALLYING LENGTHNUM FOR LEADING SPACES
    COMPUTE LENGTHNUM = LENGTH OF CIPHER - LENGTHNUM

 ---> PERFORM UNTIL SENTRY = LENGTHNUM

            IF ((FUNCTION ORD(INPUTC(SENTRY:1)) + CONVERTNUM) > (FUNCTION ORD('Z')))
             MOVE FUNCTION CHAR((FUNCTION ORD(INPUTC(SENTRY:1)) + CONVERTNUM) - 26) TO RECHAR
              ELSE
             MOVE FUNCTION CHAR(FUNCTION ORD(INPUTC(SENTRY:1)) + CONVERTNUM) TO RECHAR
             END-IF  
              IF (((FUNCTION ORD(INPUTC(SENTRY:1))) >= (FUNCTION ORD('A'))) AND 
             ((FUNCTION ORD(INPUTC(SENTRY:1))) <= (FUNCTION ORD('Z'))))
             IF ((FUNCTION ORD(INPUTC(SENTRY:1)) + CONVERTNUM) > (FUNCTION ORD('Z')))
                INSPECT INPUTC(SENTRY:1) REPLACING ALL INPUTC(SENTRY:1) BY RECHAR
             ELSE
                INSPECT INPUTC(SENTRY:1) REPLACING ALL INPUTC(SENTRY:1) BY RECHAR
             END-IF
          ELSE
                INSPECT INPUTC(SENTRY:1) REPLACING ALL INPUTC(SENTRY:1) BY INPUTC(SENTRY:1)
          END-IF

          COMPUTE SENTRY = SENTRY + 1
        --->  END-PERFORM
    DISPLAY INPUTC.
    COMPUTE LOOPI = LOOPI + 1
    --->END-PERFORM.
EXIT PROGRAM.
END PROGRAM SOLVE.
like image 370
user99999991 Avatar asked Apr 25 '13 17:04

user99999991


2 Answers

That nasty scope terminating period after DISPLAY INPUTC. is terminating the scope of the nested PERFORM statements. Get rid of the period and all should work fine.

The only periods you should ever use in the Procedure Division when coding a program to COBOL-85 standard are the ones required to terminate section and paragraph headers and another one to terminate the current paragraph, section or program.

like image 112
NealB Avatar answered Oct 24 '22 03:10

NealB


You have a period in the display INPUTC statement. Remove the period and you should be ok. The Period always ends a statement.

like image 4
Baruch Atta Avatar answered Oct 24 '22 02:10

Baruch Atta