Skip to content

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:

  1. Program Initialization:
  2. The program defines input files APVEND (primary vendor file) and AP780S (sorted input file), and an output file AP781.
  3. It uses level-break logic (L1) to process records grouped by vendor, ensuring one output record per vendor.
  4. Initializes working fields (L1AMT1, L1AMT2, BOX1, BOX2) to zero at the start of each vendor group (L1 level) using Z-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 to APVEND for matching vendor records.
  5. Extract State and City (GETSTA Subroutine):

  6. For each vendor record (L1 level), the program calls the GETSTA subroutine to parse the city and state from the vendor’s address fields (VNADD2, VNADD3, or VNADD4).
  7. Logic:
    • Clears STATE, CITY, and ADD2 fields to blanks.
    • Checks address fields in reverse priority (VNADD4, VNADD3, VNADD2) for non-blank values, copying the first non-blank field to ADD2.
    • 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 into CTY (city field).
  8. Output: Populates STATE (2 characters) and CITY (20 characters) for use in the output record.

  9. Determine Payment Amount Based on CURLST:

  10. Checks the CURLST field (from the user data structure UDS, set by AP780P as 'C' or 'L'):
    • If CURLST = 'C' (current year), adds VNYTDP (this year’s year-to-date paid, positions 242-247) to L1AMT1.
    • If CURLST = 'L' (last year), adds VNLYDP (last year’s year-to-date paid, positions 248-253) to L1AMT1.
  11. Adds VNB2AM (second 1099 box amount, positions 280-285) to L1AMT2.

  12. Assign 1099 Box Numbers:

  13. If BOX1 is zero, sets it to VNBOX1 (first 1099 box number, positions 276-277).
  14. If BOX2 is zero, sets it to VNBOX2 (second 1099 box number, positions 278-279).
  15. This ensures the box numbers from the vendor file are used unless already set.

  16. Validate and Adjust Payment Amounts:

  17. Compares L1AMT1 (total payment amount) to ENTAMT (entered amount from UDS, set by AP780P).
  18. If L1AMT1 is greater than or equal to ENTAMT (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 and BOX2 is non-zero:
    • Subtracts L1AMT2 from L1AMT1 to allocate the second box amount separately.
    • Increments TOTB (total count, positions 201-208 in UDS) by 1 to track valid records.
    • Writes the output record to AP781 using the L1ADD exception output (EXCPTL1ADD).
  19. Write Output Record to AP781:

  20. 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, from APVEND).
    • VNVEND (vendor number, positions 4-8, from APVEND).
    • VNNAME (vendor name, positions 9-38, from APVEND).
    • VNADD1 (address line 1, positions 39-68, from APVEND).
    • CITY (city, parsed from GETSTA, positions 69-88).
    • STATE (state, parsed from GETSTA, positions 89-90).
    • VNZIP5 (zip code, positions 159-163, from APVEND).
    • 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, from APVEND).
    • VNSRT4 (sort abbreviation, positions 168-171, from APVEND).
    • VNPYN1 (payee name 1, positions 300-339, from APVEND, added by JB01).
    • VNPYN2 (payee name 2, positions 340-379, from APVEND, added by JB01).
    • VNADD2 (address line 2, positions 211-240, from APVEND, added by JB02).
    • VNNOVF (name overflow, position 241, from APVEND, added by JB02).
    • VNNMCT (IRS name control, positions 242-245, from APVEND, added by JK01).
    • VNFNAM (first name, positions 246-265, from APVEND).
    • VNMNAM (middle name, positions 266-285, from APVEND).
    • VNLNAM (business/last name, positions 286-315, from APVEND).
    • VNSUFF (name suffix, positions 316-320, from APVEND).
  21. Repeat for Each Vendor:

  22. The program processes each vendor record from AP780S and APVEND, 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.

  1. Payment Amount Allocation:
  2. Uses CURLST ('C' for current year, 'L' for last year) to select the appropriate year-to-date payment amount (VNYTDP or VNLYDP).
  3. Allocates the total payment (L1AMT1) and second box amount (L1AMT2) separately if a second 1099 box (VNBOX2) is specified.
  4. Subtracts L1AMT2 from L1AMT1 when both boxes are used to avoid double-counting.

  5. Default 1099 Box:

  6. If the first 1099 box (BOX1) is zero and the payment amount meets the threshold (L1AMT1 >= ENTAMT), sets BOX1 to 7 (IRS box for nonemployee compensation on 1099-MISC).
  7. Retains vendor-specified box numbers (VNBOX1, VNBOX2) when non-zero.

  8. Threshold Validation:

  9. 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.

  10. Address Parsing:

  11. Extracts state and city from the highest-priority non-blank address field (VNADD4, VNADD3, or VNADD2).
  12. 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.
  13. Handles cases where address fields are blank by skipping city/state extraction.

  14. IRS Data Inclusion:

  15. 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.

  16. Record Tracking:

  17. Increments TOTB for each valid vendor record written to AP781, 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.