BB9433 RPGLE
The provided document is an RPGLE program named BB9433
, called from the OCL procedure BB943INQ.ocl36.txt
and referenced by the BB943
program in the IBM System/36 (or AS/400 compatibility mode) environment. This program, titled "Copy/Update Sales Agreements," is designed to copy or update customer sales agreement records in the bicuag
file, including handling expiration of original records and logging to the history file (bicuagh
). Below, I’ll explain the process steps, business rules, tables used, and external programs called, based on the provided RPGLE source code, the OCL context, and its integration with BB943
, BB943P
, and BB943V
.
Process Steps of the RPGLE Program¶
The BB9433
program is a backend module that processes the addition or updating of customer sales agreement records, including copying agreements to other locations, ship-tos, or customer-ship-to combinations, and managing expiration of original records. It receives a comprehensive parameter list from BB943
and operates in either add or update mode. Due to the truncation of the source code (7,596 characters), some logic is incomplete, but I’ll reconstruct the process steps based on the available code and context.
- Initialization (
*inzsr
Subroutine): - Receive Parameters: The program accepts three parameters via the
*ENTRY
plist:parmlist
: A data structure containing fields for the sales agreement, including:p$cono
(company number).p$cust
(customer number).p$loc
(location).p$cntr
(container code).p$unms
(unit of measure).p$alsh
(all ship-tos flag,'Y'
or'N'
).p$ship
(ship-to number).p$pr01
–p$pr10
(product codes, up to 10).p$pord
(bill-to purchase order).p$expr
(expire flag,'Y'
for expiring original record).p$prce
(price, 9.4 packed, perjk05
).p$offp
(off-price, 9.4 packed, perjk05
).p$frcd
(freight code).p$delv
(delivery code).p$ppd
(prepaid flag,'P'
or blank).p$prim
(pricing type,'I'
or'M'
).p$mnqy
(minimum quantity).p$mxqy
(maximum quantity).p$locs
(array of other locations, 30 bytes).p$shp
(array of other ship-tos, 30 bytes).p$cshp
(array of other customer-ship-to combinations, 36 bytes).p$seqn
(sequence number).p$std8
(start date, CCYYMMDD).p$sttm
(start time).p$end8
(end date, CCYYMMDD).p$entm
(end time).p$addupd
(add or update flag).p$dateflag
(date flag, 2 bytes).o@cono
,o@cust
,o@loc
,o@cntr
,o@unms
,o@ship
,o@pr01
–o@pr10
,o@pord
,o@std8
,o@sttm
,o@mnqy
,o@mxqy
(original key fields for expiring records).p$cntn
(contract number, perjk04
).p$poor
(PO/order code, perjk04
).p$fgrp
: File group ('G'
or'Z'
) for file overrides.p$flag
: Return flag (1 character, e.g.,'1'
for success,'0'
for failure).
- Set System Information: Retrieves system data via the
psda##
program status data structure (e.g.,pgmq##
for program name,jbuser
for user,jbdt##
for job date). - Set Current Date/Time: Uses the
TIME
operation to populatet#time
and converts it tot#cymd
(CCYYMMDD) andt#hms
(HHMMSS) for history record timestamps. - Move Arrays: Transfers
p$locs
,p$shp
, andp$cshp
to work arraysloc
,shp
, andcshp
for processing other locations, ship-tos, and customer-ship-to combinations. - Open Database Tables: Calls
opntbl
to apply file overrides and open files. -
Define Key Lists:
klcuag
: For accessingbicuag
withp$cono
andp$seqn
.newkey
: For new records withp$cono
andw$sq
(work sequence number).klcua3
: For checking existing agreements inbicua3
with original key fields (o@cono
,w$cust
,w$loc
,o@cntr
,o@unms
,w$ship
,o@pr01
–o@pr10
,o@pord
,o@mnqy
,o@mxqy
,o@std8
,o@sttm
,p$frcd
).
-
Open Database Tables (
opntbl
Subroutine): - File Overrides: Applies overrides based on
p$fgrp
('G'
or'Z'
) usingovg
orovz
arrays (e.g.,ovrdbf file(bicuag) tofile(*libl/gbicuag)
for'G'
). Executes overrides withQCMDEXC
. - Open Files: Opens the following files with
usropn
:bicont
(company file, update/input, keyed).bicuag
(sales agreement file, update/add/input, keyed).bicua3
(sales agreement logical file, update/input, keyed, renamed record formatbicuagpf
tobicuagf3
, perjk03
).bicuagh
(sales agreement history file, output-only, keyed).
-
Purpose: Ensures access to the correct file library (
G
orZ
) for data operations. -
Process Other Locations (
loc
Array): - Check
loc
Array: Ifchkloc
(overlay ofloc
array) is not blank, sets*IN60
to*ON
to indicate data in the location array. - Loop Through
loc
: For each non-blank entry inloc
(up to 10 elements):- Sets
w@loc
to the current location (loc(z)
). - Sets
w@cust
top$cust
andw@ship
top$ship
. - Calls
writercd
to write or update a sales agreement record for the location.
- Sets
-
Clear Indicator: Resets
*IN60
to*OFF
after processing. -
Process Other Ship-tos (
shp
Array): - Check
shp
Array: Ifchkshp
(overlay ofshp
array) is not blank, sets*IN61
to*ON
. - Loop Through
shp
: For each non-blank entry inshp
(up to 10 elements):- Sets
w@ship
to the current ship-to (shp(y)
). - Sets
w@cust
top$cust
andw@loc
top$loc
. - Calls
writercd
to write or update a sales agreement record for the ship-to.
- Sets
-
Clear Indicator: Resets
*IN61
to*OFF
after processing. -
Process Other Customer-Ship-to Combinations (
cshp
Array): - Check
cshp
Array: Ifchkcshp
(overlay ofcshp
array) is not blank, sets*IN62
to*ON
. - Loop Through
cshp
: For each non-blank entry incshp
(up to 4 elements):- Extracts customer (
dscust
) and ship-to (dsship
) fromdscstshp
. - Sets
w@cust
todscust
,w@ship
todsship
, andw@loc
top$loc
. - Calls
writercd
to write or update a sales agreement record for the customer-ship-to combination.
- Extracts customer (
-
Clear Indicator: Resets
*IN62
to*OFF
after processing. -
Write/Update Record (
writercd
Subroutine): - Populate
bicuag
Fields: Maps input parameters tobicuag
record fields:bacono = p$cono
,bacust = p$cust
,baloc = w@loc
,bacntr = p$cntr
,baunms = p$unms
,baship = w@ship
.- Product codes:
bapr01
–bapr10
=p$pr01
–p$pr10
. - Dates:
bastd8 = p$std8
,bastdt = p$std8
(with flag'1'
),basttm = p$sttm
,baend8 = p$end8
,baendt = p$end8
(with flag'1'
),baentm = p$entm
. - Other fields:
bapord = p$pord
,baalsh = p$alsh
,baprce = p$prce
,baoffp = p$offp
,bafrcd = p$frcd
,badelv = p$delv
,bappd = p$ppd
,baprim = p$prim
,bamnqy = p$mnqy
,bamxqy = p$mxqy
,bacntn = p$cntn
,bapoor = p$poor
.
-
Write/Update Logic (Truncated):
- Likely checks if the record exists using
klcuag
ornewkey
and updates (UPDATE
) or writes (WRITE
) tobicuag
. - If
p$expr = 'Y'
, expires the original record usingklcua3
by setting its end date/time and writing tobicuagh
(perjk04
). - Uses
wkcuag
(external data structure) andsvcuag
(256-byte save data structure) to hold record data during processing.
- Likely checks if the record exists using
-
Write to History File (
writehist
Subroutine): - Clear History Record: Clears the
bicuaghpf
record format. - Populate History Fields: Maps
bicuag
fields tobicuagh
fields (e.g.,hhcono = bacono
,hhdel = badel
perjk02
,hhcust = bacust
, etc.). - Add Audit Fields:
- Sets
hhchd8 = t#cymd
(current date) andhhchtm = t#hms
(current time). - Sets
hhuser = jbuser8
(user ID, 8 characters).
- Sets
-
Write Record: Writes to
bicuagh
usingWRITE bicuaghpf
. -
Program Termination (Truncated):
- Likely closes all files (
close *all
) and sets*inlr = *on
to terminate. - Returns
p$flag
to indicate success ('1'
) or failure ('0'
) toBB943
.
Business Rules¶
The program enforces the following business rules for copying or updating sales agreements:
- Add vs. Update Mode:
- Controlled by
p$addupd
:'A'
(add): Creates new records inbicuag
for the primary key and any additional locations (p$locs
), ship-tos (p$shp
), or customer-ship-to combinations (p$cshp
).'U'
(update): Updates existing records based onp$seqn
.
-
Indicators
*IN60
,*IN61
, and*IN62
track whetherloc
,shp
, orcshp
arrays contain data. -
Copy to Other Locations/Ship-tos/Customer-Ship-tos:
- Processes
p$locs
(other locations),p$shp
(other ship-tos), andp$cshp
(other customer-ship-to combinations) to create multiple agreement records with varyingbaloc
,baship
, orbacust
/baship
combinations. -
Ensures no duplicate agreements exist (validated by
BB943V
before callingBB9433
). -
Expiration Handling (per
jk04
): - If
p$expr = 'Y'
, expires the original record (identified byo@cono
,o@cust
,o@loc
,o@cntr
,o@unms
,o@ship
,o@pr01
–o@pr10
,o@pord
,o@std8
,o@sttm
,o@mnqy
,o@mxqy
) only if:- Its expiration date (
baend8
) is greater than the new record’s start date (p$std8
) or is zero.
- Its expiration date (
-
Writes expired records to
bicuagh
with audit fields (hhchd8
,hhchtm
,hhuser
). -
Duplicate Start Dates (per
jk01
): -
Allows identical start dates (
p$std8
,p$sttm
) if freight codes (p$frcd
) differ. -
Price and Quantity Fields (per
jk05
): p$prce
andp$offp
are stored as 9.4 packed decimal inbaprce
andbaoffp
.-
p$mnqy
andp$mxqy
are stored inbamnqy
andbamxqy
(added perjk03
). -
Contract Number and PO/Order Code (per
jk04
): - Stores
p$cntn
inbacntn
(contract number). -
Stores
p$poor
inbapoor
(PO or order code). -
History Logging:
- Writes expired or modified records to
bicuagh
with current date/time (hhchd8
,hhchtm
) and user (hhuser
). -
Transfers deletion flag (
badel
tohhdel
, perjk02
). -
Validation:
- Relies on
BB943V
for input validation before processing. Ensures fields likep$cono
,p$cust
,p$loc
,p$cntr
,p$pr01
–p$pr10
, etc., are valid.
Tables Used¶
The program uses the following files, as defined in the File Specification (F-spec) section:
- bicuag: Primary sales agreement file, update/add/input, keyed.
- bicont: Company file, update/input, keyed.
- bicua3: Sales agreement logical file (replaced
bicua2
perjk03
), update/input, keyed, with renamed record format (bicuagpf
tobicuagf3
). - bicuagh: Sales agreement history file, output-only, keyed.
File Overrides:
- The ovg
and ovz
arrays specify overrides for file groups 'G'
and 'Z'
, mapping files to libraries (e.g., gbicuag
, zbicuagh
).
External Programs Called¶
The program explicitly calls one external program:
- QCMDEXC:
- Called in the
opntbl
subroutine to execute file override commands. - Parameters:
dbov##
(override command string, 80 bytes),dbol##
(length, 15.5).
Implied Program:
- GSDTCLC1: Implied by the pldtclc1
PLIST for date addition/subtraction, used for date calculations (e.g., expiration date adjustments). Parameters: p#dat1
, p#dat2
, p#fmt
, p#diff
, p#err
.
Summary¶
- Process Steps:
- Initialize by receiving
parmlist
,p$fgrp
, andp$flag
, setting date/time, and moving arrays (loc
,shp
,cshp
). - Apply file overrides and open files (
opntbl
). - Process
loc
array to create/update agreements for other locations (*IN60
). - Process
shp
array for other ship-tos (*IN61
). - Process
cshp
array for other customer-ship-to combinations (*IN62
). - Write/update records in
bicuag
usingwritercd
, mapping parameters to file fields. - Write expired records to
bicuagh
with audit fields (writehist
). -
Terminate, returning
p$flag
(success/failure). -
Business Rules:
- Supports add (
'A'
) and update ('U'
) modes viap$addupd
. - Copies agreements to other locations, ship-tos, or customer-ship-to combinations.
- Expires original records if
p$expr = 'Y'
and expiration conditions are met (perjk04
). - Allows identical start dates if freight codes differ (per
jk01
). - Logs expired/modified records to
bicuagh
with audit fields. - Uses expanded price fields (
baprce
,baoffp
, perjk05
) and quantity fields (bamnqy
,bamxqy
, perjk03
). -
Stores contract number (
bacntn
) and PO/order code (bapoor
, perjk04
). -
Tables Used:
-
bicuag
,bicont
,bicua3
,bicuagh
. -
External Programs Called:
QCMDEXC
(for file overrides).GSDTCLC1
(implied for date calculations).
Due to the truncation of the source code, details of the main processing loop and parts of the writercd
subroutine are incomplete. If you can provide the complete BB9433.rpgle
code or specific sections (e.g., full writercd
logic), I can refine the process steps and business rules further. Additionally, if you have related files (e.g., BB943
full source, display file bb943d
, or GSDTCLC1
), I can provide more context. Let me know how you’d like to proceed!