Skip to content

AP300 RPG

The provided RPG program, AP300.rpg36.txt, is an RPG II program designed for the IBM System/36 environment, called by the OCL script AP300.ocl36.txt. It performs the actual clearing of Month-to-Date (MTD) and Year-to-Date (YTD) totals in the Accounts Payable (A/P) vendor master file. This program is the final step in the A/P update process orchestrated by AP300P.ocl36.txt, AP300P.rpg36.txt, and AP300.ocl36.txt. Below, I’ll explain the process steps, business rules, tables (files) used, and external programs called, ensuring a concise and clear analysis that integrates with the previous documents.


Process Steps of the RPG Program

The AP300 program processes the sorted vendor records to clear MTD and optionally YTD totals in the vendor master file. Here’s a step-by-step breakdown:

  1. File and Data Definitions:
  2. Files:
    • APVEND: Vendor master file, defined as an update file (UP) with 579-byte records, indexed (I), used for reading and updating vendor records.
    • AP300S: Sorted input file, defined as an input file (IR) with 30-byte records, indexed with 3-byte keys (3IT), used to identify which vendor records to update.
  3. Input Specifications:
    • APVEND fields (packed decimal, P):
    • VN$YTD (6,2): YTD purchases (positions 195–200).
    • VN$LYR (6,2): Last year’s purchases (positions 201–206).
    • VNDMTD (4,2): MTD discounts (positions 207–210).
    • VNDYTD (5,2): YTD discounts (positions 211–215).
    • VNPBAL (5,2): Previous balance (positions 220–224).
    • VNPURC (5,2): MTD purchases (positions 225–229).
    • VNPAY (5,2): MTD payments (positions 230–234).
    • VNCBAL (5,2): Current balance (positions 235–239).
    • VNTYDP (6,2): This year’s YTD paid (positions 242–247).
    • VNLYDP (6,2): Last year’s YTD paid (positions 248–253).
    • UDS (Local Data Area):
    • KYYTDY (1 byte, position 135): Flag indicating whether to clear YTD totals ('Y' or blank).
  4. Indicators:

    • 05: Controls whether the program runs (set if KYYTDY ≠ 'Y').
    • 50: Set if YTD clearing is requested (KYYTDY = 'Y').
    • 01: Output indicator for updating APVEND records.
  5. Initialization and YTD Check (Lines 0026–0027):

  6. Checks if KYYTDY = 'Y' (from AP300P.rpg36.txt via the Local Data Area).
  7. If true, sets indicator 50 to control YTD field updates.
  8. If KYYTDY ≠ 'Y', sets indicator 05 to ensure the program processes MTD updates (line 0027).

  9. MTD Field Updates (Lines 0029–0032):

  10. For each vendor record processed:
    • Clears VNDMTD (MTD discounts) to 0 (Z-ADD0).
    • Sets VNPBAL (previous balance) to the value of VNCBAL (current balance), preserving the balance before clearing MTD fields.
    • Clears VNPURC (MTD purchases) to 0.
    • Clears VNPAY (MTD payments) to 0.
  11. These updates apply to all records processed, regardless of KYYTDY.

  12. YTD Field Updates (Lines 0034–0038):

  13. If indicator 50 is on (KYYTDY = 'Y'):

    • Moves VN$YTD (YTD purchases) to VN$LYR (last year’s purchases), preserving YTD data before clearing.
    • Clears VNDYTD (YTD discounts) to 0.
    • Clears VN$YTD (YTD purchases) to 0.
    • Moves VNTYDP (this year’s YTD paid) to VNLYDP (last year’s YTD paid), preserving payment data.
    • Clears VNTYDP (this year’s YTD paid) to 0.
  14. Output to Vendor File (Lines 0040–0049):

  15. Updates the APVEND file for each processed record (indicator 01):
    • If indicator 50 is on, updates:
    • VN$YTD (YTD purchases).
    • VN$LYR (last year’s purchases).
    • VNDYTD (YTD discounts).
    • VNTYDP (this year’s YTD paid).
    • VNLYDP (last year’s YTD paid).
    • Updates MTD fields for all records:
    • VNDMTD (MTD discounts).
    • VNPBAL (previous balance).
    • VNPURC (MTD purchases).
    • VNPAY (MTD payments).
  16. The updates are written to the APVEND file, modifying the vendor records.

  17. Program Flow:

  18. The program processes records from AP300S (sorted by company and vendor, as prepared by #GSORT in AP300.ocl36.txt).
  19. For each record in AP300S, it locates the corresponding record in APVEND (via indexing) and applies the MTD and optional YTD updates.
  20. The program relies on the AP300S file to determine which vendors to update, based on the company selection (KYALCO, KYCO1, KYCO2, KYCO3) from AP300P.rpg36.txt.

Business Rules

The program enforces the following business rules for clearing MTD and YTD totals:

  1. MTD Clearing:
  2. Always clears MTD fields for all processed records:
    • VNDMTD (MTD discounts) set to 0.
    • VNPURC (MTD purchases) set to 0.
    • VNPAY (MTD payments) set to 0.
  3. Preserves the current balance by moving VNCBAL to VNPBAL before clearing MTD fields.

  4. YTD Clearing:

  5. Clears YTD fields only if KYYTDY = 'Y' (controlled by indicator 50):
    • Moves VN$YTD (YTD purchases) to VN$LYR (last year’s purchases).
    • Clears VN$YTD and VNDYTD (YTD discounts) to 0.
    • Moves VNTYDP (this year’s YTD paid) to VNLYDP (last year’s YTD paid).
    • Clears VNTYDP to 0.
  6. Preserves YTD data in last-year fields (VN$LYR, VNLYDP) for historical reference or auditing.

  7. Record Selection:

  8. Processes only records included in the sorted AP300S file, which filters vendors by:

    • Company selection (ALL or specific companies KYCO1, KYCO2, KYCO3) from AP300P.
    • Non-deleted status (NECD ≠ 'D') from AP300.ocl36.txt.
  9. Data Integrity:

  10. Ensures the current balance (VNCBAL) is not modified, maintaining financial accuracy.
  11. Preserves YTD data in last-year fields when clearing YTD totals, supporting audit and 1099 requirements.

  12. Dependencies:

  13. Relies on AP300P.rpg36.txt to validate user input (KYYTDY, company selections).
  14. Relies on AP300.ocl36.txt to sort APVEND into AP300S and handle backups for 1099 processing.

Tables (Files) Used

The program uses the following files:

  1. APVEND:
  2. Type: Disk file (update, UP).
  3. Purpose: Vendor master file containing financial data (MTD/YTD totals), updated by the program.
  4. Record Length: 579 bytes, indexed (I).
  5. Fields Updated:
    • VN$YTD, VN$LYR, VNDMTD, VNDYTD, VNPBAL, VNPURC, VNPAY, VNTYDP, VNLYDP.
  6. Label: ?9?APVEND (e.g., PRODAPVEND).

  7. AP300S:

  8. Type: Disk file (input, IR).
  9. Purpose: Sorted temporary file containing vendor records to be updated, filtered by company and non-deleted status.
  10. Record Length: 30 bytes, indexed with 3-byte keys (likely company and vendor numbers).
  11. Label: ?9?AP300S.

External Programs Called

The RPG program does not directly call any external programs (e.g., via CALL operations). It is executed by the AP300.ocl36.txt script and relies on:

  1. #GSORT (from AP300.ocl36.txt):
  2. Prepares the AP300S file by sorting APVEND based on company and vendor fields.
  3. Not called directly by AP300.rpg36.txt but critical to its input.

  4. AP300P.rpg36.txt (indirectly):

  5. Provides validated parameters (KYYTDY, KYALCO, KYCO1, etc.) via the Local Data Area, set before AP300 runs.

No other programs are called within the RPG code.


Summary

Process Overview: - AP300.rpg36.txt clears MTD and optionally YTD totals in the APVEND vendor master file. - Processes records from the sorted AP300S file, updating: - MTD fields (VNDMTD, VNPURC, VNPAY) to 0, with VNPBAL set to VNCBAL. - YTD fields (VN$YTD, VNDYTD, VNTYDP) to 0 if KYYTDY = 'Y', moving current YTD values to last-year fields (VN$LYR, VNLYDP). - Updates are written back to APVEND for each processed record.

Business Rules: - Always clears MTD fields, preserving the current balance. - Clears YTD fields only if KYYTDY = 'Y', preserving YTD data in last-year fields. - Processes only records from AP300S, filtered by company and non-deleted status. - Maintains data integrity for financial accuracy and auditing.

Tables Used: - APVEND: Vendor master file (updated). - AP300S: Sorted temporary file (input).

External Programs: - None called directly; relies on #GSORT (via AP300.ocl36.txt) and AP300P.rpg36.txt (for parameters).

This program completes the A/P update process by performing the actual data modifications, integrating with the validation from AP300P.rpg36.txt and file management from AP300.ocl36.txt. If you need further details (e.g., file record layouts or additional context), please provide more information!