Skip to content

BI9413 RPG36

The provided RPG program, BI9413.rpg36.txt, is an RPG III program for IBM System/36 or AS/400, invoked by the BI941.ocl36 OCL program. Its primary purpose is to preprocess the customer sales agreement work file (BICUAG) by updating records with zero ending dates to a default date (123179, i.e., December 31, 1979) and filtering records based on user-specified criteria, such as brand name, product class, group, inventory group, and bill-to PO. The processed records are written to an output file (BICUAGO). Below, I’ll explain the process steps, business rules, tables used, and external programs called.


Process Steps of the BI9413 RPG Program

The program reads records from the BICUAG file, applies filtering logic based on user inputs, updates ending dates if necessary, and writes valid records to the BICUAGO file. Here’s a detailed breakdown of the process steps:

  1. File and Data Structure Definitions (Lines 0002–0037):
  2. Header (H) Specification:
    • 064: Likely a program option or parameter.
    • Program name: BI9413.
  3. File Specifications (F):
    • BICUAG: Primary input file (256 bytes, disk) containing customer agreement data.
    • GSCNTR1: Input file (512 bytes, indexed, 3-byte key, 5 access paths) for container data (replaced GSCNTR per comment).
    • GSPROD: Input file (512 bytes, indexed, 6-byte key, 8 access paths) for product data.
    • BICUAGO: Update file (256 bytes, indexed, 11-byte key, external key) for outputting processed records.
  4. Input Specifications (I):
    • BICUAG:
    • Fields: BACONO (company number), BACUST (customer number), BAPR01 (product code), BAENDT (end date, YMD), BAEND8 (end date, CYMD), BASEQN (sequence number), BACNTR (container code), BAPORD (bill-to PO), RECORD (entire 256-byte record).
    • GSCNTR1:
    • Fields: TCDEL (deletion flag), TCCNTR (container code), TCCNTA (alpha container code), TCDESC (description), TCDSCS (short description), TCDSCL (long description), TCCNTY (container type), TCFRTB (freight table code), TCDES2 (second description), TCCTRS (container source), TCIUM (IMS unit of measure).
    • GSPROD:
    • Fields: TPDEL (deletion flag), TPCONO (company number), TPPROD (product code), TPDESC (description), TPDES1 (complete description), TPDES2 (abbreviated description), TPPRCL (product class code), TPPRGP (product group code), TPINGP (inventory group code), and others (e.g., STCC code, price list group).
    • UDS (User Data Structure):
    • Fields: KYCO1 (company number), KYBRND (brand name), KYENDT (ending date), KYPORD (exclude PO pricing flag), KYCLCD (product class), KYGRCD (product group), KYIVGR (inventory group).
  5. Comment:

    • JK01 (02/24/16): Indicates a modification to use GSCNTR1 instead of GSCNTR for alpha key support.
  6. Calculation Specifications (C) (Lines 0013–0015):

  7. Initialization:
    • SETOF 509899 and SETOF 9896: Clear indicators 50, 98, 99, and 96 to reset program state.
  8. Processing Loop (for each BICUAG record, record format 01):
    • End Date Check:
    • If BAENDT (YMD end date) is zero:
      • Set indicator 50 to flag the record for date update.
    • Brand Name Filtering:
    • If KYBRND (brand name) is non-blank:
      • Chain BACNTR (container code) to GSCNTR1.
      • If not found (indicator 98 on), skip to END.
      • If TCDES2 (second description in GSCNTR1) does not match KYBRND, skip to END.
    • Bill-to PO Filtering:
    • If KYPORD is Y (exclude PO pricing):
      • If BAPORD (bill-to PO) is non-blank, skip to END.
    • End Date Validation:
    • If BAEND8 (CYMD end date) and KYENDT (user-specified end date) are non-zero:
      • Convert KYENDT to YMD format (KYYMD = KYENDT * 10000.01).
      • Set KYEND8 to century 20 plus KYYMD.
      • If BAEND8 is less than or equal to KYEND8, skip to END.
    • Product Validation:
    • Chain BACONO (company) and BAPR01 (product code) to GSPROD using KEY6.
    • If not found (indicator 96 on), proceed to checks; otherwise, use GSPROD data.
    • Product Class Check:
      • If KYCLCD is non-blank and does not match TPPRCL (product class in GSPROD), skip to END.
    • Product Group Check:
      • If KYGRCD is non-blank and does not match TPPRGP (product group in GSPROD), skip to END.
    • Inventory Group Check:
      • If KYIVGR is non-blank and does not match TPINGP (inventory group in GSPROD), skip to END.
    • Write to Output File:
    • Chain BACONO and BASEQN to BICUAGO using BAKEY (11-byte key) to check for existing records.
    • If not found (indicator 99 on), write the record to BICUAGO:
      • Write the entire RECORD (256 bytes).
      • If indicator 50 is on (zero end date), set BAENDT to 791231 (December 31, 1979) and BAEND8 to 20791231 (CYMD equivalent).
  9. End Processing:

    • Jump to END tag if any filtering condition fails.
    • Loop continues for the next BICUAG record.
  10. Output Specifications (O) (Lines 0016–0017):

  11. Output to BICUAGO:

    • Record format DADD (add record) is used when indicator 99 is on (record not found in BICUAGO).
    • Outputs the entire RECORD (256 bytes).
    • If indicator 50 is on, updates:
    • Position 70 (6 bytes) to 791231 (YMD end date).
    • Position 133 (8 bytes) to 20791231 (CYMD end date).
  12. Program Termination:

  13. The program ends after processing all BICUAG records, with valid records written to BICUAGO.

Business Rules

  1. Zero Ending Date Handling:
  2. Records with BAENDT (YMD end date) of 000000 are updated to 791231 (December 31, 1979).
  3. Corresponding BAEND8 (CYMD end date) is set to 20791231.

  4. Brand Name Filtering:

  5. If a brand name (KYBRND) is specified, only include records where the container code (BACNTR) exists in GSCNTR1 and its second description (TCDES2) matches KYBRND.

  6. Bill-to PO Filtering:

  7. If KYPORD is Y (exclude PO pricing), exclude records with a non-blank bill-to PO (BAPORD).

  8. End Date Filtering:

  9. If both BAEND8 (record end date) and KYENDT (user-specified end date) are non-zero, compare them:

    • Convert KYENDT to CYMD format (KYEND8) with century 20.
    • Exclude records where BAEND8 is less than or equal to KYEND8 (i.e., expired agreements).
  10. Product Filtering:

  11. Validate product code (BAPR01) against GSPROD using company number (BACONO).
  12. If product class (KYCLCD), product group (KYGRCD), or inventory group (KYIVGR) is specified, ensure they match TPPRCL, TPPRGP, or TPINGP in GSPROD, respectively.
  13. Exclude records that do not match specified product criteria.

  14. Output Record Writing:

  15. Only write records to BICUAGO if they pass all filtering conditions and do not already exist (based on BACONO and BASEQN).

Tables Used

The program uses the following files/tables: 1. BICUAG: - Primary input file containing customer agreement data. - Fields: BACONO (company), BACUST (customer), BAPR01 (product code), BAENDT (end date YMD), BAEND8 (end date CYMD), BASEQN (sequence number), BACNTR (container code), BAPORD (bill-to PO). 2. BICUAGO: - Output file for processed and filtered agreement records. - Same structure as BICUAG, with updates to BAENDT and BAEND8 for zero dates. 3. GSCNTR1: - Container file used to validate brand names. - Fields: TCDEL (deletion flag), TCCNTR (container code), TCCNTA (alpha container code), TCDES2 (second description for brand name). 4. GSPROD: - Product file used to validate product class, group, and inventory group. - Fields: TPDEL (deletion flag), TPCONO (company), TPPROD (product code), TPPRCL (product class), TPPRGP (product group), TPINGP (inventory group).


External Programs Called

  • None:
  • The BI9413 program does not call any external programs. It performs all processing internally, reading from BICUAG, GSCNTR1, and GSPROD, and writing to BICUAGO.

Summary

  • Process Steps:
  • Define input files (BICUAG, GSCNTR1, GSPROD) and output file (BICUAGO).
  • For each BICUAG record:
    • Check if BAENDT is zero and flag for date update (indicator 50).
    • Filter by brand name (KYBRND) using GSCNTR1.
    • Filter by bill-to PO (KYPORD and BAPORD).
    • Filter by end date (BAEND8 vs. KYENDT).
    • Validate product class (KYCLCD), group (KYGRCD), and inventory group (KYIVGR) using GSPROD.
    • Write valid records to BICUAGO, updating zero end dates to 791231/20791231.
  • Terminate after processing all records.

  • Business Rules:

  • Update zero end dates to 791231/20791231.
  • Filter records by brand name, bill-to PO, end date, product class, product group, and inventory group.
  • Only write non-duplicate records to BICUAGO.

  • Tables Used:

  • BICUAG, BICUAGO, GSCNTR1, GSPROD.

  • External Programs Called:

  • None.

This program serves as a preprocessing step to clean and filter customer agreement data before further sorting and reporting in the BI941 workflow.