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
PAGE1
andPAGE2
to zero for pagination. - Captures system time (
TIMEOF
) for report headers.
- Resets company totals (
- Retrieve Company Data:
- Chains to
ARCONT
usingARCO
(company number) to retrieve company name (CONAME
) and aging limits (ACLMT1
,ACLMT2
,ACLMT3
,ACLMT4
). - Adjusts limits (
LMT1
,LMT2
,LMT3
,LMT4
) by adding 1 toACLMT1-3
for display purposes. - If
ARCONT
record is missing (*IN99
), setsCONAME
to blank.
- Chains to
- Customer Class Processing:
- If
KYCUCL
(customer class) is specified, chains toGSTABL
to retrieve class description (TBDESC
intoCUDESC
). - Sets
*IN66
if class is valid.
- If
- Outstanding Invoices Check:
- If
KYOUTS = 'O'
, sets*IN50
to print only outstanding invoices.
- If
- Report Sequence:
- If
KYREPT = 'C'
, sets*IN80
for customer sequence subtotals.
- If
-
Credit Limit and NOD Flags:
- Sets
*IN72
ifKYCLYN = 'Y'
(print credit limit). - Sets
*IN73
ifKYNOD = 'Y'
(NOD report only).
- Sets
-
Customer Group Processing (Level 4 - L4):
- Resets group totals (
L4TOT
,L4CUR
,L40110
,L41120
,L42130
,L4OV30
) to zero. -
Sets
*IN85
and*IN89
based 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
*IN62
for customer subtotal printing.
- Resets customer totals (
- Retrieve Customer Data:
- Chains to
ARCUSP
usingARCOCU
(company/customer key) to retrieve credit comments (CSCMT1-3
) and contact name (CSCNCT
). - Sets
*IN71
if comments are non-blank. - Chains to
GSTABL
usingARTERM
(terms code) to retrieve terms description (TBDESC
intoTMDESC
). - Chains to
GSTABL
usingARSLS#
(salesman number) to retrieve salesman name (TBDESC
intoSLNAME
).
- Chains to
-
Credit Limit:
- If
ARCO = ADGCO
andARCUST = ADGCUS
, usesARCLMT
as the credit limit (CLMT
); otherwise, defaults to zero.
- If
-
Detail Processing (Level 1 - L1):
- Initialize Detail Totals:
- Resets
DTA
array,TOTARD
,CURDAR
,AR011T
,AR112T
,AR213T
,AROV3T
to zero. - Clears indicators
31
,51
,52
,53
for balance checks.
- Resets
-
Process
ARCUST
Records:- Accumulates totals from
ARCUST
fields (ARTOTD
,ARCURD
,AR0110
,AR1120
,AR2130
,AROV30
) intoTOTARD
,CURDAR
,AR011T
,AR112T
,AR213T
,AROV3T
. - If
TOTARD ≠ 0
and*IN50
(outstanding only), sets*IN61
and*IN62
. - Compares
ARCLMT
toTOTARD
to set*IN57
if over credit limit. - Skips to
END
if*IN61
is 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 = 2
sets*IN10
or*IN11
.ADAGE = 4
sets*IN15
,*IN13
,*IN14
, and reassignsADAGE = 5
.- Sets
I
toADAGE
for 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*IN60
and*IN62
; otherwise, skips toEND
. - If
ADINV1 = 9
(prepaid cash), adjustsL5CPRE
(company prepay). - Adds
ADAMT - ADPART
toDTA(I)
. - Credit (
ADTYPE = 'C'
): - Adds
ADAMT - ADPART
toDTA(I)
. - Adjustment (
ADTYPE = 'J'
): - Adds
ADAMT
toDTA(I)
. - Payment (
ADTYPE = 'P'
): - Subtracts
ADAMT
fromDTA(I)
and negatesADAMT
. - Invalid Type:
- Sets
*IN25
, writes an exception record, and clears*IN25
.
- Invoice (
-
NOD Processing:
- If
KYNOD = 'Y'
, accumulatesDTA
intoCURDAR
,AR011T
,AR112T
,AR213T
,AROV3T
, and computesTOTARD
.
- If
-
Balance Validation:
- Compares
DTA
array withARCUST
totals (CURDAR
,AR011T
,AR112T
,AR213T
,AROV3T
).- Sets
*IN51
if any mismatch.
- Sets
- Crossfoots
ARCUST
aging fields (ARCURD + AR0110 + AR1120 + AR2130 + AROV30 = ARTOTD
).- Sets
*IN52
if totals mismatch. - Sets
*IN53
ifTOT ≠ 0
but no detail records exist.
- Sets
-
Increments
OUTBAL
if mismatches occur (*IN51
,*IN52
,*IN53
,*IN31
). -
Subtotal and Total Calculations:
- 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 incrementsOUTBAL
.
- Accumulates
- Group Totals (L4):
- Accumulates
L4TOT
,L4CUR
,L40110
,L41120
,L42130
,L4OV30
if*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
ARDETL
type (*IN25
), missingARCUST
record (*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
KYCUCL
is specified, filters by customer class and retrieves description fromGSTABL
. - Balance Validation:
- Ensures
ARDETL
totals matchARCUST
totals. - Crossfoots
ARCUST
aging 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
ARDETL
types, missingARCUST
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!