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 Program¶
The AP781
program processes sorted vendor data from the AP780S
file and the original vendor file APVEND
to create a consolidated output file AP781
, which is used in subsequent steps to generate the IRS 1099 file. Here’s a step-by-step breakdown of the process:
- Program Initialization:
- The program defines input files
APVEND
(primary vendor file) andAP780S
(sorted input file), and an output fileAP781
. - It uses level-break logic (
L1
) to process records grouped by vendor, ensuring one output record per vendor. -
Initializes working fields (
L1AMT1
,L1AMT2
,BOX1
,BOX2
) to zero at the start of each vendor group (L1
level) usingZ-ADD*ZEROS
.- 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.
-
Extract State and City (GETSTA Subroutine):
- For each vendor record (
L1
level), the program calls theGETSTA
subroutine to parse the city and state from the vendor’s address fields (VNADD2
,VNADD3
, orVNADD4
). - Logic:
- Clears
STATE
,CITY
, andADD2
fields to blanks. - Checks address fields in reverse priority (
VNADD4
,VNADD3
,VNADD2
) for non-blank values, copying the first non-blank field toADD2
. - If no address fields are found, skips to
ENDSTA
. - Parses
ADD2
to extract the state: - Reads backward from position 30 to find the first letter (A-Z), which is assumed to be the start of the state code (e.g., "PA").
- Extracts the state (2 characters) into
STATE
. - Parses
ADD2
to extract the city: - Reads backward from the state’s position to find a space or comma, marking the end of the city.
- Copies characters from the start of
ADD2
to the delimiter intoCTY
(city field).
- Clears
-
Output: Populates
STATE
(2 characters) andCITY
(20 characters) for use in the output record. -
Determine Payment Amount Based on CURLST:
- Checks the
CURLST
field (from the user data structureUDS
, set byAP780P
as'C'
or'L'
):- If
CURLST = 'C'
(current year), addsVNYTDP
(this year’s year-to-date paid, positions 242-247) toL1AMT1
. - If
CURLST = 'L'
(last year), addsVNLYDP
(last year’s year-to-date paid, positions 248-253) toL1AMT1
.
- If
-
Adds
VNB2AM
(second 1099 box amount, positions 280-285) toL1AMT2
. -
Assign 1099 Box Numbers:
- If
BOX1
is zero, sets it toVNBOX1
(first 1099 box number, positions 276-277). - If
BOX2
is zero, sets it toVNBOX2
(second 1099 box number, positions 278-279). -
This ensures the box numbers from the vendor file are used unless already set.
-
Validate and Adjust Payment Amounts:
- Compares
L1AMT1
(total payment amount) toENTAMT
(entered amount fromUDS
, set byAP780P
). -
If
L1AMT1
is greater than or equal toENTAMT
(indicator 50 on):- If
BOX1
is zero, sets it to 7 (default IRS box for 1099-MISC nonemployee compensation). - If
L1AMT2
(second box amount) is greater than zero andBOX2
is non-zero: - Subtracts
L1AMT2
fromL1AMT1
to allocate the second box amount separately. - Increments
TOTB
(total count, positions 201-208 inUDS
) by 1 to track valid records. - Writes the output record to
AP781
using theL1ADD
exception output (EXCPTL1ADD
).
- If
-
Write Output Record to AP781:
-
When a valid record is processed (indicator 50 on), the program writes a record to the
AP781
file with the following fields:- Record Identification:
'A'
(position 1, constant). VN1099
(1099 code, position 2, fromAPVEND
).VNVEND
(vendor number, positions 4-8, fromAPVEND
).VNNAME
(vendor name, positions 9-38, fromAPVEND
).VNADD1
(address line 1, positions 39-68, fromAPVEND
).CITY
(city, parsed fromGETSTA
, positions 69-88).STATE
(state, parsed fromGETSTA
, positions 89-90).VNZIP5
(zip code, positions 159-163, fromAPVEND
).L1AMT1
(adjusted payment amount, positions 94-102, 9 digits, 2 decimals).L1AMT2
(second box amount, positions 103-111, 9 digits, 2 decimals).BOX1
(first 1099 box number, positions 112-113).BOX2
(second 1099 box number, positions 114-115).VNID#
(tax ID, positions 265-275, fromAPVEND
).VNSRT4
(sort abbreviation, positions 168-171, fromAPVEND
).VNPYN1
(payee name 1, positions 300-339, fromAPVEND
, added by JB01).VNPYN2
(payee name 2, positions 340-379, fromAPVEND
, added by JB01).VNADD2
(address line 2, positions 211-240, fromAPVEND
, added by JB02).VNNOVF
(name overflow, position 241, fromAPVEND
, added by JB02).VNNMCT
(IRS name control, positions 242-245, fromAPVEND
, added by JK01).VNFNAM
(first name, positions 246-265, fromAPVEND
).VNMNAM
(middle name, positions 266-285, fromAPVEND
).VNLNAM
(business/last name, positions 286-315, fromAPVEND
).VNSUFF
(name suffix, positions 316-320, fromAPVEND
).
- Record Identification:
-
Repeat for Each Vendor:
- The program processes each vendor record from
AP780S
andAPVEND
, using level-break logic (L1
) to group records by vendor, ensuring one output record per vendor regardless of multiple company entries.
Business Rules¶
The AP781
program enforces the following business rules for 1099 preprocessing:
1. Single Record per Vendor:
- Consolidates multiple vendor records (potentially across different companies, as indicated by VNCO
) into a single record per vendor, using the vendor number (VNVEND
) as the key, as processed by the sorted AP780S
file.
- Payment Amount Allocation:
- Uses
CURLST
('C'
for current year,'L'
for last year) to select the appropriate year-to-date payment amount (VNYTDP
orVNLYDP
). - Allocates the total payment (
L1AMT1
) and second box amount (L1AMT2
) separately if a second 1099 box (VNBOX2
) is specified. -
Subtracts
L1AMT2
fromL1AMT1
when both boxes are used to avoid double-counting. -
Default 1099 Box:
- If the first 1099 box (
BOX1
) is zero and the payment amount meets the threshold (L1AMT1 >= ENTAMT
), setsBOX1
to 7 (IRS box for nonemployee compensation on 1099-MISC). -
Retains vendor-specified box numbers (
VNBOX1
,VNBOX2
) when non-zero. -
Threshold Validation:
-
Only writes output records if the total payment amount (
L1AMT1
) is greater than or equal to the entered amount (ENTAMT
), ensuring only vendors meeting the IRS reporting threshold (e.g., $600 for 1099-MISC) are included. -
Address Parsing:
- Extracts state and city from the highest-priority non-blank address field (
VNADD4
,VNADD3
, orVNADD2
). - Assumes the state is a 2-character code (e.g., "PA") located after the zip code, and the city precedes the state, separated by a space or comma.
-
Handles cases where address fields are blank by skipping city/state extraction.
-
IRS Data Inclusion:
-
Includes IRS-specific fields like tax ID (
VNID#
), payee names (VNPYN1
,VNPYN2
), name overflow (VNNOVF
), IRS name control (VNNMCT
), and individual name components (VNFNAM
,VNMNAM
,VNLNAM
,VNSUFF
) to comply with IRS 1099 reporting requirements. -
Record Tracking:
- Increments
TOTB
for each valid vendor record written toAP781
, likely used for reporting or validation in subsequent steps.
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
.