Format 1
PROCEDURE DIVISION
[ {USING } {parameter} ... ] .
{CHAINING}
[ DECLARATIVES.
{ section-name SECTION [segment-no] .
declarative-sentence
[ paragraph-name.
[ sentence ] ... ] ... } ...
END DECLARATIVES. ]
{ section-name SECTION [segment-no] .
[ paragraph-name.
[ sentence ] ... ] ... } ...
Format 2
PROCEDURE DIVISION
[ {USING } {parameter} ... ] .
{CHAINING}
{ paragraph-name.
[ sentence ] ... ] ... } ...
Syntax Rules
- If one paragraph is in a section, all paragraphs must be in sections.
- A
section consists of a section header followed by zero or more paragraphs.
- A
paragraph consists of a paragraph header followed by zero or more sentences.
- A
sentence is one or more statements terminated by a period.
- parameter must refer to a data item defined with a level-number of 01 or 77. If the USING phrase is used, then each
parameter must be declared in the Linkage Section. If the CHAINING phrase is used, then each parameter must be declared in the File
or Working-Storage Section.
- Each
parameter may not appear more than once in a USING/CHAINING phrase.
- declarative-sentence must be a USE statement followed by a period.
- segment-no must be a number between zero and 99.
- Each
segment-no in the Declaratives must be less than 50.
- If the
segment-no is absent, it is treated as if it were zero.
- Each
section-name must be a unique user-defined word (exception: a
section-name may be the same as a data name).
General Rules
- The USING phrase is used only for programs that are invoked by a CALL statement with a USING phrase.
- The USING phrase identifies the names used in the program to refer to arguments passed from the calling program. In the calling
program, the USING phrase of the CALL statement identifies the arguments. The two USING lists correspond positionally.
- References to USING phrase parameters operate according to the data description entries in the program's Linkage Section independent
of their descriptions in the calling program.
- A Linkage Section data item can be referred to in the Procedure Division only if it satisfies one of the following conditions:
- It is named in the Procedure Division's USING phrase.
- The address of the data item is assigned to another data item or a pointer. This is accomplished through the SET ADDRESS OF
statement. See the Linkage Section in
Data Division Format and the
SET Statement for additional information.
- It is subordinate to a
parameter named in the USING phrase.
- It is a data item defined by a REDEFINES or RENAMES clause whose object is named in the USING phrase. Data items subordinate
to such items may also be referenced.
- It is a
condition-name or
index-name associated with any data item that satisfies any of the previous conditions.
- Any changes made to the data items referred to in the USING phrase are reflected in the calling program when the current program
exits.
- The CHAINING phrase is used only for a program that is the first program executed in a run unit (a "main" program). Each
parameter has its initial value set according to the following rules:
- If the program is initiated from the host operating system, each
parameter is initialized to the corresponding command-line argument
- If the program is initiated by a CHAIN statement, then each
parameter receives the value of the corresponding USING item specified by that CHAIN statement.
- Values are assigned to each
parameter as if the value were the alphanumeric source for an elementary MOVE to
parameter. If
parameter is not alphanumeric, then it is treated as if it were implicitly redefined as alphanumeric before this MOVE occurs.
- If there are fewer arguments than parameters, then the excess parameters are initialized according to the rules that would
apply if they were not listed in the CHAINING phrase.
- If there are more arguments than parameters, the excess arguments are ignored.
- Segment-numbers describe the segments of the program. If segmentation is used, then sections must be placed so that a particular
segment number is never smaller than the segment number for any previous section (in other words, all the sections belonging
to a particular segment must be placed together).
- Unless altered by the SEGMENT-LIMIT phrase of the Configuration Section, segment numbers less than 50 are placed in the program's
fixed memory space. The fixed memory space is loaded when the program first starts and remains resident until the program
is canceled.
- Segment numbers of 50 or greater reside in the swapped memory space. The swapped memory space contains only one segment at
a time. If the program's flow of control requires that a different segment be executed than the one that is currently residing
in the swapped memory space, then it is loaded from the program's object file. This reduces the amount of memory space required
by the program, at the expense of performing additional disk reads when new segments are needed. This swapped memory space
applies only to Version 7.2 and earlier. Later versions treat segmentation as commentary.
- Sections with the same
segment-no are considered to be part of the same segment. They are all loaded together when that segment is read into memory.
- The functional behavior of a program with segmentation is identical to that same program without segmentation. The only difference
is that the program requires less memory but (potentially) more time to run. It is legal for the flow of control to pass directly
or indirectly from one swapped segment to another.
- When using segmentation, take care that the program's flow of control does not cause excessive swapping. If it does, the performance
of the program may be substantially degraded.
- An individual segment may not exceed 64 KB.