Skip to content

AR822 RPGLE

The AR822R.rpgle.txt RPG program, written in RPG/36 (or early RPG IV) for the IBM System/36 or AS/400, is designed for Price Lookup for Customer Service Representatives (CSR). It is called by the AR820.ocl36.txt OCL program and retrieves pricing information based on customer, product, container, and company inputs, displaying results in subfiles on a workstation screen. Below is a detailed explanation of the process steps, business rules, tables/files used, and external programs called.


Process Steps of the RPG Program

The program operates in a loop, processing user input and displaying pricing data in multiple subfiles (SFLC1, SFLC2, SFLC3, SFLC4) for different pricing scenarios (e.g., sales agreements, rack pricing, or no pricing). It handles input validation, retrieves data from various files, and supports navigation via function keys. The program uses subroutines to modularize logic. Here’s a step-by-step breakdown:

  1. File and Data Definitions:
  2. Files:
    • AR822RD: Workstation file with four subfiles (SFLC1, SFLC2, SFLC3, SFLC4) for displaying pricing data.
    • BBPRCY: Rack pricing file (128 bytes, keyed by company, location, product, container).
    • BICUA6: Sales agreement file (256 bytes, keyed by company, customer, location).
    • GSTABL: General system table (256 bytes, commented out in parts, replaced by other files).
    • GSPROD: Product master file (512 bytes, keyed by product code).
    • ARCUPR: Customer pricing file (80 bytes, keyed by company, customer, ship-to, product, and container type after JB07).
    • ARCUSP: Customer special pricing file (1344 bytes, keyed by company, customer).
    • ARCUST: Customer master file (384 bytes, keyed by company, customer).
    • SHIPTO: Ship-to address file (2048 bytes, keyed by company, customer, ship-to).
    • GSCNTR1: Container master file (512 bytes, keyed by container code).
  3. Data Structures:
    • UDS: Local data area (LDA) fields: CO (company, 2 digits), PROD (product, 4 characters), CNTR (container, 3 characters), CUST (customer, 6 characters).
    • PSDS##: Program status data structure for error handling (PS#ERR) and parameter count (PS#PRM).
    • Input specifications define fields for each file (e.g., RKDEL, RKCONO, BADEL, CPDEL, etc.).
  4. Entry Parameters (DC02):

    • Parameters (P$CO, P$PROD, P$CNTR, P$CUST) can be passed from a calling program. If none are provided, LDA values are used.
  5. Initialization (DC02, *INZSR Subroutine):

  6. Checks for passed parameters (company, product, container, customer) via *ENTRY PLIST.
  7. If parameters are passed (PS#PRM >= 1), moves them to CO, PROD, CNTR, CUST. Otherwise, uses LDA values.
  8. Error handling via *PSSR checks for invalid parameter counts (PS#ERR = 221) and sets a return code.

  9. Main Processing Loop (Lines B001–E001):

  10. The program runs in a DO loop until NEXT equals '$EOJ'.
  11. Uses a CASE structure to route control to subroutines based on the NEXT variable:

    • $XCUTC: Displays customer subfile (SFLC1).
    • $XCUTC2: Displays sales agreement subfile (SFLC2).
    • $XCUTC3: Displays no sales agreement screen (SFLC3).
    • $XCUTC4: Displays no rack pricing screen (SFLC4).
    • $SERCH: Performs rack pricing search.
    • $SERCH2: Performs sales agreement search.
    • Default: Calls $ENTRY for initial setup.
  12. $ENTRY Subroutine:

  13. Initializes screen fields (S1CUST, S1PROD, S1CNTR) from CUST, PROD, CNTR.
  14. Clears pricing and unit of measure fields (RKUNMS1, RKUNMS2, RKUNMS3, RKPRC1, RKPRC2, RKPRC3).
  15. Retrieves customer name from ARCUST using CUSKEY (company + customer); if found, sets S1NAME.
  16. Retrieves product description from GSPROD using KLPROD (company + product); if found, sets S1DESC.
  17. Retrieves container description and type from GSCNTR1 using CNTR; if found, sets S1CTDS and WKCNTY (container type, e.g., 'B', 'P').
  18. Writes initial screen (SCRE1) and sets indicators for subfile control.
  19. Handles function keys:
    • F3: Sets NEXT to '$EOJ' to exit.
    • F5: Sets NEXT to '$SERCH2' for sales agreement search.
    • F7: Sets NEXT to '$EOJ' and U7 indicator.
  20. If PO# is blank, initializes subfile control (CTLC2) and clears subfile record numbers (RRNC1, RRNC2, RRNC3, RRNC4).
  21. Sets NEXT to '$SERCH' for rack pricing search.

  22. $XCUTC, $XCUTC2, $XCUTC3, $XCUTC4 Subroutines:

  23. Each subroutine displays a specific subfile (SFLC1, SFLC2, SFLC3, SFLC4) by writing control records (SCRC1, SCRC2, SCRC3, SCRC4) and formatting the subfile (EXFMT).
  24. Handles function keys:
    • F3: Sets NEXT to '$EOJ' to exit.
    • F5 (for $XCUTC, $XCUTC4): Sets NEXT to '$SERCH2' for sales agreement search.
    • F7: Sets NEXT to '$EOJ' and U7 indicator.
  25. These subroutines manage the display of customer, sales agreement, no sales agreement, and no rack pricing screens, respectively.

  26. $SERCH Subroutine (Truncated, but key logic described):

  27. Searches for rack pricing in BBPRCY using keys (RKCONO, RKLOC, RKPROD, RKCNTR).
  28. Skips deleted records (RKDEL = 'D') and records where RKDATE exceeds current date (DATE).
  29. Populates subfile fields (S2PROD, S2DESC, S2QTY1, S2QTY2, S2QTY3, S2QTY4, S2PRC1, S2PRC2, S2PRC3, S2PRC4, S2MINQ) with pricing data.
  30. Calls $WRITE to write subfile records.
  31. If records are found (RRNC1 > 0), sets NEXT to '$XCUTC'. Otherwise, calls $WRITE4 and sets NEXT to '$XCUTC4' (no rack pricing).

  32. $SERCH2 Subroutine:

  33. Searches for sales agreements in BICUA6 using FLD30 (company, customer, product, container, date, and time).
  34. Skips deleted records (BADEL = 'D'), non-matching customer (BACUST), product (BAPR01), container (BACNTR), company (BACONO), or expired records (BASTD8 > DATE or BAEND8 < DATE unless BAEND8 = 0).
  35. Retrieves ship-to description from SHIPTO using BBKEY (company, customer, ship-to).
  36. Determines freight terms (S4TERM):
    • If BAFRCD is blank, chains to ARCUPR using FRTKEY (company, customer, ship-to, product, container type). If not found, tries with blank container type (JB07).
    • Sets S4TERM based on freight codes (CPFRCD, CSFRCD, BAFRCD):
    • 'C': "COLLECT" (or "COLLECT." if CPCAFR = 'Y', JB09).
    • 'A': "PPD & ADD".
    • 'P': "3RD PARTY" (if CPSFRT = 'N' and CPCAFR = 'N') or "PREPAID".
  37. Populates subfile fields (S4PRCE, S4UOFM, S4SHIP, S4LOC, S4DESC, S4MNQY, S4MXQY, S4POY, S4PORD) with sales agreement data.
  38. If BAPRCE is non-zero, uses it for S4PRCE and sets S4TYPE to 'P'. Otherwise, uses BAOFFP (percent off price) and sets S4TYPE to 'O' with yellow highlighting (JK01).
  39. Calls $WRITE2 to write subfile records.
  40. If records are found (RRNC2 > 0), sets NEXT to '$XCUTC2'. Otherwise, calls $WRITE3 and sets NEXT to '$XCUTC3' (no sales agreement).

  41. $CLEAR Subroutine:

  42. Clears subfile fields (S2PROD, S2DESC, S2QTY1, S2QTY2, S2QTY3, S2QTY4, S2PRC1, S2PRC2, S2PRC3, S2PRC4, S2MINQ, S4PRCE, S4UOFM, S4SHIP, S4LOC, S4TERM, S4TYPE, S4MNQY, S4MXQY, SVPROD, SVUNMS, SVSHIP, SVLOC, SVCUST) and resets indicators.

  43. $WRITE, $WRITE2, $WRITE3, $WRITE4 Subroutines (Truncated):

  44. Write records to subfiles SFLC1, SFLC2, SFLC3, and SFLC4, respectively, based on pricing data retrieved.

  45. Termination:

    • Exits when NEXT = '$EOJ' or function keys (F3, F7) are pressed, setting LR (last record) indicator.

Business Rules

  1. Input Handling:
  2. Accepts company (CO), product (PROD), container (CNTR), and customer (CUST) from parameters or LDA (DC02).
  3. Validates inputs by retrieving customer name (ARCUST), product description (GSPROD), and container description/type (GSCNTR1).

  4. Pricing Lookup:

  5. Rack Pricing (BBPRCY):
    • Retrieves pricing based on company, location, product, and container.
    • Skips deleted records (RKDEL = 'D') and future-dated records (RKDATE > DATE).
    • Displays quantities and prices (S2QTY1–4, S2PRC1–4, S2MINQ).
  6. Sales Agreements (BICUA6):

    • Matches records by company, customer, product, container, and ship-to location.
    • Skips deleted records (BADEL = 'D'), non-matching records, or expired records (BASTD8 > DATE or BAEND8 < DATE unless BAEND8 = 0, JB03).
    • Uses BAPRCE (price) or BAOFFP (percent off price) for S4PRCE, with S4TYPE indicating price type ('P' or 'O', JK01).
    • Displays purchase order fields (S4POY, S4PORD) if BAPORD is non-blank (JB03).
    • Retrieves ship-to city (S4DESC) from SHIPTO (DC01).
  7. Freight Terms:

  8. Determines freight terms (S4TERM) based on BAFRCD (from BICUA6), CPFRCD (from ARCUPR), or CSFRCD (from ARCUSP):
    • 'C': "COLLECT" (or "COLLECT." for freight collect with calculation, JB09).
    • 'A': "PPD & ADD".
    • 'P': "PREPAID" or "3RD PARTY" (based on CPSFRT and CPCAFR).
  9. For non-fluid products, tries container type 'P' if initial lookup fails (JB07).
  10. Special case: Freight collect with service fee (CYY, JB10) adds $100 to customer billing when arranged by ARG but billed by the carrier.

  11. Subfile Display:

  12. SFLC1: Customer pricing details (rack pricing).
  13. SFLC2: Sales agreement details (price, PO, freight terms).
  14. SFLC3: Displayed when no sales agreement is found.
  15. SFLC4: Displayed when no rack pricing is found.
  16. Supports up to 100 records in SFLC2 before setting indicator 80.

  17. Function Key Behavior:

  18. F3: Exits the program.
  19. F5: Triggers sales agreement search ($SERCH2) from SFLC1 or SFLC4.
  20. F7: Exits with U7 indicator set.

  21. Historical Modifications:

  22. DC01 (05/12/2010): Replaced BBSHSP with SHIPTO for ship-to data.
  23. DC02 (11/27/2011): Added parameter passing, falling back to LDA if none provided.
  24. JB03 (01/09/2013): Added purchase order fields (BAPORD, S4POY, S4PORD) and allowed zero end date for sales agreements.
  25. JB04 (01/09/2013): Added fields for no rack required and inactive status in display.
  26. MG05 (04/25/2013): Ignores deleted rack pricing records.
  27. JB06 (06/05/2013): Ignores deleted sales agreement records.
  28. JK01 (01/23/2015): Displays BAOFFP in yellow if non-zero, removes calculated off-price logic.
  29. JB07 (05/18/2015): Added container type to ARCUPR key, tries blank or 'P' container type if lookup fails.
  30. JK02 (04/13/2016): Replaced GSTABL container lookup with GSCNTR1.
  31. JB09 (05/19/2020): Added freight collect logic (CNY) for non-Bradford shipments.
  32. JB10 (01/17/2022): Added freight collect with service fee (CYY, $100 charge).
  33. JK03 (01/02/2023): Replaced GSTABL product lookup with GSPROD.

Tables/Files Used

  1. AR822RD: Workstation file with subfiles SFLC1, SFLC2, SFLC3, SFLC4 for displaying pricing data.
  2. BBPRCY: Rack pricing file (key: company, location, product, container).
  3. BICUA6: Sales agreement file (key: company, customer, location).
  4. GSTABL: General system table (partially commented out, replaced by GSPROD and GSCNTR1).
  5. GSPROD: Product master file (key: product code).
  6. ARCUPR: Customer pricing file (key: company, customer, ship-to, product, container type).
  7. ARCUSP: Customer special pricing file (key: company, customer).
  8. ARCUST: Customer master file (key: company, customer).
  9. SHIPTO: Ship-to address file (key: company, customer, ship-to).
  10. GSCNTR1: Container master file (key: container code).

External Programs Called

  • None: The AR822R program does not call any external RPG programs. It relies on internal subroutines ($ENTRY, $XCUTC, $XCUTC2, $XCUTC3, $XCUTC4, $SERCH, $SERCH2, $CLEAR, $WRITE, $WRITE2, $WRITE3, $WRITE4, *PSSR, @PARMS, *INZSR) for its logic.

Summary

The AR822R.rpgle.txt program is a pricing lookup tool for CSRs, retrieving rack pricing (BBPRCY) and sales agreement data (BICUA6) based on company, customer, product, and container inputs. It validates inputs using ARCUST, GSPROD, and GSCNTR1, determines freight terms from ARCUPR and ARCUSP, and displays results in subfiles. It supports purchase order fields, freight collect scenarios (including a $100 service fee for CYY), and flexible container type lookups. No external programs are called, and the listed files support the pricing and customer data required.