AP766 RPG
Explanation of the Process Steps and Business Rules in the RPG Program (AP766.rpg36.txt)¶
The RPG III program AP766.rpg36.txt
is designed to preprocess Accounts Payable (A/P) 1099 forms on an IBM System/36 or AS/400 system. It is called by the OCL program AP765.ocl36.txt
and processes vendor data to consolidate records (one per vendor, regardless of multiple companies) and prepare them for printing 1099 forms. Below is a detailed explanation of the process steps, business rules, tables/files used, external programs called, and outputs.
Process Steps¶
- Program Setup and File Definitions:
- Header Specification (H):
- Line
0001
: Defines the program name (AP766
) and parameterP064
, likely a control parameter passed from the OCL program.
- Line
- File Specifications (F):
- Line
0006
:APVEND
(Input, Primary, 579 bytes, Record Address TypeR
): The vendor file (e.g.,APVN2012
, labeled?13?
in the OCL), read sequentially. - Line
0007
:AP765S
(Input, Record Address, 30 bytes, Indexed by positions 3-3): The sorted file (e.g.,?9?AP765S
) from the#GSORT
step in the OCL, used to control the order of processing. - Line
0008
:AP766
(Output, 300 bytes): The output work file (e.g.,?9?AP766
) that stores processed data for printing.
- Line
- Extension Specification (E):
- Line
0009
: LinksAP765S
(sorted file) toAPVEND
(vendor file) for record address processing, ensuring records are read in the sorted order (by 1099 type, vendor, and company).
- Line
-
Input Specifications (I):
- Lines
0011-0027
: Define fields in theAPVEND
file (formatNS 01
): VNDEL
(1 char, position 1): Delete code.VNCO
(29 chars, positions 2-30): Company number.VNVENDL1
(5 chars, positions 4-8): Vendor number.VNNAME
(30 chars, positions 9-38): Vendor name.VNADD1
(30 chars, positions 39-68): Address line 1.VNADD2
(30 chars, positions 69-98): Address line 2.VNADD3
(30 chars, positions 99-128): Address line 3.VNADD4
(30 chars, positions 129-158): Address line 4.VNZIP5
(5 numeric, positions 159-163): ZIP code.VNNOVF
(1 char, position 216, added by revisionJB02
): Name overflow indicator.VNYTDP
(6,2 numeric, positions 242-247): Current year year-to-date paid amount.VNLYDP
(6,2 numeric, positions 248-253): Last year year-to-date paid amount.VN1099L2
(1 char, position 264): A/P 1099 code (e.g.,M
,N
,I
,D
).VNID#
(11 chars, positions 265-275): 1099 ID number (e.g., Tax ID).VNBOX1
(2 numeric, positions 276-277): First 1099 box number.VNBOX2
(2 numeric, positions 278-279): Second 1099 box number.VNB2AM
(6,2 numeric, positions 280-285): Second 1099 box amount.VNPYN1
(40 chars, positions 300-339, added by revisionJB01
): Payee name 1.VNPYN2
(40 chars, positions 340-379, added by revisionJB01
): Payee name 2.- Lines
0028-0030
: Define fields in the User Data Structure (UDS
): KYCRLS
(1 char, position 141): Current/Last indicator (C
orL
).KYAMT
(8,2 numeric, positions 142-149): Amount threshold for processing.
- Lines
-
Initialization at Level 1 (L1):
-
Lines
0031-0034
: At the start of each level 1 break (L1
, triggered by a change in the key fields fromAP765S
, i.e., vendor number):L1AMT1
(9,2 numeric): Initialize to zero (total amount for box 1).L1AMT2
(9,2 numeric): Initialize to zero (total amount for box 2).BOX1
(2 numeric): Initialize to zero (first 1099 box number).BOX2
(2 numeric): Initialize to zero (second 1099 box number).
-
Process Year-to-Date Amount:
- Lines
0039-0043
: CheckKYCRLS
to determine whether to use current or last year’s YTD amount:- If
KYCRLS
isC
(current year), addVNYTDP
(current year YTD paid) toL1AMT1
. - Otherwise (e.g.,
L
for last year), addVNYTDP
toL1AMT1
(note: theELSE
clause usesVNYTDP
, which seems incorrect; it likely should useVNLYDP
for last year, indicating a potential bug or oversight).
- If
-
Line
0045
: AddVNB2AM
(second 1099 box amount) toL1AMT2
. -
Assign Box Numbers:
-
Lines
0047-0053
:- If
BOX1
is zero, set it toVNBOX1
(first 1099 box number from the vendor file). - If
BOX2
is zero, set it toVNBOX2
(second 1099 box number from the vendor file).
- If
-
Amount Validation and Adjustment:
- Line
0055
: CompareL1AMT1
(total amount for box 1) withKYAMT
(threshold amount fromUDS
). Set indicator50
ifL1AMT1
is greater than or equal toKYAMT
. -
Lines
0056-0063
(Level 1 and Indicator50
):- If
BOX1
is zero, set it to7
(likely a default box number for 1099 forms, e.g., box 7 for Non-Employee Compensation on 1099-NEC). - If
L1AMT2
(second box amount) is greater than zero andBOX2
is greater than zero, subtractL1AMT2
fromL1AMT1
to split the total amount between two boxes.
- If
-
Write Output Record:
- Line
0064
: If indicator50
is on (i.e.,L1AMT1
meets or exceeds the thresholdKYAMT
), write a record to theAP766
file using theL1ADD
output format. - Output Format (L1ADD) (Lines
0066-0079
):- Position 1:
'A'
(record identification). - Position 2:
VN1099
(1099 code, 1 char). - Positions 3-7:
VNVEND
(vendor number, 5 chars). - Positions 8-37:
VNNAME
(vendor name, 30 chars). - Positions 38-67:
VNADD1
(address line 1, 30 chars). - Positions 68-97:
VNADD2
(address line 2, 30 chars). - Positions 98-127:
VNADD3
(address line 3, 30 chars). - Positions 128-157:
VNADD4
(address line 4, 30 chars). - Positions 158-166:
L1AMT1
(box 1 amount, 9,2 numeric). - Positions 167-175:
L1AMT2
(box 2 amount, 9,2 numeric). - Positions 176-177:
BOX1
(box 1 number, 2 numeric). - Positions 178-179:
BOX2
(box 2 number, 2 numeric). - Positions 180-190:
VNID#
(1099 ID number, 11 chars). - Positions 191-230:
VNPYN1
(payee name 1, 40 chars, added byJB01
). - Positions 231-270:
VNPYN2
(payee name 2, 40 chars, added byJB01
). - Position 271:
VNNOVF
(name overflow indicator, 1 char, added byJB02
).
- Position 1:
Business Rules¶
- Consolidate Vendor Records:
-
The program processes one record per vendor, regardless of whether the vendor appears in multiple companies (indicated by
VNCO
). This is achieved using theL1
(Level 1) break on the vendor number from the sorted fileAP765S
. -
Year-to-Date Amount Selection:
- If
KYCRLS
isC
, use the current year’s YTD paid amount (VNYTDP
) forL1AMT1
. - If
KYCRLS
is notC
(e.g.,L
), the program incorrectly usesVNYTDP
instead ofVNLYDP
(last year’s YTD paid amount), which may be a coding error. -
The second 1099 box amount (
VNB2AM
) is added toL1AMT2
. -
Box Number Assignment:
- If
BOX1
orBOX2
are zero, they are set toVNBOX1
orVNBOX2
, respectively, from the vendor file. -
If
L1AMT1
meets the threshold (KYAMT
) andBOX1
is zero,BOX1
is set to7
(likely for 1099-NEC box 7). -
Amount Splitting:
-
If a second box amount (
L1AMT2
) and box number (BOX2
) exist, subtractL1AMT2
fromL1AMT1
to split the total amount between two 1099 boxes. -
Threshold Check:
-
Only vendors with
L1AMT1
greater than or equal toKYAMT
(threshold amount) are written to the output fileAP766
. -
Output Record Structure:
- The output file
AP766
includes vendor details, payment amounts, box numbers, and payee names, formatted for printing 1099 forms. - Revisions (
JB01
,JB02
) added support for payee names (VNPYN1
,VNPYN2
) and a name overflow indicator (VNNOVF
) for extended name handling.
Tables/Files Used¶
- APVEND:
- Input file (579 bytes, primary, labeled
?13?
in the OCL, e.g.,APVN2012
). - Contains vendor data from the period-end process (
AP300
), including vendor number, name, address, 1099 amounts, box numbers, and payee names. -
Fields include
VNDEL
,VNCO
,VNVENDL1
,VNNAME
,VNADD1-4
,VNZIP5
,VNNOVF
,VNYTDP
,VNLYDP
,VN1099L2
,VNID#
,VNBOX1
,VNBOX2
,VNB2AM
,VNPYN1
,VNPYN2
. -
AP765S:
- Input file (30 bytes, record address, labeled
?9?AP765S
in the OCL, e.g.,XXAP765S
). - Sorted file from
#GSORT
, used to control the order of processing (by 1099 type, vendor, and company). -
Linked to
APVEND
via theE
specification for record address processing. -
AP766:
- Output file (300 bytes, labeled
?9?AP766
in the OCL, e.g.,XXAP766
). -
Contains processed vendor records with consolidated amounts and box numbers, ready for printing 1099 forms.
-
PA1099X (Implied):
- Referenced in the OCL program (
?9?PA1099X
), likely a cross-reference or configuration file, but not directly used in this RPG program.
External Programs Called¶
- None are explicitly called within
AP766
. The program is invoked by the OCL programAP765.ocl36.txt
and works in conjunction with: #GSORT
(from the OCL, producesAP765S
).AP765
(from the OCL, prints 1099 forms usingAP766
).
Outputs¶
- AP766 File:
- A work file (e.g.,
?9?AP766
) containing one record per vendor with the following fields:- Record identifier (
'A'
, position 1). - 1099 code (
VN1099
, position 2). - Vendor number (
VNVEND
, positions 3-7). - Vendor name (
VNNAME
, positions 8-37). - Address lines (
VNADD1-4
, positions 38-157). - Box 1 amount (
L1AMT1
, positions 158-166). - Box 2 amount (
L1AMT2
, positions 167-175). - Box 1 number (
BOX1
, positions 176-177). - Box 2 number (
BOX2
, positions 178-179). - 1099 ID number (
VNID#
, positions 180-190). - Payee name 1 (
VNPYN1
, positions 191-230). - Payee name 2 (
VNPYN2
, positions 231-270). - Name overflow indicator (
VNNOVF
, position 271).
- Record identifier (
- Used by the subsequent
AP765
program to print 1099 forms.
Summary¶
- Purpose: The RPG program
AP766
preprocesses vendor data for 1099 forms, consolidating records to one per vendor, calculating payment amounts for specific 1099 boxes, and writing the results to a work file for printing. - Process:
- Reads sorted vendor data (
AP765S
andAPVEND
) in order (by 1099 type, vendor, company). - Initializes amounts and box numbers at each vendor break (
L1
). - Selects current or last year’s YTD amount based on
KYCRLS
(with a potential bug usingVNYTDP
for both). - Assigns box numbers and splits amounts if a second box is used.
- Writes records to
AP766
if the total amount meets the threshold (KYAMT
). - Business Rules:
- One record per vendor, regardless of multiple companies.
- Splits amounts between two 1099 boxes if applicable.
- Applies a threshold (
KYAMT
) to filter vendors. - Supports extended payee names and name overflow.
- Files Used:
- Input:
APVEND
(vendor data),AP765S
(sorted control file). - Output:
AP766
(processed work file). - External Programs: None called directly; part of a workflow with
#GSORT
andAP765
. - Outputs: The
AP766
file, formatted for printing 1099 forms by theAP765
program.
This program is a critical step in preparing consolidated vendor data for 1099 form generation, ensuring accurate amounts and box assignments.