AP125 RPGLE
The AP125.rpg
program is an RPG III program running on an IBM AS/400 (iSeries) system, designed to create voucher transactions from freight invoice data, likely called from the AP125.ocl36.txt
OCL script after the AP125P
program has selected invoices for batch processing. It processes freight invoice headers (FRCINH
or FRCFBH
) to generate accounts payable transactions in the APTRAN
file, including header and detail records. Below, I will detail the process steps, business rules, tables used, and external programs called, based on the provided source code.
Process Steps of the AP125 Program¶
The program is structured to process freight invoices, validate data, calculate due dates, and create or update accounts payable transactions. The main process steps are:
- Initialization:
- Parameters: Receives input parameters:
CO
: Company code (2 digits).CAID
: Carrier ID (6 characters).CAIN
: Invoice number (25 characters).RCD
: Record type (FRCFBHP4
for freight billed balance header, otherwiseFRCINHP4
, per revisionJB06
).RDNO
: Reference number (numeric, defined likeFRRDNO
).
- Initializes fields and indicators, setting indicators 81-83, 50-53, 60-69, and 51-62 to off.
-
Sets up key fields for file access (e.g.,
TERMKY
forAPTERM
,BBCAKY
forBBCAID
). -
Subroutine S1 (Main Processing):
- Validate Company: Chains to
APCONT
usingCO
to retrieve company details (e.g.,ACAPGL
,ACCAGL
,ACRTGL
,ACNXTE
). If not found, sets indicator 50. - Retrieve Invoice Data:
- Constructs a key (
FRCKEY
orFRCK39
) usingCO
,CAID
,CAIN
, andRDNO
(forFRCFBH
). - Chains to
FRCINH
(ifRCD ≠ 'FRCFBHP4'
) orFRCFBH
(ifRCD = 'FRCFBHP4'
, perJB06
) to retrieve invoice details. - If found, populates transaction fields:
ATINV#
: Invoice number (FRCAIN
).INTY
: Invoice type (FRINTY
).ATINDT
/INDT
: Invoice date (FRIYMD
converted to MMDDYY).ATIAMT
/IAMT
/ATFRTL
/FRTL
: Invoice amount (FRINAM - FRFBOA
, perJB06
).ATSORN
/SORN
: Sales order number (FRRDNO
).ATSSRN
/SSRN
: Sales sequence number (FRSRN
).- Sets indicators 51 (
INTY = 'P'
) or 52 (INTY = 'O'
) for invoice description.
- Constructs a key (
- Generate Entry Number:
- If
ENT#
is zero, setsRECSTS = 'ADDNEW'
, retrieves the next entry number (ACNXTE
) fromAPCONT
, increments it, and updatesAPCONT
. - Ensures
ENT#
does not exceed 99999, adjustingACNXTE
accordingly.
- If
- Retrieve Vendor Information:
- Chains to
APVENY
usingCO
andCAID
to get the vendor number (VYVEND
). - Chains to
APVEND
usingCO
andVEND
to retrieve vendor details (VNVNAM
,VNAD1
,VNAD2
,VNAD3
,VNAD4
,VNHOLD
,VNSNGL
,VNTERM
,VNEXGL
). - Sets hold description (
HLDD
) based onVNHOLD
(perJB02
andMG18
): H
: "VENDOR ON HOLD" (COM,01).A
: "ON HOLD FOR ACH" (COM,02).W
: "ON HOLD FOR WIRE TRANSFER" (COM,03).U
: "ON HOLD FOR UTILITY AUTO-PAYMENT" (COM,04).
- Chains to
-
Output: Writes or updates the transaction header in
APTRAN
via theEXCPT
operation. -
Subroutine S2 (Header Processing and Detail Setup):
- Chains to
APTRAN
usingKEYENT
(constructed fromCOENT
and "000") to check for an existing header. - If not found, populates header fields from
APCONT
(APGL
,BKGL
,RTGL
) and vendor data. - Calls
S2EDIT
to validate header fields. - Calls
HDRADD
to write/update the transaction header. - Calls
ROLFWD
to initiate detail line processing. -
Sets indicator 81 to trigger further processing.
-
Subroutine S2EDIT (Header Validation):
- Validate Invoice Date:
- Moves
INDT
toMMDDYY
and callsDTEDIT
to validate the date.
- Moves
- Calculate Due Date:
- If
DUDT
is zero andVEND
is non-zero, callsCLCDUE
to calculate the due date based on vendor terms (VNTERM
). - Otherwise, sets
DUDT = INDT
.
- If
- Validate Due Date:
- Converts
DUDT
toMMDDYY
and validates viaDTEDIT
. - Adjusts for century (
Y2KCEN
) to createINDT8
andDUDT8
(8-digit dates). - Checks
APDATE
(perMG17
) to replaceDUDT8
with a non-holiday/non-weekend date (ADNED8
).
- Converts
-
Validate G/L Accounts:
- Chains to
GLMAST
to validateAPGL
,BKGL
, andRTGL
, retrieving descriptions (APGLNM
,BKGLNM
,RTGLNM
). Sets indicators 61, 62, or 63 if invalid.
- Chains to
-
Subroutine CLCDUE (Calculate Due Date):
- If
VNTERM
is non-zero, chains toGSTABL
(tableAPTERM
) to retrieve terms (TBNETD
,TBPRXD
,TBDISC
,TBDISD
). - If valid, retrieves discount percentage (
TBDISC
toSVDSPC
, perMG03
). -
Calls
TMDATN
(net days) orTMDATP
(prox days) to calculateDUDT
. -
Subroutine TMDATN (Net Days Calculation):
- Converts
INDT
to Julian format (G$JD
) via@DTE1
. - Adds net days (
TBNETD
) toG$JD
. -
Converts back to Gregorian format (
$MDY
) via@DTE2
to setDUDT
. -
Subroutine TMDATP (Prox Days Calculation):
-
Adjusts
INDT
by incrementing the month (and year if December) and sets the day toTBPRXD
to calculateDUDT
. -
Subroutine DTEDIT (Date Validation):
- Validates
MMDDYY
by breaking it into month, day, and year. - Checks:
- Month (1-12).
- Day (1-31, or 1-28/29 for February, accounting for leap years).
-
Sets indicator 99 if invalid.
-
Subroutine @DTE1 (Gregorian to Julian Conversion):
- Converts a Gregorian date (
$MDY
,$CN
) to Julian days (G$JD
) for dates between March 1, 1900, and February 28, 2100. -
Calculates the day of the week (
G$JW
). -
Subroutine @DTE2 (Julian to Gregorian Conversion):
- Converts a Julian date (
G$JD
) back to Gregorian format ($MDY
,$CN
).
- Converts a Julian date (
-
Subroutine ROLFWD (Detail Line Processing):
- If
SORN
andSSRN
are non-zero andRECSTS = 'ADDNEW'
, populates aSALES
data structure withCO
,SORN
,SSRN
,ENT#
,VEND
,FRTL
,SVDSPC
, andCMPDT8
(invoice date minus one year, perJB05
). - Calls
AP1012
to populate freight detail lines with calculated percentage amounts. - Resets
RECSTS
and setsKEYENT
to "001" for the first detail line.
- If
-
Subroutine S3 (Detail Line Processing):
- If
FRTL
andPRAM
are non-zero, calculates the freight amount (FRAM = PRAM * FRTL
) and adds it toHOLDAM
andSVTTL
. - Adjusts
FRAM
ifIAMT > SVTTL
to balance the invoice amount. - Combines
PRAM
andFRAM
to setAMT
. - If
AMT
is zero, clears the header (HDRCLR
) and exits. - Calls
S3EDIT
to validate detail fields. - Calls
DETADD
to write the detail line. - Calls
DETCLR
to clear detail fields. - Calls
ROLFWD
to process additional lines. - Updates
FRCINH
orFRCFBH
(settingFRAPST = 'Y'
) based onRCD
. - Writes the updated record via
EXCPT
(APINST
forFRCINH
,APINSF
forFRCFBH
).
- If
-
Subroutine S3EDIT (Detail Validation):
- Sets default expense G/L (
EXGL
) fromVNEXGL
if not specified. - Chains to
GLMAST
to validateEXGL
, setting indicator 50 if invalid.
- Sets default expense G/L (
-
Subroutine HDRADD (Add/Update Header):
- Chains to
APTRAN
and writes/updates the header record usingEXCPT
.
- Chains to
-
Subroutine DETADD (Add Detail Line):
- Writes the detail line to
APTRAN
usingEXCPT
.
- Writes the detail line to
-
Subroutine HDRCLR (Clear Header Fields):
- Clears header fields (e.g.,
SVAPGL
,SVBKGL
,HDEL
,ENT#
,VNAM
, etc.).
- Clears header fields (e.g.,
-
Subroutine DETCLR (Clear Detail Fields):
- Clears detail fields (e.g.,
SVLNGL
,SVLNCO
,DDEL
,AMT
,DISC
, etc.).
- Clears detail fields (e.g.,
-
Subroutine ROLLBK (Rollback Processing):
- Rolls back detail lines by decrementing
NXLINE
and chaining toAPTRAN
. - If a header is reached, calls
S2EDIT
to validate and sets indicator 82.
- Rolls back detail lines by decrementing
-
Program Termination:
- Sets
*INLR = *ON
to end the program.
- Sets
Business Rules¶
- Invoice Processing:
- Processes invoices from
FRCINH
orFRCFBH
based onRCD
(FRCFBHP4
for freight billed balance, perJB06
). -
Adjusts invoice amount (
ATIAMT = FRINAM - FRFBOA
, perJB06
) to account for freight balancing order override total. -
Hold Status:
- Supports hold codes (
VNHOLD
):H
(hold),A
(ACH),W
(wire transfer),U
(utility auto-payment, perMG18
). -
Assigns corresponding descriptions to
HLDD
(perJB02
,MG18
). -
Due Date Calculation:
- Calculates due date (
DUDT
) based on vendor terms (VNTERM
) using net days (TBNETD
) or prox days (TBPRXD
) fromGSTABL
. - Adjusts due date to avoid holidays/weekends using
APDATE
(ADNED8
, perMG17
). -
Defaults to invoice date (
INDT
) if no terms are specified. -
Discount Handling:
-
Retrieves discount percentage (
TBDISC
) fromGSTABL
and applies it toSVDSPC
(perMG03
). -
Date Validation:
- Validates invoice and due dates for valid months, days, and leap years.
-
Handles century adjustments for Y2K compliance.
-
G/L Account Validation:
-
Validates accounts payable (
APGL
), bank (BKGL
), and retention (RTGL
) G/L accounts againstGLMAST
. -
Detail Line Calculation:
- Calculates freight amount (
FRAM
) as a proportion ofPRAM
andFRTL
. -
Ensures total line amount (
AMT = PRAM + FRAM
) aligns with the invoice amount (IAMT
). -
Freight Detail Lines:
-
Calls
AP1012
to populate detail lines with calculated freight percentages, using sales order (SORN
), sequence number (SSRN
), and invoice date minus one year (CMPDT8
, perJB05
). -
Transaction Creation:
- Creates header and detail records in
APTRAN
with vendor, G/L, and freight details. - Updates
FRCINH
orFRCFBH
to mark invoices as processed (FRAPST = 'Y'
).
Tables (Files) Used¶
- Update Files:
APTRAN
: Accounts Payable transaction file (header and detail records, 404 bytes, keyed by company and entry number).APCONT
: Accounts Payable control file (256 bytes, keyed by company).FRCINH
: Freight Invoice Header (206 bytes, keyed by company, carrier ID, invoice number).-
FRCFBH
: Freight Billed Balance Header (206 bytes, keyed by company, carrier ID, invoice number, reference number, perJB06
). -
Input Files:
APVEND
: Vendor master file (579 bytes, keyed by company and vendor number).APVENY
: Vendor cross-reference file (320 bytes, keyed by company and carrier ID).GLMAST
: General Ledger master file (256 bytes, keyed by company and G/L account).GSTABL
: General table file (256 bytes, keyed by table typeAPTERM
for terms).APDATE
: Due date adjustment file (19 bytes, keyed by company and due date, perMG17
).
External Programs Called¶
- AP1012:
- Called in
ROLFWD
to populate freight detail lines with calculated percentage amounts, passing theSALES
data structure.
Summary¶
The AP125.rpg
program processes freight invoices from FRCINH
or FRCFBH
to create accounts payable transactions in APTRAN
. It validates company, vendor, and G/L data, calculates due dates (adjusted for holidays/weekends), applies discounts, and generates header and detail records. The program handles freight balancing adjustments, hold statuses, and detail line calculations via AP1012
. It ensures data integrity through extensive validation and updates the source invoice records upon completion.
If you need further details or clarification on specific subroutines, business rules, or file structures, please let me know!