MGSTABL RPGLE
The provided document is an RPGLE (RPG IV) program named MGSTABL, designed as a generic table values lookup utility. It is called from the main program BB931 (as referenced in the previous query) to facilitate the selection of valid table values, specifically for fields like the unit of measure (S1FRUM) in BB931. Below, I’ll explain the process steps, business rules, tables used, and external programs called, ensuring clarity and conciseness.
Process Steps of the MGSTABL RPGLE Program¶
The MGSTABL program provides a user interface to display and select values from the GSTABL file, allowing users to filter and choose a specific table value based on a type and optional search string. It operates as a lookup utility, returning the selected value to the calling program (e.g., BB931). Here’s a breakdown of the process steps:
- Initialization (
*inzsrSubroutine): - Purpose: Sets up the program environment.
-
Actions:
- Defines the entry parameter list to receive
p$type(table type) andp$code(selected table code, returned to the caller). - Initializes subfile control fields:
rrn1andrrnsv1(relative record numbers) to zero,pagsz1(page size) to 14. - Sets flags:
sf1agn(subfile processing loop) to*OFF,repsfl(reposition subfile) to*OFF. - Defines key fields and lists:
k$type(set to'TYPE ') andkltype(key list forGSTABLaccess usingk$typeandc$type).
- Defines the entry parameter list to receive
-
Error Handling (
*pssrSubroutine): - Purpose: Validates the number of parameters passed to the program.
-
Actions:
- Checks the program status data structure (
psds##) for parameter errors (ps#err = 221). - If incorrect parameters are detected, sets the return code to
*detcand exits. - Note: This subroutine is executed at the start of the program to ensure valid parameters before proceeding.
- Checks the program status data structure (
-
Process Parameters (
@parmsSubroutine): - Purpose: Handles input parameters and sets up the display.
-
Actions:
- Sets global protection indicator
*IN70to*ONby default (fields protected). - If at least one parameter is passed (
ps#prm >= 1), movesp$typetoc$type(control field for table type) and sets*IN70to*OFF(fields unprotected for input). - Ensures the program Austenite subfile is enabled for user interaction when parameters are provided.
- Sets global protection indicator
-
Process Subfile (
srsfl1Subroutine): - Purpose: Manages the main user interface loop, displaying and processing the subfile (
sfl1) for table values. -
Actions:
- Initial Positioning:
- Calls
sf1repto clear and reposition the subfile based onc$typeandc$srch. - Main Loop (
sf1agn): - Writes an overlay window record (
wdwovr) and the subfile control format (sflwdw1). - Sets display control indicator (
*IN40forSFLDSPCTL) and displays the subfile control (sflctl1) usingEXFMT. - Checks for existing subfile records to set the display indicator (
*IN41forSFLDSP). - Clears error indicators (
*IN50–*IN69) and updates cursor location (csrloc, though commented out) and subfile record number (rcdnb1 = pagrrn). - Processes user input:
- F12: Exits the subfile loop, returning to the caller.
- PAGEDN: Loads additional subfile records (
sf1lod). - ENTER: Processes subfile selections (
sf1prc). - F10: Positions the cursor to the control record, clearing cursor coordinates (
row1,col1) and setting*IN69. - User Positioning: If
c$typeorc$srchchanges, repositions the subfile (sf1rep).
- Continues the loop until
sf1agnis set to*OFF(e.g., via F12 or selection).
-
Process Subfile on ENTER (
sf1prcSubroutine): - Purpose: Handles subfile selections when the user presses ENTER.
-
Actions:
- Reads changed subfile records (
readc sfl1) if the subfile is not empty (rrn1 > 0). - Processes each changed record by calling
sf1chg.
- Reads changed subfile records (
-
Process Subfile Record Change (
sf1chgSubroutine): - Purpose: Processes user selections in the subfile.
-
Actions:
- If the option field (
s1opt = 1), callssf1s01to handle the selection. - Exits the subfile loop after a selection is made.
- If the option field (
-
Select Value (
sf1s01Subroutine): - Purpose: Returns the selected table code to the caller.
-
Actions:
- Moves the selected table code (
tbcode) to the output parameterp$code. - Sets
sf1agnto*OFFto exit the subfile loop, returning control to the caller.
- Moves the selected table code (
-
Reposition Subfile (
sf1repSubroutine): - Purpose: Clears and reloads the subfile based on user input.
-
Actions:
- Clears the subfile (
sf1clr). - Validates control input (
sf1cte). - If no errors (
*IN50 = *OFF), positions theGSTABLfile usingc$typeand loads records (sf1lod). - Retains control fields (
c$type,c$srch) inr$type,r$srch,h$type, andh$srchfor repositioning. - Calculates the length of the search string (
c$srch) for filtering.
- Clears the subfile (
-
Edit Subfile Control Input (
sf1cteSubroutine): - Purpose: Validates the table type in the control record.
-
Actions:
- Chains
c$typetoGSTABLusing the key listkltype. - If valid (
*IN50 = *OFF), concatenates the table description (tbdesc) to the title (TITLEM) for the header (c$hdr1). - If invalid, sets an error (
*IN50) and uses a default header with the error message fromcom(01)("Invalid Table Type Code").
- Chains
-
Subfile Protection Schemes (
sf1proSubroutine):- Purpose: Controls field protection based on parameters.
- Actions:
- If no parameters are passed (
ps#prm <= 0), protects the option field (*IN76 = *ON). - Otherwise, enables the option field (
*IN76 = *OFF).
-
Load Subfile Records (
sf1lodSubroutine):- Purpose: Loads table records into the subfile.
- Actions:
- Starts from the last subfile record number (
rrnsv1). - Reads records from
GSTABLusingc$typeuntil the page size (pagsz1 = 14) or end of file (*IN43). - Filters records if a search string (
c$srch) is provided, using theSCANoperation to matchtbdesc. - Formats each record (
sf1fmt) and writes tosfl1, incrementingrrn1. - Saves the last record number (
rrnsv1) and clears cursor coordinates.
-
Format Subfile Detail Line (
sf1fmtSubroutine):- Purpose: Formats a subfile record for display.
- Actions:
- Clears the option field (
s1opt). - Note: The program assumes fields like
tbcodeandtbdescare displayed directly from theGSTABLfile.
-
Clear Subfile (
sf1clrSubroutine):- Purpose: Clears the subfile and resets record numbers.
- Actions:
- Sets
rrn1andrrnsv1to zero. - Clears display control indicators (
*IN40,*IN41) and setsSFLCLR(*IN42). - Writes the subfile control (
sflctl1) and resetsSFLCLR.
-
Program Termination:
- Purpose: Cleans up and exits.
- Actions:
- Closes all files.
- Sets
*INLR = *ONand returns to the caller withp$code(if a selection was made).
Business Rules¶
The MGSTABL program enforces the following business rules:
1. Parameter Validation:
- Requires a valid number of parameters; otherwise, it exits with a *detc return code.
- If no parameters are passed, the option field is protected, limiting user interaction to viewing.
- Table Type Validation:
- The table type (
c$type, derived fromp$type) must exist in theGSTABLfile. -
Invalid table types result in an error message ("Invalid Table Type Code") and a default header.
-
Search Filtering:
- Users can filter table records by entering a search string (
c$srch) that is scanned against the table description (tbdesc). -
Only matching records are loaded into the subfile.
-
Selection Mechanism:
- Users select a record by entering
1in the option field (s1opt). -
The selected table code (
tbcode) is returned viap$code, and the program exits. -
User Interface:
- The subfile displays up to 14 records per page (
pagsz1). - Users can navigate with:
- F12: Exit without selecting a value.
- PAGEDN: Load the next page of records.
- ENTER: Process selections or reposition based on changes to
c$typeorc$srch. - F10: Move the cursor to the control record for input.
-
Fields are protected in read-only mode if no parameters are passed.
-
Error Handling:
- Invalid table types trigger an error indicator (
*IN50) and a message. - The program ensures the subfile is cleared and repositioned correctly after errors or user repositioning.
Tables (Files) Used¶
- MGSTABLD: Display file (workstation file) with subfile
sfl1for user interaction, including thesflctl1control format andwdwovroverlay window. - GSTABL: Input-only file containing table values, accessed by key fields
tbtypeandtbcode, withtbdescused for descriptions.
External Programs Called¶
The MGSTABL program does not explicitly call any external programs. Unlike BB931, it does not use QCMDEXC, QMHSNDPM, or QMHRMVPM for message handling or overrides, as it relies on the display file for user interaction and direct file access for GSTABL.
Summary¶
The MGSTABL program is a lookup utility designed to allow users to select values from the GSTABL file, typically called by programs like BB931 to provide valid unit of measure codes (e.g., S1FRUM). It validates the table type, filters records based on a search string, and returns the selected code to the caller. The program uses a subfile-based interface with a page size of 14, supports navigation via function keys, and enforces business rules for parameter and type validation. It interacts with the GSTABL file for data and the MGSTABLD display file for user interaction, with no external program calls, making it a self-contained utility for table lookups.