Skip to content

AP200 RPG

The RPG program AP200 is an Accounts Payable (A/P) Purchase Register program that processes vendor invoices, vouchers, and related transactions. Below is a detailed analysis of the process steps, business rules, tables used, and external programs called based on the provided source code.


Process Steps

The program follows a structured flow to process A/P transactions, including header and detail records, cancellations, intercompany transfers, and updates to various files. The main steps are:

  1. Initialization (ONCE routine):
  2. Executes once at program start.
  3. Converts the journal date (JRDATE) to a year-month-day format (PJYMD).
  4. Handles Y2K logic to determine the century (JCN).
  5. Initializes variables (e.g., Z5, Z6, Z7, Z8, Z9, Z10, Z4, ONE1, ONE3, TWO1, THREE1) to zeros or specific values.
  6. Sets the POKEY to '000' and increments the ONCE counter.

  7. Level 2 Processing (L2DET subroutine):

  8. Initializes page number, captures system time and date.
  9. Converts system date (SYSDAT) to a year-month-day format (SYSYMD).
  10. Chains to APCONT to retrieve company data and next voucher number (ACNXVO).
  11. Determines journal ID (JRNID) based on wire transfer flag (WIRE):
    • 'WT' for wire transfers, 'EE' for employee expenses, or 'PJ' otherwise.
  12. Updates ACJRNL (journal number) and writes to APCONT if not found.
  13. Initializes level 2 accumulators (L2PAMT, L2FAMT, L2AMT, L2DISC).

  14. Level 1 Processing (L1DET subroutine):

  15. Initializes level 1 accumulators (L1PAMT, L1FAMT, L1AMT, L1DISC, L1RTAM, L1RTDS).
  16. Resets indicators (e.g., 03, 10, 12, 13, 19, 24, 25, 32).
  17. Initializes sequence number (SEQ#).

  18. Header Record Processing (EACH01 subroutine):

  19. Processes header records from APTRAN.
  20. Checks if the voucher is deleted (ATHDEL = 'D'):
    • If deleted, updates FRCFBH and FRCINH to blank FRAPST if it was 'Y'.
    • Skips further processing for deleted vouchers.
  21. Converts dates (ATINDT, ATDUDT, ATPCKD, ATDSDT) to internal format.
  22. Validates vendor number (ATVEND), canceled voucher (ATCNVO), prepaid status (ATPAID), single check (ATSNGL), and hold codes (ATHOLD).
  23. Assigns voucher number (VOUCHR) from NXTVO or retention voucher (RTVO) if applicable.
  24. Processes prepaid vouchers (check, ACH, wire transfer, employee expense) by updating APPYTR.
  25. Handles canceled vouchers by calling the CANCEL subroutine.
  26. Checks for retention (ATRTPC) and calculates retention amounts if applicable.

  27. Detail Record Processing (EACH02 subroutine):

  28. Processes detail records from APTRAN.
  29. Handles gallons (ATGALN) and receipt number (ATRCPT) for printing.
  30. Calculates discounts based on discount percent (ATDSPC) and amount (ATAMT).
  31. Processes retention amounts (ATRTAM, ATRTDS) if applicable.
  32. Updates payment transaction records (APPYTR) for discounts.
  33. Accumulates amounts (L1AMT, L1PAMT, L1FAMT, L1DISC, L1RTAM, L1RTDS).
  34. Checks for intercompany transfers by calling INTRCO if company numbers differ (ATCONO ≠ ATEXCO).
  35. Updates purchase order files (POFILEH, POFILED) if ACPOYN = 'Y' and ATPONO is not blank.

  36. Cancel Voucher Processing (CANCEL subroutine):

  37. Processes canceled vouchers (ATCNVO).
  38. Builds a key (OPKY12) using company and vendor data.
  39. Reads APOPEN to find matching records.
  40. Updates APOPENH, APOPEND, or APOPENV based on record type (OPRCTY).
  41. Writes history records to APHISTH, APHISTD, or APHISTV.

  42. Level 1 Totals (L1TOT subroutine):

  43. Accumulates level 1 totals into level 2 totals (L2PAMT, L2FAMT, L2AMT, L2DISC).
  44. Updates vendor totals (VN$YTD, VNPURC, VNCBAL) in APVEND.
  45. Writes invoice header (APINVH) if vendor is not zero.
  46. Writes totals to APPRINT.

  47. Intercompany Transfers (INTRCO subroutine):

  48. Processes intercompany transfers when company numbers differ.
  49. Sets debit and credit company codes (IDRCO, ICRCO) and G/L accounts (IDRGL, ICRGL).
  50. Writes journal entries to APPJJR for debit and credit sides.
  51. Handles retention amounts separately if applicable.

  52. Output Processing:

  53. Writes records to output files (APOPENH, APOPEND, APOPENV, APHISTH, APHISTD, APHISTV, APPJJR, APPYTR, APVEND, APINVH, POFILEH, POFILED, FRCINH, FRCFBH).
  54. Generates a purchase register report via APPRINT.

Business Rules

The program enforces several business rules to ensure accurate A/P processing:

  1. Voucher Number Assignment:
  2. Voucher numbers are assigned from ACNXVO in APCONT and incremented.
  3. Retention vouchers (RTVO) are assigned separately if ATRTPC is non-zero.
  4. Canceled vouchers use the original voucher number (ATCNVO).

  5. Prepaid Vouchers:

  6. Prepaid vouchers are flagged with ATPAID = 'P' (check), 'A' (ACH), 'W' (wire transfer), or 'E' (employee expense).
  7. Payment transactions are written to APPYTR for prepaid vouchers.

  8. Hold Vouchers:

  9. Vouchers can be held with ATHOLD = 'H' (hold), 'A' (ACH), 'W' (wire transfer), 'E' (employee expense), or 'U' (utility auto-pay).
  10. Hold descriptions (ATHLDD) are printed for held vouchers.

  11. Discounts:

  12. Discounts are calculated if ATDSPC (discount percent) is non-zero.
  13. Discount amount (ATDISC) is computed as ATAMT * (ATDSPC / 100).
  14. Discounts are accumulated in L1DISC and written to APPYTR.

  15. Retention:

  16. Retention is processed if ATRTPC (retention percent) is non-zero.
  17. Retention amount (ATRTAM) is calculated as ATAMT * (ATRTPC / 100).
  18. Retention vouchers are written to APOPENH, APOPEND, and APOPENV with a hold code ('H') and description ('RETENTION').

  19. Intercompany Transfers:

  20. If ATCONO ≠ ATEXCO, intercompany journal entries are written to APPJJR.
  21. Debit and credit entries use the intercompany G/L account (ACICGL).

  22. Purchase Order Integration:

  23. If ACPOYN = 'Y' and ATPONO is non-blank, updates POFILEH (header) and POFILED (detail).
  24. Updates applied amount (POAPPU), received quantity (PDRCQT), and A/P voucher amount (PDAPV$).

  25. Deleted Vouchers:

  26. If ATHDEL = 'D', blanks FRAPST in FRCINH or FRCFBH if it was 'Y'.
  27. Skips further processing for deleted vouchers.

  28. Single Check and Canceled Vouchers:

  29. Single check vouchers are flagged with ATSNGL = 'S'.
  30. Canceled vouchers are processed by updating APOPEN and writing to APHIST.

  31. Y2K Date Handling:

    • Adjusts century for dates based on Y2KCMP and Y2KCEN.
  32. Journal ID Assignment:

    • Assigns JRNID as 'WT' for wire transfers, 'EE' for employee expenses, or 'PJ' otherwise.

Business Rules

  1. Voucher Processing:
  2. Processes header (NS 01) and detail (NS 02) records from APTRAN, skipping deleted vouchers (ATHDEL = 'D').
  3. Assigns new voucher numbers (NXTVO) for non-canceled, non-100% retention vouchers and retention vouchers.
  4. Supports multiple payment types: prepaid (P), ACH (A), wire transfer (W), employee expense (E), and utility auto-pay (U).

  5. Freight Invoice Handling:

  6. Clears FRAPST to blank in FRCINH or FRCFBH if a voucher is deleted and FRAPST = 'Y'.
  7. Prioritizes FRCFBH (freight bill override header) over FRCINH (carrier invoice header) when checking freight status.

  8. Discounts and Retentions:

  9. Calculates discounts if ATDSPC ≠ 0 and ATDISC = 0 (ATDISC = ATAMT * (ATDSPC / 100)).
  10. For retentions (ATRTPC ≠ 0), computes retention amount (ATRTAM) and adjusts ATAMT. For 100% retention, moves ATAMT to ATRTAM and zeros ATAMT.

  11. Intercompany Transfers:

  12. Generates journal entries (APPJJR) for intercompany transactions (ATCONO ≠ ATEXCO) using intercompany G/L accounts (ACICGL).

  13. Cancellation:

  14. Marks canceled vouchers (ATCNVO ≠ *ZEROS) as deleted ('D') in APOPENH, APOPEND, APOPENV and writes history records (APHISTH, APHISTD, APHISTV).

  15. Vendor and Invoice Updates:

  16. Updates vendor balances (VN$YTD, VNPURC, VNCBAL) with voucher and retention amounts.
  17. Records invoice details in APINVH for non-one-time vendors.

  18. Journal Entries:

  19. Generates APPJJR entries for A/P, expense, and intercompany accounts, including retention and non-retention transactions.

  20. Purchase Order Updates:

  21. Disabled (skipped via GOTO SKIP), but intended to update POFILEH (POAPPU) and POFILED (PDRCQT, PDAPV$, PDRCDT, PDCOMP).

  22. Reporting:

  23. Produces a detailed Purchase Register with company, voucher, and line item details, including special fields like sales order, carrier ID, and process type.

Tables Used

The program interacts with the following files (tables):

File Name Type Description Usage
APTRAN Input A/P Transaction File Reads header and detail records
APCONT Update A/P Control File Retrieves company data, updates ACJRNL, ACNXVO
APVEND Update A/P Vendor File Updates vendor totals (VN$YTD, VNPURC, VNCBAL)
APOPEN Input A/P Open File Reads open vouchers for cancellation
APOPENH Update A/P Open Header File Writes/updates header records
APOPEND Update A/P Open Detail File Writes detail records
APOPENV Update A/P Open Vendor File Writes vendor records
APINVH Input A/P Invoice Header File Writes invoice header records
POFILEH Update Purchase Order Header File Updates applied amounts (POAPPU)
POFILED Update Purchase Order Detail File Updates received qty (PDRCQT), voucher amounts
APHISTH Output A/P History Header File Writes history header records
APHISTD Output A/P History Detail File Writes history detail records
APHISTV Output A/P History Vendor File Writes history vendor records
APPJJR Output A/P Journal File Writes journal entries
APPYTR Update A/P Payment Transaction File Writes/updates payment transactions
FRCINH Update Freight Invoice Header File Updates FRAPST for deleted vouchers
FRCFBH Update Freight Bill Override Header File Updates FRAPST for deleted vouchers
APPRINT Output A/P Purchase Register Report Generates the purchase register report

External Programs Called

The program does not explicitly call external programs using the CALL opcode. All processing is handled within the program through subroutines and file operations. The subroutines used are:

  • L2DET: Level 2 detail processing.
  • L1DET: Level 1 detail processing.
  • EACH01: Header record processing.
  • EACH02: Detail record processing.
  • CANCEL: Cancel voucher processing.
  • L1TOT: Level 1 totals processing.
  • INTRCO: Intercompany transfer processing.

No external programs are invoked, as the program is self-contained for A/P processing.


Summary

The AP200 RPG program is a comprehensive A/P Purchase Register system that processes vendor invoices, assigns voucher numbers, handles prepaid and held vouchers, calculates discounts and retentions, and supports intercompany transfers and purchase order integration. It uses 16 files for input, update, and output operations and enforces strict business rules for data integrity. No external programs are called, and all logic is managed via internal subroutines.