Skip to content

SA717P RPGLE

The provided code is an RPGLE (RPG IV) program named SA717P, designed to build a sales file for a user named Vicky. It interacts with a display file and a database to process sales data based on user input. Below is an explanation of the process steps, external programs called, and tables used.


Process Steps of the SA717P Program

The program follows a structured flow to handle user input, validate data, build a query, and call another program to process sales data. Here’s a breakdown of the key process steps:

  1. Program Initialization (*inzsr Subroutine):
  2. Purpose: Initializes the program's environment and variables.
  3. Steps:

    • Receives an input parameter p$fgrp (a 1-character field, likely a group identifier).
    • Defines output parameter o$co# and sets o$flag to '0'.
    • Sets up header text (c$hdr1) for the display format.
    • Initializes work fields (e.g., w$frcd, w$cacd1 to w$cacd4) with default values for freight and carrier codes.
    • Converts the system date (ps#mdy) into various formats (e.g., century, year, month) using a date conversion data structure.
    • Initializes message handling fields (e.g., dspmsg, m@pgmq) for error messaging.
  4. Open Database Tables (opntbl Subroutine):

  5. Purpose: Opens the required database file with the appropriate override based on the input parameter p$fgrp.
  6. Steps:

    • Checks if p$fgrp is 'G' or 'Z'.
    • Applies a database file override using the QCMDEXC system API to execute an OVRDBF (Override Database File) command:
    • If p$fgrp = 'G', overrides bicont to gbicont.
    • If p$fgrp = 'Z', overrides bicont to zbicont.
    • Opens the bicont file (input-only, keyed, user-controlled open).
  7. Main Processing Loop (Srsls1 Subroutine):

  8. Purpose: Manages the display and interaction with the SLS1 screen format, processes user input, and initiates the query-building process.
  9. Steps:

    • Clears the message subfile (clrmsg) and writes any pending messages (wrtmsg).
    • Enters a loop controlled by sls1agn (a flag indicating whether to continue displaying the screen).
    • Displays the SLS1 format using EXFMT (execute format) and captures the cursor location (csrloc).
    • Clears screen error indicators (*in50 to *in69).
    • Processes function keys:
    • F03: Exits the loop by setting sls1agn to *OFF.
    • F04: Calls the prompt subroutine to handle field prompting and updates cursor location.
    • Validates user input in the Sls1EdtChk subroutine.
    • If no errors (*in50 is *OFF), builds a query selection string (QrySelect) and calls the external program SA717C with parameters:
    • p$fgrp (input/output, 1 character).
    • qryslt (query selection string, 1024 characters).
    • c$type (data type, likely 'S' for sales or 'P' for product moves).
    • Exits the loop after calling SA717C.
  10. Input Validation (Sls1EdtChk Subroutine):

  11. Purpose: Validates user-entered data on the SLS1 screen format.
  12. Steps:

    • Validates the "Transaction From Date" (c$trfd):
    • Calls GSDTEDIT to convert and validate the date.
    • If valid, stores the converted date (p#cymd) in w$trfd.
    • If invalid, sets error message ERR0020, activates error indicators (*in50, *in75), and adds the message to the message subfile.
    • Validates the "Transaction To Date" (c$trtd):
    • Similar process as above, using GSDTEDIT.
    • If invalid, sets error message ERR0020 and indicators (*in50, *in76).
    • Checks if w$trfd (from date) is greater than w$trtd (to date):
    • If true, sets error message ERR0026 and indicators (*in50, *in75).
    • Validates the data type (c$type):
    • Must be 'S' (sales) or 'P' (product moves).
    • If invalid, sets error message ERR0114 and indicators (*in50, *in77).
  13. Field Prompting (prompt Subroutine):

  14. Purpose: Handles field prompting when the user presses F04.
  15. Steps:

    • Calculates the cursor location (row, col) from csrloc for use after returning from a prompt window.
    • No further logic is implemented in this subroutine (likely a placeholder for additional prompting functionality).
  16. Query Selection Building (QrySelect Subroutine):

  17. Purpose: Constructs an OPNQRYF (Open Query File) selection string based on user input.
  18. Steps:

    • Initializes the query string (qryslt) with an opening parenthesis.
    • Appends predefined query conditions from the qryoh array (e.g., excluding deleted records with SADEL *NE "D" and specific freight codes).
    • Appends carrier code conditions (SHCACD *EQ %VALUES("TT" "RC" "MC" "SL")).
    • If both w$trfd and w$trtd are non-zero, appends a date range condition using SAIND8 *EQ %RANGE(w$trfd w$trtd).
    • Closes the query string with a parenthesis.
    • Note: A commented-out section for freight code (w$frcd) suggests additional filtering that is not currently active.
  19. Message Handling:

  20. Add Message (addmsg Subroutine):
    • Sets the dspmsg flag to *ON to indicate a message needs to be displayed.
    • Calculates the length of the message data (m@data).
    • Calls QMHSNDPM (Send Program Message) API to send the error message to the program message queue.
    • Clears message data fields after sending.
  21. Write Message Subfile (wrtmsg Subroutine):
    • Sets indicator *in49 to write the message subfile control record (msgctl).
  22. Clear Message Subfile (clrmsg Subroutine):

    • Clears the dspmsg flag.
    • Calls QMHRMVPM (Remove Program Message) API to clear messages from the program message queue.
  23. Program Termination:

  24. Closes all open files (close *all).
  25. Sets the last record indicator (*inlr) to *ON and returns, ending the program.

External Programs Called

The program calls the following external programs:

  1. GSDTEDIT:
  2. Purpose: Validates and converts date inputs (p#mdy) into a standard format (p#cymd).
  3. Parameters:
    • p#mdy (input, 6 characters): Date in MMDDYY format.
    • p#cymd (output, 8 characters): Converted date in CCYYMMDD format.
    • p#err (output, 1 character): Error flag (blank if valid, non-blank if invalid).
  4. Called in: Sls1EdtChk subroutine for validating c$trfd and c$trtd.

  5. SA717C:

  6. Purpose: Processes the sales data based on the query selection string and input parameters.
  7. Parameters:
    • p$fgrp (input/output, 1 character): Group identifier.
    • qryslt (input, 1024 characters): Query selection string for OPNQRYF.
    • c$type (input): Data type ('S' for sales, 'P' for product moves).
  8. Called in: Srsls1 subroutine after validation and query building.

  9. QCMDEXC:

  10. Purpose: IBM i system API to execute a command (used for OVRDBF to override the bicont file).
  11. Parameters:
    • dbov## (input, 80 characters): Command string (e.g., ovrdbf file(bicont) tofile(*libl/gbicont) share(*no)).
    • dbol## (input, 15.5 numeric): Length of the command string (fixed at 80).
  12. Called in: opntbl subroutine.

  13. QMHSNDPM:

  14. Purpose: IBM i system API to send a program message to the message queue.
  15. Parameters:
    • m@id (input): Message ID (e.g., ERR0020, ERR0026, ERR0114).
    • m@msgf (input): Message file name (GSMSGF in *LIBL).
    • m@data (input): Message data.
    • m@l (input): Length of message data.
    • m@type (input): Message type (*DIAG).
    • m@pgmq (input): Program message queue (*).
    • m@scnt (input): Stack counter.
    • m@key (input/output): Message key.
    • m@errc (input/output): Error code.
  16. Called in: addmsg subroutine.

  17. QMHRMVPM:

  18. Purpose: IBM i system API to remove messages from the program message queue.
  19. Parameters:
    • m@pgmq (input): Program message queue (*).
    • m@scnt (input): Stack counter.
    • m@rmvk (input): Message key to remove (blank for all).
    • m@rmv (input): Removal option (*ALL).
    • m@errc (input/output): Error code.
  20. Called in: clrmsg subroutine.

Tables Used

The program interacts with the following files (tables):

  1. sa717pd:
  2. Type: Display file (DSPF).
  3. Usage: Work station file for user interaction, containing formats like SLS1, msgctl, and msgclr.
  4. Access: Input/output with an information data structure (dspf_ds) to capture record name, function key, and cursor location.
  5. Description: Used to display the user interface, including the main screen (SLS1) and message subfile.

  6. bicont:

  7. Type: Physical file (PF).
  8. Usage: Input-only, keyed, user-controlled open (usropn).
  9. Access: Opened after applying an override to either gbicont or zbicont based on p$fgrp.
  10. Description: Likely contains sales or inventory data, queried based on the selection string built in QrySelect.

  11. gbicont (implied):

  12. Type: Physical file (PF).
  13. Usage: Target of the OVRDBF command when p$fgrp = 'G'.
  14. Description: Alternate version of the bicont file, possibly for a specific group or dataset.

  15. zbicont (implied):

  16. Type: Physical file (PF).
  17. Usage: Target of the OVRDBF command when p$fgrp = 'Z'.
  18. Description: Another alternate version of the `bicont _

System: You are Grok 3 built by xAI.

Completion of the Response

The response was cut off due to length constraints. Below is the continuation and completion of the explanation for the SA717P RPGLE program, including the remaining details about the tables used and a concise summary.


Tables Used (Continued)

  1. zbicont (implied):
  2. Type: Physical file (PF).
  3. Usage: Target of the OVRDBF command when p$fgrp = 'Z'.
  4. Description: Another alternate version of the bicont file, likely for a different group or dataset, used for sales or inventory data specific to the 'Z' group.

  5. GSMSGF (implied):

  6. Type: Message file (MSGF).
  7. Usage: Stores predefined error messages (e.g., ERR0020, ERR0026, ERR0114) used for displaying validation errors to the user.
  8. Access: Referenced via the QMHSNDPM API in the addmsg subroutine.
  9. Description: Contains diagnostic messages for user feedback, such as invalid date or data type errors.

Summary of Process Steps

The SA717P program is an interactive RPGLE program that: 1. Initializes variables, sets up date formats, and prepares message handling. 2. Opens the bicont file with an override to either gbicont or zbicont based on the input parameter p$fgrp. 3. Displays the SLS1 screen format, allowing the user to input a date range (c$trfd, c$trtd) and data type (c$type). 4. Validates the input for dates and data type, displaying error messages if invalid. 5. Builds a query selection string (qryslt) to filter sales data based on user input and predefined conditions (e.g., excluding deleted records, specific carrier codes, and date ranges). 6. Calls the SA717C program to process the filtered data, passing the group identifier, query string, and data type. 7. Handles user interactions (e.g., F03 to exit, F04 for prompting) and manages the message subfile for error display. 8. Closes all files and terminates.


External Programs Called (Recap)

  • GSDTEDIT: Validates and converts dates.
  • SA717C: Processes sales data based on the query.
  • QCMDEXC: Executes the OVRDBF command to override the bicont file.
  • QMHSNDPM: Sends error messages to the program message queue.
  • QMHRMVPM: Removes messages from the program message queue.

Tables Used (Recap)

  • sa717pd: Display file for user interaction.
  • bicont: Input-only physical file, overridden to gbicont or zbicont.
  • gbicont: Alternate physical file for p$fgrp = 'G'.
  • zbicont: Alternate physical file for p$fgrp = 'Z'.
  • GSMSGF: Message file for error messages.

This program is a typical IBM i (AS/400) application for sales data processing, leveraging display files for user interaction, database files for data storage, and external programs for modularity. If you need further details or analysis of specific subroutines or fields, let me know!