FR105P RPGLE
The RPG program FR105P is designed for managing freight out balancing customer invoices within a Traffic/Freight Invoicing system. It provides an interactive interface using a display file with a subfile to allow users to view, filter, and process freight invoice records. Below is a detailed explanation of the process steps, followed by a list of external programs called and database tables used.
Process Steps of FR105P¶
- Program Initialization (
*inzsrSubroutine): - Receives input parameters:
p$mode(run mode: maintenance or inquiry) andp$fgrp(file group: 'Z' or 'G'). - Initializes variables, including subfile control fields, message handling fields, and key lists.
- Sets up work fields for date and time handling, using the current system date and time.
-
Defines key lists (
klsfl1,kls1s1, etc.) for database access and sets default values for headers and function key labels. -
Open Database Tables (
opntblSubroutine): - Applies file overrides based on the
p$fgrpparameter ('G' or 'Z'), redirecting file access to appropriate libraries (e.g.,garcustorzarcust). -
Opens the input-only database files:
arcust,frbinh,frbinh1(renamed record format), andshipto. -
Process Subfile (
srsfl1Subroutine): - Clear Message Subfile: Clears any existing messages in the message subfile (
clrmsg) and writes the message control (wrtmsg). - Initialize Subfile Mode: Sets the subfile to folded mode (
sfmod1 = '1',*in45 = *on) for the initial load. - Initialize Control Fields: Sets default values for subfile control fields (e.g.,
c1co = 10) and the include/exclude deleted entries filter (w$del = *off). - Set Protection Mode: Based on
p$mode, enables (*in70 = *on) or disables (*in70 = *off) global input protection for inquiry or maintenance mode. - Position File: Calls
sf1repto position the file pointer based on user input or defaults. -
Main Loop:
- Displays the command line and message subfile.
- Checks if subfile records exist to enable display (
*in41forSFLDSP). - Sets folded/unfolded mode based on
sfmod1. - Displays the subfile control (
sflctl1) usingexfmt. - Clears message subfile and format indicators after display.
- Determines cursor location for the next display.
- Initializes the subfile record number (
rcdnb1) with the lowest subfile record number (pagrrn) for proper page redisplay. - Processes user input (function keys, enter, or repositioning):
- F03: Exits the program.
- F04: Prompts for field input (calls
promptsubroutine). - F05: Refreshes the subfile by clearing positioning fields and repositioning (
repsfl = *on). - F08: Toggles the include/exclude deleted entries filter (
w$del) and updates the function key label (s1f08d). - PAGEDN: Loads additional subfile records (
sf1lod). - ENTER: Processes subfile records (
sf1prc). - Repositioning: If control fields (e.g.,
c1co,c1rdno) differ from saved values, repositions the subfile (sf1rep). - F10: Resets cursor to the control record.
-
Process Subfile on ENTER (
sf1prcSubroutine): - Reads changed subfile records (
readc sfl1) if the subfile is not empty (rrn1 > 0). -
Processes each changed record by calling
sf1chg. -
Process Subfile Record Change (
sf1chgSubroutine): - Saves selected subfile values (
s1co,s1rdno,s1srn) into work fields (s$co,s$ord#,s$srn). - Constructs a descriptive string (
s$item) for the selected entry. - Processes the subfile option (
s1opt):- If
s1opt = 1, callssf1s01to handle the "Create" action.
- If
-
Updates the subfile record:
- Chains to
frbinhusing the key listklsfl1to retrieve the latest data. - Chains to the subfile record (
sfl1) to update it. - Clears the option field (
s1opt), formats the subfile line (sf1fmt), applies color coding (sf1col), and updates the subfile record.
- Chains to
-
Reposition Subfile (
sf1repSubroutine): - Clears the subfile (
sf1clr) and resets the relative record number (rrn1). - Validates subfile control input (
sf1cte). - If no errors (
*in50 = *off), positions the file pointer usingsetllonfrbinh1and loads subfile records (sf1lod). -
Saves control fields (
c1co,c1rdno, etc.) for future repositioning. -
Edit Subfile Control Input (
sf1cteSubroutine): -
Currently commented out, but intended to validate the company number (
c1co) against a control file (prcontc). If invalid, it would set an error message (ERR0021) and error indicators (*in50,*in51). -
Load Subfile Records (
sf1lodSubroutine): - Sets the relative record number (
rrn1) to the last saved value (rrnsv1) to append records. - Sets the subfile record number (
rcdnb1) to ensure the new page is displayed correctly. - Loads up to
pagsz1(32) records:- Reads the next record from
frbinh1based on the company number (c1co) or sequentially. - Applies filters:
- Skips deleted records (
bodel = 'D') ifw$del = *off. - Skips records not matching user-specified filters (
c1co,c1rdno,c1cust,c1ship,c1invn,c1car). - Skips customer-owned products (
bocoon = 'Y') [jb02]. - Skips records with freight code 'C' (collect) and calculated freight 'N' (
bocafr = 'N') [jb03, jb04]. - Applies open/closed filter (
c1clos) [jb01]. - Formats the subfile line (
sf1fmt), applies color coding (sf1col), and writes the record to the subfile.
- Reads the next record from
-
Saves the last relative record number (
rrnsv1). -
Format Subfile Detail Line (
sf1fmtSubroutine): - Clears the subfile record.
- Populates subfile fields (
s1co,s1rdno,s1srn,s1cust,s1ship,s1invn,s1indt,s1shdt,s1car,s1caid,s1frcd,s1clos,s1del) from thefrbinhrecord. - Retrieves the customer name (
s1csnm) fromarcustusing the key listklcust. -
Retrieves the ship-to name (
s1shnm) by callingrtvshipto. -
Retrieve Ship-to Name (
rtvshiptoSubroutine):- Handles different ship-to scenarios:
- If
s1ship = 0, uses the customer name (arname) fromarcust. - If
s1ship < 900, chains toshiptousingklshipcst(company/customer/ship-to). - If
s1ship >= 900, chains toshiptousingklship999(company/customer/999) or falls back toklshipcstfors1shipbetween 900 and 998. - Sets the ship-to name (
s1shnm) if the chain is successful.
-
Subfile Color Coding (
sf1colSubroutine):- Sets the color indicator (
*in72) to blue for deleted records (s1del = 'D').
- Sets the color indicator (
-
Clear Subfile (
sf1clrSubroutine):- Resets
rrn1andrrnsv1to zero. - Disables subfile display (
*in41) and control (*in40), enables clear (*in42), writes the subfile control (sflctl1), and resets the clear indicator.
- Resets
-
Subfile Option 01 - Create (
sf1s01Subroutine):- Saves the cursor location.
- Calls the external program
FR105with parameters for company, order, shipping reference, mode, file group, and a return flag. - If the return flag (
o$flag = '1') indicates success, sends a confirmation message (ERR0000) with the modified entry details and triggers a subfile reposition (repsfl = *on).
-
Field Prompting (
promptSubroutine):- Handles prompting for customer (
c1cust) or ship-to (c1ship) fields in the subfile control (SFLCTL1). - Calls
LCSTSHPwith parameters to retrieve customer and ship-to data. - Updates
c1custandc1shipif valid values are returned. - Sets
*in19to indicate a panel format input change.
- Handles prompting for customer (
-
Message Handling (
addmsg,wrtmsg,clrmsgSubroutines):- addmsg: Sends a message to the program message queue using
QMHSNDPM, setting the message ID, file, data, type, and other parameters. - wrtmsg: Writes the message subfile control (
msgctl) with*in49enabled. - clrmsg: Clears the message subfile using
QMHRMVPM, saving and restoring the current record format and page number.
- addmsg: Sends a message to the program message queue using
-
Program Termination:
- Closes all open files (
close *all). - Sets the last record indicator (
*inlr = *on) and returns.
- Closes all open files (
External Programs Called¶
- FR105:
- Called in the
sf1s01subroutine to handle the "Create" action for a selected subfile record. -
Parameters:
o$co: Company number.o$ord#: Customer order number.o$srn: Shipping reference number.o$mode: Run mode ('MNT' for maintenance).o$fgrp: File group ('Z' or 'G').o$flag: Return flag indicating success ('1') or failure.
-
LCSTSHP:
- Called in the
promptsubroutine to provide prompting for customer and ship-to fields. -
Parameters:
x$cstshp: Data structure containing company (x$co), search string (x$srch), customer (x$cust), ship-to (x$ship), flag (x$flag), and file group (x$fgrp).
-
QCMDEXC:
- Called in the
opntblsubroutine to execute file override commands (e.g.,ovrdbf). -
Parameters:
dbov##: Override command string (80 characters).dbol##: Length of the command (15.5).
-
QMHSNDPM:
- Called in the
addmsgsubroutine to send messages to the program message queue. -
Parameters:
m@id: Message ID.m@msgf: Message file name (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 the
clrmsgsubroutine to 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.
Database Tables Used¶
- arcust:
- Input-only file containing customer master data.
- Used to retrieve the customer name (
arname) in thesf1fmtsubroutine. -
Keyed access using
klcust(company and customer number). -
frbinh:
- Input-only file containing freight invoice header data.
- Used to retrieve invoice details for subfile records.
-
Keyed access using
klsfl1(company, order number, shipping reference number). -
frbinh1:
- Input-only file, a renamed version of
frbinh(record formatfrbinhp1). - Used for reading invoice records during subfile loading (
sf1lod) and positioning (sf1rep). -
Keyed access using
kls1s1orkls1r3(company number). -
shipto:
- Input-only file containing ship-to address data.
- Used to retrieve the ship-to name (
csname) in thertvshiptosubroutine. - Keyed access using
klshipcst(company, customer, ship-to) orklship999(company, customer, 999).
Additional Notes¶
- The program uses a display file (
fr105pd) with a subfile (sfl1) and control (sflctl1) to present freight invoice data. - Revisions (jb01–jb04) add filtering for open/closed status, skip customer-owned products, and handle freight code and calculated freight conditions.
- The program supports maintenance (
MNT) and inquiry modes, with global input protection in inquiry mode. - Function keys (F03, F04, F05, F08, F10, PAGEDN, ENTER) provide user interaction for navigation, prompting, refreshing, filtering, and repositioning.
- The subfile supports pagination, filtering (e.g., include/exclude deleted records), and color coding for deleted entries.
This program is a typical AS/400 RPG application, leveraging subfiles for interactive data display and processing, with robust error handling and database access.