SHARE
TWEET

Untitled

a guest Sep 7th, 2018 100 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /// THIS IS A COMMENT
  2. /// PLF QUIZ 3: FILE MAINTENANCE (CHECK BALANCE)
  3. /// BY: CHRISTIAN BARON NAMQUI
  4. ///    MAINFRAME TRAINEE
  5. /// AUTHOR'S NOTE: PLEASE OPEN FILE USING NOTEPAD++ AND SET LANGUAGE TO "COBOL" FOR EASIER READING
  6. /// END COMMENT
  7.  
  8. /// THIS IS A COMMENT
  9. /// ASSUME MASTER-FILE AND TRANSCATION FILE ARE SORTED BY ACCOUNT #
  10. /// ASSUME ALL ENTRIES IN THE TRANSACTION FILE ARE VALID
  11. /// NO NEGATIVE VALUES WILL BE ALLOWED IN THE MASTER FILE
  12. /// ASSUME ALL ACCOUNT NUMBERS ARE GREATER THAN 0
  13. /// LINES THAT START WITH "//" ARE COMMENTS AND ARE NOT PART OF THE CODE
  14. /// END COMMENT
  15. START
  16.     OPEN MASTER-FILE
  17.     CREATE NEW-MASTER-FILE
  18.     CREATE LOG
  19.     OPEN NEW-MASTER-FILE
  20.     OPEN LOG
  21.     OPEN TRANS-FILE
  22. //  DECLARE VARIABLES
  23.     ACCUM-ACCT-BALANCE = 0
  24.     GRAND-TOTAL-BALANCE = 0
  25.     ACCT-NO = 0
  26.     CUST-NAME = ""
  27.     TRANS-AMT = 0
  28.     FLAG-DELETE = FALSE
  29.     M-INDEX = 0
  30.     T-INDEX = 0
  31.     M-ANUM = 0
  32.     T-ANUM = 0
  33.     LOG-LINE-CTR = 0
  34.     LOG-PAGE-CTR = 0
  35.     REMARK = ""
  36.     DEPOSITS = 0
  37.     CHECKS = 0
  38.     CHECK-CHG = 0
  39.     BAD-CHECKS = 0
  40.     BAD-CHECK-CHG = 0
  41.     NO-DEPOSITS = 0
  42.     NO-CHECKS = 0
  43.     NO-BAD-CHECKS = 0
  44.     NO-OPEN-ACCTS = 0
  45.     NO-CLOSED-ACCTS = 0
  46.     WRITTEN = 0
  47.     CREATED-ACCT-NO = 0
  48.     CREATED-ACCUM-BAL = 0
  49.     CREATED-ACCT-NAME = ""
  50. //  END VARIABLE DECLARATION
  51.  
  52.     PERFORM PRINT-LOG-HEADERS
  53.  
  54. //  START MAIN LOOP
  55. //  LOOP ENDS WHEN BOTH FILES REACH THEIR END
  56.     DO WHILE !EOF(MASTER-FILE) || !EOF(TRANS-FILE)
  57. //      RESET DEFAULT VALUES
  58.         ACCT-NO = 0
  59.         CUST-NAME = ""
  60.         TRANS-AMT = 0
  61.         REMARK = ""
  62. //      INITIALIZE FIRST READING
  63.         IF M-INDEX == 0 && T-INDEX == 0
  64.             READ MASTER-FILE
  65.             READ TRANS-FILE
  66.             M-INDEX = 1
  67.             T-INDEX = 1
  68.             M-ANUM = MASTER-FILE[M-INDEX](ACCOUNT NUMBER)
  69.             T-ANUM =TRANS-FILE[T-INDEX](ACCOUNT NUMBER)
  70.         ENDIF
  71. //      SEPARATE LOOP USING CASE BLOCKS. I WON'T BE USING THE "CASE" NOTATION, JUST THE USUAL IF ELSE IF
  72. //      LOGGING OCCURS FOR EVERY TRASACNTION. NOTE: INVALID TRANSACTIONS ARE NOT LOGGED
  73. //      WITH THE EXCEPTION OF OVERDRAWN CHECKS SINCE THEY ARE CHRAGED 3$ FOR EACH OCCURENCE
  74. //      CASE WHEN  M-ANUM > T-ANUM
  75. //      THIS MEANS ONLY A TRANSACTION CODE OF '2' IS VALID
  76. //      HOWEVER A SPECIAL CASE MAY BE CONSIDERED WHEN A NEW ACCOUNT IS CREATED AND IS UPDATED IN THE NEXT ITERATION
  77. //      TO TAKE THIS INTO ACCOUNT WE STORE THAT DATA INTO TEMPORARY FIELDS AND
  78. //      DEFER WRITING THEM TO THE MASTER FILE
  79. //      THUS WE DISCARD ALL OTHER TRANSACTIONS OF ANY OTHER TYPE
  80.         IF M-ANUM > T-ANUM
  81.             ACCT-NO = T-ANUM
  82.             CUST-NAME = TRANS-FILE[T-INDEX](CUSTOMER NAME)
  83.             TRANS-AMT = TRANS-FILE[T-INDEX](TRANSACTION AMOUNT)
  84.             IF T-ANUM > CREATED-ACCT-NO
  85. //      FIRST CHECK FOR ANY DEFERRED WRITING INTO THE NEW MASTER FILE FROM CREATED ACCOUNTS
  86. //      THE TRANSACTIONS PERTAINING TO THIS ACCOUNT WERE ALREADY LOGGED SO NO NEED TO LOG
  87.                 IF CREATED-ACCT-NAME IS NOT EMPTY
  88.                     GRAND-TOTAL-BALANCE = GRAND-TOTAL-BALANCE + ACCUM-ACCT-BALANCE
  89.                     WRITE-TO(NEW-MASTER-FILE) CREATED-ACCT-NO " " CREATED-ACCT-NAME " " CREATED-ACCUM-ACCT-BAL
  90.                 ENDIF
  91.                 IF TRANS-FILE[T-INDEX](TRANSACTION CODE) == 2
  92.                     ACCUM-ACCT-BALANCE = TRANS-AMT
  93.                     CREATED-ACCT-NO = ACCT-NO
  94.                     CREATED-ACCUM-BAL = TRANS-AMT
  95.                     CREATED-ACCT-NAME = CUST-NAME
  96.                     WRITTEN = WRITTEN + 1
  97.                     REMARK = "NEW ACCOUNT " ACCT-NO " CREATED"
  98.                     NO-OPEN-ACCTS = NO-OPEN-ACCTS + 1
  99.                 ENDIF
  100.             ELSE
  101.                 IF TRANS-FILE[T-INDEX](TRANSACTION CODE) == 0
  102.                     CREATED-ACCUM-ACCT-BAL = CREATED-ACCUM-ACCT-BAL + TRANS-AMT
  103.                     DEPOSIT = DEPOSIT + TRANS-AMT
  104.                     NO-DEPOSITS = NO-DEPOSITS + 1
  105.                     REMARK = "DEPOSIT SUCCESSFUL"
  106.                 ELSE IF TRANS-FILE[T-INDEX](TRANSACTION CODE) == 1
  107. //                  IF THE CHECK IS VALID WE CHARGE THEM 1$ AND DEDUCT THE WITHRAWN AMOUNT FROM THE ACCUMULATED BALANCE
  108. //                  IF ITS NOT VALID, MEANING  THE AMOUNT WITHRAWN EXCEEDS THE CURRENT BALANCE WE DEDUCT 3$ AND WE DON'T PROCESS THE TRANSACTION
  109. //                  IF THE CURRENT BALANCE IS LESS THAN 3$ WE ZERO IT OUT AND ENTER IT TO THE LOG
  110.                     IF ACCUM-ACCT-BALANCE > = TRANS-AMT + 1
  111.                         CREATED-ACCUM-BAL = CREATED-ACCUM-BAL - (TRANS-AMT + 1)
  112.                         REMARK = "CHECK PROCESSING SUCCESSFUL"
  113.                         CHECK = CHECK + TRANS-AMT
  114.                         CHECK-CHG = CHECK-CHG + 1
  115.                         NO-CHECKS = NO-CHECKS + 1
  116.                     ELSE IF ACCUM-ACCT-BALANCE > = 3 && ACCUM-ACCT-BALANCE < TRANS-AMT + 1
  117.                         CREATED-ACCUM-BAL = CREATED-ACCUM-BAL - 3
  118.                         BAD-CHECKS = BAD-CHECKS + TRANS-AMT
  119.                         BAD-CHECK-CHG = BAD-CHECK-CHG + 3
  120.                         NO-BAD-CHECKS = NO-BAD-CHECKS + 1
  121.                         REMARK = "INSUFFICIENT FUNDS CHECK. PENALTY OF 3$ HAS BEEN CHARGED"
  122.                     ELSE
  123.                         BAD-CHECK-CHG = BAD-CHECK-CHG + CREATED-ACCUM-BAL
  124.                         CREATED-ACCUM-BAL = 0
  125.                         BAD-CHECKS = BAD-CHECKS + TRANS-AMT
  126.                         NO-BAD-CHECKS = NO-BAD-CHECKS + 1
  127.                         REMARK = "INSUFFICIENT FUNDS FOR CHECK. PENALTY OF 3$ CANNOT BE CHARGED ACCOUNT ZEROED OUT"
  128.                     ENDIF
  129.                
  130.                 ELSE IF TRANS-FILE[T-INDEX](TRANSACTION CODE) == 3
  131.                     FLAG-DELETE = TRUE
  132.                     NO-CLOSED-ACCTS = NO-CLOSED-ACCTS + 1
  133.                     REMARK = "ACCOUNT WITH ACCOUNT NUMBER: " ACCT-NO " HAS BEEN CLOSED"
  134.                     CREATED-ACCT-NAME = ""
  135.                     CREATED-ACCT-NO = 0
  136.                     CREATED-ACCT-BAL = 0
  137.                 ENDIF
  138.             ENDIF
  139.             ACCUM-ACCT-BALANCE = CREATED-ACCUM-ACCT-BAL
  140.             PERFORM WRITE-TO-LOG
  141.             PERFORM INC-T-ANUM
  142. //      CASE WHEN  M-ANUM < T-ANUM
  143. //      THIS MEANS THERE ARE NO MORE TRANSACTIONS FOR THE CURRENT ACCOUNT NUMBER
  144.         ELSE IF M-ANUM < T-ANUM
  145. //      FIRST CHECK FOR ANY DEFERRED WRITING INTO THE NEW MASTER FILE FROM CREATED ACCOUNTS
  146. //      THE TRANSACTIONS PERTAINING TO THIS ACCOUN WERE ALREADY LOGGED SO NO NEED TO LOG
  147.             IF CREATED-ACCT-NAME IS NOT EMPTY
  148.                 GRAND-TOTAL-BALANCE = GRAND-TOTAL-BALANCE + ACCUM-ACCT-BALANCE
  149.                 WRITE-TO(NEW-MASTER-FILE) CREATED-ACCT-NO " " CREATED-ACCT-NAME " " CREATED-ACCUM-ACCT-BAL
  150.             ENDIF
  151. //      NEXT CHECK IF THERES AN ACCUMULATED VALUE FROM PREVIOUS TRANSACTIONS
  152. //      TO BE WRITTEN INTO THE MASTER FILE
  153.             IF ACCUM-ACCT-BALANCE == 0
  154. //          IF THE DELETE FLAG IS TRUE THEN WE CONTINUE WITH THE LOOP
  155. //          WITHOUT WRITING TO THE MASTER FILE
  156.                 IF FLAG-DELETE
  157.                     ACCUM-ACCT-BALANCE = 0
  158.                     FLAG-DELETE = FALSE
  159.                     CYCLE
  160.                 ELSE
  161.                     ACCT-NO = M-ANUM
  162.                     CUST-NAME = MASTER-FILE[M-INDEX](ACCOUNT NAME)         
  163.                     WRITE-TO(NEW-MASTER-FILE) ACCT-NO " " CUST-NAME " " ACCUM-ACCT-BALANCE
  164.                     WRITTEN = WRITTEN + 1
  165.                     ACCUM-ACCT-BALANCE = 0
  166.                     GRAND-TOTAL-BALANCE = GRAND-TOTAL-BALANCE + ACCUM-ACCT-BALANCE
  167. //                  NO LOGS ARE NEEDED FOR THIS SECTION SINCE NO TRANSACTION WAS MADE HERE
  168. //                  THIS IS JUST WHERE WE PRINT THE ACCUMULATED VALUES
  169.                 ENDIF
  170.                 PERFORM INC-M-ANUM
  171. //      IF THERE ARE NO PREVIOUS VALUES THEN JUST PRINT OUT THE CURRENT LINE
  172.             ELSE
  173.                 ACCT-NO = M-ANUM
  174.                 CUST-NAME = MASTER-FILE[M-INDEX](ACCOUNT NAME)
  175.                 TRANS-AMT = MASTER-FILE[M-INDEX](PRESENT BALANCE)
  176.                 ACCUM-ACCT-BALANCE = TRANS-AMT
  177.                 WRITE-TO(NEW-MASTER-FILE) ACCT-NO " " CUST-NAME " " ACCUM-ACCT-BALANCE
  178.                 WRITTEN = WRITTEN + 1
  179.                 GRAND-TOTAL-BALANCE = GRAND-TOTAL-BALANCE + ACCUM-ACCT-BALANCE
  180.                 PERFORM INC-M-ANUM
  181. //      CASE WHEN  M-ANUM = T-ANUM
  182. //      THIS MEANS A TRANSACTION CODE OF '2' IS INVALID
  183. //      THUS WE DISCARD ALL OTHER TRANSACTIONS OF THIS TYPE
  184.         ELSE
  185. //      FIRST CHECK FOR ANY DEFERRED WRITING INTO THE NEW MASTER FILE FROM CREATED ACCOUNTS
  186. //      THE TRANSACTIONS PERTAINING TO THIS ACCOUN WERE ALREADY LOGGED SO NO NEED TO LOG
  187.             IF CREATED-ACCT-NAME IS NOT EMPTY
  188.                 GRAND-TOTAL-BALANCE = GRAND-TOTAL-BALANCE + ACCUM-ACCT-BALANCE
  189.                 WRITE-TO(NEW-MASTER-FILE) CREATED-ACCT-NO " " CREATED-ACCT-NAME " " CREATED-ACCUM-ACCT-BAL
  190.             ENDIF
  191. //          IF THE ACCUM-ACCT-BALANCE IS EMPTY, THIS MEANS THERE WAS NO TRANSACTION BEFORE THIS ITERATION
  192. //          THUS WE SET ITS STARTING VALUE AT THE CURRENT BALANCE
  193.             IF ACCUM-ACCT-BALANCE == 0
  194.                 ACCUM-ACCT-BALANCE = MASTER-FILE[M-INDEX](CURRENT BALANCE)
  195.             ENDIF
  196.             ACCT-NO = M-ANUM
  197.             CUST-NAME = MASTER-FILE[M-INDEX](ACCOUNT NAME)
  198.             TRANS-AMT = TRANS-FILE[T-INDEX](TRANSACTION AMOUNT)
  199.            
  200.             IF TRANS-FILE[T-INDEX](TRANSACTION CODE) == 0
  201.                 ACCUM-ACCT-BALANCE = ACCUM-ACCT-BALANCE + TRANS-AMT
  202.                 DEPOSIT = DEPOSIT + TRANS-AMT
  203.                 NO-DEPOSITS = NO-DEPOSITS + 1
  204.                 REMARK = "DEPOSIT SUCCESSFUL"
  205.             ELSE IF TRANS-FILE[T-INDEX](TRANSACTION CODE) == 1
  206. //              IF THE CHECK IS VALID WE CHARGE THEM 1$ AND DEDUCT THE WITHRAWN AMOUNT FROM THE ACCUMULATED BALANCE
  207. //              IF ITS NOT VALID, MEANING  THE AMOUNT WITHRAWN EXCEEDS THE CURRENT BALANCE WE DEDUCT 3$ AND WE DON'T PROCESS THE TRANSACTION
  208. //              IF THE CURRENT BALANCE IS LESS THAN 3$ WE ZERO IT OUT AND ENTER IT TO THE LOG
  209.                 IF ACCUM-ACCT-BALANCE > = TRANS-AMT + 1
  210.                     ACCUM-ACCT-BALANCE = ACCUM-ACCT-BALANCE - (TRANS-AMT + 1)
  211.                     REMARK = "CHECK PROCESSING SUCCESSFUL"
  212.                     CHECK = CHECK + TRANS-AMT
  213.                     CHECK-CHG = CHECK-CHG + 1
  214.                     NO-CHECKS = NO-CHECKS + 1
  215.                 ELSE IF ACCUM-ACCT-BALANCE > = 3 && ACCUM-ACCT-BALANCE < TRANS-AMT + 1
  216.                     ACCUM-ACCT-BALANCE = ACCUM-ACCT-BALANCE - 3
  217.                     BAD-CHECKS = BAD-CHECKS + TRANS-AMT
  218.                     BAD-CHECK-CHG = BAD-CHECK-CHG + 3
  219.                     NO-BAD-CHECKS = NO-BAD-CHECKS + 1
  220.                     REMARK = "INSUFFICIENT FUNDS FOR CHECK. PENALTY OF 3$ HAS BEEN CHARGED"
  221.                 ELSE
  222.                     BAD-CHECK-CHG = BAD-CHECK-CHG + ACCUM-ACCT-BALANCE
  223.                     ACCUM-ACCT-BALANCE = 0
  224.                     BAD-CHECKS = BAD-CHECKS + TRANS-AMT
  225.                     NO-BAD-CHECKS = NO-BAD-CHECKS + 1
  226.                     REMARK = "INSUFFICIENT FUNDS FOR CHECK. PENALTY OF 3$ CANNOT BE CHARGED. ONLY " ACCUM-ACCT-BALANCE "$ WAS CHARGED"
  227.                 ENDIF
  228.            
  229.             ELSE IF TRANS-FILE[T-INDEX](TRANSACTION CODE) == 3
  230.                 FLAG-DELETE = TRUE
  231.                 NO-CLOSED-ACCTS = NO-CLOSED-ACCTS + 1
  232.                 REMARK = "ACCOUNT WITH ACCOUNT NUMBER: " ACCT-NO " HAS BEEN CLOSED"
  233.             ENDIF
  234. //          LOG EACH TRANSACTION HERE. REMARKS ARE GENERATED AT EACH OF THE TRANSACTION CASE BLOCKS        
  235.             PERFORM WRITE-TO-LOG
  236.             ENDIF
  237. //          ONLY READ NEXT VALUE FROM TRANSACTION FILE
  238. //          IN THE NEXT ITERATION SINCE T-ANUM AND M-ANUM WERE EQUAL IN THIS ITERATION
  239. //          THE ONLY POSSIBLE CASES FOR THE NEXT ITERATION ARE T-ANUM > M-ANUM OR T-ANUM == M-ANUM
  240. //          IN T-ANUM > M-ANUM IT WILL CHECK IF PREV-ACCT-NO IS EMPTY, IF IT ISN'T IT PRINTS THAT OUT
  241.             PERFORM INC-T-ANUM
  242.         ENDIF
  243.     ENDDO
  244. //  PRINT GRAND TOTALS
  245.     LOG-LINE-CTR = TRANS-LOG-LINE-CTR + 1
  246.     IF TRANS-LOG-LINE-CTR > 56
  247.         PERFORM PRINT-TRANS-LOG-HEADERS
  248.         TRANS-LOG-LINE-CTR = 1
  249.     ENDIF
  250.     WRITE-TO(LOG) "GRAND-TOTAL: " GRAND-TOTAL-BALANCE
  251. // PRINT STATISTICS
  252.     LOG-LINE-CTR = TRANS-LOG-LINE-CTR + 1
  253.     IF TRANS-LOG-LINE-CTR > 40
  254.         PERFORM PRINT-TRANS-LOG-HEADERS
  255.         TRANS-LOG-LINE-CTR = 1
  256.     ENDIF
  257.     WRITE-TO(LOG) "Total amount of deposits collected       :   " DEPOSITS
  258.     WRITE-TO(LOG) "Total amount of processed checks     :   " CHECKS
  259.     WRITE-TO(LOG) "Total check processing charges collected :   " CHECK-CHG
  260.     WRITE-TO(LOG) "Total amount of bad checks           :   99999.99" BAD-CHECKS
  261.     WRITE-TO(LOG) "Total amount of bad check charges        :   " BAD-CHECK-CHG
  262.     WRITE-TO(LOG) NEW LINE
  263.     WRITE-TO(LOG) "Run Statistics: "
  264.     WRITE-TO(LOG) "Total number of deposits made            :   " NO-DEPOSITS
  265.     WRITE-TO(LOG) "Total number of checks processed     :   " NO-CHECKS
  266.     WRITE-TO(LOG) "Total number of overdrawn checks     :   " NO-BAD-CHECKS
  267.     WRITE-TO(LOG) "Total number new accounts opened     :   " NO-OPEN-ACCTS
  268.     WRITE-TO(LOG) "Total number of accounts closed      :   " NO-CLOSED-ACCTS
  269.     WRITE-TO(LOG) NEW LINE
  270.     WRITE-TO(LOG) " transaction records read            :   " T-INDEX
  271.     WRITE-TO(LOG) "Total masterfile records read            :   " M-INDEX
  272.     WRITE-TO(LOG) "Total masterfile records written         :   " WRITTEN
  273.    
  274.    
  275.  
  276.     SAVE NEW-MASTER-FILE AS MASTER-FILE
  277.     CLOSE MASTER-FILE
  278.     CLOSE NEW-MASTER-FILE
  279.     CLOSE TRANS-FILE
  280. END
  281.  
  282. INC-T-ANUM.
  283.     IF (!EOF(TRANS-FILE))
  284.         READ TRANS-FILE
  285.     IF (EOF(TRANS-FILE))
  286.         T-ANUM = 100000000
  287.     ELSE
  288.         T-INDEX =  T-INDEX  + 1
  289.         T-ANUM =TRANS-FILE[T-INDEX](ACCOUNT NUMBER)
  290.     ENDIF
  291. INC-T-ANUM END.
  292. INC-M-ANUM.
  293.     IF (!EOF(MASTER-FILE))
  294.         READ MASTER-FILE
  295.     IF (EOF(MASTER-FILE))
  296.         M-ANUM = 100000000
  297.     ELSE
  298.         M-INDEX =  M-INDEX  + 1
  299.         M-ANUM = MASTER-FILE[M-INDEX](ACCOUNT NUMBER)
  300.     ENDIF
  301. INC-M-ANUM END.
  302.  
  303. PRINT-LOG-HEADERS.
  304.     LOG-PAGE-CTR = LOG-PAGE-CTR + 1
  305.     WRITE-TO(LOG) "         XYZ Banking Corporation         Page: "  LOG-PAGE-CTR
  306.     WRITE-TO(LOG) NEW LINE
  307.     WRITE-TO(LOG) "Account Balancing Run Report"
  308.     WRITE-TO(LOG) NEW LINE
  309.     WRITE-TO(LOG) "Acct     Acct        Updated Trans       Remarks"
  310.     WRITE-TO(LOG)  "Number  Name        Balance Code"
  311.     LOG-LINE-CTR = TRANS-LOG-LINE-CTR + 7
  312.  
  313. PRINT-LOG-HEADERS END.
  314.  
  315. WRITE-TO-LOG
  316.     LOG-LINE-CTR = TRANS-LOG-LINE-CTR + 1
  317.     IF TRANS-LOG-LINE-CTR > 56
  318.         PERFORM PRINT-TRANS-LOG-HEADERS
  319.         TRANS-LOG-LINE-CTR = 1
  320.     ENDIF
  321.     WRITE-TO(LOG) ACCT-NO " " CUST-NAME " " ACCUM-ACCT-BALANCE " " TRANS-FILE[T-INDEX](TRANSACTION CODE) " " REMARK
  322. WRITE-TO-LOG END.
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top