Skip to content

AP156 RPG

Below, I provide a detailed analysis of the AP156.ocl36.txt OCL script and the AP156.rpg36.txt RPG program, which are part of the Accounts Payable (A/P) payment processing system. The OCL script invokes the AP156 RPG program to create a National Automated Clearing House Association (NACHA) file for ACH payments to PNC Bank. I will outline the process steps, business rules, tables used, and external programs called for both the OCL and RPG components.


AP156.ocl36.txt (OCL Script)

Process Steps

The AP156.ocl36.txt OCL script is responsible for initiating the creation of a NACHA file for ACH payments. The steps are as follows:

  1. Conditional Execution Check:
  2. Checks if the payment run is for ACH payments by examining position 400 of the Local Data Area (LDA). The value must be 'A', set by the AP155 program if ACH payments (OPPAID = 'A') are detected in APPAY.
  3. If the LDA position 400 does not contain 'A', the script jumps to the END tag, skipping execution of the AP156 program.

  4. Clear ACH File:

  5. Executes the CLRPFM command to clear the physical file ACHFIL (labeled ?9?ACHFIL), ensuring no residual data from previous runs.

  6. Load and Run AP156 Program:

  7. Loads the AP156 RPG program using the LOAD AP156 command.
  8. Specifies input and output files:
    • APPYCK: Check file, labeled ?9?APPC?WS?, shared access (DISP-SHR).
    • APCONT: A/P control file, labeled ?9?APCONT, shared access.
    • APVEND: Vendor file, labeled ?9?APVEND, shared access.
    • ACHFILE: Output NACHA file, labeled ?9?ACHFIL, shared access.
  9. Executes the program using the RUN command.

  10. Termination:

  11. If the ACH condition is not met, the script terminates at the END tag without running AP156.

Business Rules

  1. ACH Payment Requirement:
  2. The script only proceeds if the payment run includes ACH payments (LDA position 400 = 'A').
  3. If no ACH payments are present, the script skips execution to avoid unnecessary processing.

  4. File Preparation:

  5. The ACHFIL file must be cleared before processing to ensure a clean slate for the NACHA file output.

  6. Shared File Access:

  7. All files (APPYCK, APCONT, APVEND, ACHFILE) are opened with shared access (DISP-SHR) to allow concurrent access by other programs or processes.

Tables (Files) Used

  1. APPYCK (?9?APPC?WS?):
  2. Check file containing payment records.
  3. APCONT (?9?APCONT):
  4. A/P control file with company details.
  5. APVEND (?9?APVEND):
  6. Vendor file with vendor details, including ACH information.
  7. ACHFILE (?9?ACHFIL):
  8. Output file for the NACHA-formatted ACH payment data.

External Programs Called

  • AP156: The RPG program loaded and executed to create the NACHA file.

AP156.rpg36.txt (RPG Program)

Process Steps

The AP156 RPG program generates a NACHA-formatted file (ACHFILE) for ACH payments to PNC Bank, processing records from APPYCK and retrieving additional data from APCONT and APVEND. The program produces a structured file with specific record types (1, 5, 6, 8, 9) as required by NACHA standards. Here are the steps:

  1. Initialization (ONETIM Subroutine):
  2. Executes once (ONCE = 1) to set up the environment:

    • Retrieves system date and time (SYTMDT) and formats the date for NACHA records.
    • Initializes counters: BATCH# (batch number), TRACE# (trace number), LRCNT (entry count), LRHASH (hash total), LRDR (debit total), LRCR (credit total), RECCNT (record count).
    • Writes the File Header Record (Type 1) to ACHFILE with fields like priority code, ABA numbers, transmission date/time, and company names.
  3. Process APPYCK Records:

  4. Reads APPYCK records (check file) sorted by company (PYCONO) and vendor (PYVEND).
  5. For each record:

    • Validates that the record is not a detail record (NS 01) and has a valid status (PYSTAT = 'A' for ACH payments).
    • Chains to APCONT to retrieve company details (e.g., ACNAME, ACBKGL) using PYCONO.
    • Chains to APVEND to retrieve vendor ACH details (e.g., VNARTE, VNABK#, VNACOS, PYNAME) using PYVEND.
  6. Write Batch Header (L2DET Subroutine):

  7. On the first record for a new company (L1, N84), writes a Batch Header Record (Type 5) to ACHFILE.
  8. Includes fields like service class code (200 for credits), company name, tax ID, and effective entry date (CKYMD from PYCKDT).
  9. Initializes batch counters (L2CNT, L2HASH, L2DR, L2CR).

  10. Write Entry Detail (EACH Subroutine):

  11. For each APPYCK record:

    • Determines the transaction code (TRNCDE): '22' for checking accounts (VNACOS = 'C') or '32' for savings accounts.
    • Sets the payment amount (AMOUNT = PYCKAM).
    • Updates counters: increments TRACE#, L2CNT, LRCNT, RECCNT, and adds VNARTE to L2HASH and LRHASH, and AMOUNT to L2CR and LRCR.
    • Writes an Entry Detail Record (Type 6) to ACHFILE with vendor bank routing code (VNARTE), account number (VNABK#), amount, vendor ID, and name.
  12. Write Batch Control (L2TOT Subroutine):

  13. At the end of each company (L2, 84), writes a Batch Control Record (Type 8) to ACHFILE.
  14. Includes batch entry count (L2CNT), hash total (L2HASH), credit total (L2CR), and batch number (BATCH#).

  15. Write File Control and Filler (LRTOT Subroutine):

  16. At the end of processing (LR, 10), writes a File Control Record (Type 9) to ACHFILE with batch count (LRBCNT), block count (LRBLOK), entry count (LRCNT), hash total (LRHASH), and credit total (LRCR).
  17. Calculates the number of blocks (LRBLOK = RECCNT / 10, rounded up) and fills remaining block space with filler records containing '999999999999999999999999'.

  18. Report Output:

  19. Outputs a report to REPORT (printer file) for logging or verification, though specific details are not defined in the code.

  20. Termination:

  21. Completes after processing all APPYCK records and writing the necessary NACHA records.

Business Rules

  1. ACH Payment Validation:
  2. Only processes APPYCK records with PYSTAT = 'A' (ACH payments), as confirmed by the OCL script’s LDA check.

  3. NACHA Record Structure:

  4. Adheres to NACHA file format standards:
    • Type 1 (File Header): Includes fixed ABA numbers (043000096, 1222318612), transmission date/time, and company names.
    • Type 5 (Batch Header): Uses service class code 200 (credits only), company tax ID (1222318612), and effective entry date.
    • Type 6 (Entry Detail): Uses transaction codes (22 for checking, 32 for savings), vendor bank details, and payment amount.
    • Type 8 (Batch Control): Summarizes batch entries and totals.
    • Type 9 (File Control): Summarizes file-level counts and totals.
  5. Filler records pad blocks to multiples of 10.

  6. Vendor ACH Details:

  7. Requires valid ACH data in APVEND (VNARTE, VNABK#, VNACOS).
  8. Transaction code is set based on account type (VNACOS = 'C' for checking, otherwise savings).

  9. Counter and Hash Management:

  10. Maintains accurate counts for batches (L2CNT), entries (LRCNT), blocks (LRBLOK), and hash totals (L2HASH, LRHASH) for NACHA compliance.
  11. Credit totals (L2CR, LRCR) reflect payment amounts.

  12. Company and Vendor Validation:

  13. Chains to APCONT to ensure valid company number (PYCONO).
  14. Chains to APVEND to ensure valid vendor number (PYVEND) and retrieve ACH-specific fields.

Tables (Files) Used

  1. APPYCK (IP, Input Primary, 96 bytes):
  2. Check file containing ACH payment records.
  3. Fields: PYSTAT (status), PYCONO (company), PYBKGL (bank G/L), PYCHK# (check number), PYVEND (vendor), PYCKAM (check amount), PYCKDT (check date), PYNAME (vendor name), PYSEQ# (sequence), PYCNTR (count).

  4. APCONT (IC, Input with Chain, 256 bytes):

  5. A/P control file for company details.
  6. Fields: ACNAME (company name), ACCONO (company number), ACBKGL (bank G/L), ACPRE# (pre-numbered checks flag).

  7. APVEND (IC, Input with Chain, 579 bytes):

  8. Vendor file for ACH payment details.
  9. Fields: VNNAME (vendor name), VNARTE (ACH bank routing code), VNABK# (ACH bank account number), VNACOS (checking/savings), VNVEND (vendor number).

  10. ACHFILE (O, Output, 94 bytes):

  11. Output file for NACHA-formatted ACH payment data.
  12. Record types: 1 (file header), 5 (batch header), 6 (entry detail), 8 (batch control), 9 (file control), filler.

  13. REPORT (O, Output, 132 bytes):

  14. Printer file for logging or reporting (details not specified in code).

External Programs Called

  • The AP156 RPG program does not call any external programs. It is a standalone program invoked by the AP156.ocl36.txt script, processing input files and producing output files internally.

Summary

The AP156.ocl36.txt OCL script conditionally invokes the AP156 RPG program to create a NACHA file for ACH payments if LDA position 400 = 'A'. It clears the ACHFIL file and loads AP156 with access to APPYCK, APCONT, APVEND, and ACHFILE. The AP156 RPG program processes APPYCK records to generate a NACHA-compliant file with file header, batch header, entry detail, batch control, and file control records, adhering to strict formatting rules. It uses vendor ACH details from APVEND and company data from APCONT, maintaining counters and hash totals for compliance. The program interacts with five files and does not call external programs, completing the ACH payment file creation process for PNC Bank.