Skip to content

AR820 RPG36

The provided RPG program, AR820.rpg36.txt, is written in RPG/36 (used on IBM System/36 or AS/400 systems) and supports an Alpha Customer Search for pricing inquiries, as called from the AR820.ocl36.txt OCL program. It handles customer searches based on customer number, product code, container code, and a partial customer name, displaying results interactively 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 RPG program is structured to handle user input, validate data, retrieve customer and product information, and display results on a screen. It uses subroutines to manage input processing, scrolling (roll forward/backward), and data validation. Here’s a step-by-step breakdown of the process:

  1. File and Program Definitions (Lines 0013–0192):
  2. File Definitions:
    • SCREEN: A workstation file for interactive display (100 bytes, with subfiles for scrolling).
    • ARCONT: Input file for company control data (256 bytes, keyed by company number).
    • ARCUSX: Input file for customer cross-reference data (384 bytes, keyed by company and customer).
    • ARCUST: Input file for customer master data (384 bytes, keyed by customer number).
    • GSPROD: Input file for product master data (512 bytes, keyed by product code).
    • GSCNTR1: Input file for container data (512 bytes, keyed by container code).
  3. Array and Data Structure Definitions:

    • SNM: Array for keyed search name (10 elements, 1 character each).
    • CXNM: Array for customer cross-reference name (10 elements, 1 character each).
    • MSG: Array for error messages (6 elements, 40 characters each).
    • INFDS: Information data structure for workstation status (e.g., STATUS for function key detection).
    • UDS: User data structure for local data area (LDA) fields like ICO (company), ICUST (customer), IPROD (product), ICNTR (container), EOJ (end-of-job flag), and FIRST (first screen flag).
  4. Initialization (Lines 0068–0070):

  5. Resets indicators 81, 82, 83, 60, 61, 62, and 84 to 0.
  6. Sets default message to MSG,2 ("MORE ITEMS EXIST") in the MORE field.
  7. Initializes PRDKEY to 'PRODCD' for product code lookups.

  8. Function Key Handling (Lines 0072–0081, 0257–0261):

  9. KA (F3): Sets indicator 81 (rekey, no add/update) and resets 01, 02, 09 (Lines 0075–0076).
  10. KG (F12): Sets LR (last record), sets EOJ to 'E', resets 01, 02, 09, and jumps to END (Lines 0078–0081).
  11. 18 (Roll Up): Calls ROLLFW subroutine for forward scrolling (Line 0072).
  12. 19 (Roll Down): Calls ROLLBW subroutine for backward scrolling (Line 0073).
  13. The ROLLKY subroutine (Lines 0257–0261) detects function keys by checking STATUS (01122 for Roll Up, 01123 for Roll Down).

  14. First Screen Processing (Subroutine S1, Lines 0101, 0111–0144):

  15. Input Validation (Screen NS 01, Lines 0024–0028):
    • Reads input fields: CONO (company number), HCUST (customer number), HPROD (product code), HCNTR (container code), SNM (search name).
    • If FIRST is blank (first execution), sets FIRST to 'N' and indicator 81 (Line 0083–0086).
    • If CONO is zero, chains to ARCONT to validate company number; if invalid, sets error message MSG,6 ("INVALID COMPANY NUMBER ENTERED"), indicator 81, and jumps to ENDCHK (Lines 0090–0091).
    • If HCUST is non-zero:
    • Chains to ARCONT to validate company (Lines 0096–0098).
    • Constructs CUSKEY (company + customer) and chains to ARCUST to validate customer; if invalid, sets MSG,3 ("INVALID CUSTOMER NUMBER ENTERED") and indicator 81 (Lines 0096–0098).
    • If HPROD is non-blank, chains to GSPROD to validate product code; if invalid, sets MSG,4 ("INVALID PRODUCT CODE ENTERED") and indicator 81 (Lines 0096–0098, JB02).
    • If HCNTR is non-blank, chains to GSCNTR1 to validate container code; if invalid, sets MSG,5 ("INVALID CONTAINER ENTERED") and indicator 81 (Lines 0096–0098, JB03).
    • Stores valid inputs (CONO, HCUST, HPROD, HCNTR) in LDA fields (ICO, ICUST, IPROD, ICNTR).
  16. Search Name Processing:

    • Counts non-blank characters in SNM (search name) up to the first blank or 10 characters, storing count in SCNT (Lines 0128–0136).
    • Replaces asterisks (*) in SNM with blanks (Lines 0132–0133).
    • Builds VXLIM1 (company + search name) and sets lower limit for ARCUSX file using SETLL (Lines 0139–0142).
    • Calls SETUP2 subroutine to process search results (Line 0143).
  17. Second Screen Processing (Subroutine S2, Lines 0106, 0203–0210):

  18. Reads input fields: ICO (company), ICUST (customer), IPROD (product), ICNTR (container) (Lines 0031–0033).
  19. If ICUST is zero or IPROD is blank, sets LR and jumps to END (Lines 0103–0105).
  20. Otherwise, calls SETUP2 to display results (Line 0106).
  21. Resets roll indicators 18 and 19 (Line 0107).

  22. SETUP2 Subroutine (Lines 0146–0187):

  23. Initializes line counter (LIN) to 6 and resets indicators (Line 0149).
  24. If HPROD or HCNTR is non-blank, updates LDA fields IPROD and ICNTR (Lines 0148–JB03).
  25. Reads ARCUSX records sequentially (Line 0152):
    • Skips records where CXDEL is 'D' (deleted) or CXCONO does not match CONO (Lines 0155–0157).
    • Calls CK subroutine to compare search name (SNM) with customer cross-reference name (CXNM) (Line 0159).
    • If no match (30 indicator off), skips to next record (Lines 0160–0161).
    • Chains to ARCUST using CSKEY (company + customer) to retrieve customer details (Line 0166).
    • Checks if ARTOTD (total due) is non-zero, setting OPENYN to 'Y' or blank (Lines 0167–0169).
    • Outputs record to screen (indicator 83, Lines 0171–0172).
    • Increments LIN; if LIN reaches 21, sets indicator 20 (more records exist) and jumps to MORE (Lines 0174–0176).
  26. If no more records, reads previous ARCUSX record, updates MORE to MSG,1 ("END OF ITEMS"), and outputs final screen (Lines 0181–0186).

  27. CK Subroutine (Lines 0189–0201):

  28. If SCNT (search name length) is zero, displays all customers (indicator 30, Line 0190).
  29. Otherwise, compares each character of CXNM (customer name) with SNM (search name) up to SCNT characters (Lines 0194–0199).
  30. Sets indicator 30 if all characters match (Line 0196).

  31. ROLLFW Subroutine (Lines 0263–0265):

  32. Sets indicator 02 to trigger forward scrolling (Line 0264).

  33. ROLLBW Subroutine (Lines 0267–0303):

  34. Sets lower limit on ARCUSX using SVBEG (saved key, Line 0268).
  35. Reads previous ARCUSX records (Line 0274):
    • Skips deleted records (CXDEL = 'D') or non-matching company records (Lines 0277–0278).
    • Calls CK to validate search name (Line 0279).
    • Chains to ARCUST, updates OPENYN, and outputs to screen (Lines 0283–0290).
    • Decrements LIN until it reaches 6 or no more records (Lines 0292–0294).
  36. Updates MORE to MSG,1 ("END OF ITEMS") and outputs final screen (Lines 0298–0300).

  37. Output Specifications (Lines 0305–0323):

    • Outputs to SCREEN using subfile records (AR820S1, AR820S2, AR820S3, AR820S4):
    • AR820S1 (indicator 81): Displays input fields (CONO, HCUST, HPROD, HCNTR, SNM) and error messages (MSG40).
    • AR820S2 (indicator 82): Displays company, customer, product, and container fields.
    • AR820S3 (indicator 83): Displays customer details (OPENYN, CCUSXT, ARNM24, ARAD1, ARAD2).
    • AR820S4 (indicator 84): Displays MORE message ("MORE ITEMS EXIST" or "END OF ITEMS").
  38. Termination (Lines 0099–0109):

    • Sets LR (last record) and jumps to END tag when processing completes or conditions are met (e.g., invalid input, KG key, or end of file).

Business Rules

  1. Input Validation:
  2. Validates CONO (company number) against ARCONT. If invalid, displays "INVALID COMPANY NUMBER ENTERED".
  3. Validates HCUST (customer number) against ARCUST. If invalid, displays "INVALID CUSTOMER NUMBER ENTERED".
  4. Validates HPROD (product code) against GSPROD. If invalid, displays "INVALID PRODUCT CODE ENTERED".
  5. Validates HCNTR (container code) against GSCNTR1. If invalid, displays "INVALID CONTAINER ENTERED".
  6. Stores valid inputs in the LDA for reuse.

  7. Search Logic:

  8. Supports partial customer name search using SNM (up to 10 characters).
  9. Matches SNM against CXNM (customer cross-reference name) in ARCUSX.
  10. If SCNT is zero, displays all non-deleted customers for the company.
  11. Skips deleted records (CXDEL = 'D') and records with non-matching company numbers.

  12. Display Logic:

  13. Displays up to 15 customer records per screen (LIN from 6 to 21).
  14. Shows customer details: customer number (CCUSXT), name (ARNM24), address (ARAD1, ARAD2), and open balance indicator (OPENYN = 'Y' if ARTOTD > 0).
  15. Indicates if more records exist (MORE = "MORE ITEMS EXIST") or not ("END OF ITEMS").

  16. Function Key Behavior:

  17. KA (F3): Resets input screen for rekeying.
  18. KG (F12): Ends the job, setting EOJ to 'E'.
  19. Roll Up (F18): Scrolls forward to the next set of records.
  20. Roll Down (F19): Scrolls backward to the previous set of records.

  21. Data Modifications (Historical Changes):

  22. 04/15/08: Changed product code (HPROD, IPROD) from numeric to alphanumeric (JB02).
  23. 10/11/14: Changed container code (HCNTR, ICNTR) from numeric to alphanumeric (JB03).
  24. 04/13/16: Replaced container code lookup in GSTABL with GSCNTR1 (alphanumeric key, JK01).
  25. 12/31/22: Replaced product code lookup in GSTABL with GSPROD (JK02).

Tables/Files Used

The RPG program uses the following files (all defined with shared access, as per the OCL):

  1. SCREEN: Workstation file for interactive input/output (subfile for scrolling).
  2. ARCONT: Company control file (256 bytes, keyed by company number).
  3. ARCUSX: Customer cross-reference file (384 bytes, keyed by company and customer).
  4. ARCUST: Customer master file (384 bytes, keyed by customer number).
  5. GSPROD: Product master file (512 bytes, keyed by product code).
  6. GSCNTR1: Container master file (512 bytes, keyed by container code).

Note: GSTABL is commented out (Lines JK02), replaced by GSPROD and GSCNTR1 in later updates.


External Programs Called

  • None: The RPG program AR820 does not explicitly call any external RPG programs. It is called by the OCL program (AR820.ocl36.txt) and relies on internal subroutines (S1, S2, SETUP2, CK, ROLLFW, ROLLBW, ROLLKY) for its logic. The OCL program calls AR822R, but AR820 itself does not.

Summary

The AR820.rpg36.txt program is an interactive customer search tool for pricing inquiries, processing user inputs (company, customer, product, container, and partial name) and displaying matching customer records from ARCUSX and ARCUST. It validates inputs against ARCONT, GSPROD, and GSCNTR1, supports scrolling, and handles errors with appropriate messages. The program uses subroutines to modularize logic and relies on the LDA for data persistence. No external programs are called directly, and the listed files support the customer and product data required for the inquiry.