General Formats (Cont.) [ Micro Focus COBOL Language Reference ] MPE/iX 5.0 Documentation
Micro Focus COBOL Language Reference
General Formats (Cont.)
The EXIT Statement
Function.
The EXIT statement provides a common end point for a series of
procedures.
For MF only: The EXIT statement can also exit an inline PERFORM, a
paragraph or a section.
The EXIT PROGRAM statement marks the logical end of a called program.
For MF only: You can also return values to calling programs written in
any language.
General Formats.
Format 1.
Format 2 (MF).
Format 3 (MF).
Format 4.
Syntax Rules.
Format 1.
1. The EXIT statement should appear in a sentence by itself.
For MF and VSC2 only: This rule is not enforced.
2. The EXIT sentence should be the only sentence in the paragraph.
For MF and VSC2 only: This rule is not .enforced.
For MF only: Format 2.
3. A Format 2 EXIT statement can be used only within an inline
PERFORM.
Format 4.
4. If an EXIT PROGRAM statement appears in a consecutive sequence of
imperative statements within a sentence, it must not appear as
the last statement in that sequence.
For MF and VSC2 only: This rule is not enforced .
5. There must be no sentence other than the EXIT PROGRAM sentence in
the paragraph.
For MF, ANS85 and VSC2 only: This rule is not enforced .
6. For MF only: Integer-1 may be signed.
7. For MF only: GIVING and RETURNING are equivalent.
8. For MF only: If the ADDRESS OF clause is not specified,
identifier-1 must be no larger than 8 bytes in size.
General Rules.
Format 1.
1. An EXIT statement serves only to enable the user to assign a
procedure-name to a given point in a program. Such an EXIT
statement has no other effect on the compilation or execution of
the program.
For MF only: Format 2.
2. The execution of an EXIT PERFORM statement without a CYCLE phrase
causes control to be passed to an implicit CONTINUE statement,
immediately following the END-PERFORM associated with the nearest
inline PERFORM statement.
3. The execution of an EXIT PERFORM statement with a CYCLE phrase
causes control to be passed to an implicit CONTINUE statement,
immediately preceding the END-PERFORM associated with the nearest
inline PERFORM statement.
For MF only: Format 3.
4. The execution of a Format 3 EXIT statement with the PARAGRAPH
phrase causes control to pass to an implicit CONTINUE statement
immediately preceding:
a. The next paragraph or section header, whichever comes
first.
b. The end of the source program if no paragraph or section
header appears between this EXIT statement and the end of
the source program.
5. The execution of a Format 3 EXIT statement with the SECTION
phrase causes control to pass to an implicit CONTINUE statement
immediately preceding:
a. The next section header.
b. Or immediately before the end of the source program if no
section header appears between this EXIT statement and the
end of the source program.
For ANS85 only: Format 4.
6. If the EXIT PROGRAM statement is executed in a program which is
not under the control of a calling program, the EXIT PROGRAM
statement causes execution of the program to continue with the
next executable statement.
7. The execution of an EXIT PROGRAM statement in a called program
which does not possess the initial attribute causes execution to
continue with the next executable statement following the CALL
statement in the calling program. The program state of the
calling program is not altered and is identical to that which
existed at the time it executed the CALL statement except that
the contents of data items and the contents of data files shared
between the calling and called program may have been changed.
The program state of the called program is not altered except
that the ends of the ranges of all PERFORM statements executed by
that called program are considered to have been reached.
8. Besides the actions specified in General Rule 7, the execution of
an EXIT PROGRAM statement in a called program which possesses the
initial attribute is equivalent to also executing a CANCEL
statement referencing that program except that the statement will
not free any memory. See the section The CANCEL Statement
earlier in this chapter.
9. An EXIT PROGRAM statement must not be executed while executing a
declarative procedure in which the GLOBAL phrase is specified
except in a program called while executing that declarative
procedure.
10. For MF only: Execution of an EXIT PROGRAM statement in a
program that is under the control of a calling program, causes a
return value to be set in the system area generally available for
non-COBOL programs to return a value. This system area is never
smaller than 4 bytes in size but may be larger in some
environments (see your COBOL System Reference for details)
If the GIVING phrase is not specified and the calling convention
specifies updating the RETURN-CODE special-register (see the CALL
CONVENTION clause in the earlier section The Special-Names
Paragraph) then the object program operates as if the system area
were declared as a COBOL numeric data item with USAGE COMP-5 and
with a size determined by the operating environment external to
the COBOL system (see your COBOL System Reference) and as if a
MOVE statement had been executed with the RETURN-CODE as the
sending item and the system area as the receiving item. (See the
section Special Registers in the chapter Concepts of the COBOL
Language for details of RETURN-CODE.)
If the GIVING ADDRESS OF phrase is specified, the object program
operates as if the system area were declared as a COBOL data item
with USAGE POINTER and as if a SET statement had been executed
with TO ADDRESS OF identifier-1 as the first operand and the
system area as the second operand. The ADDRESS OF phrase may be
used to indirectly pass a value that is larger than the system
area.
If the GIVING identifier-1 phrase is specified, identifier-1 must
describe the same number of character positions as is required to
hold the return value in the system area and must be of the type
and usage that is expected by the calling program. The object
program operates as if a MOVE statement had been executed with
identifier-1 as the sending item and the system area as the
receiving item.
If the GIVING integer-1 phrase is specified, integer-1 must not
be larger than the value that can be held in the system area.
The object program operates as if the system area were declared
as a COBOL numeric data item with USAGE COMP-5 and with a size
determined by the operating environment external to the COBOL
system (see your COBOL System Reference) and as if a MOVE
statement had been executed with integer-1 as the sending item
and the system area as the receiving item.
For OSVS, VSC2 and MF only: The GOBACK Statement
Function.
The GOBACK statement marks the logical end of a called program.
For MF only: You can also return values to calling programs written in
any language or to the operating system environment .
General Format.
Syntax Rules.
1. If a GOBACK statement appears in a consecutive sequence of
imperative statements within a sentence, it must appear as the
last statement in that sequence.
This rule is not enforced, although any statements in the sentence
that follow the GOBACK statement will not be executed.
2. For MF only: GIVING and RETURNING are equivalent.
3. For MF only: If thte ADDRESS OF clause is not specified,
identifier-1 must be no larger than 8 bytes in size.
4. Integer-1 may be signed.
General Rules.
1. If a GOBACK statement is executed in a program which is under the
control of a calling program, the object program operates as if
executing an EXIT PROGRAM statement that has the same clauses as
the GOBABCK statement. See the section The EXIT Statement.
2. If a GOBACK statement without the ADDRESS OF clause is executed in
a program which is not under the control of a calling program, the
object program operates as if executing a STOP RUN statement that
has the same clauses as the GOBACK statement.
3. If a GOBACK statement with the ADDRESS OF clause is executed in a
program which is not under the control of a calling program, the
object program operates as if executing a STOP RUN statement
except that an arbitrary returned value is set in the system area.
The GOBACK statement may result in more compact code than the
equivalent EXIT PROGRAM and STOP RUN statement.
4. A GOBACK statement must not be executed while executing a
declarative procedure in which the GLOBAL phrase is specified
except in a program called while executing that declarative
procedure.
The GO TO Statement
Function.
The GO TO statement causes control to be transferred from one part of the
Procedure Division to another.
For ANS85 only: The option of omitting procedure-name-1 in a Format 1 GO
TO statement is classed as an obsolete element in the ANSI'85 standard
and is scheduled to be deleted from the next full revision of the ANSI
Standard .
For MF only: All dialects in this COBOL implementation fully support
this syntax. Refer to your COBOL System Reference for details on using
the FLAGSTD directive to detect all occurrences of this syntax.
For XOPEN only: Although it is a part of the standard COBOL definition,
omitting the procedure-name in Format 1 is explicitly excluded from the
X/Open COBOL language definitions and should not be used in an X/Open
COBOL conforming source program.
General Formats.
Format 1.
Format 2.
Syntax Rules.
All Formats.
1. Identifier is the name of a numeric elementary item which is an
integer.
2. When a paragraph is referenced by an ALTER statement, that
paragraph can consist only of a paragraph header followed by a
Format 1 GO TO statement.
Format 1.
3. A Format 1 GO TO statement, without procedure-name-1, can only
appear in a single statement paragraph.
For MF only: This restriction is not enforced.
4. If a GO TO statement represented by Format 1 appears in a
consecutive sequence of imperative statements within a sentence,
it must appear as the last statement in that sequence.
Format 2.
5. In Format 2, at least two procedure-names should be specified.
For ANS85 only: A Format 2 statement can be written with only
one procedure name.
General Rules.
All Formats.
1. If procedure-name-1 is not specified in Format 1, an ALTER
statement, referring to this GO TO statement, must be executed
prior to the execution of this GO TO statement.
For MF and VSC2 only: If an ALTER statement referring to the
paragraph containing this GO TO statement has not been executed
before this GO TO statement is executed, this GO TO statement is
treated like a CONTINUE .
Format 1.
2. When a GO TO statement represented by Format 1 is executed,
control is transferred to procedure-name-1 or to another
procedure-name if the GO TO statement has been modified by an
ALTER statement.
Format 2.
3. When a GO TO statement represented by Format 2 is executed,
control is transferred to procedure-name-1, procedure-name-2, and
so on, depending on the value of the identifier being 1, 2,...,
n. If the value of the identifier is anything other than the
positive or unsigned integers 1, 2,..., n, then no transfer
occurs and control passes to the next statement in the normal
sequence for execution.
The IF Statement
Function.
The IF statement causes a condition to be evaluated (see the section
Conditional Expressions earlier in this chapter). The subsequent action
of the object program depends on whether the value of the condition is
true or false.
General Format.
Syntax Rules.
1. Statement-1 and statement-2 represent either an imperative
statement or a conditional statement optionally preceded by an
imperative statement.
2. If the END-IF phrase is specified, the NEXT SENTENCE phrase must
not be specified (ANS85).
NEXT SENTENCE can be specified with END-IF (VSC2)(MF).
If the NEXT SENTENCE phrase is executed, control will not pass to
the next statement following the END-IF, but instead will pass to
the statement after the closest following period.
General Rules.
1. The scope of an IF statement can be terminated by any of the
following:
a. For ANS85 only: An END-IF phrase at the same level of
nesting.
b. A separator period.
c. If nested, by an ELSE phrase associated with an IF
statement at a higher level of nesting.
2. When an IF statement is executed, the following transfers of
control occur:
a. If the condition is true, statement-1 is executed if
specified. If statement-1 contains a procedure branching
or conditional statement, control is explicitly transferred
in accordance with the rules of that statement. If
statement-1 does not contain a procedure branching or
conditional statement, the ELSE phrase, if specified, is
ignored and control passes to the end of the IF statement.
b. If the condition is true and the NEXT SENTENCE phrase is
specified instead of statement-1, the ELSE phrase, if
specified, is ignored and control passes to the next
executable sentence.
c. If the condition is false, statement-1 or its surrogate
NEXT SENTENCE is ignored, and statement-2, if specified, is
executed. If statement-2 contains a procedure branching or
conditional statement, control is explicitly transferred in
accordance with the rules of that statement. If
statement-2 does not contain a procedure branching or
conditional statement, control passes to the end of the IF
statement. If the ELSE statement-2 phrase is not
specified, statement-1 is ignored and control passes to the
end of the IF statement.
d. If the condition is false, and the ELSE NEXT SENTENCE
phrase is specified, statement-1 is ignored, if specified,
and control passes to the next executable sentence.
3. Statement-1 and/or statement-2 can contain an IF statement. In
this case the IF statement is said to be nested.
For ANS85 only: IF statements within IF statements are considered
matched IF, ELSE, and END-IF ordered combinations, proceeding from
left to right. Thus, any ELSE encountered is matched with the
nearest preceding IF that has not been already matched with an
ELSE or has not been implicitly or explicitly terminated. Any
END-IF encountered is matched with the nearest preceding IF that
has not been implicitly or explicitly terminated.
For ANS85 only: The INITIALIZE Statement
Function.
The INITIALIZE statement provides the ability to set selected types of
data fields to predetermined values; for example, numeric data to zeros
or alphanumeric data to spaces.
General Format.
Syntax Rules.
1. Literal-1 and the data item referenced by identifier-2 represent
the sending area; the data item referenced by identifier-1
represents the receiving area.
2. Each category stated in the REPLACING phrase must be a permissible
category as a receiving operand in a MOVE statement where the
corresponding data item referenced by identifier-2 or literal-1 is
used as the sending operand. (See the section The MOVE Statement
later in this chapter.)
3. The same category cannot be repeated in a REPLACING phrase.
4. The description of the data item referenced by identifier-1 or any
items subordinate to identifier-1 can not contain the DEPENDING
phrase of the OCCURS clause.
For VSC2 only: The data item referenced by identifier-1 can not
be variably located, that is, can not follow in the same record
description an item containing the DEPENDING phrase of the OCCURS
clause unless identifier-1 is subordinate to that item with the
OCCURS clause.
For MF only: The data item referenced by identifier-1 can be
variably located.
5. An index data item can not appear as an operand of an INITIALIZE
statement.
6. The data description entry for the data item referenced by
identifier-1 must not contain a RENAMES clause.
7. For VSC2 and MF only: A floating-point data item or literal can
be used anywhere a numeric identifier or literal is specified.
8. For MF only: NATIONAL and NATIONAL-EDITED fields can only be
initialized with national character values.
General Rules.
1. The key word following the word REPLACING corresponds to a
category of data as defined elsewhere in this document. (See the
section Concepts Of Classes Of Data in the chapter Concepts of the
COBOL Language.)
2. Whether identifier-1 references an elementary item or a group
item, all operations are performed as if a series of MOVE
statements had been written, each of which has an elementary item
as its receiving field, subject to the following rules:
If the REPLACING phrase is specified:
a. If identifier-1 references a group item, any elementary
item in the data item referenced by identifier-1 is
initialized only if it belongs to the category specified in
the REPLACING phrase.
b. If identifier-1 references an elementary item, that item is
initialized only if it belongs to the category specified in
the REPLACING phrase.
This initialization takes place as follows: the data item
referenced by identifier-2 or literal-1 acts as the sending
operand in an implicit MOVE statement to the identified item.
All such elementary receiving fields, including all occurrences of
table items in the group, are affected; the only exceptions are
those fields specified in General Rules 3 and 4.
3. Index and pointer (MF and VSC2 only) data items and elementary
FILLER data items are not affected by the execution of an
INITIALIZE statement
4. Any item that is subordinate to a receiving area identifier and
which contains the REDEFINES clause or any item that is
subordinate to such an item is excluded from this operation.
However, a receiving area identifier can itself have a REDEFINES
clause or be subordinate to a data item with a REDEFINES clause.
5. When the statement is written without the REPLACING phrase, data
items of the categories alphabetic, alphanumeric, and alphanumeric
edited are set to spaces; data items of the categories numeric ,
external floating-point (MF and VSC2 only) and numeric edited are
set to zeros ; data items of the categories national and
national-edited are set to national-edited spaces (MF only). In
this case, the operation is as if each affected data item is the
receiving area in an elementary MOVE statement with the indicated
source literal (that is, spaces or zeros).
6. In all cases, the content of the data item referenced by
identifier-1 is set to the indicated value in the order (left to
right) of the appearance of identifier-1 in the INITIALIZE
statement. Within this sequence, where identifier-1 references a
group item, affected elementary items are initialized in the
sequence of their definition in the group.
7. If identifier-1 occupies the same storage area as identifier-2,
the result of the execution of this statement is undefined, even
if they are defined by the same data description entry. (See the
section Overlapping Operands earlier in this chapter).
8. For MF only: NATIONAL and NATIONAL-EDITED fields can be
initialized with national character values.
MPE/iX 5.0 Documentation