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¶
- Initialization:
- Date and Century Handling:
- Retrieves journal date (
JRDATE) from the User Data Structure (UDS). - Converts
JRDATEtoJRYMD(YYYYMMDD) by multiplying by 10000.01. - Extracts year (
JYR) and compares it toY2KCMP(80, fromUDS): - If
JYR >= 80, sets century (JCN) toY2KCEN(19). - Otherwise, adds 1 to
Y2KCEN(e.g., 19 + 1 = 20). - Combines century and
JRYMDintoJRYM8(century + YYYYMMDD).
- Retrieves journal date (
- Variable Setup:
- Clears indicators
20,90,91,92and sets zero fields (ZERO2,ZERO4,ZERO6,ZERO8) to 0. - Sets
ONCEto 1 to ensure date processing occurs only once.
- Clears indicators
-
Amount Setup:
- Moves
APGRAM(gross amount fromAPTRAN) toAPAMT(working amount field).
- Moves
-
Skip Deleted or Sales Order Records:
- Checks if
ATSORN(sales order number) is zero (IFEQ *ZERO):- If non-zero, skips to
END(bypasses posting for sales order-related invoices, perJB01revision).
- If non-zero, skips to
-
Checks if header (
APHDEL) or detail (APDDEL) delete flags are not'D':- If either is deleted, skips to
END.
- If either is deleted, skips to
-
Process A/P Invoice:
- Determine Processing Type:
- If indicator
20is off (N20), callsNORMALsubroutine (standard invoice processing). - If indicator
20is on, callsFREIGHsubroutine (freight invoice processing, which sets indicator11and callsNORMAL).
- If indicator
- Receipt Key:
- Builds
RCTKEY(9 bytes) by combiningAPCONO(company number, 3 bytes) andAPREC#(receipt number, 6 bytes).
- Builds
-
Log to Printer:
- Writes detail record to
APLIST(EXCPTDTL) with invoice details (company, vendor, invoice number, date, G/L, receipt, gallons, amount, status).
- Writes detail record to
-
NORMAL Subroutine:
-
Match Receipt (Exact Match):
- Sets lower limit (
SETLL) onINFIL1andINTZH1usingRCTKEY. - Reads
INFIL1(indicator76) until end-of-file (90) or match. - If end-of-file on
INFIL1, switches toINTZH1(indicator77) and reads. - If a match is found (
N90): - Calculates remaining quantity (
RNQTY = IHNQTY + IHNQTF - IHAPTQ - IHAPTF). - If
APGAL(A/P gallons) equalsRNQTY, updates the record:- Adds
APAMTtoIHAPTD(total dollars). - Adds
APGALtoIHAPTQ(total quantity). - Sets
IHCLCD(status) to'O'(open) or'C'(closed) based onAPCLCD. - Updates
IHCLDT(closed date, YMD) andIHCLD8(closed date, CYMD) withJRYMDandJRYM8. - Updates
APINVN(invoice number) andIHPONO(PO number). - Writes update to
INFIL1orINTZH1(EXCPTUPDRCP). - Logs to
APLIST(EXCPTDT01). - Clears
APAMTandAPGAL.
- Adds
- Sets lower limit (
-
Match Receipt (Partial Match):
- If no exact match, re-reads
INFIL1andINTZH1to find a record with more gallons thanAPGAL. - If found (
N90andAPGAL < RNQTY): - Updates
IHAPTD,IHAPTQ,IHCLCD,IHCLDT,IHCLD8,APINVN, andIHPONOas above. - Writes update (
EXCPTUPDRCP). - Logs to
APLIST(EXCPTDT02). - Clears
APAMTandAPGAL.
- If no exact match, re-reads
-
No Match, Update First Record:
- If no match and
APGALis non-zero, reads first record fromINFIL1orINTZH1. - Updates
IHAPTD,IHAPTQ,IHCLCD,IHCLDT,IHCLD8,APINVN, andIHPONO. - Writes update (
EXCPTUPDRCP). - Logs to
APLIST(EXCPTDT03). - Clears
APAMTandAPGAL.
- If no match and
-
FREIGH Subroutine:
- Sets indicator
11to flag freight processing. - Calls
NORMALsubroutine to process freight invoices similarly to standard invoices. -
Clears indicator
11. -
End Processing:
- Continues reading
APTRANrecords until end-of-file. - Closes files and terminates.
Business Rules¶
- Skip Sales Orders (
JB01, 07/08/10): - Bypasses posting if
ATSORN(sales order number) is non-zero, as sales order invoices are not posted to inventory receipts. - Skip Deleted Records:
- Skips records where
APHDELorAPDDELis'D'(deleted). - Dual File Support (
JB02, 09/18/14): - Checks both
INFIL1(inventory file) andINTZH1(holding file) for receipt matches, switching if no match is found inINFIL1. - Quantity Matching:
- Matches A/P gallons (
APGAL) to remaining receipt quantity (IHNQTY + IHNQTF - IHAPTQ - IHAPTF). - Updates the first record with sufficient gallons or the first available record if no match.
- Status Update:
- Sets
IHCLCDto'O'(open) or'C'(closed) based onAPCLCD. - Updates closed dates (
IHCLDT,IHCLD8) with journal date. - Freight Invoices:
- Processes freight invoices separately but uses the same
NORMALlogic (indicator11flags freight). - Printer Logging (
JB03, 09/18/14): - Logs all updates to
APLISTfor debugging and verification, with distinct exception records (DTL,DT01,DT02,DT03). - Y2K Compliance:
- Handles dates using
Y2KCEN(19) andY2KCMP(80) to determine 19xx or 20xx century. - Field Updates (
MG04, 09/15/15): - Supports expanded
INFIL1(448 bytes) andAPINVN(20 bytes). - 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
INFIL1but with different positions (e.g.,IHAPTDat 171-179,IHCLCDat 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
AP210program 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 forINTZH1(holding file).JB03(09/18/14): AddsAPLISTfor logging.MG04(09/15/15): ExpandsINFIL1and adds invoice number (APINVN) and PO number (IHPONO).- File Switching:
- Dynamically switches between
INFIL1andINTZH1if 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!