Skip to content

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:

  1. Initialization (*inzsr Subroutine):
  2. Purpose: Sets up the program environment.
  3. Actions:

    • Defines the entry parameter list to receive p$type (table type) and p$code (selected table code, returned to the caller).
    • Initializes subfile control fields: rrn1 and rrnsv1 (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 ') and kltype (key list for GSTABL access using k$type and c$type).
  4. Error Handling (*pssr Subroutine):

  5. Purpose: Validates the number of parameters passed to the program.
  6. Actions:

    • Checks the program status data structure (psds##) for parameter errors (ps#err = 221).
    • If incorrect parameters are detected, sets the return code to *detc and exits.
    • Note: This subroutine is executed at the start of the program to ensure valid parameters before proceeding.
  7. Process Parameters (@parms Subroutine):

  8. Purpose: Handles input parameters and sets up the display.
  9. Actions:

    • Sets global protection indicator *IN70 to *ON by default (fields protected).
    • If at least one parameter is passed (ps#prm >= 1), moves p$type to c$type (control field for table type) and sets *IN70 to *OFF (fields unprotected for input).
    • Ensures the program Austenite subfile is enabled for user interaction when parameters are provided.
  10. Process Subfile (srsfl1 Subroutine):

  11. Purpose: Manages the main user interface loop, displaying and processing the subfile (sfl1) for table values.
  12. Actions:

    • Initial Positioning:
    • Calls sf1rep to clear and reposition the subfile based on c$type and c$srch.
    • Main Loop (sf1agn):
    • Writes an overlay window record (wdwovr) and the subfile control format (sflwdw1).
    • Sets display control indicator (*IN40 for SFLDSPCTL) and displays the subfile control (sflctl1) using EXFMT.
    • Checks for existing subfile records to set the display indicator (*IN41 for SFLDSP).
    • 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$type or c$srch changes, repositions the subfile (sf1rep).
    • Continues the loop until sf1agn is set to *OFF (e.g., via F12 or selection).
  13. Process Subfile on ENTER (sf1prc Subroutine):

  14. Purpose: Handles subfile selections when the user presses ENTER.
  15. Actions:

    • Reads changed subfile records (readc sfl1) if the subfile is not empty (rrn1 > 0).
    • Processes each changed record by calling sf1chg.
  16. Process Subfile Record Change (sf1chg Subroutine):

  17. Purpose: Processes user selections in the subfile.
  18. Actions:

    • If the option field (s1opt = 1), calls sf1s01 to handle the selection.
    • Exits the subfile loop after a selection is made.
  19. Select Value (sf1s01 Subroutine):

  20. Purpose: Returns the selected table code to the caller.
  21. Actions:

    • Moves the selected table code (tbcode) to the output parameter p$code.
    • Sets sf1agn to *OFF to exit the subfile loop, returning control to the caller.
  22. Reposition Subfile (sf1rep Subroutine):

  23. Purpose: Clears and reloads the subfile based on user input.
  24. Actions:

    • Clears the subfile (sf1clr).
    • Validates control input (sf1cte).
    • If no errors (*IN50 = *OFF), positions the GSTABL file using c$type and loads records (sf1lod).
    • Retains control fields (c$type, c$srch) in r$type, r$srch, h$type, and h$srch for repositioning.
    • Calculates the length of the search string (c$srch) for filtering.
  25. Edit Subfile Control Input (sf1cte Subroutine):

  26. Purpose: Validates the table type in the control record.
  27. Actions:

    • Chains c$type to GSTABL using the key list kltype.
    • 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 from com(01) ("Invalid Table Type Code").
  28. Subfile Protection Schemes (sf1pro Subroutine):

    • 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).
  29. Load Subfile Records (sf1lod Subroutine):

    • Purpose: Loads table records into the subfile.
    • Actions:
    • Starts from the last subfile record number (rrnsv1).
    • Reads records from GSTABL using c$type until the page size (pagsz1 = 14) or end of file (*IN43).
    • Filters records if a search string (c$srch) is provided, using the SCAN operation to match tbdesc.
    • Formats each record (sf1fmt) and writes to sfl1, incrementing rrn1.
    • Saves the last record number (rrnsv1) and clears cursor coordinates.
  30. Format Subfile Detail Line (sf1fmt Subroutine):

    • Purpose: Formats a subfile record for display.
    • Actions:
    • Clears the option field (s1opt).
    • Note: The program assumes fields like tbcode and tbdesc are displayed directly from the GSTABL file.
  31. Clear Subfile (sf1clr Subroutine):

    • Purpose: Clears the subfile and resets record numbers.
    • Actions:
    • Sets rrn1 and rrnsv1 to zero.
    • Clears display control indicators (*IN40, *IN41) and sets SFLCLR (*IN42).
    • Writes the subfile control (sflctl1) and resets SFLCLR.
  32. Program Termination:

    • Purpose: Cleans up and exits.
    • Actions:
    • Closes all files.
    • Sets *INLR = *ON and returns to the caller with p$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.

  1. Table Type Validation:
  2. The table type (c$type, derived from p$type) must exist in the GSTABL file.
  3. Invalid table types result in an error message ("Invalid Table Type Code") and a default header.

  4. Search Filtering:

  5. Users can filter table records by entering a search string (c$srch) that is scanned against the table description (tbdesc).
  6. Only matching records are loaded into the subfile.

  7. Selection Mechanism:

  8. Users select a record by entering 1 in the option field (s1opt).
  9. The selected table code (tbcode) is returned via p$code, and the program exits.

  10. User Interface:

  11. The subfile displays up to 14 records per page (pagsz1).
  12. 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$type or c$srch.
    • F10: Move the cursor to the control record for input.
  13. Fields are protected in read-only mode if no parameters are passed.

  14. Error Handling:

  15. Invalid table types trigger an error indicator (*IN50) and a message.
  16. The program ensures the subfile is cleared and repositioned correctly after errors or user repositioning.

Tables (Files) Used

  1. MGSTABLD: Display file (workstation file) with subfile sfl1 for user interaction, including the sflctl1 control format and wdwovr overlay window.
  2. GSTABL: Input-only file containing table values, accessed by key fields tbtype and tbcode, with tbdesc used 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.