RPG/400 Help

SETGT (Set Greater Than)

*---------*---------------*-----------------*----------------*---------------*
|   CODE  |    FACTOR 1   |     FACTOR 2    |     RESULT     |  INDICATORS   |
|         |               |                 |      FIELD     |               |
*---------*---------------*-----------------*----------------*---------------*
| SETGT   | Search        | File name       |                |    NR ER _    |
|         | argument      |                 |                |               |
*---------*---------------*-----------------*----------------*---------------*

The SETGT operation positions a file at the next record with a key or relative record number that is greater than the key or relative record number specified in factor 1. The file must be a full procedural file (identified by an F in position 16 of the file description specifications).

Factor 1 is required. If the file is accessed by key, factor 1 can be a field name, a named constant, a figurative constant, or a literal that is used as the search argument in positioning a file. You can also specify a KLIST (Define a Composite Key) name in factor 1 for an externally described file that is positioned by key. If the file is accessed by relative record number, factor 1 must be an integer literal, named constant, or field.

Factor 2 is required and must be either a file name or, in the OS/400 system, a record format name. A record format name in factor 2 is allowed only with an externally described file.

You can specify a resulting indicator in positions 54 and 55 to be set on if no record is found with a key or relative record number that is greater than the search argument specified in factor 1. You can specify any valid resulting indicator in positions 56 and 57 to be set on if an error occurs during processing of the operation.

If the SETGT operation is not successful (no-record-found condition), the file is positioned to the end of the file.

Figurative constants can also be used to position the file. When used with a file with a composite key, figurative constants are treated as though each field of the key contained the figurative constant value. In most cases, *LOVAL positions the file so that the first read retrieves the record with the lowest key. In most cases, *HIVAL positions the file so that a READ receives an end-of-file indication; a subsequent READP retrieves the last record in the file. However, note the following cases for using *LOVAL and *HIVAL with numeric keys:

Following the SETGT operation, a file is positioned so that it is immediately before the first record whose key or relative record number is greater than the search argument specified in factor 1. You retrieve this record by reading the file. Before you read the file, however, records may be deleted from the file by another job or through another file in your job. Thus, you may not get the record you expected. For information on preventing unexpected modification of your files, see the discussion of allocating objects in the Programming: Control Language Reference.

Figure "SETGT Operation" illustrates the SETGT operation.

SETGT Example

Figure 52. SETGT Operation

*...1....+....2....+....3....+....4....+....5....+....6....+....7...
CL0N01N02N03Factor1+++OpcdeFactor2+++ResultLenDHHiLoEqComments++++++
C*  This example shows how to position the file so READ will read
C*  the next record. The search argument, KEY, specified for the
C*  SETGT operation has a value of 98; therefore, SETGT positions
C*  the file before the first record of file format FILEA that
C*  has a key field value greater than 98.  The file is positioned
C*  before the first record with a key value of 100.  The READ
C*  operation reads the record that has a value of 100 in its key
C*  field.
C           KEY       SETGTFILEA                      GREATER THAN
C                     READ FILEA                    64READ NEXT
C*
C*
C*  This example shows how to read the last record of a group of
C*  records with the same key value and format from a program
C*  described file.  The search argument, KEY, specified for the
C*  SETGT operation positions the file before the first record of
C*  file FILEB that has a key field value greater than 70.
C*  The file is positioned before the first record with a key
C*  value  of 80.  The READP operation reads the last record that
C*  has a value of 70 in its key field.
C           KEY       SETGTFILEB                      GREATER THAN
C                     READPFILEB                    64READ LAST
              Key Field                         Key Field
               Values                            Values
          *---------------*                  *---------------*
          |       97      |                  |      50       |
          *---------------*                  *---------------*
          |       97      |                  |      60       |
          *---------------*                  *---------------*
          |       97      |                  |      70       |
          *---------------*                  *---------------*
          |       97      |        (READP)--*|      70       |
          *---------------*FILEA   (SETGT)---*---------------*FILEB
          |       98      |                  |      80       |
(SETGT)---*---------------*                  *---------------*
(READ)---*|      100      |                  |      80       |
          |---------------*                  *---------------*
          |      100      |                  |      80       |
          *---------------*                  *---------------*
          |      100      |                  |      90       |
          *---------------*                  *---------------*
          |      101      |                  |      90       |
          *---------------*                  *---------------*
          |      101      |                  |      91       |
          *---------------*                  *---------------*
 
*...1....+....2....+....3....+....4....+....5....+....6....+....7...
CL0N01N02N03Factor1+++OpcdeFactor2+++ResultLenDHHiLoEqComments++++++
C*
C*  This example shows the use of *LOVAL.  The SETGT operation
C*  positions the file before the first record of a file in
C*  ascending order.  The READ operation reads the first record
C*  (key value 97).
C           *LOVAL    SETGTRECDA                      GREATER THAN
C                     READ RECDA                    64READ NEXT
C*
C*
C*  This example shows the use of *HIVAL.  The SETGT operation
C*  positions the file after the last record of a file in ascending
C*  order. The READP operation reads the last record (key value 91).
C           *HIVAL    SETGTRECDB                      GREATER THAN
C                     READPRECDB                    64READ LAST
               Key Field                       Key Field
                Values                          Values
(SETGT)----*---------------*               *---------------*
 (READ)----*       97      |               |      50       |
           |---------------*               *---------------*
           |       97      |               |      60       |
           *---------------*               *---------------*
           |       97      |               |      70       |
           *---------------*               *---------------*
           |       97      |               |      70       |
           *---------------*RECDA          *---------------*RECDB
           |       98      | Record        |      80       | Record
           *---------------* Format        *---------------* Format
           |      100      |               |      80       |
           *---------------*               *---------------*
           |      100      |               |      80       |
           *---------------*               *---------------*
           |      100      |               |      90       |
           *---------------*               *---------------*
           |      101      |               |      90       |
           *---------------*               *---------------*
           |      101      |    (READP)----*      91       |
           *---------------*    (SETGT)----*---------------*
 


[ Top of Page | Previous Page | Next Page | Table of Contents ]