# Business Logic

> [← Back to README](../README.md) | [Workflows →](./workflows.md) | [Decision Logic →](./decision-logic.md)

## 1. Authentication (COSGN00C)

**Source:** `app/cbl/COSGN00C.cbl` (lines 72–260)

### Rules
- User ID and password are required fields (lines 80–95)
- Credentials validated against USRSEC VSAM file via `EXEC CICS READ` (line 110–114)
- Password compared in plaintext: `IF SEC-USR-PWD = WS-USER-PWD` (line 223)
- User type determines routing: `IF CDEMO-USRTYP-ADMIN` → admin menu, else → main menu (line 230)
- RESP code NOTFND (13) = invalid user ID (line 245)
- Any other RESP error = system error display (line 251)

## 2. Account Management

### Account View (COACTVWC)
**Source:** `app/cbl/COACTVWC.cbl` (941 lines)
- Reads ACCTDAT by account ID
- Reads CARDDAT via AIX path for associated cards
- Reads CUSTDAT via CCXREF cross-reference
- Display-only — no update operations

### Account Update (COACTUPC)
**Source:** `app/cbl/COACTUPC.cbl` (4,236 lines — largest program)
- Extensive field validation using CSUTLDWY/CSUTLDPY date utilities
- Validates: account status, credit limits, dates (open, expiration, reissue), ZIP code
- Lookup validation against CSLKPCDY (state codes, area codes, ZIP prefixes)
- Uses COPY CSSETATY REPLACING for 18+ field attribute settings
- Reads/updates ACCTDAT, reads CUSTDAT and CCXREF

## 3. Credit Card Operations

### Card List (COCRDLIC)
**Source:** `app/cbl/COCRDLIC.cbl` (1,459 lines)
- Paginated browse of CARDDAT via STARTBR/READNEXT
- Supports forward/backward paging (PF7/PF8)
- Selection transfers to detail view (COCRDSLC) or update (COCRDUPC) via XCTL

### Card Detail View (COCRDSLC)
**Source:** `app/cbl/COCRDSLC.cbl` (887 lines)
- Reads CARDDAT by card number
- Joins with CUSTDAT for customer information
- Display-only with option to edit (PF5 → COCRDUPC)

### Card Update (COCRDUPC)
**Source:** `app/cbl/COCRDUPC.cbl` (1,560 lines)
- Validates: card number, embossed name, expiration date, active status
- Date validation via CSUTLDWY/CSUTLDPY copybooks
- Updates CARDDAT record

## 4. Transaction Processing

### Online Transaction Add (COTRN02C)
**Source:** `app/cbl/COTRN02C.cbl` (783 lines)
- Validates card number against CCXREF cross-reference
- Validates account exists in ACCTDAT and is active
- Generates transaction ID with timestamp
- Writes new transaction record to TRANSACT VSAM file

### Batch Transaction Posting (CBTRN02C)
**Source:** `app/cbl/CBTRN02C.cbl` (731 lines)
- Core batch processing engine
- Reads daily transactions from DALYTRAN sequential file
- For each transaction:
  1. Validates card number exists in XREFDAT
  2. Looks up account in ACCTDAT
  3. Updates account balance (ACCT-CURR-BAL adjusted by TRAN-AMT)
  4. Updates transaction category balance in TCATBALF
  5. Writes to TRANSACT master file
- Rejected transactions (invalid xref, inactive account) logged separately

### Interest Calculation (CBACT04C)
**Source:** `app/cbl/CBACT04C.cbl` (652 lines)
- Accepts date parameter via LINKAGE SECTION (line 175–180)
- For each account (via XREFDAT browse):
  1. Reads transaction category balances from TCATBALF
  2. Looks up disclosure group rates from DISCGRP (using ACCT-GROUP-ID + type + category)
  3. Calculates interest: `balance × rate / 100 / 365 × days`
  4. Creates interest transaction in TRANSACT
  5. Updates ACCTDAT with new balance
  6. Updates TCATBALF with new category balance

## 5. Bill Payment (COBIL00C)
**Source:** `app/cbl/COBIL00C.cbl` (572 lines)
- Validates account exists via CCXREF and ACCTDAT
- Uses ASKTIME/FORMATTIME for current timestamp (lines 251–255)
- Creates payment transaction in TRANSACT
- Updates account balance

## 6. Reporting

### Online Report Request (CORPT00C)
**Source:** `app/cbl/CORPT00C.cbl` (649 lines)
- User selects report type and parameters
- Submits batch job via CICS TD queue (WRITEQ TD to JOBS queue, line 517)
- TD queue routes to internal reader for JCL submission

### Batch Transaction Report (CBTRN03C)
**Source:** `app/cbl/CBTRN03C.cbl` (649 lines)
- Reads TRANSACT, joins with XREFDAT, TRANTYPE, TRANCATG
- Generates formatted transaction report output

### Statement Generation (CBSTM03A/CBSTM03B)
**Source:** `app/cbl/CBSTM03A.CBL` (924 lines), `app/cbl/CBSTM03B.CBL` (230 lines)
- CBSTM03A orchestrates: reads XREFDAT, CUSTDAT, ACCTDAT
- CBSTM03B handles page formatting and output
- Generates customer-facing statements with transaction details

## 7. User Administration (COUSR00C-03C)

### User List (COUSR00C, 695 lines)
- Paginated browse of USRSEC file
- Supports forward/backward paging

### Add User (COUSR01C, 299 lines)
- Validates user ID uniqueness (EXEC CICS READ with RESP check)
- Writes new record to USRSEC (EXEC CICS WRITE, line 240)

### Update User (COUSR02C, 414 lines)
- Reads existing record with UPDATE option
- Validates changes, rewrites record

### Delete User (COUSR03C, 359 lines)
- Confirms deletion, reads record with UPDATE
- Deletes record from USRSEC

## 8. Authorization Processing (Optional — COPAUA0C)
**Source:** `app/app-authorization-ims-db2-mq/cbl/COPAUA0C.cbl` (1,026 lines)
- MQ-triggered program: receives authorization request from queue
- Validates card via VSAM CCXREF cross-reference
- Retrieves account from ACCTDAT, customer from CUSTDAT
- Checks IMS pending authorization database
- Logs fraud check results to DB2 AUTHFRDS table
- Sends approval/denial response via MQ reply queue

## 9. Transaction Type Management (Optional — DB2)

### List/Delete (COTRTLIC, 2,098 lines)
- DB2 cursor-based paginated listing of TRNTYPE table
- Supports delete operation with confirmation

### Add/Edit (COTRTUPC, 1,702 lines)
- INSERT new or UPDATE existing transaction types in DB2
- Validates type code and description

---

*See also: [Workflows](./workflows.md) | [Decision Logic](./decision-logic.md) | [Error Handling](./error-handling.md)*
