Skip to content

AP210 RPG

The AP210.rpg36.txt file is an RPG III program (AP210) called within the AP200.ocl36.txt OCL procedure to post Accounts Payable (A/P) invoices to inventory receipt records. Below, I provide a detailed explanation of its process steps, business rules, tables/files used, and external programs called, along with its purpose in the context of the AP200 OCL procedure.


Purpose in AP200 OCL

The AP210 program is responsible for updating inventory receipt records (INFIL1 or INTZH1) with A/P invoice data from the transaction file (APTRAN). It matches A/P invoices to inventory receipts based on receipt numbers, updates quantities, amounts, and status, and logs the activity in a printer output file (APLIST). In the AP200 OCL procedure, AP210 is called after the main Purchase Journal processing to ensure A/P invoices are reflected in inventory records, which is critical for tracking costs and quantities associated with inventory receipts.


Process Steps

  1. Initialization:
  2. Date and Century Handling:
    • Retrieves journal date (JRDATE) from the User Data Structure (UDS).
    • Converts JRDATE to JRYMD (YYYYMMDD) by multiplying by 10000.01.
    • Extracts year (JYR) and compares it to Y2KCMP (80, from UDS):
    • If JYR >= 80, sets century (JCN) to Y2KCEN (19).
    • Otherwise, adds 1 to Y2KCEN (e.g., 19 + 1 = 20).
    • Combines century and JRYMD into JRYM8 (century + YYYYMMDD).
  3. Variable Setup:
    • Clears indicators 20, 90, 91, 92 and sets zero fields (ZERO2, ZERO4, ZERO6, ZERO8) to 0.
    • Sets ONCE to 1 to ensure date processing occurs only once.
  4. Amount Setup:

    • Moves APGRAM (gross amount from APTRAN) to APAMT (working amount field).
  5. Skip Deleted or Sales Order Records:

  6. Checks if ATSORN (sales order number) is zero (IFEQ *ZERO):
    • If non-zero, skips to END (bypasses posting for sales order-related invoices, per JB01 revision).
  7. Checks if header (APHDEL) or detail (APDDEL) delete flags are not 'D':

    • If either is deleted, skips to END.
  8. Process A/P Invoice:

  9. Determine Processing Type:
    • If indicator 20 is off (N20), calls NORMAL subroutine (standard invoice processing).
    • If indicator 20 is on, calls FREIGH subroutine (freight invoice processing, which sets indicator 11 and calls NORMAL).
  10. Receipt Key:
    • Builds RCTKEY (9 bytes) by combining APCONO (company number, 3 bytes) and APREC# (receipt number, 6 bytes).
  11. Log to Printer:

    • Writes detail record to APLIST (EXCPTDTL) with invoice details (company, vendor, invoice number, date, G/L, receipt, gallons, amount, status).
  12. NORMAL Subroutine:

  13. Match Receipt (Exact Match):

    • Sets lower limit (SETLL) on INFIL1 and INTZH1 using RCTKEY.
    • Reads INFIL1 (indicator 76) until end-of-file (90) or match.
    • If end-of-file on INFIL1, switches to INTZH1 (indicator 77) and reads.
    • If a match is found (N90):
    • Calculates remaining quantity (RNQTY = IHNQTY + IHNQTF - IHAPTQ - IHAPTF).
    • If APGAL (A/P gallons) equals RNQTY, updates the record:
      • Adds APAMT to IHAPTD (total dollars).
      • Adds APGAL to IHAPTQ (total quantity).
      • Sets IHCLCD (status) to 'O' (open) or 'C' (closed) based on APCLCD.
      • Updates IHCLDT (closed date, YMD) and IHCLD8 (closed date, CYMD) with JRYMD and JRYM8.
      • Updates APINVN (invoice number) and IHPONO (PO number).
      • Writes update to INFIL1 or INTZH1 (EXCPTUPDRCP).
      • Logs to APLIST (EXCPTDT01).
      • Clears APAMT and APGAL.
  14. Match Receipt (Partial Match):

    • If no exact match, re-reads INFIL1 and INTZH1 to find a record with more gallons than APGAL.
    • If found (N90 and APGAL < RNQTY):
    • Updates IHAPTD, IHAPTQ, IHCLCD, IHCLDT, IHCLD8, APINVN, and IHPONO as above.
    • Writes update (EXCPTUPDRCP).
    • Logs to APLIST (EXCPTDT02).
    • Clears APAMT and APGAL.
  15. No Match, Update First Record:

    • If no match and APGAL is non-zero, reads first record from INFIL1 or INTZH1.
    • Updates IHAPTD, IHAPTQ, IHCLCD, IHCLDT, IHCLD8, APINVN, and IHPONO.
    • Writes update (EXCPTUPDRCP).
    • Logs to APLIST (EXCPTDT03).
    • Clears APAMT and APGAL.
  16. FREIGH Subroutine:

  17. Sets indicator 11 to flag freight processing.
  18. Calls NORMAL subroutine to process freight invoices similarly to standard invoices.
  19. Clears indicator 11.

  20. End Processing:

  21. Continues reading APTRAN records until end-of-file.
  22. Closes files and terminates.

Business Rules

  1. Skip Sales Orders (JB01, 07/08/10):
  2. Bypasses posting if ATSORN (sales order number) is non-zero, as sales order invoices are not posted to inventory receipts.
  3. Skip Deleted Records:
  4. Skips records where APHDEL or APDDEL is 'D' (deleted).
  5. Dual File Support (JB02, 09/18/14):
  6. Checks both INFIL1 (inventory file) and INTZH1 (holding file) for receipt matches, switching if no match is found in INFIL1.
  7. Quantity Matching:
  8. Matches A/P gallons (APGAL) to remaining receipt quantity (IHNQTY + IHNQTF - IHAPTQ - IHAPTF).
  9. Updates the first record with sufficient gallons or the first available record if no match.
  10. Status Update:
  11. Sets IHCLCD to 'O' (open) or 'C' (closed) based on APCLCD.
  12. Updates closed dates (IHCLDT, IHCLD8) with journal date.
  13. Freight Invoices:
  14. Processes freight invoices separately but uses the same NORMAL logic (indicator 11 flags freight).
  15. Printer Logging (JB03, 09/18/14):
  16. Logs all updates to APLIST for debugging and verification, with distinct exception records (DTL, DT01, DT02, DT03).
  17. Y2K Compliance:
  18. Handles dates using Y2KCEN (19) and Y2KCMP (80) to determine 19xx or 20xx century.
  19. Field Updates (MG04, 09/15/15):
  20. Supports expanded INFIL1 (448 bytes) and APINVN (20 bytes).
  21. Includes PO number (IHPONO) from the purchase order system.

Tables/Files Used

  • Input:
  • APTRAN (Primary Input, IP):
    • A/P transaction file.
    • Fields: APHDEL (header delete flag), APCONO (company), APVEND (vendor), ATCNVO (canceled voucher), APINVD (invoice date), ATSORN (sales order number), ATSSRN (sales sequence number), APINVN (invoice number), APIN10 (short invoice number), APDDEL (detail delete flag), APREC# (receipt number), APGAL (gallons), APGL (G/L number), APGRAM (gross amount), APCLCD (open/closed status).
  • INFIL1 (Update/Input, UF):
    • Inventory file (448 bytes).
    • Fields: IHNQTY (net quantity), IHNQTF (net quantity fraction), IHUNMS (unit of measure), IHAPID (last invoice date), IHAPLE (last expense G/L), IHAPLP (last purchase journal), IHAPTQ (total quantity), IHAPTF (total quantity fraction), IHAPTD (total dollars), IHCLCD (open/closed status), IHCLDT (closed date, YMD), IHCLD8 (closed date, CYMD), IHAPI# (last invoice number), IHPONO (PO number).
  • INTZH1 (Update/Input, UF):
    • Inventory transaction holding file (592 bytes).
    • Fields: Same as INFIL1 but with different positions (e.g., IHAPTD at 171-179, IHCLCD at 170).
  • Output:
  • INFIL1 (Update, E 76 UPDRCP):
    • Updates inventory receipt records with A/P data.
  • INTZH1 (Update, E 77 UPDRCP):
    • Updates holding file records with A/P data.
  • APLIST (Printer, O):
    • Printer output file for logging (164 bytes).
    • Logs invoice details (DTL) and update details (DT01, DT02, DT03) with fields like company, vendor, invoice number, date, G/L, receipt, gallons, amount, status, and journal data.

External Programs Called

  • None:
  • The AP210 program does not call external programs. It relies on internal subroutines (NORMAL, FREIGH) for processing.

Role in AP200 OCL

In the AP200 OCL procedure, AP210 is called after the main Purchase Journal processing (AP200) and journal summarization (AP205) to: - Post A/P invoice data (amounts, quantities, invoice numbers, PO numbers) to inventory receipt records in INFIL1 or INTZH1. - Ensure inventory records reflect A/P costs and quantities, maintaining alignment between financial and inventory systems. - Log updates to APLIST for verification, especially useful for debugging (per JB03). - Support freight invoices and bypass sales order-related invoices, ensuring accurate inventory cost tracking.

This step is critical for integrating A/P transactions with inventory management, ensuring that receipt records are updated with financial data for accurate cost tracking and reporting.


Key Notes

  • Revisions:
  • JB01 (07/08/10): Bypasses sales order invoices.
  • JB02 (09/18/14): Adds support for INTZH1 (holding file).
  • JB03 (09/18/14): Adds APLIST for logging.
  • MG04 (09/15/15): Expands INFIL1 and adds invoice number (APINVN) and PO number (IHPONO).
  • File Switching:
  • Dynamically switches between INFIL1 and INTZH1 if no match is found, ensuring flexibility in receipt processing.
  • Error Handling:
  • Skips deleted records and non-inventory invoices (e.g., sales orders).
  • Logs all updates for traceability.
  • Quantity Logic:
  • Matches A/P gallons to receipt quantities, updating the first suitable record if no exact match is found.

If you need further details on specific fields, logic, or integration with other OCL steps, let me know!