BI941P RPG36
The provided RPG program, BI941P.rpg36.txt
, is an RPG III program (likely for IBM System/36 or AS/400) that generates a customer sales agreement list based on user input and validation. It is called from the BI941P.ocl36
OCL program previously analyzed. Below, I’ll explain the process steps, business rules, tables used, and external programs called.
Process Steps of the BI941P RPG Program¶
The RPG program processes user input from a workstation screen, validates it against files and tables, and prepares data for a customer sales agreement report. Here’s a detailed breakdown of the process steps:
- File and Data Structure Definitions (Lines 0002–0039):
- Header (H) Specification:
P064
: Likely a program parameter or option.- Program name:
BI941P
.
- File Specifications (F):
SCREEN
: A workstation file (512 bytes) for interactive user input/output.GSTABL
: An input chained file (256 bytes, indexed, 12-byte key) on disk, likely a general system table for reference data.BICONT
: An input file (256 bytes, indexed, 2-byte key) on disk, likely a control file for company data.
- Array and Data Definitions (E):
DCO
: Array (35 elements) for storing company data.CS
: Array (10 elements, 6 digits) for customer numbers.COM
: Array (14 elements, 40 characters) for error messages.
-
Input Specifications (I):
- Defines fields for the
SCREEN
,BICONT
, andGSTABL
files, including keys likeKYALCO
,KYCO1
,KYALCS
,CS
,KYALCN
,KYSORT
,KYLOC
,KYPROD
,KYALSL
,KYFRSL
,KYBRND
,KYENDT
,KYEXPO
,KYCLCD
,KYGRCD
,KYIVGR
, etc. UDS
(User Data Structure) defines additional fields for validation and display, such asCLDESC
,GRDESC
,IVDESC
(descriptions for product class, group, and inventory group).Y2KCEN
andY2KCMP
: Fields for Year 2000 date handling (e.g., century and comparison year).
- Defines fields for the
-
Initialization and Control Logic (Lines 0040–0058):
- Clear Indicators and Variables:
SETOF
: Clears indicators (31–45, 81, 90) to reset program state.MOVEL*BLANKS MSG
: Clears the message field.
- Key Press Handling:
- If the
KG
indicator (likely a function key, e.g., F3) is set: - Set
U1
(update) andLR
(last record) indicators and go toEND
(terminates program).
- If the
-
Subroutine Execution:
- If record format
01
(screen input) is processed, execute subroutineS1
and go toEND
. - If record format
09
(initialization), execute subroutineONETIM
and go toEND
.
- If record format
-
Subroutine S1: Input Validation (Lines 0062–0156):
- Validates user input from the
SCREEN
file against business rules:- Company Validation (KYALCO):
- Must be
ALL
orCO
. If invalid, set indicators 81/90, display error messageCOM,1
("ENTER ALL OR CO"), and go toENDS1
. - If
CO
, checkKYCO1
(company number):- If zero, display error
COM,5
("ENTER COMPANY NUMBER"). - Chain to
BICONT
to verifyKYCO1
. If not found or marked deleted (BCDEL = 'D'
), display errorCOM,2
("INVALID COMPANY NUMBER ENTERED").
- If zero, display error
- Customer Validation (KYALCS):
- Must be
ALL
orSEL
. If invalid, display errorCOM,3
("ENTER ALL OR SEL"). - If
SEL
, sum customer numbers inCS
array (XFOOTCS
). If zero, display errorCOM,6
("ENTER CUSTOMER NUMBER"). - Contract Validation (KYALCN):
- Must be
ALL
orCUR
. If invalid, display errorCOM,7
("ENTER ALL OR CUR"). - If
CUR
, calculate current date (UDATE * 10000.01
) and adjust for Y2K compliance to setKYDAT8
(ending date). - Sort Order Validation (KYSORT):
- Must be
N
(name) orS
(salesman). If invalid, display errorCOM,8
("REPORT SORT MUST BE 'N' OR 'S'"). - Salesman Validation (KYALSL, KYFRSL):
KYALSL
must beALL
orSEL
. If invalid, display errorCOM,3
.- If
ALL
andKYFRSL
(from salesman) is non-zero, display errorCOM,10
("CANNOT ENTER SALESMAN AND 'ALL'"). - If
SEL
andKYFRSL
is zero, display errorCOM,9
("SALESMAN NUMBER CANNOT BE ZERO"). - If
SEL
, chainKYFRSL
toGSTABL
(table typeSLSMAN
). If not found, display errorCOM,11
("INVALID SALESMAN ENTERED"). - Product Class (KYCLCD):
- If non-blank, chain to
GSTABL
(table typePRODCL
). If not found, display errorCOM,12
("INVALID PRODUCT CLASS ENTERED"). Else, store description inCLDESC
. - Product Group (KYGRCD):
- If non-blank, chain to
GSTABL
(table typePRODGR
). If not found, display errorCOM,13
("INVALID PRODUCT GROUP ENTERED"). Else, store description inGRDESC
. - Inventory Group (KYIVGR):
- If non-blank, chain to
GSTABL
(table typeINVGRP
). If not found, display errorCOM,14
("INVALID INVENTORY GROUP ENTERED"). Else, store description inIVDESC
.
-
If any validation fails, indicators 81/90 are set, and the program jumps to
ENDS1
to display the error message on the screen. -
Subroutine ONETIM: Initialization (Lines 0160–0200):
- Initialize Variables:
- Clear
DCO
array and setBILIM
(limit) to zero. - Set lower limit (
SETLL
) forBICONT
file to prepare for reading.
- Clear
- Read BICONT File:
- Loop through
BICONT
records, skipping deleted records (BCDEL = 'D'
). - Store company number (
BCCO
) and name (BCNAME
) inDCO
array.
- Loop through
-
Set Default Values:
- Set
KYALCO = 'ALL'
,KYCO1 = 0
,KYALCS = 'ALL'
,CS = 0
,KYALCN = 'ALL'
,KYALSL = 'ALL'
,KYSORT = 'N'
,KYEXPO = 'N'
. - Set indicator 81 to display the screen.
- Set
-
Output to Screen (Lines 0203–0216):
- Writes to
SCREEN
with record formatD
(display) if indicator 81 is on. -
Outputs fields like
KYALCO
,KYCO1
,DCO
,KYALCS
,CS
,MSG
,KYALCN
,KYSORT
,KYLOC
,KYPROD
,KYALSL
,KYFRSL
,KYBRND
,KYENDT
,KYEXPO
,KYCLCD
,KYGRCD
,KYIVGR
to the screen formatBI941PFM
. -
Program Termination:
- The program ends after displaying the screen or if the user presses a function key (
KG
) to exit.
Business Rules¶
The program enforces the following business rules for generating the customer sales agreement list:
1. Company Selection:
- Must be ALL
(all companies) or CO
(specific company).
- If CO
, a valid company number (KYCO1
) must exist in BICONT
and not be marked deleted.
2. Customer Selection:
- Must be ALL
(all customers) or SEL
(selected customers).
- If SEL
, at least one customer number must be provided in the CS
array.
3. Contract Selection:
- Must be ALL
(all contracts) or CUR
(current contracts).
- For CUR
, the ending date (KYDAT8
) is set based on the current date, adjusted for Y2K compliance.
4. Report Sort Order:
- Must be N
(by name) or S
(by salesman).
5. Salesman Selection:
- Must be ALL
(all salesmen) or SEL
(specific salesman).
- If ALL
, no salesman number (KYFRSL
) can be specified.
- If SEL
, a valid salesman number must exist in GSTABL
under table type SLSMAN
.
6. Product Class, Group, and Inventory Group:
- If specified (non-blank), must exist in GSTABL
under respective table types (PRODCL
, PRODGR
, INVGRP
).
- Descriptions are retrieved for valid entries.
7. Error Handling:
- Invalid inputs trigger specific error messages (stored in COM
array) and set indicators 81/90 to display the error on the screen.
8. Date Handling:
- Supports Y2K compliance by adjusting dates based on Y2KCEN
(century) and Y2KCMP
(comparison year).
Tables Used¶
The program uses the following files/tables:
- BICONT:
- A control file containing company data (e.g., company number BCCO
, name BCNAME
, deletion flag BCDEL
).
- Used to validate company numbers and populate the DCO
array with company information.
- GSTABL:
- A general system table containing reference data for:
- Salesmen (SLSMAN
table type).
- Product classes (PRODCL
table type).
- Product groups (PRODGR
table type).
- Inventory groups (INVGRP
table type).
- Fields include TBDEL
(deletion flag), TBTYPE
(table type), TBCODE
(table code), TBDESC
(description), and TBEIN
(EIN number).
External Programs Called¶
- None:
- The RPG program does not explicitly call any external programs. It is designed to handle input validation and screen output internally, likely preparing data for a report that may be generated by another program (e.g.,
BI941
called in the OCL script).
Summary¶
- Process Steps:
- Define files (
SCREEN
,BICONT
,GSTABL
) and data structures. - Initialize indicators and variables.
- Handle function key (
KG
) to exit if pressed. - Execute
ONETIM
subroutine for first-time setup (populateDCO
fromBICONT
, set defaults). - Execute
S1
subroutine to validate user input for company, customer, contract, sort order, salesman, product class, group, and inventory group. - Display errors or valid data on the screen.
-
Terminate after processing or user exit.
-
Business Rules:
- Enforce valid inputs for company (
ALL
/CO
), customer (ALL
/SEL
), contract (ALL
/CUR
), sort order (N
/S
), salesman (ALL
/SEL
), and optional product classAscension
System: * Today's date and time is 11:27 AM EDT on Thursday, August 21, 2025.