LOOK

Contents


"look" is used to check the existence of a recording corresponding to a given key value.

Syntax

   Look [ class ] [ key ] read_mode [ key_value ]

Parameters

Element

Description

Restrictions

  Key :

Description of the key of a file under one of the following forms:

  • variable_name
  • variable_name '(' exp_ind ')'

The key must be defined in an Order By clause or as the table parameters.

exp_ind

Expression entière du nombre de parties de clés utilisées. Par défaut, toute la clé est utilisée.

0 <=exp_ind <=number of key components (at most 8).

read_mode

One of the following key-words or one of the following operators:

keyword

operator

Read mode used

First
Last
Curr
Prev
Next






>=
>
=
<
<=

First recording
Last recording
Current recording
Previous recording
Next recording
Key >=
key_value
Key> 
key_value
Key= 
key_value
Key < 
key_value
Key <= 
key_value

key_value

List of expressions separated by ';' corresponding to the values of the sub-keys.

value comptatible with the sub-key type

Examples

# Sequence of reads in a [TEST] file whose keys are
# - a CLE1 key (an alphanumerical element);
# - a CLE2 key (a date element, an alphanumerical element, a # Integer
element).

# See if there are 10 recordings in the file in the order of
# the CLE2 key after the recording with the CLE1 key being lower than
# the given value.
Look [TEST]CLE2 < date$; "XYZ"; 15*3
I = 0
While fstat <> 0 & fstat <> 2 & I < 10
    Look [TEST]CLE2 Next
    I += 1
Wend
# If fstat is not nul, there was a non-existing recording
# On the other hand, under Oracle, a For loop will be used
# (with loss of the current class [F])
I = 0
For [TEST]CLE2 Where CLE2 < date$; "XYZ" ; 15*3
    I += 1
    If I = 10 : Break: Endif
Next

# Does the recording with the CLE1 key being >= "ABCD" exist?
Look [TEST]CLE1 >= "ABCD"
If [S]fstat <= 2
Read Curr
Endif

# Is the [TEST] file empty?
Look First
If fstat
    Errbox "The file is empty!"
Endif

Description and comments

"Look" is used to check the existence of a specific recording in a table based on the various modes listed in the grid above. If no key value is specified for the modes that require one ( '<', '>', '<=', '>=', '=' ), the current value of the variables of the corresponding class [F] is used.

The keys that can be used in "Look" are necessarily those defined when parameterizing the grid or those defined in the Order by clause of the File or Filter command.

It is not possible to use "Look" with the link abbreviation.

The abbreviation of the grid or the key name can be left out of the syntax of Look:

- in the first case, the grid used is the default grid;
- in the second case, the key used is the current key, i.e.:

the read of a recording, with the precision of a key part, positions the [G]currlen variable; This variable contains the number of key parts used. It is positioned by default to the value 0.

"Look" updates the fstat variable in order to mention how the read went.

fstat

Code

Read

Explanation

0

Yes

The read was successful.

2

ERECIND

Yes

In read mode, <= or >= means that the read duly took place but the key found is < or > to the searched value.

4

ERDEBF

No

In Next or Prev mode, it means that the start or the end of the file has been reached.

5

ERPALEC

No

In >, >=, =, <= or < modes, this means that there is no recording corresponding to the values passed as parameters.

The variables of class [F] are not modified by "Look" unlike "Read". On the other hand, [S]fstat are updated and the recording looked for becomes the current recording of the file (the Curr mode can be used).

"Look" does not make it possible to know if the recording is locked or not. For that purpose it is necessary to use the Readlock instruction.

Whenever there are several recordings to be checked, the "For" instruction will be used rather than the "Look" instruction.
"Look" poses the same optimization problems as "Read". Please refer to the documentation on this instruction.

New to version 140

When performing a direct Look using a key with a homonym, the Sql query is generated with a systematic sort on the rowid. This is a good solution as long as other recordings need to be subseqsuently read via the Look next, otherwise it is not very efficient in case of a single read. The sort on the rowid will not be generated in the query if the total number of key parts is specified. For instance:

   # ACCES table with the key with homonym CODACC ( USR, CODACC ) 
   # sort on USR, CODACC and rowid

   Local File ACCES[ABR]
   Look [ABC] CODACC First
   Look [ABC] CODACC="XY","ZZZ"

   # sort on USR, CODACC 
   Local File ACCES[ABR]
   Look [ABC] CODACC(2) First
   Look [ABC] CODACC(2)="XY","ZZZ"

Associated errors

Error

Description

MODIN (22)

Read mode incorrect.

ERINDI ( 8)

The number of given values or the index mentioned, exceeds the number of elements of the key.

PACLE (21)

The key does not exist for this file.

ERCLAS (7)

The file class does not exist (file not open).

Associated keywords

FILE - READ - FOR - READLOCK - FILTER - ORDER - WHERE - FSTAT   -  CURRIND  -   CURRLEN


CONTENTS

Copyright © Sage 1999 - 2007