AP781 RPG36
The AP781.rpg36.txt
is an RPG/36 program invoked by the main OCL program (AP780.ocl36.txt
) to preprocess Accounts Payable (A/P) vendor data for IRS 1099 file creation. It consolidates vendor data from the APVEND
file, using the sorted AP780S
file to ensure one record per vendor, and produces the AP781
output file for further processing by AP780
. Below, I’ll detail the process steps, business rules, tables used, and external programs called.
Process Steps of the AP781 RPG/36 Program¶
The program reads vendor data from APVEND
and a sorted control file AP780S
, processes it to consolidate amounts and extract city/state information, and writes a single record per vendor to AP781
. Here are the detailed steps:
- File and Data Structure Definitions:
- Files:
APVEND
: Primary input file (579 bytes, indexed), containing vendor data.AP780S
: Secondary input file (30 bytes, indexed by 3-byte key), used to identify vendors for processing.AP781
: Output file (320 bytes), storing consolidated vendor data.
- Input Record (APVEND):
VNDEL
(1): Delete code.VNCO
(2–3): Company number.VNVENDL1
(4–8): Vendor number.VNNAME
(9–38): Vendor name.VNADD1
(39–68): Address line 1.VNADD2
(69–98): Address line 2.VNADD3
(99–128): Address line 3.VNADD4
(129–158): Address line 4.VNZIP5
(159–163, zoned): 5-digit ZIP code.VNSRT4
(168–171): Alpha sort abbreviation.VNNOVF
(216): Name overflow indicator (Y
if address used for name continuation).VNYTDP
(242–247, packed): Current year-to-date paid amount.VNLYDP
(248–253, packed): Last year-to-date paid amount.VN1099L2
(264): 1099 code (D
,I
,M
,N
).VNID#
(265–275): 1099 tax ID.VNBOX1
(276–277, zoned): First 1099 box number.VNBOX2
(278–279, zoned): Second 1099 box number.VNB2AM
(280–285, packed): Second 1099 box amount.VNPYN1
(300–339): Payee name 1.VNPYN2
(340–379): Payee name 2.VNNMCT
(380–383): IRS name control.VNFNAM
(418–437): First name.VNMNAM
(438–457): Middle name.VNLNAM
(458–487): Business/last name.VNSUFF
(488–491): Name suffix.
- Data Structures:
ADD2
(30): Temporary field for address processing.CITY
(1–20): Extracted city name.CTY
(1–20): Temporary city field.STATE
(2): Extracted state code.
- User Data Structure (UDS):
ENTAMT
(111–118, zoned): Entered amount threshold.CURLST
(123): Current (C
) or last (L
) year indicator.TOTB
(201–208, zoned): Total count of records written.
-
External Description:
AP780S
links toAPVEND
for matching vendor records.
-
Main Processing Loop (Level 1, L1):
-
For each level 1 break (group by vendor, driven by
AP780S
):- Executes the
GETSTA
subroutine to extractSTATE
andCITY
. - Initializes
L1AMT1
,L1AMT2
,BOX1
, andBOX2
to zeros. - Accumulates payment amounts based on
CURLST
: - If
CURLST = 'C'
, addsVNYTDP
(current year YTD) toL1AMT1
. - If
CURLST = 'L'
, addsVNLYDP
(last year YTD) toL1AMT1
. - Adds
VNB2AM
(second box amount) toL1AMT2
. - Sets
BOX1
toVNBOX1
andBOX2
toVNBOX2
if not zero. - If
L1AMT1
meets or exceedsENTAMT
(threshold): - If
BOX1 = 0
, defaults to 7 (Nonemployee Compensation for 1099-MISC). - If
L1AMT2 > 0
andBOX2 > 0
, subtractsL1AMT2
fromL1AMT1
to split amounts. - Increments
TOTB
(record count). - Writes an output record to
AP781
(EXCPT L1ADD
).
- Executes the
-
GETSTA Subroutine:
- Extracts
STATE
andCITY
from address fields (VNADD4
,VNADD3
,VNADD2
):- Checks
VNADD4
,VNADD3
,VNADD2
(in that order) for non-blank data, moving the first non-blank toADD2
. - If all address fields are blank, skips to
ENDSTA
. - Reads
ADD2
backwards from position 30 to find the state (first letter betweenA
andZ
). - Extracts the state code (2 characters) starting at the found position.
- Extracts the city by reading backwards from the state position until a space or comma is found, then copies characters from position 1 to the delimiter into
CTY
.
- Checks
-
Outputs
STATE
andCITY
for theAP781
record. -
Output Record (L1ADD):
- Writes to
AP781
with:A
(record identifier).VN1099
(1099 code).VNVEND
(vendor number).VNNAME
(vendor name).VNADD1
(address line 1).CITY
(extracted city).STATE
(extracted state).VNZIP5
(ZIP code).L1AMT1
(primary amount).L1AMT2
(secondary amount).BOX1
(first box number).BOX2
(second box number).VNID#
(tax ID).VNSRT4
(sort abbreviation).VNPYN1
,VNPYN2
(payee names).VNADD2
(address line 2).VNNOVF
(name overflow indicator).VNNMCT
(IRS name control).VNFNAM
,VNMNAM
,VNLNAM
,VNSUFF
(name components).
Business Rules¶
The program enforces the following business rules:
1. Single Record per Vendor:
- Consolidates data to produce one record per vendor, regardless of multiple company entries, using AP780S
to identify unique vendors.
2. Amount Threshold:
- Only writes records to AP781
if L1AMT1
(total amount) meets or exceeds ENTAMT
(threshold from UDS
).
3. Amount Splitting:
- If a second box amount (VNB2AM
) exists, it’s assigned to L1AMT2
, and L1AMT1
is reduced by L1AMT2
to reflect the primary box amount.
- Example: If VNYTDP = $15,000
, VNBOX1 = 7
(Nonemployee Compensation), VNBOX2 = 1
(Rents), and VNB2AM = $5,000
, then L1AMT1 = $10,000
, L1AMT2 = $5,000
.
4. Default Box Number:
- If BOX1 = 0
and the amount threshold is met, defaults to box 7 (Nonemployee Compensation for 1099-MISC).
5. Year Selection:
- Uses CURLST
(C
or L
) to select VNYTDP
(current year) or VNLYDP
(last year) for L1AMT1
.
6. City/State Extraction:
- Extracts STATE
and CITY
from the highest non-blank address field (VNADD4
, VNADD3
, VNADD2
).
- Assumes state is the last 2 characters before the ZIP code, and city is the text before a space or comma.
7. Name Handling:
- Includes VNPYN1
, VNPYN2
(payee names), VNNOVF
(name overflow), and VNNMCT
(IRS name control) for downstream processing.
Tables Used¶
The program uses the following files/tables: 1. APVEND: - Primary input file (579 bytes, indexed). - Contains vendor data including payment amounts, 1099 codes, tax IDs, and address fields. 2. AP780S: - Secondary input file (30 bytes, 3-byte key, indexed). - Sorted file used to identify unique vendors for consolidation. 3. AP781: - Output file (320 bytes). - Stores consolidated vendor data with extracted city/state, amounts, and box numbers.
External Programs Called¶
The AP781
program does not explicitly call any external programs. It is invoked by the main OCL program (AP780.ocl36.txt
) and processes data from APVEND
and AP780S
to produce AP781
.
Summary¶
The AP781
RPG/36 program preprocesses A/P vendor data by:
- Consolidating vendor records from APVEND
using AP780S
to ensure one record per vendor.
- Accumulating payment amounts (VNYTDP
or VNLYDP
) based on CURLST
, splitting amounts if a second box (VNB2AM
) exists.
- Extracting CITY
and STATE
from address fields using the GETSTA
subroutine.
- Writing records to AP781
only if the total amount meets the ENTAMT
threshold, with a default box number of 7 if unspecified.
- Including payee names, name overflow, and IRS name control for IRS compliance.
The program uses APVEND
and AP780S
as inputs and AP781
as output, with no external program calls, and enforces rules to ensure accurate 1099 data for downstream processing by AP780
.