Skip to content

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:

  1. Initialization (ONETIM Subroutine):
  2. Clears the CANCEL field and initializes counters (BLIM, Z2, Z7, Z8) to zero.
  3. Sets the lower limit for the BBIBCH file (SETLL BBIBCH) to start reading records.
  4. Calls the DRLFWD subroutine to populate the initial batch display.
  5. Sets indicators 21 and 83 to control screen display and program flow.
  6. Checks the PGM parameter (passed from the OCL program):

    • If PGM = 'I' (Invoice Entry), clears indicator 44 to allow batch creation.
    • If PGM ≠ 'I', sets indicator 44 to restrict batch creation.
  7. Screen Processing:

  8. The program uses three display formats (S1, S2, S3) defined in the SCREEN file:
    • 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.
  9. The program checks the function key pressed (KG, KA, KD) and input fields (BTCH#X, DEL) to determine the action:

    • KG (Cancel): Sets CANCEL = 'CANCEL', sets the Last Record (LR) indicator, and exits to ENDS1.
    • KA: Initiates forward scrolling (DRLFWD) and displays the next set of batches.
    • KD with DEL = 'D': Deletes a batch and updates the BBIBCHX file.
  10. Batch Selection or Creation (S1 Subroutine):

  11. New Batch Creation:
    • If BTCH#X = 0 (indicator 40), the user is creating a new batch.
    • Checks if PGM = 'I' (Invoice Entry). If not, displays error message COM,2 ("CANNOT CREATE A BATCH NOW") and exits.
    • Retrieves the next batch number (ABNXTB) from BBIBCHX (record with key '99').
    • Increments ABNXTB and updates the BBIBCHX file (EXCPT UPDNXB).
    • Initializes new batch fields:
    • LKDESC = COM,11 ("AVAILABLE").
    • PRTD = 'N' (Invoices not printed).
    • RTPD = 'N' (Not ready to post).
    • DTMDY and DATE set to the current date (UDATE).
    • LUMDY and LUDT set to zero (no updates yet).
    • #REC = 0 (no records in batch).
    • Checks if the batch number exists (CHAIN BBIBCHX). If it does, loops to NXTBCH to get another number.
    • Adds the new batch to BBIBCHX (EXCPT ADDBCH) and sets LR to exit.
  12. Existing Batch Selection:

    • If BTCH#X ≠ 0, the user is selecting an existing batch.
    • Retrieves the batch record (CHAIN BBIBCHX with BATCH# = BTCH#X).
    • Validates the batch:
    • If not found, deleted (ABDEL = 'D'), or BATCH# = 99, displays error COM,1 ("INVALID BATCH NO.") and exits.
    • If PGM = 'P' (Posting) and ABRTPD ≠ 'Y' (not ready to post), displays error COM,5 ("ERROR...PLEASE RE-PRINT ALL INVOICES") and exits.
    • If PAR13C ≠ ABSRCE (batch source mismatch, e.g., PP vs. non-PP), displays error COM,1 and 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 (per JB02 and MG01 changes).
    • If locked by the post process (ABLOCK = 'P'), displays error COM,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 the S2 screen.
    • Updates the batch record (EXCPT UPDBCH) if not deleting and sets LR or indicator 24 (for posting) to exit.
  13. Batch Deletion (S2 Subroutine):

  14. If DEL = 'D' and confirmed (KD), marks the batch as deleted (EXCPT DELBCH) and sets LR to exit.
  15. If creating a new batch, adds the batch record (EXCPT ADDBCH) and sets LR.
  16. Otherwise, refreshes the batch list (DRLFWD) after setting the file position (SETLL BBIBCH).

  17. Cancel or Reset (S3 Subroutine):

  18. If KG is pressed, retrieves the batch record (CHAIN BBIBCHX), saves the lock status (EXCPT SAVBCH), sets CANCEL = 'CANCEL', and exits with LR.

  19. Scrolling (DRLFWD and DRLBAK Subroutines):

  20. DRLFWD: Reads forward through BBIBCH to 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 on ABLOCK (AVAILABLE, INV ENTRY, INV EDIT, POSTING, INV PRINT).
    • Stops when 10 records are loaded or the end of the file is reached.
  21. DRLBAK: Sets indicator 21 for backward scrolling (minimal implementation, likely incomplete).

  22. Screen Display and Output:

  23. Outputs batch details to the SCREEN file using formats BB051S1, BB051S2, or BB051S3.
  24. Updates or adds records to BBIBCHX via exception outputs (UPDNXB, ADDBCH, UPDBCH, RELBCH, DELBCH, SAVBCH).

  25. Termination:

  26. The program exits with the Last Record (LR) indicator set when a batch is selected, created, deleted, or cancelled.

Business Rules

  1. Batch Creation:
  2. New batches can only be created if PGM = 'I' (Invoice Entry).
  3. The next batch number is retrieved from BBIBCHX (key '99') and incremented.
  4. If the batch number exists, the program loops to find an available number.
  5. New batches are initialized with PRTD = 'N', RTPD = 'N', and the current date.

  6. Batch Selection:

  7. Batches must exist, not be deleted (ABDEL ≠ 'D'), and not be the reserved batch number 99.
  8. For posting (PGM = 'P'), the batch must be ready to post (ABRTPD = 'Y').
  9. The batch source (ABSRCE) must match the input parameter PAR13C (e.g., PP for Viscosity Post).
  10. 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') (per MG01 and JB04).
    • The workstation ID (ABLKWS) is blank, and the user matches (per JB02).
  11. If a batch is locked by another user or the post process, an error is displayed, and the batch is released.

  12. Batch Deletion:

  13. Users can mark a batch for deletion (DEL = 'D') after confirmation.
  14. Deletion updates the ABDEL field in BBIBCHX.

  15. Lock Management:

  16. Batches can be locked for Invoice Entry (I), Edit (E), Forms (F), or Posting (P).
  17. The program prevents access to locked batches unless the user or workstation matches the lock criteria.

  18. Date Handling:

  19. Dates are stored in 6-digit format (ABDAT6, ABLUD6) and converted for display (per JB03).
  20. The creation date (DATE) and last update date (LUDT) are updated using the system date (UDATE).

  21. Error Handling:

  22. Displays specific error messages (COM,1 to COM,7) for invalid batch numbers, locked batches, or unprinted invoices.
  23. Ensures batches are ready to post and match the source code before allowing selection.

Tables (Files) Used

  1. SCREEN:
  2. A workstation display file (600 bytes) used for user interaction.
  3. Supports three formats: BB051S1 (batch list), BB051S2 (batch confirmation), BB051S3 (cancel/reset).
  4. Keyed by WSID (workstation ID) and uses STAT for status and ROLLKY for roll key handling.

  5. BBIBCH:

  6. Invoice batch header file (48 bytes, logical file with 2-byte key).
  7. Used for reading batch records during scrolling and selection.
  8. Disposition: Input (ID), shared access (DISP-SHR in OCL).

  9. BBIBCHX:

  10. Invoice batch header file (48 bytes, physical file with 2-byte key, update-capable).
  11. 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., PP for Viscosity Post).
    • ABRTPD (1 byte): Ready to post status.
    • ABNXTB (2 bytes): Next batch number.
  12. Used for reading, updating, adding, and deleting batch records.
  13. Disposition: Update-capable (UC), shared access (DISP-SHR in 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.