Skip to content

AP765 RPG36

Explanation of the Process Steps and Business Rules in the RPG Program (AP765.rpg36.txt)

The RPG III program AP765.rpg36.txt is designed to print vendor 1099 forms on an IBM System/36 or AS/400 system. It is called by the OCL program AP765.ocl36.txt and uses data from the preprocessed file AP766 to generate 1099 forms, printing two forms per page on laser paper. Below is a detailed explanation of the process steps, business rules, tables/files used, and external programs called.


Process Steps

  1. Program Setup and File Definitions:
  2. Header Specification (H):
    • Line 0002: Defines the program name (AP765) and parameter P016, likely a control parameter passed from the OCL program.
  3. File Specifications (F):
    • Line 0008: AP766 (Input, Primary, 300 bytes): The preprocessed work file (e.g., ?9?AP766 from the OCL), containing consolidated vendor data.
    • Line 0009: AP1099 (Output, 80 bytes, Printer): The printer file used to output 1099 forms, configured in the OCL with form type 1099, 10 CPI, and 6 LPI.
  4. Line Counter Specification (L):
    • Line 0011: Defines line counter settings for AP1099 with 66 lines per form (FL 66) and 66 lines of overflow (OL 66), ensuring proper pagination.
  5. Input Specifications (I):

    • Lines 0012-0025: Define fields in the AP766 file (format NS 01):
    • VNDEL (1 char, position 1): Delete code.
    • VN1099 (1 char, position 2): A/P 1099 code (e.g., M for Miscellaneous, N for Non-Employee Compensation).
    • VNVEND (5 chars, positions 3-7): Vendor number.
    • VNNAME (30 chars, positions 8-37): Vendor name.
    • VNADD1-4 (30 chars each, positions 38-157): Address lines 1-4.
    • L1AMT1 (9,2 numeric, positions 158-166): First box amount.
    • L1AMT2 (9,2 numeric, positions 167-175): Second box amount.
    • BOX1 (2 numeric, positions 176-177): First box number.
    • BOX2 (2 numeric, positions 178-179): Second box number.
    • VNID# (11 chars, positions 180-190): 1099 ID number (e.g., Tax ID).
    • VNPYN1 (40 chars, positions 191-230, added by JB01): Payee name 1.
    • VNPYN2 (40 chars, positions 231-270, added by JB01): Payee name 2.
    • VNNOVF (1 char, position 271, added by JB02): Name overflow indicator.
    • STATID (8 chars, positions 272-279): State ID.
    • STATED (9,2 numeric, positions 280-288): State amount.
    • Lines 0026-0032: Define fields in the User Data Structure (UDS):
    • HEAD1 (30 chars, positions 1-30): First heading (e.g., company name).
    • HEAD2 (30 chars, positions 31-60): Second heading (e.g., address line 1).
    • HEAD3 (30 chars, positions 61-90): Third heading (e.g., address line 2).
    • ID# (10 chars, positions 91-100): Company Tax ID.
    • ENTAMT (8,2 numeric, positions 101-108): Threshold amount for printing.
    • CURLST (1 char, position 109): Current/Last indicator (C or L).
    • CNYEAR (4 numeric, positions 201-204): Current year.
    • YEAR (4 numeric, positions 203-204): Year (overlaps with CNYEAR, possibly a typo or legacy field).
  6. Initial Vendor Processing:

  7. Vendor Number Check:
    • Lines C*: If VNVEND equals 9384, set YES to 'YES' (3 chars). This likely flags a specific vendor for special handling, though its purpose is unclear.
  8. 1099 Type Check:

    • If VN1099 is M (Miscellaneous), set indicator 33 on.
    • If VN1099 is N (Non-Employee Compensation), set indicator 34 on.
    • These indicators control which box amounts are printed (e.g., AMT11 for 1099-MISC or 1099-NEC).
  9. Amount Validation:

  10. Line 0034: Add L1AMT1 and L1AMT2 to compute TOTAMT (9,2 numeric), the total vendor payment.
  11. Line 0035: Compare TOTAMT with ENTAMT (threshold amount from UDS). Set indicator 30 if TOTAMT is greater than or equal to ENTAMT.
  12. Line 0036: If indicator 30 is off (N30), skip to the END tag, bypassing the vendor (i.e., only vendors meeting the threshold are printed).

  13. Form Counter Logic:

  14. Lines C*: Manage the COUNTP (2 numeric) field to track whether the first (31) or second (32) form on the page is being processed:

    • If COUNTP is zero, set it to 1, set indicator 31 on (first form), and set 32 off.
    • Otherwise, increment COUNTP, set 31 off, and set 32 on (second form).
    • This supports printing two forms per page (revision MG03).
  15. Clear Work Fields:

  16. Lines JB01: For each form (indicators 31 or 32):

    • Clear fields for payee names (PYN11, PYN12, PYN21, PYN22), tax IDs (VNID#1, VNID#2), state amounts (STATE1, STATE2), state IDs (STATI1, STATI2), vendor numbers (VNVEN1, VNVEN2), addresses (ADDR11, ADDR12, ADDR21, ADDR22, CTSTZ1, CTSTZ2), and amounts (AMT11, AMT12, AMT31, AMT32, AMT61, AMT62, AMT71, AMT72).
    • Reset indicators 71, 72, 35, 36 to control name and address printing.
  17. Payee and Address Processing (First Form, Indicator 31):

  18. Lines JB01: Determine whether to use vendor name or payee names:
    • If VNPYN1 is blank, use VNNAME for PYN11 (vendor name).
    • If VNNOVF is Y (name overflow, revision JB02), set indicators 35 and 71 on.
    • If VNPYN1 is not blank, use VNPYN1 for PYN11 and set 71 on. If VNPYN2 is not blank, use VNPYN2 for PYN21 and set 71 on.
  19. Lines 0045-0069: Assign address fields based on non-blank values:
    • If VNADD4 is not blank, set CTSTZ1 (city/state/ZIP) to VNADD4, VNAD21 to VNADD3, VNAD11 to VNADD2, and PYN21 to VNADD1.
    • Else if VNADD3 is not blank, set CTSTZ1 to VNADD3, VNAD21 to VNADD2, PYN21 to VNADD1.
    • Else if VNADD2 is not blank, set CTSTZ1 to VNADD2, PYN21 to VNADD1.
    • Else if VNADD1 is not blank, set CTSTZ1 to VNADD1.
    • If none are non-blank, set indicator 73 on (likely to skip address printing).
    • Jump to CONT1 tag after address assignment.
  20. Lines 0045-0069 (non-overflow case, N35): Similar address assignment without overflow logic.

  21. Payee and Address Processing (Second Form, Indicator 32):

  22. Identical logic to the first form, but for fields PYN12, PYN22, VNAD12, CTSTZ2, with indicators 36 and 72, jumping to CONT2 tag.

  23. Address Processing (Non-Overflow, CONT3 and CONT4):

  24. Lines 0045-0069: For both forms (31N35 and 32N36), assign address fields similarly to ensure proper formatting when no name overflow occurs.

  25. Amount Assignment for Printing:

  26. Lines 0071-0094: Assign amounts to specific 1099 box fields based on BOX1 and BOX2:

    • For BOX1 (indicators 31 and 32):
    • If 1, set AMT11/AMT12 to L1AMT1 (e.g., box 1 for 1099-MISC).
    • If 3, set AMT31/AMT32 to L1AMT1 (e.g., box 3 for 1099-MISC).
    • If 6, set AMT61/AMT62 to L1AMT1 (e.g., box 6 for 1099-MISC).
    • If 7, set AMT71/AMT72 to L1AMT1 (e.g., box 7 for 1099-NEC).
    • For BOX2 (indicators 31 and 32):
    • If 1, set AMT11/AMT12 to L1AMT2.
    • If 3, set AMT31/AMT32 to L1AMT2.
    • If 6, set AMT61/AMT62 to L1AMT2.
    • If 7, set AMT71/AMT72 to L1AMT2.
  27. Accumulate Totals:

    • Lines 0095-0098: For each form:
    • Increment COUNT (6 numeric, total vendors printed).
    • Add AMT11/AMT12 to LRAMT1 (10,2 numeric, total for box 1).
    • Add AMT31/AMT32 to LRAMT3 (total for box 3).
    • Add AMT61/AMT62 to LRAMT6 (total for box 6).
    • Add AMT71/AMT72 to LRAMT7 (total for box 7).
  28. Page Break Logic:

    • Lines C*: If COUNTP equals 2 (both forms on the page filled):
    • Reset COUNTP to zero, set 31 on, and execute an EXCPT to print the page.
    • At end of file (LR on):
    • If data remains for the first form (31 on, not 32), print a final page with one vendor.
    • Compute total amount LRAMT (11,2 numeric) by summing LRAMT1, LRAMT3, LRAMT6, LRAMT7.
    • Set indicator 30 and execute EXCPT to print totals.
  29. Output to Printer:

    • Lines 0107-0140: Define the output format for AP1099:
    • First Form (Indicator 31):
      • Lines 5-23: Print company headers (HEAD1-3), year (CNYEAR), tax IDs (ID#, VNID#1), payee names (PYN11, PYN21), addresses (VNAD11, VNAD21, CTSTZ1), and amounts (AMT11, AMT31, AMT61, AMT71).
      • Conditional on 33 (1099-MISC) or 34 (1099-NEC) for amount fields.
    • Second Form (Indicator 32):
      • Similar fields for the second form, using PYN12, PYN22, VNAD12, CTSTZ2, AMT12, AMT32, AMT62, AMT72, VNID#2.
    • Totals (LR):
      • Print HEAD1-3, ID#, totals (LRAMT1, LRAMT3, LRAMT6, LRAMT7, LRAMT), and vendor count (COUNT).
    • Vendor Number (Revision JB02):
      • Print VNVEN1/VNVEN2 as the account number for each form.

Business Rules

  1. Threshold Check:
  2. Only vendors with a total amount (TOTAMT = L1AMT1 + L1AMT2) greater than or equal to ENTAMT are printed.

  3. Two Forms per Page:

  4. The program prints two 1099 forms per page on laser paper (revision MG03), managed by COUNTP and indicators 31/32.
  5. If only one vendor remains at the end of the file, a final page with one form is printed.

  6. Payee Name Handling:

  7. If VNPYN1 is blank, use VNNAME (vendor name). Otherwise, use VNPYN1 and VNPYN2 (payee names, revision JB01).
  8. If VNNOVF is Y, use address fields to continue the name on the second line (revision JB02).

  9. Address Formatting:

  10. Use the highest non-blank address field (VNADD4 to VNADD1) for city/state/ZIP (CTSTZ1/CTSTZ2) and shift other fields accordingly to ensure proper formatting.

  11. Box Amount Assignment:

  12. Amounts are assigned to boxes 1, 3, 6, or 7 based on BOX1 and BOX2 values, supporting both 1099-MISC and 1099-NEC forms (revision MG04).

  13. 1099 Type:

  14. Indicator 33 for 1099-MISC (VN1099 = 'M') and 34 for 1099-NEC (VN1099 = 'N') control amount field printing.

  15. Totals:

  16. Accumulate totals for each box (LRAMT1, LRAMT3, LRAMT6, LRAMT7) and vendor count (COUNT) for the final summary.

  17. Vendor Number as Account Number:

  18. Print VNVEND as the account number (revision JB02).

Tables/Files Used

  1. AP766:
  2. Input file (300 bytes, labeled ?9?AP766 in the OCL, e.g., XXAP766).
  3. Contains preprocessed vendor data from AP766.rpg36.txt, including vendor details, amounts, box numbers, and payee names.

  4. AP1099:

  5. Output printer file (80 bytes, labeled AP1099 in the OCL).
  6. Configured to print 1099 forms with form type 1099, 10 CPI, 6 LPI, two forms per page.

  7. PA1099X (Implied):

  8. Referenced in the OCL (?9?PA1099X), likely a cross-reference file, but not used directly in this program.

External Programs Called

  • None are explicitly called within AP765. It is invoked by AP765.ocl36.txt and processes data from AP766.rpg36.txt, with input prepared by #GSORT and AP766.

Outputs

  1. AP1099 Printer File:
  2. Prints 1099 forms (two per page, revision MG03) with:
    • Company headers (HEAD1, HEAD2, HEAD3).
    • Year (CNYEAR).
    • Company Tax ID (ID#) and vendor Tax ID (VNID#1/VNID#2).
    • Payee names (PYN11/PYN12, PYN21/PYN22) or vendor name (VNNAME).
    • Addresses (VNAD11/VNAD12, VNAD21/VNAD22, CTSTZ1/CTSTZ2).
    • Amounts for boxes 1, 3, 6, or 7 (AMT11/AMT12, AMT31/AMT32, AMT61/AMT62, AMT71/AMT72).
    • Vendor number as account number (VNVEN1/VNVEN2, revision JB02).
  3. Final page includes totals (LRAMT1, LRAMT3, LRAMT6, LRAMT7, LRAMT) and vendor count (COUNT).

Summary

  • Purpose: The RPG program AP765 prints 1099 forms (MISC and NEC) using preprocessed vendor data, formatting two forms per page on laser paper.
  • Process:
  • Reads AP766 and validates vendor amounts against a threshold (ENTAMT).
  • Manages two forms per page with COUNTP and indicators 31/32.
  • Assigns payee names, addresses, and amounts to appropriate fields.
  • Prints forms with company and vendor details, amounts, and totals.
  • Business Rules:
  • Prints only vendors meeting the amount threshold.
  • Supports two forms per page and different 1099 types (MISC, NEC).
  • Handles payee names, name overflow, and vendor number as account number.
  • Accumulates totals for reporting.
  • Files Used:
  • Input: AP766 (preprocessed vendor data).
  • Output: AP1099 (printer file for 1099 forms).
  • External Programs: None called directly; part of a workflow with #GSORT, AP766, and AP765P.

This program finalizes the 1099 form printing process, producing IRS-compliant output for vendors.