In this case study, we will develop a simplified banking system using COBOL. This project will help you understand how to apply the concepts learned throughout the course in a real-world scenario. The banking system will include functionalities such as creating accounts, depositing money, withdrawing money, and checking account balances.
Objectives
- Understand the application of COBOL in a real-world banking system.
- Implement file handling for storing account information.
- Use control structures to manage banking operations.
- Apply modular programming techniques to organize the code.
System Requirements
- Create Account: Allow users to create a new bank account.
- Deposit Money: Allow users to deposit money into their account.
- Withdraw Money: Allow users to withdraw money from their account.
- Check Balance: Allow users to check their account balance.
System Design
Data Structure
We will use a sequential file to store account information. Each record in the file will represent an account with the following fields:
- Account Number (Numeric, 10 digits)
- Account Holder Name (Alphanumeric, 30 characters)
- Account Balance (Numeric, 9 digits with 2 decimal places)
File Layout
Field Name | Data Type | Length |
---|---|---|
Account Number | Numeric | 10 |
Account Holder Name | Alphanumeric | 30 |
Account Balance | Numeric | 9.2 |
COBOL Program Structure
The program will be divided into multiple sections:
- Identification Division: Program metadata.
- Environment Division: File definitions.
- Data Division: Variable and file record definitions.
- Procedure Division: Main logic and subroutines.
Implementation
Identification Division
Environment Division
ENVIRONMENT DIVISION. INPUT-OUTPUT SECTION. FILE-CONTROL. SELECT AccountFile ASSIGN TO "accounts.dat" ORGANIZATION IS SEQUENTIAL.
Data Division
DATA DIVISION. FILE SECTION. FD AccountFile. 01 AccountRecord. 05 AccountNumber PIC 9(10). 05 AccountHolderName PIC X(30). 05 AccountBalance PIC 9(7)V99. WORKING-STORAGE SECTION. 01 WS-Choice PIC 9. 01 WS-AccountNumber PIC 9(10). 01 WS-AccountHolderName PIC X(30). 01 WS-AccountBalance PIC 9(7)V99. 01 WS-Amount PIC 9(7)V99.
Procedure Division
PROCEDURE DIVISION. MAIN-PARA. PERFORM DisplayMenu ACCEPT WS-Choice EVALUATE WS-Choice WHEN 1 PERFORM CreateAccount WHEN 2 PERFORM DepositMoney WHEN 3 PERFORM WithdrawMoney WHEN 4 PERFORM CheckBalance WHEN OTHER DISPLAY "Invalid choice. Please try again." END-EVALUATE STOP RUN. DisplayMenu. DISPLAY "1. Create Account" DISPLAY "2. Deposit Money" DISPLAY "3. Withdraw Money" DISPLAY "4. Check Balance" DISPLAY "Enter your choice: ". CreateAccount. DISPLAY "Enter Account Number: " ACCEPT WS-AccountNumber DISPLAY "Enter Account Holder Name: " ACCEPT WS-AccountHolderName MOVE 0 TO WS-AccountBalance OPEN OUTPUT AccountFile MOVE WS-AccountNumber TO AccountNumber MOVE WS-AccountHolderName TO AccountHolderName MOVE WS-AccountBalance TO AccountBalance WRITE AccountRecord CLOSE AccountFile DISPLAY "Account created successfully.". DepositMoney. DISPLAY "Enter Account Number: " ACCEPT WS-AccountNumber DISPLAY "Enter Amount to Deposit: " ACCEPT WS-Amount OPEN I-O AccountFile PERFORM ReadAccount IF AccountNumber = WS-AccountNumber ADD WS-Amount TO AccountBalance REWRITE AccountRecord DISPLAY "Deposit successful." ELSE DISPLAY "Account not found." END-IF CLOSE AccountFile. WithdrawMoney. DISPLAY "Enter Account Number: " ACCEPT WS-AccountNumber DISPLAY "Enter Amount to Withdraw: " ACCEPT WS-Amount OPEN I-O AccountFile PERFORM ReadAccount IF AccountNumber = WS-AccountNumber IF AccountBalance >= WS-Amount SUBTRACT WS-Amount FROM AccountBalance REWRITE AccountRecord DISPLAY "Withdrawal successful." ELSE DISPLAY "Insufficient balance." END-IF ELSE DISPLAY "Account not found." END-IF CLOSE AccountFile. CheckBalance. DISPLAY "Enter Account Number: " ACCEPT WS-AccountNumber OPEN INPUT AccountFile PERFORM ReadAccount IF AccountNumber = WS-AccountNumber DISPLAY "Account Balance: " AccountBalance ELSE DISPLAY "Account not found." END-IF CLOSE AccountFile. ReadAccount. READ AccountFile INTO AccountRecord AT END DISPLAY "End of file reached." NOT AT END IF AccountNumber = WS-AccountNumber EXIT PERFORM END-IF END-READ.
Summary
In this case study, we developed a simplified banking system using COBOL. We covered:
- Creating a sequential file to store account information.
- Implementing basic banking operations such as creating accounts, depositing money, withdrawing money, and checking balances.
- Using control structures and modular programming techniques to organize the code.
This case study provides a practical application of COBOL programming concepts and prepares you for more complex real-world projects.