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 ACCEPT Statement 

Function 

The ACCEPT statement causes data keyed at the console or supplied by the
operating system to be made available to the program in a specified data
item.

General Formats 

Format 1 

[]
Format 2
[]
Format 3
[]
[]
[]
[]
[]
Syntax Rules Format 1 1. The mnemonic-name in Format 1 must be associated with a function-name in the SPECIAL-NAMES paragraph in the Environment Division. See General Rule 12 in the section "The Special-Names Paragraph" in this chapter for a list of valid function-names. ________________________________________________________________________ |(OSVS) (VSC2) (MF) | | | | | | | |2. Alternatively, function-name can itself be used instead of an | | associated mnemonic-name. | | | ________________________________________________________________________ ________________________________________________________________________ |(MF) (XOPEN) | | | | | | | |3. When mnemonic-name is associated with ARGUMENT-NUMBER in the | | SPECIAL-NAMES paragraph, then identifier must be an unsigned | | integer. | | | |4. When mnemonic-name is associated with ARGUMENT-VALUE or | | ENVIRONMENT-VALUE in the SPECIAL-NAMES paragraph, then identifier| | must be an alphanumeric data item. | | | ________________________________________________________________________ ________________________________________________________________________ | | | 5. Identifier can be a USAGE DISPLAY-1 (DBCS) item or an external | | floating-point data item. (VSC2) | | | |(MF) | |Identifier can be an internal floating-point data item. | ________________________________________________________________________ ________________________________________________________________________ |(MF) | | | | | | | |6. If you do not specify FROM, then FROM CONSOLE is assumed for all | | such ACCEPTs except the first one executed in a run unit. The | | source of the first ACCEPT without a FROM clause will be | | equivalent to either ACCEPT...FROM CONSOLE or ACCEPT...FROM | | COMMAND LINE. The exact behavior depends upon the setting of the | | run-time configuration option command_line_accept. See the | | section Configuration of Run-Time Behavior in your Additional | | Facilities for details of behavior configuration. | | | ________________________________________________________________________ Format 2 ________________________________________________________________________ |(OSVS) (VSC2) (MF) | | | | | | | |7. Identifier can be an internal floating-point or external | | floating-point item. | | | ________________________________________________________________________ ________________________________________________________________________ |(MF) | | | |Format 3 | | | | | | | |8. There are no restrictions on the class, category or usage of the | | identifier. However, the actual value placed into the identifier| | and the validity of moving such values to the identifier are | | dependent on the FROM clause. See the Format 3 General Rules for| | more information. | | | | | |Format 4 | |[REV BEG] | | | | | |9. Screen-name cannot be an item with an OCCURS clause.[REV | | END] | | | |10. Identifier-8 must be an integer. It can be signed. If unsigned | | it is treated as positive. | | | |11. Integer-7 must be an integer which can optionally be signed. If | | unsigned it is treated as positive. | | | | | |Formats 4 and 5 | | | | | | | |12. The order of execution of an ACCEPT statement is always: | | | | | | 1. the AT phrase | | | | 2. the BLANK phrase | | | | 3. display of current contents of the data area | | | | 4. the BELL phrase | | | | 5. the ACCEPT operation | | | ________________________________________________________________________ ________________________________________________________________________ |(MF) | | | | | | | |13. The LINE and COLUMN phrases can appear in any order. | | | |14. EXCEPTION and ESCAPE are equivalent. | | | |15. Identifier-3 must be a PIC 9(4) or a PIC 9(6) data item. | | | | | |Format 5 | | | | | | | |16. An ACCEPT statement whose operand is an identifier is treated as | | Format 2 if it has an AT phrase, a FROM phrase with the CRT | | option, a WITH phrase, a MODE IS BLOCK phrase, or an EXCEPTION | | phrase; or if it has no FROM phrase but the CONSOLE option clause| | is specified in the SPECIAL-NAMES paragraph. If it has the | | FROM phrase with the CONSOLE option, or if it has no FROM | | phrase and the CONSOLE IS CRT clause is not specified in the | | SPECIAL-NAMES paragraph, it is treated as the standard ANSI | | ACCEPT statement. | | | |17. The phrases following the identifier can be in any order. | | | |18. The SPACE-FILL, ZERO-FILL, LEFT-JUSTIFY, RIGHT-JUSTIFY, PROMPT | | and TRAILING-SIGN options are allowed only if the operand is an | | elementary item. | | | |19. Elementary data items within identifier-1 must be of USAGE | | DISPLAY. | | | ________________________________________________________________________ General Rules Format 1 1. When the operand of an ACCEPT statement has USAGE other than DISPLAY or an individual sign, conversion to the correct format takes place after data has been transferred into a temporary area according to rule 2. below. ________________________________________________________________________ |(MF) | | | | | | | |2. If the function-name COMMAND-LINE, or a mnemonic name associated | | with the function-name COMMAND-LINE, is specified then data is | | overwritten by the contents of a system-dependent command-line | | buffer. All other permissible function-names are treated as | | equivalent to CONSOLE. (See "The Special-Names Paragraph" | | ). | | | ________________________________________________________________________ ________________________________________________________________________ |(MF) (XOPEN) | | | | | | | |3. If the mnemonic-name associated with the function-name | | ARGUMENT-NUMBER is used, then identifier receives the number of | | arguments contained in the command line. (This includes all | | arguments, those before the program-name, the program-name | | itself, and any arguments following the program-name. Hence no | | portability from types of program invocation is expected.) | | | |4. If the mnemonic name associated with the function-name | | ARGUMENT-VALUE is used then, | | | | | | a. If a previous DISPLAY with a mnemonic-name associated with| | an ARGUMENT-NUMBER has been performed, then the value of | | the designated command-line argument is placed into | | identifier. | | | | b. If this is the first ACCEPT with a mnemonic associated | | with ARGUMENT-VALUE and there has been no preceding | | DISPLAY with a mnemonic associated with an | | ARGUMENT-NUMBER, then the value of the first command-line | | argument is placed into identifier. | | | | c. If there has been no intervening DISPLAY with a mnemonic | | associated with ARGUMENT-NUMBER since a previous ACCEPT | | with a mnemonic asscociated with ARGUMENT-VALUE, then the | | value of the next command-line argument is placed into | | identifier. | | | | d. If the current argument-number has been set to an invalid | | argument-number (greater than 99, less than 0, or greater | | than the actual number of arguments on the command-line) | | and the ON EXCEPTION phrase has been specified, that logic| | path will be followed. The value in identifier is | | undefined in this case. | | | | e. If the current ARGUMENT-NUMBER has been set to 0 then it | | is intended that the program-name of the main program of | | the run-unit will be returned. However, the effects of | | variations on program invocation can impact these results | | so that a utility or calling program can be returned | | instead. (See your COBOL System Reference for additional | | details.) | | | | Note that if an attempt is made to perform a display with a | | mnemonic-name associated with ARGUMENT- NUMBER to a value greater| | than the number of command-line arguments, there is no ON | | EXCEPTION phrase for the display; it is any subsequent ACCEPT (if| | specified) associated with ARGUMENT-VALUE which initiates the ON | | EXCEPTION path. | | | ________________________________________________________________________ ________________________________________________________________________ |(MF) (XOPEN) | | | | | | | |5. 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 performed, then the value of | | the designated environment-variable is placed into | | identifier. | | | | b. If no previous DISPLAY with a mnemonic name associated | | with an ENVIRONMENT-NAME has been performed, or if the | | specified environment-variable does not exist, then the | | imperative statement associated with an ON EXCEPTION | | phrase is executed. The value in identifier is undefined | | in this case. | | | |6. The effect of retrieving command line arguments and the number of| | arguments in a program that is called by another program is | | defined as the same as if they were retrieved by the first | | program in the run unit. | | | ________________________________________________________________________ 7. The EXCEPTION phrase may be specified only if FROM is specified with either ARGUMENT-NAME or ARGUMENT-VALUE, or with the mnemonic names associated with them. Format 2 8. The ACCEPT statement causes the information requested to be transferred to the data item specified by identifier according to the rules of the MOVE statement. DATE, DAY ,DAY-OF-WEEK (ANS85) and TIME are conceptual data items and, therefore, are not described in the COBOL program. 9. DATE is composed of the data elements: year of century, month of year, and day of month. The sequence of the data element codes shall be from high to low order (left to right): year of century, month of year, and day of month. Date, when accessed by a COBOL program, behaves as if it had been described in the COBOL program as an unsigned elementary numeric integer data item six digits in length. 10. DAY is composed of the data elements: year of century and day of year. The sequence of the data element codes shall be from high order to low order (left to right): year of century, day of year. Therefore, July 1, 1968 would be expressed as 68183. DAY, when accessed by a COBOL program, behaves as if it had been described in a COBOL program as an unsigned elementary numeric integer data item five digits in length. ________________________________________________________________________ |(ANS85) | | | | | | | |11. DAY-OF-WEEK is composed of a single data element whose content | | represents the day of the week. DAY-OF-WEEK, when accessed by a | | COBOL program, behaves as if it had been described in a COBOL | | program as an unsigned elementary numeric integer data | | item one digit in length. In DAY-OF-WEEK, the value 1 | | represents Monday, 2 represents Tuesday, ... , 7 represents | | Sunday. | | | ________________________________________________________________________ 12. TIME is composed of the data elements: hours, minutes, seconds and hundredths of a second. TIME is based on elapsed time after midnight on a 24-hour clock basis - thus, 2:41 P.M. would be expressed as 14410000. TIME, when accessed by a COBOL program behaves as if it had been described in a COBOL program as an unsigned elementary numeric integer data item eight digits in length. The minimum value of TIME is 00000000; the maximum value of TIME is 23595999. If the hardware does not have the facility to provide fractional parts of TIME, the value is converted to the closest decimal approximation. ________________________________________________________________________ |Format 3 | | | |(MF) | | | | | | | |13. The value returned from the ACCEPT FROM LINE NUMBER phrase is | | always numeric. The value is implementation- dependent. See | | your COBOL System Reference for details. | | | |14. The FROM USER NAME option returns a user-id number on UNIX | | systems, or spaces on systems where such a concept is | | meaningless. | | | |15. The FROM ESCAPE KEY option returns the two digit code generated | | by a termination key. | | | |16. The EXCEPTION STATUS item contains a three-character code that | | identifies the type of exception condition that has occurred | | during the exception of a CALL or CALL PROGRAM statement. Its | | PICTURE clause is 9 (3). | | | ________________________________________________________________________ ________________________________________________________________________ |(MF) | |If EXCEPTION STATUS is to be examined this should be done immediately | |following the CALL or CALL PROGRAM statement. There must be nothing | |between the CALL and ACCEPT FROM EXCEPTION STATUS, including an | |exception status. File I-O operations will alter the exception status| |value making it unpredictable. | | | |Format 4 | | | | | | | |17. This format of the ACCEPT statement accepts screen items,which | | are defined within the Screen Section of the program, and allows | | full access to the enhanced screen handling facilities. | | | | | |Formats 4 and 5 | | | | | | | |18. The AT phrase gives the absolute address on the screen where the | | ACCEPT operation is to start. | | | |19. 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. | | | |20. 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 | | ACCEPT starts at the position following that where the | | preceding Format 1 or Format 2 ACCEPT 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 ACCEPT starts at the specified column, | | on the line following that where the preceding Format 1 or| | Format 2 ACCEPT operation finished. | | | | e. If the column number is zero, but a non-zero line number | | is specified, the ACCEPT starts on the specified line, at | | the column following that where the preceding Format 1 or | | Format 2 ACCEPT operation finished. | | | ________________________________________________________________________ ________________________________________________________________________ |(MF) | | | | | | | |21. If the ON EXCEPTION phrase is specified, imperative-statement-1 | | is executed if the ACCEPT operation finishes with anything other | | than a normal termination. If the NOT ON EXCEPTION phrase is | | specified, imperative-statement-2 is executed if the ACCEPT | | operation terminates normally. (See the section The CRT | | STATUS Clause earlier in this chapter for possible types of | | termination.) | | | |22. The END-ACCEPT phrase delimits the scope of the ACCEPT statement.| | (See "Explicit and Implicit Scope Terminators" in the chapter| | COBOL Concepts.) END-ACCEPT is treated as a reserved word only | | if the MF(4) system directive is set. See your COBOL System | | Reference for details. | | | | | |Format 5 | | | | | | | |23. The ACCEPT operation starts at line 1, column 1 if no AT phrase | | is specified. | | | |24. If identifier is a group item and there is no MODE IS BLOCK | | phrase, then those elementary subordinate items which have names | | other than FILLER are accepted. They are positioned on the | | screen in the order their descriptions appear in the Data | | Division and are 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. The items are accepted in the same | | order. | | | | Unless otherwise specified in the CURSOR IS clause (see the | | section The CURSOR IS Clause earlier in this chapter), the cursor| | is initially positioned at the start of the first item. As the | | ACCEPT operation into each item is terminated, the cursor moves | | to the start of the next item. | | | |25. 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. | | | |26. If the PROMPT option is not specified, no character is output to | | mark empty character-positions. PROMPT without the CHARACTER | | option causes this to be done, using the character configured for| | this purpose. | | | ________________________________________________________________________ ________________________________________________________________________ |(MF) | | | | | | | |27. If the PROMPT option is not specified, those character-positions | | into which the operator does not enter data produce spaces in the| | data item. | | | |28. The WITH phrase allows you to specify certain options available | | during the operation. (See 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. | | | |29. The SPACE-FILL option causes data in free-format non-edited | | numeric data items to appear on the screen with zero-suppression | | in all integer character positions. This option affects only | | free-format, non-edited numeric data items. This takes | | effect when initial data in the data item is displayed | | and again when the ACCEPT operation into the data item is | | terminated. Any leading sign is displayed in the rightmost | | space. | | | ________________________________________________________________________ ________________________________________________________________________ |(MF) | | | | | | | |30. The ZERO-FILL option causes data in free-format non-edited | | numeric data items to appear on the screen with no | | zero-suppression. This takes effect when initial data in the | | data item is displayed and again when the ACCEPT operation | | into the data item is terminated. (See the section "The | | ZERO-FILL Clause" earlier in this chapter for this | | option's effect when used with alphabetic or alphanumeric data | | items.) | | | |31. The LEFT-JUSTIFY option is documentary only. | | | |32. The RIGHT-JUSTIFY option causes operator-keyed characters to be | | moved on the screen to the rightmost character positions of the | | field. This option affects only free-format non-edited numeric | | data items. This takes effect upon display of the initial data | | (the current contents displayed) in the data item and also upon | | termination of the ACCEPT operation. | | | |33. The TRAILING-SIGN option causes the operational sign to appear in| | the rightmost character position of the field. This takes effect| | upon display of initial data in the data item and also upon | | termination of the ACCEPT operation. This option affects only | | signed, non-edited numeric data items which are in free-format | | mode. | | | |34. The UPDATE option causes the current contents (initial data) of | | the data item to be displayed before the operator is prompted to | | key in new input. If the operator does not key in any new | | data, the initial data is then treated as though it were | | operator-keyed. If the UPDATE option is not specified, the | | display of initial data is a configuration option. (See | | your COBOL System Reference for details of configuration | | options.) | | | |35. The WITH UPPER option forces input into upper case. | | | |36. The WITH LOWER option forces input into lower case. | | | |37. If REDEFINES is used with 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. | | | |38. If identifier-8 or integer-7 has a negative value, this | | represents a request that no time-out "exception" should occur no| | matter how long there is between/before key-strokes. | | | ________________________________________________________________________ ________________________________________________________________________ |(MF) | | | | | | | |39. If identifier-8 or integer-7 is zero, this indicates that a | | time-out should not occur if characters are waiting. However, if| | no characters are waiting (when the ACCEPT is processed), then | | issue a time-out immediately. | | | |40. The ON EXCEPTION clause, if present, will be executed when a | | time-out occurs and a TIME-OUT clause is specified. The NOT ON | | EXCEPTION clause, if present, will be executed when a TIME-OUT | | clause is specified but no time-out (or other exception) | | occurs. | | | |41. If a time-out exception occurs, then the contents of any ACCEPT | | resultant-field will be defined as follows: | | | | | | a. Any field which has been partially modified will contain | | any information which has already been received. | | | | b. Fields which have "FULL" or "REQUIRED" attributes or any | | other attribute which would normally impact partial field | | input, will NOT be required to meet those attributes when | | a partial field entry has occurred when a time-out | | exception occurs. | | | | c. The rules listed above apply whether or not the timeout | | clock is reset upon each keystroke. | | | |42. If at run-time a positive timeout interval greater than | | 2,147,483,647 hundredths of a second is detected the timeout | | value will be reset to 2,147,483,647 hundredths of a second | | (which is approximately eight months). | | | |43. The TIME-OUT value specifies the number of seconds (or tenths of | | a second) after the ACCEPT statement begins processing until a | | time-out exception occurs. A new ADISCF configuration option | | controls whether or not the time-out clock is "reset" each time a| | new keyboard action is detected. An application which wants some| | ACCEPT statements to be handled with a RESET and some without, | | can make specific calls to the ADIS runtime interface before or | | after the ACCEPT statements that need changes from the default. | | For example when ADIS was configured not to do resets, if a | | program had: | | | | ACCEPT INPUT-FIELD TIME-OUT AFTER +10 | | | | Then a time-out would occur after 10 seconds had elapsed from the| | beginning of the ACCEPT, even if some characters were entered | | after 5 seconds into the ACCEPT processing. | | | ________________________________________________________________________ ________________________________________________________________________ |(MF) | | | | | | | | If, on the other hand, ADIS were configured to do resets, if a | | program had the same code given above, then each time a new | | character were entered, the TIMEOUT "clock" would be reset to | | zero. | | | |44. If a time-out exception occurs and no ON EXCEPTION phrase is | | specified, then the CRT Status keys (if specified) are updated, | | the application continues to the next logical phrase, and the | | contents of the ACCEPT receiving field are as defined above. | | (The above is true whether or not a NOT ON EXCEPTION phrase is | | specified.) | | | |45. All references to (NOT) ON EXCEPTION phrases also apply to (NOT) | | ON ESCAPE phrases. | | | ________________________________________________________________________ The ADD Statement Function The ADD statement causes two or more numeric operands to be summed and the result to be stored. General Formats Format 1
[]
Format 2
[]
Format 3
[]
Syntax Rules 1. In Formats 1 and 2, each identifier must refer to an elementary numeric item, except that in Format 2 each identifier following the word GIVING must refer to either an elementary numeric item or an elementary numeric edited item. In Format 3, each identifier must refer to a group item. 2. Each literal must be a numeric literal. 3. The composite of operands must not contain more than 18 digits (see the section "Arithmetic Statements" earlier in this chapter). a. In Format 1 the composite of operands is determined by using all of the operands in a given statement. b. In Format 2 the composite of operands is determined by using all of the operands in a given statement excluding the data items that follow the word GIVING. c. In Format 3 the composite of operands is determined separately for each corresponding pair of data items. 4. CORR is an abbreviation for CORRESPONDING. ________________________________________________________________________ |(OSVS) (VSC2) (MF) | | | | | | | |5. In Formats 1, 2, and 3, floating-point literals and | | floating-point data items can be used anywhere a numeric data | | item or literal can be specified. | | | ________________________________________________________________________ General Rules 1. See the section "The ROUNDED Phrase" , " The ON SIZE ERROR Phraseand NOT ON SIZE ERROR Phrase (ANS85)" , "The CORRESPONDING Phrase" , "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. If Format 1 is used, the values of the operands preceding the word TO are added together, then this sum is added to the current value of identifier-2 storing the result immediately into identifier-2, and repeating this process respectively for each successive operand following the word TO in left-to-right order. 3. If Format 2 is used, the value of the operands preceding the word GIVING are added together, then the sum is stored as the new value of each data item referenced by identifier-3, the resultant identifier. 4. If Format 3 is used, data items in identifier-1 are added to and stored in corresponding data items in identifier-2. ________________________________________________________________________ |(MF) | | | | | | | |5. Your COBOL system ensures that enough places are carried so as | | not to lose any significant digits during execution. | | | ________________________________________________________________________


MPE/iX 5.0 Documentation