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 (FRCFBHP4for 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.,
TERMKYforAPTERM,BBCAKYforBBCAID). -
Subroutine S1 (Main Processing):
- Validate Company: Chains to
APCONTusingCOto retrieve company details (e.g.,ACAPGL,ACCAGL,ACRTGL,ACNXTE). If not found, sets indicator 50. - Retrieve Invoice Data:
- Constructs a key (
FRCKEYorFRCK39) 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 (FRIYMDconverted 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, adjustingACNXTEaccordingly.
- If
- Retrieve Vendor Information:
- Chains to
APVENYusingCOandCAIDto get the vendor number (VYVEND). - Chains to
APVENDusingCOandVENDto retrieve vendor details (VNVNAM,VNAD1,VNAD2,VNAD3,VNAD4,VNHOLD,VNSNGL,VNTERM,VNEXGL). - Sets hold description (
HLDD) based onVNHOLD(perJB02andMG18): 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
APTRANvia theEXCPToperation. -
Subroutine S2 (Header Processing and Detail Setup):
- Chains to
APTRANusingKEYENT(constructed fromCOENTand "000") to check for an existing header. - If not found, populates header fields from
APCONT(APGL,BKGL,RTGL) and vendor data. - Calls
S2EDITto validate header fields. - Calls
HDRADDto write/update the transaction header. - Calls
ROLFWDto initiate detail line processing. -
Sets indicator 81 to trigger further processing.
-
Subroutine S2EDIT (Header Validation):
- Validate Invoice Date:
- Moves
INDTtoMMDDYYand callsDTEDITto validate the date.
- Moves
- Calculate Due Date:
- If
DUDTis zero andVENDis non-zero, callsCLCDUEto calculate the due date based on vendor terms (VNTERM). - Otherwise, sets
DUDT = INDT.
- If
- Validate Due Date:
- Converts
DUDTtoMMDDYYand validates viaDTEDIT. - Adjusts for century (
Y2KCEN) to createINDT8andDUDT8(8-digit dates). - Checks
APDATE(perMG17) to replaceDUDT8with a non-holiday/non-weekend date (ADNED8).
- Converts
-
Validate G/L Accounts:
- Chains to
GLMASTto validateAPGL,BKGL, andRTGL, retrieving descriptions (APGLNM,BKGLNM,RTGLNM). Sets indicators 61, 62, or 63 if invalid.
- Chains to
-
Subroutine CLCDUE (Calculate Due Date):
- If
VNTERMis non-zero, chains toGSTABL(tableAPTERM) to retrieve terms (TBNETD,TBPRXD,TBDISC,TBDISD). - If valid, retrieves discount percentage (
TBDISCtoSVDSPC, perMG03). -
Calls
TMDATN(net days) orTMDATP(prox days) to calculateDUDT. -
Subroutine TMDATN (Net Days Calculation):
- Converts
INDTto Julian format (G$JD) via@DTE1. - Adds net days (
TBNETD) toG$JD. -
Converts back to Gregorian format (
$MDY) via@DTE2to setDUDT. -
Subroutine TMDATP (Prox Days Calculation):
-
Adjusts
INDTby incrementing the month (and year if December) and sets the day toTBPRXDto calculateDUDT. -
Subroutine DTEDIT (Date Validation):
- Validates
MMDDYYby 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
SORNandSSRNare non-zero andRECSTS = 'ADDNEW', populates aSALESdata structure withCO,SORN,SSRN,ENT#,VEND,FRTL,SVDSPC, andCMPDT8(invoice date minus one year, perJB05). - Calls
AP1012to populate freight detail lines with calculated percentage amounts. - Resets
RECSTSand setsKEYENTto "001" for the first detail line.
- If
-
Subroutine S3 (Detail Line Processing):
- If
FRTLandPRAMare non-zero, calculates the freight amount (FRAM = PRAM * FRTL) and adds it toHOLDAMandSVTTL. - Adjusts
FRAMifIAMT > SVTTLto balance the invoice amount. - Combines
PRAMandFRAMto setAMT. - If
AMTis zero, clears the header (HDRCLR) and exits. - Calls
S3EDITto validate detail fields. - Calls
DETADDto write the detail line. - Calls
DETCLRto clear detail fields. - Calls
ROLFWDto process additional lines. - Updates
FRCINHorFRCFBH(settingFRAPST = 'Y') based onRCD. - Writes the updated record via
EXCPT(APINSTforFRCINH,APINSFforFRCFBH).
- If
-
Subroutine S3EDIT (Detail Validation):
- Sets default expense G/L (
EXGL) fromVNEXGLif not specified. - Chains to
GLMASTto validateEXGL, setting indicator 50 if invalid.
- Sets default expense G/L (
-
Subroutine HDRADD (Add/Update Header):
- Chains to
APTRANand writes/updates the header record usingEXCPT.
- Chains to
-
Subroutine DETADD (Add Detail Line):
- Writes the detail line to
APTRANusingEXCPT.
- 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
NXLINEand chaining toAPTRAN. - If a header is reached, calls
S2EDITto validate and sets indicator 82.
- Rolls back detail lines by decrementing
-
Program Termination:
- Sets
*INLR = *ONto end the program.
- Sets
Business Rules¶
- Invoice Processing:
- Processes invoices from
FRCINHorFRCFBHbased onRCD(FRCFBHP4for 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) fromGSTABLand 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 ofPRAMandFRTL. -
Ensures total line amount (
AMT = PRAM + FRAM) aligns with the invoice amount (IAMT). -
Freight Detail Lines:
-
Calls
AP1012to 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
APTRANwith vendor, G/L, and freight details. - Updates
FRCINHorFRCFBHto 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 typeAPTERMfor terms).APDATE: Due date adjustment file (19 bytes, keyed by company and due date, perMG17).
External Programs Called¶
- AP1012:
- Called in
ROLFWDto populate freight detail lines with calculated percentage amounts, passing theSALESdata 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!