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:
- File Initialization and Setup:
- The program defines input, update, and output files (see Tables Used below) for processing A/P checks, payments, vendor data, and history.
-
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. -
Main Processing Loop (Level Breaks):
-
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'
, setsJRNID='WD'
) or standard check (JRNID='CD'
orACCDJR
). - Sets payment method description (
PAYBY
) based onPTHOLD
(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 updatingAPCHKR
.
- Executes the
-
Check Record Processing (
EACH01
Subroutine): - Processes each record in
APPYCK
(check file) using indicator01
. - Formats the check date (
AXCKDT
) intoAXYMD8
for reporting. - Copies the check number to the Positive Pay field (
PNCCHK
) for external bank reconciliation. - Evaluates the record code (
AXRECD
):'C'
: Credit/no pay, skips processing (19
set, jumps toENDL1D
).'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, and11
for prepaid).
- 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), setsAMCODE='V'
, clearsAMCKAM
, and updates clear date (AMCLDT
,CLDT8
). - For non-voided checks, sets
AMCODE='O'
(open) and updatesAMCKAM
with the check amount (AXAMT
). - Formats dates for Positive Pay (
PNCDT8
) and setsPNCCOD
('V' for void, 'I' for issued).
- Chains to
-
Updates counters and totals (
C3CNT
,C3AMT
, etc.) based on payment type, excluding voided checks (N13
). -
Payment Processing (
EACH02
Subroutine): - Processes each payment record in
APPAY
(payment file) using indicator02
andN19
(non-credit records). - Accumulates totals for gross amount (
L2GRAM
), discount (L2DISC
), partial paid to date (L2PPTD
), and payment amount (L2AMT
) at the vendor level (L2
). - Updates vendor name overflow (
AXNAM2
) fromAPVEND2
ifVNNOVF='Y'
. - Calculates A/P reduction (
OPPAY = OPDISC + OPLPAM
) and open amount (OPOPEN = OPGRAM - OPPPTD - OPPAY
). - If fully paid (
OPOPEN=0
,20
set), marks the record for deletion. - Updates
APOPEN
(open invoices):- Sets lower limit (
SETLL
) usingOPKEY
and reads records. - Chains to
APOPENH
,APOPEND
, orAPOPENV
based on indicators (04
,05
,06
) to update or delete records. - If fully paid (
20
set), writes deletion records ('D'
) toAPOPENH
,APOPEND
, orAPOPENV
.
- Sets lower limit (
- 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 toFRCFBH
(APFBST
exception). - If not found in
FRCFBH
, chains toFRCINH
(carrier invoice header) and writes toFRCINH
(APINST
exception).
- Builds a key (
- Updates
APPYDS
(discount missed table):- Chains to
APPYDS
usingOPKY1
and writes records if a discount is missed (97
not set).
- Chains to
-
Writes history records to
APHISTH
,APHISTD
,APHISTV
for header, detail, and one-time vendor transactions, including payment details, check numbers, and dates. -
Vendor Totals Update (
L2TOT
Subroutine): -
At the vendor level break (
L2
), updatesAPVEND
:- 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
).
- Chains to
-
Company Totals and Control Update (
L4TOT
Subroutine): -
At the company/bank G/L level break (
L4
), updatesAPCONT
:- Increments the next check number (
ACCKNO
) if the last check number (L4CHEK
) is greater than zero and matches or exceeds the currentACCKNO
. - Increments the next cash disbursements journal number (
ACCDJR
).
- Increments the next check number (
-
Output Generation:
- 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.
- Prints headers with company name (
- Positive Pay File (
APPNCF
):- Outputs check data (
PNCCHK
,PNCDT8
,AXAMT
,AXNAME
,AXNAM2
,PNCCOD
) for bank reconciliation.
- Outputs check data (
-
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
).
- Writes records for cash (
-
Cleanup:
- Ensures all files are updated or written as needed (e.g.,
APOPEN
,APHISTH
,APHISTD
,APHISTV
,APCHKR
,FRCFBH
,FRCINH
,APCDJR
,APPYDS
). - 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:
- Payment Type Handling:
- Supports multiple payment types based on
AXRECD
andPTHOLD
:'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.
-
Wire transfers, ACH, and employee expenses skip
APCHKR
updates (indicator50
set). -
Check Reconciliation:
- Updates
APCHKR
for non-prepaid, non-void checks with status'O'
(open) or'V'
(voided). -
Maintains original check amount (
AMOCAM
) and clear date (AMCLDT
) for voided checks. -
Vendor Balance and History:
- Tracks vendor totals (last payment, discounts, balance, year-to-date paid) in
APVEND
. - Records payment history in
APHISTH
(header),APHISTD
(detail), andAPHISTV
(one-time vendor). -
Adjusts vendor current balance (
VNCBAL
) by subtracting payment and discount amounts. -
Open Invoice Management:
- Marks fully paid invoices (
OPOPEN=0
) for deletion ('D'
) inAPOPENH
,APOPEND
,APOPENV
. -
Updates partial payments (
OPPPTD += OPLPAM
). -
Freight Invoice Processing:
- Updates
FRCFBH
(freight bill override header) orFRCINH
(carrier invoice header) for freight invoices with a carrier ID (OPCAID
). -
Sets posting status (
FRAPST='P'
) for freight records. -
Discount Tracking:
- Records missed discounts in
APPYDS
if applicable. -
Accumulates discounts taken (
VNDMTD
,VNDYTD
) inAPVEND
. -
Journal and Check Numbering:
- Increments
ACCDJR
(journal number) andACCKNO
(check number) inAPCONT
for tracking. -
Ensures unique journal entries in
APCDJR
for cash, discounts, and A/P accounts. -
Date Handling:
- Supports century-aware date processing using
Y2KCEN
(e.g., 19 for 1900s, 20 for 2000s). -
Formats dates for reporting (
AXYMD8
,CDYMD8
,PNCDT8
) and Positive Pay output. -
Positive Pay Compliance:
- 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:
- Input Files:
- APPYCK (IP, 96 bytes, keyed): Check file, contains check details (e.g.,
AXCHEK
,AXAMT
,AXCKDT
,VEND
,AXNAME
,AXRECD
). - APPAY (IS, 384 bytes, keyed): Payment file, contains payment details (e.g.,
COVNVO
,OPGRAM
,OPDISC
,OPLPAM
,OPPAID
). - APPYTR (IC, 128 bytes, keyed): Transaction file, contains check date (
PTCKDT
,PTCKYY
) and hold code (PTHOLD
). - APVEND (UC, 579 bytes, keyed): Vendor master file, contains vendor details (e.g.,
VNNAME
,VNLPAY
,VNCBAL
). - APVEND2 (IC, 579 bytes, keyed): Secondary vendor file, includes address and name overflow (
VNNOVF
). - APCHKR (UC, 128 bytes, keyed): Check reconciliation file, tracks check status (
AMCODE
,AMCKAM
,AMCLDT
). - APOPEN (ID, 384 bytes, keyed): Open A/P invoices, contains invoice details (
OPKY1
,OPKY2
,OPGRAM
,OPDISC
). - APOPENH (UC, 384 bytes, keyed): Open A/P header file, used for header-level updates.
- APOPEND (UC, 384 bytes, keyed): Open A/P detail file, used for detail-level updates.
- APOPENV (UC, 384 bytes, keyed): Open A/P one-time vendor file, used for one-time vendor updates.
- FRCINH (UF, 206 bytes, keyed): Freight carrier invoice header, tracks freight invoice details.
- FRCFBH (UF, 206 bytes, keyed): Freight bill override header, used for freight bill overrides.
-
APPYDS (IF, 384 bytes, keyed): Discount missed table, tracks missed discount invoices.
-
Output Files:
- APHISTH (O, 384 bytes): A/P history header file, stores header-level payment history.
- APHISTD (O, 384 bytes): A/P history detail file, stores detail-level payment history.
- APHISTV (O, 384 bytes): A/P history one-time vendor file, stores one-time vendor payment history.
- APCDJR (O, 128 bytes): Cash disbursements journal file, records journal entries for cash, discounts, and A/P.
- APPNCF (O, 155 bytes, PRINTER): Positive Pay file for bank reconciliation.
- APPRINT (O, 132 bytes, PRINTER): Check Register report file.
-
APDSMS (O, 384 bytes): Discount missed summary file, stores summary data for missed discounts.
-
Table File:
- 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.