Skip to content

BI941A RPG36

The provided RPG program, BI941A.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 identify and report duplicate current customer sales agreements by processing records from the BICUAGXX file, checking for active agreements based on the current date, and outputting results to the BI941O file and a printed report. Below, I’ll explain the process steps, business rules, tables used, and external programs called.


Process Steps of the BI941A RPG Program

The program reads customer sales agreement records from BICUAGXX, checks if they are active based on the current date, and identifies duplicates by writing records to BI941O and flagging those that already exist. It also generates a printed report for duplicate agreements. Here’s a detailed breakdown of the process steps:

  1. File and Data Structure Definitions (Lines 0002–0040):
  2. Header (H) Specification:
    • P064: Likely a program option or parameter.
    • Program name: BI941A.
  3. File Specifications (F):
    • BICUAGXX: Primary input file (258 bytes, disk) containing pre-processed customer sales agreement data.
    • BI941O: Update file (100 bytes, indexed, 21-byte key, 1 access path) for storing processed agreement records.
    • PRINTER: Output file (132 bytes) for the printed report.
  4. Input Specifications (I):
    • BICUAGXX (record format 01):
    • Fields: BADEL (deletion flag), BACONO (company number), BACUST (customer number), BALOC (location), BAPR01BAPR10 (product codes 1–10), BASTDT (start date, CYMD), BASTTM (start time, HM), BAENDT (end date, CYMD), BAENTM (end time, HM), 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, I/M for invoice/EOM), BASTD8 (start date, CYMD), BAEND8 (end date, CYMD), BACNTR (container code), BASHIP (ship-to number), BACNT# (contract number).
    • Keys: KEY1 (company + product code 1, positions 2–16), KEY2 (container code + ship-to, positions 164–169).
    • BI941O (record format 02):
    • No specific fields defined in the input specs, as it’s primarily an output file.
  5. Comment:

    • JB040700:ADD: Indicates an addition related to product codes (BAP array).
  6. Calculation Specifications (C) (Lines 0085–0134):

  7. Date Calculation:
    • UDATE * 10000.01KYDAT6: Converts the system date (UDATE) to a 6-digit format (likely YYMMDD).
    • Z-ADD KYDAT6 KYDAT8: Stores the 6-digit date in KYDAT8 (8-digit field).
    • MOVEL 20 KYDAT8: Prepends century 20 to KYDAT8, creating an 8-digit CYMD date (e.g., 20YYMMDD).
  8. Processing Loop (for each BICUAGXX record, record format 01):

    • Clear Indicator:
    • SETOF 99: Clears indicator 99 (used for BI941O chaining).
    • Build Key for BI941O:
    • MOVEL KEY1 KEY21: Copies KEY1 (company + product code 1) to KEY21 (21-byte key).
    • MOVE KEY2 KEY21: Appends KEY2 (container code + ship-to) to KEY21.
    • Check for Duplicate:
    • Chain KEY21 to BI941O.
    • If a record exists (indicator 99 off), it’s a duplicate; execute the FILE exception output to BI941O.
    • Check if Agreement is Current:
    • If no duplicate (indicator 99 on):
      • Check if KYDAT8 (current date) is greater than or equal to BASTD8 (start date) and less than or equal to BAEND8 (end date).
      • If true (agreement is current), execute the PRINT exception output to PRINTER.
    • End of Conditions:
    • Continue processing the next BICUAGXX record.
  9. Output Specifications (O) (Lines 0086–0181):

  10. Output to BI941O (Exception FILE):
    • Triggered when a duplicate is found (indicator 99 off).
    • Writes: BACONO (company, position 2), BACUST (customer, position 8), BALOC (location, position 11), BAPR01 (product code 1, position 15), BACNTR (container code, position 18), BASHIP (ship-to, position 21), BASTDT (start date, position 28), BASTTM (start time, position 32), BAENDT (end date, position 39), BAENTM (end time, position 43), BAPRCE (price, position 53).
  11. Output to PRINTER (Exception PRINT):

    • Triggered for current agreements (indicator 99 on, KYDAT8 within BASTD8 and BAEND8).
    • Writes: KEY1 (company + product code 1, position 20), KEY2 (container code + ship-to, position 35), BASTD8 (start date, formatted as MM/DD/YYYY, position 50), BAEND8 (end date, formatted as MM/DD/YYYY, position 65).
  12. Program Termination:

  13. The program ends after processing all BICUAGXX records, producing the BI941O file with all processed records and a printed report of current duplicate agreements.

Business Rules

  1. Duplicate Detection:
  2. A record is considered a duplicate if a matching record exists in BI941O based on the key KEY21 (company number + product code 1 + container code + ship-to number).
  3. Duplicate records are written to BI941O using the FILE exception output.

  4. Current Agreement Check:

  5. An agreement is considered current if the current date (KYDAT8, derived from UDATE) falls between the agreement’s start date (BASTD8) and end date (BAEND8).
  6. Only current agreements are printed in the report (PRINTER).

  7. Data Integrity:

  8. Skips deleted records (BADEL = 'D').
  9. Assumes BICUAGXX records are pre-processed (e.g., by BI9413) with valid date formats (BASTD8, BAEND8).
  10. Uses a composite key (KEY1 + KEY2) to uniquely identify agreements for duplicate checking.

  11. Output Content:

  12. BI941O: Stores agreement details for all processed records (duplicate or not), including company, customer, location, product code, container code, ship-to, dates, times, and price.
  13. PRINTER: Reports current duplicate agreements with company, product code, container code, ship-to, and start/end dates in a formatted layout.

  14. Date Handling:

  15. Converts the system date (UDATE) to an 8-digit CYMD format (20YYMMDD) for comparison with agreement dates.

Tables Used

The program uses the following files/tables: 1. BICUAGXX: - Primary input file with pre-processed customer sales agreement data. - Fields: BADEL, BACONO, BACUST, BALOC, BAPR01BAPR10, BASTDT, BASTTM, BAENDT, BAENTM, BAPRCE, BAOFFP, BAMNGL, BAMXGL, BAPPD, BAALSH, BAPRIM, BASTD8, BAEND8, BACNTR, BASHIP, BACNT#. - Keys: KEY1 (company + product code 1), KEY2 (container code + ship-to). 2. BI941O: - Update file for storing processed agreement records, including duplicates. - Fields: BACONO, BACUST, BALOC, BAPR01, BACNTR, BASHIP, BASTDT, BASTTM, BAENDT, BAENTM, BAPRCE.


External Programs Called

  • None:
  • The BI941A program does not call any external programs. It performs all processing internally, reading from BICUAGXX, updating BI941O, and writing to PRINTER.

Summary

  • Process Steps:
  • Define input file BICUAGXX, update file BI941O, and output file PRINTER.
  • Calculate the current date in CYMD format (KYDAT8).
  • For each BICUAGXX record:
    • Build a key (KEY21) from company, product code 1, container code, and ship-to.
    • Chain to BI941O to check for duplicates.
    • If a duplicate is found, write to BI941O.
    • If no duplicate and the agreement is current (KYDAT8 between BASTD8 and BAEND8), print to PRINTER.
  • Terminate after processing all records.

  • Business Rules:

  • Identify duplicate agreements based on company, product code 1, container code, and ship-to.
  • Report only current agreements (based on the current date) in the printed output.
  • Store all processed records in BI941O, including duplicates.

  • Tables Used:

  • BICUAGXX, BI941O.

  • External Programs Called:

  • None.

This program serves as an optional utility in the BI941 workflow to detect and report duplicate current customer sales agreements, ensuring data integrity by flagging potential issues. Note that the OCL program (BI941.ocl36) warns against running BI941A unless its key references are updated, indicating potential compatibility issues.