BB051 RPG36
The RPG program BB051.rpg36.txt is called by the BB600P.ocl36.txt program to handle invoice batch selection in an IBM System/36 or AS/400 environment. Below is a detailed explanation of the process steps, business rules, tables used, and external programs called.
Process Steps of the BB051 RPG Program¶
The BB051 program is responsible for selecting or creating an invoice batch, ensuring proper batch management (e.g., checking locks, validating user access, and handling batch creation or deletion). It uses a workstation display file (SCREEN) to interact with the user and manages batch records in the BBIBCH and BBIBCHX files. The program executes through subroutines (ONETIM, S1, S2, S3, DRLFWD, DRLBAK, DETCLR) and handles user input for batch selection, creation, or deletion.
Process Steps:¶
- Initialization (
ONETIMSubroutine): - Clears the
CANCELfield and initializes counters (BLIM,Z2,Z7,Z8) to zero. - Sets the lower limit for the
BBIBCHfile (SETLL BBIBCH) to start reading records. - Calls the
DRLFWDsubroutine to populate the initial batch display. - Sets indicators
21and83to control screen display and program flow. -
Checks the
PGMparameter (passed from the OCL program):- If
PGM = 'I'(Invoice Entry), clears indicator44to allow batch creation. - If
PGM ≠ 'I', sets indicator44to restrict batch creation.
- If
-
Screen Processing:
- The program uses three display formats (
S1,S2,S3) defined in theSCREENfile:- S1: Displays a list of batches for selection (handled by
DRLFWD). - S2: Confirms batch selection or deletion.
- S3: Handles cancellation or reset of batch selection.
- S1: Displays a list of batches for selection (handled by
-
The program checks the function key pressed (
KG,KA,KD) and input fields (BTCH#X,DEL) to determine the action:KG(Cancel): SetsCANCEL = 'CANCEL', sets the Last Record (LR) indicator, and exits toENDS1.KA: Initiates forward scrolling (DRLFWD) and displays the next set of batches.KDwithDEL = 'D': Deletes a batch and updates theBBIBCHXfile.
-
Batch Selection or Creation (
S1Subroutine): - New Batch Creation:
- If
BTCH#X = 0(indicator40), the user is creating a new batch. - Checks if
PGM = 'I'(Invoice Entry). If not, displays error messageCOM,2("CANNOT CREATE A BATCH NOW") and exits. - Retrieves the next batch number (
ABNXTB) fromBBIBCHX(record with key'99'). - Increments
ABNXTBand updates theBBIBCHXfile (EXCPT UPDNXB). - Initializes new batch fields:
LKDESC = COM,11("AVAILABLE").PRTD = 'N'(Invoices not printed).RTPD = 'N'(Not ready to post).DTMDYandDATEset to the current date (UDATE).LUMDYandLUDTset to zero (no updates yet).#REC = 0(no records in batch).- Checks if the batch number exists (
CHAIN BBIBCHX). If it does, loops toNXTBCHto get another number. - Adds the new batch to
BBIBCHX(EXCPT ADDBCH) and setsLRto exit.
- If
-
Existing Batch Selection:
- If
BTCH#X ≠ 0, the user is selecting an existing batch. - Retrieves the batch record (
CHAIN BBIBCHXwithBATCH# = BTCH#X). - Validates the batch:
- If not found, deleted (
ABDEL = 'D'), orBATCH# = 99, displays errorCOM,1("INVALID BATCH NO.") and exits. - If
PGM = 'P'(Posting) andABRTPD ≠ 'Y'(not ready to post), displays errorCOM,5("ERROR...PLEASE RE-PRINT ALL INVOICES") and exits. - If
PAR13C ≠ ABSRCE(batch source mismatch, e.g.,PPvs. non-PP), displays errorCOM,1and exits. - Checks batch lock status (
ABLOCK): - If locked (
ABLOCK ≠ *BLANK) and not locked by the post process (ABLOCK ≠ 'P'), allows access if the user (ABUSER) matches the current user (USER) or if the workstation ID (ABLKWS) is blank and the user matches (perJB02andMG01changes). - If locked by the post process (
ABLOCK = 'P'), displays errorCOM,7("BATCH POSTING, CONTACT I.T. FOR HELP") and releases the batch (EXCPT RELBCH). - If locked by another user or workstation, displays error
COM,3("BATCH # IN USE--PLEASE CHOOSE ANOTHER") and releases the batch. - If the batch is accessible, populates fields (
LKDESC,PRTD,RTPD,USER,DATE,LUDT,#REC) for display. - If
DEL = 'D', prompts for deletion confirmation (COM,4) and sets indicators for theS2screen. - Updates the batch record (
EXCPT UPDBCH) if not deleting and setsLRor indicator24(for posting) to exit.
- If
-
Batch Deletion (
S2Subroutine): - If
DEL = 'D'and confirmed (KD), marks the batch as deleted (EXCPT DELBCH) and setsLRto exit. - If creating a new batch, adds the batch record (
EXCPT ADDBCH) and setsLR. -
Otherwise, refreshes the batch list (
DRLFWD) after setting the file position (SETLL BBIBCH). -
Cancel or Reset (
S3Subroutine): -
If
KGis pressed, retrieves the batch record (CHAIN BBIBCHX), saves the lock status (EXCPT SAVBCH), setsCANCEL = 'CANCEL', and exits withLR. -
Scrolling (
DRLFWDandDRLBAKSubroutines): - DRLFWD: Reads forward through
BBIBCHto display up to 10 batches:- Skips deleted batches (
ABDEL = 'D') or batches with source mismatch (ABSRCE ≠ PAR13C). - Populates arrays (
BTC,LKD,LKW,PRT,RTP,USR,DTE,LUD,#RC) with batch details. - Sets lock description (
LKD) based onABLOCK(AVAILABLE,INV ENTRY,INV EDIT,POSTING,INV PRINT). - Stops when 10 records are loaded or the end of the file is reached.
- Skips deleted batches (
-
DRLBAK: Sets indicator
21for backward scrolling (minimal implementation, likely incomplete). -
Screen Display and Output:
- Outputs batch details to the
SCREENfile using formatsBB051S1,BB051S2, orBB051S3. -
Updates or adds records to
BBIBCHXvia exception outputs (UPDNXB,ADDBCH,UPDBCH,RELBCH,DELBCH,SAVBCH). -
Termination:
- The program exits with the Last Record (
LR) indicator set when a batch is selected, created, deleted, or cancelled.
Business Rules¶
- Batch Creation:
- New batches can only be created if
PGM = 'I'(Invoice Entry). - The next batch number is retrieved from
BBIBCHX(key'99') and incremented. - If the batch number exists, the program loops to find an available number.
-
New batches are initialized with
PRTD = 'N',RTPD = 'N', and the current date. -
Batch Selection:
- Batches must exist, not be deleted (
ABDEL ≠ 'D'), and not be the reserved batch number99. - For posting (
PGM = 'P'), the batch must be ready to post (ABRTPD = 'Y'). - The batch source (
ABSRCE) must match the input parameterPAR13C(e.g.,PPfor Viscosity Post). - Locked batches (
ABLOCK ≠ *BLANK) can only be accessed if:- The user (
ABUSER) matches the current user (USER), and the lock is not set by the post process (ABLOCK ≠ 'P') (perMG01andJB04). - The workstation ID (
ABLKWS) is blank, and the user matches (perJB02).
- The user (
-
If a batch is locked by another user or the post process, an error is displayed, and the batch is released.
-
Batch Deletion:
- Users can mark a batch for deletion (
DEL = 'D') after confirmation. -
Deletion updates the
ABDELfield inBBIBCHX. -
Lock Management:
- Batches can be locked for Invoice Entry (
I), Edit (E), Forms (F), or Posting (P). -
The program prevents access to locked batches unless the user or workstation matches the lock criteria.
-
Date Handling:
- Dates are stored in 6-digit format (
ABDAT6,ABLUD6) and converted for display (perJB03). -
The creation date (
DATE) and last update date (LUDT) are updated using the system date (UDATE). -
Error Handling:
- Displays specific error messages (
COM,1toCOM,7) for invalid batch numbers, locked batches, or unprinted invoices. - Ensures batches are ready to post and match the source code before allowing selection.
Tables (Files) Used¶
- SCREEN:
- A workstation display file (600 bytes) used for user interaction.
- Supports three formats:
BB051S1(batch list),BB051S2(batch confirmation),BB051S3(cancel/reset). -
Keyed by
WSID(workstation ID) and usesSTATfor status andROLLKYfor roll key handling. -
BBIBCH:
- Invoice batch header file (48 bytes, logical file with 2-byte key).
- Used for reading batch records during scrolling and selection.
-
Disposition: Input (
ID), shared access (DISP-SHRin OCL). -
BBIBCHX:
- Invoice batch header file (48 bytes, physical file with 2-byte key, update-capable).
- Fields include:
ABDEL(1 byte): Delete code.ABBTCH(2 bytes): Batch number.ABLOCK(1 byte): Batch lock status (I,E,F,P, or blank).ABLKWS(2 bytes): Batch lock workstation ID.ABPRTD(1 byte): BOL/Invoice printed status.ABUSER(8 bytes): User ID.ABDATE,ABDAT6(7, 6 bytes): Creation date (CYM and 6-digit format).ABLUDT,ABLUD6(7, 6 bytes): Last update date (CYM and 6-digit format).ABREC(8 bytes): Number of records.ABSRCE(2 bytes): Batch source (e.g.,PPfor Viscosity Post).ABRTPD(1 byte): Ready to post status.ABNXTB(2 bytes): Next batch number.
- Used for reading, updating, adding, and deleting batch records.
- Disposition: Update-capable (
UC), shared access (DISP-SHRin OCL).
External Programs Called¶
The BB051 program does not explicitly call any external programs. It is a self-contained RPG program that interacts with the user via the SCREEN display file and manages the BBIBCH and BBIBCHX files.
Summary¶
The BB051 RPG program facilitates invoice batch selection and creation for the invoice posting process initiated by BB600P.ocl36.txt. It:
- Initializes the batch selection process and displays available batches.
- Allows creation of new batches (only in Invoice Entry mode) or selection of existing batches.
- Enforces business rules for batch access, locking, deletion, and readiness for posting.
- Handles user interaction through display formats and updates the batch header file.
Tables Used: SCREEN (display file), BBIBCH (logical batch file), BBIBCHX (physical batch file).
External Programs Called: None.