HP 3000 Manuals

Procedure Division (cont.) [ COBOL/HP-UX Language Reference for the Series 700 and 800 ] MPE/iX 5.0 Documentation


COBOL/HP-UX Language Reference for the Series 700 and 800

Procedure Division (cont.) 

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 1 

[]
Format 2
[]
Note that the required relational character "=" is not underlined to avoid confusion with other symbols. Syntax Rules 1. In both Formats 1 and 2, identifier-1 must not be subscripted or indexed, but its description must contain an OCCURS clause and an INDEXED BY clause. The description of identifier-1 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-1, condition-2, and so on, can be any condition as described in the section Conditional Expressions earlier in this chapter. 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-1, data-name-2 can be qualified. Each data-name-1, data-name-2 must be indexed by the first index-name associated with identifier-1 along with other indices or literals as required, and must be referenced in the KEY clause of identifier-1. Identifier-3, identifier-4, or identifiers specified in arithmetic-expression-1, arithmetic-expression-2 must not be referenced in the KEY clause of identifier-1 or be indexed by the first index-name associated with identifier-1. In Format 2, when a data-name in the KEY clause of identifier-1 is referenced, or when a condition-name associated with a data-name in the KEY clause of identifier-1 is referenced, all preceding data-names in the KEY clause of identifier-1 or their associated condition-names must also be referenced. ________________________________________________________________________ |(OSVS) (VSC2) (MF) | | | | | | | |5. In Format 1, identifier-1, the table element being searched, can | | be an internal or external floating-point item. | | | |6. In Format 2, identifier-1, the table element being searched, can | | not be a floating-point item. | | | |7. In Format 2, neither data-name-1 nor data-name-2, the key data | | items, can be floating point items. However, identifier-3, | | identifier-4, literal-1, or literal-2, the items against which | | the key is compared, can be floating-point items. | | | ________________________________________________________________________ ________________________________________________________________________ |(ANS85) | | | | | | | |8. If the END-SEARCH phrase is specified, the NEXT SENTENCE phrase | | must not be specified. | | | ________________________________________________________________________ ________________________________________________________________________ |(VSC2) (MF) | |END-SEARCH can be specified with NEXT SENTENCE. If the NEXT SENTENCE | |phrase is executed, control will not pass to the next statement | |following the END-SEARCH, but instead will pass to the statement after| |the closest following period. | ________________________________________________________________________ ________________________________________________________________________ |(MF) | | | | | | | |9. Both imperative-statement-1 and imperative-statement-2 can be | | replaced by a conditional statement. | | | ________________________________________________________________________ General Rules 1. The scope of a SEARCH statement can be terminated by any of the following: ________________________________________________________________________ |(ANS85) | | | | | | | |a. An END-SEARCH phrase at the same level of nesting. | | | ________________________________________________________________________ b. A separator period. c. An ELSE or END-IF (ANS85) associated with a previous IF statement. 2. If Format 1 of the SEARCH is used, a serial type of search operation takes place, starting with the current index setting. a. If, at the start of execution of the SEARCH statement, the index-name associated with identifier-1 contains a value that corresponds to an occurrence number that is greater than the highest permissible occurrence number for identifier-1, the SEARCH is terminated immediately. The number of occurrences of identifier-1, the last of which is the highest permissible, is discussed in the OCCURS clause. (See the section "The OCCURS Clause" earlier in this chapter.) Then, if the AT END phrase is specified, imperative- statement-1 is executed; if the AT END phrase is not specified, control passes to the next executable sentence. b. If, at the start of execution of the SEARCH statement, the index-name associated with identifier-1 contains a value that corresponds to an occurrence number that is not greater than the highest permissible occurrence number for identifier-1 (the number of occurrences of identifier-1, the last of which is the highest permissible is discussed in the OCCURS clause), the SEARCH statement operates by evaluating the conditions in the order that they are written, making use of the index settings, wherever specified, to determine the occurrence of those items to be tested. If none of the conditions is satisfied, the index name for identifier-1 is incremented to obtain reference to the next occurrence. The process is then repeated using the new index-name settings unless the new value of the index-name settings for identifier-1 corresponds to a table element outside the permissible range of occurrence values, in which case the search terminates as indicated in General Rule 1a above. If one of the conditions is satisfied upon its evaluation, the search terminates immediately and the imperative statement associated with that condition is executed; the index-name remains set at the occurrence which caused the condition to be satisfied. 3. In a Format 2 SEARCH, the results of the SEARCH ALL operation are predictable only when: a. The data in the table is ordered in the same manner as described in the ASCENDING/DESCENDING KEY clause associated with the description of identifier-1, and: b. The contents of the key(s) referenced in the WHEN clause are sufficient to identify a unique table element. 4. If Format 2 of the SEARCH is used, a non-serial type of search operation can take place; the initial setting of the index-name for identifier-1 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 first 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-1 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 index indicates an occurrence that allows the conditions to be satisfied, and control passes to imperative-statement-2. 5. After execution of imperative-statement-1, imperative- statement-2, or imperative-statement-3 that does not terminate with a GO TO statement, control passes to the next executable sentence. 6. 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-1. Any other index-names for identifier-1 remain unchanged. 7. 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-1. Any other index-names for identifier-1 remain unchanged. 8. In Format 1, if the VARYING index-name-1 phrase is specified, and if index-name-1 appears in the INDEXED BY phrase of identifier-1, 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-1 is used for the search. In addition, the following operations will occur: a. If the VARYING index-name-1 phrase is used, and if index-name-1 appears in the INDEXED BY phrase of another table entry, the occurrence number represented by index-name-1 is incremented by the same amount as, and at the same time as, the index-name associated with identifier-1 is incremented. b. If the VARYING identifier-2 phrase is specified, and identifier-2 is an index data item, then the data item referenced by identifier-2 is incremented by the same amount as, and at the same time as, the index associated with identifier-1 is incremented. If identifier-2 is not an index data item, the data item referenced by identifier-2 is incremented by the value (1) at the same time as the index referenced by the index-name associated with identifier-1 is incremented. 9. If identifier-1 is a data item subordinate to a data item that contains an OCCURS clause (providing for a two or three dimensional table), an index-name must be associated with each dimension of the table through the INDEXED BY phrase of the OCCURS clause. Only the setting of the index-name associated with identifier-1 (and the data item identifier-2 or index-name-1, if present) is modified by the execution of the SEARCH statement. To search an entire two or three dimensional table it is necessary to execute a SEARCH statement several times. Prior to each execution of a SEARCH statement, SET statements must be executed whenever index-names must be adjusted to appropriate settings. ________________________________________________________________________ |(VSC2) | | | | | | | |10. In Format 2, neither imperative-statement-2 nor NEXT SENTENCE is | | required. Without them, the SEARCH statement sets the index to | | the value in the table that matched the condition. | | | ________________________________________________________________________ Figure 3-5 shows a flowchart of the Format 1 SEARCH operation containing two WHEN phrases.
[]
Figure 3-5. Flowchart of SEARCH Operation Containing Two WHEN Phrases 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. ________________________________________________________________________ |(OSVS) (VSC2) | | | |The SERVICE Statement | | | |Function | | | |The SERVICE statement is used to establish addressability to Linkage | |Section items usually in a CICS program. | ________________________________________________________________________ General Format
[]
________________________________________________________________________ |(OSVS) (VSC2) | | | |Syntax Rules | | | | | | 1. SERVICE LABEL is generated by the mainframe CICS preprocessor | | to indicate control flow. It is not intended for general | | use. | | | | 2. The SERVICE LABEL statement can appear only in the Procedure | | Division, not in the Declaratives Section. | | | | 3. Identifier should either be the first 01-level item in Linkage | | Section or a pointer (BLL-cell reference) used in the SET | | option of an EXEC CICS statement. | | | |General Rules | | | | | | 1. At the statement following the SERVICE LABEL statement, all | | registers that can no longer be valid are reloaded. | | | | 2. If the OS/VS COBOL BLL mechanism is used in a CICS program, | | addressability to the parameter list must be established at the| | start of the Procedure Division. This is done by adding a | | SERVICE RELOAD identifier statement at the start of the | | Procedure Division where the identifier is the first item in | | Linkage Section and it includes pointers to all other entries | | in the Linkage Section. | | | | 3. If a locate-mode EXEC CICS statement is included in a program | | compiled with the OSVS directive, then a SERVICE RELOAD | | statement must follow each such CICS command and the identifier| | must be the same pointer (BLL-cell reference) used in the CICS | | command. | | | | 4. In a CICS program compiled with the OSVS directive, any time a | | reference is made to a Linkage Section which is greater than | | 4096 bytes long, a SERVICE RELOAD statement should be made to | | re-establish addressability to that portion of the data item | | greater than 4096 byte. | | | | 5. The SERVICE RELOAD statement is documentary only in a program | | compiled with the VSC2 directive. | ________________________________________________________________________ The SET Statement Function ________________________________________________________________________ |(ANS85) | | | | | | | |1. The SET statement is used to alter the status of external | | switches. | | | |2. The SET statement is used to alter the value of conditional | | variables. | | | ________________________________________________________________________ ________________________________________________________________________ |(MF) (VSC2) | | | | | | | |3. The SET statement is used to assign the address of a data item to| | a pointer variable. | | | ________________________________________________________________________ ________________________________________________________________________ |(MF) | | | | | | | |4. The SET statement is used to adjust the contents of a pointer | | variable. | | | ________________________________________________________________________ 5. The SET statement establishes reference points for table handling operations by setting indices associated with table elements. ________________________________________________________________________ |[REV BEG](MF) | | | | | | | |6. The SET statement is used to assign the address of an entry-point| | to a procedure-pointer-data-item. | | | ________________________________________________________________________ [REV END] General Formats
[]
[]
[]
Format 5
[]
Format 6
[]
[]
Syntax Rules ________________________________________________________________________ |(ANS85) | | | | | | | |1. Mnemonic-name-1 must be associated with an external switch, the | | status of which can be altered. | | | |2. Condition-name-1 must be associated with a conditional | | variable. | | | ________________________________________________________________________ ________________________________________________________________________ |(MF) (VSC2) | | | | | | | |3. Identifier-1 must refer to an 01 or 77 level item in the Linkage | | Section. | | | | Identifier-3 must name an item in the Linkage Section of any | | level except 66 or 88. ADDRESS OF identifier-3 contains the | | address of the identifier, and not the content of the identifier.| | Identifier-2 and identifier-4 must refer to an item with USAGE IS| | POINTER. | | [REV BEG] | | | | Identifier-3 can name any data item in the Data Division of any | | level except 66 or 88. (MF)[REV END] | | | ________________________________________________________________________ ________________________________________________________________________ |(MF) | | | | | | | |4. Identifier-5 must have USAGE POINTER. | | | |5. Identifier-6 must be an elementary numeric item described as an | | integer. | | | ________________________________________________________________________ 6. All references to index-name-1, identifier-8, and index-name-3 apply equally to all recursions thereof. [REV BEG] 7. Identifier-8 and identifier-9 must name either index data items or elementary items described as an integer. At least one of identifier-8 and identifier-9 must be an index data item.[REV END] 8. Identifier-10 must be described as an elementary numeric integer. 9. Integer-2 and integer-3 can be signed. Integer-1 must be positive. [REV BEG] ________________________________________________________________________ |(MF) | | | | | | | |10. Procedure-pointer-data-item-1 must refer to an item defined with | | USAGE IS PROCEDURE-POINTER. | | | |11. Identifier and literal must be alphanumeric and must reference an| | entry-point. | | | ________________________________________________________________________ Format 2 ________________________________________________________________________ |(ANS85) | | | | | | | |12. Condition-name-1 and condition-name-2 must be associated with a | | conditional variable. | | | |13. If the FALSE phrase is specified, the FALSE phrase must be | | specified in the VALUE clause of the Data Description entry for | | condition-name-2. | | | |14. Each FALSE or TRUE phrase applies to the occurrences of | | condition-name-2 that precede that phrase and follow a previous | | FALSE or TRUE phrase, if any. | | | ________________________________________________________________________ ________________________________________________________________________ |(MF) (VSC2) | | | |Format 3 | | | | | | | |15. Literal-1 can contain the characters @ . # , . | | | ________________________________________________________________________ [REV END] General Rules ________________________________________________________________________ |(ANS85) | | | |Format 1 | | | | | | | |1. The status of each external switch associated with the | | specified mnemonic-name-1 is modified such that the truth value | | resulting from evaluation of a condition-name associated with | | that switch will reflect an on status if the ON phrase is | | specified, or an off status if the OFF phrase is specified. | | (See the section Switch-Status Condition earlier in this | | chapter.) | | | | | |Format 2 | | | | | | | |2. The literal in the VALUE clause associated with condition-name-1 | | or condition-name-2 is placed in the conditional variable | | according to the rules of the VALUE clause (see the section "The | | VALUE Clause" earlier in this chapter.) If more than one | | literal is specified in the VALUE clause, the conditional | | variable is set to the value of the first literal that appears in| | the VALUE clause. | | | |3. If multiple condition-names are specified, the results are the | | same as if a separate SET statement had been written for each | | condition-name-1 or condition-name-2 in the same order as | | specified in the SET statement. | | [REV BEG] | | | | | |4. If the FALSE phrase is specified, the literal in the FALSE phrase| | of the VALUE clause associated with condition-name-2 is placed in| | the conditional variable according to the rules for the VALUE | | clause. (See the section "The VALUE Clause" earlier in this | | chapter.)[REV END] | | | ________________________________________________________________________ ________________________________________________________________________ |(MF) (VSC2) | | | |Format 3 | | | | | | | |5. If identifier-2 is specified, the address given by the TO phrase | | is moved into identifier-2. This link will be valid until | | the program terminates or returns control to its calling | | program. If identifier-1 is specified, identifier-1 is | | relinked so that any subsequent reference to it references | | the item whose address is given by the TO phrase. The | | address given by the TO phrase is the address contained in | | identifier-4, or the address of identifier-3, or, if NULL is | | specified, a null address guaranteed to point to no data item. | | See the section "The USAGE Clause" earlier in this | | chapter. | | | | Whether or not the link is retained between invocations of a | | subprogram is dependent on the STICKY-LINKAGE directive. See your| | COBOL System Reference for details. (MF) | | | ________________________________________________________________________ ________________________________________________________________________ |(MF) | | | |Format 4 | | | | | | | |6. This statement changes the pointer variable identifier-1 to point| | to a memory location +/-n locations from where it pointed before | | the statement, where n is the value of integer-1 or of | | the item identifier-6, or the length in bytes of the item | | identifier-7. | | | |7. Although syntactically correct, this feature should not be used | | to change which record is pointed to by a pointer. The positions| | of records in memory are not defined in the COBOL language and | | can vary between implementations. | | | ________________________________________________________________________ Format 5 and 6 8. Index-names are considered related to a given table and are defined by being specified by the INDEXED BY clause. 9. If index-name-2 is specified, the value of the index before the execution of the SET statement must correspond to an occurrence number of an element in the associated table. If index-name-3 is specified, the value of the index both before and after the execution of the SET statement must correspond to an occurrence number of an element in the associated table. If index-name-1 is specified, the value of the index after the execution of the SET statement must correspond to an occurrence number of an element in the associated table. The value of the index associated with an index-name after the execution of a SEARCH or PERFORM statement can be undefined. (See the sections "The SEARCH Statement" and "The PERFORM Statement" earlier in this chapter.) Format 5 10. a. Index-name-1 is set to a value causing it to refer to the table element that corresponds in occurrence number to the table element referenced by index-name-2, identifier-9, or integer-2. If identifier-9 is an index data item, or if index-name-2 is related to the same table as index-name-1, no conversion takes place. b. If identifier-8 is an index data item, it can be set equal to either the contents of index-name-2 or identifier-9 where identifier-9 is also an index item; no conversion takes place in either case. c. If identifier-8 is not an index data item, it can be set only to an occurrence number that corresponds to the value of index-name-2. Neither identifier-9 nor integer-2 can be used in this case. d. The process is repeated for all recurrence of index-name-1 and, identifier-8, if specified. Each time the value of index-name-2 or identifier-9 is used as it was at the beginning of the execution of the statement. Any subscripting or indexing associated with identifier-8, and so on is evaluated immediately before the value of the respective data item is changed. Format 6 11. The contents of index-name-3 are incremented (UP BY) or decremented (DOWN BY) by a value that corresponds to the number of occurrences represented by the value of integer-3 or identifier-10; thereafter, the process is repeated for each recurrence of index-name-3. Each time the value of identifier-10 is used as it was at the beginning of the execution of the statement. 12. Data in Table 3-11 represents the validity of various operand combinations in the SET statement. The General Rule reference indicates the applicable general rule. ________________________________________________________________________ |(MF) | | | |Format 7 | | | | | | | |13. Procedure-pointer-data-item-1 is assigned the value of: | | | | | | | | - the contents of procedure-pointer-data-item-2 | | | | - the address of the entry point or program-id specified | | in | | identifier-1 or literal-2 | | | | - NULL | | | | | | Procedure-pointer-data-item-2 remains unchanged. Note that | | following the SET operation the action of CALL procedure-pointer-| | data-item-1 is identical to that of CALL identifier or | | literal. | | | |14. Literal and identifier do not need to be contained within this | | program. | | | ________________________________________________________________________ Example 01 startpoint usage is procedure-pointer. . . procedure division. . . set startpoint to ENTRY "Joe" . . entry "Joe". Table 3-11. SET Index Statement Valid Operand Combinations --------------------------------------------------------------------------------- | | | | Sending Item | Receiving Item1 | | | | --------------------------------------------------------------------------------- | | | | | | | Integer Data Item | Index-Name | Index Data Item | | | | | | --------------------------------------------------------------------------------- | | | | | | Integer Literal | No/10c | Valid/10a | No/10b | | | | | | --------------------------------------------------------------------------------- | | | | | | Integer Data Item | No/10c | Valid/10a | No/10b | | | | | | --------------------------------------------------------------------------------- | | | | | | Index-Name | Valid/10c | Valid/10a | Valid/10b2 | | | | | | --------------------------------------------------------------------------------- | | | | | | Index Data Item | No/10c | Valid/10a2 | Valid/10b2 | | | | | | --------------------------------------------------------------------------------- 1 = Rule numbers under General Rules above are referred to. 2 = No conversion takes place.


MPE/iX 5.0 Documentation