AP110 RPG
The AP110.rpg36.txt
is an RPG III program for IBM midrange systems (e.g., AS/400 or iSeries), called by an OCL program (e.g., AP110.ocl36.txt
). It performs validation and editing of Accounts Payable (A/P) voucher transactions, ensuring data integrity for headers and detail lines. The program generates a printed report (APLIST
) listing transaction details, errors, and totals for invoice amounts, discounts, and prepaid checks. It includes modifications for ACH payments, employee expenses, utility auto-payments, FlexiCapture invoice uploads, and validations for gallons, receipts, and purchase orders. Below is a detailed explanation of the process steps, business rules, tables used, and external programs called.
Process Steps of the RPG Program (AP110)¶
The AP110
program processes A/P voucher transactions from the APTRAN
file, validates them against various files (e.g., APVEND
, GLMAST
, APCONT
), and produces a detailed error report via APLIST
. The key steps are as follows:
- Initialization (Lines 0092–0107):
- Executes at the total level (
L2
) to initialize variables:- Retrieves system date and time (
TIME
) and stores them inTIMDAT
,SYSTIM
,SYSDAT
, andSYSYMD
(year-month-day format). - Converts system date to 8-digit format (
SYSDT8
) for comparisons. - Sets separator (
SEP
) to'* '
for report formatting. - Initializes page number (
PAGE
) and accumulators (L2CNT
,L2VHSH
,L2AMT
,L2PAMT
,L2FAMT
,L2DISC
,L2NET
,L2PPD
,L2PPA
,L2PPW
,L2PPE
) to zero.
- Retrieves system date and time (
- Validates company number (
ATCONO
) againstAPCONT
. If not found (92
), sets error indicator. -
At the detail level (
L1
):- Initializes detail accumulators (
L1AMT
,L1PAMT
,L1FAMT
,L1DISC
,L1NET
) to zero. - For wire transfer transactions (
WIREDS ≠ *BLANKS
), prints a header (PRTHDR
) for each entry.
- Initializes detail accumulators (
-
Main Processing Loop (Lines 0109–0125):
- Processes header records (
01
,L1
) and detail records (02
,L1
) fromAPTRAN
:- For header records (
01
), executes theHDR
subroutine. - For detail records (
02
, non-deletedN51
), executes theDET
subroutine.
- For header records (
- Accumulates totals at
L1
(if no delete,N51
):- Adds detail amounts (
L1AMT
,L1PAMT
,L1FAMT
,L1DISC
,L1NET
) toL2
totals (L2AMT
,L2PAMT
,L2FAMT
,L2DISC
,L2NET
). - For prepaid (
28
), ACH (24
), wire transfer (25
), or employee expense (32
) payments, accumulates amounts intoL2PPD
,L2PPA
,L2PPW
, orL2PPE
.
- Adds detail amounts (
-
Updates
APSTAT
with error status ('Y'
if errors exist,'N'
otherwise) usingSTATKY
(company and workstation). -
HDR Subroutine (Lines 0127–0144):
-
Validates header records:
- If the header is deleted (
ATHDEL = 'D'
), sets indicator51
and skips toENDHDR
. - Increments invoice count (
L2CNT
) and vendor hash total (L2VHSH
). - Validates retention percentage (
ATRTPC ≠ 0
, sets26
), hold code (ATHOLD = 'H'
, sets77
), canceled voucher (ATCNVO ≠ 0
, sets27
), prepaid code (ATPAID = 'P'
, sets28
;= 'A'
, sets24
;= 'E'
, sets32
;= 'U'
, sets33
), single check (ATSNGL = 'S'
, sets29
), and sales order (ATSORN ≠ 0
, sets19
). - Checks hold description (
ATHLDD
) for blanks (sets77
if blank). - Calls
HEADCK
subroutine for additional header validations.
- If the header is deleted (
-
HEADCK Subroutine (Lines MG02):
-
Validates company, vendor, and invoice details:
- Chains
ATCONO
toAPCONT
. If not found (99
), sets error95
. - Chains vendor key (
ATCONO
,ATVEND
) toAPVEND
. If not found (99
), deleted (VNDEL = 'D'
), inactive (VNDEL = 'I'
), or vendor name blank (VNVNAM = *BLANKS
), sets error95
. - Retrieves terms code (
VNTERM
) fromGSTABL
. If not found (99
), clears term description (TRMDSC
). - Ensures invoice date (
ATINDT
) is non-zero. If zero, sets error95
. - Compares invoice date (
ATIND8
) to system date minus one year (SYSDT8 - 10000
). If older, sets warning96
(MG09). - Ensures invoice amount (
ATIAMT
) is non-zero. If zero, sets error95
. - Ensures invoice number (
ATINV#
) is not blank. If blank, sets error95
. - For non-prepaid (
N28
), non-canceled (N27
), non-wire-transfer (N25
) transactions with non-zero vendor (ATVEND ≠ 0
): - Checks for duplicate invoices in
APTRNX
(INVKEY = XXKEY
,XXENT ≠ ATENT#
, sets95
if found). - Checks
APINVH
for duplicate invoice keys (INVKEY = AIKEY
, sets95
if found, MGXX). - Checks
APOPNHC
for duplicate invoice (OCCONO = ATCONO
,OCVEND = ATVEND
,OCINVN = ATINV#
, sets95
if found). - Validates A/P G/L (
ATAPGL
) and bank G/L (ATBKGL
) againstGLMAST
. If not found (99
), deleted (GLDEL = 'D'
), or inactive (GLDEL = 'I'
), sets error95
.
- Chains
-
DET Subroutine (Lines 0146–0169):
-
Validates detail records:
- If the detail is deleted (
ATDDEL = 'D'
), sets52
and skips toENDDTL
. - Checks if gallons (
ATGALN ≠ 0
, sets60
) or job number (ATJOB# ≠ *BLANKS
, sets30
) are present. - Validates discount:
- If discount percentage (
ATDSPC ≠ 0
), ensures discount amount (ATDISC
) is zero (sets10
if both non-zero). - If
ATDSPC ≠ 0
, calculatesATDISC = ATAMT * (ATDSPC / 100)
. - Calculates net amount (
NETAMT = ATAMT - ATDISC
). - Accumulates detail amounts (
L1AMT
,L1PAMT
,L1FAMT
,L1DISC
,L1NET
). - For prepaid transactions (
28
), callsPPDCHK
subroutine. - Calls
DETLCK
subroutine for additional detail validations.
- If the detail is deleted (
-
PPDCHK Subroutine (Lines 0171–0183):
-
Validates prepaid checks:
- Chains check key (
CKKY21
) toAPCHKT
. If not found (N90
), addsATAMT
toACCKAM
. If found (90
), setsACCKAM = ATAMT
. - Subtracts discount (
ATDISC
) fromACCKAM
. - Writes or updates
APCHKT
with the prepaid check record (PPDREC
). - Writes the prepaid check detail to
APLIST
.
- Chains check key (
-
DETLCK Subroutine (Lines MG02–MGXX):
-
Validates detail line fields:
- Validates gallons/receipt requirements based on vendor (
VNGRRQ
) and G/L (GLAPCD
): - If
VNGRRQ = 'Y'
, requiresATGALN
andATRCPT
(sets95
if either is zero). - If
VNGRRQ = 'N'
, prohibitsATGALN
andATRCPT
(sets95
if either is non-zero). - If
GLAPCD = 'Y'
andATAMT > 0
, requiresATGALN
(sets95
if zero). - If
ATGALN > 0
, requiresGLAPCD = 'Y'
(sets95
if not). - If G/L requires a purchase order (
GLPOCD = 'Y'
, MG08), ensuresATPONO
is not blank (sets95
if blank). - Validates receipt number (
ATRCPT ≠ 0
): - Chains
RCTKEY
toINFIL1
orINTZH1
. If not found (47
and77
), sets error95
. - Accumulates net quantity (
RNQTY = IHNQTY + IHNQTF - IHAPTQ - IHAPTF
) and A/P quantity (APQTY = IHAPTQ + IHAPTF
). - If
ATGALN > RNQTY
, sets error95
and46
. - Ensures receipt code (
ATCLCD
) is'O'
or'C'
(sets95
if not). - Validates discount:
- If
ATDISC ≠ 0
orATDSPC ≠ 0
, requires a discount G/L (ACDSGL ≠ 0
, sets95
if not). - If
ATDSD8 ≠ 0
andATDSD8 ≤ SYSDT8
, sets warning96
(MGXX). - If terms have no discount (
TBDISC = 0
), prohibitsATDSPC
orATDISC
(sets95
if non-zero). - If terms have a discount (
TBDISC ≠ 0
), ensuresATDSPC = TBDISC
(sets95
if not) or requiresATDISC
andATDSPC
to be non-zero (sets95
if both zero). - Validates expense G/L (
ATEXGL
) againstGLMAST
. If not found (99
), deleted (GLDEL = 'D'
), or inactive (GLDEL = 'I'
), sets error95
.
- Validates gallons/receipt requirements based on vendor (
-
Output to APLIST (Lines 0195–0340):
-
Generates a formatted report:
- Header (L2): Prints company name (
ACNAME
), page number, date (SYSDAT
), time (SYSTIM
), and static text ("ACCOUNTS PAYABLE VOUCHER EDIT"). - Detail (01, N51): Prints header details (
ATENT#
,ATVEND
,ATVNAM
,ATINV#
,ATINDT
,TRMDSC
,ATAPGL
,ATDUDT
,ATDSDT
,ATBKGL
,ATSNGL
,ATRTGL
,ATRTPC
,ATCNVO
,ATHOLD
,ATHLDD
,ATSORN
,ATSSRN
,ATCAID
,ATPTYP
). - Detail (02, N51, N52): Prints detail line details (
ATPONO
,ATDDES
,ATPRAM
,ATFRAM
,ATAMT
,ATDISC
,NETAMT
,ATEXGL
,ATEXCO
,ATGALN
,ATRCPT
,ATCLCD
,ATJOB#
,ATCCOD
,ATCTYP
,ATJQTY
). - Errors/Warnings: Prints error (
95
) or warning (96
) messages with entry number (ATENT#
). - Totals (L1, N51): Prints entry totals (
L1PAMT
,L1FAMT
,L1AMT
,L1DISC
,L1NET
) and prepaid details (ATPPCK
,ATPCKD
). - Totals (L2): Prints invoice totals (
L2PAMT
,L2FAMT
,L2AMT
,L2DISC
,L2NET
), prepaid totals (L2PPD
,L2PPA
,L2PPW
,L2PPE
), invoice count (L2CNT
), and vendor hash total (L2VHSH
).
- Header (L2): Prints company name (
-
File Updates:
- Writes or updates
APCHKT
with prepaid check records (PPDREC
). -
Writes or updates
APSTAT
with error status (STATAD
,STATUP
). -
Termination:
- Processes all records in
APTRAN
, generates the report, and terminates when no more records are found.
- Processes all records in
Business Rules¶
- Header Validation:
- Company number (
ATCONO
) must exist inAPCONT
and not be deleted (ACDEL ≠ 'D'
). - Vendor number (
ATVEND
) must exist inAPVEND
, not be deleted (VNDEL ≠ 'D'
), not inactive (VNDEL ≠ 'I'
), and have a non-blank name (VNVNAM ≠ *BLANKS
). - Invoice date (
ATINDT
) must be non-zero and not older than one year prior to the system date (warning only, MG09). - Invoice amount (
ATIAMT
) must be non-zero. - Invoice number (
ATINV#
) must be non-blank and unique (checked againstAPTRNX
,APINVH
,APOPNHC
for non-prepaid, non-canceled, non-wire-transfer transactions). - A/P G/L (
ATAPGL
) and bank G/L (ATBKGL
) must exist inGLMAST
, not be deleted (GLDEL ≠ 'D'
), and not inactive (GLDEL ≠ 'I'
). - Hold codes (
ATHOLD
) must be'H'
(hold),'A'
(ACH),'W'
(wire transfer),'E'
(employee expense), or'U'
(utility auto-payment). - Prepaid codes (
ATPAID
) must be'P'
(prepaid),'A'
(ACH),'E'
(employee expense), or'U'
(utility auto-payment). - Single check (
ATSNGL = 'S'
) and retention percentage (ATRTPC ≠ 0
) are flagged if present. -
Canceled voucher (
ATCNVO ≠ 0
) is flagged if present. -
Detail Validation:
- Expense G/L (
ATEXGL
) must exist inGLMAST
, not be deleted (GLDEL ≠ 'D'
), and not inactive (GLDEL ≠ 'I'
). - If G/L requires a purchase order (
GLPOCD = 'Y'
),ATPONO
must be non-blank. - Gallons and receipt validation:
- If vendor requires gallons/receipts (
VNGRRQ = 'Y'
),ATGALN
andATRCPT
must be non-zero. - If vendor does not require gallons/receipts (
VNGRRQ = 'N'
),ATGALN
andATRCPT
must be zero. - If G/L requires gallons (
GLAPCD = 'Y'
),ATGALN
must be non-zero for positive amounts (ATAMT > 0
). - If
ATGALN > 0
, G/L must require gallons (GLAPCD = 'Y'
). - Receipt number (
ATRCPT
) must exist inINFIL1
orINTZH1
, with sufficient quantity (ATGALN ≤ RNQTY
) and no prior A/P postings (removed in MG04). - Receipt code (
ATCLCD
) must be'O'
(open) or'C'
(closed).
- If vendor requires gallons/receipts (
-
Discount validation:
- Discount amount (
ATDISC
) and percentage (ATDSPC
) cannot both be non-zero. - If
ATDISC
orATDSPC
is non-zero, a discount G/L (ACDSGL
) must exist. - If terms have no discount (
TBDISC = 0
),ATDISC
andATDSPC
must be zero. - If terms have a discount (
TBDISC ≠ 0
),ATDSPC
must matchTBDISC
, or bothATDISC
andATDSPC
must be non-zero. - If discount due date (
ATDSD8
) is non-zero and not later than the system date (SYSDT8
), a warning (96
) is issued.
- Discount amount (
-
Prepaid Check Validation:
- Prepaid check amounts (
ACCKAM
) are updated inAPCHKT
by adding or settingATAMT - ATDISC
. -
Prepaid check details are written to the report.
-
Error and Warning Handling:
- Errors (
95
) are flagged for critical validation failures (e.g., invalid company, vendor, G/L, duplicate invoice). - Warnings (
96
) are flagged for non-critical issues (e.g., invoice date older than one year, discount date expired). -
Errors are written to
APSTAT
(AXERR = 'Y'
) and reported inAPLIST
. -
Reporting:
- The report includes headers, detail lines, entry totals, and grand totals for invoices, prepaid amounts, and vendor hash.
- Errors and warnings are listed with entry numbers for correction.
Tables (Files) Used¶
The program uses the following files, defined with specific attributes:
- APTRAN:
- Primary input file (
IP
), 404 bytes, key length 10, contains voucher header and detail records. -
Fields:
ATHDEL
,ATCONO
,ATENT#
,ATVEND
,ATCNVO
,ATAPGL
,ATIDES
,ATINDT
,ATDUDT
,ATSNGL
,ATHOLD
,ATHLDD
,ATPAID
,ATPPCK
,ATVNAM
,ATVAD1–4
,ATBKGL
,ATIAMT
,ATRTGL
,ATRTPC
,ATPCKD
,ATIND8
,ATDUD8
,ATPCK8
,ATFRTL
,ATPIVN
,ATPIIN
,ATSORN
,ATSSRN
,ATCAID
,ATPTYP
,ATDSDT
,ATDSD8
,ATINV#
,ATDDEL
,ATENSQ
,ATCORD
,ATEXCO
,ATEXGL
,ATDDES
,ATAMT
,ATDISC
,ATDSPC
,ATITEM
,ATQTY
,ATUNMS
,ATJOB#
,ATCCOD
,ATCTYP
,ATJQTY
,ATGALN
,ATRCPT
,ATCLCD
,ATPRAM
,ATFRAM
,ATPONO
. -
APTRNX:
- Input file (
IF
), 404 bytes, key length 27, external key, used for duplicate invoice checking. -
Fields:
XXCO
,XXENT
,XXVEND
,XXINV
. -
APOPNHC:
- Input file (
IF
), 384 bytes, key length 32, used for duplicate invoice checking. -
Fields:
OCDEL
,OCCONO
,OCVEND
,OCVONO
,OCINDS
,OCINVN
. -
APVEND:
- Input file (
IF
), 579 bytes, key length 7, used for vendor validation. -
Fields:
VNDEL
,VNVNAM
,VNAD1–4
,VNGRRQ
,VNHOLD
,VNSNGL
,VNEXGL
,VNTERM
,VNCAID
,VNPRID
,VNACLS
,VNACOS
,VNARTE
,VNABK#
. -
APCONT:
- Input file (
IF
), 256 bytes, key length 2, used for company validation. -
Fields:
ACDEL
,ACNAME
,ACAPGL
,ACCAGL
,ACDSGL
,ACNXTE
,ACJCYN
,ACRTGL
,ACPOYN
,ACEEGL
. -
APCHKT:
- Update file (
UF
), 80 bytes, key length 21, used for prepaid check validation. -
Fields:
ACCKAM
,ATPCKD
,ATPCK8
,ATHOLD
. -
GLMAST:
- Input file (
IF
), 256 bytes, key length 11, used for G/L validation. -
Fields:
GLDEL
,GLDESC
,GLAPCD
,GLPOCD
. -
APINVH:
- Input file (
IF
), 64 bytes, key length 32, used for duplicate invoice checking. -
Fields:
AIKEY
,AIVONO
. -
APSTAT:
- Update file (
UF
), 14 bytes, key length 12, used to store error status. -
Fields:
AXCODE
,AXCONO
,AXWSTN
,AXERR
. -
GSTABL:
- Input file (
IF
), 256 bytes, key length 12, used for terms validation. - Fields:
TBDEL
,TBDESC
,TBNETD
,TBPRXD
,TBDISC
,TBADON
,TBDISD
.
- Input file (
-
INFIL1:
- Input file (
IF
), 448 bytes, key length 9, external key, used for receipt validation. - Fields:
IHNQTY
,IHNQTF
,IHUNMS
,IHAPLP
,IHAPTQ
,IHAPTF
,IHAPTD
.
- Input file (
-
INTZH1:
- Input file (
IF
), 592 bytes, key length 9, external key, used for receipt validation. - Fields:
IHNQTY
,IHNQTF
,IHUNMS
,IHAPLP
,IHAPTQ
,IHAPTF
,IHAPTD
.
- Input file (
-
APLIST:
- Output printer file (
O
), 164 bytes, used to generate the voucher edit report. - Contains headers, detail lines, error/warning messages, and totals.
- Output printer file (
External Programs Called¶
- None: The
AP110
program does not call any external programs. It operates independently, processing input files, performing validations, and generating the report.
Summary¶
The AP110
RPG program validates A/P voucher transactions by processing header and detail records from APTRAN
. It enforces strict business rules, including company, vendor, G/L, invoice, gallons/receipt, purchase order, and discount validations. Errors (95
) and warnings (96
) are flagged and reported in APLIST
, with error status updated in APSTAT
. The program supports ACH, wire transfer, employee expense, and utility auto-payment transactions, and includes enhancements for FlexiCapture invoice uploads. It accumulates totals for invoices, prepaid amounts, and vendor hash, producing a comprehensive report for correction. No external programs are called, making it a self-contained validation routine.