I am trying to understand the behavior of some COBOL code that seems to be missing end-if statements in the nested if statements. Could someone please explain, if you can? I marked where I think there should be end-if statements I believe are missing. However, I do not want to alter this code without understanding how it would fall through the if statement nest.
040-EACH-RENDITION.
READ TC298-PAYFILE AT END
MOVE 'Y' TO END-INPUT
.
IF END_INPUT = 'Y' THEN
CONTINUE
ELSE
MOVE SPACES TO HOLD-CO-CODE;
MOVE PF-ACCOUNT TO HOLD-PF-ACCOUNT;
EXEC SQL
SELECT COUNTY-CODE
INTO HOLD-CO-CODE
FROM TAXDTL
WHERE CLIENT-ID = :ACT-CLIENT-ID
AND CAN = :HOLD-PF-ACCOUNT
AND YEAR = :CLIENT-CURRENT-YEAR
END-EXEC
IF HOLD-CO-CODE = SPACES
MOVE 'XXX' TO HOLD-CO-CODE
END-IF;
DISPLAY 'AFTER SELECT HOLD-CO-CODE=' HOLD-CO-CODE ';'
PF-ACCOUNT
MOVE RENDITION-BEGIN-DATE TO RENDITION-FIX-DATE
IF PF-LEVY = 0
CONTINUE
ELSE
IF PF-YEAR < RENDITION-BEGIN-YEAR
IF (ACT-CLIENT-ID = 81000000
AND PF-YEAR = 2005
AND PF-DEPOSIT-DATE < '20080309')
CONTINUE
ELSE
IF (ACT-CLIENT-ID = 81000000
AND PF-YEAR = 2006
AND PF-DEPOSIT-DATE < '20080301')
CONTINUE
ELSE
IF PF-DEPOSIT-DATE < RENDITION-BEGIN-DATE
CONTINUE
ELSE
MOVE PF-ACCOUNT TO RP-CAN
MOVE PF-YEAR TO RP-YEAR
MOVE PF-JURISDICTION TO RP-TAXUNIT
MOVE PF-RECTYPE TO RP-RECTYPE
MOVE PF-OWNERNO TO RP-OWNERNO
MOVE PF-RECEIPT TO RP-RECEIPT
MOVE PF-VALNUM TO RP-VALNUM
MOVE PF-REMIT-SEQ TO RP-REMIT-SEQ
MOVE PF-DEPOSIT TO RP-DEPOSIT
PERFORM 042-GET-PENALTY
IF RENDITION-SW = 'Y'
MOVE PF-RECORD TO WF-RECORD
MOVE RENPEN-AMOUNT TO WF-RENPEN
MOVE HOLD-CO-CODE TO WF-COCODE
WRITE WF-RECORD
END-IF
* seems a few missing end-if statements should go here
ELSE
MOVE PF-ACCOUNT TO RP-CAN
MOVE PF-YEAR TO RP-YEAR
MOVE PF-JURISDICTION TO RP-TAXUNIT
MOVE PF-RECTYPE TO RP-RECTYPE
MOVE PF-OWNERNO TO RP-OWNERNO
MOVE PF-RECEIPT TO RP-RECEIPT
MOVE PF-VALNUM TO RP-VALNUM
MOVE PF-REMIT-SEQ TO RP-REMIT-SEQ
MOVE PF-DEPOSIT TO RP-DEPOSIT
PERFORM 042-GET-PENALTY
IF RENDITION-SW = 'Y'
MOVE PF-RECORD TO WF-RECORD
MOVE RENPEN-AMOUNT TO WF-RENPEN
MOVE HOLD-CO-CODE TO WF-COCODE
WRITE WF-RECORD
.
042-GET-PENALTY.
Like mentioned in the comments, an ELSE statement will be paired with the last IF statement without an ELSE.
I personally detest this type of code because it is hard to verify as working correctly. I hate counting END-IF's and ELSES. I prefer to rework that type of code to use an EVALUATE TRUE statement with multiple WHEN clauses.