BB9433 RPGLE
The RPG program BB9433.rpgle is an IBM i (AS/400) program designed for copying or updating customer sales agreement records in the bicuag file. It is called from the main OCL program (likely via BB943P) to handle the copying of sales agreement records to new locations, ship-tos, or customer ship-tos, as well as updating existing records with new details. The program supports expiration logic and history logging. 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 BB9433 program processes input parameters to copy or update sales agreement records, handling multiple locations, ship-tos, or customer ship-tos, and ensures proper expiration and history logging. The key process steps are:
- Initialization (
*inzsrSubroutine): - Parameters: Receives three parameters:
parmlist: A data structure containing fields such as company (p$cono), customer (p$cust), location (p$loc), container (p$cntr), unit of measure (p$unms), ship-to (p$ship), product codes (p$pr01–p$pr10), purchase order (p$pord), price (p$prce), off-price (p$offp), freight code (p$frcd), delivery (p$delv), prepaid (p$ppd), primary flag (p$prim), min/max quantities (p$mnqy,p$mxqy), arrays for other locations (p$locs), ship-tos (p$shp), customer ship-tos (p$cshp), sequence number (p$seqn), start/end dates and times (p$std8,p$sttm,p$end8,p$entm), add/update flag (p$addupd), date flag (p$dateflag), and original key fields for expiration (o@cono,o@cust, etc.).p$fgrp: File group ('G' or 'Z') to determine database file overrides.p$flag: Return flag to indicate the action taken.
- Field Setup: Initializes work fields (
w$loc,w$cust,w$ship), arrays for locations (loc), ship-tos (shp), and customer ship-tos (cshp) fromp$locs,p$shp, andp$cshp. Sets current date/time (t#time,t#cymd) for validation and history logging. -
Data Structures: Defines
wkcuag(external data structure forbicuag) andsvcuag(256-byte structure to storebicuagrecord data). -
Open Database Tables (
opntblSubroutine): - Applies file overrides (
ovgorovz) based onp$fgrpusing theQCMDEXCAPI, mapping files to appropriate libraries (e.g.,gbicuagorzbicuag). -
Opens files (
bicont,bicuag,bicua3,bicuagh) withUSROPNfor validation, update, and history logging. -
Main Processing (
mainSubroutine, Implicit): - Check for Arrays: Checks if data exists in location (
*in60), ship-to (*in61), or customer ship-to (*in62) arrays to determine if copying to multiple locations/ship-tos is required. - Process Original Record:
- Chains to
bicuagusingklcuag(p$cono,p$seqn) to retrieve the original record if it exists. - If
p$expr = 'Y'(expire original record), checks expiration logic (jk04): - Expires the original record only if its end date (
baend8) is greater than the new record’s start date (p$std8) or zero. - Updates the original record’s end date/time to one minute before the new record’s start date/time (per
mg12inBB943context). - Writes the expired record to
bicuaghusingwritehist. - Copies the original record to
wkcuagfor modification.
- Chains to
- Copy to Other Locations/Ship-Tos:
- Iterates through the
loc,shp, orcshparrays if populated (*in60,*in61,*in62). - For each valid entry:
- Updates
wkcuagwith new location (baloc), ship-to (baship), or customer/ship-to (bacust,baship). - Generates a new sequence number (
w$sq) for the copied record. - Checks for duplicates in
bicua3usingklcua3to avoid conflicts. - Writes the new record to
bicuagusingwritecuag. - Writes a history record to
bicuaghusingwritehist.
- Iterates through the
-
Single Record Update:
- If no arrays are populated, updates or adds a single record using
writecuag. - Validates against
bicontfor company and ensures no duplicate records exist inbicua3.
- If no arrays are populated, updates or adds a single record using
-
Write Sales Agreement (
writecuagSubroutine): - Populates
wkcuagfields with input parameters (e.g.,bacono = p$cono,bacust = p$cust,bapr01 = p$pr01, etc.). - Sets additional fields like creation date (
bacrdt), creation time (bacrtm), last update date (baludt), last update time (balutm), and contract number (bacntn, perjk04). -
Writes or updates the record in
bicuag. -
Write History (
writehistSubroutine): - Clears the
bicuaghpfrecord format. - Copies fields from
wkcuagto the history record (hhcono,hhcust,hhloc, etc.). - Sets history fields:
hhdel = badel(deletion status, perjk02).hhuser = jbuser8(user ID, 8 characters).hhchd8 = t#cymd(change date, CCYYMMDD).hhchtm = t#hms(change time, HHMMSS).
-
Writes the record to
bicuagh. -
Program Termination:
- Closes all files (
close *all). - Sets
*inlr = *onand returns, passing backp$flagto indicate success or failure.
Business Rules¶
The program enforces the following business rules for copying or updating customer sales agreement records:
- Copy to Multiple Locations/Ship-Tos:
- Supports copying a sales agreement to multiple locations (
p$locs), ship-tos (p$shp), or customer ship-tos (p$cshp) using arrays, indicated by*in60,*in61, and*in62. - Each copied record gets a new sequence number (
w$sq) to avoid conflicts. -
Duplicate records are prevented by checking
bicua3withklcua3(key fields: company, customer, location, container, unit of measure, ship-to, product codes, PO, min/max quantities, start date/time, freight code). -
Expiration Logic (
jk04): - If
p$expr = 'Y', the original record is expired only if its end date (baend8) is greater than the new record’s start date (p$std8) or zero. - The expired record’s end date/time is set to one minute before the new record’s start date/time (aligned with
mg12inBB943). -
Expired records are written to
bicuagh. -
Freight Code Differentiation (
mg12): -
Allows multiple records with identical start dates if their freight codes (
p$frcd) differ, ensuring flexibility in agreement management. -
Field Validation:
- Company (
p$cono) must exist inbicont. - Price (
p$prce) and off-price (p$offp) use expanded 9.4 packed format (jk05). - Min/max quantities (
p$mnqy,p$mxqy) are supported (jk03). -
Contract number (
p$cntn) is included in the input parameters and written tobicuag(jk04). -
History Logging:
-
Every add, update, or expiration action writes a record to
bicuaghwith the user ID, change date/time, and deletion status (hhdel, perjk02). -
File Group Overrides:
- Uses
p$fgrp('G' or 'Z') to apply appropriate file overrides, ensuring access to the correct dataset (e.g.,gbicuagorzbicuag).
Tables Used¶
The program uses the following database files, with overrides applied based on p$fgrp ('G' or 'Z'):
- bicont: Company master file (update/input, validates company number).
- bicuag: Sales agreement file (update/add, primary file for storing agreements).
- bicua3: Sales agreement logical file (update/input, checks for duplicates, includes min/max quantities, per
jk03). - bicuagh: Sales agreement history file (output, logs changes, per
jk02).
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').
- GSDTCLC1: Called via the
pldtclc1parameter list to calculate date differences for expiration logic (e.g., checking start vs. end dates).
No other user-defined programs are explicitly called in the provided source code.
Summary¶
- Process Steps: Initializes parameters and arrays, applies file overrides, opens database files, retrieves the original sales agreement record, expires it if required, copies or updates records for multiple locations/ship-tos or a single record, writes to
bicuag, logs tobicuagh, and handles date calculations. - Business Rules: Supports copying to multiple locations/ship-tos, expires original records based on date logic, allows same start dates with different freight codes, validates company and duplicate records, logs all changes to history, and uses expanded price fields.
- Tables Used:
bicont,bicuag,bicua3,bicuagh. - External Programs Called:
QCMDEXC,GSDTCLC1.
If you need further analysis of specific subroutines, file structures, or integration with BB943P, BB943, or BB944, please provide additional details or source code. Alternatively, I can perform a DeepSearch for related information if enabled. Let me know how to proceed!