AR781 RPG36
Overview of AR781¶
AR781 is the main processing program in the three-program batch chain (AR781P → AR781 → AR781A). It is an RPG II program written for the IBM System/36 environment (or AS/400 in S/36 compatibility mode).
Its purpose is to: - Take the pre-filtered list of group/parent customers (from AR780I, created by AR781P) that have at least one open order flagged as over credit limit and not yet authorized. - For each such group customer, aggregate all related customers in the same credit-limit group (via ARCLGR). - Calculate group-level credit exposure: - Total A/R balance and aging (current + past due) - Open approved orders - Open orders not yet approved (over limit and unauthorized) - Available credit - Determine which individual open order lines are eligible for release from credit hold. - Write qualifying order lines to CREDREL (detail file) and group summaries to CREDRLH (header file). - Print a report titled "CREDIT HOLD ELIGIBLE FOR RELEASE REPORT" showing group summaries and eligible orders.
This report helps credit managers decide which held orders can be safely released.
Process Steps (High-Level Flow)¶
- Initialization (ONCE block):
- Runs once at program start.
- Gets current date/time and formats it.
- Chains to ARCONT (likely company control) using a company number to retrieve aging bucket definitions (ACLMT1–ACLMT4) for display on the report header.
-
Outputs the report heading (company name, title, page, date/time, aging buckets).
-
Main Loop – Process each group customer from AR780I:
- Reads AR780I sequentially (input primary file, indicator 01).
-
For each record (each qualifying group customer):
- Uses the group key (company + group customer number) to read the ARCLGR (credit limit group) file, which contains an array of up to 200 member customers belonging to the same credit group.
- Loops through all non-deleted member customers in the group:
- Chains to ARCUST to get A/R balances (total due, current, aging buckets).
- Accumulates group-level totals:
- Total A/R due (
S2TOTD) - Aging buckets (
S2CURD,S20110, etc.) - Past-due amount (
ARPBAM= sum of all overdue buckets)
- Total A/R due (
- If a member has a non-zero credit limit, uses it as the group credit limit (
S2CLMT). - Reads all open order lines (BBORCL) for every member customer in the group.
- Calculates order amount (
BLAMT=BLTAMTif non-zero, elseBLOAMT). - Classifies each order line:
- Approved orders: either not over limit (
BLOVCL ≠ 'Y') or over limit but already authorized (BLAUIN ≠ blank). - Not approved (pending): over limit and no authorization.
- Approved orders: either not over limit (
- Accumulates:
S2ORAP= total value of approved ordersS2ONAP= total value of pending (over-limit, unauthorized) orders
- Calculates available credit:
S2AVCL = S2CLMT – S2TOTD – S2ORAP(credit limit minus A/R minus approved open orders)
-
Determine eligibility of individual pending orders:
-
For each pending order line (over limit, no authorization):
- Checks two business rules:
- Customer is not flagged as a chronic credit problem (
ARCLPB ≠ 'Y'). - There is enough available credit for this specific order:
S2AVCL – order amount > 0 - If both true → the order is eligible for release:
- Sets status message "THIS ORDER IS ELIGIBLE FOR RELEASE"
- Outputs a detail record to CREDREL
- Outputs/adds to header record in CREDRLH (if not already exists)
- If not eligible:
- If
ARCLPB = 'Y'→ "HAS PAST DUE BALANCE - NOT ELIGIBLE" (actually the message is for past-due, but code uses a different message for problem customers) - If not enough available credit → status reflects that.
-
Report Output:
- Prints a header for each group with:
- Group customer number, name, address, contact, phone
- Group totals: total due, credit limit, approved orders, available credit, pending orders
- Prints detail lines for each eligible order line.
Key Business Rules¶
- Credit limit is shared at the group level (parent/group customer).
- Available credit calculation:
- Available = Credit Limit – (A/R Total Due + Value of Approved Open Orders)
- An order is eligible for release only if:
- It is currently over credit limit and not yet authorized.
- The customer is not marked as a credit problem (
ARCLPB ≠ 'Y'). - Adding this order would not make available credit negative (i.e., there is room under the limit after considering A/R and approved orders).
- Past-due balances:
- The program accumulates past-due amounts but does not automatically block release due to past-due (except if
ARCLPB = 'Y'). - Message 03 ("HAS PAST DUE BALANCE - NOT ELIGIBLE") is defined but not clearly used in visible logic — likely a remnant or used elsewhere.
- Authorization:
- Manual override via initials (
BLAUIN) or user ID (BLUSID) marks an order as approved even if over limit.
Tables/Files Used¶
| File | Type | Description | Access Mode | Key Usage |
|---|---|---|---|---|
| AR780I | Input (Primary) | Intermediate file from AR781P – list of group customers with potential over-limit orders | Sequential read | Driver file |
| ARCONT | Input | Company control / aging bucket definitions | Random chain | Once at start |
| ARCUST | Input | Customer master (A/R balances, credit limit, addresses, group info) | Random chain | Multiple times |
| ARCUSP | Input | Customer special/contact info | Not clearly used in visible code | Likely for contact name |
| BBORCL | Input | Open order lines (backlog) | Sequential + SETLL/READ | By customer |
| ARCLGR | Input | Credit limit group file (array of member customers) | Random chain | Group members |
| BBORDR | Input | Order header (used to get order-taker initials) | Random chain | By order number |
| CREDREL | Output | Detail file – one record per eligible order line | Add (EADD) | Written when eligible |
| CREDRLH | Output (Update) | Header/summary file – one record per group customer | Add/Chain | Written/updated |
| JBLIST / REPORT | Output | Printer file – spooled report output | EXCPT | Report |
External Programs Called¶
- None in the provided source code.
- There are comments referencing a "CALL AUTHORIZATION ROUTINE" and subroutines like
S2FILL, but no actualCALLstatement to an external program. - All logic is internal subroutines (
EXSR).
Summary¶
AR781 is the core of the credit release process. It performs group-level credit analysis, identifies which specific held orders can be safely released without exceeding the group credit limit (assuming no credit problem flag), and produces both data files (CREDREL/CREDRLH) for downstream use (likely by AR781A for final sorted reporting) and a detailed printed report for credit staff review. This was a classic batch decision-support tool in older ERP/AR systems.