Compaq COBOL
Reference Manual


Previous Contents Index

6.7 Segmentation

Compaq COBOL programs execute in a virtual memory environment. Therefore, programs need not manage physical memory by overlaying Procedure Division code. Compaq COBOL provides support for segmentation only for compatibility with existing applications developed on older hardware such as the PDP-11. You should not use segmentation in newly written COBOL programs since segmentation results in the generation of extra code which might impact performance.

Segmentation controls the assignment of Procedure Division sections to fixed or independent segments. The optional segment-number in the section header determines the type of segment.


section-name

names a Procedure Division section.

segment-number

must be an integer in the range 0 to 99. If there is no segment-number in a section header, the implied segment-number is 0.

segment-number classifies a segment into fixed segments or independent segments. Sections with segment-numbers from 0 to 49 are in fixed segments. Those with segment-numbers from 50 to 99 are in independent segments.

Sections in the Declaratives part of the Procedure Division must have segment-numbers less than 50.

A segment consists of all sections that have the same segment-number.

Both fixed and independent segments are in their initial state the first time entered. A fixed segment appears to reside in memory at all times and is, therefore, in its last used state each time it is entered.

The state of an independent segment depends on how and when it receives control. On subsequent control transfers, Compaq COBOL resets the segment's ALTERed GO TO statements to their initial states whenever an independent segment is entered in one of the following ways:

  1. Explicitly, by means of a GO TO statement with a target within the section.
  2. Explicitly, by means of an out-of-line PERFORM statement in another segment whose range is within the section.
  3. Implicitly, when a SORT or MERGE statement in another segment specifies an input or output procedure within the section.
  4. Implicitly, by transfer of control between consecutive statements from a segment with a different segment-number.

6.8 General Formats and Rules for Statements

Function

The Procedure Division contains the routines that process the files and data described in the Environment and Data Divisions.


Syntax Rules

  1. The Procedure Division follows the Data Division.
  2. The Procedure Division must begin with the Procedure Division header.
  3. The end of the Procedure Division is indicated by one of the following:
  4. A procedure consists of either:
  5. If one paragraph is in a section, all paragraphs must be in sections.
  6. A procedure-name refers to a paragraph or section in the source program. It is either paragraph-name (which can be qualified) or section-name.
  7. A section consists of a section header followed by zero or more successive paragraphs. A section ends immediately before the next section or at the end of the Procedure Division. In the declaratives part of the Procedure Division, a section can also end at the key words END DECLARATIVES. See Section 2.3 for more information on declaratives.
  8. A paragraph consists of a paragraph-name followed by a separator period, and by zero or more successive sentences. A paragraph ends immediately before the next paragraph-name or section-name or at the end of the Procedure Division. In the declaratives part of the Procedure Division, a paragraph can also end at the key words END DECLARATIVE. See Section 2.3 for more information on declaratives.
  9. sentence contains one or more statements terminated by a separator period.
  10. A statement is a syntactically valid combination of words and symbols that begins with a COBOL verb.
  11. identifier is the word or words necessary to refer uniquely to a data item.

Procedure Division Header

  1. The Procedure Division header identifies and begins the Procedure Division. It consists of the reserved words PROCEDURE DIVISION and optional USING and GIVING phrases followed by a separator period.
  2. The USING phrase is required only if the program is invoked by a CALL statement with a USING phrase.
  3. The Procedure Division header USING phrase identifies the names used in the program to refer to arguments from the calling program. In the calling program, the USING phrase of the CALL statement identifies the arguments. The data items in the two USING phrase lists correspond positionally.
  4. Each data-name in the USING phrase must be defined in the Linkage Section with a level-01 or level-77 entry.
  5. Each data-name cannot appear more than once in the USING phrase.
  6. In the USING phrase, data-name cannot have the external attribute.
  7. In the USING phrase, the data description for data-name cannot contain a REDEFINES clause. However, the data description can be the object of a REDEFINES clause.
  8. The Procedure Division header GIVING phrase specifies a function result of the program. The identifier must refer to an elementary integer numeric data item with COMP, COMP-1, or COMP-2 usage and no scaling positions. The identifier cannot be subscripted, but it can be qualified.

Procedure Division Body

  1. The Procedure Division body consists of all Procedure Division text following the Procedure Division header.

General Rules

  1. References to USING phrase data-names operate according to data descriptions in the called program's Linkage Section, regardless of the descriptions in the calling program.
  2. The called program can refer, in its Procedure Division, to a Linkage Section data item only if the data item satisfies one of these conditions:
  3. On Alpha systems, when a called program returns control to the calling program, the return value is made available to the calling program in the data item specified in its CALL statement GIVING phrase. The value is moved to that data item according to the rules for the MOVE statement. If the calling program does not specify a GIVING phrase, then the return value is made available in the calling program's RETURN-CODE special register. Note that the value in the called program's RETURN-CODE is not returned to the caller.
  4. On Alpha systems, if no GIVING phrase is specified in the called program, the value in the RETURN-CODE special register is made available to the calling program in the data item specified in the calling program's CALL statement GIVING phrase. The value is moved according to the rules for the MOVE statement. If the calling program does not specify a CALL GIVING phrase, the value in the called program's RETURN-CODE special register is made available to the calling program in the calling program's RETURN-CODE special register.
    Table 6-7 shows the relationship between the GIVING phrase and RETURN-CODE.

Table 6-7 Relation of GIVING Phrase to RETURN-CODE Special Register (Alpha)
Calling program has CALL GIVING X Called program has PROCEDURE DIVISION GIVING Y Called program puts result in Calling program gets result in
YES YES Y (also RETURN-CODE) X (moved from Y)
YES NO RETURN-CODE X (moved from called program's RETURN-CODE)
NO YES Y (also RETURN-CODE) RETURN-CODE (moved from Y)
NO NO RETURN-CODE RETURN-CODE (moved from called program's RETURN-CODE)

Technical Notes

  1. On Alpha systems, because the reserved word RETURN-CODE is one of the X/Open reserved words, you cannot use the compilation flag -rsv noxopen (for Tru64 UNIX systems) or the corresponding qualifier /RESERVED_WORDS = NOXOPEN (for OpenVMS systems) if your program uses the RETURN-CODE special register.
  2. On Alpha systems, Compaq COBOL supports passing status to the operating system for RETURN-CODE and PROCEDURE DIVISION GIVING when EXIT PROGRAM or STOP RUN is executed. <>
    Four of the data types supported by PROCEDURE DIVISION GIVING can be used to communicate status to the operating system. Following is a summary of what is supported for both RETURN CODE and PROCEDURE DIVISION GIVING:


            RETURN-CODE (Alpha-only*) 
             EXIT PROGRAM /STA=V3    yes 
             EXIT PROGRAM /STA=85    yes 
             STOP RUN                yes 
            PROCEDURE DIVISION GIVING 
             EXIT PROGRAM /STA=V3    yes 
             EXIT PROGRAM /STA=85    yes 
             STOP RUN                yes* 
             Data Types 
              COMP-1,COMP-2          no 
              PIC  9(04) COMP        no 
              PIC S9(04) COMP        no 
              PIC  9(09) COMP        yes 
              PIC S9(09) COMP        yes 
              PIC  9(18) COMP        yes 
              PIC S9(18) COMP        yes 
              PIC  9(31) COMP        no 
              PIC S9(31) COMP        no 
     
    *Refer to the appendix on compatibility in the Compaq COBOL User 
    Manual for differences on VAX. 
    

    This support is subject to the limitations on status handling imposed by the operating system. If PIC S9(18) COMP or PIC 9(18) COMP is used, the high-order 32 bits are truncated before the status is passed on to the operating system.
    To display the operating system status information, do the following:


    [UNIX]               echo $status 
    [OpenVMS]            show symbol $status 
    

Additional References

Example

The following is an example of a Procedure Division header:


WORKING-STORAGE SECTION. 
01      RETURN-RESULT PIC 9(8) COMP. 
LINKAGE SECTION. 
01      ARG1. 
        03 ARG2       PIC X(6). 
        03 ARG3       PIC S9(6) COMP. 
01      ARG4          PIC X(4). 
PROCEDURE DIVISION USING ARG1 ARG4 GIVING RETURN-RESULT. 
        . 
        . 
        . 
        MOVE 17 TO RETURN-RESULT. 
        EXIT PROGRAM. 

6.8.1 ACCEPT

Function

The ACCEPT statement makes low-volume data available to the program. The Compaq extensions to the ACCEPT statement (Formats 3, 4, and 5) are COBOL language additions that facilitate video forms design and data handling. The WITH CONVERSION phrase and some other options in Format 1 are also Compaq extensions.

Format 6 retrieves the number of arguments on the program run command line, Format 7 reads those command line arguments into designated program variables, and Format 8 reads environment variables and logicals into designated program variables.



dest-item

is the identifier of a data item into which data is accepted.

input-source

is a mnemonic-name defined in the SPECIAL-NAMES paragraph of the Environment Division.

stment

is an imperative statement executed when the relevant condition (at end or on exception) occurs.

stment2

is an imperative statement executed when the relevant condition (not at end or not on exception) occurs.

stment3

is an imperative statement executed when an attempt is made to read beyond the last argument on the command line, or if the command line argument does not exist.

stment4

is an imperative statement executed if the name of a referenced environment variable or logical has not been set, or if the referenced environment variable or logical does not exist.

stment5

is an imperative statement executed if the exception condition does not exist.

line-num

is a numeric literal that specifies a line position on the terminal screen. line-num must be a positive integer; it cannot be zero.

line-id

is the identifier of a data item that provides a line position on the terminal screen. It must be a positive integer; it cannot be zero.

plus-num

is a numeric literal that increments the current value for line or column position, or that increments the value of line-id or column-id. plus-num can be zero or a positive integer.

column-num

is a numeric literal that specifies a column position on the terminal screen. column-num must be a positive integer; it cannot be zero.

column-id

is the identifier of a data item that provides a column position on the terminal screen. It must be a positive integer; it cannot be zero.

prot-size-lit

is a numeric literal that specifies the maximum length of the video screen field into which data can be typed. prot-size-lit must be a positive integer; it cannot be zero.

prot-size-item

is the identifier of a numeric integer data item that specifies the maximum length of the video screen field into which data can be typed. prot-size-item must be a positive integer; it cannot be zero.

prot-fill-lit

is a single character alphanumeric literal that is used to initialize each character position of a protected video screen field into which data can be typed.

def-src-lit

is a nonnumeric literal or a figurative constant. However, it cannot be the figurative constant ALL literal.

def-src-item

is the identifier of an alphanumeric data item.

key-dest-item

is the identifier of a data item that defines a control key. key-dest-item must specify an alphanumeric data item at least four characters in length.

screen-name

is the name of a screen item defined in the SCREEN SECTION of the program.

arg-count

is a mnemonic name associated with ARGUMENT-NUMBER in the SPECIAL-NAMES paragraph in the Environment Division. It represents the number of arguments present on the run command line.

arg-value

is a mnemonic name associated with ARGUMENT-VALUE in the SPECIAL-NAMES paragraph in the Environment Division. It contains the value of the argument on the run command line specivied by the current argument position indicator.

envlog-value

is a mnemonic name associated with ENVIRONMENT-VALUE in the SPECIAL-NAMES paragraph in the Environment Division. It contains the value of a selected environment variable or system logical.

Syntax Rules

Format 3

  1. You cannot specify a phrase more than once for any dest-item.
  2. When you use the DEFAULT phrase and the PROTECTED phrase without the SIZE option, the size of def-src-item or def-src-lit must be less than or equal to the size of dest-item.
  3. When you use the DEFAULT phrase and the PROTECTED phrase with the SIZE option, the size of def-src-item and def-src-lit must be less than or equal to prot-size-lit. If prot-size-item is specified and the specified size at run time is less than the length of def-src-item or def-src-lit, reprompting occurs.
  4. The FILLER phrase cannot be used with the EDITING phrase. If both are present, the FILLER phrase is ignored.

Format 4

  1. You cannot specify a phrase more than once for any key-dest-item.

Format 6 (Alpha)

  1. dest-item must reference a data item described as an unsigned integer.

Formats 7 and 8 (Alpha)

  1. dest-item must reference an alphanumeric data item. <>

General Rules

Format 1

  1. The ACCEPT statement transfers data from input-source. The transferred data replaces the contents of dest-item.
  2. The ACCEPT statement transfers a stream of characters with no editing or conversion, unless the WITH CONVERSION phrase is specified. Data transfer begins with the leftmost character position of dest-item and continues to the right.
  3. If the data does not completely fill dest-item, remaining character positions are filled with spaces. If the data is too long for dest-item, it is truncated on the right.
  4. The ACCEPT statement treats dest-item as alphanumeric, regardless of its class, unless the WITH CONVERSION phrase is specified.
  5. If there is no FROM phrase, the ACCEPT statement transfers data from the default system input device.

Format 2

  1. The ACCEPT statement transfers data to dest-item according to the MOVE statement rules.
  2. DATE, DAY, DAY-OF-WEEK, and TIME are not actual data items. Therefore, the source program must not describe them.
  3. DATE has three elements. From left to right, they are as follows:
    The ACCEPT statement operates as if DATE were described in the program as an eight-digit or six-digit, unsigned, elementary, numeric integer data item (PIC 9(8) or PIC 9(6)).
    For example, June 3, 1997 is expressed as 19970603 or 970603.5
  4. DAY has two elements. From left to right, they are as follows:
    The ACCEPT statement operates as if DAY were described in the program as a seven-digit or five-digit, unsigned, elementary, numeric integer data item (PIC 9(7) or (PIC 9(5)).
    For example, the fifteenth day of 1998 is expressed as 1998015 or 98015.+
    The YYYYMMDD and YYYYDDD options are Compaq extensions.
  5. DAY-OF-WEEK is a one-digit item that represents the day of the week.
    The ACCEPT statement operates as if DAY-OF-WEEK were described in the program as a one-digit, unsigned, elementary numeric integer data item.
    The values of DAY-OF-WEEK range from 1 (for Monday) to 7 (for Sunday).
  6. TIME represents elapsed time after midnight, as shown on a 24-hour clock. It has four, two-digit elements. From left to right, they are as follows:
    The ACCEPT statement operates as if TIME were described in the program as an eight-digit, unsigned elementary numeric integer data item (PIC 9(8)).
    The time 6:13 PM is expressed as 18130000. The minimum and maximum values of TIME are 00000000 and 23595999.

Formats 3 and 4

  1. The ACCEPT statement transfers data from a video terminal. The data replaces the contents of dest-item (Format 3), or key-dest-item (Format 4). Format 3 can also update key-dest-item.
  2. The presence of either the LINE NUMBER phrase or the COLUMN NUMBER phrase implies NO ADVANCING. The cursor remains on the character position immediately following the position of the last input character or in the position immediately following the rightmost position in the protected area. (For example, ACCEPT... PROTECTED SIZE 10 LINE 1 COLUMN 1, leaves the cursor at line 1, column 11, no matter what is typed in.) This is the default starting position of the next data item the program will input from or display upon the terminal.
  3. If you do not use either the LINE NUMBER phrase or the COLUMN NUMBER phrase, data is accepted according to positioning rules for the Format 1 ACCEPT statement.

Formats 3, 4, and 5

  1. The execution of certain extended ACCEPTs when the input source is assigned to a file (for example, in batch mode on OpenVMS systems), is a restriction. Syntax and actions that result in outputs from the ACCEPT operation (positioning, erasing, setting character attributes, reprompting, and protecting) to a nonvideo terminal are not supported and are ignored.

LINE NUMBER Phrase (Formats 3 and 4)

  1. The LINE NUMBER phrase positions the cursor on a specific line of the video screen for data input.
  2. If the LINE NUMBER phrase does not appear, but the COLUMN NUMBER phrase does, then data is accepted from the current line position and specified column position.
  3. If line-num or the value of line-id is greater than the bottommost line position of the current screen, program results are undefined. (See Technical Notes.) Scrolling results if relative positioning is attempted past the bottom of the screen.
  4. If you use line-id without its PLUS option, the line position is the value of line-id.
  5. If you use line-id with its PLUS option, the line position is the sum of plus-num and the value of line-id.
  6. If you use the PLUS option without line-id, the line position is the sum of plus-num and the value of the current line position.
  7. If you use the PLUS option, but you do not specify plus-num, then PLUS 1 is implied.
  8. Data input results are undefined if your program generates a value for line-id that is one of the following:

COLUMN NUMBER Phrase (Formats 3 and 4)

  1. The COLUMN NUMBER phrase positions the cursor on a specific column of the video screen.
  2. If the COLUMN NUMBER phrase does not appear, but the LINE NUMBER phrase does, then data is accepted from column 1 of the specified line position.
  3. If you use column-id without its PLUS option, the column position is the value of column-id.
  4. If you use column-id with its PLUS option, the column position is the sum of plus-num and the value of column-id.
  5. If you use the PLUS option without column-id, the column position is the sum of plus-num and the value of the current column position.
  6. If you use the PLUS option, but do not specify plus-num, PLUS 1 is implied.
  7. Data input results are undefined if the program generates a value for column position that is one of the following:

LINE NUMBER and COLUMN NUMBER Phrases (Format 5) (Alpha)

  1. The LINE NUMBER and COLUMN NUMBER phrases together give the starting screen coordinates.
  2. The position of each screen item within the referenced screen-name is offset from the LINE and COLUMN positions.
  3. If either LINE or COLUMN is not specified, the default value is 1. <>

ERASE Phrase (Formats 3 and 4)

  1. The ERASE phrase erases all, or part, of a line (or screen) before accepting data. You must specify SCREEN or LINE with the ERASE phrase.
  2. If you use the TO END option, the ERASE phrase erases the line (or screen) from the implied, or stated, cursor position to the end of the line (or screen).
  3. If you do not use the TO END option, the ERASE phrase erases the entire line (or screen).

BELL Phrase (Formats 3 and 4)

  1. The BELL phrase rings the terminal bell before accepting data.

CONTROL KEY Phrase (Formats 3 and 4)

  1. If you use the CONTROL KEY phrase, the characters representing PF keys and arrow keys, as well as TAB and RETURN, are legal terminator keys and can be accepted from the terminal. (See Technical Notes.)
  2. key-dest-item stores the terminator key code; unused character positions, if any, are filled with spaces. (See Technical Notes.)

ON EXCEPTION Phrase (Formats 3 and 4)

  1. The ON EXCEPTION phrase allows execution of an imperative statement when an exception (or error) condition occurs. ON EXCEPTION takes effect when illegal numeric data has been entered or there is an overflow on the left or right of the decimal point when CONVERSION is specified.
  2. ON EXCEPTION can be used to detect numeric data entry errors only when accepting numeric data while CONVERSION is being used.
  3. ON EXCEPTION can be used to detect end-of-file in any Format 3 or Format 4 ACCEPT statement.
  4. ON EXCEPTION and AT END are mutually exclusive. If ON EXCEPTION is specified, the end-of-file indication is also a control key.
  5. A DISPLAY statement within an ACCEPT ON EXCEPTION must be terminated (with, for example, END-DISPLAY) on Alpha systems. (If you are concerned with the different VAX behavior, refer to the appendix on compatibility in the Compaq COBOL User Manual.)

NOT ON EXCEPTION Phrase (Formats 3 and 4)

  1. The NOT ON EXCEPTION phrase allows execution of an imperative statement when an exception (or error) condition does not occur.

ON EXCEPTION Phrase (Format 5, Alpha)

  1. The ON EXCEPTION phrase allows execution of an imperative statement when the ACCEPT statement terminates unsuccessfully. When there is an applicable CRT STATUS clause, unsuccessful termination is indicated by a value of '1' or '9' in the first character of the CRT STATUS data item (see the SPECIAL-NAMES section of Chapter 4).

Note

5 Compaq COBOL also supports four-digit years using the CURRENT-DATE intrinsic function (see Chapter 7.) Compaq recommends the use of four-digit years.


Previous Next Contents Index