SQL query tool
SAFE X3 technology includes a Query tool function (GESALH) designed to create inquiry screens from queries expressed as lists of fields drawn from database tables. These tables are linked either by default or through explicitly defined relationships. This approach enables you to quickly build queries without needing to learn a specific query language, requiring only a basic understanding of the database structure. Such knowledge can be supported by technical documentation (such as the MCD pages).
The tool also provides a user-friendly interface with multi-column inquiry screens and supports navigation through tunnels. However, it has limitations when handling complex queries that cannot be represented as simple lists of fields. For technically skilled users familiar with SQL, this tool may not deliver the desired flexibility or results.
To address this, this additional SQL query tool was introduced, allowing you to write queries using standard SQL syntax. This tool differs from the standard query tool only in its setup screen. The resulting inquiry screens are executed through the same View queries function (EXEALH). Like the standard tool, it operates by temporarily extracting data into a table for consultation. However, inquiries are limited to a single level, and features such as breaks and totals are not supported at this stage.
As with the classic query tool, the temporary table structure ensures that each user retains the results of their last executed query. Using this functionality involves three steps:
-
Define the query using the function, then validate it to generate the corresponding inquiry screen.
-
Run the query by clicking the Run button.
-
Consult the results if the query has already been executed.
Prerequisites
Refer to the implementation documentation.
Screen management
The screen is defined in 3 tabs:
Header
The header provides information to identify the query, along with general configuration settings.
General information
| Query (COD) |
|
This code is used to identify a request. |
| Description (INTIT) |
|
Use this field to assign a description to each record. |
| Short description (INTITSHO) |
|
This title, which describes the record, is used in some screens or records when there is not enough space to display the long title. |
| Factory owner (AFACTORYOWN) |
| Indicates if the query is delivered by Sage. You cannot modify factory queries. |
| Active (ENAFLG) |
|
Select this checkbox to activate the current record. Inactive records keep their content and configuration but cannot be used by recalling their code:
Authorizations for a given function can restrict the creation of an active record. In this case, the checkbox is disabled by default. It can only be modified by an authorized user or through a signature workflow. |
Characteristics
| Query type (ALLUSR) |
|
This field controls how your query displays in inquiry mode. Three options are available:
|
| Representation (REPGRA) |
|
This indicator defines how data will be displayed on the screen. The available display modes are as follows:
|
| Default display or graphical position (OPTGRA) |
|
This setting defines how the graphical representation is positioned relative to the grid when the data display mode allows both formats.
|
| Activity code (CODACT) |
|
An activity code is used to:
|
| Module (MODULE) |
| Select the module to which your query belongs. |
Setup tab
You can use the first block to define the query and specify general parameters.
In the Columns grid, you can provide details to refine the presentation of the results. When the query is executed, it returns a list of values displayed in a grid. If no additional information is provided:
-
The grid columns have no titles.
-
Data types default to generic formats (alphanumeric, numeric, or date) based on the returned values.
A fixed SQL query offers limited flexibility. To make the query dynamic, you need to include parameters that can be entered at runtime. Use the Parameters grid to do so.
First block
| Report (RPT) |
|
Define the report code associated with the File / List function from the query inquiry. If no report code is specified, the ALISTE report is used, which applies a standard page format. You can duplicate this generic report and adjust the page format to create a custom report tailored to the inquiry. The report code entered here can also be linked to a set of print codes using the dedicated function. |
| Function (FCTLNK) |
|
Define the report code associated with the File / List function from the query inquiry. If no report code is specified, the ALISTE report is used, which applies a standard page format. You can duplicate this generic report and adjust the page format to create a custom report tailored to the inquiry. The report code entered here can also be linked to a set of print codes using the dedicated function. |
| Access code (ACS) |
|
Define the report code associated with the File / List function from the query inquiry. If no report code is specified, the ALISTE report is used, which applies a standard page format. You can duplicate this generic report and adjust the page format to create a custom report tailored to the inquiry. The report code entered here can also be linked to a set of print codes using the dedicated function. |
| Number of lines (NBRLIG) |
|
Define the number of logical lines displayed per page in the inquiry screen generated by the query designer. If the specified number exceeds the available physical display space, a vertical scroll bar appears on the right side of the grid. Navigation buttons at the top of the screen allow you to move between logical pages (First, Previous, Next, Last). |
| Maximum lines (MAXLIG) |
|
Specify the maximum number of lines to return. This corresponds to the query parameter maxrows, which stops the search once the specified number of rows meeting the conditions is found in the database. These rows are then sorted, but the database does not guarantee that the retrieved rows are the first N in the final sort order. This parameter is an optimization to reduce database load. |
| Group (GRP) |
|
You can make a classification criterion available for use in queries. |
| No. of fixed columns (NBRCOL) |
|
Use this field to fix the first X columns of a grid when horizontal paging is enabled. |
| Maximum times (MAXTIM) |
|
Specify the maximum execution time for the search in seconds. If this time limit is reached, the search stops automatically. This helps avoid long wait times, especially when setting up a new query. Unlike the maximum number of lines, this setting is not sent to the database. The maximum time limit can still be exceeded if the inquiry takes too long to process.
|
SQL query
| (TEXTE) |
|
Enter your query in standard SQL syntax recognized by the database. Key points:
|
Columns grid
| Description (COLTIT) |
| This field displays the column's name. |
| Type (COLTYP) |
|
This data type specifies how the data displays. For a local menu, enter the corresponding menu number. If the selected data type is linked to an object, a tunnel to the object management screen will be available during the inquiry. |
| Menu (COLNUM) |
|
Specify the local menu number used to display the numerical value of the corresponding column returned by the query. |
| Graph type (GRA) |
|
You can only modify this field if the representation mode in the header is not set to Character. It specifies how the field is used in the graphical representation. Possible values:
|
| Representation (REP) |
|
You can only edit this field:
Used to manage graph combinations when the selected graph type (defined in the graphical parameters) supports multiple series, even of different types. If the graph type does not allow multiple series, this setting is ignored. Available combinations include:
The rule is as follows :
|
Parameters grid
| Description (PARTIT) |
|
If this field is filled in, you can enter a parameter with a title matching this field before executing the query via the Criteria button. You can reference this parameter in the query body using the %N% syntax, where N is the line number of the parameter in the Parameters grid. |
| Type (PARTYP) |
|
This data type simplifies the corresponding parameter's entry.
|
| Menu (PARNUM) |
|
Specify the local menu number used to enter the parameter value. |
| Default value (VALDEB) |
|
You can enter a default value for the parameter. |
Graph tab
You can edit this tab only if a graphical representation is available for the query. It allows you to define how the data displays in the chart.
Graph
| Type (TYPGRA) |
|
You can use this field when the grid contains multiple numeric values that can be displayed graphically. It supports two options:
|
| Representation (FSHGRA) |
|
When multiple series are displayed in a graph, provided they share the same presentation style and are not of the sector type, you can define how their values are combined by selecting one of the following options
|
| Default graph (DEFGRA) |
|
This field defines the type of graphical representation used to display the data. Options include Bars, Lines, Area, or Sectors. An image displays based on the selected option. If only one data series is available, the default representation is determined by this parameter. If multiple series are present, you can mix presentation modes (for example, one series as bars, another as lines). In this case, each series uses the value specified in the Representation field in the grid:
When only one series is displayed, a graph type selector is available, allowing the user to choose a different presentation mode. |
| (IMAG) |
|
Visual representation of the previously entered information. |
The SQL query tool does not apply any authorization-based filters (whether by role, site, or access codes).
To ensure security:
-
Protect these queries with an access code to restrict both display and execution rights.
-
Limit access to this function to a restricted list of users.
Specific buttons
-
Validate
This button generates the inquiry screen associated with the query and validates the query by submitting it to the database to check both syntax and semantics.
-
Run
Select this button to run the current query by updating a temporary table, which is then transmitted to the inquiry function. This process allows you to view your query's results.
-
Copy
This button is used to copy the record definition from or to another folder.
The following fields are included on the window opened through this button:
Block 1
(OBJET)
(CLES)
Block 2
From folder (DOSORG)
Use this field to define the folder from which the record will be copied. The possible syntaxes are described in the dedicated appendix.
All folders (TOUDOS)
Use this option to copy the record to all the folders defined in the dictionary (ADOSSIER table of the current solution).
To folder (DOSDES)
Use this field to define the folder to which the record will be copied. The possible syntaxes are described in the dedicated appendix.
Error messages
Other than the generic messages, the following error messages can appear when entering data:
Incorrect query
Your query is incorrect.
[Error description returned by the database]
From the database perspective, the query is invalid. This can be due to a syntax error or because a referenced element does not exist. The error description corresponds to the message returned by the database.
Not possible to access this record
An attempt was made to access a query created with the classic query tool using the SQL query tool. This is not allowed because query codes are tool-specific:
-
You cannot use codes from an SQL query to reference a classic query.
-
Likewise, you cannot use codes from a classic query for an SQL query.
Too many fields
The query has returned too many columns. The SQL query tool supports a maximum of 120 columns. Reduce the number of columns in your query and try again.
Tables used
Refer to the implementation documentation.