FR711A RPGLE
The RPGLE program FR711A is called by FR711C to build the temporary work file FR711W for the Freight Out Reconciliation Report, specifically for the location-sorted version of the report. It processes data from input files, applies filtering and calculations, and writes records to the work file. Below is an explanation of the process steps, business rules, tables used, and external programs called, based on the provided source code.
Process Steps of the RPGLE Program (FR711A)¶
The program initializes the environment, reads and filters data from input files, performs calculations, and writes the processed data to the output work file. Here are the detailed steps:
- Initialization (
*inzsrSubroutine): - Purpose: Sets up the program environment and parameters.
-
Actions:
- Receives six input parameters:
p$co: Company code (2 characters).p$rdat: Report date (8 digits, CYMD format).p$loc: Location code (3 characters).p$caid: Carrier ID (6 characters).p$selmo: Month selection (1 character, added in revisionjb02).p$fgrp: File group (1 character, 'G' or 'Z').- Moves
p$cotok$co(key field for company). - Moves
p$rdattow$rdat(report date) andw$rdatfr(from report date, with day set to '01'). - Moves
p$selmotow$selmo(month selection). - Defines two key lists:
klkey1: For accessingfrbinh(usesk$cofor company).klkey2: For accessingfrbind(usesboco,bordno, andbosrnfor company, order number, and sequence number).
-
Open Database Tables (
opntblSubroutine): - Purpose: Opens the input files with appropriate overrides based on the file group.
-
Actions:
- Checks the
p$fgrpparameter ('G' or 'Z') to apply file overrides: - For 'G': Overrides
frbinh,frbinf,frcinhj1, andfrbindtogfrbinh,gfrbinf,gfrcinhj1, andgfrbindrespectively. - For 'Z': Overrides to
zfrbinh,zfrbinf,zfrcinhj1, andzfrbind. - Executes the overrides using the
QCMDEXCsystem program, looping through theovgorovzarrays (four overrides). - Opens the input files:
frbinh,frbinf,frcinhj1(revised fromfrcinh1injb06), andfrbind.
- Checks the
-
Read Header File (
readbinhSubroutine): - Purpose: Reads and filters records from the
frbinhfile, applying selection criteria. -
Actions:
- Sets the lower limit for
frbinhusingklkey1(company code) and reads records withREADEuntil end-of-file (*in90 = *ON). - Applies filters to exclude records:
- If
p$caidis non-blank andbocaid(carrier ID) does not match, skips the record. - If
p$locis non-blank andboloc(location) does not match, skips the record. - If
bocoon = 'Y'(customer-owned product, revisionjb05), skips the record. - If
bocafr = 'N'(calculate freight flag) andbofrto = 0(freight total, revisionjb05), skips the record. - Applies date and status filters based on
w$selmo(month selection, revisionsjb01,jb02,jb04): - Shipped before the selected month start (
boshd8 < w$rdatfr) and not closed (boclos ≠ 'C'):- Included if
w$selmo = *blankorw$selmo = 'A'.
- Included if
- Shipped before the selected month start, closed (
boclos = 'C'), but closed after the report date (bocld8 > w$rdat):- Included if
w$selmo = *blankorw$selmo = 'A'.
- Included if
- Shipped within the selected month (
boshd8 ≥ w$rdatfrandboshd8 ≤ w$rdat):- If not closed (
boclos ≠ 'C') andw$selmo = 'M','O','A', or*blank, includes the record. - If closed (
boclos = 'C') andw$selmo = 'M','C', or*blank, includes the record.
- If not closed (
- For matching records, chains to
frcinhj1(revised fromfrcinh1injb06) to retrieve freight invoice amounts (ficfam). - Calculates freight amounts:
w$bfrt: Freight billed amount (bofrto).w$efrt: Effective freight amount (boefr).w$cfrt: Invoice amount (ficfam) minus freight balancing order override total (bobfot, revisionjb06).- Determines if the difference should be zeroed (
w$nodiff): - Set to 'N' if closed in the selected month (
boclos = 'C'andbocld8matches the selected month). - Calculates the difference (
w$diff): - If
w$efrt ≠ 0, thenw$diff = w$efrt - w$cfrt. - Otherwise,
w$diff = w$bfrt - w$cfrt. - If
w$nodiff = 'N', setsw$diff = 0(revisionjb03). - Calls the
readbindsubroutine to process detail records.
- Sets the lower limit for
-
Read Detail File (
readbindSubroutine): - Purpose: Reads and processes detail records from
frbindfor the current header record. -
Actions:
- Clears detail-level work fields (
w$diffdtl,w$efrtdtl,w$cfrtdtl,w$bfrtdtl). - Sets the lower limit for
frbindusingklkey2(company, order number, sequence number) and reads records withREADEuntil end-of-file (*in93 = *ON). - For each detail record:
- Calculates prorated amounts based on
bdpctt(percentage total):w$bfrtdtl = w$bfrt * bdpctt.w$efrtdtl = w$efrt * bdpctt.w$cfrtdtl = w$cfrt * bdpctt.
- Calculates the detail-level difference (
w$diffdtl):- If
w$efrtdtl ≠ 0, thenw$diffdtl = w$efrtdtl - w$cfrtdtl. - Otherwise,
w$diffdtl = w$bfrtdtl - w$cfrtdtl. - If
w$nodiff = 'N', setsw$diffdtl = 0(revisionjb03).
- If
- Calls the
writewrksubroutine to write the detail record tofr711w.
- Clears detail-level work fields (
-
Write to Work File (
writewrkSubroutine): - Purpose: Writes processed detail records to the
fr711wwork file. -
Actions:
- Clears the output record format (
fr711wpf). - Populates fields from header and detail records and calculated values:
w1co: Company (boco).w1cust: Customer number (bocust).w1name: Customer name (boname).w1frgl: Freight general ledger (bdfrgl).w1rtcd: Routing code (bortcd).w1sdat: Ship 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 (bdprod).w1qty: Quantity (bdctqt).w1clos: Closed status (boclos).w1bfrt: Billed freight (w$bfrtdtl).w1efrt: Effective freight (w$efrtdtl).w1afrt: Actual freight (w$cfrtdtl).w1diff: Difference (w$diffdtl).w1seq: Sequence (bdseq).tlbfrt: Total billed freight (w$bfrt).tlefrt: Total effective freight (w$efrt).tlafrt: Total actual freight (w$cfrt).w1loc: Location (boloc).w1sst: Ship state (bosst).w1rtg1: Routing group (bortg1).w1scit: Ship city (boscit).w1ship: Ship number (boship).w1frcd: Freight code (bofrcd).- Writes the record to
fr711w.
- Clears the output record format (
-
Program Termination:
- Closes all open files (
close *all). - Sets
*inlr = *ONto indicate the program is ending. - Returns control to the caller (
FR711C).
Business Rules¶
- Record Selection Filters (revisions
jb01,jb02,jb04,jb05): - Excludes records where:
- Carrier ID (
bocaid) does not matchp$caidif specified. - Location (
boloc) does not matchp$locif specified. - Customer-owned product is 'Y' (
bocoon, revisionjb05). - Calculate freight is 'N' (
bocafr) and freight total is zero (bofrto, revisionjb05).
- Carrier ID (
- Includes records based on ship date (
boshd8), closed status (boclos), and month selection (w$selmo):- Previous Month (Open): Includes records shipped before the selected month start (
w$rdatfr) and not closed, ifw$selmo = *blankor'A'. - Previous Month (Closed After Report Date): Includes records shipped before the selected month start, closed, but closed after the report date (
bocld8 > w$rdat), ifw$selmo = *blankor'A'. - Selected Month:
- Includes open records (
boclos ≠ 'C') ifw$selmo = 'M','O','A', or*blank. - Includes closed records (
boclos = 'C') ifw$selmo = 'M','C', or*blank.
- Previous Month (Open): Includes records shipped before the selected month start (
-
The
w$rdatfris set to the first day of the selected month, andw$rdatis the report date (typically the last day). -
Month Selection Options (revisions
jb02,jb04): M: Selected month only, including all (open and closed) records.O: Selected month, open records only.C: Selected month, closed records only.A: All open records from previous and selected months.-
Blank: Previous month open records and selected month all records.
-
Freight Calculations (revision
jb06): - Freight invoice amount (
w$cfrt) is calculated asficfam(fromfrcinhj1) minus the freight balancing order override total (bobfot). - Difference calculations:
- Header level:
w$diff = w$efrt - w$cfrtifw$efrt ≠ 0, otherwisew$diff = w$bfrt - w$cfrt. - Detail level:
w$diffdtl = w$efrtdtl - w$cfrtdtlifw$efrtdtl ≠ 0, otherwisew$diffdtl = w$bfrtdtl - w$cfrtdtl.
- Header level:
-
If a record is closed in the selected month (
w$nodiff = 'N'), the difference (w$diffandw$diffdtl) is set to zero (revisionjb03). -
File Group:
-
The
p$fgrpparameter ('G' or 'Z') determines which files are accessed:- 'G': Uses
gfrbinh,gfrbinf,gfrcinhj1,gfrbind. - 'Z': Uses
zfrbinh,zfrbinf,zfrcinhj1,zfrbind.
- 'G': Uses
-
Multi-File Logical File (revision
jb06): -
Replaced
frcinh1withfrcinhj1, a multi-file logical file, to include freight billed balance headers, enhancing data coverage without significant program changes. -
Error Handling:
- The program does not explicitly handle errors beyond file read indicators (
*in90,*in93). Errors are likely managed by the calling program or system.
Tables Used¶
- Input Files:
frbinh: Header file for freight billing, overridden togfrbinhorzfrbinhbased onp$fgrp.frbinf: Freight billing file, overridden togfrbinforzfrbinf.frcinhj1: Multi-file logical file for freight invoice data (revised fromfrcinh1injb06), overridden togfrcinhj1orzfrcinhj1.-
frbind: Detail file for freight billing, overridden togfrbindorzfrbind. -
Output File:
fr711w: Temporary work file inQTEMP(created byFR711C), used to store processed records for the report.
External Programs Called¶
- QCMDEXC: System program used to execute file override commands in the
opntblsubroutine.
Additional Notes¶
- Purpose:
FR711Ais responsible for extracting, filtering, and calculating freight data to populate thefr711wwork file, which is then used byFR711Bto generate the location-sorted report. - Multi-User Support: The use of
QTEMP/fr711w(set up byFR711C) ensures multi-user capability by providing a job-specific work file. - Parameter Validation: The program assumes input parameters are valid, as they are validated by
FR711Pand passed throughFR711C. - Execution Context: Runs in the same job session as its caller, processing data sequentially and writing to the work file.
- Comparison with
FR712A: Likely similar in structure but tailored for location-sorted data, whileFR712Ahandles carrier-sorted data.
This program efficiently processes freight data, applying complex filtering and calculations to prepare the work file for the Freight Out Reconciliation Report.