BB943V RPGLE
The RPG program BB943V.rpgle (referred to as BB9643V in the BB943 program) is an IBM i (AS/400) validation program called by BB943 to validate input fields for the Customer Sales Agreement Maintenance process. It ensures that the data entered in the sales agreement record adheres to specific business rules before it is added or updated in the bicuag file. Below, I will explain the process steps, business rules, tables used, and external programs called based on the provided RPG source code.
Process Steps of the RPG Program¶
The BB943V program is designed to validate a data structure (CUAGDS) containing customer sales agreement fields passed from BB943. It performs checks against multiple database files and returns error messages or cursor positioning information if validation fails. Here are the key process steps:
- Initialization (
*inzsrSubroutine, Implicit): - Parameters: Receives two parameters:
CUAGDS: A data structure containing fields like company (CONO), customer (CUST), location (ALOC), container (KCNTR), product codes (S3PR), start/end dates (STDT,ENDT), and others (seeCUAGDSdefinition).p$fgrp: File group ('G' or 'Z') to determine database file overrides.
-
Y2K Setup: Sets
y2kcen = 19andy2kcmp = 80for date handling (likely for legacy Y2K compatibility, perjb01). -
Open Database Tables (
opntblSubroutine): - Applies file overrides (
ovgorovz) based onp$fgrpusing theQCMDEXCAPI, mapping files to appropriate libraries (e.g.,gbicontorzbicont). -
Opens input files (
BICONT,ARCUST,SHIPTO,INLOC,GSTABL,GSCNTR1,BICUA3,BICUA9,BBORDH,GSPROD) withUSROPNfor validation checks. -
Main Validation Logic (
$SBLKSubroutine): - Initializes error flags and message fields (
@MSG,@PC). -
Performs validation checks on the
CUAGDSdata structure fields, including:- Company (
CONO): Chains toBICONTto verify the company exists (COM(01)if invalid). - Customer (
CUST): Chains toARCUSTto verify the customer exists (COM(06)if not found). - Location (
ALOC): Chains toINLOCto verify the location exists (COM(20)if invalid). - Container (
KCNTR): Chains toGSCNTR1to verify the container code (COM(33)if invalid). Checks container type (TCCNTY) againstGSTABL(COM(32)if invalid). - Unit of Measure (
UNMS): Validates againstGSTABL(COM(08)orCOM(50)if invalid). - Product Codes (
S3PR): Ensures at least one valid product code is entered (COM(09)), checks for duplicates (COM(11)), and verifies againstGSPROD(COM(51)). Ensures fluid products have a valid container (COM(54)) and non-fluid products have a blank container (COM(17),COM(52)). - Purchase Order (
PORD): Validates againstBBORDHifS3POOR = 'O'(COM(13)if invalid). - Ship-To (
SHIP,ALSH): Validates ship-to codes againstSHIPTO. EnsuresALSH = 'Y'impliesSHIP = 0(COM(28)), andALSH = 'N'impliesSHIP ≠ 0(COM(49)). Checks for valid ship-to (COM(48)). - Other Locations (
S3LO): Ensures no duplicates (COM(40)) and validates againstINLOC. - Other Ship-To (
S3SH): Ensures no duplicates (COM(43)) and validates againstSHIPTO. - Other Customer Ship-To (
S3CS): Ensures no duplicates (COM(56),COM(57)) and validates customer/ship-to combinations againstARCUSTandSHIPTO. - Start/End Dates and Times (
STDT,STTM,ENDT,ENTM): Validates date formats and ensures end date/time follows start date/time (COM(15),COM(18),COM(35)). Checks hours (00-23,COM(21),COM(23)) and minutes (00-59,COM(22),COM(24)). Ensures non-zero times (COM(25),COM(26)). - Freight Code (
FRCD): Validates againstGSTABL(COM(31)if invalid). - Prepaid (
PPD): Must be 'P' or blank (COM(55)). - Primary Flag (
PRIM): Must be 'I' or 'M' (COM(29)). - Min/Max Quantity (
MNQY,MXQY): EnsuresMXQY ≥ MNQY(implicit check, no specific error message listed). - PO/Order Code (
S3POOR): Must be 'P' or 'O' (COM(36)). - Password (
KAGPW): Validates againstBICONT(BCAGPW,COM(34)). Requires a password if the start date is more than 3 days ago (COM(37)).
- Company (
-
Duplicate Record Check (
EDITS3Subroutine): - For add operations (
ADDREC = 'Y'), checksBICUA3to ensure no existing agreement matches the key fields (company, customer, location, container, unit of measure, ship-to, product codes, PO, min/max quantities, start date/time, freight code) usingotkH102keylist (COM(58)if a duplicate exists). - For update operations (
ADDREC ≠ 'Y'), checksBICUA9for:- An agreement with the new end date/time, ignoring records with start dates after the current end date or end dates not equal to 12/31/2079 23:59 (
COM(58)if no match). - An agreement without an end date/time, ensuring a record exists to update (
COM(58)if no match).
- An agreement with the new end date/time, ignoring records with start dates after the current end date or end dates not equal to 12/31/2079 23:59 (
-
Skips update checks for "copy to other" fields per
jb01. -
Copy to Other Validation (
jb01): - Only allows "copy to other" processing (other locations, ship-tos, customer ship-tos) when adding a record (
ADDREC = 'Y'), either via F6 or option 3 (copy). - Protects "copy to other" fields during updates and prevents their modification.
-
Validates "expire" field (
S3EXPR) only for copy operations (COM(47)if not 'Y' during copy). -
Program Termination:
- Sets
*inlr = *onand returns, passing back theCUAGDSdata structure with any error messages (@MSG) and cursor positioning (@PC).
Business Rules¶
The program enforces the following business rules to validate customer sales agreement data:
- Mandatory Field Validation:
- Company (
CONO) must exist inBICONT(COM(01)). - Customer (
CUST) must exist inARCUST(COM(06)). - Location (
ALOC) must exist inINLOC(COM(20)). - At least one valid product code (
S3PR) must be entered (COM(09)). -
PO/Order code (
S3POOR) must be 'P' (purchase order) or 'O' (order) (COM(36)). -
Duplicate Prevention:
- No duplicate product codes (
COM(11)). - No duplicate other locations (
COM(40)), ship-tos (COM(43)), or customer ship-tos (COM(56),COM(57)). -
No duplicate agreements for add operations based on key fields (
COM(58)). -
Container and Product Rules:
- Container (
KCNTR) must be valid inGSCNTR1(COM(33)) and have a valid type inGSTABL(COM(32)). - Non-fluid products (based on
TPFLCDinGSPROD) must have a blank container (COM(17),COM(52)). - Fluid products require a valid container (
COM(54)). -
Unit of measure (
UNMS) must be valid inGSTABL(COM(08),COM(50)). -
Date and Time Validation:
- Start and end dates (
STDT,ENDT) must be valid (COM(15),COM(18)). - Start and end times (
STTM,ENTM) must have valid hours (00-23,COM(21),COM(23)) and minutes (00-59,COM(22),COM(24)). - Start and end times cannot be all zeros (
COM(25),COM(26)). - End date/time must follow start date/time (
COM(35)). -
Allows same start dates if freight codes (
FRCD) differ (MG04). -
Ship-To Rules:
- If all ship-tos (
ALSH = 'Y'), ship-to (SHIP) must be zero (COM(28)). -
If not all ship-tos (
ALSH = 'N'), ship-to must be non-zero and valid inSHIPTO(COM(49),COM(48)). -
Copy to Other Restrictions (
jb01): - "Copy to other" fields (other locations, ship-tos, customer ship-tos) are only editable during add operations (F6 or option 3).
- These fields are protected during updates.
-
The expire field (
S3EXPR) is only used for copy operations and must be 'Y' (COM(47)). -
Password Validation:
- Agreement password (
KAGPW) must matchBCAGPWinBICONT(COM(34)). -
A password is required if the start date is more than 3 days in the past (
COM(37)). -
Other Field Rules:
- Freight code (
FRCD) must be 'C', 'P', 'A', or blank (COM(31)). - Prepaid (
PPD) must be 'P' or blank (COM(55)). - Primary flag (
PRIM) must be 'I' (invoice) or 'M' (month-end) (COM(29)). - Either price (
PRCE) or off-price (OFFP) must be non-zero (COM(14)). -
Purchase order (
PORD) must exist inBBORDHifS3POOR = 'O'(COM(13)). -
Update Validation:
- For updates, ensures an agreement exists with the specified end date/time or no end date/time (
COM(58)). - Ignores records with start dates after the current end date or end dates not equal to 12/31/2079 23:59.
Tables Used¶
The program uses the following database files, with overrides applied based on p$fgrp ('G' or 'Z'):
- BICONT: Company master file (input, validates
CONOandBCAGPW). - ARCUST: Customer master file (input, validates
CUST). - SHIPTO: Ship-to file (input, validates
SHIPand customer ship-tos). - INLOC: Location file (input, validates
ALOCand other locations). - GSTABL: Table file (input, validates container type and unit of measure).
- GSCNTR1: Container file (input, validates
KCNTR, alpha key, replacedGSCNTRperjk06inBB943). - BICUA3: Sales agreement logical file (input, checks for duplicate agreements during add, includes min/max quantities per
jk02). - BICUA9: Sales agreement logical file (input, checks for existing agreements during update, includes min/max quantities per
jk02). - BBORDH: Order header file (input, validates purchase order number for
S3POOR = 'O'). - GSPROD: Product file (input, validates product codes and fluid/non-fluid status, added per
jk04).
Overrides map these files to specific libraries (e.g., gbicont or zbicont).
External Programs Called¶
The program calls the following external program:
- QCMDEXC: System API to execute file override commands for the specified file group ('G' or 'Z').
No other external programs are explicitly called in the provided source code. Note that BB943V is called by BB943 but does not itself call other user-defined programs.
Summary¶
- Process Steps: Initializes parameters, applies file overrides, opens database files, validates fields in the
CUAGDSdata structure (company, customer, location, container, product codes, dates, etc.), checks for duplicate or existing agreements, and returns error messages or cursor positioning if validation fails. - Business Rules: Validates mandatory fields, prevents duplicates, enforces container/fluid product rules, ensures valid dates/times, restricts "copy to other" to add operations, requires passwords for past dates, and validates freight codes, prepaid flags, and primary flags.
- Tables Used:
BICONT,ARCUST,SHIPTO,INLOC,GSTABL,GSCNTR1,BICUA3,BICUA9,BBORDH,GSPROD. - External Programs Called:
QCMDEXC.
If you need a deeper analysis of specific validation checks, file structures, or related programs, please provide additional details or source code (e.g., for BB943 or BB943P). Alternatively, I can perform a DeepSearch for related information if enabled. Let me know how to proceed!