BB001 RPG36
Process Steps of the RPG Program (BB001.rpg36.txt)¶
This RPG program, BB001, is designed for an IBM System/36 environment and is called by the BB170 OCL procedure as part of an order management system. Its primary function is order batch selection, allowing users to select an existing batch or create a new one for order processing. It uses an interactive workstation display (SCREEN) to prompt for batch selection, validates inputs, and manages batch records in the BBBTCH/BBBTCHX files. The program handles batch creation, updates, deletion, and locking, with logic for scrolling through batch records and error handling. Below is a step-by-step breakdown of the process, executed within the RPG cycle:
- Initialization (Mainline Calculations):
- If indicators 75 and 76 are off (roll key status indicators for scrolling), set off indicators 50, 21, 22 (error/display controls) and 23, 24 (scrolling flags).
- Clear the error message field (MSG) to blanks.
- Set off indicators 75, 76 (roll key status) to reset scrolling state.
- If indicator 09 is on (first-pass flag), execute ONETIM subroutine for one-time setup.
-
Based on screen input formats (NS 01, 02, 03):
- If indicator 01 is on (format BB001S1), execute S1 subroutine (main batch selection).
- If indicator 02 is on (format BB001S2), execute S2 subroutine (batch confirmation/deletion).
- If indicator 03 is on (format BB001S3), execute S3 subroutine (batch reset/cancellation).
-
ROLLKY Subroutine (Handle Scrolling):
- Triggered by roll key presses (status codes 01122 for forward, 01123 for backward).
- Set off indicators 21, 22, 23, 24, 50 (clear scrolling and error states).
- If status is 01122 and indicator 83 is on (forward roll), execute DRLFWD (scroll forward).
- If status is 01123 and 83 is on (backward roll), execute DRLBAK (scroll backward).
-
If 83 is on, branch to ENDRL tag, clear STATUS, and set off 09 to reset for next input.
-
ONETIM Subroutine (One-Time Setup):
- Clear CANCEL field (local data area offset 121) to blanks.
- Initialize counters: BLIM (batch limit), Z2, Z7, Z8 to zero.
- Set lower limit (SETLL) on BBBTCH file at BLIM (start of file).
- Execute DRLFWD to load first batch record(s) for display.
- Set on indicators 21 (display BB001S1 format) and 83 (scroll control).
-
If PGM (offset 504, set to 'O' by OCL) is 'O' (order entry mode), set off 44 (allow batch creation); otherwise, set on 44 (restrict creation).
-
S1 Subroutine (Main Batch Selection):
- If KG is on (cancellation mode), set off 01, 02, 09, set CANCEL to 'CANCEL', set on LR (last record, end program), and branch to ENDS1.
-
Compare BTCH#X (user-entered batch number) to zero:
- If zero (new batch):
- If PGM is not 'O', display error message 2 ("CANNOT CREATE A BATCH NOW"), set on 90, 21, 51 (error state), and branch to ENDS1.
- Chain to BBBTCHX at key '99' (next batch number record).
- If not found (99 on), set ABNXTB to 1; otherwise, increment ABNXTB (next batch number).
- If ABNXTB reaches 99, reset to 1 (wrap-around).
- Update next batch number (EXCPT UPDNXB).
- Set batch fields: LKDESC to message 11 ("AVAILABLE"), PRTD to 'N' (not printed), DTMDY/DATE to current date (UDATE), LUMDY/LUDT to zero (no updates), #REC to zero.
- Chain to BBBTCHX with BATCH# (new batch number).
- If not found (49 on), add new batch record (EXCPT ADDBCH, includes PAR13C from offset 470), set on LR, set off 83, and branch to ENDS1.
- If found (batch exists), loop to NXTBCH to try next number.
- If non-zero (existing batch):
- Set BATCH# to BTCH#X and chain to BBBTCHX.
- If not found, deleted (ABDEL='D'), or BATCH# is 99, display message 1 ("INVALID BATCH NO. -- PLEASE REKEY"), set on 90, 21, and branch to ENDS1.
- If ABLOCK='O' and PGM='P' (posting mode), display message 5 ("BATCH # IN USE--CANNOT POST NOW"), set on 90, 21, branch to ENDS1.
- If PAR13C (order type, e.g., 'PP') does not match ABSRCE (batch source), display message 1, set on 51, 90, 21, branch to ENDS1.
- If ABLOCK is not blank and ABUSER matches USER (same user locked it), skip to AROUND (allow access).
- If ABLOCK is not blank (batch locked), display message 3 ("BATCH # IN USE--PLEASE CHOOSE ANOTHER"), set on 90, 21, 51, release batch (EXCPT RELBCH), and branch to ENDS1.
- Set batch fields for update: LKDESC, PRTD, DTMDY, LUDT (current date), #REC.
- If DEL='D' (delete requested), display message 4 ("CMD 4 - TO DELETE EXISTING BATCH"), set on 90, 22 (display BB001S2), set off 83.
- If not deleting, update batch (EXCPT UPDBCH).
- If PGM='P', set on 24 (post mode flag) and branch to ENDS1; otherwise, set on LR.
-
S2 Subroutine (Batch Confirmation/Deletion):
- If KA is on (scroll forward), set on 83, 21, set lower limit on BBBTCH, execute DRLFWD, and branch to ENDS2.
- If 52 (delete mode) and KD is off (no delete key), set on 83, 21, set lower limit, execute DRLFWD, and branch to ENDS2.
- If 52 and KD (delete confirmed), set on U1 (update mode), delete batch (EXCPT DELBCH), set on LR, and branch to ENDS2.
-
If BATCH# exists (chain to BBBTCHX, 49 on), add new batch (EXCPT ADDBCH), set off 49, set on LR.
-
S3 Subroutine (Batch Reset/Cancellation):
-
If KG is on and BATCH# exists (chain to BBBTCHX, 49 off), save batch state (EXCPT SAVBCH), set off 01, 02, 03, 09, set CANCEL to 'CANCEL', set on LR, and branch to ENDS3.
-
DRLFWD Subroutine (Scroll Forward):
- Initialize counter X to 1, clear batch arrays (BTC, LKD, etc.) via DETCLR.
- Read BBBTCH sequentially, skipping if ABBTCH=99 or ABDEL='D'.
- If PAR13C (order type) matches ABSRCE, populate arrays (BTC, LKD, LKW, PRT, USR, DTE, LUD, #RC) for display, increment X.
- Set LKD based on ABLOCK ('O'→12 "ORD ENTRY", 'L'→13 "PICK LIST", 'B'→15 "BOL PRINT", 'P'→14 "POSTING", else 11 "AVAILABLE").
- Stop at X=11 or end of file (99 on, set 68).
-
If no records (X=1 and 68 on), set on 23 (no data) and reposition BBBTCH.
-
DRLBAK Subroutine (Scroll Backward):
-
Set on 21 (display BB001S1); minimal logic (likely incomplete or stubbed).
-
DETCLR Subroutine (Clear Arrays):
-
Zero out arrays BTC, DTE, LUD, #RC; blank LKD, LKW, PRT, USR for display refresh.
-
Output Operations:
- Format BB001S1 (indicator 21): Display batch list (KYHDG, BTC, LKD, LKW, PRT, USR, DTE, LUD, #RC, BTCH#X, DEL, MSG).
- Format BB001S2 (22): Confirm batch details (KYHDG, BATCH#, LKDESC, WSID, PRTD, USER, DTMDY, LUMDY, #REC, MSG).
- Format BB001S3 (24): Similar to BB001S2, for posting mode.
- Exceptions: UPDNXB (update next batch number), ADDBCH (add batch, includes PAR13C), UPDBCH (update batch), RELBCH (release lock), DELBCH (delete batch), SAVBCH (save batch state).
-
Program End:
- If LR is set (via cancellation, batch creation, or deletion), end program, returning to OCL.
- Otherwise, loop via RPG cycle for user input (batch selection or correction).
Business Rules¶
- Batch Selection:
- Users can select an existing batch (BTCH#X non-zero) or create a new one (BTCH#X zero).
- Existing batches must exist, not be deleted (ABDEL≠'D'), and not be batch 99 (reserved).
- Batches must match the order type (PAR13C=ABSRCE, e.g., 'PP' for viscosity ASN).
- Batch Creation:
- Only allowed in order entry mode (PGM='O').
- Next batch number (ABNXTB) increments from 1 to 99, wrapping to 1.
- New batches are initialized with: no lock (ABLOCK blank), not printed (PRTD='N'), current date (UDATE), zero records (#REC), and PAR13C as source.
- Batch Locking:
- Locked batches (ABLOCK non-blank) are restricted unless the current user (USER) matches the locking user (ABUSER).
- Lock types: 'O' (order entry), 'L' (pick list), 'P' (posting), 'B' (BOL print).
- Posting (PGM='P') is blocked if ABLOCK='O'.
- Batch Deletion:
- Users can mark a batch for deletion (DEL='D'), confirmed via BB001S2.
- Deletion updates the batch record (EXCPT DELBCH).
- Cancellation:
- If KG is on, set CANCEL to 'CANCEL' and exit (checked by OCL).
- Data Integrity:
- Batch numbers are unique (checked via chain).
- BBBTCH (input) and BBBTCHX (update) point to the same file, with BBBTCHX allowing record updates/additions.
- Date fields (ABDATE, ABLUDT) are stored in century-year-month format, converted for display.
- Scrolling:
- Display up to 10 batches (X=1 to 10) in BB001S1, skipping deleted or mismatched source batches.
- Roll keys (01122/01123) control forward/backward scrolling.
- Error Handling:
- Invalid batch: Message 1, highlight field.
- Cannot create batch outside order entry: Message 2.
- Batch in use: Message 3 (unless same user).
- Delete prompt: Message 4.
- Posting conflict: Message 5.
- Errors protect the screen (90 on) and prompt rekeying.
Tables Used¶
- BBBTCH: Batch control file (input, 48-byte records, 2-byte alphanumeric key, indexed). Used for reading batch records sequentially or by key.
- BBBTCHX: Same physical file as BBBTCH (update mode, UC). Used for adding/updating batch records (e.g., ABNXTB, new batches).
- Fields: ABDEL (delete code), ABBTCH (batch number), ABLOCK (lock status), ABLKWS (lock workstation ID), ABPRTD (BOL printed), ABUSER (user ID), ABDATE (creation date), ABLUDT (last update date), ABREC (# of records), ABSRCE (batch source), ABNXTB (next batch number).
- SCREEN: Workstation file (600-byte records) for interactive display (formats BB001S1, BB001S2, BB001S3). Not a disk table.
External Programs Called¶
- None. BB001 is self-contained, relying on subroutines (ROLLKY, ONETIM, S1, S2, S3, DRLFWD, DRLBAK, DETCLR) and exception outputs (UPDNXB, ADDBCH, RELBCH, DELBCH, UPDBCH, SAVBCH) to manage batch operations.