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:
- File and Data Structure Definitions (Lines 0002–0040):
- Header (H) Specification:
P064
: Likely a program option or parameter.- Program name:
BI941A
.
- 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.
- Input Specifications (I):
BICUAGXX
(record format01
):- Fields:
BADEL
(deletion flag),BACONO
(company number),BACUST
(customer number),BALOC
(location),BAPR01
–BAPR10
(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 format02
):- No specific fields defined in the input specs, as it’s primarily an output file.
-
Comment:
JB040700:ADD
: Indicates an addition related to product codes (BAP
array).
-
Calculation Specifications (C) (Lines 0085–0134):
- Date Calculation:
UDATE * 10000.01
→KYDAT6
: Converts the system date (UDATE
) to a 6-digit format (likely YYMMDD).Z-ADD KYDAT6 KYDAT8
: Stores the 6-digit date inKYDAT8
(8-digit field).MOVEL 20 KYDAT8
: Prepends century20
toKYDAT8
, creating an 8-digit CYMD date (e.g.,20YYMMDD
).
-
Processing Loop (for each
BICUAGXX
record, record format01
):- Clear Indicator:
SETOF 99
: Clears indicator 99 (used forBI941O
chaining).- Build Key for
BI941O
: MOVEL KEY1 KEY21
: CopiesKEY1
(company + product code 1) toKEY21
(21-byte key).MOVE KEY2 KEY21
: AppendsKEY2
(container code + ship-to) toKEY21
.- Check for Duplicate:
- Chain
KEY21
toBI941O
. - If a record exists (indicator 99 off), it’s a duplicate; execute the
FILE
exception output toBI941O
. - Check if Agreement is Current:
- If no duplicate (indicator 99 on):
- Check if
KYDAT8
(current date) is greater than or equal toBASTD8
(start date) and less than or equal toBAEND8
(end date). - If true (agreement is current), execute the
PRINT
exception output toPRINTER
.
- Check if
- End of Conditions:
- Continue processing the next
BICUAGXX
record.
-
Output Specifications (O) (Lines 0086–0181):
- Output to
BI941O
(ExceptionFILE
):- 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).
-
Output to
PRINTER
(ExceptionPRINT
):- Triggered for current agreements (indicator 99 on,
KYDAT8
withinBASTD8
andBAEND8
). - 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).
- Triggered for current agreements (indicator 99 on,
-
Program Termination:
- The program ends after processing all
BICUAGXX
records, producing theBI941O
file with all processed records and a printed report of current duplicate agreements.
Business Rules¶
- Duplicate Detection:
- A record is considered a duplicate if a matching record exists in
BI941O
based on the keyKEY21
(company number + product code 1 + container code + ship-to number). -
Duplicate records are written to
BI941O
using theFILE
exception output. -
Current Agreement Check:
- An agreement is considered current if the current date (
KYDAT8
, derived fromUDATE
) falls between the agreement’s start date (BASTD8
) and end date (BAEND8
). -
Only current agreements are printed in the report (
PRINTER
). -
Data Integrity:
- Skips deleted records (
BADEL = 'D'
). - Assumes
BICUAGXX
records are pre-processed (e.g., byBI9413
) with valid date formats (BASTD8
,BAEND8
). -
Uses a composite key (
KEY1
+KEY2
) to uniquely identify agreements for duplicate checking. -
Output Content:
- 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.
-
PRINTER: Reports current duplicate agreements with company, product code, container code, ship-to, and start/end dates in a formatted layout.
-
Date Handling:
- 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
, BAPR01
–BAPR10
, 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 fromBICUAGXX
, updatingBI941O
, and writing toPRINTER
.
Summary¶
- Process Steps:
- Define input file
BICUAGXX
, update fileBI941O
, and output filePRINTER
. - 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
betweenBASTD8
andBAEND8
), print toPRINTER
.
- Build a key (
-
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.