MBBFR1 RPGLE
The RPG program MBBFR1.rpgle
is a module within the Bradford Order Entry/Invoices system designed to calculate freight charges for orders or invoices. It is called by programs such as BB101
(Order Entry), BB495
(Bill of Lading Entry), and BB500
(Invoice Entry) to compute freight-related costs, including line haul amounts, fuel surcharges, insurance, and other accessorial charges. The program supports two modes: Order Entry (FROEI = 'O'
) and Invoice Entry (FROEI = 'I'
), with the latter allowing manual override of freight rates. Below is a detailed explanation of the process steps, business rules, tables used, and external programs called.
Process Steps of MBBFR1.rpgle
¶
The program operates through a series of subroutines to initialize parameters, retrieve data, and calculate freight charges. The main steps are:
- Initialization (
*inzsr
Subroutine): - Receives Input Parameters (via
*entry
plist, stored inFRGHT
data structure):FCO
: Company number.FCUST
: Customer number.FORDR
: Order number.FSHIP
: Ship-to number.FCAID
: Carrier ID.FAMT
: Total freight amount (output).FFPU
: Freight per unit (input for override in Invoice mode).FRQDT
: Pickup date (YYMMDD).FQTY
: Quantity.FMSG
: Message field for errors or status.FCACD
: Carrier code.FCAFR
: Calculate freight flag.FRQCN
: Pickup date century.FFRCD
: Freight code.FRCAR
: Railcar number (for Invoice mode).FROEI
: Mode ('O' for Order Entry, 'I' for Invoice Entry).- Additional fields:
FSFRT
(separate freight flag),SVPROD
(product code),SVCNTR
(container code),SVUM
(unit of measure),CSMILS
(miles),MLCNT
(multi-load count),ROUTE
,FGALT
,FGGALT
,FQTYT
(total quantity),FWT
(weight).
- Defines
FSPC
(fuel surcharge percentage) as a field likebkfrpc
fromBBCFSD1
. -
Initializes output fields (e.g.,
FAMT
,CFAMT
,SCAM
,CSCAM
,INAM
,CINAM
,RCRAT
,MSFR
,OTFR
,LNHA
,CLNHA
,SCPC
,CSCPC
) to zero. -
Retrieve Customer Freight Data:
- Uses the
FRTTBL
data structure (mapped toBICUFR
file fields) to read customer freight details. -
Chains to
BICUFR
using key fields (BFCONO
,BFCUST
,BFSHIP
,BFLOC
,BFCAID
) to retrieve freight parameters such as:CFRPUM
: Freight rate per unit of measure.CFSCHG
: Fuel surcharge percentage.CFINSP
: Insurance percentage.CFCLEN
,CFPUMP
,CFHOSE
,CFPUUP
,CFTOLL
,CFDENT
,CFINTA
,CFSTOP
,CFSCAL
: Accessorial charges.BFSCCA
: Surcharge calculation code ('N' for no carrier fuel surcharge, 'M' for mileage-based surcharge).
-
Calculate Freight:
- Determine Quantity:
- If
FROEI = 'I'
(Invoice Entry) andFFPU ≠ 0
, uses the override freight rate (FFPU
) instead ofCFRPUM
. - Calculates the effective quantity (
RESULT
) based onFQTY
,SVUM
, and conversion factors fromGSUMCV
(unit of measure conversion). - Applies minimum freight quantity (
FMIN
,FMINNG
) if defined inBICUFR
.
- If
-
Line Haul Amount:
- Multiplies
RESULT
byCFRPUM
(orFFPU
) to compute the carrier line haul amount (CLNHA
) and initial freight amount (CFAMT
). - Adjusts for negative quantities if
RESULT < 0
usingFMINNG
.
- Multiplies
-
Calculate Fuel Surcharge:
-
Checks
BFSCCA
(surcharge calculation code):- If
BFSCCA ≠ 'N'
(JB02, 05/04/2020): - If
CFSCHG ≠ 0
, uses the customer-specific fuel surcharge percentage (CFSCHG
):CSCHG = CFAMT * CFSCHG
.- Adds
CSCHG
toCFAMT
. - Sets
CSCPC = CFSCHG * 100
,CSCAM = CSCHG
.
- Otherwise, retrieves the carrier fuel surcharge percentage (
FSPC
) fromBB080
(called withFCO
,FCAID
,FRQCN + FRQDT
,0
):CSCHG = CFAMT * FSPCT
(whereFSPCT = FSPC / 100
).- Adds
CSCHG
toCFAMT
. - Sets
CSCPC = FSPCT * 100
,CSCAM = CSCHG
.
- If
BFSCCA = 'M'
(MG01, 07/18/2018): - Retrieves railcar fuel surcharge rate (
RCRAT
) fromBBRCSC2
by chaining withFCO
,FRCAR
, andFRQCN + FRQDT
. - Calculates railcar surcharge amount (
RCSAM
) and adds it toCFAMT
andCSCAM
.
- If
-
Calculate Insurance:
-
If
CFINSP ≠ 0
:- Computes insurance percentage (
CINSP = CFINSP * 0.01
). - Calculates insurance amount (
CINSA = CLNHA * CINSP
). - Adds
CINSA
toCFAMT
and setsCINAM = CINSA
.
- Computes insurance percentage (
-
Add Accessorial Charges:
- If
CLNHA < 0
, negates accessorial charges (CFCLEN
,CFPUMP
,CFHOSE
,CFPUUP
,CFTOLL
,CFDENT
,CFINTA
,CFSTOP
,CFSCAL
) to maintain consistency. - Sums accessorial charges into
CFOTH
:CFOTH = CFCLEN + CFPUMP + CFHOSE + CFPUUP + CFTOLL + CFDENT + CFINTA + CFSTOP + CFSCAL
.
- For Invoice Entry (
FROEI = 'I'
) with multi-loads (MLCNT ≠ 0
):- Multiplies
CFOTH
byMLCNT
to account for multiple loads.
- Multiplies
-
Adds
CFOTH
toCFAMT
(JB03, 01/31/2023, ensures correct summation). -
Finalize Freight Amount:
- Sets the total carrier freight amount (
CTFAM = CFAMT
). -
Updates output parameters in
FRGHT
:FAMT = CFAMT
: Total freight amount.LNHA = CLNHA
: Line haul amount.SCPC = CSCPC
: Fuel surcharge percentage.SCAM = CSCAM
: Fuel surcharge amount.INAM = CINAM
: Insurance amount.RCRAT
: Railcar fuel surcharge rate (if applicable).
-
Program End:
- Returns control to the calling program with updated
FRGHT
data structure values.
Business Rules¶
The program enforces the following business rules to ensure accurate freight charge calculations:
1. Mode-Specific Behavior:
- Order Entry (FROEI = 'O'
): Reads order transaction data and uses BICUFR
freight rates without override.
- Invoice Entry (FROEI = 'I'
): Reads invoice transaction data (keyed by railcar number FRCAR
) and allows override of freight rate per unit (FFPU
).
- Quantity Calculation:
- Converts order/invoice quantity (
FQTY
) to the appropriate unit of measure usingGSUMCV
conversion factors. -
Applies minimum freight quantities (
FMIN
for positive,FMINNG
for negative) if specified inBICUFR
. -
Fuel Surcharge Calculation:
- If
BFSCCA = 'N'
(JB02, 05/04/2020), skips carrier fuel surcharge calculation. - If
CFSCHG ≠ 0
, uses customer-specific fuel surcharge percentage fromBICUFR
. - Otherwise, calls
BB080
to retrieve carrier fuel surcharge percentage (FSPC
) based on the National Diesel Fuel Index (BBNDFI2
). -
For
BFSCCA = 'M'
(MG01, 07/18/2018), adds railcar fuel surcharge (RCSAM
) fromBBRCSC2
. -
Insurance Calculation:
-
Applies insurance percentage (
CFINSP
) to the line haul amount (CLNHA
) if non-zero. -
Accessorial Charges:
- Sums charges for cleaning (
CFCLEN
), pumping (CFPUMP
), hose (CFHOSE
), pump-up (CFPUUP
), tolls (CFTOLL
), detention (CFDENT
), interchange (CFINTA
), stops (CFSTOP
), and scales (CFSCAL
). - Adjusts for negative line haul amounts by negating accessorial charges.
-
Multiplies accessorial charges by multi-load count (
MLCNT
) in Invoice Entry mode. -
Data Precision:
-
Per revision JB04 (06/17/2024), the fuel surcharge percentage (
FSPC
) is stored as a 5.2 packed decimal for increased precision (previously 3.1). -
Error Handling:
- Returns error or status messages in
FMSG
if issues occur (e.g., invalid data or missing records).
Tables (Files) Used¶
The program accesses the following files:
1. GSUMCV: Product unit of measure conversion file (input, 64 bytes, 12-byte key).
2. BBCFSH: Carrier fuel surcharge header file (input, 84 bytes, 16-byte key).
3. BBCFSD1: Carrier fuel surcharge detail file (input, 96 bytes, 22-byte key).
4. BBNDFI2: National Diesel Fuel Index file (input, 88 bytes, 17-byte key).
5. BBRCSC2: Railcar fuel surcharge file (input, 88 bytes, 14-byte key).
6. BICUFR (not explicitly declared but referenced via FRTTBL
): Customer freight file for freight rates and charges.
External Programs Called¶
The program calls the following external program:
1. BB080: Retrieves the carrier fuel surcharge percentage (FSPC
) based on company, carrier ID, effective date, and time.
Summary¶
The MBBFR1.rpgle
program, called by BB101
, BB495
, and BB500
, calculates freight charges for orders or invoices in the Bradford Order Entry/Invoices system. It supports Order Entry and Invoice Entry modes, handling line haul amounts, fuel surcharges (customer-specific, carrier-based, or railcar-based), insurance, and accessorial charges. The program uses BICUFR
for customer freight data, GSUMCV
for unit conversions, and BB080
for carrier fuel surcharges, with railcar surcharges from BBRCSC2
(MG01). Revisions (e.g., JB02, JB04) enhance surcharge calculations and field precision. The program returns a comprehensive set of freight-related values in the FRGHT
data structure for use by the calling program.