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:
- Program Initialization:
- Header Specifications:
H P064: Program identifier.- Sets up the program to handle A/R data processing.
- File Declarations:
- Defines input and output files (see Tables Used section).
- 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 likeLDATE(aging date),KYOUTS(outstanding invoices),KYREPT(report sequence),KYCLYN(credit limit flag),KYNOD(NOD report flag), andKYCUCL(customer class).
-
Indicators:
- Uses indicators (e.g.,
31,41,50,51,52,53,60,61,62, etc.) to control logic, printing, and error handling.
- Uses indicators (e.g.,
-
Company-Level Processing (Level 5 - L5):
- Initialize Company Totals:
- Resets company totals (
L5TOT,L5CUR,L50110,L51120,L52130,L5OV30,L5CDUE,L5CPRE) to zero. - Sets
PAGE1andPAGE2to zero for pagination. - Captures system time (
TIMEOF) for report headers.
- Resets company totals (
- Retrieve Company Data:
- Chains to
ARCONTusingARCO(company number) to retrieve company name (CONAME) and aging limits (ACLMT1,ACLMT2,ACLMT3,ACLMT4). - Adjusts limits (
LMT1,LMT2,LMT3,LMT4) by adding 1 toACLMT1-3for display purposes. - If
ARCONTrecord is missing (*IN99), setsCONAMEto blank.
- Chains to
- Customer Class Processing:
- If
KYCUCL(customer class) is specified, chains toGSTABLto retrieve class description (TBDESCintoCUDESC). - Sets
*IN66if class is valid.
- If
- Outstanding Invoices Check:
- If
KYOUTS = 'O', sets*IN50to print only outstanding invoices.
- If
- Report Sequence:
- If
KYREPT = 'C', sets*IN80for customer sequence subtotals.
- If
-
Credit Limit and NOD Flags:
- Sets
*IN72ifKYCLYN = 'Y'(print credit limit). - Sets
*IN73ifKYNOD = 'Y'(NOD report only).
- Sets
-
Customer Group Processing (Level 4 - L4):
- Resets group totals (
L4TOT,L4CUR,L40110,L41120,L42130,L4OV30) to zero. -
Sets
*IN85and*IN89based on whetherADZERO(grouping customer zero flag) is zero to distinguish petroleum vs. miscellaneous billing customers. -
Customer Processing (Level 3 - L3):
- Initialize Customer Totals:
- Resets customer totals (
L3TOT,L3CUR,L30110,L31120,L32130,L3OV30) to zero. - Clears
*IN62for customer subtotal printing.
- Resets customer totals (
- Retrieve Customer Data:
- Chains to
ARCUSPusingARCOCU(company/customer key) to retrieve credit comments (CSCMT1-3) and contact name (CSCNCT). - Sets
*IN71if comments are non-blank. - Chains to
GSTABLusingARTERM(terms code) to retrieve terms description (TBDESCintoTMDESC). - Chains to
GSTABLusingARSLS#(salesman number) to retrieve salesman name (TBDESCintoSLNAME).
- Chains to
-
Credit Limit:
- If
ARCO = ADGCOandARCUST = ADGCUS, usesARCLMTas the credit limit (CLMT); otherwise, defaults to zero.
- If
-
Detail Processing (Level 1 - L1):
- Initialize Detail Totals:
- Resets
DTAarray,TOTARD,CURDAR,AR011T,AR112T,AR213T,AROV3Tto zero. - Clears indicators
31,51,52,53for balance checks.
- Resets
-
Process
ARCUSTRecords:- Accumulates totals from
ARCUSTfields (ARTOTD,ARCURD,AR0110,AR1120,AR2130,AROV30) intoTOTARD,CURDAR,AR011T,AR112T,AR213T,AROV3T. - If
TOTARD ≠ 0and*IN50(outstanding only), sets*IN61and*IN62. - Compares
ARCLMTtoTOTARDto set*IN57if over credit limit. - Skips to
ENDif*IN61is set unless processing NOD records.
- Accumulates totals from
-
Detail Record Processing (
ARDETL): - Match Records:
- If no match (
NMR), sets*IN26, writes an exception record, and skips toEND.
- If no match (
- Aging Bucket Assignment:
- Converts
ADDATE(A/R date) to MMDDYY format (ADMDY). - Uses
ADAGE(age code) to assign buckets: ADAGE = 2sets*IN10or*IN11.ADAGE = 4sets*IN15,*IN13,*IN14, and reassignsADAGE = 5.- Sets
ItoADAGEfor array indexing.
- Converts
- Record Type Processing:
- Invoice (
ADTYPE = 'I'): - If
ADPART ≠ 0, marksINVPMO = '*'(prior month activity). - If
ADNOD = 'Y', setsINVNOD = 'NOD'. - If
*IN50(outstanding only), calculates balance (ADBAL = ADAMT - ADPAID). - If
ADBAL ≠ 0, sets*IN60and*IN62; otherwise, skips toEND. - If
ADINV1 = 9(prepaid cash), adjustsL5CPRE(company prepay). - Adds
ADAMT - ADPARTtoDTA(I). - Credit (
ADTYPE = 'C'): - Adds
ADAMT - ADPARTtoDTA(I). - Adjustment (
ADTYPE = 'J'): - Adds
ADAMTtoDTA(I). - Payment (
ADTYPE = 'P'): - Subtracts
ADAMTfromDTA(I)and negatesADAMT. - Invalid Type:
- Sets
*IN25, writes an exception record, and clears*IN25.
- Invoice (
-
NOD Processing:
- If
KYNOD = 'Y', accumulatesDTAintoCURDAR,AR011T,AR112T,AR213T,AROV3T, and computesTOTARD.
- If
-
Balance Validation:
- Compares
DTAarray withARCUSTtotals (CURDAR,AR011T,AR112T,AR213T,AROV3T).- Sets
*IN51if any mismatch.
- Sets
- Crossfoots
ARCUSTaging fields (ARCURD + AR0110 + AR1120 + AR2130 + AROV30 = ARTOTD).- Sets
*IN52if totals mismatch. - Sets
*IN53ifTOT ≠ 0but no detail records exist.
- Sets
-
Increments
OUTBALif mismatches occur (*IN51,*IN52,*IN53,*IN31). -
Subtotal and Total Calculations:
- Customer Subtotals (L3):
- Accumulates
L3TOT,L3CUR,L30110,L31120,L32130,L3OV30from detail totals. - Validates
L3TOTagainst crossfooted totals (L3CUR + L30110 + L31120 + L32130 + L3OV30). - Sets
*IN54if mismatch and incrementsOUTBAL.
- Accumulates
- Group Totals (L4):
- Accumulates
L4TOT,L4CUR,L40110,L41120,L42130,L4OV30if*IN80(customer sequence).
- Accumulates
-
Company Totals (L5):
- Accumulates
L5TOT,L5CUR,L50110,L51120,L52130,L5OV30. - Calculates
L5CDUE = L5CUR - L5CPRE.
- Accumulates
-
Report Output:
- 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).
- Prints company name (
- 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.
- Prints customer number (
- 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).
-
Exception Records:
- Prints errors for invalid
ARDETLtype (*IN25), missingARCUSTrecord (*IN26), or out-of-balance conditions (*IN51,*IN52,*IN53).
- Prints errors for invalid
-
Termination:
- Writes final out-of-balance message and credit limit warning at last record (
LR).
- Writes final out-of-balance message and credit limit warning at last record (
Business Rules¶
- Aging Buckets:
- Uses invoice date (
ADDATE) for aging (revised 04/13/05). - Buckets: 0-30, 31-60, 61-90, 91-120, over 120 days from invoice date.
- Outstanding Invoices:
- If
KYOUTS = 'O', only processes invoices with outstanding balances (ADAMT - ADPAID ≠ 0). - NOD Report:
- If
KYNOD = 'Y', processes only records withADNOD = 'Y'(Notification of Difference). - Credit Limit:
- If
KYCLYN = 'Y', prints credit limit (ARCLMT) and flags customers exceeding it (*IN57). - Customer Class:
- If
KYCUCLis specified, filters by customer class and retrieves description fromGSTABL. - Balance Validation:
- Ensures
ARDETLtotals matchARCUSTtotals. - Crossfoots
ARCUSTaging fields to match total due (ARTOTD). - Reports out-of-balance conditions (
OUTBAL > 0). - Record Types:
- Processes invoices (
I), credits (C), adjustments (J), and payments (P). - Invalid types trigger exception output.
- Hierarchy:
- Processes data by company (
L5), customer group (L4), and customer (L3). - Accumulates totals at each level for reporting.
- Report Formatting:
- Includes headers, detail lines, subtotals, and totals.
- Supports multiple printers (
PRINT,PRINT2,PRINT3) for different output streams.
Tables (Files) Used¶
- ARCUST:
- Type: Input Primary (
IPEA 3840 384 DISK). - Purpose: Customer master file with balance and aging data.
- Key:
ARCOCU(company/customer number). - 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). - ARDETL:
- Type: Input Secondary (
IS AF 138 138 DISK). - Purpose: A/R detail file with invoice and transaction data.
- Key:
ADCOCU(company/customer number). - 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). - ARCUSP:
- Type: Input (
IF F 1344 8AI 2 DISK). - Purpose: Customer supplemental file for credit comments and contact info.
- Key:
ARCOCU(company/customer number). - Fields:
CSCMT1-3(credit comments),CSCNCT(contact name). - GSTABL:
- Type: Input (
IF F 256 12AI 2 DISK). - Purpose: General system table for terms, salesman, and class descriptions.
- Key:
TBTYPE/TBCODE(e.g.,ARTERM,SLSMAN). - Fields:
TBDEL(delete flag),TBTYPE(table type),TBCODE(code),TBDESC(description). - ARCONT:
- Type: Input (
IF F 256 2AI 2 DISK). - Purpose: A/R control file for company data and aging limits.
- Key:
ARCO(company number). - Fields:
CONAME(company name),ACLMT1-4(aging limits). - PRINT:
- Type: Output (
O 164 OF PRINTER U8). - Purpose: Primary report output.
- PRINT2:
- Type: Output (
O 164 OA PRINTER). - Purpose: Secondary report output for errors or additional copies.
- PRINT3:
- Type: Output (
O 164 OV PRINTER U7). - 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
ARDETLtypes, missingARCUSTrecords, 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!