Skip to content

AR500 RPG36

The provided document is an RPG/36 program, AR500.rpg36.txt, called by the OCL program AR500P.ocl36.txt to generate an Accounts Receivable (A/R) Aged Trial Balance report by customer number. This program processes customer and invoice data, calculates aging buckets, and produces a detailed report. Below, I’ll explain the process steps, business rules, tables used, and external programs called.

Process Steps of the RPG/36 Program

The AR500 RPG program is designed to produce an A/R Aged Trial Balance report, categorizing customer balances into aging buckets based on invoice dates (as revised on 04/13/05 per revision log). It processes data hierarchically by company, customer group, and customer, generating subtotals and totals. Here’s a detailed breakdown of the process steps:

  1. Program Initialization:
  2. Header Specifications:
    • H P064: Program identifier.
    • Sets up the program to handle A/R data processing.
  3. File Declarations:
    • Defines input and output files (see Tables Used section).
  4. Data Structures:
    • DTA: A 5-element array (9,2) to accumulate aging bucket amounts (current, 1-30, 31-60, 61-90, over 90/91-120 days).
    • UDS: Defines input parameters like LDATE (aging date), KYOUTS (outstanding invoices), KYREPT (report sequence), KYCLYN (credit limit flag), KYNOD (NOD report flag), and KYCUCL (customer class).
  5. Indicators:

    • Uses indicators (e.g., 31, 41, 50, 51, 52, 53, 60, 61, 62, etc.) to control logic, printing, and error handling.
  6. Company-Level Processing (Level 5 - L5):

  7. Initialize Company Totals:
    • Resets company totals (L5TOT, L5CUR, L50110, L51120, L52130, L5OV30, L5CDUE, L5CPRE) to zero.
    • Sets PAGE1 and PAGE2 to zero for pagination.
    • Captures system time (TIMEOF) for report headers.
  8. Retrieve Company Data:
    • Chains to ARCONT using ARCO (company number) to retrieve company name (CONAME) and aging limits (ACLMT1, ACLMT2, ACLMT3, ACLMT4).
    • Adjusts limits (LMT1, LMT2, LMT3, LMT4) by adding 1 to ACLMT1-3 for display purposes.
    • If ARCONT record is missing (*IN99), sets CONAME to blank.
  9. Customer Class Processing:
    • If KYCUCL (customer class) is specified, chains to GSTABL to retrieve class description (TBDESC into CUDESC).
    • Sets *IN66 if class is valid.
  10. Outstanding Invoices Check:
    • If KYOUTS = 'O', sets *IN50 to print only outstanding invoices.
  11. Report Sequence:
    • If KYREPT = 'C', sets *IN80 for customer sequence subtotals.
  12. Credit Limit and NOD Flags:

    • Sets *IN72 if KYCLYN = 'Y' (print credit limit).
    • Sets *IN73 if KYNOD = 'Y' (NOD report only).
  13. Customer Group Processing (Level 4 - L4):

  14. Resets group totals (L4TOT, L4CUR, L40110, L41120, L42130, L4OV30) to zero.
  15. Sets *IN85 and *IN89 based on whether ADZERO (grouping customer zero flag) is zero to distinguish petroleum vs. miscellaneous billing customers.

  16. Customer Processing (Level 3 - L3):

  17. Initialize Customer Totals:
    • Resets customer totals (L3TOT, L3CUR, L30110, L31120, L32130, L3OV30) to zero.
    • Clears *IN62 for customer subtotal printing.
  18. Retrieve Customer Data:
    • Chains to ARCUSP using ARCOCU (company/customer key) to retrieve credit comments (CSCMT1-3) and contact name (CSCNCT).
    • Sets *IN71 if comments are non-blank.
    • Chains to GSTABL using ARTERM (terms code) to retrieve terms description (TBDESC into TMDESC).
    • Chains to GSTABL using ARSLS# (salesman number) to retrieve salesman name (TBDESC into SLNAME).
  19. Credit Limit:

    • If ARCO = ADGCO and ARCUST = ADGCUS, uses ARCLMT as the credit limit (CLMT); otherwise, defaults to zero.
  20. Detail Processing (Level 1 - L1):

  21. Initialize Detail Totals:
    • Resets DTA array, TOTARD, CURDAR, AR011T, AR112T, AR213T, AROV3T to zero.
    • Clears indicators 31, 51, 52, 53 for balance checks.
  22. Process ARCUST Records:

    • Accumulates totals from ARCUST fields (ARTOTD, ARCURD, AR0110, AR1120, AR2130, AROV30) into TOTARD, CURDAR, AR011T, AR112T, AR213T, AROV3T.
    • If TOTARD ≠ 0 and *IN50 (outstanding only), sets *IN61 and *IN62.
    • Compares ARCLMT to TOTARD to set *IN57 if over credit limit.
    • Skips to END if *IN61 is set unless processing NOD records.
  23. Detail Record Processing (ARDETL):

  24. Match Records:
    • If no match (NMR), sets *IN26, writes an exception record, and skips to END.
  25. Aging Bucket Assignment:
    • Converts ADDATE (A/R date) to MMDDYY format (ADMDY).
    • Uses ADAGE (age code) to assign buckets:
    • ADAGE = 2 sets *IN10 or *IN11.
    • ADAGE = 4 sets *IN15, *IN13, *IN14, and reassigns ADAGE = 5.
    • Sets I to ADAGE for array indexing.
  26. Record Type Processing:
    • Invoice (ADTYPE = 'I'):
    • If ADPART ≠ 0, marks INVPMO = '*' (prior month activity).
    • If ADNOD = 'Y', sets INVNOD = 'NOD'.
    • If *IN50 (outstanding only), calculates balance (ADBAL = ADAMT - ADPAID).
    • If ADBAL ≠ 0, sets *IN60 and *IN62; otherwise, skips to END.
    • If ADINV1 = 9 (prepaid cash), adjusts L5CPRE (company prepay).
    • Adds ADAMT - ADPART to DTA(I).
    • Credit (ADTYPE = 'C'):
    • Adds ADAMT - ADPART to DTA(I).
    • Adjustment (ADTYPE = 'J'):
    • Adds ADAMT to DTA(I).
    • Payment (ADTYPE = 'P'):
    • Subtracts ADAMT from DTA(I) and negates ADAMT.
    • Invalid Type:
    • Sets *IN25, writes an exception record, and clears *IN25.
  27. NOD Processing:

    • If KYNOD = 'Y', accumulates DTA into CURDAR, AR011T, AR112T, AR213T, AROV3T, and computes TOTARD.
  28. Balance Validation:

  29. Compares DTA array with ARCUST totals (CURDAR, AR011T, AR112T, AR213T, AROV3T).
    • Sets *IN51 if any mismatch.
  30. Crossfoots ARCUST aging fields (ARCURD + AR0110 + AR1120 + AR2130 + AROV30 = ARTOTD).
    • Sets *IN52 if totals mismatch.
    • Sets *IN53 if TOT ≠ 0 but no detail records exist.
  31. Increments OUTBAL if mismatches occur (*IN51, *IN52, *IN53, *IN31).

  32. Subtotal and Total Calculations:

  33. Customer Subtotals (L3):
    • Accumulates L3TOT, L3CUR, L30110, L31120, L32130, L3OV30 from detail totals.
    • Validates L3TOT against crossfooted totals (L3CUR + L30110 + L31120 + L32130 + L3OV30).
    • Sets *IN54 if mismatch and increments OUTBAL.
  34. Group Totals (L4):
    • Accumulates L4TOT, L4CUR, L40110, L41120, L42130, L4OV30 if *IN80 (customer sequence).
  35. Company Totals (L5):

    • Accumulates L5TOT, L5CUR, L50110, L51120, L52130, L5OV30.
    • Calculates L5CDUE = L5CUR - L5CPRE.
  36. Report Output:

  37. Headers (L5/L4):
    • Prints company name (CONAME), date (UDATE), time (TIMEOF), page number (PAGE1/PAGE2), and aging date (LDATE).
    • Indicates outstanding invoices (KYOUTS = 'O'), NOD report (KYNOD = 'Y'), or customer class (KYCUCL).
    • Prints aging bucket headers (e.g., 0-30, 31-60, 61-90, 91-120, OVER 120).
  38. Detail Lines (L1):
    • Prints customer number (ARCUST), name (ARNAME), salesman (ARSLS#, SLNAME), totals (L3TOT, L3CUR, etc.), last payment (ARPYMT, ARPDAT), and finance charges (ARFIN$).
    • Prints invoice details (ADINV#, ADMDY, ADAMT, ADRFIV) for invoices, credits, adjustments, or payments.
    • Includes credit limit (CLMT), terms (TMDESC), and contact/comments (CSCNCT, CSCMT1-3) if applicable.
  39. Subtotals and Totals (L3/L4/L5):
    • Prints customer, group, and company totals with aging buckets.
    • Highlights out-of-balance conditions (OUTBAL) and credit limit violations (*IN57).
  40. Exception Records:

    • Prints errors for invalid ARDETL type (*IN25), missing ARCUST record (*IN26), or out-of-balance conditions (*IN51, *IN52, *IN53).
  41. Termination:

    • Writes final out-of-balance message and credit limit warning at last record (LR).

Business Rules

  1. Aging Buckets:
  2. Uses invoice date (ADDATE) for aging (revised 04/13/05).
  3. Buckets: 0-30, 31-60, 61-90, 91-120, over 120 days from invoice date.
  4. Outstanding Invoices:
  5. If KYOUTS = 'O', only processes invoices with outstanding balances (ADAMT - ADPAID ≠ 0).
  6. NOD Report:
  7. If KYNOD = 'Y', processes only records with ADNOD = 'Y' (Notification of Difference).
  8. Credit Limit:
  9. If KYCLYN = 'Y', prints credit limit (ARCLMT) and flags customers exceeding it (*IN57).
  10. Customer Class:
  11. If KYCUCL is specified, filters by customer class and retrieves description from GSTABL.
  12. Balance Validation:
  13. Ensures ARDETL totals match ARCUST totals.
  14. Crossfoots ARCUST aging fields to match total due (ARTOTD).
  15. Reports out-of-balance conditions (OUTBAL > 0).
  16. Record Types:
  17. Processes invoices (I), credits (C), adjustments (J), and payments (P).
  18. Invalid types trigger exception output.
  19. Hierarchy:
  20. Processes data by company (L5), customer group (L4), and customer (L3).
  21. Accumulates totals at each level for reporting.
  22. Report Formatting:
  23. Includes headers, detail lines, subtotals, and totals.
  24. Supports multiple printers (PRINT, PRINT2, PRINT3) for different output streams.

Tables (Files) Used

  1. ARCUST:
  2. Type: Input Primary (IPEA 3840 384 DISK).
  3. Purpose: Customer master file with balance and aging data.
  4. Key: ARCOCU (company/customer number).
  5. Fields: ARDEL (delete flag), ARCO (company number), ARCUST (customer number), ARNAME (name), ARADR1-4 (address), ARZIP5/9/14 (zip codes), ARTOTD (total due), ARCURD (current due), AR0110 (1-30 days), AR1120 (31-60 days), AR2130 (61-90 days), AROV30 (over 90 days), ARPYMT (last payment), ARPDAT (payment date), ARPREP (unapplied cash), ARMTD$ (MTD sales), ARYTD$ (YTD sales), ARSTMT (statements Y/N), ARFIN$ (finance charge), ARPBAL (previous balance), ARFINC (finance charge Y/N), ARCLMT (credit limit), ARAREA (area code), ARTELE (phone), ARSLS# (salesman), ARTERM (terms), ADGCO (group company), ADGCUS (group customer), ARPDA8 (payment date YMD), ARHID8 (recent high date YMD).
  6. ARDETL:
  7. Type: Input Secondary (IS AF 138 138 DISK).
  8. Purpose: A/R detail file with invoice and transaction data.
  9. Key: ADCOCU (company/customer number).
  10. Fields: ADDEL (delete flag), ARCO (company number), ARCUST (customer number), ADINV# (invoice number), ADTYPE (I/J/P/C), ADSEQ# (sequence number), ADDATE (A/R date), ADAMT (amount), ADAGE (age code), ADPART (partial payment), ADPAY (current month paid), ADSLS (salesman), ADPOST (posting code), ADNEXT (next sequence), ADPURG (purge code), ADDUDT (due date), ADTERM (terms), ADJRNL (journal date), ADDUD8 (due date YMD), ADJRN8 (journal date YMD), ADNOD (NOD flag), ADRFIV (reference invoice), ADGCO (group company), ADGCUS (group customer).
  11. ARCUSP:
  12. Type: Input (IF F 1344 8AI 2 DISK).
  13. Purpose: Customer supplemental file for credit comments and contact info.
  14. Key: ARCOCU (company/customer number).
  15. Fields: CSCMT1-3 (credit comments), CSCNCT (contact name).
  16. GSTABL:
  17. Type: Input (IF F 256 12AI 2 DISK).
  18. Purpose: General system table for terms, salesman, and class descriptions.
  19. Key: TBTYPE/TBCODE (e.g., ARTERM, SLSMAN).
  20. Fields: TBDEL (delete flag), TBTYPE (table type), TBCODE (code), TBDESC (description).
  21. ARCONT:
  22. Type: Input (IF F 256 2AI 2 DISK).
  23. Purpose: A/R control file for company data and aging limits.
  24. Key: ARCO (company number).
  25. Fields: CONAME (company name), ACLMT1-4 (aging limits).
  26. PRINT:
  27. Type: Output (O 164 OF PRINTER U8).
  28. Purpose: Primary report output.
  29. PRINT2:
  30. Type: Output (O 164 OA PRINTER).
  31. Purpose: Secondary report output for errors or additional copies.
  32. PRINT3:
  33. Type: Output (O 164 OV PRINTER U7).
  34. Purpose: Additional report output, possibly for group or company summaries.

External Programs Called

The RPG program does not explicitly call external programs (e.g., via CALL operation). However, it is called by the OCL program AR500P.ocl36.txt, which passes parameters like ?9? and ?11? (likely mapped to KYOUTS, KYREPT, etc.).

Additional Notes

  • Revision Log:
  • Modified on 04/13/05 to use invoice date (ADDATE) instead of due date for aging, with buckets changed to 0-30, 31-60, 61-90, 91-120, over 120 days.
  • Error Handling:
  • Reports invalid ARDETL types, missing ARCUST records, and out-of-balance conditions.
  • Hierarchical Processing:
  • Uses RPG cycle levels (L1, L3, L4, L5) for customer, group, and company processing.
  • Output:
  • Produces a detailed report with headers, customer details, aging buckets, and totals, with special handling for NOD and out-of-balance conditions.

If you need further details (e.g., specific field calculations, report layout, or additional file structures), please provide more context or related files!