AP100 RPG
The provided AP100.rpg36.txt
is an RPG III program for IBM midrange systems (e.g., AS/400 or iSeries), called by the OCL program AP100.ocl36.txt
. It handles the entry and validation of Accounts Payable (A/P) voucher transactions, including header and detail records, with support for various payment types (e.g., wire transfers, ACH, employee expenses) and validations for inventory, purchase orders, and vendor data. Below is an explanation of the process steps, business rules, tables used, and external programs called.
Process Steps of the RPG Program (AP100)¶
The RPG program AP100
manages the interactive entry and editing of A/P voucher transactions through multiple screen formats (AP100S1
, AP100S2
, AP100S3
, AP100S5
). It validates input, retrieves data from files, and updates transaction records. Here are the key process steps:
- Initialization:
- Clears variables and sets indicators to their initial state (e.g.,
Z-ADD *ZERO
,MOVE *BLANKS
,SETOF
). - Sets the process type (
PTYP
) to'NORMAL'
if blank (modificationJK01
). - Retrieves the current system date and time (
TIME
), formats it into various date fields (SYTIME
,SYDATE
,SYDYMD
,MONTH
,YEAR
), and calculates century for date handling (Y2KCEN
). - Checks for wire transfer (
LDAWT = 'WT'
) or employee expense (LDAWT = 'EE'
) flags, setting indicators22
or23
accordingly. -
Initializes keys for file access (e.g.,
TERMKY
for terms,GSCKEY
for carrier ID). -
Screen Processing:
- The program uses multiple screen formats:
- AP100S1: Collects company number (
CONO
), vendor number (VEND
), entry number (ENT#
), canceled voucher number (CNVO
), and purchase order number (PONO
). - AP100S2: Displays and collects header information (e.g., vendor details, invoice amount, invoice number, dates, hold codes).
- AP100S3: Handles detail line entry (e.g., expense G/L, amount, discount, purchase order, gallons, receipt number).
- AP100S5: Allows entry of a vendor number (
VEND#
) for lookup or navigation.
- AP100S1: Collects company number (
-
The main loop (
DO
at line 0446) processes user input based on the screen format triggered (indicators01
,02
,03
,05
forS1
,S2
,S3
,S5
subroutines). -
S1 Subroutine (AP100S1 Screen):
- Validates the company number (
CONO
) againstAPCONT
. If invalid or deleted (ACDEL = 'D'
), displays error message (COM,1
) and exits. - Checks if vendor (
VEND
), entry number (ENT#
), canceled voucher (CNVO
), or purchase order (PONO
) are blank or zero. If so, displays error (COM,31
) and exits. - Searches for vendor information (
VNSRCH
subroutine) if vendor is valid. If not found, displays error (COM,32
). - Retrieves the next entry number (
ACNXTE
) fromAPCONT
for new entries (ADDNEW
mode) or validates existing entry numbers (ENT#
) againstAPTRAN
. - Checks if job cost (
ACJCYN = 'Y'
) or purchase order (ACPOYN = 'Y'
) processing is active, setting indicators65
and67
. -
Updates
APCONT
with the next entry number and writes the record. -
S2 Subroutine (AP100S2 Screen):
- Retrieves or clears header information (vendor name, address, invoice amount, dates, hold codes, etc.).
- Validates vendor number (
VEND
) againstAPVEND
. If invalid, deleted (VNDEL = 'D'
), or inactive (VNDEL = 'I'
), displays errors (COM,2
orCOM,67
). - Applies vendor defaults (e.g., hold code
VNHOLD
, single checkVNSNGL
, expense G/LVNEXGL
, termsVNTERM
). - For employee vendors (
VNPRID ≠ 0
), sets hold code to'E'
and uses employee expense G/L (ACEEGL
). - Validates hold codes (
H
,A
,W
,E
,U
) and prepay codes (P
,A
,W
,E
), setting appropriate hold descriptions (HLDD
). - Checks invoice number (
INV#
) for duplicates inAPTRANX
,APOPEN
,APOPNHC
, orAPHSTHC
. If found, requires override codes (COM2,2
,COM2,3
). - Calculates due date (
DUDT
) and discount due date (DSDT
) using terms fromGSTABL
(subroutines@DTE1
,@DTE2
,TMDATP
). - Ensures invoice amount (
IAMT
) is non-zero and matches detail totals (CLCTOT
subroutine). -
For freight invoices (
FRTL ≠ 0
), callsAP1011
to populate detail lines with calculated freight amounts. -
S3 Subroutine (AP100S3 Screen):
- Validates detail line fields (e.g., expense G/L
EXGL
, amountAMT
, discountDISC
, purchase orderPONO
, gallonsGALN
, receiptRCPT
). - Ensures expense G/L (
EXGL
) matches company (LNCO
) and is valid inGLMAST
. If deleted (GLDEL = 'D'
) or inactive (GLDEL = 'I'
), displays error (COM,7
). - Applies vendor default expense G/L (
VNEXGL
) if blank. - Validates discounts: Ensures
DISC
andDSPC
(discount percentage) are not both non-zero (COM,35
) and that a discount G/L (ACDSGL
) exists (COM,36
). - For sales orders (
SORN ≠ 0
), prohibits receipt numbers or gallons (COM,57
). - Validates gallons/receipt requirements based on
VNGRRQ
andGLAPCD
:- If
VNGRRQ = 'Y'
, requires gallons (GALN
) and receipt (RCPT
) (COM,71
,COM,72
). - If
VNGRRQ = 'N'
, prohibits gallons and receipt (COM,73
,COM,74
). - Ensures G/L requires gallons (
GLAPCD = 'Y'
) if vendor requires them, and vice versa (COM,75
,COM,76
).
- If
- If
GLPOCD = 'Y'
(PO required for G/L), ensuresPONO
is entered (COM,78
). - Validates receipt numbers (
RCPT
) againstINFIL1
orINTZH1
, checking quantities and prior postings (COM,40
,COM,42
,COM,43
). - Ensures receipt code (
CLCD
) is'O'
or'C'
(COM,44
). - Calculates freight amounts (
FRAM
) for detail lines if total freight (FRTL
) is non-zero, ensuring detail amounts sum to invoice total (IAMT
). -
Updates or adds detail records to
APTRAN
. -
S5 Subroutine (AP100S5 Screen):
- Handles vendor lookup by number (
VEND#
) or name search (ABBR
). - If
VEND#
is entered, setsVEND
and clearsABBR
, then returns toS1
. -
If blank, performs a name search (
NRLFWD
subroutine) to display vendor options. -
Roll Forward/Backward Handling:
- ROLFWD: Navigates to the next detail line in
APTRANX
, populating fields (DETGET
) and validating (S3EDIT
). -
ROLLBK: Navigates to the previous detail line or header, populating fields (
DETGET
orHDRGET
) and validating (S3EDIT
orS2EDIT
). -
Date Handling:
- Subroutines
@DTE1
and@DTE2
convert between Gregorian and Julian dates for due date and discount date calculations. -
Ensures due dates (
DUDT
) and discount due dates (DSDT
) are valid and not on holidays/weekends (APDATE
file, modificationMG17
). -
Freight Invoice Validation:
-
Checks
FRCFBH
andFRCINH
for freight invoices:- For
NORMAL
mode, ensuresFRAPST
(A/P status) is blank (COM,60
). - For
PAPER
mode, ensuresFRINTY = 'P'
(COM,62
). - For
ARGLMS
mode, ensuresFRINTY = 'O'
or'S'
(COM,61
).
- For
-
File Updates:
- Adds or updates header records in
APTRAN
(e.g.,EADD 70
,E 70N95
). - Adds or updates detail records in
APTRAN
(e.g.,EADD 71
,E 71N96
). - Updates
APCONT
with the next entry number (ACNXTE
). - Updates one-time vendor information in
APTRAN
if needed. - Writes to
APOPENH
for open invoices.
- Adds or updates header records in
-
Error Handling:
- Displays error messages from the
COM
andCOM2
arrays for various validation failures (e.g., invalid vendor, duplicate invoice, missing fields). - Sets indicator
90
to highlight errors and prevent progression until corrected.
- Displays error messages from the
-
Termination:
- Ends the program when the user presses the end-of-job key (
KG
), setting the last record indicator (LR
) and exiting.
- Ends the program when the user presses the end-of-job key (
Business Rules¶
- Company and Vendor Validation:
- Company number (
CONO
) must exist inAPCONT
and not be deleted (ACDEL ≠ 'D'
). -
Vendor number (
VEND
) must exist inAPVEND
, not be deleted (VNDEL ≠ 'D'
) or inactive (VNDEL ≠ 'I'
). -
Invoice Number Uniqueness:
-
Invoice numbers (
INV#
) must be unique within the batch (APTRANX
) and not exist in open (APOPEN
,APOPNHC
) or paid (APHSTHC
) invoices unless overridden (MG10
). -
Hold and Prepay Codes:
- Hold codes (
HOLD
) must be'H'
(hold),'A'
(ACH),'W'
(wire transfer),'E'
(employee expense), or'U'
(utility auto-payment). -
Prepay codes (
PAID
) must be'P'
,'A'
,'W'
, or'E'
, with a corresponding check number (PPCK
) if applicable. -
Gallons and Receipt Validation:
- If the vendor requires gallons/receipts (
VNGRRQ = 'Y'
), bothGALN
andRCPT
must be entered. - If
VNGRRQ = 'N'
, gallons and receipts are prohibited. - If the G/L account requires gallons (
GLAPCD = 'Y'
),GALN
must be entered and match the sign of the amount (AMT
). -
Receipt numbers (
RCPT
) must exist inINFIL1
orINTZH1
, with valid quantities and no prior A/P postings. -
Purchase Order Requirements:
-
If the G/L account requires a purchase order (
GLPOCD = 'Y'
), a validPONO
must be entered. -
Discount Validation:
- Discount amount (
DISC
) and percentage (DSPC
) cannot both be non-zero. - A discount G/L (
ACDSGL
) must exist if discounts are used. -
Discount due date (
DSDT
) must be entered if discounts are applied, or an error is raised (MG20
). -
Freight Invoices:
- Freight invoices must be processed in the correct mode (
NORMAL
,PAPER
,ARGLMS
) based on invoice type (FRINTY
) inFRCFBH
orFRCINH
. -
Freight amounts (
FRTL
) are allocated to detail lines, with calculations ensuring detail totals match the invoice total. -
Sales Order Restrictions:
-
If a sales order number (
SORN
) is entered, receipt numbers and gallons are not allowed. -
Date Handling:
- Due dates and discount due dates are calculated based on vendor terms (
VNTERM
) fromGSTABL
. -
Dates are adjusted to avoid holidays and weekends (
APDATE
). -
Amount Validation:
- Invoice amount (
IAMT
) must be non-zero and match the sum of detail line amounts (AMT
+FRAM
).
- Invoice amount (
Tables (Files) Used¶
The program uses the following files, defined with specific attributes (e.g., UC
for update/create, IF
for input, ID
for indexed):
- SCREEN: Workstation file for interactive display (1200 bytes,
WORKSTN
). - APTRAN: A/P transaction file (404 bytes, update/create, key length 10).
- APTRANX: A/P transaction index file (404 bytes, input, key length 10).
- APTRNX: A/P transaction index file (404 bytes, input, external key, 27 bytes).
- APOPEN: A/P open items file (384 bytes, input, key length 16).
- APOPENH: A/P open items history file (384 bytes, update/create, key length 16).
- APOPNHC: A/P open items history control file (384 bytes, input, key length 32).
- APCONT: A/P control file (256 bytes, update/create, key length 2).
- APVEND: A/P vendor file (579 bytes, input, key length 7).
- APVENDX: A/P vendor index file (579 bytes, input, external key, 17 bytes).
- GLMAST: General ledger master file (256 bytes, input, key length 11).
- GSTABL: General system table (256 bytes, input, key length 12).
- APINVH: A/P invoice history file (64 bytes, input, key length 32).
- APHSTHC: A/P history control file (384 bytes, input, key length 32).
- INFIL1: Inventory file (448 bytes, input, external key, 9 bytes).
- INTZH1: Inventory transaction holding file (592 bytes, input, external key, 9 bytes).
- SA5FIUD: Sales file (detail, 1024 bytes, input, external key, 14 bytes).
- SA5FIUM: Sales file (misc, 1024 bytes, input, key length 14).
- SA5MOUD: Sales file (detail, 1024 bytes, input, external key, 14 bytes).
- SA5MOUM: Sales file (misc, 1024 bytes, input, key length 14).
- FRCINH: Freight invoice history file (206 bytes, input, key length 33).
- FRCFBH: Freight feedback history file (206 bytes, input, key length 39).
- APDATE: A/P date file (19 bytes, input, key length 10).
External Programs Called¶
- AP1011: Called to populate freight detail lines with calculated percentage amounts when a sales order (
SORN
) and freight total (FRTL
) are present. It uses theSALES
data structure as a parameter.
Summary¶
The AP100
RPG program is a critical component of the A/P voucher entry system, handling interactive input through multiple screens (AP100S1
, AP100S2
, AP100S3
, AP100S5
). It validates company, vendor, invoice, and detail line data, ensuring compliance with business rules such as unique invoice numbers, valid hold/prepay codes, gallons/receipt requirements, and freight invoice processing. The program integrates with numerous files for transaction, vendor, inventory, and financial data, and calls AP1011
for freight detail calculations. It enforces strict validations to maintain data integrity and supports various payment types and processing modes (e.g., NORMAL
, PAPER
, ARGLMS
).