Skip to content

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

  1. Program Setup and File Definitions:
  2. Header Specification (H):
    • Line 0001: Defines the program name (AP766) and parameter P064, likely a control parameter passed from the OCL program.
  3. File Specifications (F):
    • Line 0006: APVEND (Input, Primary, 579 bytes, Record Address Type R): 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.
  4. Extension Specification (E):
    • Line 0009: Links AP765S (sorted file) to APVEND (vendor file) for record address processing, ensuring records are read in the sorted order (by 1099 type, vendor, and company).
  5. Input Specifications (I):

    • Lines 0011-0027: Define fields in the APVEND file (format NS 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 revision JB02): 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 revision JB01): Payee name 1.
    • VNPYN2 (40 chars, positions 340-379, added by revision JB01): Payee name 2.
    • Lines 0028-0030: Define fields in the User Data Structure (UDS):
    • KYCRLS (1 char, position 141): Current/Last indicator (C or L).
    • KYAMT (8,2 numeric, positions 142-149): Amount threshold for processing.
  6. Initialization at Level 1 (L1):

  7. Lines 0031-0034: At the start of each level 1 break (L1, triggered by a change in the key fields from AP765S, 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).
  8. Process Year-to-Date Amount:

  9. Lines 0039-0043: Check KYCRLS to determine whether to use current or last year’s YTD amount:
    • If KYCRLS is C (current year), add VNYTDP (current year YTD paid) to L1AMT1.
    • Otherwise (e.g., L for last year), add VNYTDP to L1AMT1 (note: the ELSE clause uses VNYTDP, which seems incorrect; it likely should use VNLYDP for last year, indicating a potential bug or oversight).
  10. Line 0045: Add VNB2AM (second 1099 box amount) to L1AMT2.

  11. Assign Box Numbers:

  12. Lines 0047-0053:

    • If BOX1 is zero, set it to VNBOX1 (first 1099 box number from the vendor file).
    • If BOX2 is zero, set it to VNBOX2 (second 1099 box number from the vendor file).
  13. Amount Validation and Adjustment:

  14. Line 0055: Compare L1AMT1 (total amount for box 1) with KYAMT (threshold amount from UDS). Set indicator 50 if L1AMT1 is greater than or equal to KYAMT.
  15. Lines 0056-0063 (Level 1 and Indicator 50):

    • If BOX1 is zero, set it to 7 (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 and BOX2 is greater than zero, subtract L1AMT2 from L1AMT1 to split the total amount between two boxes.
  16. Write Output Record:

  17. Line 0064: If indicator 50 is on (i.e., L1AMT1 meets or exceeds the threshold KYAMT), write a record to the AP766 file using the L1ADD output format.
  18. 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 by JB01).
    • Positions 231-270: VNPYN2 (payee name 2, 40 chars, added by JB01).
    • Position 271: VNNOVF (name overflow indicator, 1 char, added by JB02).

Business Rules

  1. Consolidate Vendor Records:
  2. The program processes one record per vendor, regardless of whether the vendor appears in multiple companies (indicated by VNCO). This is achieved using the L1 (Level 1) break on the vendor number from the sorted file AP765S.

  3. Year-to-Date Amount Selection:

  4. If KYCRLS is C, use the current year’s YTD paid amount (VNYTDP) for L1AMT1.
  5. If KYCRLS is not C (e.g., L), the program incorrectly uses VNYTDP instead of VNLYDP (last year’s YTD paid amount), which may be a coding error.
  6. The second 1099 box amount (VNB2AM) is added to L1AMT2.

  7. Box Number Assignment:

  8. If BOX1 or BOX2 are zero, they are set to VNBOX1 or VNBOX2, respectively, from the vendor file.
  9. If L1AMT1 meets the threshold (KYAMT) and BOX1 is zero, BOX1 is set to 7 (likely for 1099-NEC box 7).

  10. Amount Splitting:

  11. If a second box amount (L1AMT2) and box number (BOX2) exist, subtract L1AMT2 from L1AMT1 to split the total amount between two 1099 boxes.

  12. Threshold Check:

  13. Only vendors with L1AMT1 greater than or equal to KYAMT (threshold amount) are written to the output file AP766.

  14. Output Record Structure:

  15. The output file AP766 includes vendor details, payment amounts, box numbers, and payee names, formatted for printing 1099 forms.
  16. Revisions (JB01, JB02) added support for payee names (VNPYN1, VNPYN2) and a name overflow indicator (VNNOVF) for extended name handling.

Tables/Files Used

  1. APVEND:
  2. Input file (579 bytes, primary, labeled ?13? in the OCL, e.g., APVN2012).
  3. Contains vendor data from the period-end process (AP300), including vendor number, name, address, 1099 amounts, box numbers, and payee names.
  4. Fields include VNDEL, VNCO, VNVENDL1, VNNAME, VNADD1-4, VNZIP5, VNNOVF, VNYTDP, VNLYDP, VN1099L2, VNID#, VNBOX1, VNBOX2, VNB2AM, VNPYN1, VNPYN2.

  5. AP765S:

  6. Input file (30 bytes, record address, labeled ?9?AP765S in the OCL, e.g., XXAP765S).
  7. Sorted file from #GSORT, used to control the order of processing (by 1099 type, vendor, and company).
  8. Linked to APVEND via the E specification for record address processing.

  9. AP766:

  10. Output file (300 bytes, labeled ?9?AP766 in the OCL, e.g., XXAP766).
  11. Contains processed vendor records with consolidated amounts and box numbers, ready for printing 1099 forms.

  12. PA1099X (Implied):

  13. 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 program AP765.ocl36.txt and works in conjunction with:
  • #GSORT (from the OCL, produces AP765S).
  • AP765 (from the OCL, prints 1099 forms using AP766).

Outputs

  1. AP766 File:
  2. 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).
  3. 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 and APVEND) 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 using VNYTDP 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 and AP765.
  • Outputs: The AP766 file, formatted for printing 1099 forms by the AP765 program.

This program is a critical step in preparing consolidated vendor data for 1099 form generation, ensuring accurate amounts and box assignments.