Skip to content

SA880 RPG36

The provided document, SA880.rpg36.txt, is an RPG (Report Program Generator) program written for the IBM System/36 or System/36 Environment on IBM i, designed to perform a "Sales Analysis Inquiry by Product." It is called from the OCL procedure SA880.ocl36.txt previously discussed. Below, I’ll explain the process steps, business rules, tables used, and any external programs called, based on the RPG code and its integration with the OCL procedure.

Process Steps of the SA880 RPG Program

The RPG program SA880 is an interactive inquiry program that allows users to query sales analysis data by product, company, and location, displaying results on a workstation screen. It uses files SASMY1 and GSPROD (with GSTABL commented out) to retrieve sales and product information. Here’s a detailed breakdown of the process steps, following the program’s structure:

  1. Program Initialization (Header and File Specifications):
  2. H-Spec (Line 0002): Defines the program name (SA880) and sets P064 (possibly a program option or priority) with debugging enabled (B).
  3. F-Specs (Lines 0004–0008, JK01):
    • SCREEN: Defines a workstation file (256 bytes) for interactive display, with keywords KSLN LIN (line number tracking), KINFSR ROLLKY (roll key subroutine for handling roll keys), and KINFDS INFDS (information data structure for status).
    • SASMY1: Input file (128 bytes, 15-byte key, alternate index AI, external key EXTK), used for sales summary data.
    • GSTABL: Commented out, not used (originally a 256-byte input file with a 12-byte key).
    • GSPROD: Input file (512 bytes, 6-byte key, alternate index), used for product master data.
  4. E-Specs (Lines 0010–0011): Define arrays MSG (2 messages, 40 characters each) and MOR (3 messages, 28 characters each) for error and navigation messages.

  5. Input Specifications (I-Specs, Lines 0012–0050):

  6. Define input fields for SCREEN and SASMY1 (and commented GSTABL, GSPROD):

    • SCREEN:
    • Record format NS 01 (screen 1): Fields COPRLO (company/location, 3-11), COPROD (product, 3-8), CO (company, 3-40).
    • Record format NS 02: Fields PROD (product, 5-8), LOC (location, 9-11).
    • Record format NS 09: No fields, likely for control or exit.
    • SASMY1: Fields include SYDEL (delete flag), SYCONO (company number), SYLOC (location), SYYR (year), SYMO (month), SYPROD (product), SYINTY (invoice type), SYINST (invoice style), SYUNMS (unit of measure), SYBQTY (billed quantity), SYBDOL (billed dollars), SYCYM (company/year/month).
    • GSPROD: Fields include TPDEL (delete flag), TPCO (company), TPCODE (product code), TPDESC (description), TPDES1 (complete description), TPDESA (abbreviated description), TPPRGP (product group), TPTP20 (ranking column), TPICOL (inventory column), TPPRCL (product class), TPINGP (inventory group), TPSGL# (sales G/L number), TPVCF (VCF code).
    • INFDS: Defines STATUS for workstation status codes.
    • Data structure (DS): Defines ROLLKY (roll key, 15 bytes), SYCONO, SYPROD, SYLOC, SYCYM for internal use.
  7. Calculation Specifications (C-Specs, Lines 0050–0266):

  8. Initialization (Lines 0051–0054): Clear indicators 81-83, 84, 95, and set MSGE to blanks.
  9. Key Handling:
    • KA (Line 0055–0057): If function key KA is pressed, clear indicator 02, set 81, and go to END (exit).
    • KG (Line 0059–0061): If KG is pressed, clear indicators 01, 02, 09, set LR (last record), and go to END.
    • Indicator 09 (Lines 0063–0066): If set, display "NON STOCK ITEM" in NSDESC, set 81, and go to END.
  10. Screen 1 Processing (Lines 0068–0076):
    • Indicator 01: Execute SUBSC1 subroutine to process screen 1 input (company, product, location).
    • Indicator 02 with 88: Clear PROD, LOC, set 81, clear 02, 18.
  11. Roll Key Handling (Lines 0077–0085):
    • Indicator 18 (roll forward): If 78 off, call ROLLFW; if 78 on, call ROLLBW; then call READFW and go to END.
    • Indicator 19 (roll backward): If 79 off, call ROLLBW; if 79 on, call ROLLFW; then call READBW and go to END.
  12. Subroutines:

    • SUBSC1 (Lines 0090–0115):
    • If PROD is 'NS', set TPDES1 to NSDESC (non-stock item).
    • Else, set KLPROD to COPROD and chain to GSPROD to retrieve product data. If not found (95) or deleted (TPDEL='D'), set error message (MSG,1) and indicator 81.
    • If LOC is blank, set indicator 70.
    • Build SYKEY from COPRLO, set lower limit on SASMY1, and call READFW.
    • READFW (Lines 0117–0161): Read SASMY1 forward, display up to 12 records per screen:
    • Set 82, write screen, clear 82, 90, initialize line counter (LIN=10), and record counter (X=1).
    • Read SASMY1, compare SYCONO, SYPROD, SYLOC with input. If no match or end of file (88), set 78, display "END OF RECORDS", and exit.
    • If X=1, save ROLLKY to SVTOP and SVBOT.
    • Display record (set 83, write, clear 83), increment LIN, X. If X<12, loop to AGN.
    • If X=12, call TESTFW to check for more records.
    • READBW (Lines 0163–0207): Similar to READFW, but reads SASMY1 backward, starting LIN=21, decrementing LIN.
    • TESTFW (Lines 0209–0227): Check for more records forward, set 78 if none, update MORE message.
    • TESTBW (Lines 0229–0245): Check backward, set 79 if none, update MORE.
    • ROLLKY (Lines 0247–0252): Check STATUS for roll key codes (01122 for forward, 01123 for backward), set 18 or 19.
    • ROLLFW (Lines 0254–0260): Set lower limit to SVBOT, read forward.
    • ROLLBW (Lines 0262–0266): Set lower limit to SVTOP, read backward.
  13. Output Specifications (O-Specs, Lines 0270–0293):

  14. Define screen formats for SCREEN:
    • Format 81 (SA880S1): Display CO, PROD, LOC, MSGE for input screen.
    • Format 82 (SA880S2): Display CO, PROD, LOC, TPDES1 (product description).
    • Format 83 (SA880S3): Display SYLOC, SYMO, SYYR, SYINTY, SYBQTY, SYUNMS, SYBDOL for sales data.
    • Format 84 (SA880S4): Display MORE (navigation message).
  15. Messages:

    • MSG: "INVALID PRODUCT", "NO RECORDS EXIST FOR THIS PRODUCT".
    • MOR: "(---MORE RECORDS EXIST---)", "(--- END OF RECORDS ---)", "(--- START OF RECORDS ---)".
  16. Program Flow:

  17. The program uses RPG’s program cycle, driven by indicators and user input:
    • Display input screen (SA880S1) for company, product, location.
    • Validate product in GSPROD; if invalid, show error.
    • Set lower limit on SASMY1 based on input, read forward/backward, display up to 12 records.
    • Handle roll keys (forward/backward) to navigate records, updating MORE message.
    • Exit on KA or KG keys.

Business Rules

Based on the program logic and context, the business rules enforced by SA880 include: 1. Input Validation: - Users must enter a company (CO), product (PROD), and optionally location (LOC) on the input screen. - If PROD is 'NS', treat as a non-stock item and set description to NSDESC. - For other products, validate against GSPROD. If the product is not found or deleted (TPDEL='D'), display "INVALID PRODUCT" and prevent further processing. - If LOC is blank, allow retrieval of all locations for the company/product (indicator 70).

  1. Data Retrieval:
  2. Retrieve sales data from SASMY1 matching the input company (SYCONO), product (SYPROD), and location (SYLOC, if specified).
  3. Records are filtered by SYCONO, SYPROD, and SYLOC (if not blank) to ensure relevant sales data is displayed.
  4. Display up to 12 records per screen, showing location, month, year, invoice type, billed quantity, unit of measure, and billed dollars.

  5. Navigation:

  6. Support forward/backward scrolling using roll keys (status codes 01122 for forward, 01123 for backward).
  7. Display navigation messages ("MORE RECORDS EXIST", "END OF RECORDS", "START OF RECORDS") based on whether additional records exist.
  8. Save top/bottom record keys (SVTOP, SVBOT) for scrolling continuity.

  9. Error Handling:

  10. Display "NO RECORDS EXIST FOR THIS PRODUCT" if no matching records are found in SASMY1.
  11. Handle end-of-file (88) by setting appropriate indicators (78, 79) and displaying navigation messages.

  12. Exit Conditions:

  13. Exit on KA key (clear screen, set error indicator).
  14. Exit on KG key (set last record indicator LR).
  15. Exit on indicator 09 for non-stock items or invalid input.

Tables Used

The RPG program uses the following files (tables), consistent with the OCL procedure: 1. SASMY1: Sales summary file containing: - SYDEL: Delete flag. - SYCONO: Company number. - SYLOC: Location. - SYYR: Year. - SYMO: Month. - SYPROD: Product. - SYINTY: Invoice type. - SYINST: Invoice style. - SYUNMS: Unit of measure. - SYBQTY: Billed quantity (11.2 format). - SYBDOL: Billed dollars (11.2 format). - SYCYM: Company/year/month (6 bytes). 2. GSPROD: Product master file containing: - TPDEL: Delete flag. - TPCO: Company. - TPCODE: Product code. - TPDESC, TPDES1, TPDESA: Product descriptions (full, complete, abbreviated). - TPVCF: VCF code (used in inquiry). - Other fields (TPPRGP, TPTP20, TPICOL, TPPRCL, TPINGP, TPSGL#) are defined but not used in this program. 3. GSTABL: Commented out, not used in this version (replaced by GSPROD per comment JK01).

External Programs Called

  • None: The SA880 RPG program does not explicitly call any external programs (e.g., via CALL operation). All logic is handled within subroutines (SUBSC1, READFW, READBW, TESTFW, TESTBW, ROLLKY, ROLLFW, ROLLBW).

Integration with OCL

The OCL procedure (SA880.ocl36.txt) sets up the environment for SA880: - Loads SA880 (// LOAD SA880). - Allocates SASMY1 and GSPROD with shared access (DISP-SHR). - Executes SA880 (// RUN). The RPG program relies on these files being allocated by the OCL, with ?9? substitution variables resolved to appropriate library prefixes.

Additional Notes

  • RPG II/36 Characteristics: The program uses RPG II syntax (fixed-format, column-based), typical for System/36, with the program cycle managing screen interactions and file I/O. Indicators (01, 02, 09, 18, 19, 78, 79, 81–84, 88, 90, 95) control flow and screen output.
  • Screen Interaction: The program is interactive, using a workstation file (SCREEN) with multiple formats (SA880S1–S4) for input, product validation, data display, and navigation messages.
  • Modifications (JK01): Comments indicate a change on 02/19/23 by Jim Krajacic, replacing GSTABL with GSPROD for product data, reflected in commented-out GSTABL references.
  • Limitations: The program assumes valid file structures and does not handle all edge cases (e.g., file access errors beyond EOF). The exact screen layout (e.g., field positions) depends on external display file definitions (not provided).

Summary

  • Process Steps:
  • Initialize program, files (SASMY1, GSPROD), and screen.
  • Accept user input (company, product, location) via screen SA880S1.
  • Validate product in GSPROD; handle non-stock items ('NS') or errors.
  • Retrieve and filter SASMY1 records based on input, displaying up to 12 records per screen (SA880S3).
  • Handle roll forward/backward navigation, updating MORE messages.
  • Exit on KA, KG, or error conditions.
  • Business Rules:
  • Validate company, product, and optional location input.
  • Check product validity in GSPROD, handle non-stock items.
  • Filter sales data by company, product, and location (if specified).
  • Display up to 12 records with navigation messages.
  • Handle errors for invalid products or no records.
  • Tables Used: SASMY1 (sales data), GSPROD (product data).
  • External Programs Called: None.

If you have additional details (e.g., display file definitions, sample data, or specific questions about subroutines), I can provide further analysis. Let me know!