Cobol - Bank Loans

A program that will process a file of bank loans with validation.

Cobol

      *IDENTIFICATION DIVISION
       PROGRAM-ID. BANKLOANBILLS.
       AUTHOR. STEVENBARTSCH.
      *******
      ******* Program will process a file of bank loan bills with
      ******* validation.
      *******

       ENVIRONMENT DIVISION.
       INPUT-OUTPUT SECTION.
       FILE-CONTROL.
           SELECT F01-ASST3-FILE  ASSIGN TO 'ASST_3.DAT'
                                  ORGANIZATION IS LINE SEQUENTIAL.
           SELECT F02-PRINT-FILE  ASSIGN TO 'OUTPUT.DAT'
                                  ORGANIZATION IS LINE SEQUENTIAL.
           SELECT F03-ERROR-FILE  ASSIGN TO 'ASST3.ERR'
                                  ORGANIZATION IS LINE SEQUENTIAL.
       DATA DIVISION.
       FILE SECTION.
       FD F01-ASST3-FILE
          RECORD CONTAINS 56 CHARACTERS
          DATA RECORD IS F01-ASST3-FILE.

       01 F01-ACCOUNT-HOLDER.
          05 F01-ACC-NUMBER.
             10 F01-ACC-1              PIC X.
             10 F01-ACC-2              PIC X.
             10 F01-ACC-3              PIC X.
             10 F01-ACC-4              PIC X.
             10 F01-ACC-5              PIC X.
             10 F01-ACC-6              PIC X.
          05 F01-ACC-HOLDER-NAME       PIC X(20).
          05 F01-ACC-TYPE.
             10 F01-ACC-TYPE-CODE      PIC X.
             10 F01-ACC-COSIGN-CODE    PIC X.
             10 F01-PAYMENT-CODE       PIC X(2).
          05 F01-LOAN-INFO.
             10 F01-LOAN-AMOUNT        PIC 9(7).
             10 F01-LOAN-RISK-CODE     PIC X.
             10 F01-FIRST-PAYMENT-DATE.
                15 F01-FROM-YEAR       PIC 9(2).
                88 F01-FROM-MONTH      VALUES 1 THRU 12.
                15 F01-FROM-DAY        PIC 9(2).
             10 F01-LAST-PAYMENT-DATE.
                15 F01-TO-YEAR         PIC 9(2).
                88 F01-TO-MONTH        VALUES 1 THRU 12.
                15 F01-TO-DAY          PIC 9(2).
             10 F01-INTEREST-PERCENT   PIC 999V99.

       FD F02-PRINT-FILE
          RECORD CONTAINS 98 CHARACTERS
          DATA RECORD IS F02-PRINT-LINE-RECORD.
       01 F02-PRINT-LINE-RECORD        PIC X(98)   VALUE SPACES.

       FD F03-ERROR-FILE
          RECORD CONTAINS 106 CHARACTERS
          DATA RECORD IS F03-ERROR-LINE-RECORD.
       01 F03-ERROR-LINE-RECORD        PIC X(106)  VALUE SPACES.

       WORKING-STORAGE SECTION.
       01 W01-DATA-REMAINS-SWITCH      PIC X(2)    VALUES SPACES.

       01 W02-PRINT-DATA-HEADER.
          05   PIC X(10)   VALUE 'ACCOUNT #'.
          05   PIC X(15)   VALUE 'ACCOUNT HOLDER'.
          05   PIC X(13)   VALUE 'ACCOUNT TYPE'.
          05   PIC X(12)   VALUE 'LOAN AMOUNT'.
          05   PIC X(10)   VALUE 'RISK CODE'.
          05   PIC X(14)   VALUE 'FIRST PAYMENT'.
          05   PIC X(13)   VALUE 'LAST PAYMENT'.
          05   PIC X(11)   VALUE 'INTEREST %'.

       01 W03-PRINT-DATA-LINE.
          05 W03-PRINT-ACCOUNT-NUMBER  PIC X(10) VALUE SPACES.
          05 W03-PRINT-ACCOUNT-HOLDER  PIC X(15) VALUE SPACES.
          05 W03-PRINT-ACCOUNT-TYPE    PIC X(13) VALUE SPACES.
          05 W03-PRINT-LOAN-AMOUNT     PIC X(12) VALUE SPACES.
          05 W03-PRINT-RISK-CODE       PIC X(10) VALUE SPACES.
          05 W03-PRINT-FIRST-PAYMENT   PIC X(14) VALUE SPACES.
          05 W03-PRINT-LAST-PAYMENT    PIC X(13) VALUE SPACES.
          05 W03-PRINT-INTEREST-PER    PIC 9(6).

       01 W04-PRINT-ERROR-HEADER.
          05   PIC X(15)   VALUE 'ACCOUNT NUMBER'.
          05   PIC X(20)   VALUE 'ACCOUNT HOLDER NAME'.
          05   PIC X(50)   VALUE 'ERROR MESSAGE'.
          05   PIC X(21)   VALUE 'ERROR FIELD CONTENTS'.

       01 W05-PRINT-ERROR-LINE.
          05 W05-PRINT-ACCOUNT-NUMBER  PIC X(15) VALUE SPACES.
          05 W05-PRINT-ACCOUNT-HOLDER  PIC X(20) VALUE SPACES.
          05 W05-PRINT-ERROR-MESSAGE   PIC X(50) VALUE SPACES.
          05 W05-PRINT-ERROR-FIELDS    PIC X(21) VALUE SPACES.

       01 W06-VALIDATE-ACCOUNT.
          05 W06-PRESENCE-ACCOUNT-NUM  PIC X     VALUE SPACES.
          05 W06-NUMERIC-ACCOUNT-NUM   PIC X     VALUE SPACES.
          05 W06-VALIDATE-ACCOUNT-TYPE PIC X     VALUE SPACES.
          05 W06-NUMERIC-LOAN-AMOUNT   PIC X     VALUE SPACES.
          05 W06-VALIDATE-RISK-CODE    PIC X     VALUE SPACES.
          05 W06-VALIDATE-LAST-PAY     PIC X     VALUE SPACES.
          05 W06-NUMERIC-INTEREST      PIC X     VALUE SPACES.
          05 W06-VALIDATE-INTEREST     PIC X     VALUE SPACES.

       01 W07-ERROR-MESSAGES.
          05 W07-ERROR-ONE             PIC X(30) VALUE SPACES.
          05 W07-ERROR-TWO             PIC X(30) VALUE SPACES.
          05 W07-ERROR-THREE           PIC X(30) VALUE SPACES.
          05 W07-ERROR-FOUR            PIC X(30) VALUE SPACES.
          05 W07-ERROR-FIVE            PIC X(30) VALUE SPACES.
          05 W07-ERROR-SIX             PIC X(30) VALUE SPACES.
          05 W07-ERROR-SEVEN           PIC X(30) VALUE SPACES.
          05 W07-ERROR-EIGHT           PIC X(30) VALUE SPACES.

       01 W08-ERROR-FIELDS.
          05 W08-ERROR-ONE             PIC X(30) VALUE SPACES.
          05 W08-ERROR-TWO             PIC X(30) VALUE SPACES.
          05 W08-ERROR-THREE           PIC X(30) VALUE SPACES.
          05 W08-ERROR-FOUR            PIC X(30) VALUE SPACES.
          05 W08-ERROR-FIVE            PIC X(30) VALUE SPACES.
          05 W08-ERROR-SIX             PIC X(30) VALUE SPACES.
          05 W08-ERROR-SEVEN           PIC X(30) VALUE SPACES.
          05 W08-ERROR-EIGHT           PIC X(30) VALUE SPACES.

       PROCEDURE DIVISION.
          PERFORM 100-OPEN-FILES
          PERFORM 200-PRINT-HEADINGS
          PERFORM 300-PROCESS-RECORDS
                  UNTIL W01-DATA-REMAINS-SWITCH = 'NO'
          PERFORM 500-CLOSE-FILES
          STOP RUN.

       100-OPEN-FILES.
          OPEN INPUT F01-ASST3-FILE
              OUTPUT F02-PRINT-FILE
              OUTPUT F03-ERROR-FILE
          .
       200-PRINT-HEADINGS.
           MOVE W02-PRINT-DATA-HEADER TO F02-PRINT-LINE-RECORD
           WRITE F02-PRINT-LINE-RECORD

           MOVE W04-PRINT-ERROR-HEADER TO F03-ERROR-LINE-RECORD
           WRITE F03-ERROR-LINE-RECORD
           .
       300-PROCESS-RECORDS.
           READ F01-ASST3-FILE
               AT END MOVE 'NO' TO W01-DATA-REMAINS-SWITCH
           END-READ
           PERFORM 310-VALIDATE-DATA
           IF (W06-VALIDATE-ACCOUNT = "YYYYYYYY") THEN
           MOVE F01-ACC-NUMBER         TO W03-PRINT-ACCOUNT-NUMBER
           MOVE F01-ACC-HOLDER-NAME    TO W03-PRINT-ACCOUNT-HOLDER
           MOVE F01-ACC-TYPE           TO W03-PRINT-ACCOUNT-TYPE
           MOVE F01-LOAN-RISK-CODE     TO W03-PRINT-RISK-CODE
           MOVE F01-FIRST-PAYMENT-DATE TO W03-PRINT-FIRST-PAYMENT
           MOVE F01-LAST-PAYMENT-DATE  TO W03-PRINT-LAST-PAYMENT
           MOVE F01-INTEREST-PERCENT   TO W03-PRINT-INTEREST-PER
           MOVE W03-PRINT-DATA-LINE    TO F02-PRINT-LINE-RECORD
           WRITE F02-PRINT-LINE-RECORD
           ELSE
           MOVE F01-ACC-NUMBER         TO W05-PRINT-ACCOUNT-NUMBER
           MOVE F01-ACC-HOLDER-NAME    TO W05-PRINT-ACCOUNT-HOLDER
           MOVE W07-ERROR-MESSAGES     TO W05-PRINT-ERROR-MESSAGE
           MOVE W08-ERROR-FIELDS       TO W05-PRINT-ERROR-FIELDS
           MOVE W05-PRINT-ERROR-LINE   TO F03-ERROR-LINE-RECORD
           WRITE F03-ERROR-LINE-RECORD
           END-IF

           .
       310-VALIDATE-DATA.
           IF NOT (F01-ACC-1 = SPACE OR F01-ACC-1 = LOW-VALUE OR
               F01-ACC-2 = SPACE OR F01-ACC-2 = LOW-VALUE OR
               F01-ACC-3 = SPACE OR F01-ACC-3 = LOW-VALUE OR
               F01-ACC-4 = SPACE OR F01-ACC-4 = LOW-VALUE OR
               F01-ACC-5 = SPACE OR F01-ACC-5 = LOW-VALUE OR
               F01-ACC-6 = SPACE OR F01-ACC-6 = LOW-VALUE) THEN
               MOVE 'Y' TO W06-PRESENCE-ACCOUNT-NUM
           ELSE
               MOVE 'N' TO W06-PRESENCE-ACCOUNT-NUM
               MOVE 'DATA MISSING IN ACCOUNT NUMBER' TO
               W07-ERROR-ONE
               MOVE 'ACCOUNT HOLDER NAME' TO W08-ERROR-ONE

           END-IF

           IF (F01-ACC-NUMBER IS NUMERIC) THEN
               MOVE 'Y' TO W06-NUMERIC-ACCOUNT-NUM
           ELSE
               MOVE 'N' TO W06-NUMERIC-ACCOUNT-NUM
               MOVE 'NONNUMERIC ACCOUNT NUMBER' TO
               W07-ERROR-TWO
               MOVE 'ACCOUNT NUMBER' TO W08-ERROR-TWO

           END-IF

           IF (F01-ACC-TYPE = 'MN25' OR 'MN30' OR 'MY25' OR 'MY30' OR
      -'CN05' OR 'CY10' OR 'CY05' OR 'CYOT' OR 'PNLT' OR 'PYLT') THEN

               MOVE 'Y' TO W06-VALIDATE-ACCOUNT-TYPE
           ELSE
               MOVE 'N' TO W06-VALIDATE-ACCOUNT-TYPE
               MOVE 'INVALID ACCOUNT TYPE' TO
               W07-ERROR-THREE
               MOVE 'ACCOUNT TYPE' TO W08-ERROR-THREE

           END-IF

           IF (F01-LOAN-AMOUNT IS NUMERIC) THEN
               MOVE 'Y' TO W06-NUMERIC-LOAN-AMOUNT
           ELSE
               MOVE 'N' TO W06-NUMERIC-LOAN-AMOUNT
               MOVE 'NONNUMERIC LOAN AMOUNT' TO
               W07-ERROR-FOUR
               MOVE 'LOAN AMOUNT' TO W08-ERROR-FOUR
           END-IF

           IF (F01-LOAN-RISK-CODE = 'A') THEN
               MOVE '100-999' TO W03-PRINT-LOAN-AMOUNT
               MOVE 'Y' TO W06-VALIDATE-RISK-CODE
           ELSE IF(F01-LOAN-RISK-CODE = 'B') THEN
               MOVE '1000-4999' TO W03-PRINT-LOAN-AMOUNT
               MOVE 'Y' TO W06-VALIDATE-RISK-CODE
           ELSE IF (F01-LOAN-RISK-CODE = 'C')
               MOVE '5000-9999' TO W03-PRINT-LOAN-AMOUNT
               MOVE 'Y' TO W06-VALIDATE-RISK-CODE
           ELSE IF (F01-LOAN-RISK-CODE = 'D')
               MOVE '10000-99999' TO W03-PRINT-LOAN-AMOUNT
               MOVE 'Y' TO W06-VALIDATE-RISK-CODE
           ELSE IF (F01-LOAN-RISK-CODE = 'E')
               MOVE '> 99999' TO W03-PRINT-LOAN-AMOUNT
               MOVE 'Y' TO W06-VALIDATE-RISK-CODE
           ELSE
               MOVE 'N' TO W06-VALIDATE-RISK-CODE
               MOVE 'INCONSISTENT RISK CODE' TO
               W07-ERROR-FIVE
               MOVE 'RISK CODE AND LOAN AMOUNT' TO
               W08-ERROR-FIVE
           END-IF

           IF (F01-LAST-PAYMENT-DATE > F01-FIRST-PAYMENT-DATE) THEN
               MOVE 'Y' TO W06-VALIDATE-LAST-PAY
           ELSE
               MOVE 'N' TO W06-VALIDATE-LAST-PAY
               MOVE 'LAST PAYMENT BEFORE FIRST PAYMENT' TO
               W07-ERROR-SIX
               MOVE 'LAST PAYMENT YEAR, FIRST PAYMENT YEAR' TO
               W08-ERROR-SIX
           END-IF

           IF (F01-INTEREST-PERCENT IS NUMERIC) THEN
               MOVE 'Y' TO W06-NUMERIC-INTEREST
           ELSE
               MOVE 'N' TO W06-NUMERIC-INTEREST
               MOVE 'INTEREST PERCENT MUST BE NUMERIC' TO
               W07-ERROR-SEVEN
               MOVE 'INTEREST PERCENT' TO W08-ERROR-SEVEN

           END-IF

           IF (F01-INTEREST-PERCENT < 40) THEN
               MOVE 'Y' TO W06-VALIDATE-INTEREST
           ELSE
               MOVE 'N' TO W06-VALIDATE-INTEREST
               MOVE 'INTEREST PERCENT TOO HIGH' TO
               W07-ERROR-EIGHT
               MOVE 'INTEREST PERCENT' TO W08-ERROR-EIGHT
           END-IF
           .
       500-CLOSE-FILES.
           CLOSE F01-ASST3-FILE
           CLOSE F02-PRINT-FILE
           CLOSE F03-ERROR-FILE
           .

DAT Input File

342545Sarah Rosen         MN250110000E001101250101002500
238945Peter Piper         MY300235000E011102310222003700
689353Jim Henson          MY250205000E011103260321005600
466567Mr Clean            CN050050000D021104150425012500
676767President Obama     CF050008000C061105140530011250
465758Mr Harper PM        CY000025000D021106150628005500
763645Stan Laurel         MN250550000E051106300729004500
11111lOliver Hardy        PNLTOO50000D031106180816021000
457686Little Miss Muffett PPLT0025000D031107181015022000
487653Graham Greene       CB050005000C121108171114011200
222222Tom Thumb           MM25125I000E121108371118007800
333333Mother Hubbard      PNLT0000250A111109201011020500
349766Prince Charming     PNLT0001250B111109191003008750
456977Aaron Hodgener      PYLT0505050E111110180902009750
444444Penelope Garcia     CN100025000D111110191211011250
945766Emily Dickinson     CY050025000D101111201325002500
457897Dr Seuss            PYLL0010100D101111010101009750
555555Dr Spencer Reid     MY251250000E101111350222021500
460674Derek Morgan        MN241250000E111112220923009500
906654Emily Prentiss      MN241250000E121114210922009000
548645Santa Claus         CYOT0025000D111114210821008750
666666Cindy Lou Who       CY050025000D101116180714007500
486467Horatio Caine       PYLT10O0000E101116181215006250
859734Callie Coe          PNLT0087500C101117181214005500
146557Isabel Smith        CN100005000C101118440115005750
387643Cathy Jones         CY050000500A111119331213015500
777777Tom Thomas          CYOT0025000D121119320718012500
984545Mike Michaels       MM251250000E111119310622017500
895098Jack Jackson        PPLTI010000E031120290129013500
567455Lisa Marie Presley  MY301250000E041120221211005750
387464Elvis Presley       MY301250000E051122351111009750
345456Cher Bono           MY251250000E041122321023009500
463454Country Squire      CN060025000D091123380528009250
888888Jocko Smith         CN050025000D071123220522008750
436355Cosmo Crane         CY100025000D091125180421008500
234557John Johnson        PYLT0025000D081126181125008250
      President Clinton   PYLT0001000B091127181123003750
489753Mary Scary          CYOT0025000D111127221111018750
487635King Kong           MY251250000E1011273503120O3333
784567Anne Marie Brady    MR251250000E1011283503180I0750
845543Mary Patricia Kline MN251250000E1111292501190I0750
387454Aileen Carney Jones MN251250000E121129241120008500
999999Margaret Polesar    MN251250000E101129230429005500
223456Janis Lichael       CY050025000D101130251028105250
348756Donna Summer        CY100025000D111130261127008750
345464Donna Braves        CN050025000A121130270126003500
646757Laura Ingalls       PNLT0000800A021130240718009250
758346Clive Owen          PPLT0000500A031130251216001350
457466Brad Pitt           PNLT0002500A021130281211025000
ZZZZZZPaul Paulson        CN100002500B011130271215032500
545465Pete Peters         CN100025000D111130261222009500
346768Cinder Ella         CY100005000C011130211229007500
859567Eddy Van Halen      CY100025000D101130221124  3250

OUT Output File

ACCOUNT # ACCOUNT HOLDER ACCOUNT TYPE LOAN AMOUNT RISK CODE FIRST PAYMENT LAST PAYMENT INTEREST %
342545    Sarah Rosen    MN25         > 99999     E         0011          0125         000010
238945    Peter Piper    MY30         > 99999     E         0111          0231         000022
689353    Jim Henson     MY25         > 99999     E         0111          0326         000032
466567    Mr Clean       CN05         10000-99999 D         0211          0415         000042
555555    Dr Spencer ReidMY25         > 99999     E         1011          1135         000022
487635    King Kong      MY25         > 99999     E         1011          2735         000031
845543    Mary Patricia KMN25         > 99999     E         1111          2925         000011