Skip to content

BB1016 RPG36

Process Steps of the RPG Program (BB1016)

This RPG program (BB1016) is a subroutine module called from other programs (e.g., BB850 for price history inquiry or BB101 for order entry) to perform product lookups and populate arrays for a lookup screen (S5 in the calling program). It supports two main lookup modes: by customer-specific products ('P') or by product description ('D'). The program selects different files and subroutines based on the calling program (PROGRM parameter, e.g., 'BB101' vs. others like 'BB850'). It reads records, filters them, and fills arrays with up to 15 products (S5L for line number, S5P for product code, S5D for description, S5A for customer alternate description, S5F for fluid code). The program is read-only and does not update data.

The high-level process steps are as follows:

  1. Parameter Reception and Initialization:
  2. Receives parameters: CO (company, 2 digits), CUST (customer, 6 digits), SHIP (ship-to, 3 digits), PROD (lookup mode, 4 chars like 'P' or 'D'), DESC (description search string, 27 chars), arrays (S5L, S5P, S5D, S5A, S5F), and PROGRM (calling program name, 5 chars).
  3. Determines file and subroutine branch based on PROGRM:
    • If PROGRM = 'BB101', uses ARCUP36 for customer products and subroutines BL3S5P/BL3S5D.
    • Otherwise (e.g., 'BB850'), uses ARCUP16 for customer products and subroutines BL1S5P/BL1S5D.
  4. The logic for each branch is similar but uses different key structures and files (ARCUP36 has a 16-byte key, ARCUP16 has a 41-byte key, likely including alternate description in the key for ARCUP16).

  5. Customer-Specific Product Lookup (If PROD = 'P*'):

  6. Builds a search key (CPKEY or CPKEY1) using company, customer, and ship-to.
  7. For ARCUP16 (non-'BB101'): Appends S5A,15 (last alternate description from previous page, for paging/continuation) to the key (making it 41 bytes).
  8. For ARCUP36 ('BB101'): Key is 16 bytes (company+customer+ship-to, padded).
  9. Positions the file pointer (SETLL on ARCUP16 or ARCUP36).
  10. Calls the appropriate subroutine (BL1S5P or BL3S5P):
    • Clears arrays.
    • Reads forward (READ), skipping deleted records (CPDEL = 'D').
    • Filters for exact match on company, customer, and ship-to.
    • Skips duplicate products (using PRSAVE to track last product code).
    • For each valid record: Populates S5L (line 1-15), S5P (CPPROD), S5A (CPCPDS - customer alternate description).
    • Chains to GSPROD using company + product code (KLPROD) to fetch standard description (S5D = TPDESC) and fluid code (S5F = TPFLCD). If not found, indicator 60 is set (but not handled explicitly).
    • Stops at 15 records or end-of-file (indicator 38).
  11. Returns the populated arrays to the caller.

  12. Product Description Lookup (If PROD = 'D*'):

  13. Builds a 36-byte key (G6KEY) using company + description search string (from DESC or last S5D,15 for paging) + ' ' padding.
  14. Positions the file pointer (SETLL on GSPRD6).
  15. Calls the appropriate subroutine (BL1S5D or BL3S5D):
    • Clears arrays.
    • Reads forward (READ on GSPRD6), skipping deleted records (TBDEL = 'D').
    • Filters for exact company match and sellable products (TBSELL = 'Y').
    • For each valid record: Populates S5L (line 1-15), S5P (TBPROD), S5D (TBDESC - standard description), S5A (blank), S5F (TBFLCD - fluid code).
    • Stops at 15 records or end-of-file (indicator 38).
  16. Returns the populated arrays to the caller.

  17. Termination:

  18. Sets LR (last record) indicator on and exits, returning control to the caller with populated arrays.
  19. If no matching PROD mode ('P' or 'D'), or end-of-file reached early, arrays may remain blank/zero.

The program supports paging: When called again (e.g., for next/previous page in the caller), it uses the last array values (e.g., S5A,15 or S5D,15) to continue from where it left off via SETLL.

Business Rules

The program enforces business logic for product lookups, tailored for order entry or inquiry contexts:

  • Lookup Modes:
  • 'P*': Searches customer-specific products (from ARCUP16/36), prioritizing customer alternate descriptions (CPCPDS) if available. Supplements with standard description and fluid code from GSPROD.
  • 'D*': Searches all sellable products by partial description (from GSPRD6), using standard descriptions only (S5A blank).

  • Filtering and Validation:

  • Excludes deleted records (CPDEL/TBDEL = 'D').
  • For customer lookups: Must match exact company, customer, and ship-to. Skips duplicates (same product code as previous).
  • For description lookups: Must match company and be sellable (TBSELL = 'Y').
  • Limits results to 15 per call (for screen display).

  • Data Enrichment:

  • Always fetches fluid code (S5F = 'N' for non-fluid, etc.) from product files.
  • Uses customer alternate description (S5A) only in customer-specific mode; otherwise blank.

  • Program-Specific Handling:

  • For 'BB101' (order entry): Uses ARCUP36 with shorter key (no alternate desc in key).
  • For other programs (e.g., inquiries like BB850): Uses ARCUP16 with longer key (includes alternate desc for better indexing/searching).

  • Changes from Modifications:

  • VV04: Added fluid code (S5F) population.
  • JK01: Replaced GSTAB4 with GSPRD4 (but in code, it's GSPRD6); added company to GSPRD6 key (TBCONO).
  • JK02: Replaced GSTABL6 with GSPROD for product chaining (TPDESC/TPFLCD).

  • Error Handling:

  • No explicit errors; if chain fails (indicator 60), fields like S5D/S5F remain blank. End-of-file (38) stops processing early.

Tables Used

In RPG, "tables" refer to database files used for input. The program defines the following files (all input-only 'IF'):

  • ARCUP16: Customer product file (used when PROGRM ≠ 'BB101'; keyed externally, 41-byte key, for customer-specific lookups with alternate descriptions).
  • ARCUP36: Alternate customer product file (used when PROGRM = 'BB101'; keyed externally, 16-byte key, for customer-specific lookups).
  • GSPROD: Product master file (keyed, used for chaining to fetch standard description and fluid code in customer lookups; replaced GSTABL6 per JK02).
  • GSPRD6: Product file for description searches (keyed externally, 36-byte key, used in 'D*' mode; added per JK01).

GSTABL6 is commented out (old table replaced by GSPROD).

External Programs Called

  • None: This program does not call any external programs; it is a self-contained subroutine that performs reads and chains internally.