Skip to content

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

  1. Initialization
  2. Sets initial values for variables (e.g., zeros for Z5, Z3; blanks for MSG, MSG2).
  3. Sets PTYP to 'FLEXI' to indicate FlexiCapture import.
  4. Initializes indicators (e.g., 50, 51, 60, 61, 90) and retrieves system date/time (TIMDAT, SYDATE, SYTIME).
  5. Converts the system date to YYMMDD format (SYDYMD) and extracts month (MONTH) and year (YEAR).
  6. Sets indicator 09 to control the main processing loop.

  7. Check for Valid Import File

  8. Verifies that the import file path (AUPATH) is not blank. If blank, the program jumps to the END tag and terminates.

  9. Retrieve A/P Control Information

  10. Chains to the A/P control file (APCONT) using indicator 10 to retrieve control data.
  11. Stores the A/P G/L account (ACAPGL) in APGL and the cash G/L account (ACCAGL) in BKGL.

  12. Process Import File Records

  13. Reads records from the import file (APINVUP) using the 01 input specification.
  14. 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) from APCONT.
    • If the entry number (ENT#) is zero, chains to APTRAN to check for conflicts, increments ACNXTE and ENT#, and updates APCONT via RELAPC exception output.
    • If ENT# is non-zero, assigns a new entry number, updates ACNXTE, and sets RECSTS 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) using AUVEND to retrieve vendor details (e.g., name VNVNAM, addresses VNAD1VNAD4, hold status VNHOLD, terms VNTERM).
    • Stores vendor data in fields like VNAM, VAD1VAD4.
    • Calculate Due Date:
    • If the due date (DUDT) is zero and the vendor is not a one-time vendor (AUVEND ≠ 0), calls the CLCDUE 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 the CLCDSC subroutine to calculate the discount due date based on discount days (TBDISD) from GSTABL.
    • 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) against APDATE and updates DSDT if necessary.
    • Handle Vendor Hold Status:
    • Sets the hold description (HLDD) based on the vendor hold status (VNHOLD):
      • 'A': Sets HLDD to "ON HOLD FOR ACH".
      • 'U': Sets HLDD to "ON HOLD FOR AUTOPAY".
      • 'E': Sets HLDD to "EMPLOYEE EXPENSE" and updates BKGL to the employee expense G/L (ACEEGL).
    • Write Header Record:
    • Calls the HDRADD subroutine to write a header record to APTRAN using the HEADER 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, description DDES, G/L account EXGL, PO number PONO) from the import record.
    • Calculates discount percentage (DSPC) by multiplying AUDSPC by 10 if non-zero.
    • Writes a detail record to APTRAN using the DETAIL 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#) to SVINV#, SVVEND, SVBTCH, and SVENT# for comparison with the next record.
    • Reset Variables:
    • Clears variables (e.g., ENT#, TOTAL, SNGL, HOLD) for the next record.
  15. If the current invoice and vendor match the saved values, writes additional detail lines without creating a new header.

  16. End Processing

  17. Loops back to process the next import record until the end of the file.
  18. Terminates at the END tag, closing files and ending the program.

Business Rules

  1. Duplicate Invoice Handling (MG19):
  2. 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.
  3. This prevents duplicate vouchers for the same invoice within the same batch.

  4. Due Date Calculation:

  5. For non-one-time vendors (AUVEND ≠ 0), calculates the due date based on the vendor’s payment terms (VNTERM) from GSTABL:
    • 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.
  6. Adjusts the due date to avoid holidays and weekends using the APDATE table (MG17).

  7. Discount Due Date Calculation (MG18):

  8. Calculates the discount due date based on discount days (TBDISD) from GSTABL for non-one-time vendors.
  9. Sets the discount due date to zero if no discount days are defined.
  10. Adjusts for holidays and weekends using APDATE.

  11. Vendor Hold Status:

  12. 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 to ACEEGL.
  13. Invoice Date Validation:

  14. Ensures the invoice date (AUDATE) is converted to a valid MMDDYY format (INDT).
  15. Handles century calculation for Y2K compliance using Y2KCEN and Y2KCMP.

  16. PO Number Storage (MG20):

  17. Stores the PO number (AUPONM) from the import file in the A/P transaction file (ATPONO) for both header and detail records.

  18. Entry Number Management:

  19. Increments the next entry number (ACNXTE) from APCONT for each new voucher.
  20. Handles overflow (entry number > 99999) by resetting and updating ACNXTE.

  21. Detail Line Description (MG17):

  22. Copies the invoice description (AUHDSC) from the header to the detail record (DDES) for new records.

  23. Discount Percentage:

  24. If a discount percentage (AUDSPC) is provided, multiplies it by 10 to store in DSPC.

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:

  1. CLCDUE: Calculates the due date based on vendor terms (VNTERM), using net days (TBNETD) or prox days (TBPRXD).
  2. CLCDSC: Calculates the discount due date based on discount days (TBDISD).
  3. HDRADD: Writes the header record to APTRAN.
  4. TMDATN: Adds net days to the invoice date to calculate the due date.
  5. TMDATS: Adds discount days to the invoice date to calculate the discount due date.
  6. TMDATP: Calculates the due date for prox terms (e.g., next month’s specific day).
  7. @DTE1: Converts a Gregorian date (MMDDYY) to Julian format for date calculations.
  8. @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) and Y2KCMP (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 to APCONT, APVEND, GSTABL, APDATE, and APTRAN, 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 updates APCONT.
  • 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!