Skip to content

AP251 RPG

The provided RPG program, AP251.rpg36.txt, is executed by the OCL program AP251.ocl36.txt, which itself is called from the main OCL program AP250.ocl36.txt within an IBM System/36 or AS/400 Accounts Payable (A/P) system. The purpose of AP251 is to update a commission table (APTORCY) with payment information from the payment file (APPAY). Below, I will explain the process steps, business rules, tables (files) used, and external programs called based on the RPG code.


Process Steps of the AP251 RPG Program

The AP251 RPG program processes payment records from the APPAY file and updates corresponding records in the APTORCY commission table. Here is a detailed breakdown of the process steps:

  1. Initialization (ONETIM Subroutine):
  2. The program starts by checking indicator 09. If 09 is off (N09), it executes the ONETIM subroutine:

    • Retrieves the current system date and time using the TIME operation, storing it in TIMDAT (12 digits).
    • Extracts the time portion into TIME (6 digits) and the date portion into DATE (6 digits).
    • Converts the date to a year-month-day format (DATYMD) by multiplying DATE by 10000.01 to adjust for century handling.
    • Sets the century prefix (20 for 2000s) into DATE8 (8-digit date field, e.g., 20YYMMDD).
    • Moves DATYMD into DATE8 for consistent date formatting.
    • Sets indicator 09 on to prevent re-execution of ONETIM.
  3. Main Processing Loop (EACH01 Subroutine):

  4. For each record in the APPAY file (processed with indicator 01), the EACH01 subroutine is executed:

    • Builds a key (KEY27, 27 characters) for chaining to the APTORCY file:
    • Copies the company number (CONO, positions 2-3) into the first part of KEY27.
    • Copies the vendor number (VEND, positions 4-8) into KEY25.
    • Copies the invoice description (OPIN20, positions 35-54) into KEY20.
    • Combines KEY20 and KEY25 into KEY27 for the full key.
    • Chains to the APTORCY file using KEY27 to locate the corresponding commission record.
    • If a matching record is found (N99, i.e., not indicator 99 set):
    • Converts the check date (AXCKDT) to an 8-digit format (AXYMD8, e.g., 20YYMMDD) by multiplying by 10000.01 and prefixing with the century (20).
    • Stores the gross amount (OPGRAM) in a temporary field (AMT92, 9.2 format).
    • Writes an exception record to APTORCY using the UPDATE exception (see Output Specification below).
    • If no matching record is found (99 set), the record is skipped.
  5. Update Commission Table:

  6. The UPDATE exception in the Output Specification (OAPTORCY E UPDATE) updates the APTORCY file with:

    • Invoice number (OPINV#, positions 207-226 from APPAY) to ATINV (positions 84-103).
    • Gross amount (AMT92, derived from OPGRAM) to ATAPMT (positions 104-108, packed).
    • Status (ATSTAT) set to 'P' (paid, position 109).
    • Check number (ATCHK#, positions 110-115, likely populated from OPCKNO in APPAY).
  7. Completion:

  8. The program processes all APPAY records sequentially, updating matching APTORCY records.
  9. Once all records are processed, the program terminates, and control returns to the calling OCL program (AP251.ocl36.txt).

Business Rules

The RPG program enforces the following business rules based on its logic and context within the A/P system:

  1. Commission Record Matching:
  2. Matches payment records from APPAY to commission records in APTORCY using a composite key (KEY27) built from:
    • Company number (CONO).
    • Vendor number (VEND).
    • Invoice description (OPIN20, likely a truncated or formatted invoice number).
  3. Only updates APTORCY records that match the key; unmatched records are skipped.

  4. Payment Status Update:

  5. Sets the commission record status (ATSTAT) to 'P' (paid) when a payment is applied.
  6. Records the payment amount (OPGRAM from APPAY) in ATAPMT and the check number (OPCKNO) in ATCHK#.
  7. Includes the invoice number (OPINV#) to link the payment to the commission record.

  8. Date Handling:

  9. Uses century-aware date processing (prefixes 20 for 2000s) to format the check date (AXCKDT) into AXYMD8 for consistency.
  10. Relies on Y2KCEN (century field, set to 19 or 20) from the User Data Structure (UDS) for date calculations.

  11. File Access:

  12. APPAY is processed sequentially as the primary input file (IP), ensuring all payment records are read.
  13. APTORCY is a keyed update file (UF, EXTK for external key), allowing random access and updates based on the composite key.

  14. No Error Output:

  15. The program does not generate error reports or logs for unmatched records (99 set). It silently skips them, assuming they are not relevant to the commission table.

  16. Integration with A/P Process:

  17. The program assumes APPAY contains valid payment data from the A/P check register process (AP250).
  18. Updates to APTORCY are part of the broader A/P workflow, ensuring commission records reflect payments made to vendors or agents.

Tables (Files) Used

The program uses the following files, as defined in the File Specification (F-spec) section:

  1. APPAY (IP, 384 bytes, keyed, DISK):
  2. Primary input file, temporary payment file created by the main OCL program (AP250.ocl36.txt).
  3. Contains payment details, including:

    • CONO: Company number (positions 2-3).
    • VEND: Vendor number (positions 4-8).
    • OPGRAM: Gross amount (packed, positions 18-23).
    • OPDISC: Discount (packed, positions 24-28).
    • OPPPTD: Partial paid to date (packed, positions 29-34).
    • OPCKNO: Check number (positions 91-96).
    • OPPAID: Payment status (position 97, e.g., 'P' for prepaid).
    • OPLPAM: This payment amount (packed, positions 161-166).
    • OPDSTK: Discount already taken (packed, positions 167-171).
    • OPSORN: Sales order number (positions 281-286).
    • OPINV#: Invoice number (positions 207-226).
    • OPIN20: Invoice description (positions 35-54).
    • AXCKDT: Check date (positions 434-439, from UDS).
  4. APTORCY (UF, 211 bytes, keyed, EXTK, DISK):

  5. Update file, commission master file.
  6. Contains commission-related data, including:

    • ATDEL: Deletion flag (position 1).
    • ATCO: Company number (positions 2-3).
    • ATCUST: Customer number (positions 4-9).
    • ATORD#: Order number (positions 10-15).
    • ATSRN#: Serial number (positions 16-18).
    • ATINV#: Invoice number (positions 19-25).
    • ATIVAM: Invoice amount (packed, positions 26-30).
    • ATINV8: Invoice date (positions 31-38).
    • ATSHD8: Shipping date (positions 39-46).
    • ATPROD: Product code (positions 47-50).
    • ATUM: Unit of measure (positions 51-53).
    • ATAMT: Amount (packed, positions 54-56).
    • ATPCT: Percentage (packed, positions 57-58).
    • ATVEND: Vendor number (positions 59-63).
    • ATHAND: Handling code (positions 64-83).
    • ATINV: Invoice number (positions 84-103, updated).
    • ATAPMT: Payment amount (packed, positions 104-108, updated).
    • ATSTAT: Status (position 109, updated to 'P').
    • ATCHK#: Check number (positions 110-115, updated).
  7. UDS (User Data Structure):

  8. Provides additional fields, including:
    • AXCKDT: Check date (positions 434-439).
    • Y2KCEN: Century indicator (positions 509-510, e.g., 19 or 20).
    • Y2KCMP: Company-related century field (positions 511-512).

External Programs Called

The AP251 RPG program does not call any external programs. It is self-contained, using two subroutines (ONETIM for initialization and EACH01 for processing) to handle all logic. The program is invoked by the AP251.ocl36.txt OCL script, which loads and runs it as part of the A/P process.


Summary

The AP251 RPG program is a focused component of the A/P system, designed to update the commission table (APTORCY) with payment data from the APPAY file. Its key functions are:

  • Process Steps:
  • Initializes date and time fields (ONETIM subroutine).
  • Processes each APPAY record, matches it to APTORCY using a composite key (company, vendor, invoice description), and updates commission records with payment details (invoice number, amount, status, check number).
  • Writes updated records to APTORCY.

  • Business Rules:

  • Matches payments to commission records using company number, vendor number, and invoice description.
  • Updates commission records with payment status ('P'), amount, and check number.
  • Handles century-aware date formatting for check dates.
  • Skips unmatched records without generating errors.
  • Operates in a shared access environment for concurrent processing.

  • Tables Used:

  • APPAY: Temporary payment file (input).
  • APTORCY: Commission master file (update).
  • UDS: User Data Structure for date and century fields.

  • External Programs Called: None.

The program integrates with the broader A/P process by processing payment data generated by AP250 and updating the commission table to reflect payments made to vendors or agents. If you have additional details (e.g., the structure of APTORCY or specific commission logic), I can provide further analysis. Please let me know if you need clarification or more details!