General Formats (Cont.) [ Micro Focus COBOL Language Reference ] MPE/iX 5.0 Documentation
Micro Focus COBOL Language Reference
General Formats (Cont.)
The RELEASE Statement
Function.
The RELEASE statement transfers records to the initial phase of a SORT
operation.
General Format.
Syntax Rules.
1. A RELEASE statement can only be used within the range of an input
procedure associated with a SORT statement for a file whose
sort-merge file description entry contains record-name. (See the
section The SORT Statement in this chapter.)
2. Record-name must be the name of a logical record in the associated
sort-merge file description entry and can be qualified.
3. For ANS85 only: If identifier is a function-identifier, it must
reference an alpha- numeric function. When identifier is not a
function-identifier,
record-name and identifier must not reference the same storage
area.
4. For MF, OSVS and VSC2 only: Record-name can be defined as a
floating-point item.
5. For MF, OSVS and VSC2 only: Identifier can be a floating-point
item.
General Rules.
1. The execution of a RELEASE statement causes the record named by
record-name to be released to the initial phase of a sort
operation.
2. If the FROM phrase is used, the contents of the identifier data
area are moved to record-name, then the contents of record-name
are released to the sort file. Moving records takes place
according to the rules specified for the MOVE statement without
the CORRESPONDING phrase. The information in the record area is
no longer available, but the information in the data area
associated with identifier is available.
3. After the execution of the RELEASE statement, the logical record
is no longer available in the record area unless the associated
sort-merge file is named in a SAME RECORD AREA clause. The
logical record is also available to the program as a record of
other files referenced in the same SAME RECORD AREA clause as the
associated sort-merge file, as well as to the file associated with
record-name. When control passes from the input procedure, the
file consists of all those records which were placed in it by the
execution of RELEASE statements.
The RETURN Statement
Function.
The RETURN statement obtains either sorted records from the final phase
of a SORT operation or merged records during a MERGE operation.
General Format.
Syntax Rules.
1. File-name must be described by a sort-merge file description entry
in the Data Division.
2. A RETURN statement can only be used within the range of an output
procedure associated with a SORT or MERGE statement for file-name.
3. The INTO phrase must not be used when the input file contains
logical records of various sizes as indicated by their record
descriptions. The storage area associated with identifier and the
record area associated with file-name must not be the same storage
area.
4. For MF, OSVS and VSC2 only: Identifier-1 can be a
floating-point item.
General Rules.
1. When the logical records of a file are described with more than
one record description, these records automatically share the same
storage area; this is equivalent to an implicit redefinition of
the area. The contents of any data items which lie beyond the
range of the current data record are undefined at the completion
of the execution of the RETURN statement.
2. The execution of the RETURN statement causes the next existing
record in the file referenced by file-name, as determined by the
keys listed in the SORT or MERGE statement, to be made available
in the record area associated with file-name. If no next logical
record exists in the file referenced by file-name, the
at end condition exists and control is transferred to
imperative-statement-1 of the AT END phrase. Execution continues
according to the rules for each statement specified in
imperative-statement-1. If a procedure branching or conditional
statement which causes explicit transfer of control is executed,
control is transferred according to the rules for that
statement. Otherwise, upon completion of the execution of
imperative-statement-1, control is transferred to the end of the
RETURN statement and the NOT AT END phrase if specified is
ignored (ANS85 only).
When the at end condition occurs, execution of the RETURN
statement is unsuccessful and the contents of the record area
associated with file-name are undefined. After the execution of
imperative-statement-1 in the AT END phrase, no RETURN statement
can be executed as part of the current output procedure.
3. For ANS85 only: If an at end condition does not occur during the
execution of a RETURN statement, then after the record is made
available and after executing any implicit move resulting from the
presence of an INTO phrase, control is transferred to
imperative-statement-2, if specified. Otherwise, control is
transferred to the end of the RETURN statement.
4. For ANS85 only: The END-RETURN phrase delimits the scope of the
RETURN statement.
5. The INTO phrase can be specified in a RETURN statement:
a. If only one record description is subordinate to the
sort-merge file description entry, or:
b. If all record-names associated with file-name and the data
item referenced by identifier describe a group item or an
elementary alphanumeric-item.
6. The result of the execution of a RETURN statement with the INTO
phrase is equivalent to the application of the following rules in
the order specified:
a. The execution of the same RETURN statement without the INTO
phrase.
b. The current record is moved from the record area to the
area specified by identifier according to the rules for the
MOVE statement without the CORRESPONDING phrase. The size
of the current record is determined by rules specified for
the RECORD clause. If the file description entry contains
a RECORD IS VARYING clause, the implied move is a group
move. The implied MOVE statement was unsuccessful. Any
subscripting associated with identifier-1 is evaluated
after the record has been read and immediately before it is
moved to the data item. The record is available in both
the record area and the data item referenced by
identifier-1.
The REWRITE Statement
Function.
The REWRITE statement logically replaces a record existing in a disk
file.
General Formats.
Format 1 (Line Sequential Files) (MF).
Format 2 (Record Sequential Files).
Format 3 (Relative and Indexed Files).
Directives and Run-time Switches.
1. In addition to flagging and reserved words directives, the
following directives may impact either the syntax or semantics
described in this section. See your COBOL System Reference for
details.
* WRITE-LOCK - acquires a record lock for a REWRITE statement
when multiple recording locking is used.
2. The following run-time switches may impact the semantics described
in this section. See your COBOL System Reference for details.
* N - controls the insertion of null characters before
control characters when writing line sequential records.
* T - controls the insertion of tab characters when writing
line sequential records.
Syntax Rules.
All Formats (All Files).
1. For ANS85 only: If identifier is a function-identifier, it must
reference an alpha-numeric function. When identifier is not a
function-identifier,
record-name and identifier must not reference the same storage
area.
2. Record-name is the name of a logical record in the File Section of
the Data Division and can be qualified.
3. For OSVS, VSC2 and MF only: Record-name can define a floating
point or DBCS item.
4. For OSVS, VSC2 and MF only: Identifier can be a USAGE DISPLAY-1
(DBCS) item or a floating- point item.
Format 3 (Relative And Indexed Files).
5. The INVALID KEY phrase must not be specified for a REWRITE
statement which references a file in sequential access mode.
For OSVS, VSC2 only: However, it can be specified for an indexed
file in sequential access mode.
6. The INVALID KEY phrase must be specified in the REWRITE statement
for files in the random or dynamic access mode for which an
appropriate USE procedure is not specified.
General Rules.
All Formats (All Files).
1. The file associated with record-name must be a disk file and must
be open in the I/O mode at the time of execution of this
statement. (See the section The OPEN Statement earlier in this
chapter.)
2. For files in the sequential access mode the last input-output
statement executed for the associated file prior to the execution
of the REWRITE statement must have been a successfully executed
READ statement. The operating system logically replaces the
record that was accessed by the READ statement.
3. The execution of a REWRITE statement with the FROM phrase is
equivalent to the execution of:
MOVE identifier TO record-name
followed by the execution of the same REWRITE statement without
the FROM phrase. The contents of the record area prior to the
execution of the implicit MOVE statement have no effect on the
execution of the REWRITE statement.
4. The file position indicator is not affected by the execution of a
REWRITE statement.
5. The execution of the REWRITE statement causes the value of the
FILE STATUS data item, if any, associated with the file to be
updated. (See the section I/O Status earlier in this chapter.)
6. For ANS85 only: The END-REWRITE phrase delimits the scope of the
REWRITE statement.
7. For MF only: A REWRITE will not be successful if any other run
unit holds a lock on the record to be rewritten.
Formats 1 and 2 (Sequential Files).
8. The number of character positions in the record referenced by
record-name must be equal to the number of character positions in
the record being replaced.
9. The logical record released by a successful execution of the
REWRITE statement is no longer available in the record area
unless the associated file is named in a SAME RECORD AREA clause.
In this case, the record is still available to the program in the
record area, not only as a record of this file, but also as a
record of other files named in the SAME RECORD AREA clause.
For MF only: Format 1 (Line Sequential Files).
10. The REWRITE statement can be used and is considered successful
whenever the record being written (after compacting by removing
trailing spaces, tab compression and null insertion) is less than
or equal to the length of the original compacted record. When a
record is read, nulls and tab characters in the record can be
expanded and this makes the record longer.
Format 3 (Relative And Indexed Files).
11. The logical record released by a successful execution of the
REWRITE statement is no longer available in the record area
unless the associated file is saved in a SAME RECORD AREA clause,
in which case the logical record is available both to the program
as a record of other files appearing in the same SAME RECORD AREA
clause as the associated I/O file, as well as to the file
associated with record-name.
Format 3 (Relative Files).
12. For a file accessed in either random or dynamic access mode, the
operating system logically replaces the record specified by the
contents of the RELATIVE KEY data item associated with the file.
If the file does not contain the record specified by the key, the
INVALID KEY condition exists. (See the section The INVALID KEY
Condition in this chapter.) The updating operation does not take
place and the data in the record area is unaffected.
Format 3 (Indexed Files).
13. For a file in sequential access mode, the record to be replaced
is specified by the value contained in the prime record key.
When the REWRITE statement is executed, the value contained in
the prime record data item of the record to be replaced must be
equal to the value of the prime record key of the last record
read from this file.
14. For a file in random or dynamic access mode, the record to be
replaced is specified by the prime record key data item.
15. The contents of alternate record key data items of the record
being rewritten can differ from those in the record being
replaced. The operating system uses the contents of the record
key data items during execution of the REWRITE statement so that
the record can subsequently be accessed via any of those
specified record keys.
16. The INVALID KEY condition exists when:
a. Access mode is sequential and the value contained in the
prime record key data item of the record to be replaced is
not equal to the value of the prime record key of the last
record read from this file, or:
b. The value contained in the prime record key data item does
not equal that of any record stored in the file, or:
c. The value contained in an alternate record key data item
for which a DUPLICATES clause has not been specified is
equal to that of a record already stored in the file.
The updating operation will not take place and the data in the
record area will be unaffected. (See the section The INVALID KEY
Condition in this chapter.)
The ROLLBACK Statement
Function.
The ROLLBACK statement releases all record locks in all files held by
this run unit. For COBOL systems that support the WITH...ROLLBACK clause
of the SELECT statement as other than documentary, the ROLLBACK statement
indicates the end of the current transaction and the effects of that
transaction are cancelled.
General Format.
General Rules.
1. Execution of the ROLLBACK statement causes all record locks in all
files held by the run-unit to be released.
2. The file lock on an exclusive file is not affected by the ROLLBACK
statement.
3. If your COBOL system supports the WITH ROLLBACK clause of the
SELECT statement as other than documentary, then the ROLLBACK
verb:
a. Indicates completion of the current transaction
b. Ensures all changes applied during the transaction are
cancelled.
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.
All Formats (All Files).
1. 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. For ANS85 only: If the END-SEARCH phrase is specified, the NEXT
SENTENCE phrase must not be specified.
For VSC2 and MF only: 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.
4. For MF only: Both imperative-statement-1 and
imperative-statement-2 can be replaced by a conditional statement.
Format 1.
5. Condition-1, condition-2, and so on, can be any condition as
described in the section Conditional Expressions earlier in this
chapter.
6. For OSVS, VSC2 and MF only: Identifier-1, the table element
being searched, can be an internal or external floating-point
item.
Format 2.
7. 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.
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.
8. For OSVS, VSC2 and MF only: Identifier-1, the table element
being searched, can not be a floating-point item.
9. For OSVS, VSC2 and MF only: 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.
General Rules.
All Formats.
1. The scope of a SEARCH statement can be terminated by any of the
following:
a. For ANS85 only: An END-SEARCH phrase at the same level of
nesting.
b. A separator period.
c. An ELSE or END-IF (ANS85 only) associated with a previous
IF statement.
2. After execution of imperative-statement-1, or imperative-
statement-2 that does not terminate with a GO TO statement,
control passes to the next executable sentence.
3. 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.
Format 1.
4. 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.
5. 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.
6. 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.
Format 2.
7. 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.
8. 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.
9. 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.
10. For OSVS, VSC2 and MF only: 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 4-5 shows a flowchart of the Format 1 SEARCH operation containing
two WHEN phrases.
Figure 4-5: Flowchart of SEARCH Operation Showing 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.
MPE/iX 5.0 Documentation