FR105 RPGLE
The RPG program FR105 is a component of the Freight Invoicing system, designed for freight out bill balancing. It is called from the main program FR105P to handle detailed processing of freight invoice records for a specific company, order, and shipping reference number. The program uses a display file with two subfiles (sfl1 and sfl1b) to allow users to manage carrier invoice details and view order details/miscellaneous charges. Below is a detailed explanation of the process steps, business rules, database tables used, and external programs called.
Process Steps of FR105¶
- Program Initialization (
*inzsrSubroutine): - Receives Input Parameters:
p$co: Company number.p$ord#: Customer order number.p$srn: Shipping reference number.p$mode: Run mode (MNTfor maintenance,INQfor inquiry).p$fgrp: File group (ZorGfor different file libraries).p$flag: Return flag to indicate processing outcome.
- Initializes variables:
- Sets subfile control fields (
rrn1,rrnsv1,rrn1b,rrnsv1b) to zero. - Defines page size (
pagsz1 = 8) for subfilesfl1. - Initializes date and time fields using the system date (
ps#mdy) and century logic. - Sets up message handling fields (
dspmsg,m@pgmq,m@key) and key lists (klc1s1,klfrbinh, etc.). - Moves input parameters to format fields (
f$co,f$ord#,f$srn) for display.
- Sets subfile control fields (
-
Sets the header (
c$hdr1) for the display format. -
Open Database Tables (
opntblSubroutine): - Applies file overrides based on
p$fgrp(GorZ) to redirect file access to the appropriate library (e.g.,gfrbinhorzfrbinh) usingQCMDEXC. - Opens input-only files:
frbinf,frcinhj1,bbcaid,sa5shy,sa5fjxd,sa5fjxm,apveny. -
Opens update files:
frbinh,frcinh,frcfbh,frcind. -
Retrieve Data for Passed Parameters (
rtvdtaSubroutine): - Chains to
frbinhusingklfrbinh(company, order, shipping reference) to validate the input record.- If not found (
*in99 = *on), setsp$flag = '1', closes files, and exits.
- If not found (
- Chains to
frbinfto retrieve additional invoice details, clearing the record if not found. - Reformats dates (
boind8,boshd8,bocld8) into display format (f$imdy,f$smdy,f$cmdy) using the date conversion data structure. - Retains shipped month (
w$smth,w$scy,w$sm) for subfile input editing. -
Calculates invoice total (
clcinvtot) and carrier freight total (clccarfrt). -
Calculate Invoice Total (
clcinvtotSubroutine): - Clears the invoice total (
f$itot). - Reads sales history records (
sa5shy) usingklfrbinhto match company, order, and shipping reference. -
Reads invoice detail (
sa5fjxd) and miscellaneous records (sa5fjxm) usingklfix:- For detail records (
samscd = *blanks), calculates freight assaqty * safrrtand adds tof$itotifs afrå *sfrt <> 'Y'. - For miscellaneous records (
samscd <> *blanks,samsty = 'F'), calculates freight assamqty * samamtand adds tof$itot.
- For detail records (
-
Calculate Carrier Freight Total (
clccarfrtSubroutine): - Clears the carrier freight total (
f$cftl). - Reads carrier invoice header records (
frcinhj1) usingklfrbinh, excluding deleted records (frdel <> 'D').- Adds invoice amount (
frinam) and ejected - Subtracts freight balancing order override total (
frfboa) [jb06]. - Updates
f$cftlwith the total.
- Adds invoice amount (
-
Calculates the freight difference (
clcfrtdiff) betweenf$cftland expected (cftfam) or actual (bftfam) freight amounts. -
Process Subfile (
srsfl1Subroutine): - Clear Message Subfile: Calls
clrmsgandwrtmsgto manage messages. - Load Subfile
sfl1b: Callssf1lodallbto load all order detail and miscellaneous records. - Position File: Calls
sf1repto position the subfile based on user input. -
Main Loop:
- Displays the command line (
sflcmd1) and message subfile. - Checks for existing records in
sfl1andsfl1bto enable display indicators (*in41,*in31). - Displays subfile control (
sflctl1b,sflctl1) and processes user input: - F03: Exits the program.
- F04: Prompts for carrier ID input (
prompt) and updates the subfile record. - F05: Refreshes the subfile (
repsfl = *on). - F06: Adds a blank subfile record for a new carrier invoice.
- F09: Updates the invoice date (
sf1upd) and refreshes the subfile [jk01]. - F10: Resets the cursor to the control record.
- F23: Deletes a paper invoice record (
sf1del) if not in inquiry mode and conditions are met (s1inty = 'P',s1apst = *blanks) [jb05]. - PAGEDN: Loads additional subfile records (
sf1lod). - ENTER: Processes changed subfile records (
sf1prc). - Handles control field changes (
sf1ctledt,sf1ctlupd) and cursor positioning.
- Displays the command line (
-
Process Subfile on ENTER (
sf1prcSubroutine): - Reads changed records in
sfl1usingreadc. -
Processes each changed record (
sf1chg) and updates the subfile. -
Process Subfile Record Change (
sf1chgSubroutine): - Edits subfile input (
sf1edt). - Updates the database (
sf1upd) if no errors (*in50 = *off) and not in inquiry mode. -
Applies processing logic (
sf1pro). -
Edit Subfile Input (
sf1edtSubroutine): - Validates carrier ID (
s1caid):- Chains to
bbcaid(formerlygstabl[jk03]) to verify the carrier ID. - If invalid or blank, sets error message
ERR0010and indicators (*in50,*in61). - Retrieves carrier name (
cicanm) if valid.
- Chains to
-
Validates vendor linkage (
apveny) for the carrier ID [jk02]:- If not linked, sets error message
ERR0037.
- If not linked, sets error message
-
Load Subfile Records (
sf1lodSubroutine):- Loads up to
pagsz1(8) records intosfl1fromfrcinhj1, excluding deleted records (frdel = 'D'). - Formats (
sf1pro) and writes records to the subfile.
- Loads up to
-
Load All Subfile Records (
sf1lodallbSubroutine):- Clears
sfl1band loads sales history (sa5shy), invoice detail (sa5fjxd), and miscellaneous records (sa5fjxm) for the order. - Filters miscellaneous records to exclude blank
samscdand include freight-related records (samsty = 'F', excludingsamscd = 'F'[jb03]). - Formats and writes records to
sfl1b.
- Clears
-
Subfile Processing (
sf1proSubroutine):- Applies formatting and validation logic for subfile records (details omitted due to truncation).
-
Field Prompting (
promptSubroutine):- Handles prompting for carrier ID (
s1caid) by callingLBBCAID(formerlyLGSTABL[jk03]) with parameters for company, carrier ID, and file group. - Updates
s1caidif a valid value is returned. - Sets
*in19for panel input change.
- Handles prompting for carrier ID (
-
Message Handling (
addmsg,wrtmsg,clrmsgSubroutines):- addmsg: Sends messages to the program message queue using
QMHSNDPM. - wrtmsg: Writes the message subfile control (
msgctl). - clrmsg: Clears the message subfile using
QMHRMVPM.
- addmsg: Sends messages to the program message queue using
-
Program Termination:
- Closes all files (
close *all). - Sets
*inlr = *onand returns.
- Closes all files (
Business Rules¶
- Input Validation:
- Validates carrier ID against
bbcaid(formerlygstabl[jk03]) and ensures it is linked to a vendor inapveny[jk02]. - Displays error messages (
ERR0010,ERR0037) for invalid or unlinked carrier IDs. -
Validates invoice dates using
GSDTEDIT[assumed frompldtedparameter list]. -
Freight Calculations:
- Calculates invoice total (
f$itot) by summing freight amounts from detail (saqty * safrrt) and miscellaneous records (samqty * samamt) wheresasfrt <> 'Y'andsamsty = 'F'. - Calculates carrier freight total (
f$cftl) fromfrcinhj1, excluding deleted records, and adjusts for freight balancing order override (frfboa) [jb06]. -
Computes the difference between actual and expected freight amounts (
f$diff). -
Subfile Filters:
- Excludes deleted carrier invoice records (
frdel = 'D') [jb05]. - Filters miscellaneous records to exclude
samscd = 'F'(separate freight) [jb03]. -
Only lists detail and miscellaneous records for the specified order and shipping reference number [jb01, jb02].
-
Mode Restrictions:
- In inquiry mode (
p$mode = 'INQ'), input fields are protected (*in70-79), and updates/deletes are disabled. -
In maintenance mode (
p$mode = 'MNT'), allows updates and deletes of paper invoices (s1inty = 'P',s1apst = *blanks) [jb05]. -
Deletion Rules:
-
Only paper invoices (
s1inty = 'P') with no A/P invoice status (s1apst = *blanks) can be deleted using F23 [jb05]. -
Multi-File Logical Support:
-
Uses multi-file logical files
sa5fjxd,sa5fjxm, andfrcinhj1to include product move records alongside invoice details [jb06]. -
Function Key Actions:
- F03: Exits the program.
- F04: Prompts for carrier ID input.
- F05: Refreshes the subfile.
- F06: Adds a blank carrier invoice record.
- F09: Accepts invoice date changes [jk01].
- F10: Positions cursor to the control record.
- F23: Deletes a paper invoice record under specific conditions.
Database Tables Used¶
- frbinf:
- Input-only file for freight invoice details.
-
Used in
rtvdtato retrieve invoice data. -
frbinh:
- Update file for freight invoice headers.
-
Used in
rtvdtato validate input parameters. -
frcinh:
- Update file for carrier invoice headers.
-
Used in
sf1updto update carrier invoice records. -
frcfbh:
- Update file for freight billed balance headers [jb06].
-
Used in
sf1updto update freight balancing records. -
frcind:
- Update file for carrier invoice details.
-
Used in
sf1delandsf1updfor deleting and updating records. -
frcinhj1:
- Input-only multi-file logical file (replaces
frcinh1[jb06]) for carrier invoice headers and freight billed balance headers. -
Used in
sf1lodandclccarfrtto load subfile records and calculate totals. -
bbcaid:
- Input-only file for carrier ID validation (replaces
gstabl[jk03]). -
Used in
sf1edtto validates1caidand retrieve carrier name (cicanm). -
sa5shy:
- Input-only file for sales history.
-
Used in
sf1lodallbandclcinvtotto load order details and calculate invoice totals. -
sa5fjxd:
- Input-only multi-file logical file (replaces
sa5fixd[jb06]) for invoice and product move detail records. -
Used in
sf1lodallbandclcinvtotto calculate freight amounts. -
sa5fjxm:
- Input-only multi-file logical file (replaces
sa5fixm[jb06]) for miscellaneous and product move records. - Used in
sf1lodallbandclcinvtotto calculate freight amounts.
- Input-only multi-file logical file (replaces
-
apveny:
- Input-only file for vendor data.
- Used in
sf1edtto ensure carrier ID is linked to a vendor [jk02].
External Programs Called¶
- QCMDEXC:
- Called in
opntblto execute file override commands (ovrdbf). -
Parameters:
dbov##: Override command string (80 characters).dbol##: Command length (15.5).
-
QMHSNDPM:
- Called in
addmsgto send messages to the program message queue. -
Parameters:
m@id: Message ID.m@msgf: Message file (GSMSGF).m@data: Message data.m@l: Message data length.m@type: Message type (*DIAG).m@pgmq: Program message queue (*).m@scnt: Stack counter.m@key: Message key.m@errc: Error code.
-
QMHRMVPM:
- Called in
clrmsgto clear messages from the program message queue. -
Parameters:
m@pgmq: Program message queue.m@scnt: Stack counter.m@rmvk: Message key for removal.m@rmv: Removal option (*ALL).m@errc: Error code.
-
LBBCAID:
- Called in
promptto handle carrier ID prompting (replacesLGSTABL[jk03]). -
Parameters:
o$co: Company number.o$caid: Carrier ID (input/output).o$fgrp: File group.
-
GSDTEDIT (Assumed):
- Implied by the
pldtedparameter list in*inzsrfor date validation. - Parameters:
p#mdy: Date in MMDDYY format.p#cymd: Date in CCYYMMDD format.p#err: Error flag.
Additional Notes¶
- The program is tightly integrated with
FR105P, which callsFR105to handle detailed freight invoice processing (e.g.,sf1s01inFR105P). - Revisions enhance functionality:
- jb01: Filters order detail/misc records by shipping reference number and improves freight calculations.
- jb02: Includes both detail and miscellaneous records in
sfl1b. - jb03: Excludes
samscd = 'F'to prevent doubling of separate freight charges. - jk02: Ensures carrier IDs are linked to vendors.
- jb05: Fixes deletion of carrier invoice detail records.
- jb06: Supports multi-file logical files for product moves and freight balancing headers, adjusting freight calculations.
- jk03: Replaces
gstablwithbbcaidfor carrier ID validation. - jk04: Renames duplicate fields in
s5movdpf. - The program uses two subfiles:
sfl1: Displays carrier invoice records.sfl1b: Displays order detail and miscellaneous records.- The program supports maintenance and inquiry modes, with restrictions on updates/deletes in inquiry mode.
- Error handling includes validation of carrier IDs, vendor linkage, and invoice dates, with appropriate error messages displayed in the message subfile.
This program is a critical component for managing freight out bill balancing, providing detailed control over carrier invoices and order details within an AS/400 environment.