AR200 RPG36
The provided document, AR200.rpg36.txt
, is an RPG III program used in an IBM AS/400 or iSeries environment, called by the OCL script AR201.ocl36.txt
. It processes accounts receivable (A/R) transactions, updates customer and detail files, generates journal entries, and prints a transaction posting register. Below, I’ll explain the process steps, business rules, tables used, and external programs called.
Process Steps of the RPG Program (AR200)¶
The AR200
program processes A/R transactions (invoices, adjustments, payments, and miscellaneous cash) from a sorted transaction file, updates relevant files, and produces a detailed posting register. Here’s a step-by-step breakdown:
- Program Initialization:
- Files Defined:
- Input:
ARTRAN
(transactions),ARDETL
(A/R details),ARCUST
(customer master),ARCONT
(A/R control). - Output:
ARHIST
(A/R history),ARDIST
(distribution for journal entries),REPORT
(primary posting register),REPORTP
(Pittsburgh copy).
- Input:
- Data Structures:
UDS
: User data structure for journal date (JRNLDT
, positions 100–105), user ID (USERID
), workstation ID (WSID
), journal type (SJTYPE
), journal number (SJ##
), and Y2K variables (Y2KCEN
,Y2KCMP
).AGE
: Array for aged customer balances (5 periods, 9.2 format).MN
: Month names array (January–December).
-
Initialization (Level L3):
- Clears accumulators (
Z2
,ZERO6
,ZERO7
,ZERO9
) and sets constants (ONE1
,ONE2
). - Initializes page counters (
PAGE
,PAGE2
,PAGE4
) to 0. - Chains to
ARCONT
by company (ATCO
) to retrieve journal numbers (ACARJ#
,ACSLJ#
). If found (N91
), setsAR#
andSL#
; ifSJ##
is non-zero, uses it forSL#
. - Clears indicators
05
,06
.
- Clears accumulators (
-
Main Processing Loop:
- Processes
ARTRAN
records sequentially, controlled by level breaks (L1
,L2
,L3
):- L3 (Company Change): Resets accumulators and retrieves journal numbers.
- L2 (Inter-Company Change): Checks if
ATICCD = 'IC'
(indicator92
for inter-company customers). - L1 (Transaction Type Change): Resets transaction accumulators (
NETCHG
,INVAMT
,ADJAMT
,TOTREC
,TOTMIS
,TOTINV
) and clears indicators71
,72
,73
.
-
Executes one-time setup (
ONETIM
) if not already done (N90
). -
One-Time Setup (
ONETIM
): - Captures system time (
TIMEOF
) and date (TIMDAT
). - Converts journal date (
JRNLDT
) to YMD format (JYMD
) with Y2K compliance:- If
JYR >= Y2KCMP (80)
, usesY2KCEN (19)
; otherwise, incrementsY2KCEN
by 1. - Builds 8-digit date (
JRNLD8
) in CCYYMMDD format.
- If
- Converts system date to YMD (
SYSDT8
) for reporting. -
Sets indicator
90
to mark setup completion. -
Transaction Type Determination (
TRNSID
): - Clears indicators for transaction types (
10
,20
,30
,40
,50
,31
,32
,37
,15
,81
,12
). - Converts transaction date (
ATDATE
) and due date (ATDUDT
) to YMD format (ATDAT8
,ATDUD8
) with Y2K compliance. - Compares invoice date to journal date if
LDRETL = 'R'
(sets indicator65
if different). - Identifies transaction type:
ATCOD = 'Y'
sets indicator25
(COD invoice).ATTYPE = 'I'
sets10
(invoice).ATTYPE = 'J'
sets20
(adjustment).ATTYPE = 'P'
sets30
(payment).
- Sets journal type (
JRNTYP
):SJ
for invoices/adjustments,CR
for payments. -
For COD invoices (
25
), skips further processing (GOTO ENDTR
). -
Transaction Processing:
- Invoice (
10
):- If miscellaneous billing (
16
and86
), sets indicators15
,17
, clears10
. - If not already an adjustment (
N12
), executesINVSUM
. - If an adjustment (
12
), executesADJUST
.
- If miscellaneous billing (
- Adjustment (
20
):- Executes
ADJUST
.
- Executes
- Payment (
30
):- If not miscellaneous (
N80
), executesPAYMNT
. - If miscellaneous (
80
), executesMISC$$
.
- If not miscellaneous (
- Inter-Company Check:
- If
ATICCD = 'IC'
(92
), skips updates toARCUST
,ARDETL
,ARHIST
(only generates journal entries).
- If
- Checks
ARDETL
for existing invoice (KEY18 = ATCOCU + ATINV# + 'I00'
):- If found (
39
) and payment (30
or20
), executesPPDADD
and loops back (GOTO AGNX
). - If not found or invoice (
10
), proceeds toUNIQUE
.
- If found (
-
Sets adjustment flag (
12
) if invoice starts with9
(ATINV1 = '9'
, indicator31
). -
Invoice Summary (
INVSUM
): - Increments invoice count (
TOTINV
). - Adds transaction amount (
ATAMT
) toINVAMT
. - Chains to
ARCUST
byATCOCU
:- If found (
N99
), updates aged balance (AGE,P
), total due (ARTOTD
), month-to-date (ARMTD$
), year-to-date (ARYTD$
). - Sets indicator
40
for customer update.
- If found (
-
Writes to
ARDETL
andARHIST
(see output specs). -
Prepaid Invoice Add (
PPDADD
): - Creates an empty invoice record for prepaid transactions (indicator
61
). -
Writes to
ARDETL
andARHIST
with zero amounts. -
Adjustment Processing (
ADJUST
): - Chains to
ARCUST
byATCOCU
:- If not found or exists (
N39
,N99
), sets indicators40
,50
. - Updates
AGE,P
,ARTOTD
,ARMTD$
,ARYTD$
.
- If not found or exists (
- Updates
ARDETL
:- Subtracts
ATAMT
from current month paid (ADPAY
). - Increments next sequence number (
ADNEXT
). - Adds sales amount (
ATDSAL
toADDSAL
). - Updates notification of difference (
ADNOD
) and reference invoice (ADRFIV
) if blank/zero.
- Subtracts
- Writes to
ARDETL
andARHIST
(indicator60
). -
Increments
TOTINV
, addsATAMT
toADJAMT
. -
Payment Processing (
PAYMNT
): - Chains to
ARCUST
byATCOCU
:- If not found or exists (
N39
,N99
), updatesAGE,P
,ARTOTD
, month-to-date paid (ARM$PD
), year-to-date paid (ARY$PD
), payment amount (ARPYMT
), payment date (ARPDAT
,ARPDA8
).
- If not found or exists (
- Updates
ARDETL
:- Increments
ADNEXT
, addsATAMT
toADPAY
, updatesADNOD
,ADRFIV
.
- Increments
- Writes to
ARDETL
andARHIST
(indicator60
). - Increments
TOTINV
, accumulates totals:TOTREC
(received),TOTDIS
(discount),ATCASH
(net cash =ATAMT - ATDISC
),TOTCAS
(total cash),TOTARC
(A/R cash).
-
Compares
ATAMT
to remaining balance (ARLEFT
, sets32
,37
). -
Miscellaneous Cash (
MISC$$
):- If finance charge (
ATDSFC = 'FIN CHG'
), chains toARCUST
and subtractsATAMT
from finance charges (ARFIN$
). - Adds
ATAMT
toTOTCAS
(total cash) andTOTMIS
(miscellaneous cash). - Sets
ATCASH
toATAMT
.
- If finance charge (
-
Final Totals (
FINTOT
):- Calculates net change to A/R (
NETCHG = INVAMT + ADJAMT - TOTREC
). - Writes final totals to
REPORT
andREPORTP
.
- Calculates net change to A/R (
-
Output Operations:
- ARDIST: Writes journal entries for invoices (
I
), adjustments (J
), payments (P
), COD invoices (I
), including customer, amount, G/L accounts, and dates. - ARTRAN: Marks processed transactions with
P
(position 54). - ARCUST: Updates customer balances, payment info, and aged amounts (indicator
40
). - ARDETL: Adds/updates invoice, adjustment, payment, or prepaid records.
- ARHIST: Logs transaction history for invoices, adjustments, payments, and prepaids.
- ARCONT: Updates journal numbers (
ACARJ#
,ACSLJ#
) at company level break (L3). - REPORT/REPORTP: Prints posting register with headers, invoice, adjustment, payment details, and totals.
- ARDIST: Writes journal entries for invoices (
Business Rules¶
- Transaction Types:
- Invoices (
ATTYPE = 'I'
): Update customer balances, A/R details, and history; generate sales journal (SJ
) entries. - Adjustments (
ATTYPE = 'J'
): Adjust customer balances and A/R details; generateSJ
entries. - Payments (
ATTYPE = 'P'
): Reduce customer balances, update payment info, and generate cash receipts (CR
) entries. - COD Invoices (
ATCOD = 'Y'
): Skip standard processing, generate journal entries only. -
Miscellaneous Cash (
80
): If finance charge (FIN CHG
), reduceARFIN$
; otherwise, record as miscellaneous cash. -
Inter-Company Customers (
ATICCD = 'IC'
): -
Do not update
ARCUST
,ARDETL
, orARHIST
; only generate journal entries inARDIST
. -
Date Handling:
- Converts transaction and due dates to YMD format (CCYYMMDD) with Y2K compliance (
Y2KCEN
,Y2KCMP
). -
Compares invoice date to journal date if
LDRETL = 'R'
to flag discrepancies (indicator65
). -
Journal Numbers:
- Increments
ACSLJ#
for invoices/adjustments (10
or20
, indicator05
) ifSJ##
is zero. - Increments
ACARJ#
for payments (30
, indicator06
). -
Updates
ARCONT
with new journal numbers at company level break. -
Customer Updates:
- Updates
ARCUST
for non-inter-company transactions: aged balances (AGE
), total due (ARTOTD
), payment info (ARPYMT
,ARPDAT
), and period totals (ARMTD$
,ARYTD$
,ARM$PD
,ARY$PD
). -
Reduces finance charges (
ARFIN$
) for miscellaneous cash payments. -
A/R Detail Updates:
- Adds new records for invoices, adjustments, payments, or prepaids.
-
Updates existing records with payments (
ADPAY
), sequence numbers (ADNEXT
), sales amounts (ADDSAL
), notification of difference (ADNOD
), and reference invoice (ADRFIV
). -
History Logging:
-
Records all transactions (except inter-company) in
ARHIST
with details like company, customer, invoice, amount, and dates. -
Reporting:
- Produces two copies of the posting register (
REPORT
,REPORTP
) with sections for invoices, adjustments, and payments, including totals for A/R applied, discounts, cash, and net change. -
Includes headers with company name, date, time, user ID, workstation ID, and journal date.
-
Prepaid Invoices:
-
Creates empty invoice records in
ARDETL
andARHIST
for prepaid transactions with zero amounts. -
Error Handling:
- Chains to
ARCUST
andARDETL
to validate customer and invoice existence. - Uses indicators (
39
,99
,50
) to handle missing or existing records.
- Chains to
Tables Used¶
The program uses the following files (tables):
1. Input Files:
- ARTRAN
(F-spec 0014): Transaction file (256 bytes, update mode), sorted input from ?9?AR201S
.
- ARDETL
(0015): A/R detail file (128 bytes, update mode, keyed by company/customer/invoice, shared access).
- ARCUST
(0016): Customer master file (384 bytes, update mode, keyed by company/customer, shared access).
- ARCONT
(0017): A/R control file (256 bytes, update mode, keyed by company, shared access).
- Output Files:
ARHIST
(0018): A/R history file (128 bytes, output mode).ARDIST
(0019): Distribution file (161 bytes, output mode) for journal entries.REPORT
(0020): Primary transaction posting register (164 bytes, printer file).-
REPORTP
(0021): Pittsburgh copy of the register (164 bytes, printer file). -
Compile-Time Data:
MN
: Month names array (January–December) for report formatting.
External Programs Called¶
The program does not explicitly call external programs using CALL
operations. All processing is handled internally via subroutines:
- ONETIM
: One-time setup for dates and system info.
- TRNSID
: Determines transaction type and converts dates.
- INVSUM
: Processes invoice summaries.
- PPDADD
: Adds prepaid invoice records.
- ADJUST
: Processes adjustments.
- PAYMNT
: Processes payments.
- MISC$$
: Handles miscellaneous cash.
- FINTOT
: Calculates final totals.
Notes¶
- Y2K Compliance: Uses
Y2KCEN
(19) andY2KCMP
(80) to handle century in dates, ensuring CCYYMMDD format. - Inter-Company Logic: Explicitly skips A/R updates for
ATICCD = 'IC'
, focusing on journal entries. - Modifications:
- 4/20/05: Enhanced description field handling for cash receipts in
TEMGEN
. - 8/06/14: Changed printer names for paperless reporting, removed W. Conshohocken copy.
- Journal Types:
SJ
(sales journal) for invoices/adjustments,CR
(cash receipts) for payments. - File Access: Shared access (
DISP-SHR
) forARDETL
,ARCUST
,ARCONT
allows concurrent processing.
If you have additional details (e.g., source for AR210
, AR211
, or file layouts), I can provide further analysis. Let me know if you need clarification or more information!