Skip to content

AP256 RPG

The provided RPG program, AP256.rpg36.txt, is executed by the OCL program AP256.ocl36.txt, which is called from the main OCL program (AP250.ocl36.txt) within an IBM System/36 or AS/400 Accounts Payable (A/P) system. Its purpose is to generate vendor payment detail reports for ACH (Automated Clearing House) vendors, with output directed to four spool files (REPORT1 to REPORT4) that are emailed to vendors. Below, I will explain the process steps, business rules, tables (files) used, and external programs called based on the RPG code.


Process Steps of the AP256 RPG Program

The AP256 RPG program processes temporary A/P transaction data (APDTWS and APDTWSC), retrieves vendor and company information, and generates up to four reports (REPORT1 to REPORT4) containing payment details for ACH vendors, formatted for emailing. Here is a detailed breakdown of the process steps:

  1. Initialization (Level 2 - Company Break):
  2. At the company level (L2, based on ADCO):

    • Retrieves the current system date and time using the TIME operation, storing it in TIMDAT (12 digits).
    • Extracts the date portion into DATE (6 digits) and converts it to a year-month-day format (DATYMD) by multiplying by 10000.01.
    • Sets the century prefix (20 for 2000s) into DATE8 (8-digit date, e.g., 20YYMMDD) and moves DATYMD into DATE8.
    • Chains to the APCONT file using the company number (ADCO) to retrieve the company name (ACNAME).
    • Initializes the page number (PAGE) to 0 and a separator line (SEP) to '* ' for report formatting.
  3. Vendor Processing (Level 1 - Vendor Break):

  4. At the vendor level (L1, based on ADVEND):

    • Chains to the APVEND file using the company/vendor number (ADCOVN) to retrieve vendor details (e.g., VNNAME, VNADD1 to VNADD4, VNZIP5, VNZPX4).
    • Chains to the APDTWSC file to retrieve the ACH transaction count (ACECNT) for the vendor.
    • Chains to the APVNFMX file up to four times to retrieve email addresses (AMEMLA) for ACH transactions (AMFMTY = 'ACHE'):
    • Stores email addresses in EMALP1 to EMALP4 for use in REPORT1 to REPORT4.
    • Initializes totals for invoice amount (L1INV$M), discount (L1DIS$M), and payment (L1PYM$M) to zero.
    • Sets indicator 60 based on the vendor type (VNCAID):
    • If VNCAID ≠ 'CRUDE', 60 is off, using standard messages (MSG,1 to MSG,3).
    • If VNCAID = 'CRUDE', 60 is on, using crude-specific messages (MSG,4 to MSG,6).
  5. Transaction Processing (Indicator 01):

  6. For each record in the APDTWS file (primary input, indicator 01):

    • Converts the payment date (ADDATE) to an 8-digit format (KYCKDTY, e.g., MMDDYYYY) using century-aware logic (Y2KCEN).
    • Formats monetary fields for reporting:
    • Invoice amount (ADINV$) to ADINV$M.
    • Discount amount (ADDISC) to ADDISCM.
    • Payment amount (ADLPAM) to ADPYM$M.
    • Accumulates totals at the vendor level (L1):
    • Adds ADINV$ to L1INV$M.
    • Adds ADDISC to L1DIS$M.
    • Adds ADLPAM to L1PYM$M.
  7. Report Generation (REPORT1 to REPORT4):

  8. Generates four reports (REPORT1 to REPORT4), each directed to a different spool file (OF, OG, OA, OB) and potentially emailed to different vendor email addresses (EMALP1 to EMALP4):

    • Headers (Lines 06-28):
    • Prints at the vendor level (L1, lines 52/53):
      • Current date (UDATE, formatted as MMDDYY).
      • Company number (ADCO) and vendor number (ADVEND).
      • Vendor name (VNNAME) and address (VNADD1 to VNADD4).
      • Messages based on vendor type:
      • Standard vendors (N60): MSG,1 to MSG,3 (e.g., "THE INVOICES LISTED BELOW WERE PAID BY ARG THROUGH ACH ON MM/DD/YY.").
      • Crude vendors (60): MSG,4 to MSG,6 (e.g., "THIS EMAIL IS NOTIFICATION THAT A DEPOSIT WILL BE MADE INTO YOUR ACCOUNT.").
      • Payment date (KYCKDTY).
      • Email address (EMALP1 to EMALP4) for the respective report.
    • Detail Lines (Line 31-33):
    • Prints for each APDTWS record:
      • Payment date (KYCKDTY).
      • Invoice number (ADINVN).
      • Invoice amount (ADINV$M).
      • Discount amount (ADDISCM).
      • Payment amount (ADPYM$M).
    • Totals (Line E 3):
    • Prints vendor-level totals at L1:
      • "TOTAL:".
      • Total invoice amount (L1INV$M).
      • Total discount (L1DIS$M).
      • Total payment (L1PYM$M).
    • Continuation Message:
    • If the report exceeds the page length, prints "CONTINUED ON NEXT PAGE".
  9. Completion:

  10. Processes all APDTWS records, generating reports for each vendor with ACH transactions.
  11. Terminates, returning control to the AP256.ocl36.txt OCL program.

Business Rules

The program enforces the following business rules based on its logic and context within the A/P system:

  1. ACH Vendor Reporting:
  2. Generates detailed payment reports for vendors using ACH payments, identified by AMFMTY = 'ACHE' in APVNFMX.
  3. Supports up to four email addresses per vendor (EMALP1 to EMALP4), allowing multiple recipients for payment notifications.

  4. Vendor Type Differentiation:

  5. Distinguishes between standard vendors and crude vendors (VNCAID = 'CRUDE'):
    • Standard vendors receive messages MSG,1 to MSG,3 (e.g., instructions to send invoices to acctpayable@amref.com).
    • Crude vendors receive messages MSG,4 to MSG,6 (e.g., notification of deposit with contact details for Ashley Lipps).
  6. Indicator 60 controls message selection based on VNCAID.

  7. Data Summarization:

  8. Accumulates invoice, discount, and payment amounts at the vendor level (L1INV$M, L1DIS$M, L1PYM$M) for reporting totals.
  9. Includes only ACH-related transactions from APDTWS, as filtered by AP256A.

  10. Date Handling:

  11. Uses century-aware date processing to format payment dates (ADDATE to KYCKDTY) based on Y2KCEN (e.g., 19 or 20 for century).

  12. Report Output:

  13. Produces four reports (REPORT1 to REPORT4), each directed to a separate spool file and potentially emailed to different vendor email addresses.
  14. Reports include vendor details, payment details, and totals, formatted for clarity and email delivery.
  15. Supports pagination with continuation messages.

  16. File Access:

  17. APDTWS is processed sequentially as the primary input file (IP).
  18. APDTWSC, APVEND, APVNFMX, and APCONT are accessed randomly (IF, keyed) for reference data.
  19. Reports are written to spool files (LPRINTER) for printing or emailing.

  20. Integration with A/P Process:

  21. Relies on APDTWS and APDTWSC being populated by AP256A and prior steps in AP250.ocl36.txt.
  22. Uses APVEND and APCONT for vendor and company details, and APVNFMX for ACH-specific email addresses.

  23. Error Handling:

  24. No explicit error reporting for unmatched records or missing data, assuming valid input from AP256A.

Tables (Files) Used

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

  1. APDTWS (IP, 256 bytes, keyed, DISK):
  2. Primary input file, temporary A/P transaction file containing payment details.
  3. Fields include:

    • ADDEL: Deletion flag (position 1).
    • ADCO: Company number (positions 2-3, L2).
    • ADVEND: Vendor number (positions 4-8, L1).
    • ADCOVN: Company/vendor number (positions 2-8).
    • ADINVN: Invoice number (positions 9-28).
    • ADIDSC: Invoice description (positions 29-53).
    • ADINV$: Invoice amount (packed, positions 54-59).
    • ADDISC: Discount amount (packed, positions 60-64).
    • ADLPAM: Last payment amount (packed, positions 65-70).
    • ADDATE: Payment date (positions 71-76).
    • ADVCH#: Voucher/check number (positions 77-81).
  4. APDTWSC (IF, 10 bytes, keyed, DISK):

  5. Indexed temporary file, containing ACH transaction counts from AP256A.
  6. Fields include:

    • ACDEL: Deletion flag (position 1).
    • ACCO: Company number (positions 2-3).
    • ACVEND: Vendor number (positions 4-8).
    • ACECNT: ACH transaction count (positions 9-10).
  7. APVEND (IF, 579 bytes, keyed, DISK):

  8. Vendor master file, containing vendor details.
  9. Fields include:

    • VNDEL: Deletion flag (position 1).
    • VNCO: Company number (positions 2-3).
    • VNVEND: Vendor number (positions 4-8).
    • VNNAME: Vendor name (positions 9-38).
    • VNADD1 to VNADD4: Address lines (positions 39-158).
    • VNZIP5: Zip code (positions 159-163).
    • VNZPX4: Extra zip (positions 164-167).
    • VNSORT: Alpha sort abbreviation (positions 168-177).
    • VNAREA: Area code (positions 178-179).
    • VNTELE: Telephone number (positions 180-183).
    • VNLPAY: Last payment amount (packed, positions 184-188).
    • VNLPDT: Last payment date (positions 189-194).
    • VN$YTD: Year-to-date purchases (packed, positions 195-200).
    • VN$LYR: Last year purchases (packed, positions 201-206).
    • VNDMTD: Month-to-date discounts (packed, positions 207-210).
    • VNDYTD: Year-to-date discounts (packed, positions 211-215).
    • VNNOVF: Name overflow flag (position 216).
    • VNPBAL: Previous balance (packed, positions 220-224).
    • VNPURC: Month-to-date purchases (packed, positions 225-229).
    • VNPAY: Month-to-date payments (packed, positions 230-234).
    • VNCBAL: Current balance (packed, positions 235-239).
    • VNHOLD: Hold payments flag (position 240).
    • VNSNGL: Single check flag (position 241).
    • VNTYDP: Year-to-date paid (packed, positions 242-247).
    • VNLYDP: Last year-to-date paid (packed, positions 248-253).
    • VNEXGL: Expense G/L account (positions 254-261).
    • VNTERM: A/P terms code (positions 262-263).
    • VN1099: 1099 code (position 264).
    • VNID#: 1099 ID number (positions 265-275).
    • VNBOX1, VNBOX2: 1099 box numbers (positions 276-279).
    • VNB2AM: 1099 box amount (packed, positions 280-285).
    • VNLPD8: Last payment date (positions 286-293).
    • VNCAID: Carrier ID (positions 294-299).
  10. APVNFMX (IF, 266 bytes, keyed, DISK):

  11. Vendor master extension file, containing ACH email addresses and other details.
  12. Fields include (based on AP256A.rpg.txt):

    • AMCONO: Company number.
    • AMCVEN: Vendor number.
    • AMCOVN: Company/vendor number.
    • AMFMTY: Form type (e.g., 'ACHE').
    • AMEMLA: Email address.
  13. APCONT (IF, 256 bytes, keyed, DISK):

  14. A/P control file, containing company details.
  15. Fields include:

    • ACNAME: Company name.
  16. REPORT1 (O, 132 bytes, LPRINTER, OF):

  17. First report spool file, emailed to EMALP1.
  18. Contains vendor payment details for ACH transactions.

  19. REPORT2 (O, 132 bytes, LPRINTER, OG):

  20. Second report spool file, emailed to EMALP2.
  21. Contains vendor payment details for ACH transactions.

  22. REPORT3 (O, 132 bytes, LPRINTER, OA):

  23. Third report spool file, emailed to EMALP3.
  24. Contains vendor payment details for ACH transactions.

  25. REPORT4 (O, 132 bytes, LPRINTER, OB):

  26. Fourth report spool file, emailed to EMALP4.
  27. Contains vendor payment details for ACH transactions.

External Programs Called

The AP256 RPG program does not call any external programs. It is self-contained, performing all processing within the main logic and level breaks (L1, L2). It is invoked by the AP256.ocl36.txt OCL program.


Summary

The AP256 RPG program generates detailed vendor payment reports for ACH vendors, formatted for emailing. Its key functions are:

  • Process Steps:
  • Initializes company-level data and retrieves company name (L2).
  • Processes vendor-level data, retrieving vendor details and up to four ACH email addresses (L1).
  • Processes APDTWS records, formatting payment details and accumulating totals.
  • Generates four reports (REPORT1 to REPORT4) with headers, detail lines, totals, and vendor-specific messages.

  • Business Rules:

  • Generates reports only for ACH vendors (AMFMTY = 'ACHE').
  • Differentiates between standard and crude vendors (VNCAID = 'CRUDE') for messaging.
  • Supports up to four email addresses per vendor for report distribution.
  • Accumulates invoice, discount, and payment totals at the vendor level.
  • Uses century-aware date formatting.
  • Produces formatted reports for printing or emailing via spool files.

  • Tables Used:

  • APDTWS: Temporary A/P transaction file (input).
  • APDTWSC: Indexed temporary file with ACH counts (input).
  • APVEND: Vendor master file (input).
  • APVNFMX: Vendor master extension file (input).
  • APCONT: A/P control file (input).
  • REPORT1 to REPORT4: Report spool files (output).

  • External Programs Called: None.

The program integrates with the A/P process by leveraging data prepared by AP256A and prior steps, producing vendor-specific reports for ACH payments. If you need further details (e.g., specific report formats or email delivery mechanics), please let me know!