Skip to content

AP250 RPG

The provided RPG program, AP250.rpg36.txt, is part of an IBM System/36 or AS/400 Accounts Payable (A/P) system, specifically designed to generate a Check Register, update master files, and handle related financial transactions such as checks, ACH payments, wire transfers, and employee expenses. It is called from the AP250.ocl36.txt OCL program. Below, I will explain the process steps, business rules, tables (files) used, and external programs called (if any) based on the RPG code.


Process Steps of the AP250 RPG Program

The RPG program AP250 processes A/P check data, updates related files (e.g., vendor, open invoices, history, and reconciliation files), and produces a Check Register report. It handles various payment types (checks, ACH, wire transfers, and employee expenses) and applies specific logic based on record codes and payment statuses. Below is a detailed breakdown of the process steps:

  1. File Initialization and Setup:
  2. The program defines input, update, and output files (see Tables Used below) for processing A/P checks, payments, vendor data, and history.
  3. It initializes variables for totals (e.g., C3CNT, C3AMT for computer checks, P3CNT, P3AMT for prepaid checks, A3CNT, A3AMT for ACH, W3CNT, W3AMT for wire transfers, E3CNT, E3AMT for employee expenses) and other control fields.

  4. Main Processing Loop (Level Breaks):

  5. L4 (Company/Bank G/L Level):

    • Executes the L4DET subroutine to initialize company-level processing.
    • Retrieves the current date and time (TIMDAT) and formats it for reporting (DATE8).
    • Chains to APCONT to fetch company details (e.g., ACNAME, ACDSGL, ACCDJR, ACCKNO).
    • Determines the journal ID (JRNID) based on whether the transaction is a wire transfer (WIRE='WT', sets JRNID='WD') or standard check (JRNID='CD' or ACCDJR).
    • Sets payment method description (PAYBY) based on PTHOLD (e.g., 'PAY BY CHECK', 'PAY BY ACH', 'PAY BY WIRE TFR', 'PAY BY PAYROLL').
    • For ACH, wire transfers, or employee expenses, sets indicator 50 to skip updating APCHKR.
  6. Check Record Processing (EACH01 Subroutine):

  7. Processes each record in APPYCK (check file) using indicator 01.
  8. Formats the check date (AXCKDT) into AXYMD8 for reporting.
  9. Copies the check number to the Positive Pay field (PNCCHK) for external bank reconciliation.
  10. Evaluates the record code (AXRECD):
    • 'C': Credit/no pay, skips processing (19 set, jumps to ENDL1D).
    • 'F': Full stub, void check, continues to next stub with the same check number (12 set).
    • 'V': Full stub, void check, uses next check number (13 set).
    • 'P', 'A', 'W', 'E': Prepaid check, ACH, wire transfer, or employee expense, respectively (25, 26, 27, 28 set, and 11 for prepaid).
  11. Updates APCHKR (Check Reconciliation file):
    • Chains to APCHKR using a key (AMKEY) built from company number (CONO), bank G/L (BKGL), and check number (AXCHEK).
    • If not found (90 set), initializes fields (AMCODE, AMCKAM, AMCLDT, AMOCAM).
    • For voided checks (13 set), sets AMCODE='V', clears AMCKAM, and updates clear date (AMCLDT, CLDT8).
    • For non-voided checks, sets AMCODE='O' (open) and updates AMCKAM with the check amount (AXAMT).
    • Formats dates for Positive Pay (PNCDT8) and sets PNCCOD ('V' for void, 'I' for issued).
  12. Updates counters and totals (C3CNT, C3AMT, etc.) based on payment type, excluding voided checks (N13).

  13. Payment Processing (EACH02 Subroutine):

  14. Processes each payment record in APPAY (payment file) using indicator 02 and N19 (non-credit records).
  15. Accumulates totals for gross amount (L2GRAM), discount (L2DISC), partial paid to date (L2PPTD), and payment amount (L2AMT) at the vendor level (L2).
  16. Updates vendor name overflow (AXNAM2) from APVEND2 if VNNOVF='Y'.
  17. Calculates A/P reduction (OPPAY = OPDISC + OPLPAM) and open amount (OPOPEN = OPGRAM - OPPPTD - OPPAY).
  18. If fully paid (OPOPEN=0, 20 set), marks the record for deletion.
  19. Updates APOPEN (open invoices):
    • Sets lower limit (SETLL) using OPKEY and reads records.
    • Chains to APOPENH, APOPEND, or APOPENV based on indicators (04, 05, 06) to update or delete records.
    • If fully paid (20 set), writes deletion records ('D') to APOPENH, APOPEND, or APOPENV.
  20. Updates freight-related files (FRCFBH, FRCINH):
    • Builds a key (FRCKEY, FRCK39) using company number (CONO), carrier ID (OPCAID), invoice number (OPINVN), or sales order number (OPSORN).
    • Chains to FRCFBH (freight bill override header) first; if found and posted (FRAPST='Y'), writes to FRCFBH (APFBST exception).
    • If not found in FRCFBH, chains to FRCINH (carrier invoice header) and writes to FRCINH (APINST exception).
  21. Updates APPYDS (discount missed table):
    • Chains to APPYDS using OPKY1 and writes records if a discount is missed (97 not set).
  22. Writes history records to APHISTH, APHISTD, APHISTV for header, detail, and one-time vendor transactions, including payment details, check numbers, and dates.

  23. Vendor Totals Update (L2TOT Subroutine):

  24. At the vendor level break (L2), updates APVEND:

    • Chains to APVEND using a key (VNKEY) built from company number (CONO) and vendor number (VEND).
    • Updates fields:
    • Last payment amount (VNLPAY += L2AMT).
    • Last payment date (VNLPDT, VNLPD8).
    • Month-to-date discounts (VNDMTD += L2DISC).
    • Year-to-date discounts (VNDYTD += L2DISC).
    • Month-to-date payments (VNPAY += L2AMT + L2DISC).
    • Current balance (VNCBAL -= L2AMT + L2DISC).
    • Year-to-date paid (VNTYDP += L2PAID).
  25. Company Totals and Control Update (L4TOT Subroutine):

  26. At the company/bank G/L level break (L4), updates APCONT:

    • Increments the next check number (ACCKNO) if the last check number (L4CHEK) is greater than zero and matches or exceeds the current ACCKNO.
    • Increments the next cash disbursements journal number (ACCDJR).
  27. Output Generation:

  28. Check Register (APPRINT):
    • Prints headers with company name (ACNAME), payment method (PAYBY), page number, date, time, and journal ID (JRNID).
    • Prints detail lines for each check (AXCHEK, VEND, AXNAME, AXCKDT, AXAMT) with annotations for prepaid, ACH, wire transfer, employee expense, or void status.
    • Prints totals for computer checks, prepaid checks, ACH payments, wire transfers, employee expenses, and overall totals.
  29. Positive Pay File (APPNCF):
    • Outputs check data (PNCCHK, PNCDT8, AXAMT, AXNAME, AXNAM2, PNCCOD) for bank reconciliation.
  30. Cash Disbursements Journal (APCDJR):

    • Writes records for cash (C), discount (D), and A/P (AP) entries, including company number (CONO), journal ID (JRNID), bank G/L (BKGL), check number (AXCHEK), description (DESC23), check date (PTCKDT), amount (OPLPAM, CDDISC, OPPAY), and vendor name (AXNAME).
  31. Cleanup:

  32. Ensures all files are updated or written as needed (e.g., APOPEN, APHISTH, APHISTD, APHISTV, APCHKR, FRCFBH, FRCINH, APCDJR, APPYDS).
  33. Commits changes to master files (APVEND, APCONT) at the appropriate level breaks.

Business Rules

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

  1. Payment Type Handling:
  2. Supports multiple payment types based on AXRECD and PTHOLD:
    • 'C': Credit/no pay, skips processing.
    • 'F', 'V': Void checks with different behaviors for check number reuse.
    • 'P', 'A', 'W', 'E': Prepaid checks, ACH, wire transfers, and employee expenses, respectively.
  3. Wire transfers, ACH, and employee expenses skip APCHKR updates (indicator 50 set).

  4. Check Reconciliation:

  5. Updates APCHKR for non-prepaid, non-void checks with status 'O' (open) or 'V' (voided).
  6. Maintains original check amount (AMOCAM) and clear date (AMCLDT) for voided checks.

  7. Vendor Balance and History:

  8. Tracks vendor totals (last payment, discounts, balance, year-to-date paid) in APVEND.
  9. Records payment history in APHISTH (header), APHISTD (detail), and APHISTV (one-time vendor).
  10. Adjusts vendor current balance (VNCBAL) by subtracting payment and discount amounts.

  11. Open Invoice Management:

  12. Marks fully paid invoices (OPOPEN=0) for deletion ('D') in APOPENH, APOPEND, APOPENV.
  13. Updates partial payments (OPPPTD += OPLPAM).

  14. Freight Invoice Processing:

  15. Updates FRCFBH (freight bill override header) or FRCINH (carrier invoice header) for freight invoices with a carrier ID (OPCAID).
  16. Sets posting status (FRAPST='P') for freight records.

  17. Discount Tracking:

  18. Records missed discounts in APPYDS if applicable.
  19. Accumulates discounts taken (VNDMTD, VNDYTD) in APVEND.

  20. Journal and Check Numbering:

  21. Increments ACCDJR (journal number) and ACCKNO (check number) in APCONT for tracking.
  22. Ensures unique journal entries in APCDJR for cash, discounts, and A/P accounts.

  23. Date Handling:

  24. Supports century-aware date processing using Y2KCEN (e.g., 19 for 1900s, 20 for 2000s).
  25. Formats dates for reporting (AXYMD8, CDYMD8, PNCDT8) and Positive Pay output.

  26. Positive Pay Compliance:

  27. Generates formatted output (APPNCF) for bank reconciliation, including check number, date, amount, vendor name, and void/issue code (PNCCOD).

Tables (Files) Used

The program uses the following files, as defined in the File Specification (F-spec) section:

  1. Input Files:
  2. APPYCK (IP, 96 bytes, keyed): Check file, contains check details (e.g., AXCHEK, AXAMT, AXCKDT, VEND, AXNAME, AXRECD).
  3. APPAY (IS, 384 bytes, keyed): Payment file, contains payment details (e.g., COVNVO, OPGRAM, OPDISC, OPLPAM, OPPAID).
  4. APPYTR (IC, 128 bytes, keyed): Transaction file, contains check date (PTCKDT, PTCKYY) and hold code (PTHOLD).
  5. APVEND (UC, 579 bytes, keyed): Vendor master file, contains vendor details (e.g., VNNAME, VNLPAY, VNCBAL).
  6. APVEND2 (IC, 579 bytes, keyed): Secondary vendor file, includes address and name overflow (VNNOVF).
  7. APCHKR (UC, 128 bytes, keyed): Check reconciliation file, tracks check status (AMCODE, AMCKAM, AMCLDT).
  8. APOPEN (ID, 384 bytes, keyed): Open A/P invoices, contains invoice details (OPKY1, OPKY2, OPGRAM, OPDISC).
  9. APOPENH (UC, 384 bytes, keyed): Open A/P header file, used for header-level updates.
  10. APOPEND (UC, 384 bytes, keyed): Open A/P detail file, used for detail-level updates.
  11. APOPENV (UC, 384 bytes, keyed): Open A/P one-time vendor file, used for one-time vendor updates.
  12. FRCINH (UF, 206 bytes, keyed): Freight carrier invoice header, tracks freight invoice details.
  13. FRCFBH (UF, 206 bytes, keyed): Freight bill override header, used for freight bill overrides.
  14. APPYDS (IF, 384 bytes, keyed): Discount missed table, tracks missed discount invoices.

  15. Output Files:

  16. APHISTH (O, 384 bytes): A/P history header file, stores header-level payment history.
  17. APHISTD (O, 384 bytes): A/P history detail file, stores detail-level payment history.
  18. APHISTV (O, 384 bytes): A/P history one-time vendor file, stores one-time vendor payment history.
  19. APCDJR (O, 128 bytes): Cash disbursements journal file, records journal entries for cash, discounts, and A/P.
  20. APPNCF (O, 155 bytes, PRINTER): Positive Pay file for bank reconciliation.
  21. APPRINT (O, 132 bytes, PRINTER): Check Register report file.
  22. APDSMS (O, 384 bytes): Discount missed summary file, stores summary data for missed discounts.

  23. Table File:

  24. AP250S (IR, 3 bytes, keyed): Internal table file, likely used for temporary storage or control data.

External Programs Called

The RPG program does not explicitly call external programs (e.g., via CALL or EXSR to external routines). All processing is handled within the AP250 program through its subroutines (L4DET, EACH01, EACH02, L2TOT, L4TOT). The program is self-contained, relying on file operations and internal logic to perform its tasks. However, it is called by the AP250.ocl36.txt OCL program, which orchestrates the broader A/P process.


Summary

The AP250 RPG program is a critical component of the A/P system, responsible for processing checks, updating master files, and generating reports. It: - Processes check and payment records, handling various payment types (checks, ACH, wire transfers, employee expenses). - Updates vendor balances, open invoices, freight records, and history files. - Generates a Check Register (APPRINT), Positive Pay file (APPNCF), and Cash Disbursements Journal (APCDJR). - Enforces business rules for payment types, invoice status, discount tracking, and reconciliation. - Uses a variety of input, update, and output files to manage A/P data.

The program is tightly integrated with the OCL program (AP250.ocl36.txt) and relies on shared files to maintain data consistency across the A/P process. If you meant VNNOVF as a field (noted in APVEND2 as a name overflow indicator) rather than a file, it is used to determine if additional vendor name data (VNADD1) should be moved to AXNAM2 for reporting. Please clarify if you need further details on VNNOVF or any other aspect.