Skip to content

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:

  1. Program Setup and File Definitions:
  2. 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 in ARTEMG.
  3. 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).
  4. 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.
  5. Output Specifications (O Specs):

    • Defines ARTEMG output 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.
  6. Initialization:

  7. Sets DISAMT (discount amount) to zero and turns off indicator 82 (discount < 0).
  8. Executes ONETIM subroutine (if indicator 98 is off):

    • Captures system time (TIMEOF).
    • Chains to ARCONT using ADCO (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.
  9. Main Processing Loop:

  10. Processes each ARDIST record:

    • Miscellaneous Amount Handling:
    • If indicator 86 (miscellaneous amount ADMISC ≠ 0) and 16 (amount = 0), sets ADAMT = ADMISC (miscellaneous cash).
    • If 86 on and 16 off, subtracts ADMISC from ADAMT to isolate the net amount.
    • Discount Handling:
    • If indicator 51 (discount ADDISC ≠ 0), sets DISAMT = ADDISC.
    • If indicator 82 (discount < 0), multiplies DISAMT by -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) with ADCO to set indicator 54 (mismatch).
    • If 54 on and 81 on, negates ADAMT and runs CASE03 (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 calls GLDISC to generate a discount entry.
    • Adds DISAMT to debit total (DBTOT) if 82 off, or credit total (CRTOT) if 82 on.
  11. Subroutine CASE01 (Positive Amount):

  12. 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 DRAMT to DBTOT.
    • Credit Entry:
    • Sets CRAMT = ADAMT, credit account (CRACCT = ADGLCR), company (CRCO = ADCOCR), and type (DORC = 'C').
    • Writes credit entry to ARTEMG (indicator 31).
    • Adds CRAMT to CRTOT.
  13. Subroutine CASE02 (Negative Amount):

  14. Handles negative transaction amounts (ADAMT < 0):

    • Debit Entry:
    • Sets DRAMT = -ADAMT, DRACCT = ADGLCR, DRCO = ADCOCR, DORC = 'D'.
    • Writes debit entry (indicator 32).
    • Adds DRAMT to DBTOT.
    • Credit Entry:
    • If payment (63 on), CRAMT = -ADAMT, adjusted by DISAMT (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 CRAMT to CRTOT.
  15. Subroutine CASE03 (Inter-Company Transactions):

  16. Handles transactions where company codes differ (ADCODRADCO or ADCOCRADCO):

    • Credit Entry:
    • Sets ICRAMT = ADAMT ± DISAMT (subtract if 82 off, add if 82 on).
    • Uses ACTRGL (AR control GL account) and ADCOCR for ICRGL8, company ICRCO = ADCODR.
    • Sets IC = 'C' if ADAMT ≥ 0 (81 off), else IC = 'D'.
    • Writes entry to ARTEMG (indicator 34).
    • Debit Entry:
    • Sets IDRAMT = ADAMT ± DISAMT.
    • Uses ACTRGL and ADCODR for IDRGL8, company IDRCO = ADCOCR.
    • Sets ID = 'D' if ADAMT ≥ 0, else ID = 'C'.
    • Writes entry to ARTEMG (indicator 34).
  17. Subroutine GLDISC (Discount Entry):

  18. 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 to ARTEMG (indicator 35).
  19. Subroutine ONETIM:

  20. Runs once to initialize:

    • Captures system time (TIMEOF).
    • Chains to ARCONT for company-specific data.
    • Sets indicators 61 (invoice/adjustment) or 63 (payment) based on ARDIST record type (01, 02, 03).
    • Sets indicator 98 to prevent re-running.
  21. Output to ARTEMG:

  22. 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.
  23. Program Termination:

    • Ends when ARDIST input is exhausted.
    • Accumulates totals (DBTOT, CRTOT) for balancing but does not write them to output (used by later programs).

Business Rules

The program enforces accounting rules for generating GL journal entries from AR distributions:

  1. Transaction Types:
  2. Invoices (01, CI) and Adjustments (02, CJ): Generate debit and credit entries using ADGLDR and ADGLCR, respectively.
  3. Payments (03, CP): Adjust amounts by discounts (ADDISC) and generate entries.
  4. Miscellaneous Cash (86): If ADAMT = 0, use ADMISC as the amount; otherwise, subtract ADMISC from ADAMT.
  5. Discounts (51): Generate separate GL entries using ADGLDI (discount account).

  6. Debit and Credit Entries:

  7. For positive amounts (ADAMT ≥ 0):
    • Debit: ADGLDR, adjusted by discount if payment.
    • Credit: ADGLCR.
  8. For negative amounts (ADAMT < 0):
    • Debit: ADGLCR (reverses account).
    • Credit: ADGLDR, adjusted by discount if payment.
  9. Entries include company, journal number, customer, invoice, date, and description.

  10. Inter-Company Transactions:

  11. If debit/credit company codes (ADCODR, ADCOCR) differ from ADCO (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.
  12. Discount Handling:

  13. Discounts (ADDISC) are applied to payment amounts and generate separate GL entries with ADGLDI.
  14. Negative discounts are inverted for reporting.
  15. Discount entries are debit if positive, credit if negative.

  16. Y2K Compliance:

  17. Uses Y2KCEN (century, e.g., 19 or 20) and Y2KCMP (comparison year, e.g., 80) for date handling, though ADJRDT is assumed pre-validated by AR200P.

  18. Summarization:

  19. Most entries are marked for summarization ('S' at position 96) for GL posting by AR211.
  20. Payment entries with specific conditions (indicators 63 and 40) may omit the summarize flag.

  21. Audit and Control:

  22. Tracks totals (DBTOT, CRTOT) for balancing.
  23. Includes user ID (USERID), workstation ID (WSID), and journal number (SJ##) for traceability.
  24. 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:

  1. Input Files:
  2. ARDIST (?9?CRDIGG): AR distribution file, primary input, 161 bytes, contains transaction details.
  3. ARCONT (?9?ARCONT): AR control file, input with control, 256 bytes, keyed, provides GL account (ACTRGL).

  4. Output Files:

  5. ARTEMG (?9?CRTGGG): Temporary GL journal file, output, 128 bytes, contains debit/credit entries for GL posting.

  6. No Printer Files:

  7. Unlike AR200, this program produces no reports, focusing solely on data output to ARTEMG.

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.txt after AR200 generates ARDIST (?9?CRDIGG). Uses journal date from AR200P (via UDS) and company data from ARCONT.
  • Parameters: Inherits ?9? from the OCL call (AR210 section), setting file labels (e.g., GGCRDIGG, GGCRTGGG).
  • Flow: Outputs ARTEMG (?9?CRTGGG), which is sorted by #GSORT and processed by AR211 for GL posting.
  • Switches: No explicit switch settings, but AR200P’s cancellation (U1) would prevent AR210 from running if the OCL cancels early.

Notes

  • Y2K Compliance: Relies on Y2KCEN and Y2KCMP for date handling, though ADJRDT is likely pre-validated by AR200P.
  • Description Change: The 4/20/05 modification ensures the full 25-character ADDESC is preserved, with the journal date moved to the second description field in ARTEMG.
  • No Reporting: Unlike AR200, this program is data-focused, producing no reports, only GL journal entries.
  • Balancing: Accumulates DBTOT and CRTOT for internal validation, likely checked by AR211 or 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!