FR710A RPGLE
The RPG program FR710A is designed to build the FR710W work file for the Freight Out Accrual Report. It is called by the FR710C program and processes data from multiple input files to generate records for the report based on specific business rules. Below is a detailed explanation of the process steps, business rules, tables used, and external programs called.
Process Steps of the FR710A Program¶
- Program Initialization (
*inzsrSubroutine): - Purpose: Sets up the program environment and initializes variables.
-
Steps:
- Receives three input parameters:
p$co: Company number (2 characters).p$rdat: Report date (8 digits,CCYYMMDDformat).p$fgrp: File group ('G' or 'Z') to determine file overrides.- Moves
p$cotok$co(key field for file access) andp$rdattow$rdat(work field for report date). - Defines key lists:
klkey1: Usesk$coto access thefrbinhfile by company.klkey2: Usesboco(company),bordno(order number), andbosrn(serial number) to accessfrbinf,frcinhj1, andfrbindfiles.
-
Open Database Tables (
opntblSubroutine): - Purpose: Opens input files with appropriate overrides based on the file group.
-
Steps:
- Checks the
p$fgrpparameter ('G' or 'Z'). - For 'G', applies overrides from the
ovgarray to point to filesgfrbinh,gfrbinf,gfrcinhj1, andgfrbind. - For 'Z', applies overrides from the
ovzarray to point to fileszfrbinh,zfrbinf,zfrcinhj1, andzfrbind. - Executes overrides using the
QCMDEXCsystem API, passing the override command and length. - Opens the input files:
frbinh,frbinf,frcinhj1(replacingfrcinh1per revisionjb03), andfrbind.
- Checks the
-
Read Header File (
readbinhSubroutine): - Purpose: Reads the
frbinhfile (freight billing header) and applies selection criteria. -
Steps:
- Sets the lower limit (
setll) forfrbinhusingklkey1(company number). - Reads records (
reade) until end-of-file (*in90is*on). - Applies filtering rules (see Business Rules below):
- Skips records where
bocoon(customer-owned product) is 'Y' (revisionjb02). - Skips records where
bocafr(calculate freight) is 'N' andbofrto(freight total) is zero (revisionjb02). - Includes records where:
- Shipment date (
boshd8) is on or before the report date (w$rdat) and the order is not closed (boclos≠ 'C'). - Or, shipment date is on or before the report date, the order is closed (
boclos= 'C'), and the close date (bocld8) is after the report date.
- Shipment date (
- Clears work fields (
w$diffdtl,w$efrtdtl,w$cfrtdtl,w$bfrtdtl,w$bfrt,w$efrt,w$cfrt,w$diff) for each header record. - Sets
w$nodiffto 'N' if the order is closed in the selected month (boclos= 'C' andbocld8≤w$rdat) to zero out differences (revisionjb01). - Calls
readbinfto process related detail records.
- Sets the lower limit (
-
Read Freight Billing Detail File (
readbinfSubroutine): - Purpose: Aggregates freight amounts from the
frbinffile (freight billing detail). -
Steps:
- Clears work fields
w$bfrt(booked freight) andw$efrt(estimated freight). - Sets the lower limit for
frbinfusingklkey2(company, order number, serial number). - Reads matching records (
reade) until end-of-file (*in91). - Accumulates
bftfam(booked freight amount) intow$bfrtandcftfam(estimated freight amount) intow$efrt. - Calls
readcinhto process related invoice records.
- Clears work fields
-
Read Freight Invoice File (
readcinhSubroutine): - Purpose: Aggregates invoice amounts from the
frcinhj1file (freight invoice header, replacedfrcinh1per revisionjb03). -
Steps:
- Clears work fields
w$cfrt(invoiced freight) andw$diff(difference). - Sets the lower limit for
frcinhj1usingklkey2. - Reads matching records (
reade) until end-of-file (*in92). - Accumulates
frinam(invoice amount) intow$cfrt, subtractingfrfboa(freight balancing order override total) per revisionjb03. - Calculates the difference (
w$diff): - If
w$efrt(estimated freight) is non-zero, subtractsw$efrtfromw$cfrt. - Otherwise, subtracts
w$bfrt(booked freight) fromw$cfrt. - If
w$nodiffis 'N' (order closed in selected month), setsw$diffto zero (revisionjb01). - Calls
readbindto process detail records.
- Clears work fields
-
Read Freight Billing Detail File (
readbindSubroutine): - Purpose: Processes detail records from
frbindand calculates prorated amounts. -
Steps:
- Clears work fields
w$diffdtl,w$efrtdtl,w$cfrtdtl, andw$bfrtdtl. - Sets the lower limit for
frbindusingklkey2. - Reads matching records (
reade) until end-of-file (*in93). - Calculates prorated amounts using
bdpctt(percentage): w$bfrtdtl=w$bfrt×bdpctt(booked freight detail).w$efrtdtl=w$efrt×bdpctt(estimated freight detail).w$cfrtdtl=w$cfrt×bdpctt(invoiced freight detail).- Calculates detail-level difference (
w$diffdtl): - If
w$efrtdtlis non-zero, subtractsw$cfrtdtlfromw$efrtdtl. - Otherwise, subtracts
w$cfrtdtlfromw$bfrtdtl. - If
w$nodiffis 'N', setsw$diffdtlto zero (revisionjb01). - If the order is not closed (
boclos≠ 'C') or is closed butw$diffdtlis non-zero, callswritewrkto write to the work file (revisionjb01).
- Clears work fields
-
Write to Work File (
writewrkSubroutine): - Purpose: Writes processed data to the
FR710Wwork file. -
Steps:
- Clears the
fr710wpfrecord format. - Populates fields from input files and calculations:
w1co(company),w1cust(customer),w1name(name),w1frgl(freight GL),w1rtcd(route code),w1sdat(ship date),w1rdno(order number),w1srn(serial number),w1invn(invoice number),w1type(type),w1um(unit of measure),w1prod(product),w1qty(quantity),w1clos(close status),w1bfrt(w$bfrtdtl),w1efrt(w$efrtdtl),w1afrt(w$cfrtdtl),w1diff(w$diffdtl),w1seq(sequence).- Totals:
tlbfrt(w$bfrt),tlefrt(w$efrt),tlafrt(w$cfrt). - Writes the record to
fr710wpf.
- Clears the
-
Program Termination:
- Closes all open files (
close *all). - Sets
*inlrto*onto signal program completion. - Returns control to the caller (
FR710C).
Business Rules¶
- Record Selection (Header):
- Excludes records where the product is customer-owned (
bocoon= 'Y') (revisionjb02). - Excludes records where freight calculation is not required (
bocafr= 'N') and the freight total is zero (bofrto= 0) (revisionjb02). - Includes records based on shipment and close status:
- Shipped on or before the report date and not closed.
- Shipped on or before the report date, closed, but closed after the report date.
- Zeroes out differences (
w$diffandw$diffdtl) if the order is closed in the selected month (boclos= 'C' andbocld8≤w$rdat) (revisionjb01). - Freight Calculation:
- Aggregates booked (
bftfam) and estimated (cftfam) freight fromfrbinf. - Aggregates invoiced freight (
frinam) fromfrcinhj1, subtracting the freight balancing order override (frfboa) (revisionjb03). - Calculates differences at the header level (
w$diff) and detail level (w$diffdtl) based on estimated or booked freight versus invoiced freight. - Prorates freight amounts at the detail level using
bdpctt(percentage). - File Overrides:
- Uses
p$fgrpto select between 'G' (production) and 'Z' (development) file sets, ensuring flexibility across environments. - Work File Output:
- Writes only records where the order is not closed or has a non-zero difference when closed (revision
jb01). - Includes detailed fields and totals for use by the report printing program (
FR710B). - Multi-File Support:
- Replaced
frcinh1withfrcinhj1(a multi-file logical file) to include freight billed balance headers without significant code changes (revisionjb03).
Tables Used¶
- Input Files:
frbinh: Freight billing header file, used to select orders based on company, shipment date, and close status.frbinf: Freight billing detail file, used to aggregate booked (bftfam) and estimated (cftfam) freight amounts.frcinhj1: Freight invoice header file (replacedfrcinh1perjb03), used to aggregate invoiced freight (frinam) and subtract balancing overrides (frfboa).frbind: Freight billing detail file, used to calculate prorated freight amounts based on percentages (bdpctt).- Output File:
fr710w: Work file (fr710wpfrecord format) inQTEMP, populated with processed data for the Freight Out Accrual Report.- File Overrides:
- For
p$fgrp= 'G':gfrbinh,gfrbinf,gfrcinhj1,gfrbind. - For
p$fgrp= 'Z':zfrbinh,zfrbinf,zfrcinhj1,zfrbind.
External Programs Called¶
- QCMDEXC: System API used to execute file override commands for
frbinh,frbinf,frcinhj1, andfrbind.
Additional Notes¶
- Revisions:
- jb01 (4/27/2015): Fixed record selection and added logic to zero out differences for orders closed in the selected month.
- jb02 (5/30/2018): Excluded customer-owned products (
bocoon= 'Y') and records with no freight calculation and zero freight total. - jb03 (2/4/2019): Replaced
frcinh1withfrcinhj1to include freight billed balance headers and subtractedfrfboafrom invoice amounts. - Error Handling: Uses indicators (
*in90to*in93) to detect end-of-file conditions but lacks explicit error handling for file access or processing failures. - Purpose: The program processes complex freight data, applying business rules to filter and calculate accruals, and prepares a work file for the final report generation by
FR710B.
This program is critical for building the data foundation for the Freight Out Accrual Report, ensuring accurate freight calculations and proper record selection based on the specified criteria.