Skip to content

AP791 RPG36

The provided document, AP791.rpg36.txt, is an RPG/36 program (used in IBM System/36 or AS/400 environments) called from the OCL program AP791.ocl36.txt. This program processes and prints a 1099 file for IRS reporting, handling data from the IRSTAX file, outputting to the PA1099 file, and generating a printed report. Below, I’ll explain the process steps, business rules, tables/files used, and external programs called.

Process Steps of the AP791 RPG Program

The RPG program follows a structured flow to read, process, and output 1099-related data. Here’s a breakdown of the process steps based on the RPG/36 code:

  1. File Definitions (Lines 0005-0006):
  2. Input File (IRSTAX): Defined as a primary input file (IP) with a record length of 750 bytes. It contains 1099 data, including transmitter "T" records and payee "B" records. Multiple commented-out definitions suggest possible variations (e.g., IRSTAXSOIS or a 864-byte version), but only the 750-byte IRSTAX is active.
  3. Output File (PA1099): Defined as an output file (O) with a record length of 875 bytes, used to store processed 1099 data.
  4. Printer File (PRINT): Defined as a printer output file (O) with a record length of 164 bytes, used to generate a formatted 1099 report.

  5. Input Specifications (Lines 0007-0122):

  6. The program reads records from IRSTAX and identifies them by a record type (A1REC) at position 1:
    • Transmitter "T" Record (Line 0007, NS 01): Identified by A1REC = 'T', processed differently from payee records.
    • Payee "B" Record (Line 0007, NS 02): Default record type for payee data, processed for 1099 reporting.
  7. Fields are mapped from the IRSTAX file, including:

    • Payment year (A1YR, positions 2-5)
    • Taxpayer ID number (A1TIN#, positions 12-20)
    • Type of TIN (A1TTIN, position 11, 1 for EIN, 2 for SSN)
    • Payment amounts (A1PAY1 to A1PAYC, positions 55-198, for various payment types)
    • Payee details (name, address, city, state, zip, etc.)
    • Tax withholding (A1SITW for state, A1LITW for local)
    • Other indicators (e.g., A1FCI for foreign country, A1DSI for direct sales).
  8. Calculation Specifications (Lines 0194-0206):

  9. Record Processing:
    • For "T" records (NS 01):
    • The program skips processing and jumps to the END tag (Line 0206), bypassing payee calculations.
    • For "B" records (NS 02):
    • Increments a record counter (REC#) and a count (COUNT) for tracking (Line 0194, 0199).
    • Accumulates non-zero payment amounts (A1PAY1, A1PAY2, A1PAY3, A1PAY7) into totals (TPAY1, TPAY2, TPAY3, TPAY7) and a combined total (DPAY) (Lines 0199-0200).
    • Checks the TIN type (A1TTIN = 1 for EIN or 2 for SSN) to set indicators 21 or 22 (Lines 0203-0204).
    • Writes the processed record to the PA1099 file via the IN exception output (Line 0205).
  10. Commented-Out Logic:

    • Some conditional checks (e.g., A1PYES IFNE 'PA') and additional accumulations (NPAY1, NPAY2, NPAY7) are commented out, suggesting they were used in prior versions or for specific cases (e.g., filtering by state or additional totals).
  11. Output Specifications (Lines 0207-0251):

  12. Printer Output (PRINT):
    • Header Records (Lines 0207-0231):
    • Prints headers for the report, including:
      • Company name (“AMERICAN REFINING GROUP, INC”).
      • Program name (“AP791”) and report title (“A/P 1099 FILE”).
      • Page number (PAGE) and date (UDATE).
      • Column headers for record number, TIN type, name control, SSN/EIN, payment amounts, name, address, city, state, and zip.
    • Headers are printed at the start of the report (1P) or on overflow (OF).
    • Detail Lines (Lines 0232-0251, E IN):
    • For each payee record, prints:
      • Record number (REC#).
      • TIN type (A1TTIN) and name control (A1NCTL).
      • Formatted TIN (A1ID21, A1ID22, etc., with hyphens for readability).
      • Payment amounts (A1PAY1M, A1PAY2M, A1PAY3M).
      • Payee details (name, address, city, state, zip).
    • Total Lines (Line 0232, E TOTL):
    • Prints accumulated totals for TPAY1, TPAY2, TPAY7 at the end of the report.
  13. File Output (PA1099) (Lines 0232-0251, EADD IN):

    • Writes records to the PA1099 file with:
    • Hard-coded values (e.g., 222318612 for payer TIN, 001 for sequence).
    • Payment year (A1YR), TIN (A1TIN#), vendor number (A1VEND), and payee details.
    • Payment amounts (A1PAY1, A1PAY2, A1PAY3, A1PAY7, A1SITW).
    • Company details (“AMERICAN REFINING GROUP, INC”, address, etc.).
    • Combined payment total (DPAY).
  14. End of Program:

  15. After processing all records, the program writes final totals to the printer (EXCPTTOTL) and terminates at the END tag (Line 0206).

Business Rules

The program enforces the following business rules for 1099 processing: 1. Record Type Handling: - Skips “T” (Transmitter) records, as they are not relevant for payee reporting. - Processes “B” (Payee) records for 1099 data.

  1. Payment Accumulation:
  2. Only non-zero payment amounts (A1PAY1, A1PAY2, A1PAY3, A1PAY7) are added to running totals (TPAY1, TPAY2, TPAY3, TPAY7) and a combined total (DPAY).
  3. These payments likely correspond to specific 1099 categories (e.g., non-employee compensation, rents, royalties).

  4. TIN Formatting:

  5. TINs are identified as EIN (A1TTIN = '1') or SSN (A1TTIN = '2') and formatted accordingly (e.g., XXX-XXXXXX for EIN, XXX-XX-XXXX for SSN) for the printed report.

  6. Payee Filtering:

  7. Commented-out logic suggests a prior rule to filter records where the state (A1PYES) is not “PA” (Pennsylvania), but this is not active in the current version.

  8. Output Formatting:

  9. The PA1099 file includes fixed payer details (e.g., TIN 222318612, address “77 NORTH KENDALL AVENUE, BRADFORD, PA 16701”) and payee-specific data.
  10. The printed report formats TINs with hyphens for readability and aligns payment amounts and payee details in columns.

  11. IRS Compliance:

  12. The program structures data in the PA1099 file to meet IRS 1099 reporting requirements, including payment amounts, withholding, and payee information (name, address, TIN).

Tables/Files Used

  1. IRSTAX:
  2. Type: Input (IP)
  3. Record Length: 750 bytes
  4. Description: Primary input file containing 1099 data, including transmitter (“T”) and payee (“B”) records. Fields include payment year, TIN, payment amounts, and payee details.

  5. PA1099:

  6. Type: Output (O)
  7. Record Length: 875 bytes
  8. Description: Output file storing processed 1099 data for IRS submission, including payer and payee details, payment amounts, and withholding.

  9. PRINT:

  10. Type: Printer Output (O)
  11. Record Length: 164 bytes
  12. Description: Printer file for generating a formatted 1099 report with headers, detail lines, and totals.

External Programs Called

  • None: The RPG program does not explicitly call any external programs. The GSY2K program referenced in the OCL program is executed before AP791 is loaded, so it is not called from within the RPG code.

Additional Notes

  • Commented-Out Code: The presence of commented-out definitions (e.g., IRSTAXSOIS, alternate IRSTAX lengths) and logic (e.g., state filtering, additional totals) suggests the program was adapted over time or supports multiple configurations. These could be re-enabled for specific requirements.
  • TIN Formatting: The program formats TINs differently for EIN and SSN, ensuring compliance with IRS reporting standards.
  • Hard-Coded Values: The PA1099 output includes fixed payer details (e.g., TIN 222318612, address), indicating the program is tailored for “AMERICAN REFINING GROUP, INC.”
  • Environment: The program is designed for the System/36 or AS/400, using RPG/36 syntax and OCL for job control.

If you need further details (e.g., specific field mappings, IRS 1099 form alignment, or analysis of commented-out logic), please let me know!