Skip to content

AP765N RPG36

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

The RPG III program AP765N.rpg36.txt is designed to print vendor 1099-NEC (Non-Employee Compensation) forms on an IBM System/36 or AS/400 system. It is called by the OCL program AP765N.ocl36.txt when ?L'110,1'? is set to N in the main OCL (AP765P.ocl36.txt), indicating a focus on 1099-NEC forms. This program is similar to AP765.rpg36.txt (used for 1099-MISC forms) but has modifications to handle three forms per page instead of two, reflecting differences in form layout or printing requirements for 1099-NEC. 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 (AP765N) and parameter P016, likely a control parameter passed from the OCL.
  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 from AP766.rpg36.txt.
    • Line 0009: AP1099 (Output, 80 bytes, Printer): The printer file used to output 1099-NEC 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., 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. Indicator Reset:
    • Line C*: Set indicator 33 off (disabling 1099-MISC logic, as this program is for 1099-NEC).
  8. 1099 Type Check:
    • Lines C*: If VN1099 is N, set indicator 34 on (for 1099-NEC).
    • The commented-out logic for VN1099 = 'M' (1099-MISC) indicates this program is exclusively for 1099-NEC.
  9. Vendor Number Check:

    • Lines C*: If VNVEND equals 32800, set YES to 'YES' (3 chars). This likely flags a specific vendor for special handling, though its purpose is unclear (different from 9384 in AP765).
  10. Amount Validation:

  11. Line 0034: Add L1AMT1 and L1AMT2 to compute TOTAMT (9,2 numeric), the total vendor payment.
  12. Line 0035: Compare TOTAMT with ENTAMT (threshold amount from UDS). Set indicator 30 if TOTAMT is greater than or equal to ENTAMT.
  13. 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).

  14. Form Counter Logic:

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

    • If COUNTP is 2, increment to 3, set indicator 40 on (third form), set 32 off, and jump to SKIP.
    • If COUNTP is zero, set it to 1, set 31 on (first form), set 32 and 40 off.
    • Otherwise, increment COUNTP, set 31 and 40 off, set 32 on (second form).
    • This supports printing three forms per page, a key difference from AP765 (which prints two forms per page, revision MG03).
  16. Clear Work Fields:

  17. Lines JB01: For each form (indicators 31, 32, 40):

    • Clear fields for payee names (PYN11, PYN12, PYN13, PYN21, PYN22, PYN23), tax IDs (VNID#1, VNID#2, VNID#3), state amounts (STATE1, STATE2, STATE3), state IDs (STATI1, STATI2, STATI3), vendor numbers (VNVEN1, VNVEN2, VNVEN3), addresses (ADDR11, ADDR12, ADDR13, ADDR21, ADDR22, ADDR23, CTSTZ1, CTSTZ2, CTSTZ3), and amounts (AMT11, AMT12, AMT13, AMT31, AMT32, AMT33, AMT61, AMT62, AMT63, AMT71, AMT72, AMT73).
    • Reset indicators 71, 72, 73, 35, 36, 37 to control name and address printing.
  18. Payee and Address Processing (First Form, Indicator 31):

  19. 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.
  20. 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.
  21. Lines 0045-0069 (non-overflow case, N35): Similar address assignment without overflow logic.

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

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

  24. Payee and Address Processing (Third Form, Indicator 40):

  25. Identical logic to the first form, but for fields PYN13, PYN23, VNAD13, CTSTZ3, with indicators 37 and 73, jumping to CONT3 tag.

  26. Address Processing (Non-Overflow, CONT3, CONT4, CONT5):

  27. Lines 0045-0069: For each form (31N35, 32N36, 40N37), assign address fields similarly to ensure proper formatting when no name overflow occurs, jumping to CONT3, CONT4, or CONT5 tags.

  28. Amount Assignment for Printing:

    • Lines 0071-0094: Assign amounts to specific 1099 box fields based on BOX1 and BOX2 for each form (31, 32, 40):
    • For BOX1:
      • If 1, set AMT11/AMT12/AMT13 to L1AMT1 (box 1 for 1099-NEC).
      • If 3, set AMT31/AMT32/AMT33 to L1AMT1 (box 3, possibly for other forms).
      • If 6, set AMT61/AMT62/AMT63 to L1AMT1 (box 6, possibly for other forms).
      • If 7, set AMT71/AMT72/AMT73 to L1AMT1 (box 7, standard for 1099-NEC Non-Employee Compensation).
    • For BOX2:
      • If 1, set AMT11/AMT12/AMT13 to L1AMT2.
      • If 3, set AMT31/AMT32/AMT33 to L1AMT2.
      • If 6, set AMT61/AMT62/AMT63 to L1AMT2.
      • If 7, set AMT71/AMT72/AMT73 to L1AMT2.
  29. Accumulate Totals:

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

    • Lines C*: If COUNTP equals 3 (all three forms on the page filled):
    • Reset COUNTP to zero, set indicators 31, 32, 40 on, and execute an EXCPT to print the page.
    • At end of file (LR on):
    • If data remains for the first form (31 on), set indicator 30 on, clear TEST (11 chars), and execute EXCPT to print a final page with one vendor.
    • Unlike AP765, this program does not compute a grand total (LRAMT) across all boxes, focusing only on individual box totals.
  31. 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), amounts (AMT11, AMT31, AMT61, AMT71), and vendor number (VNVEN1, revision JB02).
      • Conditional on 34 (1099-NEC) for primary amount (AMT11) and N34 for other boxes (AMT31).
    • Second Form (Indicator 32):
      • Similar fields for the second form, using PYN12, PYN22, VNAD12, CTSTZ2, AMT12, AMT32, AMT62, AMT72, VNID#2, VNVEN2.
    • Third Form (Indicator 40):
      • Similar fields for the third form, using PYN13, PYN23, VNAD13, CTSTZ3, AMT13, AMT33, AMT63, AMT73, VNID#3, VNVEN3.
    • Totals (LR):
      • Print HEAD1-3, ID#, totals (LRAMT1, LRAMT6, LRAMT7), and vendor count (COUNT). Notably, LRAMT3 is printed but not accumulated for 40, indicating a possible oversight or specific requirement.

Business Rules

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

  3. Three Forms per Page:

  4. The program prints three 1099-NEC forms per page on laser paper (revision MG03, modified for three forms), managed by COUNTP and indicators 31, 32, 40.
  5. If fewer than three vendors remain at the end, a final page with one or two vendors 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/CTSTZ3) 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, with a focus on box 7 for 1099-NEC Non-Employee Compensation (revision MG04 supports multiple form types).

  13. 1099 Type:

  14. Indicator 34 is set for VN1099 = 'N' (1099-NEC). The commented-out logic for M (1099-MISC) ensures this program is dedicated to 1099-NEC.

  15. Totals:

  16. Accumulate totals for boxes 1, 3, 6, and 7 (LRAMT1, LRAMT3, LRAMT6, LRAMT7) and vendor count (COUNT). Unlike AP765, no grand total (LRAMT) is computed.

  17. Vendor Number as Account Number:

  18. Print VNVEND as the account number (VNVEN1/VNVEN2/VNVEN3, revision JB02).

Comparison with AP765.rpg36.txt

  • Similarity:
  • Both programs read AP766, validate amounts against ENTAMT, handle payee names and addresses, assign amounts to boxes 1, 3, 6, or 7, and print to AP1099.
  • Both support revisions JB01 (payee names), JB02 (name overflow, vendor number as account), MG03 (laser paper), and MG04 (multiple form types).
  • Differences:
  • Forms per Page: AP765 prints two forms per page (COUNTP up to 2, indicators 31/32), while AP765N prints three forms per page (COUNTP up to 3, indicators 31/32/40).
  • 1099 Type: AP765 handles both 1099-MISC (VN1099 = 'M', indicator 33) and 1099-NEC (VN1099 = 'N', indicator 34), while AP765N is dedicated to 1099-NEC (VN1099 = 'N', indicator 34 only).
  • Vendor Number Check: AP765 checks for VNVEND = 9384, while AP765N checks for VNVEND = 32800.
  • Totals: AP765 computes a grand total (LRAMT), while AP765N does not, though it prints LRAMT3 in the totals section without accumulating it for 40.
  • Output Lines: AP765N has fewer active output lines for amounts (e.g., AMT61, AMT71 are commented out), focusing on 1099-NEC fields.

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-NEC forms with form type 1099, 10 CPI, 6 LPI, three 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 AP765N. It is invoked by AP765N.ocl36.txt and processes data from AP766.rpg36.txt, with input prepared by #GSORT and AP766.

Outputs

  1. AP1099 Printer File:
  2. Prints 1099-NEC forms (three per page) with:
    • Company headers (HEAD1, HEAD2, HEAD3).
    • Year (CNYEAR).
    • Company Tax ID (ID#) and vendor Tax ID (VNID#1/VNID#2/VNID#3).
    • Payee names (PYN11/PYN12/PYN13, PYN21/PYN22/PYN23) or vendor name (VNNAME).
    • Addresses (VNAD11/VNAD12/VNAD13, VNAD21/VNAD22/VNAD23, CTSTZ1/CTSTZ2/CTSTZ3).
    • Amounts for boxes 1, 3, 6, or 7 (AMT11/AMT12/AMT13, AMT31/AMT32/AMT33, AMT61/AMT62/AMT63, AMT71/AMT72/AMT73), primarily box 7 for 1099-NEC.
    • Vendor number as account number (VNVEN1/VNVEN2/VNVEN3, revision JB02).
  3. Final page includes totals (LRAMT1, LRAMT6, LRAMT7, LRAMT3 for 31/32 only) and vendor count (COUNT).

Summary

  • Purpose: The RPG program AP765N prints 1099-NEC forms, formatting three forms per page on laser paper, using preprocessed vendor data from AP766.
  • Process:
  • Reads AP766 and validates vendor amounts against ENTAMT.
  • Manages three forms per page with COUNTP and indicators 31/32/40.
  • Assigns payee names, addresses, and amounts to appropriate fields, focusing on 1099-NEC.
  • Prints forms with company and vendor details, amounts, and totals.
  • Business Rules:
  • Prints only vendors meeting the amount threshold.
  • Supports three forms per page and 1099-NEC exclusively.
  • Handles payee names, name overflow, and vendor number as account number.
  • Accumulates totals for boxes 1, 3, 6, and 7, but not a grand total.
  • Files Used:
  • Input: AP766 (preprocessed vendor data).
  • Output: AP1099 (printer file for 1099-NEC forms).
  • External Programs: None called directly; part of a workflow with #GSORT, AP766, and AP765N.ocl36.txt.

This program is tailored for 1099-NEC forms, differing from AP765 by supporting three forms per page and focusing exclusively on Non-Employee Compensation, ensuring IRS-compliant output for vendors.