HP 3000 Manuals

Procedure Division (cont) [ COBOL/HP-UX Language Reference for the Series 700 and 800 ] MPE/iX 5.0 Documentation


COBOL/HP-UX Language Reference for the Series 700 and 800

Procedure Division (cont) 

The COMPUTE Statement 

Function 

The COMPUTE statement assigns to one or more data items the value of an
arithmetic expression.

General Format 

[]
Syntax Rule Identifiers that appear only to the left of "=" must refer to either an elementary numeric item or an elementary numeric edited item or a floating-point item. (OSVS) (VSC2) (MF) General Rules 1. See the sections "The ROUNDED Phrase" , " The ON SIZE ERROR Phraseand NOT ON SIZE ERROR Phrase (ANS85)" , "Arithmetic Statements" , "Overlapping Operands" and "Multiple Results in Arithmetic Statements" in this chapter; and the sections "Explicit and Implicit Scope Terminators" and "Delimited Scope Statements" in the chapter COBOL Concepts. 2. An arithmetic expression consisting of a single identifier or literal provides a method of setting the values of identifier-1 equal to the value of the single identifier or literal. 3. If more than one identifier is specified for the result of the operation, that is preceding "=", the value of the arithmetic expression is computed, and then this value is stored as the new value of each occurrence of identifier-1 in turn. 4. The COMPUTE statement allows the user to combine arithmetic operations without the restrictions on composite of operands and/or receiving data items imposed by the arithmetic statements ADD, SUBTRACT, MULTIPLY and DIVIDE. The CONTINUE Statement ________________________________________________________________________ |(MF) | | | |Function | | | |The CONTINUE statement is a no operation statement. It indicates that| |no executable statement is present. | | | |General Format | | | | CONTINUE | | | |Syntax Rule | | | |The CONTINUE statement can be used anywhere a conditional statement or| |an imperative-statement can be used. | | | |General Rule | | | |The CONTINUE statement has no effect on the execution of the | |program. | ________________________________________________________________________ The DISPLAY Statement Function The DISPLAY statement causes data to be transferred from specified data items to the appropriate hardware device, such as the CRT screen. ________________________________________________________________________ |(MF) | |The DISPLAY statement also transfers data from your program to the CRT| |or video terminal screen: non-scrolling forms, into which you can | |enter data, are displayed. | ________________________________________________________________________ General Formats Format 1
[]
Format 3
[]
[]
Syntax Rules Format 1 1. The mnemonic-name must be associated with a function-name in the SPECIAL-NAMES paragraph in the Environment Division. See General Rule 9 in the section "The Special-Names Paragraph" in this chapter for a list of valid function-names. ________________________________________________________________________ |(MF) (OSVS) (VSC2) | | | | | | | |2. Alternatively, function-name can itself be used instead of an | | associated mnemonic name. | | | ________________________________________________________________________ 3. Each literal can be any figurative constant, except ALL. 4. If the literal is numeric, it must be an unsigned integer. ________________________________________________________________________ |(MF) (OSVS) (VSC2) | |This restriction can be ignored. | ________________________________________________________________________ ________________________________________________________________________ |(MF) (XOPEN) | | | | | | | |5. When mnemonic name is associated with ARGUMENT-NUMBER, then | | identifier-1 or literal-1 must each, if used, reference a data | | item defined as an unsigned integer or an unsigned integer | | literal respectively. Only a single identifier-1 or literal-1 | | can be used and the WITH NO ADVANCING phrase can not be | | used. | | | |6. When mnemonic name is associated with ENVIRONMENT-NAME or | | ENVIRONMENT-VALUE, then identifier-1 or literal-1 must each, if | | used, reference an alphanumeric data item or a nonnumeric literal| | respectively. Only a single identifier-1 or literal-1 | | can be used and the WITH NO ADVANCING phrase can not be | | used. | | | ________________________________________________________________________ ________________________________________________________________________ |(MF) | | | |Format 2 | |[REV BEG] | | | | | |7. Screen-name cannot be an item with an OCCURS clause.[REV | | END] | | | | | |Formats 2 and 3 | | | | | | | |8. The LINE and COLUMN phrases can appear in any order. | | | |9. Integer-3 must be 4 or 6 digits long. | | | | | |Format 3 | | | | | | | |10. A DISPLAY statement with an operand that is an identifier or a | | literal is treated as Format 2 if it has an AT phrase, an UPON | | phrase with the CRT or CRT-UNDER option, a WITH phrase, or a MODE| | IS BLOCK phrase; or if it has no UPON phrase but the CONSOLE IS | | CRT clause is specified in the SPECIAL-NAMES paragraph. If it | | has the UPON phrase with the CONSOLE option, or if it has no UPON| | phrase and the CONSOLE IS CRT clause is not specified in the | | SPECIAL-NAMES paragraph, it is treated as the standard ANSI | | DISPLAY statement. | | | |11. The phrases following the identifier can be in any order. | | | |12. If identifier-1 or literal-1 is not specified, then the MODE IS | | BLOCK and WITH phrases are not allowed. | | | |13. Elementary data items within identifier-1 must be of USAGE | | DISPLAY. | | | ________________________________________________________________________ General Rules Format 1 1. When operands in a DISPLAY statement have USAGE other than DISPLAY, or have included signs, they are converted to USAGE DISPLAY with separate sign. The size of the operand is taken as the size after conversion. 2. If a figurative constant is specified as one of the operands, only a single occurrence of the figurative constant is displayed. ________________________________________________________________________ |(MF) | | | | | | | |3. If the function-name COMMAND-LINE, or a mnemonic name associated | | with the function-name COMMAND LINE, is specified, then data | | overwrites the contents of a system-dependent command-line buffer| | from where it can be retrieved by subsequent use of ACCEPT | | FROM COMMAND-LINE. Only one operand is allowed in this | | case. | | | | All other permissible function-names are treated as equivalent to| | CONSOLE and each operand is transferred to the console device in | | the order listed. The total size of data displayed is equal to | | the sum of the sizes of each operand. The display starts from | | the current cursor position, overflowing onto the following | | line(s) if necessary. | | | | On earlier releases, trailing spaces after the last operand were | | not displayed. | | | ________________________________________________________________________ ________________________________________________________________________ |(ANS85) | | | | | | | |4. If the NO ADVANCING phrase is specified, the cursor is then | | left at the space following the last character displayed; | | otherwise it is positioned at the start of the next line. | | Scrolling can take place whenever the cursor is moved to a new | | line. | | | ________________________________________________________________________ ________________________________________________________________________ |(MF) (XOPEN) | | | | | | | |5. If the mnemonic name associated with the function-name | | ARGUMENT-NUMBER is used, then the position for any subsequent | | ACCEPT with a mnemonic associated with ARGUMENT-VALUE is set to | | retrieve the designated command-line argument. If the value | | associated with identifier-1 or literal-1 is less than 0, greater| | than 99, or greater than the total number of arguments on | | the command-line, then results are explicitly undefined; | | no ON EXCEPTION phrase, if specified, is required to be | | executed. | | | |6. If the mnemonic name associated with the function-name | | ENVIRONMENT-NAME is used then the variable to be read or | | set in any subsequent ACCEPT or DISPLAY with a mnemonic | | associated with ENVIRONMENT-VALUE is set to the designated | | variable name specified in literal-1 or as the contents of | | identifier-1. There is no defined ON EXCEPTION phrase | | associated with a DISPLAY UPON a mnemonic associated with an | | ENVIRONMENT-NAME. If any problem occurs while trying to set | | an ENVIRONMENT-NAME for a subsequent ACCEPT or DISPLAY | | associated with ENVIRONMENT-VALUE, then it is only the | | subsequent ACCEPT or DISPLAY that must detect the ON EXCEPTION | | condition. | | | |7. If the mnemonic name associated with the function-name | | ENVIRONMENT-VALUE is used then | | | | | | a. If a previous DISPLAY with a mnemonic name associated with| | an ENVIRONMENT-NAME has been done, then the value | | of the identifier is placed into the designated | | environment-variable. | | | | b. If no previous DISPLAY with a mnemonic name associated | | with an ENVIRONMENT-NAME has been performed, or, for | | ACCEPT, if the specified environment-variable does not | | exist, or, for DISPLAY, there is not enough space that can| | be allocated to store the environment variable, the | | imperative statement associated with an ON EXCEPTION | | phrase is executed. The value in identifier is undefined | | in this case. | | | | c. If no previous DISPLAY with mnemonic name associated with | | an ENVIRONMENT-NAME has been performed, the subsequent | | DISPLAY UPON ENVIRONMENT-VALUE will not take the ON | | EXCEPTION path. Results will be undefined. | | | ________________________________________________________________________ ________________________________________________________________________ |(MF) (XOPEN) | | | | | | | |8. If the mnemonic name associated with the function-name SYSERR is | | used, then a DISPLAY is performed as if to the CONSOLE except | | that all output is directed to the system's standard Error | | Device. | | | |9. When DISPLAYing UPON ENVIRONMENT-VARIABLE, trailing spaces are | | included in the value. You should use INSPECT REPLACING ALL | | SPACE BY LOW-VALUES to avoid this. | | | ________________________________________________________________________ ________________________________________________________________________ |(OSVS) (VSC2) (MF) | | | | | | | |10. Within identifier-1, internal floating-point numbers are | | converted to external floating-point numbers for display, so | | that: | | | | | | a. A COMP-1 item will display as if it has an external | | floating-point PICTURE clause of -.9(8)E-99. | | | | b. A COMP-2 item will display as if it has an external | | floating-point PICTURE clause of -.9(17)E-99 (even | | though this picture string is illegal if explicitly | | specified). | | | |11. Within literal-1, floating-point literals are allowed. | | | ________________________________________________________________________ Format 2 ________________________________________________________________________ |(MF) | | | | | | | |12. This format of the DISPLAY statement displays screen items, | | which are defined within the screen section of the program, | | and allows full access to the enhanced screen handling | | facilities. | | | | | |Format 2 and 3 | | | | | | | |13. The AT phrase gives the absolute address on the screen where the | | DISPLAY operation is to start. | | | |14. The order of execution of a DISPLAY statement is always: | | | | | | 1. the AT phrase | | | | 2. the BLANK phrase | | | | 3. the BELL phrase | | | | 4. the DISPLAY operation | | | ________________________________________________________________________ ________________________________________________________________________ |(MF) | | | | | | | |15. If integer-3 is 4 digits long, the first two digits specify the | | line, the second two the column. If integer-3 is 6 digits long, | | the first three digits specify the line, while the second three | | specify the column. | | | |16. Certain combinations of line and column numbers have special | | meanings, as follows: | | | | | | a. Until the column comes within range, out of range column | | values are reduced by the line length and the line value | | is incremented. | | | | b. Out of range line values cause the screen to scroll up one| | line. The effect is the same as if the line number of the| | bottom line had been specified. | | | | c. If the line and column numbers given are both zero, the | | DISPLAY starts at the position following that where the | | preceding Format 1 or Format 2 DISPLAY operation finished.| | Column 1 of each line is considered to follow the last | | column of the previous line. | | | | d. If the line number is zero, but a non-zero column number | | is specified, the DISPLAY starts at the specified column, | | on the line following that where the preceding Format 1 or| | 2 DISPLAY operation finished. | | | | e. If the column number is zero, but a non-zero line number | | is specified, the DISPLAY starts on the specified line, at| | the column following that where the preceding Format 1 or | | 2 DISPLAY operation finished. | | | | | |Format 3 | | | | | | | |17. Part of this statement can be repeated to allow the display of | | several data items. If the first identifier has no AT phrase, it| | begins at line 1, column 1. Each subsequent data item begins at | | the current cursor position as left after the previous data | | item. | | | |18. If identifier-1 is a group item and there is no MODE IS BLOCK | | phrase, then those elementary subordinate items which have | | names other than FILLER are displayed. They are displayed | | simultaneously, positioned on the screen in the order their | | descriptions appear in the Data Division, and separated by the | | lengths of the FILLER items in the group. For this purpose, the | | first position on a line is regarded as immediately following the| | last position on the previous line. | | | ________________________________________________________________________ ________________________________________________________________________ |(MF) | | | | | | | |19. The MODE IS BLOCK phrase indicates that the identifier is to be | | treated as an elementary item. Thus, even if it is a group item | | it is displayed as one item. | | | |20. The WITH phrase allows you to specify certain options available | | during the operation. (See the section The Screen Section | | earlier in this chapter for descriptions of these clauses.) | | | | In addition to the options available as screen description | | clauses, the following options can be used in the WITH phrase; | | SPACE-FILL, ZERO-FILL, LEFT-JUSTIFY, RIGHT-JUSTIFY TRAILING-SIGN | | and UPDATE. ZERO-FILL appears in this list and as a screen | | description clause because it has two different uses. Its second| | use is documented later in this chapter. | | | | A configuration option is available which allows the entry of | | data into numeric and numeric-edited screen fields in free-format| | mode. In COBOL, non-edited numeric data items are intended for | | holding data in an internal form; however, this format enables | | such data items to appear on the screen. See your COBOL System | | Reference for more details. If free-format mode is in | | effect, the data will appear automatically reformatted as | | follows: | | | | | | * with the virtual decimal point represented by a | | period | | | | * with the sign represented by a sign character ("-" for | | minus; space for plus) which appears immediately before | | the leftmost digit | | | | * with zero suppression in all integer character positions, | | except the least significant | | | | * with left justification | | | | The SPACE-FILL, ZERO-FILL, LEFT-JUSTIFY, RIGHT-JUSTIFY and | | TRAILING-SIGN options amend this format. | | | |21. If the identifier-1 is one of the following figurative constants | | it has a special effect as follows: SPACE clears from the | | specified cursor position to the end of the screen; LOW-VALUE | | moves the cursor to the specified position; ALL X"01" clears from| | the specified cursor position to the end of the line; ALL X"02" | | clears the whole screen; ALL X"07" sounds the bell. If the | | identifier is a figurative constant that is not listed above and | | the SIZE option is not specified, one occurrence of its value is | | displayed. | | | ________________________________________________________________________ ________________________________________________________________________ |(MF) | | | | | | | |22. If the SIZE option is specified for a figurative constant that | | has no special effect, then that figurative constant is displayed| | as many times as necessary to reach the length specified in the | | SIZE option. However, if the display wraps around to a new | | line, it starts again at the beginning of the figurative | | constant. | | | |23. If both the BLANK SCREEN and FOREGROUND-COLOR options are | | specified, the designated color becomes the default foreground | | color. | | | |24. If both the BLANK SCREEN and BACKGROUND-COLOR options are | | specified, the designated color becomes the default background | | color. | | | |25. If REDEFINES is used within identifier-1, the first description | | of the redefined data area is used and subsequent descriptions | | are ignored. If OCCURS or nested OCCURS are used the repeated | | data item is expanded into the full number of times it occurs, so| | that one definition is repeated for many fields. | | | ________________________________________________________________________ The DIVIDE Statement Function The DIVIDE statement divides one numeric data item into others and sets the values of data items equal to the quotient and remainder. General Formats Format 1
[]
Format 2
[]
Format 3
[]
Format 4
[]
Format 5
[]
Syntax Rules 1. Each identifier must refer to an elementary numeric item, except that any identifier associated with the GIVING or REMAINDER phrase must refer to either an elementary numeric item or an elementary numeric edited item. 2. Each literal must be a numeric literal. 3. The composite of operands, which is the hypothetical data item resulting from the superimposition of all receiving data items (except the REMAINDER data item) of a given statement aligned on their decimal points, must not contain more than eighteen digits. ________________________________________________________________________ |(OSVS) (VSC2) (MF) | | | | | | | |4. The REMAINDER phrase is invalid if the receiver or any of the | | operands is a floating-point item. | | | ________________________________________________________________________ General Rules 1. See the sections "The ROUNDED Phrase" , " The ON SIZE ERROR Phraseand NOT ON SIZE ERROR Phrase (ANS85)" , "Arithmetic Statements" , "Overlapping Operands" and "Multiple Results in Arithmetic Statements" in this chapter; and the sections "Explicit and Implicit Scope Terminators" and "Delimited Scope Statements" in the chapter COBOL Concepts. See also General Rules 7 and 9 for a presentation of the ROUNDED phrase and the ON SIZE ERROR phrase as they pertain to Formats 3, 4 and 5. 2. When Format 1 is used, literal-1 or the value of the data item referenced by identifier-1 is stored in a temporary data item. The value in this temporary data item is then divided into the value of identifier-2. The value of the dividend (the value of the data item referenced by identifier-2) is replaced by this quotient; similarly, the temporary data item is divided into each successive occurrence of identifier-2 in the left-to-right order in which identifier-2 is specified. 3. When Format 2 is used, the value of identifier-1 or literal-1 is divided into identifier-2 or literal-2 and the result is stored in each data item referenced by identifier-3. ________________________________________________________________________ |(OSVS) (VSC2) (MF) | | | | | | | |4. When Format 1 or 2 is used, floating-point data items and | | literals can be used anywhere a numeric data item or literal can | | be specified. | | | |5. When Format 3, 4 or 5 is used, floating-point data items or | | literals cannot be used. | | | ________________________________________________________________________ 6. When Format 3 is used, the value of identifier-1 or literal-1 is divided by the value of identifier-2 or literal-2 and the result is stored in each data item referenced by identifier-3. 7. Formats 4 and 5 are used when a remainder from the division operation is desired, namely identifier-4. The remainder in COBOL is defined as the result of subtracting the product of the quotient (identifier-3) and the divisor from the dividend. If identifier-3 is defined as a numeric edited item, the quotient used to calculate the remainder is an intermediate field which contains the unedited quotient. If ROUNDED is used, the quotient used to calculate the remainder is an intermediate field which contains the quotient of the DIVIDE statement, truncated rather than rounded. 8. In Formats 4 and 5, the accuracy of the REMAINDER data item (identifier-4) is defined by the calculation described above. Appropriate decimal alignment truncation (not rounding) will be performed for the content of the data item referenced by identifier-4, as needed. 9. When the ON SIZE ERROR phrase is used in Formats 4 and 5, the following rules pertain: a. If the size error occurs on the quotient, no remainder calculation is meaningful. Thus, the contents of the data items referenced by both identifier-3 and identifier-4 will remain unchanged. b. If the size error occurs on the remainder, the contents of the data item referenced by identifier-4 remains unchanged. However, as with other instances of multiple results of arithmetic statements, the user will have to do his own analysis to recognize which situation has actually occurred.


MPE/iX 5.0 Documentation