BB943 RPGLE
The RPG program BB943.rpgle
is an IBM i (AS/400) program designed for "Customer Sales Agreement Maintenance," providing an interactive interface to add, update, or inquire about customer sales agreement records. It is called from the main OCL program (via BB943P
) and supports maintenance ('MNT') and inquiry ('INQ') modes. 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 BB943
program follows a structured flow for managing customer sales agreements using a display file (bb943d
) with subfiles for user interaction. The process steps are as follows:
- Initialization (
*inzsr
Subroutine): - Parameters: Receives input parameters:
p$cono
: Company number.p$stat
: Status code (3 characters).p$validpw
: Valid password flag (1 character, 'Y' or blank).p$sqky
: Sequence number for the record.p$frsq
: Sequence number for copying a record.c1f6flag
: Flag for F6 defaults (carrier, billed, or all values).c1cust
,c1loc
,c1cntr
,c1prcd
,c1prim
,c1ship
: Fields fromBB943P
for pre-populating the screen.p$mode
: Run mode ('MNT' or 'INQ').p$fgrp
: File group ('G' or 'Z') for database overrides.p$flag
: Return flag.p$dspmsg
: Message flag.
- Special Case: If the user is 'KRAJTEST', sets
p$validpw = 'Y'
for testing purposes. - Field Setup: Initializes display file fields (
f$sq
,s1stat
), current date/time (t#time
,t#cymd
), and work fields (e.g.,l$cntr
,w$cnty
). Clears subfile fields (s1cono
,s1cust
, etc.) and sets message handling fields. -
File Overrides: Prepares file overrides (
ovg
orovz
) based onp$fgrp
. -
Open Database Tables (
opntbl
Subroutine): - Executes the
QCMDEXC
API to apply file overrides for the specified file group ('G' or 'Z'), mapping files likearcust
togarcust
orzarcust
. - Opens input files (
arcust
,bicont
,gscntr1
,gsprod
,apvend
,gstabl
,inloc
,shipto
,trrtcd
,arcupr
,arcomm
,bicua3
) and output file (bicuagh
) withUSROPN
. - Opens
bicuag
for add/update operations. -
Clears the message subfile (
clrmsg
). -
Main Processing Loop:
- Mode Setup: Sets protection indicators based on
p$mode
:- In 'INQ' mode,
*in70 = *on
(protects all fields). - In 'MNT' mode,
*in71 = *on
(protects key fields for updates), and*in72
depends onp$validpw
(protects values if no password).
- In 'INQ' mode,
- Display Screen: Displays the control record (
msgctl
) and message subfile (wrtmsg
) ifdspmsg = *on
. -
User Input: Uses
EXFMT
to display the format (fmt1
) and process user input via function keys:- F03 (Exit): Exits the program.
- F04 (Prompt): Calls
prompt
to assist with field entry (e.g., customer, ship-to). - F05 (Refresh): Resets fields and redisplays.
- F06 (Defaults): Toggles default values (carrier, billed, or all) based on
c1f6flag
. - ENTER: Validates input (
validate
) and processes the record (addfmt
for add,updfmt
for update).
-
Validation (
validate
Subroutine): - Calls
BB9643V
to validate fields in thep$vlist
data structure (e.g., company, customer, location, container, product codes, dates, etc.). - Checks for:
- Duplicate product codes, locations, or ship-to entries.
- Valid company (
bicont
), customer (arcust
), location (inloc
), ship-to (shipto
), and product codes (gsprod
). - Valid start/end dates and times (using
GSDTEDIT
andGSDTCLC1
). - Minimum quantity (
s1mnqy
) not exceeding maximum quantity (s1mxqy
). - Valid PO/Order code (
s1poor
, 'P' or 'O').
-
Sets error messages (e.g.,
com(04)
for duplicate product codes,com(06)
for invalid dates). -
Add Record (
addfmt
Subroutine): - Validates input fields and checks for existing records in
bicuag
usingklcua3
keylist. - If valid, writes a new record to
bicuag
with fields likes1cono
,s1cust
,s1loc
,s1cntr
,s1prod
, etc. - If
s1expr = 'Y'
, expires the original record by updating its end date/time and writing to history (bicuagh
). - Writes commission data to
arcomm
if applicable (mg09
). -
Sets success message (
com(02)
for record created). -
Update Record (
updfmt
Subroutine): - Retrieves the existing record from
bicuag
usingf$sqkey
. - Updates the record with new values if valid, preserving key fields (
*in71
). - Handles expiration logic (
jk04
): Expires the original record only if the new expiration date is greater than the start date or zero. - Writes to history (
bicuagh
) and commission (arcomm
) as needed. -
Sets success message (
com(03)
for record changed). -
Message Handling:
- Add Message (
addmsg
): Sends messages to the program message queue usingQMHSNDPM
. - Write Message (
wrtmsg
): Writes messages to the message subfile. -
Clear Message (
clrmsg
): Clears the message subfile usingQMHRMVPM
. -
Program Termination:
- Closes all files (
close *all
). - Sets
*inlr = *on
and returns.
Business Rules¶
The program enforces the following business rules to ensure proper management of customer sales agreements:
- Mode-Based Access Control:
- In 'MNT' mode, users can add or update records, with key fields protected (
*in71 = *on
) during updates. - In 'INQ' mode, all fields are protected (
*in70 = *on
), allowing only viewing. -
If no valid password (
p$validpw
not 'Y'), values are protected (*in72 = *on
). -
Field Validation:
- Company and Customer: Must exist in
bicont
andarcust
(com(01)
,com(02)
for invalid entries). - Product Codes: At least one valid product code must be entered (
com(05)
), and duplicates are not allowed (com(04)
). - Locations and Ship-To: No duplicate locations (
com(07)
) or ship-to entries (com(08)
,com(09)
for customer ship-to). - Dates and Times: Expiration date cannot be before start date (
com(06)
). Start time defaults to 0000 (mg10
). - Quantities: Maximum quantity (
s1mxqy
) must not be less than minimum quantity (s1mnqy
) (com(11)
). -
PO/Order Code: Must be 'P' (PO) or 'O' (Order) (
com(12)
). -
Container Type Handling:
- Per
jb04
, allows blank container codes for non-fluid products. - Per
jb06
, checksarcupr
with container type first, then with blank container type if not found. -
Per
jb13
(07/22/2024), users cannot enter container types in sales agreements. -
Expiration Logic (
jk04
,mg12
): - A record is expired (
s1expr = 'Y'
) only if its expiration date is greater than the new record’s start date or zero. - Expired records are written to
bicuagh
(history file). - Allows multiple records with the same start date if freight codes differ (
mg12
). -
Sets the end date of an expired record to one minute before the new record’s start time (
mg12
). -
Commission and Primary Flag:
- Includes commission information in
arcomm
when applicable (mg09
). -
Sets
s1prim = 'I'
if blank (jb08
). -
Duplicate Record Prevention:
-
Checks for existing records in
bicuag
to prevent duplicates based on key fields (company, customer, location, container, product codes, etc.). -
Error and Success Messages:
- Displays messages for invalid input (e.g.,
com(01)
–com(12)
), record creation (com(02)
), updates (com(03)
), or expiration failures (com(03)
).
Tables Used¶
The program uses the following database files, with overrides applied based on p$fgrp
('G' or 'Z'):
- arcust: Customer master file (input, contains customer details).
- bicont: Company master file (update/input, contains company details).
- gscntr1: Container file (input, alpha key, replaced
gscntr
perjk06
). - gsprod: Product file (input, contains product details).
- apvend: Vendor file (input, contains vendor details).
- gstabl: Table file (input, for reference data like container types).
- inloc: Location file (input, contains location details).
- shipto: Ship-to file (input, contains ship-to addresses).
- trrtcd: Freight code file (input, contains freight codes).
- arcupr: Customer price file (input, contains pricing data).
- arcomm: Commission file (input, contains commission data, added per
jk03
). - bicuag: Sales agreement file (update/add, primary file for agreements).
- bicua3: Sales agreement file with additional fields (min/max quantity, renamed format
bicuaglf
, added perjk03
). - bicuagh: Sales agreement history file (output, stores expired records).
Overrides map these files to specific libraries (e.g., garcust
or zarcust
).
External Programs Called¶
The program calls the following external programs:
- QCMDEXC: System API to execute file override commands.
- QMHSNDPM: System API to send messages to the program message queue.
- QMHRMVPM: System API to remove messages from the message queue.
- BB9643V: Validates input fields in the
p$vlist
data structure, checking for duplicates, valid codes, and date logic. - GSDTEDIT: Validates date formats (called via
pldted
parameter list). - GSDTCLC1: Calculates date differences (called via
pldtclc1
parameter list). - LARCUST: Called for customer field prompting (F4 on customer field).
- LCSTSHP: Called for ship-to field prompting (F4 on ship-to field).
- LINLOC: Called for location field prompting (F4 on location field).
- LGSCNCD: Called for container field prompting (F4 on container field).
- LGSPROD: Called for product field prompting (F4 on product field).
Summary¶
- Process Steps: Initializes parameters and files, opens database tables, displays an interactive screen, validates input, adds or updates sales agreement records in
bicuag
, handles expiration and history (bicuagh
), and manages messages. - Business Rules: Enforces mode-based access, validates company/customer/product codes, prevents duplicates, restricts container types (
jb13
), allows blank containers for non-fluid products (jb04
), handles expiration logic (jk04
,mg12
), and includes commission data (mg09
). - Tables Used:
arcust
,bicont
,gscntr1
,gsprod
,apvend
,gstabl
,inloc
,shipto
,trrtcd
,arcupr
,arcomm
,bicuag
,bicua3
,bicuagh
. - External Programs Called:
QCMDEXC
,QMHSNDPM
,QMHRMVPM
,BB9643V
,GSDTEDIT
,GSDTCLC1
,LARCUST
,LCSTSHP
,LINLOC
,LGSCNCD
,LGSPROD
.
If you need further analysis of specific subroutines, file structures, or called programs (e.g., BB9643V
), please provide their source code or additional details. Alternatively, I can perform a DeepSearch for related information if enabled. Let me know how to proceed!