AP106
The provided RPG program (AP106.rpg36
) is executed as part of the Accounts Payable (A/P) voucher entry upload process for FlexiCapture imports on the IBM i (AS/400) system, as referenced in the OCL file (AP106.ocl36.txt
). Below is a detailed explanation of the process steps, business rules, tables/files used, and external programs called in this RPG program.
Overview¶
The AP106
RPG program processes data from a FlexiCapture import file (APINVUP
) and converts it into A/P voucher entries in the A/P transaction file (APTRAN
). It validates vendor information, calculates due dates and discount due dates (adjusting for holidays and weekends), handles duplicate invoices based on batch numbers, and stores purchase order (PO) numbers. The program writes header and detail records to the transaction file and updates control data, ensuring proper integration with the A/P module.
Process Steps¶
- Initialization
- Sets initial values for variables (e.g., zeros for
Z5
,Z3
; blanks forMSG
,MSG2
). - Sets
PTYP
to'FLEXI'
to indicate FlexiCapture import. - Initializes indicators (e.g.,
50
,51
,60
,61
,90
) and retrieves system date/time (TIMDAT
,SYDATE
,SYTIME
). - Converts the system date to YYMMDD format (
SYDYMD
) and extracts month (MONTH
) and year (YEAR
). -
Sets indicator
09
to control the main processing loop. -
Check for Valid Import File
-
Verifies that the import file path (
AUPATH
) is not blank. If blank, the program jumps to theEND
tag and terminates. -
Retrieve A/P Control Information
- Chains to the A/P control file (
APCONT
) using indicator10
to retrieve control data. -
Stores the A/P G/L account (
ACAPGL
) inAPGL
and the cash G/L account (ACCAGL
) inBKGL
. -
Process Import File Records
- Reads records from the import file (
APINVUP
) using the01
input specification. - For each record, performs the following:
- Check for Duplicate Invoices:
- Compares the current invoice number (
AUINV#
), vendor number (AUVEND
), and batch ID (AUBTCH
) with saved values (SVINV#
,SVVEND
,SVBTCH
). - If they match, treats the record as an additional detail line for the existing voucher and skips to the
AROUND
tag to process the detail. - Get Entry Number:
- Retrieves the next entry number (
ACNXTE
) fromAPCONT
. - If the entry number (
ENT#
) is zero, chains toAPTRAN
to check for conflicts, incrementsACNXTE
andENT#
, and updatesAPCONT
viaRELAPC
exception output. - If
ENT#
is non-zero, assigns a new entry number, updatesACNXTE
, and setsRECSTS
to'ADDNEW'
. - Handles overflow if
ENT#
reaches 99999. - Validate Invoice Date:
- Converts the invoice date (
AUDATE
) to MMDDYY format (INDT
). - Extracts month (
MM
), day (DD
), and year (YY
) for further processing. - Retrieve Vendor Information:
- Chains to the vendor file (
APVEND
) usingAUVEND
to retrieve vendor details (e.g., nameVNVNAM
, addressesVNAD1
–VNAD4
, hold statusVNHOLD
, termsVNTERM
). - Stores vendor data in fields like
VNAM
,VAD1
–VAD4
. - Calculate Due Date:
- If the due date (
DUDT
) is zero and the vendor is not a one-time vendor (AUVEND ≠ 0
), calls theCLCDUE
subroutine to calculate the due date based on vendor terms (VNTERM
). - Uses the general system table (
GSTABL
) to retrieve net days (TBNETD
) or prox days (TBPRXD
) for due date calculation. - If no terms are defined, defaults to the invoice date (
INDT
) or 30 days. - Calculate Discount Due Date (MG18):
- If the discount due date (
DSDT
) is zero and the vendor is not one-time, calls theCLCDSC
subroutine to calculate the discount due date based on discount days (TBDISD
) fromGSTABL
. - Sets
DSDT
to zero if no discount days are defined. - Validate Due Date for Holidays/Weekends (MG17):
- Chains to the A/P date file (
APDATE
) using the calculated due date (DUDT8
) to check for holidays or weekends. - If a holiday/weekend is found, replaces
DUDT
with a non-holiday/weekend date (ADNED8
). - Validate Discount Due Date (MG18):
- Similarly checks the discount due date (
DSD8
) againstAPDATE
and updatesDSDT
if necessary. - Handle Vendor Hold Status:
- Sets the hold description (
HLDD
) based on the vendor hold status (VNHOLD
):'A'
: SetsHLDD
to "ON HOLD FOR ACH".'U'
: SetsHLDD
to "ON HOLD FOR AUTOPAY".'E'
: SetsHLDD
to "EMPLOYEE EXPENSE" and updatesBKGL
to the employee expense G/L (ACEEGL
).
- Write Header Record:
- Calls the
HDRADD
subroutine to write a header record toAPTRAN
using theHEADER
exception output. - Includes fields like entry number (
ACNXTE
), vendor number (AUVEND
), invoice number (AUINV#
), due date (DUDT
), and vendor details. - Process Detail Record:
- Populates detail fields (e.g., amount
AMT
, descriptionDDES
, G/L accountEXGL
, PO numberPONO
) from the import record. - Calculates discount percentage (
DSPC
) by multiplyingAUDSPC
by 10 if non-zero. - Writes a detail record to
APTRAN
using theDETAIL
exception output. - Increments the line number (
NXLINE
) for the next detail. - Save Current Record:
- Saves the invoice number (
AUINV#
), vendor number (AUVEND
), batch ID (AUBTCH
), and entry number (ENT#
) toSVINV#
,SVVEND
,SVBTCH
, andSVENT#
for comparison with the next record. - Reset Variables:
- Clears variables (e.g.,
ENT#
,TOTAL
,SNGL
,HOLD
) for the next record.
-
If the current invoice and vendor match the saved values, writes additional detail lines without creating a new header.
-
End Processing
- Loops back to process the next import record until the end of the file.
- Terminates at the
END
tag, closing files and ending the program.
Business Rules¶
- Duplicate Invoice Handling (MG19):
- If the invoice number (
AUINV#
), vendor number (AUVEND
), and batch ID (AUBTCH
) match the previous record, the program treats it as an additional detail line for the same voucher rather than creating a new voucher. -
This prevents duplicate vouchers for the same invoice within the same batch.
-
Due Date Calculation:
- For non-one-time vendors (
AUVEND ≠ 0
), calculates the due date based on the vendor’s payment terms (VNTERM
) fromGSTABL
:- Uses net days (
TBNETD
) or prox days (TBPRXD
) to determine the due date. - Defaults to the invoice date (
INDT
) or 30 days if no terms are defined.
- Uses net days (
-
Adjusts the due date to avoid holidays and weekends using the
APDATE
table (MG17). -
Discount Due Date Calculation (MG18):
- Calculates the discount due date based on discount days (
TBDISD
) fromGSTABL
for non-one-time vendors. - Sets the discount due date to zero if no discount days are defined.
-
Adjusts for holidays and weekends using
APDATE
. -
Vendor Hold Status:
-
Applies hold descriptions based on the vendor’s hold status (
VNHOLD
):'A'
: On hold for ACH payments.'U'
: On hold for autopay.'E'
: Employee expense, with the G/L account updated toACEEGL
.
-
Invoice Date Validation:
- Ensures the invoice date (
AUDATE
) is converted to a valid MMDDYY format (INDT
). -
Handles century calculation for Y2K compliance using
Y2KCEN
andY2KCMP
. -
PO Number Storage (MG20):
-
Stores the PO number (
AUPONM
) from the import file in the A/P transaction file (ATPONO
) for both header and detail records. -
Entry Number Management:
- Increments the next entry number (
ACNXTE
) fromAPCONT
for each new voucher. -
Handles overflow (entry number > 99999) by resetting and updating
ACNXTE
. -
Detail Line Description (MG17):
-
Copies the invoice description (
AUHDSC
) from the header to the detail record (DDES
) for new records. -
Discount Percentage:
- If a discount percentage (
AUDSPC
) is provided, multiplies it by 10 to store inDSPC
.
Tables/Files Used¶
The program interacts with the following database files, identified by their file names, labels, and purposes:
File Name | Label | Purpose | Access Type | Used For |
---|---|---|---|---|
APINVUP | APINVUP | Input file containing FlexiCapture import data (e.g., invoice, vendor, amount). | Input (IP) | Reading import records. |
APTRAN | APTRAN | A/P transaction file storing voucher header and detail records. | Update (UF) | Writing header/detail records, checking entry numbers. |
APCONT | APCONT | A/P control file containing G/L accounts and next entry number. | Update (UF) | Retrieving/updating control data (ACNXTE , ACAPGL , ACCAGL ). |
APVEND | APVEND | A/P vendor file containing vendor details (e.g., name, address, terms). | Input (IF) | Retrieving vendor information. |
GSTABL | GSTABL | General system table containing payment terms (e.g., net days, discount days). | Input (IF) | Retrieving terms for due date calculation. |
APDATE | APDATE | A/P date file containing non-holiday/weekend dates for due date validation. | Input (IF) | Adjusting due/discount dates for holidays/weekends. |
File Details:
- APINVUP: Record length 1090 bytes, contains fields like invoice number (AUINV#
), vendor number (AUVEND
), total amount (AUTOTL
), and PO number (AUPONM
).
- APTRAN: Record length 404 bytes, stores header (e.g., ATVEND
, ATDUDT
) and detail (e.g., ATAMT
, ATPONO
) records.
- APCONT: Record length 256 bytes, includes next entry number (ACNXTE
) and G/L accounts.
- APVEND: Record length 579 bytes, includes vendor name, addresses, and terms.
- GSTABL: Record length 256 bytes, includes terms data like net days (TBNETD
) and discount days (TBDISD
).
- APDATE: Record length 19 bytes, maps calculated due dates to non-holiday/weekend dates.
External Programs Called¶
No external programs are explicitly called via CALL
operations in this RPG program. However, the program relies on subroutines defined within itself for specific tasks:
- CLCDUE: Calculates the due date based on vendor terms (
VNTERM
), using net days (TBNETD
) or prox days (TBPRXD
). - CLCDSC: Calculates the discount due date based on discount days (
TBDISD
). - HDRADD: Writes the header record to
APTRAN
. - TMDATN: Adds net days to the invoice date to calculate the due date.
- TMDATS: Adds discount days to the invoice date to calculate the discount due date.
- TMDATP: Calculates the due date for prox terms (e.g., next month’s specific day).
- @DTE1: Converts a Gregorian date (MMDDYY) to Julian format for date calculations.
- @DTE2: Converts a Julian date back to Gregorian format.
These subroutines handle date calculations, record writing, and terms processing internally.
Additional Notes¶
- Modifications:
- MG17 (04/19/22): Added holiday/weekend due date adjustment and invoice description copying.
- MG18 (06/05/22): Added discount due date calculation and validation.
- MG19 (08/17/22): Added batch ID comparison for duplicate invoice handling.
- MG20 (11/05/23): Added PO number storage in
APTRAN
. - Y2K Compliance: The program handles century calculations for dates using
Y2KCEN
(e.g., 19 for 1900s, 20 for 2000s) andY2KCMP
(e.g., 80 to determine century). - Indicators: Uses indicators (e.g.,
50
,51
,60
,61
,79
,92
,99
) to control file access, error handling, and record processing. - File Access: Uses
CHAIN
for keyed access toAPCONT
,APVEND
,GSTABL
,APDATE
, andAPTRAN
, ensuring efficient retrieval and updates.
Summary¶
- Process Steps: Initializes variables, checks the import file, retrieves control data, processes each import record (validating dates, vendors, and terms), writes header and detail records to
APTRAN
, and updatesAPCONT
. - Business Rules: Handles duplicate invoices, calculates/adjusts due and discount dates, applies vendor hold statuses, stores PO numbers, and ensures Y2K-compliant date processing.
- Files Used:
APINVUP
(input),APTRAN
(transactions),APCONT
(control),APVEND
(vendors),GSTABL
(terms),APDATE
(dates). - External Programs: None called explicitly; relies on internal subroutines (
CLCDUE
,CLCDSC
, etc.).
Let me know if you need further clarification or additional details about specific sections or logic!