FR713A RPGLE
The FR713A program is an RPGLE program called by FR713C to build the work file FR713W for the Freight Out Reconciliation Report sorted by location. It processes freight data from multiple input files, applies filtering based on input parameters, and writes the results to the work file. Below, I’ll explain the process steps, business rules, database tables used, and external programs called, based on the provided RPGLE source code.
Process Steps of the FR713A Program¶
The FR713A program initializes the environment, opens database files, reads freight header and detail records, applies filters, calculates freight amounts, and writes the processed data to the work file. Here’s a detailed breakdown of the process steps:
- Program Initialization (
*inzsrSubroutine): - Purpose: Sets up initial conditions and processes input parameters.
-
Actions:
- Receives eight input parameters via the
*ENTRY PLIST: p$co(2): Company code.p$fdat(8): From date (inCYMDformat).p$tdat(8): To date (inCYMDformat).p$loc(3): Location code.p$caid(6): Carrier ID.p$cust(6): Customer code.p$car$(1): Flag to include zero-dollar freight records ('Y' or 'N').p$fgrp(1): File group ('G' or 'Z', determining the database file set).- Moves input parameters to work fields:
p$cotok$co(key field for company).p$fdattow$fdat(from date).p$tdattow$tdat(to date).p$custtow$cust(customer).- Defines key lists:
klkey1: For accessingfrbinh(header file) by company (k$co).klkey2: For accessingfrbinfandfrbind(detail files) by company (boco), order number (bordno), and sequence number (bosrn).- Note: A commented-out
DSPLYoperation forp$tdatsuggests debugging code that is no longer active.
- Receives eight input parameters via the
-
Open Database Tables (
opntblSubroutine): - Purpose: Opens the necessary database files with appropriate overrides based on the file group (
p$fgrp). -
Actions:
- Checks if
p$fgrpis 'G' or 'Z'. - Applies file overrides using the
ovg(for 'G') orovz(for 'Z') arrays, which containOVRDBFcommands to redirect file access to the appropriate library (e.g.,gfrbinhfor 'G' orzfrbinhfor 'Z'). - Executes the override commands using the
QCMDEXCsystem API for four files (frbinh,frbinf,frcinhj1,frbind). - Opens the input files
frbinh,frbinf,frcinhj1, andfrbind, and the output filefr713w.
- Checks if
-
Read Header File (
readbinhSubroutine): - Purpose: Reads the freight header file (
frbinh) and applies filters to select relevant records. -
Actions:
- Positions the file pointer at the start of
frbinhusingSETLLwithklkey1(company code). - Reads records sequentially using
READEwithklkey1, continuing until end-of-file (*in90 = *on). - Applies filters based on input parameters:
- Carrier ID (
p$caid): If non-blank and not matchingbocaid, skips the record (ITER). - Location (
p$loc): If non-blank and not matchingboloc, skips the record. - Customer (
w$cust): If non-zero and not matchingbocust, skips the record (added by revisionjb01). - Date Range: Ensures the shipment date (
boshd8) is within the range[w$fdat, w$tdat]. If not, skips the record. - For valid records:
- Clears work fields for differences and freight amounts (
w$diffdtl,w$efrtdtl,w$cfrtdtl,w$bfrtdtl,w$bfrt,w$efrt,w$cfrt,w$diff). - Sets
w$nodiffto 'N' if the order is closed (boclos = 'C') and the close date (bocld8) is within the to-date (w$tdat) (added byjb01). - Calls the
readbinfsubroutine to process related detail records.
- Positions the file pointer at the start of
-
Read Invoice File (
readbinfSubroutine): - Purpose: Reads the freight invoice file (
frbinf) to calculate freight amounts for the header record. -
Actions:
- Clears work fields for freight totals (
w$bfrt,w$efrt). - Positions the file pointer at the start of
frbinfusingSETLLwithklkey2(company, order number, sequence number). - Reads records matching
klkey2usingREADE, continuing until no more matching records (*in91 = *on). - For each record:
- Adds the freight amount (
bftfam) tow$bfrt(total booked freight). - (Note: The truncated code likely includes additional calculations, such as for estimated freight
w$efrt, based on context from later subroutines.) - After processing all matching records, calls the
readcinhsubroutine to process invoice header records.
- Clears work fields for freight totals (
-
Read Invoice Header File (
readcinhSubroutine, partially truncated): - Purpose: Reads the invoice header file (
frcinhj1) to retrieve additional freight data. -
Actions:
- (Due to truncation, exact details are incomplete, but based on context and revision
jb02): - Uses
frcinhj1(a multi-file logical file replacingfrcinh1) to include freight billed balance headers. - Likely calculates customer freight (
w$cfrt) and adjusts invoice amounts by subtracting freight balancing order override totals (perjb02). - Calls the
readbindsubroutine to process detail records.
- (Due to truncation, exact details are incomplete, but based on context and revision
-
Read Detail File (
readbindSubroutine): - Purpose: Reads the freight detail file (
frbind) to calculate prorated freight amounts and differences. -
Actions:
- Clears work fields for detail-level differences and freight amounts (
w$diffdtl,w$efrtdtl,w$cfrtdtl,w$bfrtdtl). - Positions the file pointer at the start of
frbindusingSETLLwithklkey2. - Reads records matching
klkey2usingREADE, continuing until no more matching records (*in93 = *on). - For each record:
- Calculates prorated amounts by multiplying total freight amounts (
w$bfrt,w$efrt,w$cfrt) by the detail percentage (bdpctt):w$bfrtdtl = w$bfrt * bdpctt(booked freight detail).w$efrtdtl = w$efrt * bdpctt(estimated freight detail).w$cfrtdtl = w$cfrt * bdpctt(actual/customer freight detail).
- Calculates the difference (
w$diffdtl):- If
w$efrtdtl ≠ 0,w$diffdtl = w$efrtdtl - w$cfrtdtl. - Else,
w$diffdtl = w$bfrtdtl - w$cfrtdtl.
- If
- If
w$nodiff = 'N'(order closed in selected period, perjb01), setsw$diffdtlto zero. - Calls the
writewrksubroutine to write the processed data to the work file.
- Clears work fields for detail-level differences and freight amounts (
-
Write to Work File (
writewrkSubroutine): - Purpose: Writes a record to the output work file
fr713w. -
Actions:
- Clears the output record (
fr713wpf). - Populates fields from header and detail data:
w1co: Company (boco).w1cust: Customer (bocust).w1name: Customer name (boname).w1frgl: Freight GL account (bdfrgl).w1rtcd: Routing code (bortcd).w1sdat: Shipment date (boshd8).w1rdno: Order number (bordno).w1srn: Sequence number (bosrn).w1invn: Invoice number (boinvn).w1type: Order type (botype).w1um: Unit of measure (bdum).w1prod: Product code (bdprod).w1qty: Quantity (bdctqt).w1clos: Close status (boclos).w1bfrt: Booked freight detail (w$bfrtdtl).w1efrt: Estimated freight detail (w$efrtdtl).w1afrt: Actual/customer freight detail (w$cfrtdtl).w1diff: Freight difference (w$diffdtl).w1seq: Sequence number (bdseq).tlbfrt: Total booked freight (w$bfrt).tlefrt: Total estimated freight (w$efrt).tlafrt: Total actual/customer freight (w$cfrt).w1loc: Location (boloc).w1sst: Ship state (bosst).w1rtg1: Routing group (bortg1).w1scit: Ship city (boscit).w1ship: Ship via (boship).w1frcd: Freight code (bofrcd).- Writes the record to
fr713wpf(thefr713wfile).
- Clears the output record (
-
Program Termination:
- Purpose: Cleans up and exits the program.
- Actions:
- Closes all open files using
CLOSE *ALL. - Sets
*INLRto*ONto indicate the program is ending. - Returns control to the caller (
FR713C).
- Closes all open files using
Business Rules¶
The FR713A program enforces the following business rules:
1. File Group Selection:
- Uses p$fgrp ('G' or 'Z') to apply overrides to access the correct database files (e.g., gfrbinh or zfrbinh), ensuring data is retrieved from the appropriate library.
2. Record Filtering:
- Filters frbinh records based on:
- Carrier ID (p$caid): Must match bocaid if specified.
- Location (p$loc): Must match boloc if specified.
- Customer (w$cust): Must match bocust if specified (per jb01).
- Shipment date (boshd8): Must be within [w$fdat, w$tdat].
- Skips records that fail these filters.
3. Zero Difference for Closed Orders:
- If an order is closed (boclos = 'C') and closed within the selected period (bocld8 ≤ w$tdat), the freight difference (w$diffdtl) is set to zero (per jb01).
4. Freight Calculations:
- Accumulates booked freight (w$bfrt) from frbinf records.
- Calculates prorated freight amounts at the detail level using bdpctt (percentage) from frbind.
- Computes the freight difference (w$diffdtl) as:
- Estimated freight (w$efrtdtl) minus actual/customer freight (w$cfrtdtl) if estimated freight is non-zero.
- Otherwise, booked freight (w$bfrtdtl) minus actual/customer freight (w$cfrtdtl).
- Adjusts invoice amounts by subtracting freight balancing order override totals (per jb02).
5. Multi-File Logical File:
- Uses frcinhj1 (replacing frcinh1 per jb02) to include freight billed balance headers, enhancing data coverage without significant program changes.
6. Zero-Dollar Freight Records:
- The p$car$ parameter ('Y' or 'N') determines whether to include records with zero freight amounts, though its exact implementation is not visible in the truncated code.
7. Data Integrity:
- Clears work fields before processing each header record and detail record to prevent data carryover.
- Writes all relevant header and detail fields to fr713w for use by the print program (FR713B).
Database Tables Used¶
The FR713A program directly accesses the following database files:
1. frbinh (Freight Billing Header, Input):
- Used to read header records for freight orders.
- Keyed by company (boco) via klkey1.
- Overrides: gfrbinh (for p$fgrp = 'G') or zfrbinh (for p$fgrp = 'Z').
- Fields used: bocaid (carrier ID), boloc (location), bocust (customer), boshd8 (shipment date), boclos (close status), bocld8 (close date), boname (customer name), bortcd (routing code), bordno (order number), bosrn (sequence number), boinvn (invoice number), botype (order type), bosst (ship state), bortg1 (routing group), boscit (ship city), boship (ship via), bofrcd (freight code).
2. frbinf (Freight Billing Invoice, Input):
- Used to calculate booked freight amounts for each header record.
- Keyed by company (boco), order number (bordno), and sequence number (bosrn) via klkey2.
- Overrides: gfrbinf (for p$fgrp = 'G') or zfrbinf (for p$fgrp = 'Z').
- Fields used: bftfam (freight amount).
3. frcinhj1 (Freight Invoice Header Join, Input):
- A multi-file logical file (replacing frcinh1 per jb02) that includes freight billed balance headers.
- Keyed by company, order number, and sequence number (inferred from context).
- Overrides: gfrcinhj1 (for p$fgrp = 'G') or zfrcinhj1 (for p$fgrp = 'Z').
- Fields used: Not fully visible due to truncation, but likely used to calculate actual/customer freight (w$cfrt).
4. frbind (Freight Billing Detail, Input):
- Used to calculate prorated freight amounts and differences.
- Keyed by company (boco), order number (bordno), and sequence number (bosrn) via klkey2.
- Overrides: gfrbind (for p$fgrp = 'G') or zfrbind (for p$fgrp = 'Z').
- Fields used: bdpctt (percentage), bdfrgl (freight GL account), bdum (unit of measure), bdprod (product code), bdctqt (quantity), bdseq (sequence number).
5. fr713w (Freight Work File, Output):
- The output work file where processed records are written.
- Populated with fields from header and detail records, including calculated freight amounts and differences.
- No overrides applied, as it is typically created in QTEMP by FR713C.
External Programs Called¶
The FR713A program calls the following external program:
1. QCMDEXC:
- System API used in the opntbl subroutine to execute file override commands (OVRDBF) for frbinh, frbinf, frcinhj1, and frbind.
- Parameters: dbov## (override command string, 80 characters) and dbol## (command length, 15.5).
Additional Notes¶
- Revisions:
- jb01 (04/29/2015): Added customer filtering (
w$cust) and logic to zero out differences for closed orders within the selected period. - jb02 (02/04/2019): Replaced
frcinh1withfrcinhj1to include freight billed balance headers and adjusted invoice amounts by subtracting freight balancing order override totals. - Truncated Code:
- The
readcinhsubroutine and parts ofreadbinfare truncated, limiting visibility into the full logic for calculating estimated and actual freight amounts. However, context suggests these involve processingfrcinhj1to computew$cfrtand possibly other freight-related calculations. - Data Structures:
- Uses time (
t#) and date (d#) conversion data structures, though they are not explicitly used in the provided code, suggesting potential future or unused functionality. - Uses a program status data structure (
psds##) to capture environment details like program name and user. - Indicator Usage:
- Indicators (e.g., 90-93 for file reads, 50-69 for errors) are used to control program flow, though no screen-related indicators (e.g., 19, 40-43) are used since this program is non-interactive.
- Integration:
FR713Ais part of the chain (FR713P→FR713PC→FR713C→FR713A→FR713B) and focuses on data preparation for the location-sorted report.
Summary¶
The FR713A program builds the FR713W work file by reading freight header (frbinh), invoice (frbinf), invoice header (frcinhj1), and detail (frbind) files, applying filters for carrier, location, customer, and date range, calculating prorated freight amounts and differences, and writing the results to the work file. It enforces business rules for filtering, zeroing differences for closed orders, and adjusting invoice amounts. The program directly accesses five database files and calls the QCMDEXC API for file overrides, with all data processing tailored for the location-sorted Freight Out Reconciliation Report.