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
ARCONTby 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
ARTRANrecords 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'(indicator92for 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, incrementsY2KCENby 1. - Builds 8-digit date (
JRNLD8) in CCYYMMDD format.
- If
- Converts system date to YMD (
SYSDT8) for reporting. -
Sets indicator
90to 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 indicator65if 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):SJfor invoices/adjustments,CRfor payments. -
For COD invoices (
25), skips further processing (GOTO ENDTR). -
Transaction Processing:
- Invoice (
10):- If miscellaneous billing (
16and86), 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
ARDETLfor existing invoice (KEY18 = ATCOCU + ATINV# + 'I00'):- If found (
39) and payment (30or20), executesPPDADDand 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
ARCUSTbyATCOCU:- If found (
N99), updates aged balance (AGE,P), total due (ARTOTD), month-to-date (ARMTD$), year-to-date (ARYTD$). - Sets indicator
40for customer update.
- If found (
-
Writes to
ARDETLandARHIST(see output specs). -
Prepaid Invoice Add (
PPDADD): - Creates an empty invoice record for prepaid transactions (indicator
61). -
Writes to
ARDETLandARHISTwith zero amounts. -
Adjustment Processing (
ADJUST): - Chains to
ARCUSTbyATCOCU:- If not found or exists (
N39,N99), sets indicators40,50. - Updates
AGE,P,ARTOTD,ARMTD$,ARYTD$.
- If not found or exists (
- Updates
ARDETL:- Subtracts
ATAMTfrom current month paid (ADPAY). - Increments next sequence number (
ADNEXT). - Adds sales amount (
ATDSALtoADDSAL). - Updates notification of difference (
ADNOD) and reference invoice (ADRFIV) if blank/zero.
- Subtracts
- Writes to
ARDETLandARHIST(indicator60). -
Increments
TOTINV, addsATAMTtoADJAMT. -
Payment Processing (
PAYMNT): - Chains to
ARCUSTbyATCOCU:- 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, addsATAMTtoADPAY, updatesADNOD,ADRFIV.
- Increments
- Writes to
ARDETLandARHIST(indicator60). - Increments
TOTINV, accumulates totals:TOTREC(received),TOTDIS(discount),ATCASH(net cash =ATAMT - ATDISC),TOTCAS(total cash),TOTARC(A/R cash).
-
Compares
ATAMTto remaining balance (ARLEFT, sets32,37). -
Miscellaneous Cash (
MISC$$):- If finance charge (
ATDSFC = 'FIN CHG'), chains toARCUSTand subtractsATAMTfrom finance charges (ARFIN$). - Adds
ATAMTtoTOTCAS(total cash) andTOTMIS(miscellaneous cash). - Sets
ATCASHtoATAMT.
- If finance charge (
-
Final Totals (
FINTOT):- Calculates net change to A/R (
NETCHG = INVAMT + ADJAMT - TOTREC). - Writes final totals to
REPORTandREPORTP.
- 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; generateSJentries. - 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 (10or20, indicator05) ifSJ##is zero. - Increments
ACARJ#for payments (30, indicator06). -
Updates
ARCONTwith new journal numbers at company level break. -
Customer Updates:
- Updates
ARCUSTfor 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
ARHISTwith 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
ARDETLandARHISTfor prepaid transactions with zero amounts. -
Error Handling:
- Chains to
ARCUSTandARDETLto 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,ARCONTallows 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!