Page 6
Selecting files on the Query for iSeries Select File display ....37 Selecting file members on the Query for iSeries Select Member display ... . 39 Selecting record formats on the Query for iSeries Select Record Format display .
Page 7
Letting Query for iSeries select records ......91 Selecting the records you want in Query for iSeries ....91 Comparison fields in Query for iSeries .
Page 8
Record on one page in Query for iSeries reports ....147 Displaying wrapping widths in Query for iSeries reports ....147 Defining output to the printer in Query for iSeries reports .
Page 9
Appendix A. Differences between Query for iSeries and Query/36 Conceptual Differences ......195 Operational Differences .
Page 10
Running a Query for iSeries query ......251 Running a default query in Query for iSeries ..... 251 Selecting records at run time in Query for iSeries .
You may need to refer to other IBM books for more specific information about a particular topic. For a list of publications related to this book, see the “Bibliography”.
Chapter 1. What is Query for iSeries? ® Query for iSeries is an IBM licensed program and a decision support utility that can be used to obtain information from the DB2 Universal Database for iSeries database. It can obtain information from any...
Another record format, named contain only the Figure 2. Three Records in NAMEADDR File (Using Record Format ZIPADDRESS) Query retrieves the data you want from the files you choose. It uses certain fields (and record formats) from those files to select, sort, calculate, and summarize that data in the form you want. It also produces the query reports containing that data.
v CL and DDS use the same terms and descriptions as IDDU, but they provide additional support for files. Using DDS and CL commands, you can define and create physical files and logical files to indicate how fields are to be organized in files. A physical file contains the fields of data, as records, but logical files do not.
Page 18
Figure 3. Major Tasks on the Query Menu and the Work with Queries Display Query for iSeries Use V5R2...
Using Query for iSeries function keys Function keys like Enter, Help, and Print can be used at any time with any query display. However, not all the function keys (such as F3, F4, and F11) apply to all displays. Each display shows, at the bottom of the display, which function keys are commonly used with that display (all the available keys may not be shown).
DBCS characters take twice the amount of space of SBCS characters. In addition, a shift-out character precedes DBCS data, and a shift-in character follows the data. The shift-out and shift-in characters are called DBCS bracket characters. DBCS-graphic data is stored in the database without bracket characters; however, the bracket characters are present when DBCS-graphic data is displayed or printed.
The number of items shown in the list part of the display varies, depending on what form the list is in and the amount of space used by the prompt part of the display. Sometimes a new display will appear that shows the list.
Using Query for iSeries commands A command is a statement used to request a function of the system. This means you need only remember a command that is a few characters long instead of remembering all the individual instructions or taking the time to go through a series of menus. Query has four commands, which can be entered from any command line: v STRQRY brings up the Query menu.
If you select option 3 (Delete a query) on the Query Utilities menu, you are shown the prompt display for the Delete Query (DLTQRY) command. You can use this command to delete a query definition. If you do not know the name of a query or library, use option 1 (Work with queries) so that you can get a list of queries and libraries.
9=Run Runs a query. Query displays a report, prints a report, or puts the data into a database file, depending on what is specified in the query definition. For information about running queries, see Chapter 15. Specifying a Query for iSeries query and its library To identify the query you want to work with, you can type the name of the query (in the Query prompt) and the name of the library (in the Library prompt) in which it is to be stored (or is already stored).
You can select as many as 30 queries from the list, as well as type a query name and option in the first list position of this display. Query processes the requests in the order that they appear in the list, starting first with the option and query that you typed in the first list position (in the input fields of the Option and Query columns).
library group are shown. For example, if you typed in the Subset prompt, you might see a list of query names like: , and so on. (The queries are shown alphabetically for each library.) You can also specify a complete name (without an *) in the Subset prompt. Continuing the previous example, if you want to see which libraries contain queries named , type that complete query name in the Subset prompt.
After you press F11, all lists on all the Query displays that use F11 are shown in the form you chose until you press F11 again. Selecting a library for your Query for iSeries queries The library name indicates where you want to store a new query or where an existing query is already stored.
Other considerations when you are trying to locate or use a particular Query for iSeries query You should be aware of other considerations when you are trying to locate or use a particular query. To use a query: v You must have the authority needed to use the query definition. You may need to either ask the owner of the query, the administrator, or security officer to give you the type of authority that is necessary.
v Change or display a query from the Work with Queries display or use the run-time option of the RUNQRY command, and the query was defined with a numeric constant and the decimal separator saved with the query does not match your current decimal separator. v Press F17 from the Select Records display.
Page 31
select only the option(s) that need to be changed and then, when you are shown the appropriate display, you need only type the new choices or change the incorrect ones. Everything else you defined earlier remains defined; you do not have to redefine the whole query. If you just want to quit, press F3 (Exit) to go to the Exit This Query display.
Page 34
Query for iSeries date ......67 Query for iSeries time ......67 Query for iSeries timestamp Displaying constants format in Query for iSeries .
Page 35
Numeric constants as values in Query for iSeries....94 Date, time, timestamp constants as values in Query for iSeries Null values in Query for iSeries ......95 Comparison tests in Query for iSeries .
Page 36
Edit code in Query for iSeries reports Optional edit code modifier in Query for iSeries reports ....131 Specifying edit words ......131 Edit word in Query for iSeries reports Edit word for summary total in Query for iSeries reports .
Page 37
Using function key F5 when running a Query for iSeries query ....169 Running a Query for iSeries query from the Query for iSeries menu ... . 169 Running a Query for iSeries query from the Exit This Query display .
If you position the cursor on the Query prompt and press F4 (Prompt) to show a list, it contains the names of all the queries that are in the library (or libraries) indicated by the Library prompt. You can get a smaller list by typing a generic name in the Query prompt before you press F4.
Selecting options for a Query for iSeries query definition To select options that you want to use from those listed in the Query Definition Option column, type a 1 in the Opt (option) column beside each of those options, then press the Enter key. The displays for the options you select are then shown one after the other so you can create those parts of the query definition.
You can specify one, several, or all of the options shown. To select all of them, press F21. Moving through the Query for iSeries definition displays For each option you select, Query shows you the definition displays for that step. (The words shown for each option on the Define the Query display match the title of the first display shown for that definition step.) After you specify your definition values on a display, press the Enter key to have them included in the query definition and to go to the next display in the sequence.
Suggested sequence of tasks for creating Query for iSeries queries The following is a suggested sequence of tasks to create queries: 1. Define result fields before selecting and sequencing fields. 2. Specify comparisons used for selecting records before selecting and sequencing fields. 3.
The Specify File Selections display is used to specify one or more database files that you want to query for the data in your report. You can specify as many as 32 files to be queried, and you can assign unique 3-character identifiers to each one.
v If you type a generic library name (in the form of the Enter key, that library group is searched for the file named in the File prompt. If the file is found in one of the libraries, the name of that library replaces the special library or generic name. v If you type a generic library name (in the form of the cursor in this prompt, the specified list of library names is shown on the Select Library display.
Using file IDs for a Query for iSeries query File IDs are used when you select more than one file. Although Query assigns a file ID value to each file selection, you can specify your own identifier. Note: When you are creating a query, the File ID prompt is not shown for your first file selection. However, if you select more than one file, you will see that Query has assigned the value the file ID of your first file.
v If you typed a file name and left blank any of the Library, Member, or Format prompts for the file v If there is a problem with one of the values you typed The cursor is positioned to the blank prompt or the prompt in error, and the message describes the error for that prompt.
Page 50
Specify File Selections display, it is used as a subset value on this display, and only file names starting with those generic characters are included in the list. (You can specify another subset value on this display to change the subset shown.) You can use the Library prompt to see the files that exist in a different library or group of libraries.
To return to the complete list of file names, blank out this prompt (or put an * in it) and press the Enter key. To move (position) the list of file names so that it starts with a particular name, move the cursor to the Position to prompt and type all of the characters or one or more of the starting characters in the name you want, and press the Enter key.
If you came from the Specify File Selections display or Specify Dependent Value Qualifiers display, you can specify which member you want your query to get data from. If you came from the Define Database File Output display, you can specify which member you want the query data to be put into. At the top of the display, the File ID field is shown if you came here from the Specify File Selections display.
At the top of the display, the File ID field shows the file ID of the file that appears in the File field. This file is the one for which you want to choose a record format. The Library field shows the library in which the file is stored.
If multiple file selections are shown, you can press the Enter key to show the join type and all the join tests for these same files. However, if you came to this display from the Specify File Selections, Change File Selections, Specify Type of Join, or Specify How to Join Files display, the Enter key returns you to the previous display.
Types of joins in a Query for iSeries query There are three types of joins, or three ways that you can select matched or unmatched records from the specified files. You can: v Select only records that have matching records in all the specified files. v Select all primary records, and include all matching secondary records.
Note: See “CCSID and join tests in Query for iSeries” on page 252 for information on how CCSIDs can affect your join selections. For each test, you specify two fields to be tested and the test value to be used. Look for a field in one file that contains the same (or similar) information that can be found in a field of the other file, such as a name or identification number.
Page 57
v A field name must be preceded by a 1- to 3-character file identifier if that field name is used in more than one file selected for the query. v You can specify up to 100 join tests. v For a matched-record join, if one or both fields in a join test are null, the records are not joined. v The data in both fields of a join test must be the same type (for example, both character), except that date, time, or timestamp fields can be compared to SBCS character, DBCS-either, or DBCS-open fields that contain a correct representation of a date, time, or timestamp.
You can obtain several different results from a file join when you use different combinations of join tests and options on the Specify How to Join Files display. Following are some examples of how you might use the three different types of joins. All of the examples assume that was specified on the Specify How to Join Files display.
Example: Selecting matched records using a primary file in a Query for iSeries query Type a 2 if you want to include in the query output every record in the primary file and all the matching records from all the other (secondary) files, whenever they exist. Every record in the primary file is selected whether or not it has a match.
In our example, the file is still the primary file, so only its records that do not have a matching secondary record are included in the query report. The file has two such unmatched records; the residents identified in records 2 and 6 do not have a telephone number, so there are no records for them in the secondary file.
Page 62
Correct method: On the Specify File Selections display, type the file first, the file second, and the file third. Specify the file IDs , , and , respectively. The join type is 2 (Matched records with primary file). The join tests are: Query performs the file join in two steps: Step 1: Join the first two files, and .
Page 63
Incorrect method: On the Specify File Selections display, type the file first, and specify the file ID as . Type the file second (file ), and the file third (file ), which is in the opposite order from the correct method.
Page 64
Query performs the file join in two steps: Step 1: Join the first two files, and . Query joins the files in the order listed, starting with file ), and file ). But there is no join test that compares a field in to a field in .
every record in file . Because there are three records in The join tests are not used in this step. The result of step 1 this time is a working file called Step 2: Join file to file . Query joins each record in file equals .
The Field columns show the fields being used to join the files. Each field name can have two parts: the file ID and the actual name of the field, separated by a period. For example, if a field named exists in files used in this query, they would be shown as find the files associated with the file IDs (such as display.
Handling missing fields during file selection process of a Query for iSeries query While you were changing a query, or were defining a new query that already had file selections specified, you chose the Specify file selections option on the Define the Query display. Then, on the Specify File Selections display, you selected a file or format that does not have all of the report fields that your first selection contained.
Page 68
problems caused by the missing fields. You must also ensure that none of the fields were used in break test values on the Format Report Break display. On the definition displays for the affected steps, the expressions or selection tests that use fields that are now missing are highlighted. v If you press F12 (Cancel), you return to the Work with Queries display without affecting your previous file (and field) selections.
always appears below and to the right of the list to tell you where you are in the list. More... means that there are more items after, and possibly before, the items currently shown. Bottom means that you are at the end of the list, but there may be more items before those currently shown.) Use F19 (Next group) to reposition the list at the beginning of the next logical group of fields (the cursor can be anywhere when you use F19).
DAYS MONTH YEAR v A time expression performs an operation on a time. Time expressions can contain the following operators or functions: + (Addition) − (Subtraction) CHAR TIME HOUR MINUTE SECOND MICROSECOND v A timestamp expression performs an operation on a timestamp. Timestamp expressions can contain the following operators or functions: + (Addition) −...
When you do more than one calculation within a numeric expression, use parentheses to tell Query in what order to do the calculations and to make the expression easier to understand. If you use nested parentheses for example, example, ), then the next innermost pair, and so on. If you do not use parentheses, Query first does multiplication and division, left to right, and then addition and subtraction, left to right.
For example, if a character constant are concatenated, the result is a field containing the value expressions are: If any field is null-capable, the resulting field is null-capable. If any field used in a concatenation is null, the resulting expression is null. Except for the case of two DBCS-open fields, if all concatenated values are either fixed-length fields or constants, the result is a fixed-length field.
The argument must be an integer or decimal value. The result of the function is a fixed-length character string. The CCSID of the string is the default SBCS CCSID at the application server. If the argument can be null, the result can be null. If the argument is null, the result is a null value.
Note: If you are sending queries between countries that use the comma for a decimal point, put a blank after each comma separating values in a list of numeric values. The selected argument is converted, if necessary, to the attributes of the result. The attributes of the result are determined as follows: v If the arguments are dates, the result is a date.
Page 76
v If the first argument is UCS2 graphic data and the result is mixed data, the result length is (2.5*(n-1)) + The third argument, if specified, must be a valid SBCS or mixed CCSID. If it is a SBCS CCSID, the first argument cannot be a DBCS-either or DBCS-only string.
VARGRAPHIC Query for iSeries function The VARGRAPHIC scalar function provides a way to convert: v character data (SBCS and Mixed) to DBCS graphic. v character data (SBCS and Mixed) to UCS2 graphic. v UCS2 graphic to UCS2 graphic. v DBCS graphic to UCS2 graphic. expression The VARGRAPHIC function returns a graphic string representation of a string expression.
The actual length of the result depends on the number of characters in the argument. Each character of the argument determines a character of the result. Regardless of the CCSID, every double-byte code point in the argument is considered a DBCS character, and every single-byte code point in the argument is considered an SBCS character with the exception of the EBCDIC mixed data shift codes X’0E’...
Table 1. Formats for Representations of Date Data Types Format Name Abbreviation International Standards Organization IBM USA Standard IBM European Standard Japanese Industrial Standard Christian era OS/400 format Note about using SAA date format: To prevent confusion about the date value, use the Systems If the OS/400 two-digit year format is used, the range of dates is from 1940 through 2039.
(for use by the CHAR function) and an example of its use. Table 2. Formats for Representations of Time Data Types Format Name International Standards Organization IBM USA Standard IBM European Standard Japanese Industrial Standard Christian era OS/400 format Note: Time separators can be either a period (.), slash (/), comma (,), dash (-), or a blank space.
Displaying constants format in Query for iSeries The Display Constants Format display shows you what date or time format you must use if you specify a date or time constant and do not use an SAA format. The Display Constants Format display appears when you: v Change a query from the Work with Queries display and at least one date or time constant is specified in the query definition in an OS/400 format other than the date or time format specified for your job.
Subtraction rules are different from addition rules because a date, time, or timestamp value cannot be subtracted from a duration. Also, subtracting two date, time, or timestamp values is not the same as subtracting a duration from a date, time, or timestamp value. The following rules apply to date, time, and timestamp subtraction: v If the first operand is a date, the second operand must either be a: –...
For example, the result of DATE(’3/15/2000’) - ’12/31/1999’ is 215, or a duration of 0 years, 2 months, and 15 days. Incrementing and decrementing dates in Query for iSeries The result of adding a duration to or subtracting a duration from a date is itself a date. It must be between January 1, 0001 and December 31, 9999 inclusive.
Page 84
selection on specific year, month, and day values. The marked (*) lines are necessary and a sample report follows. If you require rounding for fields in the report (instead of truncation), you can add to each of the intermediate expressions a minus one half, as follows: Example 2: Working with numeric dates in Query for iSeries: This example shows the reverse in formatting—...
Time arithmetic operation in Query for iSeries Times can be subtracted, incremented, or decremented. The result of subtracting one time (TIME2) from another (TIME1) is a time duration that specifies the number of hours, minutes, and seconds between the two times. For example, the result of TIME( and 30 seconds.
Timestamp duration in Query for iSeries A timestamp duration represents a number of years, months, days, hours, minutes, seconds, and microseconds expressed as a DECIMAL (20, 6) number. To be properly interpreted, the number must have the format yyyymmddhhMMsszzzzzz , where yyyy , mm , dd , hh, MM , ss and zzzzzz represent, respectively, the number of years, months, days, hours, minutes, seconds and microseconds.
DATE Query for iSeries function The DATE function returns a date from a value. The form is: expression The argument must be either a: v Timestamp v Date v Positive number or expression less than 3 652 059 v Valid character representation of a date v Character representation with a length of 7 If the argument is a character representation of length 7, it must represent a valid date in the form yyyynnn where yyyy represents the year digits and nnn represents digits between 001 and 366, signifying a day in...
If the argument is a date duration or a timestamp duration, the result is the day part of the value, a binary field with a value between −99 and 99. A nonzero result has the same sign as the argument. Example: RESULT(DAY) would equal a value between 1 and 31.
The resulting value of HOUR would equal 12. MICROSECOND Query for iSeries function The MICROSECOND function returns the microsecond part of a value. The form is: expression The argument must be either a: v Timestamp v Timestamp duration v Valid character representation of a timestamp The result of the function is a binary field.
MONTH Query for iSeries function The MONTH function returns the month part of a value. The form is: expression The argument must be either a: v Date v Timestamp v Date duration v Timestamp duration The result of the function is a binary field. If the argument can be null, the result can be null. If the argument is null, the result is null.
TIME Query for iSeries function The TIME function returns a time from a value. The form is: expression The argument must be either a: v Time v Timestamp v Valid character representation of a time The result of the function is a time value. If the argument can be null, the result can be null. If the argument is null, the result is null.
YEAR Query for iSeries function The YEAR function returns a numeric representation of the year part of a value. The form is: expression The argument must be either a: v Date v Timestamp v Date duration v Timestamp duration The result of the function is a binary field. If the argument can be null, the result can be null. If the argument is null, the result is null.
Converting date for output to a display or printer in Query for iSeries You can use the date functions to convert an input date field to a different format. Examples 1 and 2 show two methods of converting a date field from the MMDDYY format to the YYDDD format. Examples 3 and 4 show the reverse conversions, from YYDDD to MMDDYY format.
The commands to run the query in example 3 are: Example 3—Converting from YYDDD to MMDDYY format in Query for iSeries The following Define Result Fields panel defines a YYDDD to MMDDYY date conversion. The conversion is done completely within the panel. Example 4—Converting from MMDDYY to YYDD format in Query for iSeries This example shows an alternative method for the same conversion done in example 3.
The commands to run the query in example 4 are: General considerations when creating an expression in Query for iSeries Following are some general rules you should use when you are creating expressions: v Character constants that represent dates are evaluated using the date format stored in the query definition.
Page 96
– If your expression performs a division operation, avoid dividing by zero by defining the denominator as the result field just before the result field with a division. Then, for all logical OR groupings of record selection, add a logical AND test stating the denominator must not equal zero. v On the three lines provided, you can split a field name, numeric constant, or character string at the end of one line and continue it at the beginning of the next.
Column headings in Query for iSeries If you want to specify a column heading to be used for a result field, type the heading you want on the three lines (up to 20 characters each) of the display that correspond to your result field. The heading will appear in your query output exactly as you enter it on the three lines.
Example of defining a result field in Query for iSeries An example of how you would create a numeric result field called using the expression and using the report column heading is shown on the following display. The second input area shows how you would define a character result field called with a value of and no column heading.
Page 100
After making new selections or changing old ones, press the Enter key to rearrange them on the display in the new sequence. You can then renumber them with new sequence numbers in added amounts of 10 (10, 20, 30, and so on) by pressing F20. Renumbering can make it easier to add a field within the sequence later.
Page 101
You could then select the remaining fields for output on the report by pressing F21 (Select all). Query would then select and supply sequence numbers for the remaining fields in the order that they appeared in the list. Another way of making your selections is to first specify the same sequence number (a 1, for example) for all of the fields you want to select.
Page 102
After you have confirmed the fields you want by pressing the Enter key a second time without making any changes to your sequence choices, Query completes this step and takes you back to the Define the Query display so that you can continue with other query tasks. If you previously selected more options on the Define the Query display, Query shows you the first display for the next option.
Note: The value is not limited to the length of the line on the input display. If you need more space, continue on to the next line. You must separate all values with blanks. If one value ends at the end of the line and you continue on to the next line, you must include a blank space before the value on the next line.
Comparison values in Query for iSeries The value you compare the field with can be: v Another field v A numeric constant v A character constant (SBCS or DBCS) v A date constant v A time constant v A timestamp constant The field and the value you are comparing must be compatible data types.
SBCS character Timestamp DBCS-either DBCS-open v Any field can be compared to the keyword NULL using the IS or ISNOT test to determine if a field value is or is not null. Note: When comparing a date, time, or timestamp field with an SBCS, DBCS-either, or DBCS-open character field, use a character field for which each value can be recognized as an SAA formatted date, time, or timestamp.
Note: If you are sending queries between countries that use the comma for a decimal separator, put a blank after each comma separating the offset and length in the SUBSTR function and between numeric values in a list in the VALUE function. Press F17 to show which decimal separator to use in the query (see “Displaying the format of constants in Query for iSeries”...
Date, time, or timestamp comparisons in Query for iSeries A date, time, or timestamp value may be compared either with another value of the same data type or with a character representation of that data type. All comparisons are chronological. The farther a point in time is from January 1, 0001, the greater the value of that point in time.
Records are selected if the data in the field When you test for RANGE, the contents of the field must be within the range of two values (greater than or equal to the first value but less than or equal to the second) for the record to be selected. On the Select Records display, you must specify two values in the Value column, and you must separate them by a blank.
v Must be date constants if comparing to a date field. If the list contains correct representations of a date but in other than SAA format, you may get unexpected results. To prevent unexpected results, the list should be in SAA format. v Must be time constants if comparing to a time field.
You can use some special characters to represent the positions in the field that you do not care about: v An underscore (_) means skip one character at that position and do not test for that character. Each underscore takes the place of one character in the field. v A percent sign (%) means skip as many characters as necessary to get to the end of the field or to the next specified character.
Page 112
DBCS-only LIKE, NLIKE (not like) pattern in Query for iSeries: This pattern, which contains only double-byte characters, can be used for any bracketed-DBCS field, but not for a DBCS-graphic field. Start the pattern with a shift-out character and end it with a shift-in character. Use the DBCS percent sign (%%) to skip any number of characters or none at all.
If the test pattern consists of two apostrophes alone ( ) or two apostrophes enclosing only DBCS shift-out and shift-in characters ( ), the test pattern is treated as an empty string. These patterns will select records in which the field contains an empty string. Using more than one comparison test in Query for iSeries When you use more than one comparison, you need to tell Query how to connect them by typing a connection in the AND/OR column.
Page 114
You can use AND and OR connections together to be even more specific about which records to include in your report. The following example selects records for customers who placed orders from November 1986, through January 1987. Note that numeric constants are used for months. If written out, the above example looks like this: Because using a combination of AND and OR connections can be confusing, you might want to use F5 to look at your report and make sure your comparisons work the way you expect.
Written out, the example would look like this: Note: CCSIDs can affect how records are selected. See “CCSID and record selection tests in Query for iSeries” on page 253 for information on CCSIDs and how they affect record selections. Adding and removing comparisons in Query for iSeries The prompt part of the Select Records display only has room to show six comparisons at a time.
Page 118
When you press the Enter key after typing your sort priority numbers, Query rearranges the fields on the display in the following order: v If fields were selected on the Select and Sequence Fields display, they are listed in the following order: 1.
Page 119
v The states, and the customers listed for each state, should appear alphabetically. In order to obtain the order you want, your first sort field is credit limit ( ), in descending order (from highest to lowest); your second sort field is state ( );...
Notice that because you left the A/D column blank for the , and fields, Query replaces the blank with an to show that ascending order is used. The sort in this example provides a report that looks something like this: The highest credit limits ( ) are listed first, followed by the next highest.
Page 121
SBCS character data in SBCS, DBCS-open, and DBCS-either fields are sorted in the order of the hexadecimal representation of the characters or an order defined by a selected collating sequence. For more information on collating sequences, see Chapter 9, “Selecting a collating sequence in Query for iSeries”.
To collate means to place items in proper sequence or to check that items are in proper sequence. For Query for iSeries purposes, collating sequences apply to SBCS character data in SBCS, DBCS-open, or DBCS-either fields, not numeric, date, time, timestamp, DBCS-only, or DBCS-graphic fields. The collating sequences you can use are: v The collating sequence provided by Query for iSeries for the language of your country.
Selecting a Query for iSeries collating sequence To select a collating sequence, you have to understand how the data exists in your files. For example, if both uppercase and lowercase SBCS characters exist in your character fields, you have to decide if you want uppercase and lowercase characters treated the same.
Table 3. Example of How a Code Table Works (continued). The value in the left column is the first half of the hexadecimal value. The value at the top of each column is the second half of the hexadecimal value. The lowercase a in this table is at ’81’X and the uppercase A is at ’C1’X.
as in most Query for iSeries language sequences, each pair of uppercase and lowercase letters (such as and ) sort together because they share a collating weight that is distinct from the weights of other letters. The language collating sequence is not saved in the query definition. If you save your query and it is used on a system with a different language, the collating sequence for the other language is used.
The CCSID of the sequence is shown at the top and is always your job CCSID. If the collating sequence CCSID does not match your job CCSID, the previously specified or defaulted sequence is converted before it is shown on the Define Collating Sequence display. See “CCSIDs and collating sequences in Query for iSeries”...
For more information on using lists, see “Using lists in Query for iSeries” on page 9. Selecting a system sort sequence in Query for iSeries You can specify that the query use a system-provided sort sequence associated with a specific language. There are two sort sequences for each language: v One with unique weights for each character in the table.
Page 130
Job run and *JOBRUN are resolved to the sort sequence (SRTSEQ keyword) and language ID (LANGID keyword) from the user’s job when the query is run. These are the defaults for collating sequence option 5 if no sort sequence and language ID are saved in the query user profile. The language ID is not used when: v You choose Job run as the sort sequence option, and v The sort sequence of the job at run time is *HEX or a named translation table.
Each column heading appears in the report exactly as you type it. Each heading can be up to three 20-character lines, and you can use any characters you want (see the heading for the following display). If you want the headings of all your columns to line up on the lowest heading line, you must type each one on the display that way.
v 0 through 9 (single-precision) or 0 through 17 (double-precision) for floating-point fields For date, time, timestamp and DBCS fields, you cannot change the length to anything but 0, which excludes the field from the report. For numeric fields, if you increase or decrease the value in Dec, you should increase or decrease the value in Len the same amount.
Note: You cannot change the order of the fields on your report during the formatting process. If you determine that you need to change the order of the fields in your output, you must go back to the Define the Query display and choose the Select and sequence fields option (see Chapter 6, “Selecting and sequencing fields in Query for iSeries”).
Page 135
The Define Numeric Field Editing display allows you to specify the type of editing you want to use to edit a numeric field. The editing determines how the values for the field are to appear in your query report. This is the first of two displays used to define the editing;...
v The Edit option value is the value last specified in the query definition, the value associated with the field definition in the file definition (if this is a field from a file), or 1, if neither of the first two indicates its value.
Decimal point in Query for iSeries reports Type the option number of the character that you want used as the decimal point in this field. The option numbers and characters are shown below, along with examples of the edited results for a numeric value of Option Example Meaning of Option...
v If you specify option 3 (Floating currency symbol), then the negative sign moves (or floats), depending on how many leading zeros it replaces, so that it is to the immediate left of the first significant digit in the value (such as ), or it is to the immediate left of the left currency symbol (such as Right negative sign in Query for iSeries reports Type from 1 to 6 characters that you want used as the negative sign to appear on the right of negative...
The right currency symbol is always in a fixed position. Print zero value in Query for iSeries reports When this field contains a numeric value of zero, type a is to be left blank. Y=Yes A numeric value of 0, when it occurs, is to be shown. N=No A numeric value of 0 is to be shown as all blanks;...
The Describe Date/Time Field Editing display allows you to specify the type of separator character that you want used for a numeric field that contains a date or time value. The editing value determines how the values for the date or time field are to appear in your query report (if you use option 2 as the edit option for this field).
Specifying an edit code in Query for iSeries reports The Specify Edit Code display allows you to specify which edit code or user-defined edit description you want used to edit each value in a numeric field. The edit code or edit description that you choose determines how the values for the specified field are to appear in your query report (if the report is run when the edit option for the field is 3).
Page 142
Note: For all these edit codes, decimal points are always shown, and leading zeros are always suppressed. Query uses the J edit code as the default edit code whenever an error occurs during numeric field editing or whenever there are no other editing values to use. If an error occurs, an error message is shown along with the edited result produced using the J code.
Optional edit code modifier in Query for iSeries reports Type the character that you want used as the optional modifier for the specified edit code. If you specified one of the edit codes W through Z or one of the edit descriptions 5 through 9 in the Edit code prompt, you cannot specify an optional modifier in this prompt.
Page 144
For example, if you want to define an edit word containing an eleven-digit field with no decimal positions, and you want commas for thousands separators and and a value in the report would appear as You might define formatted for ten or eleven digits on the Specify Report Column Formatting display. The ten digit number The edit word might be Consider the following as you define your edit words.
v An edit word does not have to have a decimal digit position (to the right of the decimal point) for each decimal digit in the field; only the total length is significant. Query does not check the two edit words to see that they have the same number of decimal positions.
Page 148
2=Average Shows the average of the values in the field for the break level or for the whole column (numeric fields only). The average is the total divided by the count (number of values that are not null used to determine the total).
Summary functions can be specified for as many of these fields as you want, as long as that type of function is valid for that type of field. Summarizing columns in Query for iSeries reports The collating sequence that you select (see Chapter 9, “Selecting a collating sequence in Query for iSeries”) for your query has an effect on different parts of your query definition.
Page 152
An example of when you might need to define five report break levels, would be if you sequenced a group of payroll time records by employee within department, within region, within division, and within company. In this case you would assign the following break levels: v Break level 1 = company v Break level 2 = division v Break level 3 = region...
Page 153
v If no break fields are selected, no summary functions are selected and final summaries are suppressed. Only a count of the records is produced. In a name and address file, for example, you might specify that two fields named specified as break fields.
Page 154
You can exclude break fields from showing in the report in column format and still use their values in the report’s break text. That is, if you specify a 0 in the Len column of the Specify Report Column Formatting display for a field, no column of data for the field appears in the report.
Defining report break formatting in Query for iSeries reports The Format Report Break display is used to format each of the break levels (1 through 6) that you defined on the Define Report Break display. This display is shown once for each of the break levels that you defined for your query.
N=No Any summary values are not to be suppressed. They are to be included each time that a report break occurs at this break level. Y=Yes All summary values are to be suppressed. They are not to be included for this break level. Break text in Query for iSeries reports Type any text that you want to appear at each report break for this break level.
output definition information. If no field selections are made, Query produces all fields for a database file. Result fields are ordered last instead of first, as they are for printed or displayed output. Even though these characteristics may be defined in the query, they are not used unless your Output type choice specifies either displayed or printed output.
N=No The data for each output record is not to be wrapped when the length of the output record exceeds the width of the report line. Instead, any extra fields on the right end of each record are dropped. If is specified, the next two prompts are ignored.
Alignment for the wrapped fields is uneven in this example, because, although the Column Spacing value for CHAR is 2, one blank appears after the INTEGER heading and field on the first line, and one blank appears before the CHAR heading and field on the second line. The Column Spacing value for DECIMAL is also 2, but both blanks appear after CHAR on the second line and no blanks before DECIMAL on the third line.
You can also specify whether your query definition is to be printed when the report is printed. If it is, the values specified on this display apply to the printing of both the query report and the query definition. These values do not apply if you print the definition using option 6 on the Work with Queries display (which prints only the definition) or if you specify both database output and print definition (which puts the report in the file and prints the definition).
If you want to increase the left margin of the report (with the left edge being print position 1), go to the Specify Report Column Formatting display and type a larger value in the Column Spacing prompt for the first field to be shown in the report. Note: For DBCS-graphic fields, Query adds DBCS shift-out and shift-in characters before showing the fields in a displayed or printed report.
Page 163
Completing this display does not cause the query to immediately run and print a report. You must still use the Exit This Query display (see Chapter 15, “Exiting and running a Query for iSeries query”). If you have your query output spooled and if it is necessary to work with your spooled output, you can use the Work with Spooled Files display.
v If you type , the system assumes that the standard forms are already in the printer, and no message is sent to the system operator. Copies in Query for iSeries reports: Type a number from 1 through 255 to indicate the number of copies of the report that you want printed.
N=No No cover page is to be printed for your report. If you specify text on the Cover page title prompt, it is saved for future use. Cover page title of Query for iSeries reports: Type the title, or title text, to be printed on your report as a cover page.
Print standard page headings in Query for iSeries reports: Type a system’s standard headings are to be printed on each page of your report (except for the cover page). You must specify an if you do not want to print the standard headings; your use of the special date, time, and page codes does not control the printing of the standard information.
For database file output, some report characteristics (although they may be defined in this query definition) are ignored. If you later change the output type or the output form on the Select Output Type and Output Form display, these defined characteristics can be used as specified. The data from your query is saved in your database file in the order that the fields are specified in your query.
Note: This can cause an unwanted result if a date value outside the range 1940 through 2039 is put into a file field that has a two-digit year format. The value will be shown as pluses (++++++) on a report. To avoid this result, either use the CHAR function to see the data in a four-digit year format when you query the data, or change the attributes of the file field to a four-digit year format.
definition is the only way to determine some of the assigned attributes, such as the allocated length for variable length fields. Changing the format definition is the only way to specify certain attributes, such as a preferred default for null values. Specifying an output database file for Query for iSeries reports File: To specify the database file that is to store your query output, you can type a file name, use the name already shown, or press F4 (Prompt) to see a list of existing file names.
Page 170
If you specify if the file is created or replaced or has no members. is used with a request to put the output into a new member of an existing file containing members, Query for iSeries sends an error message. You need to cancel the request or replace the member named in the message.
Page 171
For all options, if the file does not exist in the specified library, Query tries to create that file. Authority in Query for iSeries reports: Type the value for the kind of object authority that you want to give to other users for your database file. (This authority value is used only if your query creates a new file.) The values that you can specify are: *LIBCRTAUT Library create authority assigns the authority from the create authority (CRTAUT) value in the library...
Summary-only output of a Query for iSeries report to a database file The data sent to a database file, when summary-only output is selected, is one of the following: v If no summary functions or report breaks have been selected, the output is a single record containing a count of the records selected by your query.
The number in parentheses, behind the explanation of the field, is the output field length and number of decimal positions. A blank break value is shown as a string of periods. Note that the overflow indicator column is blank, indicating all the data fits. Note: Truncation or rounding of averages is not considered overflow.
Rounding numeric field values during Query for iSeries processing You can control whether the result of numeric field calculations or field length changes should be rounded or truncated when your query is run. By typing a Options display, all of your numeric field calculation results are rounded (if necessary) when your query is run.
Whether you choose to have decimal data errors ignored depends on whether your data contains values that cause decimal data errors. You may want to define your query to ignore decimal data errors if the files it uses have zoned or packed numeric fields that contain data that is not normally interpreted as zoned or packed data.
Describing the Query for iSeries query definition You can also type some descriptive text about the query. The text reminds you what the query is for when it is displayed in a list of queries or printed on the cover page of a report. The text is displayed, for example, on the Work with Queries display whenever the Text column is shown.
Running a Query for iSeries query Running a query consists of telling Query for iSeries to use the query definition to acquire the data you want from selected files, to organize the data into a report format, and then to either display the report, print it, or store it in a database file.
You can run a query and get the report without saving the definition of the query only if you are running interactively. (The query must be saved to run in batch.) However: v If you are creating a query and choose not to save it, it runs only once and then is lost. To save your query, you need to supply values for the Library and Query prompts.
Query displays a report, prints a report, or puts the data into a database file, depending on what is specified on the Select Output Type and Output Form display. For more information on selecting an output device, see Chapter 13, “Selecting output type and output form in Query for iSeries reports”. Query uses current data each time a query is run.
Page 184
Following are some suggestions for using the RUNQRY command: v If you want to use an existing query without changing the file or files to query, specify only a query and library name (without an input file name). This runs the query exactly as it was defined. v If you want to run a default query on a file, specify only an input file name.
Page 186
The options currently defined for your query are shown with a > to the left of the option. You can change these and define additional options. You can choose as many options as you want from this display. Each of these options and their associated displays are described in previous chapters. Each option has its own corresponding display(s), on which you can make specific changes.
Page 187
When you finish making changes on all the displays you want to change, Query returns you to the Define the Query display, where the options now defined for your query are shown with a > to the left of the option.
Considerations for changing Query for iSeries queries To make changes to your query, choose the correct options on the Define the Query display. Refer to the appropriate chapters or appendixes in this guide for information and considerations on how to enter the definitions that you want.
Table 8. Effect of Collating Sequence and Processing Option on Selection. Either or both NAME1 and NAME2 are DBCS data. Yes means the record under test is selected. No means it is not selected. ColSeq=YES Unique Test Weights NAME1 EQ NAME2 NAME1 GE NAME2 NAME1 GT NAME2 NAME1 NE NAME2...
To place the copy in the same library as the original, do not type anything in the To library prompt. Then select a choice in the Replace query prompt: v Type a if you want the copy to replace a query that has the same name in the library. v Leave the in the prompt if you want to copy the query to the library only if no other query with the same name already exists in the library.
delete. (For more information about using lists, see “Using lists in Query for iSeries” on page 9.) Then press the Enter key. The Confirm Delete of Queries display appears. This display shows the query name(s) you chose to delete. (The above display shows some sample information.) Carefully check the names.
If you display a query and decide you want to change it, you have to return to the Work with Queries display and use option 2 (Change). You can print the information you see when you display a query, although the information will be in a different form. See “Printing a Query for iSeries query definition”. You may be able to print the definition of a query that you cannot change or display.
When you select option 6 (Print definition) on the Work with Queries display and press the Enter key, the query definition is printed immediately. Information printed for a Query for iSeries query definition The printout includes the following information: v A header at the top of each page. This header lists information about the system you are using and when the definition was printed.
Example of printed record format information for a Query for iSeries query definition The following is an example of one particular part of the query definition (the record format layout for the database output file) that can be printed when the query is run. The information shown below is printed only if the query is defined for database file output and, in this case, when it sends summary-only output to the database file.
Page 195
E means DBCS-either G means DBCS-graphic L means Date T means Time Z means Timestamp v The Null column shows whether the field is null capable (Y) or not (blank). v The Data Type column shows the data type for each field. v The Text column shows the comment (if it exists) for each field.
Joining files in Query for iSeries For joining files (type of join): v Type 1 join is the same as for Query/36 (on System/36). v Type 2 join selects all the records in a primary file and records in the secondary files that match the primary records.
In calculations involving many large fields, you can control your results better by breaking the expression into parts, calculating each part as a separate result field. Then you can use these result fields in an expression to calculate the result field you want. You can specify length and decimal positions for the intermediate result fields to minimize the length of the final result field.
Example: Increasing the decimal precision for result fields in Query for iSeries Figure 5 has a result field with a current maximum precision of 31 (length) and 2 (decimal positions). The decimal precision was derived from the calculation 31-29+9-9. Figure 5. Decimal Precision Using Default Note: The presentation length for RESULTA a would be 31,9.
Figure 6. Changing Decimal Precision Selecting records (ignoring field case) in Query for iSeries To select records ignoring the case, do one of the following: v Define your own collating sequence such that uppercase and lowercase letters have the same weight. v Use a system sort sequence with shared collating weights.
Page 208
spacing. In Query for iSeries, the report skips an extra line for report breaks unless it is defined to skip to a new page. This means the first detail line after a control break has an extra blank line printed between it and the last detail line before the break. Character fields In Query/36, character fields that were defined in IDDU with a length greater than 256 bytes were truncated at 256 bytes.
Command differences between System/36 and Query for iSeries commands The following table lists the System/36 Query commands and the equivalent OS/400 system commands (if appropriate) plus some system commands that work with queries: System/36 OS/400 System WRKQRY QRYRUN RUNQRY REMOVE DLTQRY FROMLIBR SAVOBJ...
Page 212
7. You will name the file definition first, so select option 3 (File). (The name dictionary prompt on the following display; what you see on your display is the name of the data dictionary you just created, or the name of the data dictionary you last used. You may change the data dictionary.) Then press the Enter key.
Page 213
Now press F6. You will complete the description of the and describing the remainder of the field definitions) from the next display. 11. Complete the field description with its type, size, and any other descriptors, according to the table shown below. Then name and describe the remainder of the field definitions. Field Name Field Type Character...
Page 214
Press the Enter key without making any changes to the display. 13. When you see the Create and Select Field Definitions display, verify that the field names are arranged in the proper sequence. (When sequence numbers are the same, the arrangement of the field names on the display determines the sequence of use in the record.) If a field is out of sequence, type the necessary sequence numbers to indicate the correct arrangement, and press the Enter key.
you press F3 (Exit) without making any changes to the display. You are finished creating the definitions describing a database file. The instructions to create the file and to enter data into the file are described in the following sections. Query for iSeries query exercise: Creating a database file After you have completed creating the necessary file definitions, you can create the database file using the Work with Database Files display.
Page 216
1. Choose option 3 (Work with database files) from the IDDU menu (or type line). 2. On the Work with Database Files display, specify option 2 (Enter data), your library for the library name. 3. Press the Enter key. The Work with Data in a File display is shown. 4.
Page 217
5. The Work with Data in a File display is shown again, but the fields are blank, ready for you to continue adding more data. 6. Continue adding the following data to the Work with Data in a File display: LASTNAME FIRSTNAME ADDRESS1 Daye...
You do not need to change anything on this display. Press the Enter key. 8. The Work with Database Files display is shown. A message on the bottom of the display tells you that data in your file was changed. 9.
v Amount After you create and save the query, you run it as it exists and then change the query and run it again. Query for iSeries query exercise: Creating a query In this exercise, you create a query that lists on your display all the information in the file order the information exists in the file.
Page 220
Notice that Query has already supplied a 1 for the Specify file selections option on this display. This is because whenever you create a query, you must specify a file, but you do not have to select any other options on this display. 4.
Page 221
7. Press the Enter key. The Define the Query display is shown with the message The Specify file selections option has a > shown in the Opt column to indicate that it is a previously defined option. 8. Press F3 (Exit). The Exit This Query display is shown. Query supplies a (Yes) in the Save definition prompt and a prompt because it assumes you want to both save the query definition object and run the query.
Page 222
11. Press the Enter key to save the query definition object and run the query. The report produced by the query is shown on your display: The report lists all the information in the file defined to the system using IDDU. Press F20 (Right) to see the right side of the report.
Query for iSeries query exercise: Changing a query If you want a report of only those customers who live in the state of Louisiana, you need to change the query to list customers from that state only. 1. Type a 2 (Change) for the Option prompt on the Work with Queries display. 2.
Page 224
6. Press the Enter key. The Select Records display is shown. The fields in the file single-column list format, that is the Text, Len, and Dec prompts are not shown, press F11.) You can move your cursor to any place in the list and press the Page Down key to see more field names. 7.
Page 225
This tells Query for iSeries to test the field named with that value will be included in your report. (If you are using a unique weight system sort sequence table or *HEX, make sure you type it as what the field contains and not the field name. You must also type this value in all uppercase letters because that is the way it is specified in the field.
Page 226
10. Press F3 (Exit), F12 (Cancel), or the Enter key to return to the Select Records display. Then press F3 (Exit). The Exit This Query display is shown. You can use this display to run the query with the changes you made. You can also choose to make the query changes either permanent or for this time only.
12. Press the Enter key. The Work with Queries display is shown. To sign off the system or use it for something other than Query, press F3 (Exit) to return to the menu from which you chose to use Query. Query for iSeries query exercise: Creating an advanced query In the following example, you create a file named (DSPOBJD) command.
Page 228
1. On the command line of the OS/400 Main Menu, type the DSPOBJD command as shown on the following display and press the Enter key. This creates the file named library QGPL. Note: When you type will receive an error message. You must type in the entire command exactly as it appears on the display that follows.
Page 229
4. On the Define the Query display, select definition steps Select and sequence fields, Select records, Select sort fields, Specify report column formatting, Select report summary functions, and Define report breaks by typing a 1 to the left of each of them. (Notice that Specify file selections is already selected for you.) Press the Enter key.
Page 230
The message appears. Press the Enter key again. 6. The next display to appear is the Select and Sequence Fields display. Query for iSeries Use V5R2...
Page 231
If your display is in multiple-column format (that is, if the Text, Len, and Dec columns are not shown), press F11 (Display text) to show some additional information about the fields in the list. Select the fields , and by typing the numbers 1 through 5 to the left of them as shown below.
Page 232
Press the Enter key again. 7. The next display shown is the Select Records display. Here, you specify which records you want included in your report. For your report, you want all records for objects with an object type of either *FILE or *PGM. Type the information in the Field, Test, and Value columns as shown in the following display.
Page 233
8. Now display your report by pressing F5 (Report). The Display Report display appears showing your query report, which is based on the query you have defined up to this point. (The information you see on your display depends on the objects that are currently in QGPL on your system. What you see may not match what is shown in the display that follows.) On the bottom far right side of the display, the message appears.
Page 234
On the Select Records display, press the Enter key. 9. The next display to appear is the Select Sort Fields display. Here you specify which fields you want Query to use to sort the selected records for your report. You want the records sorted first by object type and then by object size, so type a next to and a...
Page 235
Press the Enter key again. 10. The next display is the Specify Report Column Formatting display. It is here that you specify column spacing, column headings, and other report formatting options. Query supplies much of this information for you. Change the column heading for the field so that it reads instead of...
Page 236
Press the Enter key. 11. The next display you see is the Select Report Summary Functions. By specifying options on this display, you can have selected fields summarized in your report—that is, for a selected field, you can specify that a total, average, minimum, maximum, and (or) count be included in your report. Specify that you want all the summary functions (total, average, minimum, maximum, and count) for the field ODOBSZ by typing 1 through 5 next to the field as shown in the following display.
Page 237
Press the Enter key. 12. The next display to appear is the Define Report Breaks display. On this display you specify which fields you want used as break fields. Report breaks are used to break the report into groups of records each time the value of the report break field changes.
Page 238
Press the Enter key. 13. On the next display, Format Report Break, you specify the formatting you want for the report break you defined. Note that the value in the Break level prompt is zero. You can use break level 0 to print the final summary values for all specified summary functions at the end of the report.
Page 239
Press the Enter key. You are finished with all of the definition steps that you selected earlier, so the Define the Query display appears again. (The definition steps you selected earlier are now indicated with a > symbol to the left of them.) 14.
Page 240
On the bottom far right side of the display, the message report does not fit on the display. Use the page keys or F20 (Right) and F19 (Left) to page through the report (both left to right and top to bottom) so that you can see the breaks and summaries in the report.
Page 241
Press the Enter key. 16. The Work with Queries display appears, showing the message Now you can return to the OS/400 Main Menu by pressing F3 (Exit) to complete your work with this example. Appendix B. Practice exercise for Query for iSeries query...
Note: Having existing access paths is important because a temporary access path created by Query is not saved. It must be created each time that particular query is run. Select/omit access paths in Query for iSeries Use the CRTLF command to create access paths with select/omit tests specified in the DDS. Specify the select/omit tests in such a way that they match part or all of the selection tests from one or more queries.
Each time you run a saved query, Query validates the access plan by checking that the files and access paths named in the plan still exist. If it is valid, Query uses that plan to access the data. This can result in a significant performance gain, when compared with running queries without stored access plans, because Query does not have to validate the access path when running a stored query.
stored in the low-order four bits of each byte. The high-order four bits of the low-order byte contain the sign. The high-order four bits of all other bytes contain all 1s (1111). For example, the binary representation of +123 in zoned decimal format is 1111 0001 1111 0010 1111 0011. If a file contains numeric fields defined as zoned (which is common on files migrated from a System/36), the iSeries system converts the fields from zoned to packed for the arithmetic operation and then converts them back to zoned when the resulting value is returned to the program.
retrieve the text for each field. Also, showing the text for each field results in fewer fields being shown on each display so you have to page through more displays to retrieve the fields you need to view. This is also true for query, file, member, and format lists.
Note: If there is no existing access path matching some of the record selection tests, Query does not build an access path solely for purposes of selection. Query reads each record and selects those that qualify. If you request a particular query often, consider creating an access path with select/omit tests to match that query.
input or original file name. This produces a new database file containing the sorted records. The time required to produce the sorted records may vary, depending on whether Query has to build an access path to do the sort. Consider these items before performing this type of operation: v Any changes to the original file are not automatically reflected in the sorted file unless you provide for this with some type of additional maintenance.
However, if the data you want to view is at the end of the searched records, it may take longer than anticipated to display those records. This may also be true when paging down to access more data (even if the first display did appear quickly) if the additional data is located much further into the file. If Query has to build a large access path prior to retrieving data it takes longer to reach the first display.
Option 2—Matched records with primary file A record from the primary file is selected regardless of whether there is a match with any of the secondary files. The selection of primary records is dependent on the select/omit criteria specified on the Select Records display. Only primary records that meet those criteria are selected. Select/omit criteria specified against secondary files may cause a record from the primary file not to be selected.
Be careful with using the “NE” comparison between fields from different files on the Specify How to Join Files display. This could result in a large number of records being selected and a large amount of I/O being performed. Query runs more efficiently when the files are ordered from smallest to largest. In this case, smallest means the file from which the fewest records are selected for the join.
Query for iSeries performance tuning A properly tuned system provides much better overall performance than one in which performance tuning has not been used. However, there are many factors to consider when properly tuning the system to meet your needs. See the Work Management topic for details. In addition, the Performance Tools for iSeries book explains how to monitor and understand overall system performance.
display and also the total amount of time it takes the query to run. If a significant portion of the query run time is spent building an access path, attempt to use the tips and techniques previously listed on using access paths. Query running.
Page 258
Figure 7. Working with and without CCSID Conversion. Conversion, when necessary and possible, is done automatically by the system. Query for iSeries recognizes when conversion of data, collating sequences, and text is needed, and performs the conversion. The system notifies you if the conversion fails. You may not be able to work on a query or run a saved query depending on the CCSIDs involved.
CCSID marking in Query for iSeries The following bulleted objects contain CCSID tags used by query processing. Each item inherits its CCSID from the containing item unless marked with an asterisk. An asterisk indicates that the object has its own CCSID tag.
- Text about the member * - Data (the CCSID tag or tags are in the format definition) Notes: 1. The CCSID of the query definition is shown on displays that show the query name, like the Define the Query display. 2.
Note: The query profile, user-defined collating sequence default, and CCSID are only updated if you press F23 from the Define Collating Sequence display to save the sequence. Query for iSeries language sequences Following are the language sequences that are supported by Query for iSeries. Table 9.
Table 10. How CCSIDs Affect Displaying a Query Job CCSID 65535 65535 Changing a Query for iSeries query You can change the query definition if the process (job) CCSID and the query definition CCSID match, if either is marked with a CCSID of 65535 (do not convert), or if the query definition is not marked. Table 11 shows when a query can be changed and how the constants are treated.
For example, the language sequence is used to initialize the Define Collating Sequence display if there is no previously defined sequence for the query and the default sequence from the query-user’s profile is converted with warnings about the use of substitution characters. Query for iSeries warns you on the Select Collating Sequence display when the sequence previously defined for this query cannot be converted.
Table 12. How CCSIDs Affect Run-Time Record Selection Job CCSID 65535 65535 CCSIDs and Query for iSeries query definition items Query for iSeries warns you about some CCSID compatibility problems as you are working on a query definition but some problems are not diagnosed until the query is run. To understand the results, you need to know: v How CCSIDs are assigned to constants and expressions v The order in which conversions and comparisons are performed...
CCSID and result field column headings in Query for iSeries A column heading in a result field definition is converted, if necessary, to the job or document CCSID when it is passed back to the document or shown in a report. Dots (...) are shown if the conversion fails. CCSID and sort fields in Query for iSeries If the CCSID of the sort field is different from the collating sequence CCSID, the sequence is converted to the field CCSID.
CCSID compatibility considerations in Query for iSeries CCSID marking makes it possible for conversions to be performed before presentation of marked material or use of marked material in comparisons, but can also restrict the use of various combinations of marked items.
Page 267
Table 13. CCSIDs Not Compatible-Definition-Time Consequences (continued) Item 1 Item 2 Collating sequence Field Field 2/constant Field 1 Field 2/constant Field 1 1. This can happen when you specify that character substitution warnings not be ignored on the Specify Processing Options display.
Page 268
Table 14. CCSIDs Conversion Problems-Run-Time Consequences (continued) Item 1 Item 2 Collating sequence Note: For output to display, Query uses a single diagnostic message to warn you to look for unwanted dots and missing edit word text. There is no warning when you print a report. 1.
Page 269
Table 16. How CCSIDs Affect Query Use Job CCSID Query CCSID 65535 65535 65535 No tag No tag 1. Either a warning or request ending message is issued. Run Query Change Query allowed allowed Appendix E. Coded character set identifiers (CCSIDs) in Query for iSeries Run time record Display Query selection...
Printer Device Programming, SC41-5713-05, provides the application programmer and system operator with information to understand and control printing. v IBM Personal Computer Disk Operating System Reference SC21-8090, provides personal computer users with information on how to use DOS on their personal computer.
Any reference to an IBM product, program, or service is not intended to state or imply that only that IBM product, program, or service may be used. Any functionally equivalent product, program, or service that does not infringe any IBM intellectual property right may be used instead.
The licensed program described in this information and all licensed material available for it are provided by IBM under terms of the IBM Customer Agreement, IBM International Program License Agreement, or any equivalent agreement between us. If you are viewing this information softcopy, the photographs and color illustrations may not appear.
Page 276
CCSID (coded character set identifier) (continued) definition 246 displaying 17 displaying query 249 edit word 132 file selection 252 footing 253 join tests 252 language code page 256 marking 247, 254 page heading 253 query options list 256 running 256 table 256 query display table 249...
Page 277
coded character set identifier (CCSID) (continued) sort field 253 summary function 253 translation table 116 collating sequence 87, 111, 112, 249 affecting query 112, 165 CCSID (coded character set identifier) 114 collating sequence 256 default 248 hexadecimal 248 language 248 translation table 248 user-defined 248 considerations when changing for query 176...
Page 278
constant (continued) graphic migration 241 numeric record selection test 94 result field 59 control language (CL) 5 creating database files 5 Copy Queries display 177 copying query definition 173, 177 count summary function null value 136 cover page CCSID (coded character set identifier) 253 defining for printout 152 Create and Select Field Definitions display (IDDU) 200, 202...
Page 279
date, time, and timestamp field (continued) migrating N to N-1 241 date, time, and timestamp value average summary function 136 comparing to null 96 IS, ISNOT test 96 total summary function 135 date/time field editing 127 separator 128 DAY function argument rules 75 syntax diagram 75 DAYS function...
Page 281
EQ (equal) comparison test 95, 96, 165 error handling 18 ignoring in numeric field 164 Specify File Selections display 36 EUR (IBM European standard) date and time 67 example changing query definition 211 code page 114 connecting record selection test 101...
Page 282
field (continued) length and decimal position in report 120 missing from file definition during file selection process 55 starting to change or display a query 55 name numeric 59 null 8 numeric editing 122 using in result fields 59 omitting from report 121 result creating 57 DBCS 187...
Page 283
HOUR function argument rules 76 syntax diagram 76 how a collating sequence affects Query for iSeries 112 how to join files 43 IBM European standard (EUR) date and time 67 IBM USA standard (USA) date and time 67 ID (identifier)
Page 284
increasing the decimal precision 190 information for programmers, advanced 187 interactive data definition utility (IDDU) data dictionary 4 definition 199 example creating IDDU definition 199 introduction 4 main (system) menu 199 interactive processing limiting 243 restricting 243 internal numeric calculations length and decimal positions 189 International Standards Organization (ISO) date and time 67...
Page 285
list (continued) selecting items how 10 library name 10 queries 10 query name 10 selecting items from 16 library 14 subset Work with Queries display 14 LIST (list) comparison test 95, 97, 165 LOCAL time standard date and time 67 logical file definition 5 using with Query or DB2 UDB for iSeries...
Page 286
object DB2 UDB for iSeries program 5 query definition 5 omitting field from report 121 OO (double-byte O) 8 operator concatenation (||) 60 null value 60 numeric 58 optimization definition 231 OR condition specifying selection tests 236 OR connection record selection test 101 output database file defining 154...
Page 287
query definition (continued) DLTQRY command 11, 178 Query for iSeries Utilities menu 11 Work with Queries display 178 displaying 179 exiting 167 information printed 181 migrating restriction 197 naming 27 naming restrictions multilingual environment 27 printing 180 Query for iSeries menu deleting from 11 renaming 178 running 8...
Page 288
report (continued) summary function 237 specifying 135 types 135 using F13 to display layout 8 using F5 to display 8, 169 restriction migration definitions 197 result field adding 86 CCSID (coded character set identifier) 252 character 60 character constant 60, 66 column heading 85 concatenation (||) operation 60 creating 57...
Page 289
selecting (continued) items from list 10 library for file selection 34 matched records primary file 48 selected files 47 members for file selection Select Member display 39 Specify File Selections display 35 options query definition 29 output type and output form 145 queries from a list Work with Queries display 14 record for query 91...
Page 290
UCS2 level 1 support 4 unmatched records with primary file join field length restrictions 44 records in primary file without matching records 43 USA (IBM USA standard) date and time 67 user-defined collating sequence 115 using collating sequence 165 value...
Page 291
value length date 120 time 120 timestamp 120 VARCHAR function 63 VARGRAPHIC function 65 variable-length field release restrictions 241 verifying choice creating or changing query definition 36 viewing queries on display 8 word, edit numeric field 131 Work with Database Files display (IDDU) 203 Work with File Definitions display (IDDU) 202 Work with File Definitions Display (IDDU) 200 Work with Queries display...