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:
- Conditional Execution Check:
- 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 theAP155program if ACH payments (OPPAID = 'A') are detected inAPPAY. -
If the LDA position 400 does not contain
'A', the script jumps to theENDtag, skipping execution of theAP156program. -
Clear ACH File:
-
Executes the
CLRPFMcommand to clear the physical fileACHFIL(labeled?9?ACHFIL), ensuring no residual data from previous runs. -
Load and Run AP156 Program:
- Loads the
AP156RPG program using theLOAD AP156command. - 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.
-
Executes the program using the
RUNcommand. -
Termination:
- If the ACH condition is not met, the script terminates at the
ENDtag without runningAP156.
Business Rules¶
- ACH Payment Requirement:
- The script only proceeds if the payment run includes ACH payments (
LDA position 400 = 'A'). -
If no ACH payments are present, the script skips execution to avoid unnecessary processing.
-
File Preparation:
-
The
ACHFILfile must be cleared before processing to ensure a clean slate for the NACHA file output. -
Shared File Access:
- 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¶
- APPYCK (
?9?APPC?WS?): - Check file containing payment records.
- APCONT (
?9?APCONT): - A/P control file with company details.
- APVEND (
?9?APVEND): - Vendor file with vendor details, including ACH information.
- ACHFILE (
?9?ACHFIL): - 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:
- Initialization (
ONETIMSubroutine): -
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
ACHFILEwith fields like priority code, ABA numbers, transmission date/time, and company names.
- Retrieves system date and time (
-
Process APPYCK Records:
- Reads
APPYCKrecords (check file) sorted by company (PYCONO) and vendor (PYVEND). -
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
APCONTto retrieve company details (e.g.,ACNAME,ACBKGL) usingPYCONO. - Chains to
APVENDto retrieve vendor ACH details (e.g.,VNARTE,VNABK#,VNACOS,PYNAME) usingPYVEND.
- Validates that the record is not a detail record (
-
Write Batch Header (
L2DETSubroutine): - On the first record for a new company (
L1, N84), writes a Batch Header Record (Type 5) toACHFILE. - Includes fields like service class code (
200for credits), company name, tax ID, and effective entry date (CKYMDfromPYCKDT). -
Initializes batch counters (
L2CNT,L2HASH,L2DR,L2CR). -
Write Entry Detail (
EACHSubroutine): -
For each
APPYCKrecord:- 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 addsVNARTEtoL2HASHandLRHASH, andAMOUNTtoL2CRandLRCR. - Writes an Entry Detail Record (Type 6) to
ACHFILEwith vendor bank routing code (VNARTE), account number (VNABK#), amount, vendor ID, and name.
- Determines the transaction code (
-
Write Batch Control (
L2TOTSubroutine): - At the end of each company (
L2, 84), writes a Batch Control Record (Type 8) toACHFILE. -
Includes batch entry count (
L2CNT), hash total (L2HASH), credit total (L2CR), and batch number (BATCH#). -
Write File Control and Filler (
LRTOTSubroutine): - At the end of processing (
LR, 10), writes a File Control Record (Type 9) toACHFILEwith batch count (LRBCNT), block count (LRBLOK), entry count (LRCNT), hash total (LRHASH), and credit total (LRCR). -
Calculates the number of blocks (
LRBLOK = RECCNT / 10, rounded up) and fills remaining block space with filler records containing'999999999999999999999999'. -
Report Output:
-
Outputs a report to
REPORT(printer file) for logging or verification, though specific details are not defined in the code. -
Termination:
- Completes after processing all
APPYCKrecords and writing the necessary NACHA records.
Business Rules¶
- ACH Payment Validation:
-
Only processes
APPYCKrecords withPYSTAT = 'A'(ACH payments), as confirmed by the OCL script’s LDA check. -
NACHA Record Structure:
- 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 (
22for checking,32for 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.
- Type 1 (File Header): Includes fixed ABA numbers (
-
Filler records pad blocks to multiples of 10.
-
Vendor ACH Details:
- Requires valid ACH data in
APVEND(VNARTE,VNABK#,VNACOS). -
Transaction code is set based on account type (
VNACOS = 'C'for checking, otherwise savings). -
Counter and Hash Management:
- Maintains accurate counts for batches (
L2CNT), entries (LRCNT), blocks (LRBLOK), and hash totals (L2HASH,LRHASH) for NACHA compliance. -
Credit totals (
L2CR,LRCR) reflect payment amounts. -
Company and Vendor Validation:
- Chains to
APCONTto ensure valid company number (PYCONO). - Chains to
APVENDto ensure valid vendor number (PYVEND) and retrieve ACH-specific fields.
Tables (Files) Used¶
- APPYCK (
IP, Input Primary, 96 bytes): - Check file containing ACH payment records.
-
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). -
APCONT (
IC, Input with Chain, 256 bytes): - A/P control file for company details.
-
Fields:
ACNAME(company name),ACCONO(company number),ACBKGL(bank G/L),ACPRE#(pre-numbered checks flag). -
APVEND (
IC, Input with Chain, 579 bytes): - Vendor file for ACH payment details.
-
Fields:
VNNAME(vendor name),VNARTE(ACH bank routing code),VNABK#(ACH bank account number),VNACOS(checking/savings),VNVEND(vendor number). -
ACHFILE (
O, Output, 94 bytes): - Output file for NACHA-formatted ACH payment data.
-
Record types: 1 (file header), 5 (batch header), 6 (entry detail), 8 (batch control), 9 (file control), filler.
-
REPORT (
O, Output, 132 bytes): - Printer file for logging or reporting (details not specified in code).
External Programs Called¶
- The
AP156RPG program does not call any external programs. It is a standalone program invoked by theAP156.ocl36.txtscript, 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.