Quiz on IF statements for an edit:

Assume no typos were intended - I am looking for logic and language. In all cases if an error is detected, I want to move the field to a field on the error line called DATA-PROBLEM-PR and I want to move a message explaining the problem to a field called ERR-MSG-PR and finally I want to perform U-100-ERROR-ROUT.

FILES:
FD  STUDENT-FILE
    DATA RECORD IS STUDENT-RECORD. 
01  STUDENT-RECORD.
05  IDNO          PIC X(5).
05  NAMZ          PIC X(20).
05  MAJOR         PIC XX.
05  GPA           PIC 9V999.
05  RDF-GPA REDEFINES GPA         PIC XXXX.
05  NUM-CR        PIC 999.
05  RDF-NUM-CR REDEFINES NUM-CR   PIC XXX.
05  FIN-CD        PIC X.
05  FIN-AID       PIC 9999.
05 RDF-FIN-AID REDEFINES FIN-AID PIC XXXX.
FD  ERROR-FILE
    DATA RECORD IS PRINTZ.
01  PRINTZ.
05  FILLER            PIC X.
05  IDNO-PR           PIC X(5).
05  FILLER            PIC X(5).
05  DATA-PROBLEM-PR   PIC X(20).
05  FILLER            PIC X(5).
05  ERR-MSG-PR        PIC X(40).
05  FILLER            PIC X(5).
Problem #1: I want to check the NUM-CR field and make sure that it is numeric and that it is greater than 0 and less than 200. Which of the following coding example will handle this? Which will not? Explain the problems in the ones in error.

Solution #1:
IF RDF-NUM-CR IS NUMERIC
    IF NUM-CR > 0 AND NUM-CR < 200
        NEXT SENTENCE
    ELSE
        MOVE RDF-NUM-CR TO DATA-PROBLEM-PR
        MOVE "NUM CRS OUT OF RANGE" TO ERR-MSG-PR
        PERFORM U-100-ERROR-ROUT
    END-IF
END-IF
Solution #2:
IF RDF-NUM-CR IS NUMERIC
    IF NUM-CR > 0 AND NUM-CR < 200
        NEXT SENTENCE
    ELSE
        MOVE RDF-NUM-CR TO DATA-PROBLEM-PR
        MOVE "NUM CRS OUT OF RANGE" TO ERR-MSG-PR
        PERFORM U-100-ERROR-ROUT
ELSE
    MOVE RDF-NUM-CR TO DATA-PROBLEM-PR
    MOVE "NUM CRS NOT NUMERIC" TO ERR-MSG-PR
    PERFORM U-100-ERROR-ROUT.
Solution #3:
IF RDF-NUM-CR IS NUMERIC
   IF NUM-CR < 1 OR NUM-CR > 199
        MOVE RDF-NUM-CR TO DATA-PROBLEM-PR
        MOVE "NUM CRS OUT OF RANGE" TO ERR-MSG-PR
        PERFORM U-100-ERROR-ROUT
   END-IF
ELSE
    MOVE RDF-NUM-CR TO DATA-PROBLEM-PR
    MOVE "NUM CRS NOT NUMERIC" TO ERR-MSG-PR
    PERFORM U-100-ERROR-ROUT
END-IF 
Solution #4:
IF NOT RDF-NUM-CR IS NUMERIC 
    MOVE RDF-NUM-CR TO DATA-PROBLEM-PR
    MOVE "NUM CRS NOT NUMERIC" TO ERR-MSG-PR
    PERFORM U-100-ERROR-ROUT
ELSE
    IF NUM-CR < 1 OR NUM-CR > 199
        MOVE RDF-NUM-CR TO DATA-PROBLEM-PR
        MOVE "NUM CRS OUT OF RANGE" TO ERR-MSG-PR
        PERFORM U-100-ERROR-ROUT.
Solution #5:
IF RDF-NUM-CR IS NUMERIC AND NUM-CR > 0 AND NUM-CR < 200
    NEXT SENTENCE
ELSE
    MOVE RDF-NUM-CR TO DATA-PROBLEM-PR
    MOVE "NUM CRS NOT NUM OR OUT OF RANGE" TO ERR-MSG-PR
    PERFORM U-100-ERROR-ROUT.
Problem #2: I want to check and see if the FIN-CD is either spaces or contains an A or B. If it contains spaces then the FIN-AID must also be spaces. If it contains an A, then the FIN-AID needs to be numeric and between 2000 and 4000 (inclusive). If it contains a B, then the FIN-AID needs to be numeric and between 3000 and 5000 (inclusive). Problems should be printed as errors. Which of the following coding examples will handle this? If an example will not handle it, explain the errors or fix it.

Solution #1:
IF FIN-CD = SPACES
    IF RDF-FIN-AID = SPACES OR RDF-FIN-AID = ZERO
        NEXT SENTENCE
    ELSE
        MOVE RDF-FIN-AID TO DATA-PROBLEM-PR
        MOVE "FINANCIAL AID SHOULD BE BLANK" TO ERR-MSG-PR
        PERFORM U-100-ERROR-ROUT
    END-IF
ELSE
    IF FIN-CD = "A"
        IF RDF-FIN-AID IS NUMERIC
            IF FIN-AID > 4000 OR FIN-AID <  2000 
                MOVE RDF-FIN-AID TO DATA-PROBLEM-PR
                MOVE "FIN AID OUT OF RANGE" TO ERR-MSG-PR
                PERFORM U-100-ERROR-ROUT
            ELSE
                NEXT SENTENCE
            END-IF
        ELSE
            MOVE RDF-FIN-AID TO DATA-PROBLEM-PR
            MOVE "FIN AID NOT NUMERIC" TO ERR-MSG-PR
            PERFORM U-100-ERROR-ROUT
        END-IF
    ELSE
        IF FIN-CD = "B"
            IF RDF-FIN-AID IS NUMERIC
                IF FIN-AID > 5000 OR FIN-AID < 3000
                    MOVE RDF-FIN-AID TO DATA-PROBLEM-PR
                    MOVE "FIN AID OUT OF RANGE" TO ERR-MSG-PR
                    PERFORM U-100-ERROR-ROUT
                ELSE
                    NEXT SENTENCE
                END-IF
            ELSE
                MOVE RDF-FIN-AID TO DATA-PROBLEM-PR
                MOVE "FIN AID NOT NUMERIC" TO ERR-MSG-PR
                PERFORM U-100-ERROR-ROUT
            END-IF
        ELSE
            MOVE FIN-CD TO DATA-PROBLEM-PR
            MOVE "INVALID FIN CODE" TO ERR-MSG-PR
            PERFORM U-100-ERROR-ROUT
        END-IF                     
Solution #2:
IF FIN-CD = SPACES AND (RDF-FIN-AID = SPACES OR FIN-AID = 0)
     NEXT SENTENCE
ELSE
    IF RDF-FIN-AID IS NUMERIC
        IF FIN-CD = "A" 
            IF FIN-AID > 1999 AND FIN-CD < 4001
                NEXT SENTENCE
            ELSE
                MOVE FIN-AID TO DATA-PROBLEM-PR
                MOVE "INVALID RANGE" TO ERR-MSG-PR
                PERFORM U-100-ERROR-ROUT
        ELSE
            IF FIN-CD = "B"
              IF FIN-AID > 2999 AND FIN-CD < 5001
                    NEXT SENTENCE
               ELSE
                    MOVE FIN-AID TO DATA-PROBLEM-PR
                    MOVE "INVALID RANGE" TO ERR-MSG-PR
                    PERFORM U-100-ERROR-ROUT
            ELSE
               MOVE FIN-CD TO DATA-PROBLEM-PR
               MOVE "INVALID CODE" TO ERR-MSG-PR
               PERFORM U-100-ERROR-ROUT
    ELSE
        MOVE RDF-FIN-AID TO DATA-PROBLEM-PR
        MOVE "INVALID CODE" TO ERR-MSG-PR
        PERFORM U-100-ERROR-ROUT.
Problem #3: I want to check the NAMEZ field and make sure it contains something. Write the IF statement(s) to do this.

Problem #4: I want to check the GPA field and make sure that it is numeric and that it is not greater than 4. Write the IF statement(s) to do this.