Skip to content

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

  1. Program Initialization (*inzsr Subroutine):
  2. Receives Input Parameters:
    • p$co: Company number.
    • p$ord#: Customer order number.
    • p$srn: Shipping reference number.
    • p$mode: Run mode (MNT for maintenance, INQ for inquiry).
    • p$fgrp: File group (Z or G for different file libraries).
    • p$flag: Return flag to indicate processing outcome.
  3. Initializes variables:
    • Sets subfile control fields (rrn1, rrnsv1, rrn1b, rrnsv1b) to zero.
    • Defines page size (pagsz1 = 8) for subfile sfl1.
    • 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.
  4. Sets the header (c$hdr1) for the display format.

  5. Open Database Tables (opntbl Subroutine):

  6. Applies file overrides based on p$fgrp (G or Z) to redirect file access to the appropriate library (e.g., gfrbinh or zfrbinh) using QCMDEXC.
  7. Opens input-only files: frbinf, frcinhj1, bbcaid, sa5shy, sa5fjxd, sa5fjxm, apveny.
  8. Opens update files: frbinh, frcinh, frcfbh, frcind.

  9. Retrieve Data for Passed Parameters (rtvdta Subroutine):

  10. Chains to frbinh using klfrbinh (company, order, shipping reference) to validate the input record.
    • If not found (*in99 = *on), sets p$flag = '1', closes files, and exits.
  11. Chains to frbinf to retrieve additional invoice details, clearing the record if not found.
  12. Reformats dates (boind8, boshd8, bocld8) into display format (f$imdy, f$smdy, f$cmdy) using the date conversion data structure.
  13. Retains shipped month (w$smth, w$scy, w$sm) for subfile input editing.
  14. Calculates invoice total (clcinvtot) and carrier freight total (clccarfrt).

  15. Calculate Invoice Total (clcinvtot Subroutine):

  16. Clears the invoice total (f$itot).
  17. Reads sales history records (sa5shy) using klfrbinh to match company, order, and shipping reference.
  18. Reads invoice detail (sa5fjxd) and miscellaneous records (sa5fjxm) using klfix:

    • For detail records (samscd = *blanks), calculates freight as saqty * safrrt and adds to f$itot if s afr坠 *sfrt <> 'Y'.
    • For miscellaneous records (samscd <> *blanks, samsty = 'F'), calculates freight as samqty * samamt and adds to f$itot.
  19. Calculate Carrier Freight Total (clccarfrt Subroutine):

  20. Clears the carrier freight total (f$cftl).
  21. Reads carrier invoice header records (frcinhj1) using klfrbinh, excluding deleted records (frdel <> 'D').
    • Adds invoice amount (frinam) and ejected
    • Subtracts freight balancing order override total (frfboa) [jb06].
    • Updates f$cftl with the total.
  22. Calculates the freight difference (clcfrtdiff) between f$cftl and expected (cftfam) or actual (bftfam) freight amounts.

  23. Process Subfile (srsfl1 Subroutine):

  24. Clear Message Subfile: Calls clrmsg and wrtmsg to manage messages.
  25. Load Subfile sfl1b: Calls sf1lodallb to load all order detail and miscellaneous records.
  26. Position File: Calls sf1rep to position the subfile based on user input.
  27. Main Loop:

    • Displays the command line (sflcmd1) and message subfile.
    • Checks for existing records in sfl1 and sfl1b to 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.
  28. Process Subfile on ENTER (sf1prc Subroutine):

  29. Reads changed records in sfl1 using readc.
  30. Processes each changed record (sf1chg) and updates the subfile.

  31. Process Subfile Record Change (sf1chg Subroutine):

  32. Edits subfile input (sf1edt).
  33. Updates the database (sf1upd) if no errors (*in50 = *off) and not in inquiry mode.
  34. Applies processing logic (sf1pro).

  35. Edit Subfile Input (sf1edt Subroutine):

  36. Validates carrier ID (s1caid):
    • Chains to bbcaid (formerly gstabl [jk03]) to verify the carrier ID.
    • If invalid or blank, sets error message ERR0010 and indicators (*in50, *in61).
    • Retrieves carrier name (cicanm) if valid.
  37. Validates vendor linkage (apveny) for the carrier ID [jk02]:

    • If not linked, sets error message ERR0037.
  38. Load Subfile Records (sf1lod Subroutine):

    • Loads up to pagsz1 (8) records into sfl1 from frcinhj1, excluding deleted records (frdel = 'D').
    • Formats (sf1pro) and writes records to the subfile.
  39. Load All Subfile Records (sf1lodallb Subroutine):

    • Clears sfl1b and loads sales history (sa5shy), invoice detail (sa5fjxd), and miscellaneous records (sa5fjxm) for the order.
    • Filters miscellaneous records to exclude blank samscd and include freight-related records (samsty = 'F', excluding samscd = 'F' [jb03]).
    • Formats and writes records to sfl1b.
  40. Subfile Processing (sf1pro Subroutine):

    • Applies formatting and validation logic for subfile records (details omitted due to truncation).
  41. Field Prompting (prompt Subroutine):

    • Handles prompting for carrier ID (s1caid) by calling LBBCAID (formerly LGSTABL [jk03]) with parameters for company, carrier ID, and file group.
    • Updates s1caid if a valid value is returned.
    • Sets *in19 for panel input change.
  42. Message Handling (addmsg, wrtmsg, clrmsg Subroutines):

    • addmsg: Sends messages to the program message queue using QMHSNDPM.
    • wrtmsg: Writes the message subfile control (msgctl).
    • clrmsg: Clears the message subfile using QMHRMVPM.
  43. Program Termination:

    • Closes all files (close *all).
    • Sets *inlr = *on and returns.

Business Rules

  1. Input Validation:
  2. Validates carrier ID against bbcaid (formerly gstabl [jk03]) and ensures it is linked to a vendor in apveny [jk02].
  3. Displays error messages (ERR0010, ERR0037) for invalid or unlinked carrier IDs.
  4. Validates invoice dates using GSDTEDIT [assumed from pldted parameter list].

  5. Freight Calculations:

  6. Calculates invoice total (f$itot) by summing freight amounts from detail (saqty * safrrt) and miscellaneous records (samqty * samamt) where sasfrt <> 'Y' and samsty = 'F'.
  7. Calculates carrier freight total (f$cftl) from frcinhj1, excluding deleted records, and adjusts for freight balancing order override (frfboa) [jb06].
  8. Computes the difference between actual and expected freight amounts (f$diff).

  9. Subfile Filters:

  10. Excludes deleted carrier invoice records (frdel = 'D') [jb05].
  11. Filters miscellaneous records to exclude samscd = 'F' (separate freight) [jb03].
  12. Only lists detail and miscellaneous records for the specified order and shipping reference number [jb01, jb02].

  13. Mode Restrictions:

  14. In inquiry mode (p$mode = 'INQ'), input fields are protected (*in70-79), and updates/deletes are disabled.
  15. In maintenance mode (p$mode = 'MNT'), allows updates and deletes of paper invoices (s1inty = 'P', s1apst = *blanks) [jb05].

  16. Deletion Rules:

  17. Only paper invoices (s1inty = 'P') with no A/P invoice status (s1apst = *blanks) can be deleted using F23 [jb05].

  18. Multi-File Logical Support:

  19. Uses multi-file logical files sa5fjxd, sa5fjxm, and frcinhj1 to include product move records alongside invoice details [jb06].

  20. Function Key Actions:

  21. F03: Exits the program.
  22. F04: Prompts for carrier ID input.
  23. F05: Refreshes the subfile.
  24. F06: Adds a blank carrier invoice record.
  25. F09: Accepts invoice date changes [jk01].
  26. F10: Positions cursor to the control record.
  27. F23: Deletes a paper invoice record under specific conditions.

Database Tables Used

  1. frbinf:
  2. Input-only file for freight invoice details.
  3. Used in rtvdta to retrieve invoice data.

  4. frbinh:

  5. Update file for freight invoice headers.
  6. Used in rtvdta to validate input parameters.

  7. frcinh:

  8. Update file for carrier invoice headers.
  9. Used in sf1upd to update carrier invoice records.

  10. frcfbh:

  11. Update file for freight billed balance headers [jb06].
  12. Used in sf1upd to update freight balancing records.

  13. frcind:

  14. Update file for carrier invoice details.
  15. Used in sf1del and sf1upd for deleting and updating records.

  16. frcinhj1:

  17. Input-only multi-file logical file (replaces frcinh1 [jb06]) for carrier invoice headers and freight billed balance headers.
  18. Used in sf1lod and clccarfrt to load subfile records and calculate totals.

  19. bbcaid:

  20. Input-only file for carrier ID validation (replaces gstabl [jk03]).
  21. Used in sf1edt to validate s1caid and retrieve carrier name (cicanm).

  22. sa5shy:

  23. Input-only file for sales history.
  24. Used in sf1lodallb and clcinvtot to load order details and calculate invoice totals.

  25. sa5fjxd:

  26. Input-only multi-file logical file (replaces sa5fixd [jb06]) for invoice and product move detail records.
  27. Used in sf1lodallb and clcinvtot to calculate freight amounts.

  28. sa5fjxm:

    • Input-only multi-file logical file (replaces sa5fixm [jb06]) for miscellaneous and product move records.
    • Used in sf1lodallb and clcinvtot to calculate freight amounts.
  29. apveny:

    • Input-only file for vendor data.
    • Used in sf1edt to ensure carrier ID is linked to a vendor [jk02].

External Programs Called

  1. QCMDEXC:
  2. Called in opntbl to execute file override commands (ovrdbf).
  3. Parameters:

    • dbov##: Override command string (80 characters).
    • dbol##: Command length (15.5).
  4. QMHSNDPM:

  5. Called in addmsg to send messages to the program message queue.
  6. 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.
  7. QMHRMVPM:

  8. Called in clrmsg to clear messages from the program message queue.
  9. 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.
  10. LBBCAID:

  11. Called in prompt to handle carrier ID prompting (replaces LGSTABL [jk03]).
  12. Parameters:

    • o$co: Company number.
    • o$caid: Carrier ID (input/output).
    • o$fgrp: File group.
  13. GSDTEDIT (Assumed):

  14. Implied by the pldted parameter list in *inzsr for date validation.
  15. 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 calls FR105 to handle detailed freight invoice processing (e.g., sf1s01 in FR105P).
  • 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 gstabl with bbcaid for 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.