BB204 RPGLE
The BB204.rpgle
program is an RPG IV program designed to auto-post customer sales agreement pricing in the Customer Pricing system. It is called from the BB204.ocl36
OCL script, as previously discussed, and processes pricing records, updates existing records, and maintains a history of changes. Below, I will explain the process steps, business rules, tables used, and external programs called, referencing the provided RPGLE source code.
Process Steps of the BB204 RPG Program¶
The program follows a structured process to validate input, process pricing records, update the customer agreement file, and maintain a historical record. Here’s a detailed breakdown of the process steps based on the RPGLE code:
- Initialization (
*inzsr
Subroutine): - Purpose: Sets up the environment, opens files, and initializes variables.
- Receives a parameter
p$fgrp
(file group, either 'G' or 'Z') to determine file overrides. - Executes file overrides for database files (
bicuag
,bicont
,bicuagh
,bb204t
) and the printer file (qsysprt
) using theQCMDEXC
API to apply overrides defined inovg
orovz
arrays based onp$fgrp
. - Opens database files (
bicuag
,bb204t
,bicont
,bicuagh
) and the printer file (qsysprt
). - Initializes date and time fields using the system timestamp (
t#time
) and formats the current date intot#cymd
(CCYYMMDD format). - Clears message handling fields and sets up the message queue for error handling.
-
Initializes the display file (
bb204d
) and printer file headers for reporting. -
Main Processing Loop (
Process
Subroutine): - Purpose: Manages the display file interaction and orchestrates the main processing logic.
- Displays a message subfile if errors exist (
wrtmsg
subroutine) or clears the screen (clrscr
) if no messages are pending. - Presents the
pstscn
format (likely a screen for user input) usingEXFMT
and checks for function keys (F12 to exit, F09 to post). - Validates the start date entered by the user (
editstrdate
subroutine). - If the start date is valid (
*in50 = *off
):- Converts the input start date (
p#cymd
) to working fields (w1strcymd
,w1strymd
). - Calculates the expiration date as one day prior to the start date using the
GSDTCLC1
program (called viaPLDTCLC1
parameter list). - Stores the calculated expiration date in
w1endcymd
,newendd8
, andnewendd6
.
- Converts the input start date (
- If the start date is invalid, sets error indicators (
*in51
,*in53
), adds an error message (ERR0020
), and iterates the loop to redisplay the screen. -
If F09 is pressed and the start date is valid, calls the
postit
subroutine to process the pricing updates. -
Date Validation (
editstrdate
Subroutine): - Purpose: Validates the user-entered start date (
s1stdt
) to ensure it is a valid date and matches the start date in thebb204t
work file. - Breaks down the input date into month, day, and year components.
- Validates the month (must be 1–12).
- Validates the day based on the month:
- For February, checks for leap years (divisible by 4 for non-century years, or by 400 for century years) to allow 29 days in leap years or 28 days otherwise.
- For other months, allows 30 or 31 days based on standard calendar rules.
- If the date is invalid, sets indicator
*in51
(error) and*in50
to trigger an error message. -
If valid, converts the date to
p#cymd
(CCYYMMDD format) and checks if it matches the start date inbb204t
(new_banstd
). If not, sets an error (ERR0000
) with the expected start date frombb204t
. -
Posting Logic (
postit
Subroutine): - Purpose: Processes records from
bb204t
, updates the customer agreement file (bicuag
), and writes to the history file (bicuagh
). - Reads records from
bb204t
sequentially until end-of-file (%eof
). - For each record:
- Update Existing Record:
- Chains to
bicuag
using keysnew_bacono
(company number) andnew_baseqn
(sequence number). - If a record is found (
%found
):- Stores old values (
oldprice
,oldoffp
,oldenddt
,oldstrdt
,oldcntn
) for reporting. - Checks if the existing record’s expiration date (
baend8
) is greater than the new record’s start date (w1strcymd
) or is zero. - If true, updates the expiration date (
baendt
,baend8
) to the calculated end date (w$endt
,w1endcymd
) with an end time of 23:59 and sets indicator*in65
. - Updates the last updated date (
baludt
) and time (balutm
) with the current timestamp. - Writes the updated record to
bicuag
. - If
*in65
is on, writes the original record to the history file (bicuagh
) viawritehistorg
.
- Stores old values (
- If no record is found, clears old values and proceeds.
- Create New Price Record:
- Retrieves the next sequence number (
w$sq
) frombicont
viartvnxtsqky
. - Chains to
bicuag
with the new sequence number to ensure no conflict. - If no record exists, clears the
bicuag
record and populates fields frombb204t
(e.g.,new_badel
,new_bacono
,new_bacust
, etc.). - Sets creation and update timestamps (
bacrdt
,bacrtm
,baludt
,balutm
), start date (bastdt
,bastd8
), and end date (baendt
,baend8
). - Writes the new record to
bicuag
and the history file (bicuagh
) viawritehist
. - Prints a detail line (
dtl01
) toqsysprt
for reporting, including old and new pricing details.
-
Sets
fmtagn
to*off
to exit the main loop after processing. -
Sequence Number Retrieval (
rtvnxtsqky
Subroutine): - Purpose: Retrieves and increments the sequence number for new records in
bicuag
. - Chains to
bicont
usingnew_bacono
to get the current sequence number (bcseqn
). -
If found, increments the sequence number (
w$sq = bcseqn + 1
), updatesbicont
, and stores the new value. -
History File Writing (
writehist
andwritehistorg
Subroutines): - writehist: Writes a new pricing record to
bicuagh
with fields frombb204t
, including timestamps and the new sequence number (w$sq
). Sets the start date, end date, and change timestamp (hhchd8
,hhchtm
) to the current date/time. -
writehistorg: Writes the original (expired)
bicuag
record tobicuagh
when an existing record is updated, preserving its original fields and setting the change timestamp to the current date/time. -
Printer Overflow Handling (
ovrflo
Subroutine): - Purpose: Manages printer file overflow for the report.
- If the overflow indicator (
*inof
) is on, setsprtovr
to trigger a header print. -
If
prtovr
is on, prints the report header (hdr01
) and resetsprtovr
. -
Message Handling (
addmsg
,wrtmsg
,clrmsg
Subroutines): - addmsg: Sends an error message to the program message queue using
QMHSNDPM
, specifying the message ID, file (GSMSGF
), and data. - wrtmsg: Displays the message subfile (
msgctl
) when errors are present. -
clrmsg: Clears the message subfile using
QMHRMVPM
, preserving the current record format and subfile page. -
Program Termination:
- Closes all files (
close *all
). - Sets
*inlr = *on
to indicate the last record and returns control to the caller.
Business Rules¶
The program enforces the following business rules, based on the code and comments:
- Start Date Validation:
- The user-entered start date (
s1stdt
) must be a valid date (correct month, day, and leap year handling). -
It must match the start date in the
bb204t
work file (new_banstd
). If not, an error (ERR0000
) is displayed with the expected date. -
Expiration Date Calculation:
- The expiration date for new records is set to one day before the start date of the new record (calculated via
GSDTCLC1
). -
For existing records in
bicuag
, the expiration date is updated only if:- The current expiration date (
baend8
) is greater than the new record’s start date (w1strcymd
), or - The current expiration date is zero (indicating no expiration).
- The current expiration date (
-
Record Update and History:
- If an existing
bicuag
record is found for the company and sequence number, it is updated with a new expiration date and written to the history file (bicuagh
) if modified. - New pricing records are created in
bicuag
with a new sequence number retrieved frombicont
. -
Both new and expired records are written to
bicuagh
for audit purposes, with timestamps and user IDs. -
Sequence Number Management:
-
The sequence number (
baseqn
) for newbicuag
records is incremented from the last value stored inbicont
to ensure uniqueness. -
Date Format:
- Dates are handled in CCYYMMDD format (
w1strcymd
,w1endcymd
) with century indicators (w$strcen
,w$endcen
) to distinguish between 19xx and 20xx years. -
Start times for new records are set to 00:00, and end times are set to 23:59.
-
Reporting:
-
A printed report is generated with headers and detail lines, including company, customer, location, pricing, and sequence number details (old and new values).
-
Error Handling:
- Invalid dates trigger error messages (
ERR0020
for format errors,ERR0000
for mismatched start dates). -
The program uses a message subfile to display errors to the user and allows re-entry until valid data is provided.
-
File Group Handling:
- The program supports two file groups (
G
orZ
), which determine the library for file overrides (gbicuag
vs.zbicuag
, etc.).
Tables (Files) Used¶
The program uses the following files, as defined in the file specifications (F
specs) and overrides:
1. bicuag (Customer Agreement File):
- File: bicuag
(renamed to bicuagrd
internally).
- Usage: Update (uf
), add (a
), externally described (e
), keyed (k
), user-opened (usropn
).
- Purpose: Stores customer pricing agreement records. Updated with new expiration dates or new records.
- Override: gbicuag
(for p$fgrp = 'G'
) or zbicuag
(for p$fgrp = 'Z'
).
- bb204t (Work File):
- File:
bb204t
. - Usage: Input (
if
), externally described (e
), keyed (k
), user-opened (usropn
), prefixed withnew_
. - Purpose: Contains input pricing records to be processed.
-
Override:
gbb204t
(forp$fgrp = 'G'
) orzbb204t
(forp$fgrp = 'Z'
). -
bicont (Control File):
- File:
bicont
. - Usage: Update (
uf
), add (a
), externally described (e
), keyed (k
), user-opened (usropn
). - Purpose: Stores the last sequence number (
bcseqn
) for generating newbicuag
records. -
Override:
gbicont
(forp$fgrp = 'G'
) orzbicont
(forp$fgrp = 'Z'
). -
bicuagh (History File):
- File:
bicuagh
. - Usage: Output (
o
), externally described (e
), keyed (k
), user-opened (usropn
). - Purpose: Stores historical records of both new and expired pricing agreements.
-
Override:
gbicuagh
(forp$fgrp = 'G'
) orzbicuagh
(forp$fgrp = 'Z'
). -
bb204d (Display File):
- File:
bb204d
. - Usage: Combined (
cf
), externally described (e
), workstation file (workstn
), with an information data structure (infds
). -
Purpose: Provides the user interface for entering and validating the start date.
-
qsysprt (Printer File):
- File:
qsysprt
. - Usage: Output (
o
), fixed-length 184 characters, user-opened (usropn
), with overflow indicator (*inof
). - Purpose: Generates a report of posted pricing changes.
- Override: Configured with
PAGESIZE(68 184)
,LPI(8)
,CPI(15)
,OVRFLW(62)
,OUTQ(*JOB)
,HOLD(*YES)
,SAVE(*YES)
.
Note: The file biagnew
is commented out (jb01
), indicating it was previously used but is no longer part of the process.
External Programs Called¶
The program calls the following external program:
1. GSDTCLC1:
- Called via the pldtclc1
parameter list in the Process
subroutine.
- Purpose: Calculates the date difference (in days) to determine the expiration date as one day prior to the input start date.
- Parameters:
- p#dat1
: Input date (CCYYMMDD).
- p#dat2
: Output date (CCYYMMDD).
- p#fmt
: Format ('D' for days).
- p#diff
: Date difference (set to -1 for one day prior).
- p#err
: Error flag ('Y' if an error occurs).
Additionally, the program uses system APIs: - QCMDEXC: Executes file override commands for database and printer files. - QMHSNDPM: Sends messages to the program message queue. - QMHRMVPM: Removes messages from the message queue.
Summary¶
The BB204
RPG program automates the posting of customer sales agreement pricing by:
- Validating a user-entered start date against the bb204t
work file.
- Processing records from bb204t
to update or create pricing records in bicuag
.
- Maintaining a history of changes in bicuagh
.
- Managing sequence numbers via bicont
.
- Generating a printed report via qsysprt
.
- Handling errors through a message subfile and user interaction.
Business Rules:
- Start dates must be valid and match bb204t
.
- Expiration dates are calculated as one day prior to the start date.
- Existing records are updated only if their expiration date is greater than the new start date or zero.
- All changes are logged to the history file with timestamps and user IDs.
- Sequence numbers are incremented uniquely for new records.
Tables Used: bicuag
, bb204t
, bicont
, bicuagh
, bb204d
(display), qsysprt
(printer).
External Programs Called: GSDTCLC1
(date calculation), plus system APIs QCMDEXC
, QMHSNDPM
, and QMHRMVPM
.