Skip to content

AR415 RPG36

The provided document, AR415.rpg36.txt, is an RPG III program (RPG/400) on the IBM i (AS/400) platform, called by the OCL program AR415.ocl36.txt. This program generates a Customers Over Credit Report, processing customer data to identify and report customers whose total due amounts exceed their credit limits. It uses multiple files to gather customer, order, and ledger data, producing two printed reports: one for all customers and another for orders exceeding credit limits. Below, I’ll explain the process steps, business rules, tables used, and any external programs called.


Process Steps of the AR415 RPG Program

The AR415 program processes customer data by company, calculates credit-related metrics, and generates two printed reports (ARLIST and ARLIS2). Here’s a step-by-step breakdown of the process:

  1. Program Initialization:
  2. The program defines files:
    • ARCUST (input primary, 384 bytes, sorted input from #GSORT).
    • ARCUSA (input chained, 384 bytes, keyed at position 2).
    • BBORCL (input file, 256 bytes, keyed at position 2).
    • BICONT (input file, 256 bytes, keyed at position 2).
    • ARCLGR (input chained, 240 bytes, keyed at position 2).
    • ARLIST (output, 164 bytes, primary printer file).
    • ARLIS2 (output, 164 bytes, secondary printer file for over-limit orders).
  3. Defines arrays and data structures:
    • SEP (2-element array for separator lines).
    • ARC (25-element array, 6 bytes each, for customer numbers from ARCLGR).
    • Data structure UDS with CO (company code, 2 digits) and KYCANC (cancel key, 6 characters).
  4. Input specifications define fields for each file (e.g., ARKEY, ARCO, ARCUST, ARNAME, ARTOTD, ARCLMT, etc.).
  5. Initializes variables like TIMDAT, SYTIME, and SYDATE for report headers.

  6. Company-Level Processing (L2 Loop):

  7. For each company (L2 control break on ARCO):

    • Chains to BICONT using CO to retrieve company name (BCNAME).
    • Sets separator line (SEP = '* ') and captures system time (SYTIME) and date (SYDATE) using the TIME operation.
    • Prints company-level headings on both ARLIST (via PRTL2) and ARLIS2 (via PRTL22) output files.
  8. Customer-Level Processing (L1 Loop):

  9. For each customer (L1 control break on ARCUST):

    • Initializes variables: OVER, LIMIT, OWED, ORDVAL, TRXVAL to zero, and clears indicator 93.
    • Chains to ARCLGR using ARKEY (positions 2–9) to retrieve customer numbers in the ARC array.
    • If ARCLGR is found (*IN95 = *OFF) and not deleted (CGDEL <> 'D'):
    • Loops through the ARC array (up to 25 customer numbers):
      • Constructs CUSKEY (company + customer number).
      • Chains to ARCUSA using CUSKEY to get customer data (AXCLMT, AXTOTD).
      • If found (*IN93 = *OFF) and AXCLMT <> 0, adds AXCLMT to LIMIT.
      • Adds AXTOTD to OWED.
      • Processes BBORCL records for the customer (using BCLKEY = HLD8):
      • Sets lower limit (SETLL) and reads BBORCL until EOF (*IN66) or customer mismatch (*IN79).
      • Skips deleted records (BLDEL = 'D').
      • Adds BLTAMT (unposted amount) to TRXVAL and OWED if non-zero.
      • Adds BLOAMT (order amount) to ORDVAL and OWED if non-zero.
  10. Primary Customer Processing:

  11. After the ARCLGR loop, processes the primary ARCUST record:

    • If LIMIT = 0, sets LIMIT = ARCLMT (from ARCUST).
    • Adds ARTOTD to OWED.
    • Processes BBORCL records again for the customer (using BCLKEY = ARKEY):
    • Similar logic to above: skips deleted records, adds BLTAMT to TRXVAL and OWED, adds BLOAMT to ORDVAL and OWED.
    • If BLOVCL = 'Y' (over credit limit), prints an over-limit line (OVRLNE) to ARLIS2 with order details (BLORDR, BLTAMT, BLBTCH).
  12. Credit Limit Check and Output:

  13. Calculates OVER = LIMIT - OWED.
  14. If OVER < 0, sets indicator 44 to indicate the customer is over their credit limit.
  15. Prints customer details to ARLIST (via PRTL2):

    • Includes ARCUST, ARNAME, ARCLMT, ARTOTD, ORDVAL, TRXVAL, and OVER (with “OVER CREDIT LIMIT” if *IN44 = *ON).
  16. Report Output:

  17. ARLIST report:
    • Prints company name (BCNAME), date (SYDATE), time (SYTIME), and page number.
    • Includes headers for “CREDIT LIMIT”, “TOTAL DUE”, “OPEN ORDERS TOTAL”, “UNPOSTED AMOUNT”, and “AVAIL CREDIT”.
    • Lists customer data with over-limit indication.
  18. ARLIS2 report:

    • Prints similar headers but focuses on “ORDERS OVER CREDIT LIMIT”.
    • Lists orders exceeding credit limits with BLORDR, BLTAMT, and BLBTCH.
  19. Program Termination:

  20. The program ends after processing all ARCUST records, triggered by the end of the input file.

Business Rules

  1. Company Validation:
  2. The program processes data for a specific company (CO), retrieving the company name from BICONT.
  3. If the company is not found in BICONT, processing continues with default values.

  4. Customer Credit Calculation:

  5. Aggregates credit limit (LIMIT) from ARCUSA (AXCLMT) or ARCUST (ARCLMT).
  6. Calculates total owed (OWED) by summing:
    • ARTOTD (total due from ARCUST).
    • AXTOTD (total due from ARCUSA for customers in ARCLGR).
    • BLTAMT (unposted amounts from BBORCL).
    • BLOAMT (order amounts from BBORCL).
  7. Tracks TRXVAL (unposted amounts) and ORDVAL (order amounts) separately.

  8. Over Credit Limit Detection:

  9. A customer is over their credit limit if OVER = LIMIT - OWED < 0.
  10. Orders marked as over credit limit (BLOVCL = 'Y') in BBORCL are printed in the ARLIS2 report.

  11. Data Filtering:

  12. Skips deleted customers (CGDEL = 'D' in ARCLGR) and deleted orders (BLDEL = 'D' in BBORCL).
  13. Only processes non-zero amounts (BLTAMT, BLOAMT, AXCLMT, AXTOTD).

  14. Report Formatting:

  15. Produces two reports:
    • ARLIST: Lists all customers with credit limit, total due, open orders, unposted amounts, and available credit.
    • ARLIS2: Lists specific orders exceeding credit limits with order number, unposted amount, and batch number.
  16. Includes company name, date, time, and page numbers in headers.

Tables (Files) Used

The program uses the following files: 1. ARCUST (IP, input primary, 384 bytes): - Sorted input file (from #GSORT in the OCL). - Fields: ARKEY (2–9, key), ARCO (2–3, company), ARCUST (4–9, customer), ARNAME (10–39, customer name), ARTOTD (174–179, packed total due), ARCLMT (252–256, packed credit limit). 2. ARCUSA (IC, input chained, 384 bytes, keyed at 2): - Alternate customer file. - Fields: AXCUST (4–9, customer), AXTOTD (174–179, packed total due), AXCLMT (252–256, packed credit limit). 3. BBORCL (IF, input file, 256 bytes, keyed at 2): - Order file. - Fields: BLCOCU (2–9, company/customer key), BLDEL (1, delete code), BLCONO (2–3, company), BLCUST (4–9, customer), BLORDR (10–15, order number), BLBTCH (16–17, batch number), BLTAMT (18–26, unposted amount), BLOAMT (27–35, order amount), BLOVCL (36, over limit Y/N), BLAUIN (37–39, authorization initials), BLUSID (40–47, user ID). 4. BICONT (IF, input file, 256 bytes, keyed at 2): - Company control file. - Fields: BCNAME (4–33, company name), BCINST (92, invoicing style). 5. ARCLGR (IC, input chained, 240 bytes, keyed at 2): - Ledger file with customer numbers. - Fields: CGDEL (1, delete code), ARC (10–159, array of 25 customer numbers, 6 bytes each). 6. ARLIST (O, output, 164 bytes, printer): - Primary report file for customer credit data. 7. ARLIS2 (O, output, 164 bytes, printer): - Secondary report file for over-limit orders.


External Programs Called

The AR415 program does not call any external programs. It performs all processing internally, relying on file I/O and printer output operations.


Summary

Process Steps: - Initializes files, arrays, and variables. - Processes each company (L2), retrieving company name and printing headers. - For each customer (L1): - Aggregates credit limits and amounts owed from ARCUST, ARCUSA, and BBORCL. - Processes ARCLGR to include additional customer data. - Calculates over-credit status and prints to ARLIST (all customers) and ARLIS2 (over-limit orders). - Terminates after processing all records.

Business Rules: - Validates company and skips deleted customers/orders. - Aggregates total owed from multiple sources (ARTOTD, AXTOTD, BLTAMT, BLOAMT). - Identifies customers over credit limits (OVER < 0) and orders marked as over limit (BLOVCL = 'Y'). - Produces formatted reports with headers and detailed data.

Files Used: ARCUST, ARCUSA, BBORCL, BICONT, ARCLGR, ARLIST, ARLIS2. External Programs: None.