Skip to content

SA870 RPG36

The provided document, SA870.rpg36.txt, is an RPG (Report Program Generator) program for the IBM System/36, designed for a "Sales Analysis by Customer Inquiry" process. This RPG program, named SA870, is called by the OCL procedure provided earlier (SA870.ocl36.txt). Below, I will explain the process steps, business rules, tables (files) used, and any external programs called, based on the RPG source code and its integration with the OCL.

Process Steps of the RPG Program

The RPG program SA870 is an interactive customer inquiry program that allows users to retrieve and display sales analysis data for a specific customer, with the ability to scroll forward and backward through records. It uses a workstation (screen) for user interaction and processes data from two files: a customer master file (ARCUST) and a sales summary file (SASMC1). The program is structured around screen handling, file access, and subroutines for navigation and data retrieval. Here’s a detailed breakdown of the process steps:

  1. Program Initialization:
  2. File Definitions (Lines 0004–0009):
    • SCREEN: Defined as a workstation file (WORKSTN) for interactive display, with attributes for scroll line (KSLN LIN), roll key handling (KINFSR ROLLKY), and information data structure (KINFDS INFDS).
    • SASMC1: An input file (IF) with a record length of 128 bytes, indexed (L21AI), externally described (EXTK), and stored on disk.
    • ARCUST: An input file (IC) with a record length of 384 bytes, indexed (R 8AI), externally described, and stored on disk.
  3. Data Structures and Arrays (Lines 0010–0056):
    • Arrays COM (30 bytes) and MOR (28 bytes, 3 entries) store constant messages (e.g., "NO MASTER RECORD WAS FOUND" and "MORE RECORDS EXIST").
    • Data structures define composite fields like COCUST (company and customer number), ROLLKY (roll key fields), and INFDS (for workstation status).
  4. Indicator Initialization (Lines 0059–0063):

    • Clears message field (MSG) and turns off indicator 81.
    • If the KG function key (likely F3 or exit) is pressed, sets the Last Record (LR) indicator, clears indicators 81 and 82, and branches to the END tag to terminate the program.
  5. Function Key Handling:

  6. F3 (KG) (Lines 0062–0064): Exits the program by setting LR and branching to END.
  7. F4 (KA) (Lines 0066–0069): Resets customer number (CUST) to 0, sets indicator 81, and branches to END, likely to clear the screen or reset the inquiry.
  8. F9 (Indicator 09) (Lines 0071–0073): Sets indicator 81, captures the current time into RDATE, and branches to END, possibly for refreshing the screen or logging.

  9. Screen 1 Processing (Indicator 01) (Lines 0075–0076, 0098–0115):

  10. Subroutine SUBSC1:

    • Called when indicator 01 is set (likely triggered by a user action, e.g., Enter key on the first screen).
    • Chains to ARCUST using COCUST (company and customer number) to retrieve customer details (Line 0103).
    • If no record is found (indicator 95 on), displays "NO MASTER RECORD WAS FOUND" in MSG, sets indicator 81, and exits the subroutine (Lines 0105–0107).
    • If a record is found, sets the lower limit (SETLL) on SASMC1 using BEGKEY (constructed from COCUST) to position the file for reading (Lines 0109–0111).
    • Calls READFW to read and display the first set of sales records (Line 0113).
  11. Screen 2 Navigation (Indicator 02) (Lines 0078–0087):

  12. Clears indicator 19, sets indicator 18, and if indicator 88 is on (end of file or no matching records), resets CUST to 0, sets indicator 81, and clears indicators 02 and 18.
  13. Handles scrolling:

    • If indicator 18 is on and 78 is off (forward scroll), calls ROLLFW to position the file and READFW to read forward.
    • If indicator 18 and 78 are on (forward scroll with more records), calls ROLLBW to adjust positioning.
    • Branches to END after processing.
  14. Backward Navigation (Indicator 19) (Lines 0089–0092):

  15. Similar to forward navigation but for backward scrolling:

    • If indicator 19 is on and 79 is off, calls ROLLBW and READBW.
    • If indicator 19 and 79 are on, calls ROLLFW.
    • Calls READBW to read backward and branches to END.
  16. Forward Reading (READFW Subroutine) (Lines 0117–0157):

  17. Reads SASMC1 records sequentially forward.
  18. Sets indicator 82 and outputs a screen (via EXCPT).
  19. Initializes line number (LIN) to 10 and counter (X) to 1.
  20. Reads SASMC1 records, comparing SYCOCU (company/customer key) to COCUST (Lines 0129–0130).
  21. If no match or end of file (indicator 88 on), sets indicator 78 and sets MORE to "END OF RECORDS" (Lines 0132–0134).
  22. If a record is read, updates scroll keys (SVTOP, SVBOT), outputs the record to the screen (via EXCPT), and increments LIN and X (Lines 0136–0145).
  23. Loops until 12 records are displayed (X = 12, indicator 90 on), then calls TESTFW to check for more records (Lines 0146–0150).
  24. Outputs a footer screen (indicator 84) and exits.

  25. Backward Reading (READBW Subroutine) (Lines 0159–0201):

  26. Similar to READFW but reads SASMC1 records backward (READP).
  27. Starts at line 21 (LIN = 21) and decrements LIN for each record.
  28. Sets indicator 79 and updates MORE to "START OF RECORDS" if no more records are found.
  29. Outputs up to 12 records, then calls TESTBW to check for more records.

  30. Scroll Key Handling:

  31. ROLLKY Subroutine (Lines 0235–0240): Checks workstation status (INFDS) to detect scroll keys (e.g., Page Up = 01122, Page Down = 01123), setting indicators 18 or 19.
  32. ROLLFW Subroutine (Lines 0242–0248): Positions SASMC1 at SVBOT (bottom of current page) and reads forward.
  33. ROLLBW Subroutine (Lines 0250–0254): Positions SASMC1 at SVTOP (top of current page) for backward reading.

  34. Test Subroutines:

  35. TESTFW (Lines 0203–0217): Checks for more records by reading forward in SASMC1. Sets indicator 78 and updates MORE if no more matching records exist.
  36. TESTBW (Lines 0219–0233): Checks for previous records by reading backward. Sets indicator 79 and updates MORE accordingly.

  37. Screen Output (Lines 0258–0285):

    • Screen SA870S1 (Indicator 81): Displays date (RDATE), company (CO), customer number (CUST), and error message (MSG).
    • Screen SA870S2 (Indicator 82): Displays customer details (ARNAME, ARADR1, ARADR2, ARADR3).
    • Screen SA870S3 (Indicator 83): Displays sales record details (SYPROD, SYLOC, SYMO, SYYR, SYINTY, SYBQTY, SYUNMS, SYBDOL).
    • Screen SA870S4 (Indicator 84): Displays the MORE message (e.g., "MORE RECORDS EXIST", "END OF RECORDS").
  38. Program Termination:

    • The END tag (Line 0094) is the exit point for most operations, looping back to display the screen or terminate if LR is set.

Business Rules

The RPG program enforces the following business rules for the customer inquiry process: 1. Customer Validation: - The user enters a company and customer number (COCUST) on the first screen. - The program validates the input by chaining to ARCUST. If no record is found, it displays "NO MASTER RECORD WAS FOUND" and prevents further processing. 2. Data Retrieval: - Sales records from SASMC1 must match the company and customer number (SYCOCU = COCUST) to be displayed. - Records are displayed in batches of up to 12 per screen, with fields like product, location, month, year, invoice type, billed quantity, unit of measure, and billed dollars. 3. Navigation: - Users can scroll forward (Page Down) or backward (Page Up) through matching SASMC1 records. - The program tracks the top and bottom keys (SVTOP, SVBOT) to maintain scroll position. - Indicators (MORE) inform the user if more records exist or if they’ve reached the start/end of records. 4. Screen Management: - Displays customer details (name, address) from ARCUST and sales details from SASMC1. - Uses multiple screens (SA870S1 to SA870S4) for different purposes (input, customer info, sales records, navigation status). 5. Error Handling: - Displays error messages for invalid customer numbers. - Manages end-of-file conditions by updating the MORE field appropriately. 6. Function Keys: - F3 (KG): Exits the program. - F4 (KA): Resets the customer number and clears the screen. - F9: Captures the current time and refreshes the screen.

Tables (Files) Used

The RPG program uses the following files (tables): 1. SCREEN: - Type: Workstation file (WORKSTN). - Purpose: Handles interactive screen input/output for user interaction (e.g., displaying customer data, sales records, and navigation messages). - Fields: Input fields (CO, CUST), output fields (RDATE, MSG, ARNAME, ARADR1, ARADR2, ARADR3, SYPROD, etc.). 2. SASMC1: - Type: Input file (IF), 128 bytes, indexed. - Purpose: Stores sales summary data for customers. - Key Fields: SYCOCU (company/customer key), SYCONO (company), SYCUST (customer), SYPROD (product), SYLOC (location), SYMO (month), SYYR (year), SYINTY (invoice type), SYBQTY (billed quantity), SYUNMS (unit of measure), SYBDOL (billed dollars). 3. ARCUST: - Type: Input file (IC), 384 bytes, indexed. - Purpose: Stores customer master data. - Key Fields: Customer number (part of COCUST). - Fields: ARNAME (customer name), ARADR1, ARADR2, ARADR3 (address lines).

These files match the ones defined in the OCL (SASMC1 and ARCUST), confirming they are the data sources for the inquiry.

External Programs Called

The RPG program does not explicitly call any external programs. All logic is handled within SA870 through its subroutines (SUBSC1, READFW, READBW, TESTFW, TESTBW, ROLLKY, ROLLFW, ROLLBW). The program relies on the system’s file access and workstation handling capabilities, with no evidence of CALL operations to other programs.

Integration with OCL

The OCL procedure (SA870.ocl36.txt): - Loads and runs SA870 (// LOAD SA870, // RUN). - Assigns SASMC1 and ARCUST with shared access (DISP-SHR) and dynamic labels (?9?SASMC1, ?9?ARCUST), allowing flexibility in file naming. - Likely passes parameters (e.g., via ?9?) to initialize the inquiry, though the RPG program doesn’t directly reference these placeholders, suggesting they are resolved at the OCL level.

Summary

The SA870 RPG program is a robust interactive application for querying customer sales data. It validates customer input, retrieves matching sales records, and supports scrolling through results, with clear screen management and navigation feedback. The business rules ensure accurate data retrieval and user-friendly interaction, while the OCL provides the necessary file setup and program invocation.

If you need further clarification, a deeper dive into specific subroutines, or assistance with related tasks (e.g., generating a flowchart or analyzing performance), let me know!