Skip to content

Fix arithmetic and control flow bugs in batch programs#32

Open
DukeDeSouth wants to merge 1 commit into
aws-samples:mainfrom
DukeDeSouth:fix/batch-program-bugs
Open

Fix arithmetic and control flow bugs in batch programs#32
DukeDeSouth wants to merge 1 commit into
aws-samples:mainfrom
DukeDeSouth:fix/batch-program-bugs

Conversation

@DukeDeSouth

Copy link
Copy Markdown

Hi there,

Was reading through the batch programs and noticed a few issues that could cause incorrect results in production:

CBACT04C (Interest Calculator):

  • COMPUTE WS-MONTHLY-INT was missing ROUNDED, causing interest to be systematically truncated rather than rounded. For a rate of 21.50% on a $10,000 balance, this means $179.16 instead of $179.17 — adds up across accounts.

CBTRN02C (Transaction Posting):

  • Credit limit validation uses CREDIT - DEBIT, but ACCT-CURR-CYC-DEBIT already stores negative values (payments are added via ADD negative-amount). So 3000 - (-2000) = 5000 instead of 1000. This causes valid transactions to be rejected as overlimit after the customer makes payments.
  • REWRITE failure on account file was silently ignored — transaction gets written but balance never updates.
  • 9300-DALYREJS-CLOSE was displaying XREFFILE-STATUS instead of DALYREJS-STATUS (copy-paste).

CBTRN03C (Transaction Report):

  • NEXT SENTENCE inside an inline PERFORM...END-PERFORM transfers control past the END-PERFORM. period, effectively breaking out of the loop on the first out-of-range transaction. Replaced with a nested IF for proper date filtering.
  • EOF branch was adding stale TRAN-AMT to totals (last record counted twice).

All changes are minimal and isolated — no new fields, no copybook changes, no interface changes.

Cheers

Made with Cursor

CBACT04C: add ROUNDED to interest COMPUTE to prevent truncation
CBTRN02C: fix sign error in credit limit check (debit is already negative),
          add proper error handling on account REWRITE failure,
          fix wrong file status variable in DALYREJS close
CBTRN03C: replace NEXT SENTENCE with structured IF to prevent
          premature loop exit, remove stale ADD at EOF
Co-authored-by: Cursor <cursoragent@cursor.com>
@aayn

aayn commented Mar 27, 2026

Copy link
Copy Markdown

Can confirm the CBTRN03C double-counting. Ran a minimal test on z/OS V2.4 with IBM Enterprise COBOL V6.4:

  • Created a single $5.00 transaction (date in 2099 to isolate from existing data)
  • Ran CBTRN03C with CARDXREF/TRANTYPE/TRANCATG VSAM clusters populated from the CardDemo seed data

Report output:

Transaction ID   Account ID  Type        Category                Amount
9999990000000001 00000000034 01-Purchase 0001-Regular Sales Draft  5.00
Page Total ..........................................+            10.00
Grand Total.........................................+            10.00

Detail line shows $5.00, but both totals show $10.00. The EOF ELSE branch at lines 200-201 adds TRAN-AMT a second time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants