AR210 RPG36
The provided document is an RPG program named AR210.rpg36.txt, written in RPG II or III for the IBM System/36 or AS/400 System/36 Environment. It is called by the OCL procedure AR200.ocl36.txt as part of the cash receipts posting process in an accounts receivable (AR) system. The program generates journal entries for the general ledger (GL) based on AR distribution records, producing summarized entries in the ARTEMG file for subsequent GL posting. Below, I’ll explain the process steps, business rules, tables used, and external programs called.
Process Steps of the RPG Program¶
The AR210 program processes distribution records from the ARDIST file (generated by AR200) to create journal entries in the ARTEMG file, which are later sorted and posted to the GL by AR211. It handles invoice, adjustment, payment, and miscellaneous cash transactions, generating debit and credit entries with appropriate GL accounts. The program uses a primary input file (ARDIST) and a control file (ARCONT) to produce output in a temporary GL journal file (ARTEMG). Here’s a detailed breakdown of the steps:
- Program Setup and File Definitions:
- Header Specifications:
H P014: Program identifier (P014 is a control number).- Comment (4/20/05): Modified to preserve the full 25-character description (
ADDESC) from cash receipts entry, with the journal date moved to the start of the second description field inARTEMG.
- File Specifications (F Specs):
ARDIST IPE F 161 161 DISK: Primary input file (Input Primary Entry, IPE), 161-byte records, contains AR distribution records.ARTEMG O F 128 128 DISK: Output file for temporary GL journal entries, 128-byte records.ARCONT IC F 256 256R 2AI 2 DISK: AR control file, input with control (IC), keyed by 2-byte key, alternate index (AI).
- Input Specifications (I Specs):
ARDIST:- Record types: CI (01, invoice), CJ (02, adjustment), CP (03, payment).
- Fields: company (
ADCO), customer (ADCUST), invoice (ADINV#), amount (ADAMT), discount (ADDISC), GL credit/debit accounts (ADGLCR,ADGLDR), journal date (ADJRDT), customer name (ADNAME), discount code (ADCODI), and description (ADDESC). ARCONT: Includes GL account for AR control (ACTRGL).UDS(User Data Structure): Contains user ID (USERID), workstation ID (WSID), sales journal number (SJ##), Y2K fields (Y2KCEN,Y2KCMP), and other control fields.
-
Output Specifications (O Specs):
- Defines
ARTEMGoutput formats for debit (30, 32), credit (31, 33), inter-company (34), and discount (35) entries, including fields like company, journal number, account, amount, customer name, invoice, date, and description.
- Defines
-
Initialization:
- Sets
DISAMT(discount amount) to zero and turns off indicator 82 (discount < 0). -
Executes
ONETIMsubroutine (if indicator 98 is off):- Captures system time (
TIMEOF). - Chains to
ARCONTusingADCO(company number) to retrieve control data (e.g.,ACTRGL). - Sets transaction type indicators: 61 for invoice/adjustment (01/02), 63 for payment (03).
- Sets indicator 98 to prevent re-running.
- Captures system time (
-
Main Processing Loop:
-
Processes each
ARDISTrecord:- Miscellaneous Amount Handling:
- If indicator 86 (miscellaneous amount
ADMISC≠ 0) and 16 (amount = 0), setsADAMT = ADMISC(miscellaneous cash). - If 86 on and 16 off, subtracts
ADMISCfromADAMTto isolate the net amount. - Discount Handling:
- If indicator 51 (discount
ADDISC≠ 0), setsDISAMT = ADDISC. - If indicator 82 (discount < 0), multiplies
DISAMTby -1 to make it positive. - Amount Sign Handling:
- Sets indicator 81 if
ADAMT < 0. - If 81 off, executes
CASE01(positive amount). - If 81 on, executes
CASE02(negative amount). - Company Validation:
- Compares debit/credit company codes (
ADCODR,ADCOCR) withADCOto set indicator 54 (mismatch). - If 54 on and 81 on, negates
ADAMTand runsCASE03(inter-company adjustment). - If 54 on and 81 off, runs
CASE03(inter-company). - Discount GL Entry:
- If 51 on, sets
ADCODR = ADCODI(discount code) and callsGLDISCto generate a discount entry. - Adds
DISAMTto debit total (DBTOT) if 82 off, or credit total (CRTOT) if 82 on.
-
Subroutine
CASE01(Positive Amount): -
Handles positive transaction amounts (non-negative
ADAMT):- Debit Entry:
- If payment (63 on) and discount not negative (82 off),
DRAMT = ADAMT - DISAMT. - If payment and 82 on,
DRAMT = ADAMT + DISAMT. - If not payment,
DRAMT = ADAMT. - Sets debit account (
DRACCT = ADGLDR), company (DRCO = ADCODR), and type (DORC = 'D'). - Writes debit entry to
ARTEMG(indicator 30). - Adds
DRAMTtoDBTOT. - Credit Entry:
- Sets
CRAMT = ADAMT, credit account (CRACCT = ADGLCR), company (CRCO = ADCOCR), and type (DORC = 'C'). - Writes credit entry to
ARTEMG(indicator 31). - Adds
CRAMTtoCRTOT.
-
Subroutine
CASE02(Negative Amount): -
Handles negative transaction amounts (
ADAMT < 0):- Debit Entry:
- Sets
DRAMT = -ADAMT,DRACCT = ADGLCR,DRCO = ADCOCR,DORC = 'D'. - Writes debit entry (indicator 32).
- Adds
DRAMTtoDBTOT. - Credit Entry:
- If payment (63 on),
CRAMT = -ADAMT, adjusted byDISAMT(subtract if 82 off, add if 82 on). - If not payment,
CRAMT = -ADAMT. - Sets
CRACCT = ADGLDR,CRCO = ADCODR,DORC = 'C'. - Writes credit entry (indicator 33).
- Adds
CRAMTtoCRTOT.
-
Subroutine
CASE03(Inter-Company Transactions): -
Handles transactions where company codes differ (
ADCODR≠ADCOorADCOCR≠ADCO):- Credit Entry:
- Sets
ICRAMT = ADAMT ± DISAMT(subtract if 82 off, add if 82 on). - Uses
ACTRGL(AR control GL account) andADCOCRforICRGL8, companyICRCO = ADCODR. - Sets
IC = 'C'ifADAMT ≥ 0(81 off), elseIC = 'D'. - Writes entry to
ARTEMG(indicator 34). - Debit Entry:
- Sets
IDRAMT = ADAMT ± DISAMT. - Uses
ACTRGLandADCODRforIDRGL8, companyIDRCO = ADCOCR. - Sets
ID = 'D'ifADAMT ≥ 0, elseID = 'C'. - Writes entry to
ARTEMG(indicator 34).
-
Subroutine
GLDISC(Discount Entry): -
Generates GL entry for discounts (indicator 51 on):
- Sets
DISC11 = DISAMT,DORC = 'D'if discount positive (82 off), else'C'. - Uses discount GL account (
ADGLDI), company (ADCODI), and writes toARTEMG(indicator 35).
- Sets
-
Subroutine
ONETIM: -
Runs once to initialize:
- Captures system time (
TIMEOF). - Chains to
ARCONTfor company-specific data. - Sets indicators 61 (invoice/adjustment) or 63 (payment) based on
ARDISTrecord type (01, 02, 03). - Sets indicator 98 to prevent re-running.
- Captures system time (
-
Output to
ARTEMG: -
Writes journal entries with:
- Type (
'A'for AR). - Company (
DRCO,CRCO,ICRCO,IDRCO,ADCODI). - Journal number (
ADJRNL). - Debit/credit flag (
DORC,IC,ID). - GL account (
DRACCT,CRACCT,ICRGL8,IDRGL8,ADGLDI). - Customer name (
ADNAME), invoice (ADINV#), date (ADJRDT), amount (DRAMT,CRAMT,ICRAMT,IDRAMT,DISC11). - Summarize flag (
'S'at position 96, except for payments with indicator 63 and 40 on). - Description (
ADDESC) at positions 96-121, per 4/20/05 change.
- Type (
-
Program Termination:
- Ends when
ARDISTinput is exhausted. - Accumulates totals (
DBTOT,CRTOT) for balancing but does not write them to output (used by later programs).
- Ends when
Business Rules¶
The program enforces accounting rules for generating GL journal entries from AR distributions:
- Transaction Types:
- Invoices (01, CI) and Adjustments (02, CJ): Generate debit and credit entries using
ADGLDRandADGLCR, respectively. - Payments (03, CP): Adjust amounts by discounts (
ADDISC) and generate entries. - Miscellaneous Cash (86): If
ADAMT = 0, useADMISCas the amount; otherwise, subtractADMISCfromADAMT. -
Discounts (51): Generate separate GL entries using
ADGLDI(discount account). -
Debit and Credit Entries:
- For positive amounts (
ADAMT ≥ 0):- Debit:
ADGLDR, adjusted by discount if payment. - Credit:
ADGLCR.
- Debit:
- For negative amounts (
ADAMT < 0):- Debit:
ADGLCR(reverses account). - Credit:
ADGLDR, adjusted by discount if payment.
- Debit:
-
Entries include company, journal number, customer, invoice, date, and description.
-
Inter-Company Transactions:
-
If debit/credit company codes (
ADCODR,ADCOCR) differ fromADCO(indicator 54), generate two entries:- One using
ACTRGL(AR control GL account) for the AR side. - Another for the inter-company side, flipping debit/credit based on amount sign.
- One using
-
Discount Handling:
- Discounts (
ADDISC) are applied to payment amounts and generate separate GL entries withADGLDI. - Negative discounts are inverted for reporting.
-
Discount entries are debit if positive, credit if negative.
-
Y2K Compliance:
-
Uses
Y2KCEN(century, e.g., 19 or 20) andY2KCMP(comparison year, e.g., 80) for date handling, thoughADJRDTis assumed pre-validated byAR200P. -
Summarization:
- Most entries are marked for summarization (
'S'at position 96) for GL posting byAR211. -
Payment entries with specific conditions (indicators 63 and 40) may omit the summarize flag.
-
Audit and Control:
- Tracks totals (
DBTOT,CRTOT) for balancing. - Includes user ID (
USERID), workstation ID (WSID), and journal number (SJ##) for traceability. - Preserves full 25-character description (
ADDESC) per 4/20/05 change.
Tables Used¶
In RPG, "tables" refer to disk or printer files. The program uses:
- Input Files:
ARDIST(?9?CRDIGG): AR distribution file, primary input, 161 bytes, contains transaction details.-
ARCONT(?9?ARCONT): AR control file, input with control, 256 bytes, keyed, provides GL account (ACTRGL). -
Output Files:
-
ARTEMG(?9?CRTGGG): Temporary GL journal file, output, 128 bytes, contains debit/credit entries for GL posting. -
No Printer Files:
- Unlike
AR200, this program produces no reports, focusing solely on data output toARTEMG.
External Programs Called¶
The AR210 program does not explicitly call external programs (no CALL operations). All logic is handled internally via subroutines:
- Subroutines: ONETIM, CASE01, CASE02, CASE03, GLDISC.
- No External Calls: The program is self-contained, relying on input from ARDIST and control data from ARCONT.
Integration with OCL and Other Programs¶
- OCL Context: Called by
AR200.ocl36.txtafterAR200generatesARDIST(?9?CRDIGG). Uses journal date fromAR200P(viaUDS) and company data fromARCONT. - Parameters: Inherits
?9?from the OCL call (AR210section), setting file labels (e.g.,GGCRDIGG,GGCRTGGG). - Flow: Outputs
ARTEMG(?9?CRTGGG), which is sorted by#GSORTand processed byAR211for GL posting. - Switches: No explicit switch settings, but
AR200P’s cancellation (U1) would preventAR210from running if the OCL cancels early.
Notes¶
- Y2K Compliance: Relies on
Y2KCENandY2KCMPfor date handling, thoughADJRDTis likely pre-validated byAR200P. - Description Change: The 4/20/05 modification ensures the full 25-character
ADDESCis preserved, with the journal date moved to the second description field inARTEMG. - No Reporting: Unlike
AR200, this program is data-focused, producing no reports, only GL journal entries. - Balancing: Accumulates
DBTOTandCRTOTfor internal validation, likely checked byAR211or later processes.
If you have additional source code (e.g., AR211, AR2011, or file layouts for ARDIST, ARTEMG), I can provide a deeper analysis of the data flow or GL posting. Let me know if you need further clarification or specific details!