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:
- Program Initialization:
- 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).
- Defines arrays and data structures:
SEP
(2-element array for separator lines).ARC
(25-element array, 6 bytes each, for customer numbers fromARCLGR
).- Data structure
UDS
withCO
(company code, 2 digits) andKYCANC
(cancel key, 6 characters).
- Input specifications define fields for each file (e.g.,
ARKEY
,ARCO
,ARCUST
,ARNAME
,ARTOTD
,ARCLMT
, etc.). -
Initializes variables like
TIMDAT
,SYTIME
, andSYDATE
for report headers. -
Company-Level Processing (
L2
Loop): -
For each company (
L2
control break onARCO
):- Chains to
BICONT
usingCO
to retrieve company name (BCNAME
). - Sets separator line (
SEP = '* '
) and captures system time (SYTIME
) and date (SYDATE
) using theTIME
operation. - Prints company-level headings on both
ARLIST
(viaPRTL2
) andARLIS2
(viaPRTL22
) output files.
- Chains to
-
Customer-Level Processing (
L1
Loop): -
For each customer (
L1
control break onARCUST
):- Initializes variables:
OVER
,LIMIT
,OWED
,ORDVAL
,TRXVAL
to zero, and clears indicator93
. - Chains to
ARCLGR
usingARKEY
(positions 2–9) to retrieve customer numbers in theARC
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
usingCUSKEY
to get customer data (AXCLMT
,AXTOTD
). - If found (
*IN93 = *OFF
) andAXCLMT <> 0
, addsAXCLMT
toLIMIT
. - Adds
AXTOTD
toOWED
. - Processes
BBORCL
records for the customer (usingBCLKEY
=HLD8
): - Sets lower limit (
SETLL
) and readsBBORCL
until EOF (*IN66
) or customer mismatch (*IN79
). - Skips deleted records (
BLDEL = 'D'
). - Adds
BLTAMT
(unposted amount) toTRXVAL
andOWED
if non-zero. - Adds
BLOAMT
(order amount) toORDVAL
andOWED
if non-zero.
- Constructs
- Initializes variables:
-
Primary Customer Processing:
-
After the
ARCLGR
loop, processes the primaryARCUST
record:- If
LIMIT = 0
, setsLIMIT = ARCLMT
(fromARCUST
). - Adds
ARTOTD
toOWED
. - Processes
BBORCL
records again for the customer (usingBCLKEY = ARKEY
): - Similar logic to above: skips deleted records, adds
BLTAMT
toTRXVAL
andOWED
, addsBLOAMT
toORDVAL
andOWED
. - If
BLOVCL = 'Y'
(over credit limit), prints an over-limit line (OVRLNE
) toARLIS2
with order details (BLORDR
,BLTAMT
,BLBTCH
).
- If
-
Credit Limit Check and Output:
- Calculates
OVER = LIMIT - OWED
. - If
OVER < 0
, sets indicator44
to indicate the customer is over their credit limit. -
Prints customer details to
ARLIST
(viaPRTL2
):- Includes
ARCUST
,ARNAME
,ARCLMT
,ARTOTD
,ORDVAL
,TRXVAL
, andOVER
(with “OVER CREDIT LIMIT” if*IN44 = *ON
).
- Includes
-
Report Output:
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.
- Prints company name (
-
ARLIS2
report:- Prints similar headers but focuses on “ORDERS OVER CREDIT LIMIT”.
- Lists orders exceeding credit limits with
BLORDR
,BLTAMT
, andBLBTCH
.
-
Program Termination:
- The program ends after processing all
ARCUST
records, triggered by the end of the input file.
Business Rules¶
- Company Validation:
- The program processes data for a specific company (
CO
), retrieving the company name fromBICONT
. -
If the company is not found in
BICONT
, processing continues with default values. -
Customer Credit Calculation:
- Aggregates credit limit (
LIMIT
) fromARCUSA
(AXCLMT
) orARCUST
(ARCLMT
). - Calculates total owed (
OWED
) by summing:ARTOTD
(total due fromARCUST
).AXTOTD
(total due fromARCUSA
for customers inARCLGR
).BLTAMT
(unposted amounts fromBBORCL
).BLOAMT
(order amounts fromBBORCL
).
-
Tracks
TRXVAL
(unposted amounts) andORDVAL
(order amounts) separately. -
Over Credit Limit Detection:
- A customer is over their credit limit if
OVER = LIMIT - OWED < 0
. -
Orders marked as over credit limit (
BLOVCL = 'Y'
) inBBORCL
are printed in theARLIS2
report. -
Data Filtering:
- Skips deleted customers (
CGDEL = 'D'
inARCLGR
) and deleted orders (BLDEL = 'D'
inBBORCL
). -
Only processes non-zero amounts (
BLTAMT
,BLOAMT
,AXCLMT
,AXTOTD
). -
Report Formatting:
- 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.
- 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.