Skip to content

AR210 RPG36

The provided document, AR210.rpg36.txt, is an RPG III program used in an IBM AS/400 or iSeries environment, called by the OCL script AR201.ocl36.txt. Its primary function is to create journal entries for accounts receivable (A/R) transactions (invoices, adjustments, payments, and miscellaneous amounts) in the temporary general ledger file (ARTEMG) for further processing by the general ledger system. Below, I’ll explain the process steps, business rules, tables used, and external programs called.

Process Steps of the RPG Program (AR210)

The AR210 program processes records from the A/R distribution file (ARDIST), generates debit and credit journal entries for the temporary general ledger file (ARTEMG), and handles discounts and inter-company transactions. Here’s a step-by-step breakdown:

  1. Program Initialization:
  2. Files Defined:
    • Input: ARDIST (primary input, 161 bytes), ARCONT (A/R control, 256 bytes, keyed by company, shared access).
    • Output: ARTEMG (temporary general ledger file, 128 bytes).
  3. Data Structures:
    • UDS: User data structure with fields for user ID (USERID), workstation ID (WSID), sales journal number (SJ##), ledger retention flag (LDRETL), and Y2K variables (Y2KCEN = 19, Y2KCMP = 80).
  4. Initial Setup:

    • Clears discount amount (DISAMT) and indicator 82 (discount < 0).
    • Executes one-time setup (ONETIM) if not already done (N98).
  5. One-Time Setup (ONETIM):

  6. Captures system time (TIMEOF).
  7. Chains to ARCONT using company code (ADCO) to retrieve control data (e.g., ACTRGL, G/L account for inter-company transactions).
  8. Sets transaction type indicators:
    • 01 (invoice): Sets 61.
    • 02 (adjustment): Sets 61.
    • 03 (payment): Sets 63.
  9. Sets indicator 98 to mark setup completion.

  10. Main Processing Loop:

  11. Processes ARDIST records sequentially, identified by record type:
    • 01 (invoice, CI).
    • 02 (adjustment, CJ).
    • 03 (payment, CP).
  12. Adjusts transaction amount (ADAMT):
    • If miscellaneous amount exists (86) and not zero (N16), subtracts ADMISC from ADAMT (sets 81 if negative).
    • If miscellaneous and zero amount (16, 86), sets ADAMT to ADMISC (sets 81 if negative).
  13. Handles discount amount:

    • If discount exists (51), sets DISAMT to ADDISC.
    • If DISAMT is negative (82), multiplies by -1 to make positive.
  14. Transaction Processing:

  15. Case Selection:
    • If amount is non-negative (N81), executes CASE01 (standard debit/credit entries).
    • If amount is negative (81), executes CASE02 (reversed debit/credit entries).
    • If company codes differ (ADCODR ≠ ADCO or ADCOCR ≠ ADCO, indicator 54), executes CASE03 (inter-company entries) and adjusts ADAMT if negative.
  16. Discount Processing:

    • If discount exists (51), sets ADCODR to ADCODI (cash invoice company) and executes GLDISC to create a discount journal entry.
    • Adds DISAMT to debit total (DBTOT, if N82) or credit total (CRTOT, if 82).
  17. Standard Entries (CASE01):

  18. For payments (63):
    • If discount non-negative (N82), debit amount = ADAMT - DISAMT.
    • If discount negative (82), debit amount = ADAMT + DISAMT.
  19. For invoices/adjustments (N63), debit amount = ADAMT.
  20. Writes debit entry to ARTEMG:
    • Company: DRCO (ADCODR).
    • Journal: ADJRNL.
    • Type: D (debit).
    • Account: DRACCT (ADGLDR).
    • Customer: ADNAME.
    • Invoice: ADINV#.
    • Date: ADJRDT.
    • Amount: DRAMT.
    • Description: ADDESC.
  21. Sets indicator 30, writes, then clears 30.
  22. Adds DRAMT to DBTOT.
  23. Writes credit entry:

    • Company: CRCO (ADCOCR).
    • Journal: ADJRNL.
    • Type: C (credit).
    • Account: CRACCT (ADGLCR).
    • Amount: CRAMT (ADAMT).
    • Sets indicator 31, writes, then clears 31.
    • Adds CRAMT to CRTOT.
  24. Negative Amount Entries (CASE02):

  25. Writes debit entry:
    • Amount: DRAMT = -ADAMT.
    • Account: DRACCT (ADGLCR).
    • Company: DRCO (ADCOCR).
    • Type: D.
    • Sets indicator 32, writes, then clears 32.
    • Adds DRAMT to DBTOT.
  26. Writes credit entry:

    • For payments (63):
    • If discount non-negative (N82), CRAMT = -ADAMT + DISAMT.
    • If discount negative (82), CRAMT = -ADAMT - DISAMT.
    • For invoices/adjustments (N63), CRAMT = -ADAMT.
    • Account: CRACCT (ADGLDR).
    • Company: CRCO (ADCODR).
    • Type: C.
    • Sets indicator 33, writes, then clears 33.
    • Adds CRAMT to CRTOT.
  27. Inter-Company Entries (CASE03):

  28. Writes two entries to ARTEMG:

    • Credit Entry:
    • Amount: ICRAMT = ADAMT ± DISAMT (subtract if N82, add if 82).
    • Company: ICRCO (ADCODR).
    • Account: ICRGL8 (ACTRGL + ADCOCR).
    • Type: C if N81, D if 81.
    • Debit Entry:
    • Amount: IDRAMT = ADAMT ± DISAMT.
    • Company: IDRCO (ADCOCR).
    • Account: IDRGL8 (ACTRGL + ADCODR).
    • Type: D if N81, C if 81.
    • Both entries include ADJRNL, ADNAME, ADINV#, ADJRDT, ADDESC.
    • Sets indicator 34, writes, then clears 34.
  29. Discount Entry (GLDISC):

  30. Writes discount entry to ARTEMG:
    • Company: ADCODI.
    • Journal: ADJRNL.
    • Type: D if N82, C if 82.
    • Account: ADGLDI.
    • Amount: DISC11 (DISAMT).
    • Customer: ADNAME.
    • Invoice: ADINV#.
    • Date: ADJRDT.
    • Description: ADDESC.
  31. Sets indicator 35, writes, then clears 35.

Business Rules

  1. Transaction Types:
  2. Invoices (01, CI) and adjustments (02, CJ): Generate debit (ADGLDR) and credit (ADGLCR) entries.
  3. Payments (03, CP): Generate debit and credit entries, adjusted for discounts.
  4. Miscellaneous amounts (86): Adjust ADAMT by subtracting ADMISC (if non-zero) or setting to ADMISC (if zero).

  5. Discount Handling:

  6. Discounts (ADDISC, indicator 51) are recorded as separate entries with ADCODI (company) and ADGLDI (account).
  7. Negative discounts (82) are converted to positive for journal entries.
  8. Discounts adjust debit/credit amounts in payment entries.

  9. Inter-Company Transactions:

  10. If company codes differ (ADCODR ≠ ADCO or ADCOCR ≠ ADCO, 54), generates entries using inter-company G/L account (ACTRGL) from ARCONT.
  11. Debit and credit types are swapped based on amount sign (81).

  12. Amount Sign Handling:

  13. Positive amounts (N81): Standard debit/credit entries.
  14. Negative amounts (81): Reverses debit/credit accounts and adjusts amounts.

  15. Journal Entry Structure:

  16. Entries include company, journal number, debit/credit type, G/L account, customer name, invoice number, journal date, amount, and description.
  17. Description field (ADDESC) retains full 25 characters from cash receipts, with date moved to the second description field in ARTEMG (per 4/20/05 change).

  18. Accumulation:

  19. Tracks debit (DBTOT) and credit (CRTOT) totals for balancing.

  20. Y2K Compliance:

  21. Uses Y2KCEN (19) and Y2KCMP (80) for date handling, though no explicit date conversion occurs in this program (dates are pre-converted in AR200).

Tables Used

The program uses the following files (tables): 1. Input Files: - ARDIST (F-spec 0007): A/R distribution file (161 bytes, primary input) from AR200 (?9?ARDIGG). - ARCONT (0009): A/R control file (256 bytes, input mode, keyed by company, shared access).

  1. Output Files:
  2. ARTEMG (0008): Temporary general ledger file (128 bytes, output mode) for journal entries (?9?ARTGGG).

  3. Compile-Time Data:

  4. None defined.

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 system time and control file access. - CASE01: Processes standard debit/credit entries for non-negative amounts. - CASE02: Processes reversed debit/credit entries for negative amounts. - CASE03: Handles inter-company entries. - GLDISC: Creates discount journal entries.

Notes

  • Modification (4/20/05): Enhanced description field handling to retain 25 characters from cash receipts, with the date moved to the second description field in ARTEMG.
  • Indicators:
  • 16: Zero amount.
  • 51: Non-zero discount.
  • 52: Non-zero G/L credit account.
  • 53: Non-zero G/L debit account.
  • 61: Invoice or adjustment.
  • 63: Payment.
  • 81: Negative amount.
  • 82: Negative discount.
  • 86: Non-zero miscellaneous amount.
  • File Access: ARCONT is shared (DISP-SHR) for concurrent access.
  • Output: ARTEMG entries are formatted for sorting and posting by AR211.

If you have additional details (e.g., source for AR211 or file layouts), I can provide further analysis. Let me know if you need clarification or more information!