Skip to content

BI941 RPG36

The provided RPG program, BI941.rpg36.txt, is an RPG III program for IBM System/36 or AS/400, invoked by the BI941.ocl36 OCL program. Its purpose is to generate a customer sales agreement list, producing a formatted report for printing and an Excel-compatible output. It processes data from the pre-processed customer sales agreement file (BICUAGXX) and uses reference data from other files to enrich the report with details like customer names, company names, product descriptions, and container information. Below, I’ll explain the process steps, business rules, tables used, and external programs called.


Process Steps of the BI941 RPG Program

The program reads records from BICUAGXX, retrieves additional data from reference files (ARCUST, BICONT, GSTABL, GSPROD, GSCNTR1), and generates a detailed report with customer sales agreement information, including product codes, pricing, and contract details. Here’s a detailed breakdown of the process steps:

  1. File and Data Structure Definitions (Lines 0002–0049):
  2. Header (H) Specification:
    • P064: Likely a program option or parameter.
    • Program name: BI941.
  3. File Specifications (F):
    • BICUAGXX: Primary input file (258 bytes, disk) containing pre-processed customer sales agreement data.
    • GSPROD: Input file (512 bytes, indexed, 6-byte key, 8 access paths) for product data.
    • BICONT: Input file (256 bytes, indexed, 2-byte key, 2 access paths) for company data.
    • ARCUST: Input file (384 bytes, indexed, 8-byte key, 2 access paths) for customer data.
    • GSTABL: Input file (256 bytes, indexed, 12-byte key, 2 access paths) for general system table data.
    • GSCNTR1: Input file (512 bytes, indexed, 3-byte key, 5 access paths) for container data (replaced GSTABL type CNTRCD per comment JK01).
    • PRINTER: Output file (164 bytes) for printed report.
    • PRTEXCEL: Output file (225 bytes) for Excel-compatible report.
  4. Array Definitions (E):
    • SEP: Array (8 elements, 2 characters) for separators in the report.
    • BAP: Array (10 elements, 4 characters) for product codes (e.g., BAPR01 to BAPR10).
    • BAD: Array (10 elements, 10 characters) for product descriptions.
  5. Input Specifications (I):
    • BICUAGXX (record format 01):
    • Fields: BADEL (deletion flag), BACONOL3 (company number), BASLSML3 (salesman number), BACUSTL2 (customer number), BALOC (location), BAPR01BAPR10 (product codes 1–10), BASTDT (start date, CYMD), BASTTM (start time), BAENDT (end date, CYMD), BAENTM (end time), BAPRCE (price, packed), BAOFFP (off-price, packed), BAMNGL (minimum gallons/month), BAMXGL (maximum gallons/month), BAPPD (prepaid sale flag), BAALSH (apply to all ship-to flag), BAPRIM (pricing method), BACNTRL1 (container code), BAUNMSL1 (unit of measure), BAPORDL1 (bill-to PO), BASHIP (ship-to number), BACNT# (contract number), BASEQN (sequence number).
    • ARCUST:
    • Fields: ARNAME (customer name, 30 characters), ARNM20 (customer name, 20 characters).
    • BICONT:
    • Field: BCNAME (company name, 30 characters).
    • GSTABL:
    • Fields: TBDESC (table description), TBDES2 (alternate description), TBPRGP (product group code), TBPRCL (product class code), TBABDS (short description).
    • 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.
  6. Comments:

    • VV01: Changed comparison from *BLANK to *BLANKS for consistency.
    • JB02 (09/2012): Added unit of measure and bill-to PO fields.
    • JK01 (02/26/2016): Replaced GSTABL type CNTRCD with GSCNTR1.
    • JK02 (01/31/2023): Replaced GSTABL type PRODCD with GSPROD.
  7. Calculation Specifications (C) (Truncated):

  8. The truncated code likely includes logic for:

    • Reading BICUAGXX records.
    • Chaining to ARCUST, BICONT, GSTABL, and GSPROD to retrieve customer names, company names, product descriptions, and other reference data.
    • Processing product codes (BAPR01BAPR10) to fetch descriptions from GSPROD or GSTABL.
    • Handling date formatting (e.g., BASTDT, BAENDT) and flags like BAPPD, BAALSH, BAPRIM.
    • Controlling report output based on level breaks (e.g., L1, L2, L3) for company, customer, or salesman grouping.
    • Setting indicators (e.g., 37, 60) to manage output formatting (e.g., suppressing end date if NEVER).
  9. Output Specifications (O) (Lines 0087–0193, partial):

  10. Output to PRINTER:
    • Detail Lines (D 1, D 2):
    • Controlled by level indicators (L1, L2, L3) and indicator 37 (likely for specific conditions).
    • Outputs headers for company (BCNAME), customer (BACUSTZ, ARNAME), and sales agreement details (e.g., BALOC, BAP,1BAP,10, BAD,1BAD,10, STDT, BASTTM, ENDT, BAENTM, BAALSH, BASHIP, BAPRCEJ, BAOFFPJ, BAPRIM, BAMNGLJ, BAMXGLJ, BAPPD, BACNT#, BACNTR, BAUNMS, BAPORD).
    • Includes labels like PRODUCT, DATE, TIME, PRICE, MINIMUM GALLONS, MAXIMUM GALLONS, CONTRACT.
    • Handles special cases:
      • If indicator 60 is on, outputs NEVER for end date (ENDT) instead of a formatted date.
      • Outputs up to 10 product codes and descriptions (BAP, BAD).
    • Separator Lines:
    • Outputs SEP array elements for formatting (e.g., dashed lines).
  11. Output to PRTEXCEL:

    • Detail Lines (D 1, D 101):
    • Outputs Excel-compatible data with headers for company (BCNAME), salesman description (SLSDSC), and report metadata (* CUSTOMER SALES AGREEMENTS SPREADSHEET*, system date SYSDATY, time SYSTIM).
    • Includes filtering criteria: KYBRND (brand), KYCLCD/CLDESC (product class), KYGRCD/GRDESC (product group), KYIVGR/IVDESC (inventory group).
    • Outputs agreement details similar to PRINTER but formatted for Excel (e.g., BALOC, BAP, PRDDS1, STDT, BASTTM, ENDT, BAENTM, BAALSH, BASHIP, BAPRCEJ, BAOFFPJ, BAMNGLJ, BAMXGLJ, BAPPD, BACUSTZ, ARNM20, BACNTR, BAUNMS, CLSDSC).
  12. Program Termination:

  13. The program ends after processing all BICUAGXX records, producing both printed and Excel reports.

Business Rules

  1. Report Content:
  2. Generates a customer sales agreement list including:

    • Company (BACONOL3, BCNAME).
    • Customer (BACUSTL2, ARNAME, ARNM20).
    • Salesman (BASLSML3, with description from GSTABL).
    • Location (BALOC).
    • Up to 10 product codes (BAPR01BAPR10) with descriptions from GSPROD (PRDDS1) or GSTABL (TBDESC).
    • Start date/time (BASTDT, BASTTM), end date/time (BAENDT, BAENTM), with NEVER for no end date.
    • Pricing details (BAPRCE, BAOFFP, BAPRIM), gallons (BAMNGL, BAMXGL), prepaid flag (BAPPD), apply-to-all-ship-to flag (BAALSH).
    • Container code (BACNTR), unit of measure (BAUNMS), bill-to PO (BAPORD), ship-to number (BASHIP), contract number (BACNT#), sequence number (BASEQN).
  3. Filtering and Sorting:

  4. Uses pre-sorted data from BICUAGXX (sorted by #GSORT in BI941.ocl36 based on salesman or customer).
  5. Includes user-specified filters (from BI941P): brand (KYBRND), product class (KYCLCD), product group (KYGRCD), inventory group (KYIVGR).

  6. Data Enrichment:

  7. Retrieves customer names from ARCUST.
  8. Retrieves company names from BICONT.
  9. Retrieves product descriptions from GSPROD (TPDES1) or GSTABL (TBDESC).
  10. Retrieves container descriptions from GSCNTR1.

  11. Output Formats:

  12. Printed Report (PRINTER):
    • Structured with headers, detail lines, and separators.
    • Groups by company (L1), customer (L2), or salesman (L3).
    • Includes conditional formatting (e.g., NEVER for end date, product descriptions).
  13. Excel Report (PRTEXCEL):

    • Includes metadata (date, time, filters) and agreement details in a spreadsheet-compatible format.
    • Outputs additional fields like product class description (CLSDSC).
  14. Data Integrity:

  15. Skips deleted records (BADEL = 'D').
  16. Ensures valid references by chaining to ARCUST, BICONT, GSTABL, GSPROD, and GSCNTR1.

Tables Used

The program uses the following files/tables: 1. BICUAGXX: - Primary input file with pre-processed customer sales agreement data. - Fields: BADEL, BACONOL3, BASLSML3, BACUSTL2, BALOC, BAPR01BAPR10, BASTDT, BASTTM, BAENDT, BAENTM, BAPRCE, BAOFFP, BAMNGL, BAMXGL, BAPPD, BAALSH, BAPRIM, BACNTRL1, BAUNMSL1, BAPORDL1, BASHIP, BACNT#, BASEQN. 2. GSPROD: - Product file for product descriptions and attributes. - Fields: TPDEL, TPCONO, TPPROD, TPDESC, TPDES1, TPDES2, TPPRCL, TPPRGP, TPINGP. 3. BICONT: - Company control file for company names. - Field: BCNAME. 4. ARCUST: - Customer master file for customer names. - Fields: ARNAME, ARNM20. 5. GSTABL: - General system table for salesman, product class, group, and other reference data. - Fields: TBDESC, TBDES2, TBPRGP, TBPRCL, TBABDS. 6. GSCNTR1: - Container file for container descriptions. - Used to replace GSTABL type CNTRCD (per JK01).


External Programs Called

  • None:
  • The BI941 program does not call any external programs. It performs all processing internally, reading from input files and writing to PRINTER and PRTEXCEL.

Summary

  • Process Steps:
  • Define input files (BICUAGXX, GSPROD, BICONT, ARCUST, GSTABL, GSCNTR1) and output files (PRINTER, PRTEXCEL).
  • Read BICUAGXX records and retrieve reference data (customer names, company names, product/container descriptions).
  • Generate printed report (PRINTER) with headers, detail lines, and separators, grouped by company/customer/salesman.
  • Generate Excel-compatible report (PRTEXCEL) with metadata and agreement details.
  • Terminate after processing all records.

  • Business Rules:

  • Produce a detailed customer sales agreement list with company, customer, product, pricing, and contract details.
  • Enrich data with customer names (ARCUST), company names (BICONT), product descriptions (GSPROD, GSTABL), and container data (GSCNTR1).
  • Support filtering by brand, product class, group, and inventory group.
  • Format output for both printed and Excel reports, handling special cases like NEVER for end dates.

  • Tables Used:

  • BICUAGXX, GSPROD, BICONT, ARCUST, GSTABL, GSCNTR1.

  • External Programs Called:

  • None.

This program is the final step in the BI941 workflow, producing a comprehensive report of customer sales agreements based on pre-processed and sorted data.