Skip to content

BB9531 RPG36

The provided document, BB9531.rpg36.txt, is an RPG (Report Program Generator) program written for an IBM System/36 or AS/400 environment. It is called by the OCL program BB953.ocl36.txt and serves as a preprocessing step for generating a rack price list. The program processes records from the rack price master file (BBPRCE), validates them against user-specified criteria, and writes selected records to a temporary output file (BB9531) for further processing. Below, I will explain the process steps, business rules, tables (files) used, and any external programs called.


Process Steps of the RPG Program

The BB9531 RPG program preprocesses data from the rack price master file (BBPRCE) to create a temporary file (BB9531) that contains filtered and enriched records for the rack price list. It validates records based on company, date range, and division, and retrieves product descriptions from the GSPROD file (replacing GSTABL per modification JK01). Here’s a detailed breakdown of the process steps:

  1. Header and File Definitions:
  2. H-Spec: The header specification (H P064) identifies the program as BB9531 with a program identifier P064.
  3. File Definitions (F-Specs):
    • BBPRCE: Primary input file (128 bytes, indexed with 27 keys, disk-based), containing rack price data.
    • GSTABL: Input file (256 bytes, indexed with 12 keys), originally used for product lookups but replaced by GSPROD for product codes per JK01.
    • GSPROD: Input file (512 bytes, indexed with 6 keys), added per JK01 for product data lookups.
    • BB9531: Output file (169 bytes, disk-based), used to store processed records for the rack price list.
  4. Array Definitions (E-Specs):
    • RKPR: Array of 5 elements (9 bytes, 4 decimals) for rack prices.
    • RKQT: Array of 5 elements (7 bytes, 0 decimals) for quantity levels.
    • HLPR: Array of 5 elements (9 bytes, 4 decimals) for holding current rack prices.
    • HLQT: Array of 5 elements (7 bytes, 0 decimals) for holding current quantity levels.
    • PRPR: Array of 5 elements (9 bytes, 4 decimals) for previous prices (not used in output but defined).
  5. Input Specifications (I-Specs):

    • BBPRCE: Defines fields like RKDEL (delete flag), RKCONO (company), RKLOC (location), RKPROD (product code), RKCNTR (container), RKUNMS (unit of measure), RKDATE (date, CYMD format), RKTIME (time, HHMM), RKPR,1-5 (rack prices), RKQT (quantity levels), RKRKRQ (rack required flag, added per JB03), and RKINAC (inactive flag, added per JB03).
    • GSTABL: Defines fields like TBDEL (delete flag), TBTYPE (table type), TBCODE (table code), TBPROD (product code), TBDESC (description), TBPRCL (product class code), TBABDS (short description), and TBCSRT (inventory company sort).
    • GSPROD: Defines fields like TPDEL (delete flag), TPDESC (description), TPDES1 (complete description), TPPRGP (product group code), TPPRCL (product class code), TPABDS (short description), and TPFLCD (added per JK01).
    • Data Structures (DS): Define PRCEKY (price key), CUPROD, CUCNTR, CUUNMS, XXULO, XXCYMD, XXHHMM, $CYMD, $CN, $YMD for date and key manipulations.
    • User Data Structure (UDS): Defines fields like KYCO (company prompt), KYDIV (division), KYDTSL (date selection), KYFRDT (from date), KYTODT (to date), KYDVNO (division number), Y2KCEN (century, 19), and Y2KCMP (comparison year, 80).
  6. Initialization and Date Processing (Lines 0053-0287):

  7. Indicator 09 Check:

    • If indicator 09 is off (initial run), the program calculates date-related variables:
    • Today’s Date:
      • Computes KYDAT8 (8-digit date, CCYYMMDD) using UDATE (system date) and Y2KCEN (century, 19 or 20 based on UYEAR vs. Y2KCMP).
    • Date 30 Days Ago:
      • Converts KYDAT8 to $CYMD and extracts $YMD (YYMMDD).
      • Calls @GTOJ subroutine to convert to Julian date (G$JD).
      • Subtracts 31 days (SUB 31 G$JD).
      • Calls @JTOG subroutine to convert back to Gregorian date ($MDY).
      • Stores result in DT3AGO (8-digit date, CCYYMMDD).
    • Date Range Validation:
      • If KYDTSL is not 'ALL' (specific date range selected):
      • Converts KYFRDT and KYTODT to FRDYMD and TODYMD (6-digit YYMMDD).
      • Adjusts for century: if year > 80, uses 1900s (FRDAT8, TODAT8 start with 19); otherwise, uses 2000s (20).
    • Sets indicator 09 to prevent reprocessing date calculations.
  8. Record Filtering (Lines 0054-0062):

  9. Deleted Records:
    • If RKDEL = 'D' (delete flag), skips the record by jumping to END (line 0056).
  10. Company Validation:

    • If RKCONO (company number) does not match KYCO (user-specified company), skips the record by jumping to END (line 0061).
  11. Date Range Filtering (Lines 0059-0062):

  12. If KYDTSL = 'ALL':
    • Proceeds to NEXT tag, processing all records regardless of date.
  13. If KYDTSL is not 'ALL':

    • Compares RKDATE (record date, CYMD) to FRDAT8 (from date) and TODAT8 (to date).
    • If RKDATE < FRDAT8 or RKDATE > TODAT8, sets WRITIT = 'N' (do not write) and jumps to END.
    • Otherwise, proceeds to processing.
  14. Main Processing Loop (Lines 0065-0101):

  15. Initialization:
    • Clears arrays HLQT (quantity), HLPR (price), and fields HLRKRQ (rack required), HLINAC (inactive), PRPR (previous price), and WRITIT (write flag, set to blank).
  16. Product Description Lookup:
    • Builds a key (TBLKY6/KLPROD) using RKCONO (company) and RKPROD (product code).
    • Chains to GSPROD (replacing GSTABL per JK01) using KLPROD to retrieve product data (indicator 92).
    • If not found (92 on), clears description fields (TPDES1, TPABDS, TPPRGP, DES1CP, ABDSCP).
    • If found (N92), moves TPDES1 to DES1CP (complete description, 20 bytes) and TPABDS to ABDSCP (short description, 10 bytes).
  17. Product Class Lookup:
    • If product found (N65), retrieves TPPRCL (product class code) and chains to GSTABL using PRCLKY (built from RKCONO and TPPRCL) to get TBCSRT (inventory company sort, stored as DIV).
    • If product class not found (65 on), DIV remains unchanged.
  18. Division Validation (per JB04):
    • If KYDIV ≠ 'B' (not both divisions), compares DIV (from TBCSRT) to KYDVNO (division number from user input).
    • If they don’t match, sets WRITIT = 'N' and jumps to END.
  19. Price and Quantity Comparison:

    • Compares current record’s prices (RKPR,1-5), quantities (RKQT), rack required (RKRKRQ), and inactive (RKINAC) flags to previous values (HLPR, HLQT, HLRKRQ, HLINAC).
    • If any differ (indicator 10 on), updates hold arrays (HLPR, HLQT, HLRKRQ, HLINAC) with current values.
    • Sets WRITIT = 'Y' to indicate the record should be written.
  20. Write Output (Lines 0106-0108):

  21. If WRITIT = 'Y' and level L1 (primary input cycle), writes a record to BB9531 using the ADD951 exception output.
  22. Fields written include:

    • RKCONO (company, pos 1-2)
    • RKLOC (location, pos 3-5)
    • TPPRGP (product group code, pos 6-7, per JK01)
    • RKPROD (product code, pos 8-11)
    • RKCNTR (container, pos 12-14)
    • RKUNMS (unit of measure, pos 15-17)
    • HLQT (quantity levels, pos 18-52)
    • HLPR (prices, pos 53-82, packed)
    • PRPR (previous prices, pos 83-112, packed, unused)
    • DES1CP (complete description, pos 113-132)
    • ABDSCP (short description, pos 133-142)
    • RKDATE (date, pos 143-150)
    • RKTIME (time, pos 151-154)
    • RKMINQ (minimum quantity, pos 155-161)
    • DIV (division from TBCSRT, pos 162-164)
    • PRCL (product class code, pos 165-167)
    • HLRKRQ (rack required, pos 168, per JB03)
    • HLINAC (inactive flag, pos 169, per JB03)
  23. Date Conversion Subroutines:

  24. @GTOJ (Lines 0320-0384):
    • Converts Gregorian date ($MDY, YYMMDD) to Julian date (G$JD).
    • Handles century calculation using Y2KCEN and UYEAR.
    • Computes Julian days based on year, month, and day, accounting for leap years.
    • Determines the day of the week (G$JW).
  25. @JTOG (Lines 0388-0438):

    • Converts Julian date (G$JD) back to Gregorian date ($MDY, YYMMDD).
    • Calculates year, month, and day, adjusting for century and leap years.
  26. Termination:

  27. The program ends at the END tag (line 0102) after processing each input record or skipping invalid ones.

Business Rules

The BB9531 program enforces the following business rules for preprocessing the rack price list:

  1. Record Deletion:
  2. Skips records marked as deleted (RKDEL = 'D').

  3. Company Selection:

  4. Processes only records where the company number (RKCONO) matches the user-specified company (KYCO).

  5. Date Range Filtering:

  6. If KYDTSL = 'ALL', includes all records regardless of date.
  7. If KYDTSL ≠ 'ALL', includes only records where RKDATE (CYMD format) falls between FRDAT8 (from date) and TODAT8 (to date).
  8. Converts user-specified dates (KYFRDT, KYTODT) to 8-digit CCYYMMDD format, handling century (19xx or 20xx) based on year comparison with Y2KCMP (80).

  9. Division Validation:

  10. If KYDIV ≠ 'B' (not both divisions), ensures the record’s division (DIV, derived from TBCSRT in GSTABL) matches the user-specified division number (KYDVNO).
  11. Records with mismatched divisions are excluded (WRITIT = 'N').

  12. Product Lookup:

  13. Retrieves product details from GSPROD (replacing GSTABL per JK01) using a key built from RKCONO and RKPROD.
  14. If not found, clears description fields (DES1CP, ABDSCP, TPPRGP).
  15. If found, populates DES1CP (complete description), ABDSCP (short description), and TPPRCL (product class code).

  16. Product Class Lookup:

  17. If product found, uses TPPRCL to chain to GSTABL for product class details, retrieving TBCSRT (division sort code) into DIV.
  18. If product class not found, no division is set, but processing continues.

  19. Price and Quantity Tracking:

  20. Compares current record’s prices (RKPR,1-5), quantities (RKQT), rack required (RKRKRQ), and inactive (RKINAC) flags to previous values (HLPR, HLQT, HLRKRQ, HLINAC).
  21. If any differ, updates the hold arrays and sets WRITIT = 'Y' to write the record.

  22. Output Record:

  23. Writes records to BB9531 only if WRITIT = 'Y', including company, location, product group, product code, container, unit of measure, quantities, prices, descriptions, date, time, minimum quantity, division, product class, and rack/inactive flags.

  24. Date Handling:

  25. Calculates today’s date (KYDAT8) and a date 30 days prior (DT3AGO) for potential filtering.
  26. Handles century transitions for date conversions (1900s vs. 2000s).

Tables (Files) Used

The RPG program uses the following files (tables): 1. BBPRCE: Primary input file containing rack price data (e.g., RKCONO, RKLOC, RKPROD, RKCNTR, RKUNMS, RKDATE, RKTIME, RKPR, RKQT, RKRKRQ, RKINAC). 2. GSTABL: Input file for product class lookups (e.g., TBPRCL, TBCSRT), used to retrieve division sort code. 3. GSPROD: Input file for product lookups (e.g., TPDES1, TPABDS, TPPRGP, TPPRCL, TPFLCD), added per JK01 to replace GSTABL for product codes. 4. BB9531: Output file containing processed records for the rack price list (169 bytes, including fields like RKCONO, RKLOC, TPPRGP, RKPROD, DES1CP, ABDSCP, etc.).


External Programs Called

No external programs are explicitly called within the BB9531 RPG program. It operates independently, processing input from BBPRCE, performing lookups in GSTABL and GSPROD, and writing to BB9531. The program is invoked by the OCL program BB953.ocl36.txt, and its output is used by subsequent programs (BB9534, #GSORT, BB953).


Summary

The BB9531 RPG program preprocesses rack price data by: - Calculating date ranges and handling century transitions. - Filtering BBPRCE records based on company (KYCO), deletion status (RKDEL), date range (KYDTSL, KYFRDT, KYTODT), and division (KYDIV, KYDVNO). - Retrieving product descriptions and product class data from GSPROD and GSTABL. - Comparing prices, quantities, and flags to track changes and decide which records to write. - Writing valid records to BB9531 with enriched data for further processing.

Tables (Files) Used: - BBPRCE - GSTABL - GSPROD - BB9531

External Programs Called: - None

This program ensures that only relevant, validated records are included in the temporary file BB9531, setting the stage for subsequent sorting and report generation in the rack price list workflow.