Complete Projects

Apply open/deposit/withdraw/close transactions to an indexed account master, reject invalid ones, write an audit trail, and end with a meaningful return code.

42.1 Batch account update (indexed master + transaction file + audit log)

Apply open/deposit/withdraw/close transactions to an indexed account master, reject invalid ones, write an audit trail, and end with a meaningful return code.

Transaction file trans.txt (account 8, code 1, amount 9 with 2 implied decimals, name 30):

Run with cobc -x acctupdt.cob && ./acctupdt; echo $?. The first run opens account 10000001 with 1,000.00, deposits 250.50, rejects the 5,000.00 withdrawal (insufficient funds), rejects the unknown account 10000002, withdraws 100.00 (balance 1,150.50), rejects code X, and exits with status 4. Running it again rejects the duplicate open — a good illustration of why batch jobs need restart logic. On z/OS, replace the literals in ASSIGN with DD names, define the master as a VSAM KSDS (Chapter 22), and run it in a JCL step whose RC=4 drives an IF that emails the rejects report.

10000001O000100000JANE DOE
10000001D000025050
10000001W000500000
10000002D000001000
10000001W000010000
10000001X000000000
IDENTIFICATION DIVISION.
       PROGRAM-ID. ACCTUPDT.
      *----------------------------------------------------------
      * Apply transactions to an indexed account master,
      * write an audit log, and set RETURN-CODE 4 on rejects.
      *----------------------------------------------------------
       ENVIRONMENT DIVISION.
       INPUT-OUTPUT SECTION.
       FILE-CONTROL.
           SELECT ACCT-MASTER ASSIGN TO "acctmast.dat"
               ORGANIZATION IS INDEXED
               ACCESS MODE IS RANDOM
               RECORD KEY IS AM-ACCT-ID
               FILE STATUS IS WS-AM-FS.
           SELECT TRANS-FILE ASSIGN TO "trans.txt"
               ORGANIZATION IS LINE SEQUENTIAL
               FILE STATUS IS WS-TR-FS.
           SELECT AUDIT-FILE ASSIGN TO "audit.txt"
               ORGANIZATION IS LINE SEQUENTIAL
               FILE STATUS IS WS-AU-FS.
       DATA DIVISION.
       FILE SECTION.
       FD  ACCT-MASTER.
       01  AM-RECORD.
           05  AM-ACCT-ID        PIC 9(8).
           05  AM-NAME           PIC X(30).
           05  AM-BALANCE        PIC S9(9)V99 COMP-3.
           05  AM-STATUS         PIC X.
               88  AM-OPEN       VALUE "O".
               
…

42.2 Nightly batch job stream (z/OS)

Build a JCL job whose steps test the previous return codes: IEFBR14 deletes yesterday's work datasets; SORT sorts the day's transactions (GDG (0)) by account; ACCTUPDT runs against a VSAM KSDS master; IF (ACCTUPDT.RC = 4) copies the audit rejects with IEBGENER to a report dataset for operations; IDCAMS REPRO backs up the master to a new GDG generation (+1); and a report program prints a control-break summary by branch (Chapter 24).

42.3 CICS + Db2 customer inquiry

Convert the CICS inquiry program (Chapter 37) to read customers from a Db2 table with a singleton SELECT INTO, add a browse screen using a cursor (PF7/PF8 paging with the last key saved in the COMMAREA), and an update screen protected with optimistic locking (compare a timestamp column before UPDATE).

42.4 Interactive menu application (GnuCOBOL)

A console program with a main menu (ACCEPT choice → EVALUATE) for maintaining an indexed product file: add, change, delete, inquire, list with paging, and a stock-value report. Optional: use GnuCOBOL's SCREEN SECTION for full-screen forms with colors and field validation.

42.5 API-enable a COBOL program

Expose the account inquiry logic as a REST API: separate business logic into a subprogram with a clean COMMAREA/container interface, generate an OpenAPI definition with z/OS Connect, test with curl, and call it from a small web page or Python script.