Procedure Division Format

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

  1. If one paragraph is in a section, all paragraphs must be in sections.
  2. A section consists of a section header followed by zero or more paragraphs.
  3. A paragraph consists of a paragraph header followed by zero or more sentences.
  4. A sentence is one or more statements terminated by a period.
  5. 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.
  6. Each parameter may not appear more than once in a USING/CHAINING phrase.
  7. declarative-sentence must be a USE statement followed by a period.
  8. segment-no must be a number between zero and 99.
  9. Each segment-no in the Declaratives must be less than 50.
  10. If the segment-no is absent, it is treated as if it were zero.
  11. Each section-name must be a unique user-defined word (exception: a section-name may be the same as a data name).

General Rules

  1. The USING phrase is used only for programs that are invoked by a CALL statement with a USING phrase.
  2. 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.
  3. 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.
  4. A Linkage Section data item can be referred to in the Procedure Division only if it satisfies one of the following conditions:
    1. It is named in the Procedure Division's USING phrase.
    2. 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.
    3. It is subordinate to a parameter named in the USING phrase.
    4. 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.
    5. It is a condition-name or index-name associated with any data item that satisfies any of the previous conditions.
  5. Any changes made to the data items referred to in the USING phrase are reflected in the calling program when the current program exits.
  6. 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:
    1. If the program is initiated from the host operating system, each parameter is initialized to the corresponding command-line argument
    2. 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.
    3. 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.
    4. 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.
    5. If there are more arguments than parameters, the excess arguments are ignored.
  7. 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).
  8. 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.
  9. 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.
  10. 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.
  11. 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.
  12. 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.
  13. An individual segment may not exceed 64 KB.