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:
- Program Initialization (Header and File Specifications):
- H-Spec (Line 0002): Defines the program name (
SA880) and setsP064(possibly a program option or priority) with debugging enabled (B). - F-Specs (Lines 0004–0008, JK01):
SCREEN: Defines a workstation file (256 bytes) for interactive display, with keywordsKSLN LIN(line number tracking),KINFSR ROLLKY(roll key subroutine for handling roll keys), andKINFDS INFDS(information data structure for status).SASMY1: Input file (128 bytes, 15-byte key, alternate indexAI, external keyEXTK), 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.
-
E-Specs (Lines 0010–0011): Define arrays
MSG(2 messages, 40 characters each) andMOR(3 messages, 28 characters each) for error and navigation messages. -
Input Specifications (I-Specs, Lines 0012–0050):
-
Define input fields for
SCREENandSASMY1(and commentedGSTABL,GSPROD):SCREEN:- Record format
NS 01(screen 1): FieldsCOPRLO(company/location, 3-11),COPROD(product, 3-8),CO(company, 3-40). - Record format
NS 02: FieldsPROD(product, 5-8),LOC(location, 9-11). - Record format
NS 09: No fields, likely for control or exit. SASMY1: Fields includeSYDEL(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 includeTPDEL(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: DefinesSTATUSfor workstation status codes.- Data structure (DS): Defines
ROLLKY(roll key, 15 bytes),SYCONO,SYPROD,SYLOC,SYCYMfor internal use.
-
Calculation Specifications (C-Specs, Lines 0050–0266):
- Initialization (Lines 0051–0054): Clear indicators
81-83,84,95, and setMSGEto blanks. - Key Handling:
KA(Line 0055–0057): If function key KA is pressed, clear indicator02, set81, and go toEND(exit).KG(Line 0059–0061): If KG is pressed, clear indicators01,02,09, setLR(last record), and go toEND.- Indicator
09(Lines 0063–0066): If set, display "NON STOCK ITEM" inNSDESC, set81, and go toEND.
- Screen 1 Processing (Lines 0068–0076):
- Indicator
01: ExecuteSUBSC1subroutine to process screen 1 input (company, product, location). - Indicator
02with88: ClearPROD,LOC, set81, clear02,18.
- Indicator
- Roll Key Handling (Lines 0077–0085):
- Indicator
18(roll forward): If78off, callROLLFW; if78on, callROLLBW; then callREADFWand go toEND. - Indicator
19(roll backward): If79off, callROLLBW; if79on, callROLLFW; then callREADBWand go toEND.
- Indicator
-
Subroutines:
- SUBSC1 (Lines 0090–0115):
- If
PRODis 'NS', setTPDES1toNSDESC(non-stock item). - Else, set
KLPRODtoCOPRODand chain toGSPRODto retrieve product data. If not found (95) or deleted (TPDEL='D'), set error message (MSG,1) and indicator81. - If
LOCis blank, set indicator70. - Build
SYKEYfromCOPRLO, set lower limit onSASMY1, and callREADFW. - READFW (Lines 0117–0161): Read
SASMY1forward, display up to 12 records per screen: - Set
82, write screen, clear82,90, initialize line counter (LIN=10), and record counter (X=1). - Read
SASMY1, compareSYCONO,SYPROD,SYLOCwith input. If no match or end of file (88), set78, display "END OF RECORDS", and exit. - If
X=1, saveROLLKYtoSVTOPandSVBOT. - Display record (set
83, write, clear83), incrementLIN,X. IfX<12, loop toAGN. - If
X=12, callTESTFWto check for more records. - READBW (Lines 0163–0207): Similar to
READFW, but readsSASMY1backward, startingLIN=21, decrementingLIN. - TESTFW (Lines 0209–0227): Check for more records forward, set
78if none, updateMOREmessage. - TESTBW (Lines 0229–0245): Check backward, set
79if none, updateMORE. - ROLLKY (Lines 0247–0252): Check
STATUSfor roll key codes (01122for forward,01123for backward), set18or19. - ROLLFW (Lines 0254–0260): Set lower limit to
SVBOT, read forward. - ROLLBW (Lines 0262–0266): Set lower limit to
SVTOP, read backward.
-
Output Specifications (O-Specs, Lines 0270–0293):
- Define screen formats for
SCREEN:- Format
81(SA880S1): DisplayCO,PROD,LOC,MSGEfor input screen. - Format
82(SA880S2): DisplayCO,PROD,LOC,TPDES1(product description). - Format
83(SA880S3): DisplaySYLOC,SYMO,SYYR,SYINTY,SYBQTY,SYUNMS,SYBDOLfor sales data. - Format
84(SA880S4): DisplayMORE(navigation message).
- Format
-
Messages:
MSG: "INVALID PRODUCT", "NO RECORDS EXIST FOR THIS PRODUCT".MOR: "(---MORE RECORDS EXIST---)", "(--- END OF RECORDS ---)", "(--- START OF RECORDS ---)".
-
Program Flow:
- 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
SASMY1based on input, read forward/backward, display up to 12 records. - Handle roll keys (forward/backward) to navigate records, updating
MOREmessage. - Exit on KA or KG keys.
- Display input screen (
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).
- Data Retrieval:
- Retrieve sales data from
SASMY1matching the input company (SYCONO), product (SYPROD), and location (SYLOC, if specified). - Records are filtered by
SYCONO,SYPROD, andSYLOC(if not blank) to ensure relevant sales data is displayed. -
Display up to 12 records per screen, showing location, month, year, invoice type, billed quantity, unit of measure, and billed dollars.
-
Navigation:
- Support forward/backward scrolling using roll keys (status codes
01122for forward,01123for backward). - Display navigation messages ("MORE RECORDS EXIST", "END OF RECORDS", "START OF RECORDS") based on whether additional records exist.
-
Save top/bottom record keys (
SVTOP,SVBOT) for scrolling continuity. -
Error Handling:
- Display "NO RECORDS EXIST FOR THIS PRODUCT" if no matching records are found in
SASMY1. -
Handle end-of-file (
88) by setting appropriate indicators (78,79) and displaying navigation messages. -
Exit Conditions:
- Exit on KA key (clear screen, set error indicator).
- Exit on KG key (set last record indicator
LR). - Exit on indicator
09for 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
SA880RPG program does not explicitly call any external programs (e.g., viaCALLoperation). 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
GSTABLwithGSPRODfor product data, reflected in commented-outGSTABLreferences. - 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
SASMY1records based on input, displaying up to 12 records per screen (SA880S3). - Handle roll forward/backward navigation, updating
MOREmessages. - 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!