Function
The ACCEPT statement transfers small amounts of data to a data item. The data is either read from a system file or made available by the compiler or operating system.
Format 1 | reads user input by means of appropriate mnemonic names or supplies information of the operating system and compiler. |
Format 2 | supplies date and time specifications of the operating system. |
Format 3 | are used to access the command line of the POSIX subsystem. |
Format 5 | supplies the contents of a BS2000 or POSIX environment variable or the contents of a specific argument from the POSIX command line. |
Format 1
ACCEPT identifier [ FROM mnemonic-name ]
Syntax rules
identifier can be an alphanumeric group item or an alphabetic, alphanumeric, external decimal data item or external floating-point data item.
If mnemonic-name is linked to operating system information (COMPILER-INFO, PROCESS-INFO, TERMINAL-INFO or DATE-ISO4), identifier may also be a national data item.mnemonic-name must be specified in the SPECIAL-NAMES paragraph and be associated with one of the following implementor-names:
SYSIPT
TERMINAL
CONSOLE
job-variable-name (BS2000 job variable)
COMPILER-INFO
CPU-TIME, PROCESS-INFO, TERMINAL-INFO, DATE-ISO4SYSIPT, TERMINAL, or CONSOLE specifies the system file from which data is to be read.
SYSIPT refers to the system file of that name.
TERMINAL refers to the system file SYSDTA (normally assigned to the data terminal).
CONSOLE refers to the system console.When entered for a job-variable-name, mnemonic-name references the associated operating system job variable which is to be read in.
When entered for COMPILER-INFO, CPU-TIME, PROCESS-INFO, or TERMINAL-INFO, mnemonic-name specifies the information which is to be requested.
COMPILER-INFO refers to information provided by the compiler.
CPU-TIME, PROCESS-INFO, TERMINAL-INFO and DATE-ISO4 refer to information provided by the operating system.If the FROM phrase is omitted, data is read by default from the logical input file SYSIPT.
Data can also be read from the logical input file SYSDTA by means of an appropriate compiler directive (see "COBOL2000 User Guide" [1]).identifier must not be defined using the ANY LENGTH clause.
The execution of ACCEPT statements and the structure of the information provided for the individual functions are described in the "COBOL2000 User Guide" [1].
General rules
Data is stored aligned to the left in the area indicated by identifier, regardless of the PICTURE character-string associated with the identifier. Incoming data is not edited, and no error checking is performed.
The only exception to this is CPU-TIME: the CPU time is moved in accordance with the rules of the MOVE statement from a field with the description PIC 9(6)V9(4).
If identifier is a zero-length item, no data is moved.If the system file specified for an ACCEPT statement is the same as one designated for a READ statement, the results will be unpredictable.
An ACCEPT statement for job-variable will be rejected with an error message at object time if the job variables are not present in the operating system. If the job variable cannot be read in for some reason, the runtime system issues an error message, and the program is then either continued or aborted, as determined by an appropriate compiler directive (see "COBOL2000 User Guide" [1]).
In the former case, the literal "/*" is assigned to the identifier according the general rule 1.
Example 8-20
ENVIRONMENT DIVISION. CONFIGURATION SECTION. SPECIAL-NAMES: TERMINAL IS T. . . PROCEDURE DIVISION. ... ACCEPT INPUT-DATA FROM T.
The mnemonic-name T is linked to the implementor-name TERMINAL in the SPECIAL-NAMES paragraph. The subsequent ACCEPT statement requests data from the system file SYSDTA, which is assigned to TERMINAL and moves this data to the data item called INPUT-DATA.
Format 2
ACCEPT identifier FROM {DATE | DAY | DAY-OF-WEEK | TIME}
Syntax rules
The data item specified by identifier must not be an alphabetic elementary item.
The ACCEPT statement causes the requested information to be moved to the data item specified by the identifier, in accordance with the rules governing the MOVE statement.
DATE, DAY, DAY-OF-WEEK and TIME are special data items and thus are not described in the compilation unit.
General rules
DATE is composed of the data elements "year" of century, "month" of year, and "day" of month. The sequence of these conceptual elementary items is as follows, from left to right: year, month, day. Thus, for example, April 1, 1996 would be expressed as 960401. DATE, if referenced in a COBOL program, is interpreted as if it had been described as an unsigned elementary numeric integer data item, six digits in length (PIC 9(6)).
DAY is composed of the data elements "year" of century, and "day" of year. The sequence of these conceptual elementary items is as follows, from left to right: year, day. Thus, for example, April 1, 1998 would be expressed as 98091. DAY, if referenced in a COBOL program, is interpreted as if it had been described as an unsigned elementary numeric integer data item, five digits in length (PIC 9(5)).
DAY-OF-WEEK is composed of a single data element whose content represents the day of the week. If referenced in a COBOL program, DAY-OF-WEEK is interpreted as if it had been described as an unsigned elementary numeric integer data item with a length of one digit (PIC 9). In DAY-OF-WEEK, the value 1 represents Monday, 2 represents Tuesday, ... , 7 represents Sunday.
TIME is composed of the data elements "hours", "minutes", "seconds" and "hundredths of a second". TIME is based on the 24-hour clock; thus 2:41 pm, for example, would be expressed as 14410000. If referenced in a COBOL program, TIME is interpreted as if it had been described as an unsigned elementary numeric integer data item, 8 digits in length (PIC 9(8)). The minimum value for TIME is 00000000, the maximum value is 23595900. The last two digits are not supplied by the system, and are therefore always set to zero.
The following three formats of the ACCEPT statement are extensions from the X/Open Portability Guide. They allow access to environment variables and command lines. Access to command lines is meaningful only if the object program is executing in the POSIX subsystem available as of BS2000/OSD V2.0. Execution of the COBOL2000 compiler and of any programs generated by it under POSIX is described in the "COBOL2000 User Guide" [1].
Format 3
This supplies the current number of arguments in the command line.
ACCEPT identifier-1 [ FROM mnemonic-name-3 ]
[END-ACCEPT]
Syntax rule
identifier-1 must refer to an elementary item that is described as an unsigned integer.
mnemonic-name-3 must be linked in the SPECIAL-NAMES paragraph with the implementor-name ARGUMENT-NUMBER.
Format 4
This supplies (consecutively) the contents of the arguments in the command line.
ACCEPT identifier-2 [ FROM mnemonic-name-4 ]
[ON EXCEPTION imperative-statement-1 [NOT ON EXCEPTION imperative-statement-2]]
[END-ACCEPT]
Syntax rules
identifier-2 must refer to an alphanumeric elementary item defined without the ANY LENGTH clause.
mnemonic-name-4 must be linked in the SPECIAL-NAMES paragraph with the implementor-name ARGUMENT-VALUE.
NOT ON EXCEPTION can only be specified if ON EXCEPTION is also specified.
Format 5
This supplies the contents of an environment variable or the contents of a specific argument from the command line. The name of the specified environment variable or the number of the specified argument in the command line must have been defined before by an appropriate DISPLAY statement.
ACCEPT identifier-2 [ FROM mnemonic-name-6 ]
[ON EXCEPTION imperative-statement-1 [NOT ON EXCEPTION imperative-statement-2]]
[END-ACCEPT]
Syntax rules
identifier-2 must refer to an alphanumeric elementary item defined without the ANY LENGTH clause.
mnemonic-name-6 must be linked in the SPECIAL-NAMES paragraph with the implementor-name ARGUMENT-VALUE or ENVIRONMENT-VALUE.
NOT ON EXCEPTION can only be specified if ON EXCEPTION is also specified.
A detailed example illustrating access to command lines and environment variables can be found in chapter 13 of the "COBOL2000 User Guide" [1].