Module 15: CICS Real-World Projects and Interview Preparation
Account Update Transaction
An account update transaction changes stored data: deposits, withdrawals, address changes and account closure.
Unlike inquiry, it must lock the record, validate the input, rewrite the record and commit - all with clean error handling.
The update flow
- Read the record with READ ... UPDATE so CICS locks it for this task until syncpoint.
- Show the current values on the data map; the user changes the fields and presses Enter.
- Validate every input field: amounts must be numeric, names non-blank, withdrawal not more than the balance.
- Update the record fields in WORKING-STORAGE, then REWRITE the record to the file.
- On success show a confirmation message and issue EXEC CICS SYNCPOINT to commit and release the lock.
Locking and error handling
- READ UPDATE holds the record lock until the next syncpoint - keep the time between READ and syncpoint short.
- Check RESP on both READ and REWRITE. NOTFND, DUPKEY and IOERR each need their own message.
- If another task holds the record, CICS makes this task wait; handle the locked condition with a polite retry message.
- Explicit RESP checks are clearer than HANDLE CONDITION and are preferred in most shops.
- On any validation or file error, skip the REWRITE and redisplay the map with the error highlighted.
- Example:-
EXEC CICS READ FILE('ACCTMAS') INTO(ACCOUNT-RECORD) RIDFLD(WS-ACCT-NO) UPDATE RESP(WS-RESP) END-EXEC. IF WS-RESP = DFHRESP(NORMAL) ADD WS-AMOUNT TO ACCT-BALANCE EXEC CICS REWRITE FILE('ACCTMAS') FROM(ACCOUNT-RECORD) RESP(WS-RESP) END-EXEC IF WS-RESP = DFHRESP(NORMAL) EXEC CICS SYNCPOINT END-EXEC MOVE 'UPDATE SUCCESSFUL' TO MSGO ELSE EXEC CICS SYNCPOINT ROLLBACK END-EXEC MOVE 'UPDATE FAILED - TRY AGAIN' TO MSGO END-IF END-IF.
Validation rules used in real projects
- Amount fields must be numeric and positive; test with IS NUMERIC before any arithmetic.
- Withdrawal amount cannot exceed the balance - check this before the REWRITE, not after.
- Mandatory fields such as name and account number cannot be blank or spaces.
- Highlight the bad field by setting its map attribute to bright so the user sees exactly what to fix.
- Never trust map input lengths - the user can type more than the field allows on some terminals.
