• Aucun résultat trouvé

GENERAL FORMAT [USAGE IS]

Dans le document Language Reference (Page 112-117)

TABLE HANDLING

GENERAL FORMAT [USAGE IS]

SYNTAX RULES

1. An index data item can be referenced explicitly only in a SEARCH or SET statement, a relation condition, the USING phrase of a Procedure Division header, or the USING phrase of a CALL statement.

2. The SYNCHRONIZED, JUSTIFIED, PICTURE, VALUE and BLANK WHEN ZERO clauses cannot be used to describe group or elementary items described with the USAGE IS INDEX clause.

GENERAL RULES

1. The USAGE clause can be written at any level. If the USAGE clause is written at a group level, it applies to each elementary item in the group. The USAGE clause of an elementary item cannot contradict the USAGE clause of a group to which the item belongs.

Language Reference Manual 4-5

The SEARCH Statement

FUNCTION

The SEARCH statement is used to search a table for a table element that satisfies the specified condition and to adjust the associated index-name to indicate that table element.

GENERAL FORMAT

Format!

SEARCH identifier-l [VARYING {

~dentifier-2}]

lndex-name-l [: AT END imperative-statement-l]

WHEN condition-l [ , WIlER condiHon-2

Language Reference.Manual

{ imperative-statement-2 } NEXT SENTENCE

{ imperative-statement-3}]

NEXT SENTENCE

4-7

SYNTAX RULES

1. In both Formats 1 and 2, identifier-I must not be subscripted or indexed, but its description must contain an OCCURS clause and an INDEXED BY clause.

The description of identifier-I in Format 2 must also contain the KEY IS phrase in its OCCURS clause.

2. identifier-2, when specified, must be described as USAGE IS INDEX or as a numeric elementary item without any positions to the right of the assumed decimal point.

3. In Format 1, condition-I, condition-2, etc., may be any condition as described in Conditional Expressions in Chapter 3.

4. In Format 2, all referenced condition names must be defined as having only a single value. The data-name associated with a condition-name must appear in the KEY clause of identifier-1. Each data-name-l, data-name-2 may be qualified. Each data-name-I, data-name-2 must be indexed by the first index-name associated with identifier-l along with other indices or literal as required, and must be referenced in the KEY clause of identifier-1.

identifier-3, identifier-4, or identifiers specified in arithmetic-expression-l, arithmetic-expression-2 must not be referenced in the KEY clause of identifier-lor be indexed by the first index-name associated with identifier-I.

In Format 2, when a data-name in the KEY clause of identifier-l is referenced, or when a condition-name associated with a data-name in the KEY clause of identifier-l is referenced, all preceding data-names in the KEY clause of identifier-lor their associated condition-names must also be referenced.

GENERAL RULES

1. If Format 1 of the SEARCH is used, a serial type of search operation takes place, starting with the current index setting.

Language Reference Manual 4-9

3. If Format 2 of the SEARCH is used, a non-serial operation may take place; the initial setting of the index-name for identifier-l is ignored and its setting is varied during the search operation with the restriction that at no time is it set to a value that exceeds the value which corresponds to the last element of the table, or that is less than the value that corresponds to the last element of the table. The length of the table is discussed in the OCCURS clause. If any of the conditions specified in the WHEN clause cannot be satisfied for any setting of the index within the permitted range, control is passed to imperative-statement-l of the AT END phrase, when specified, or to the next executable sentence when this phrase is not specified; in either case the final setting of the index is not predictable. If all conditions can be satisfied, the inde~ indicates an occurrence that allows the condition to be satisfied, and control passes to imperative-statement-2.

4. After execution of imperative-statement-l, imperative-statement-2, or imperative-statement-3, that does not terminate with a GO TO statement, control passes to the next executable sentence.

5. In Format 2, the index-name that is used for the search operation is the first (or only) index-name that appears in the INDEXED BY phrase of identifier-I.

Any other index-names for identifier-l remain unchanged.

6. In Format 1, if the VARYING phrase is not used, the index-name that is used for the search operation is the first (or only) index-name that appears in the INDEXED BY phrase of identifier-I. Any other index-names for identifier-l remain unchanged.

7. In Format 1, if the VARYING name-l phrase is specified, and if index-name-l appears in the INDEXED BY phrase of identifier-l , that index-name is used for this search. If this is not the case, or if the VARYING identifier-2 phrase is specified, the first (or only) index-name given in the INDEXED BY phrase of identifier-l is used for the search. In addition, the following operations will occur:

a. If the VARYING index-name-l phrase is used, and if index-name-l appears in the INDEXED BY phrase of another table entry, the occurrence number represented by index-name-l is incremented by the same amount as, and at the same time as, the index-name associated with identifier-l is incremented.

Language Reference Manual 4 - 11

Figure 4-1 shows a flowchart of the Format 1 SEARCH operation containing two WHEN phrases.

START Index setting:

highest permissible occurrence number

> AT END 1

imperative-~---~~ statement-l

True

~ ________________________

~~imperative-statement-2

~ ____________ T_r_u_e __________ .limperative- 1

Increment index-name for

identifier-l index-name-l

if applicable

Increment index-name (for a different table) or identifier-2

statement-3

2

1 - These operations are options included only when specified in the SEARCH statement.

2 - Each of these control transfers is to the next executable sentence unless the imperative-statement ends with a GO TO statement.

Figure 4·1. Flowchart of SERCH Operation with Two WHEN Phrases.

Language Reference Manual 4 - 13

GENERAL RULES

Dans le document Language Reference (Page 112-117)