HP 3000 Manuals

ACCEPT Statement [ HP COBOL II/XL Reference Manual ] MPE/iX 5.0 Documentation


HP COBOL II/XL Reference Manual

ACCEPT Statement 

The ACCEPT statement can be used for low volume input from a specified
device.

Syntax 

ACCEPT has three general formats, as shown below:

	       Click here to view figure.
            

Parameters 

identifier      a valid data name; it receives the data entered by the
                execution of the ACCEPT statement.

SYSIN            

                in a batch job, the input stream file; in a session, this
                name indicates the terminal used to initiate execution of
                your program.  There is no indication of a pending user
                response; thus, you should use the DISPLAY statement
                immediately before the ACCEPT statement to indicate that
                the ACCEPT statement is awaiting input.  The SYSIN device
                for jobs (that is, in batch mode), is the stream file.
                For sessions, this is your terminal.

                When the FROM option is not specified, the compiler
                assumes the SYSIN device.

                ________________________________________________________ 

                NOTE  Special care must be taken when the SYSIN device is
                      used for the ACCEPT statement, and the program is
                      running in batch mode.  In this case, the ACCEPT
                      statement simply reads the next record of the job
                      stream.  Without careful planning, this record
                      could be a data record, or an MPE command.

                ________________________________________________________ 

CONSOLE          

                the operator's console.  When an ACCEPT statement
                specifying the FROM mnemonic name for CONSOLE option or
                FROM CONSOLE is executed, the field specified by
                identifier must not exceed 31 characters and the
                following actions result: 

                   1.  A system-generated message is automatically
                       displayed at the console, followed by the message,
                       AWAITING REPLY.

                   2.  Object program execution is suspended.

                   3.  When the computer operator enters the input data
                       requested, this data is moved to the field
                       specified by the identifier.  Data positioning
                       and/or conversion is performed subject to whether
                       the FREE phrase specification was included.

                ________________________________________________________ 

                NOTE  I-O errors that occur during execution of ACCEPT do
                      not produce a "tombstone" since the I-O is not done
                      by the file system.

                ________________________________________________________ 

mnemonic-name   a name assigned in the SPECIAL-NAMES paragraph of the
                ENVIRONMENT DIVISION. It must be a name for either SYSIN
                or CONSOLE, and has the same effect as the device name to
                which it is equated.

imperative-     one or more imperative statements.  The INPUT ERROR
statement       phrase in which it appears can only be used if the FREE
                phrase is used.

DATE             

                composed of the year of the century, month of year, and
                day of month, in that order.  Thus, for example, February
                16, 1985 is transmitted as 850216.  COBOL moves this data
                as an unsigned elementary numeric integer data item six
                digits in length.

DAY              

                composed of the year of the century and day of the year,
                in that order.  For example, February 16, 1985 is
                accessed as 85047.  COBOL moves this data as an unsigned
                elementary numeric integer data item five digits in
                length.

 DAY-OF-WEEK    composed of a single data element whose content
                represents the day of the week.  The value, 1 represents
                Monday, 2 represents Tuesday,..., and 7 represents
                Sunday.  COBOL moves this data as an unsigned elementary
                numeric data item one digit long.

TIME            the time of day, taken from a 24 hour clock, in hours,
                minutes, seconds and tenths of a second.  The minimum
                value of time is 00000000, and the maximum is 23595990.
                COBOL moves this data as an unsigned elementary numeric
                integer data item eight digits long.

ACCEPT Statement - Formats 1 and 2 

When formats 1 and 2 are used, data is accepted from an input spool file
(if your program is running in batch mode), the terminal from which your
program is executed (if it is running in session mode), or from the
operator's console (if the CONSOLE option is used).  This data is then
used to replace the contents of the data item named by identifier.

FREE and INPUT ERROR Phrases 

The FREE and INPUT ERROR phrases are HP extensions to the 1985 ANSI COBOL
standard.

The FREE phrase allows you to use free-field format to enter data. 

The INPUT ERROR phrases may also be used if the FREE phrase has been
specified.  They may not, however, be specified if the FREE phrase is
not.  This is the distinction between formats 1 and 2 of the ACCEPT
statement. 

Free-field format uses the pound sign (#) to indicate the end of data.
The ampersand (&), if used as the last nonblank character in a record,
indicates a continuation of data from one record or line to another.  An
ampersand takes precedence over the pound sign. 

If the ACCEPT statement is issued against a terminal (operator's console
or otherwise), the pound sign is not required to terminate data.  The
pound sign need only be used to indicate the end of data on a terminal
when the last nonblank character of data to be read is an ampersand.
Otherwise, simply pressing the RETURN key on the terminal indicates the
end of data.

If you want to enter a pound sign as part of your data, you must use two
consecutive pound signs, in which case, your program takes a single pound
sign as a data character.  Thus, for example, if you enter the
characters, ABC##&, a single pound sign is treated as part of the data,
and the ampersand is assumed to indicate a continuation of the data to
the next line.

In free-field format, alphanumeric data is left justified (or right
justified if JUSTIFIED [ RIGHT ] is specified in the PICTURE clause for
the receiving data item), with blank fill for any unused character
positions.  Numeric data is aligned on the decimal point, with zero fill
for unused character positions.

If the identifier named in the ACCEPT statement names a numeric or
numeric-edited data item, the input must be a numeric value, with an
optional leading separate sign.  Any necessary conversion takes place
automatically as in elementary moves (see the "MOVE Statement").

In any case other than numeric or numeric-edited data, input is assumed
to be alphanumeric.  No conversion takes place, but justification and
space filling is performed as described above.

If you use the FREE phrase, you can also specify the ON INPUT ERROR and  
NOT ON INPUT ERROR phrases.  These phrases allow you to handle the
following three input error conditions:

   *   An illegal digit or illegal sign in a numeric item, or too many
       digits.  The input data will not fit without left or right
       truncation.

   *   A physical I-O error or an end-of-file error.

   *   An input string that is too long for the receiving field.

When such an error condition occurs and the ON INPUT ERROR phrase is
specified, control is passed to the imperative statement of that phrase.
If none of these conditions occurs, the ON INPUT ERROR phrase is ignored
and control is transferred to the end of the ACCEPT statement, or to the
imperative statement specified in the NOT ON INPUT ERROR if it is used.


NOTE The maximum input record length for the ACCEPT statement with the FREE phrase is 256 characters. Use of the ampersand (&) continuation character, as the last nonblank character in the data record line input, allows the record length to be continued to the defined length of the identifier, which is then only limited by the available user stack space to contain the identifier.
Example. DATA DIVISION. 01 IN-DATA PICTURE X(19) VALUE SPACES. : PROCEDURE DIVISION. : ACCEPT IN-DATA FREE; ON INPUT ERROR DISPLAY "DATA TOO LONG". DISPLAY "'", IN-DATA, "'". : The following is user input to the above program: DOUBLE& TROUBLE & BUBBLE GUM The result of the above user input would be: DATA TOO LONG 'DOUBLETROUBLE BUBBL' And if the following were user input to the above program: ADD & GET ## OF SUM# The result would be: 'ADD & GET # OF SUM_' In the first response above, the message DATA TOO LONG was returned because the user response exceeded 19 characters. Note that the data stored did not include the five characters, E GUM. If the ON INPUT ERROR had not been specified, there would have been no indication that the data had been truncated. In the second example, the user response was 18 characters so the compiler adds a trailing character blank. ACCEPT Statement Without the FREE Phrase If a format 1 ACCEPT statement is used without the FREE phrase and the receiving data item requires fewer characters than the hardware imposed maximum, when the input data is transferred and it is the same length as the receiving data item, no problems arise. If a hardware device is not capable of transferring data of the same size as the receiving data item, two cases must be considered. First, if the size of the receiving data item exceeds the size of the transmitted data, the transmitted data is stored in the leftmost characters of the receiving data item. Additional data is then requested. The next group of data elements transmitted (if any) is aligned to the right of the rightmost character already occupying positions in the receiving data item. This process continues until either the receiving data item is full or the RETURN key is depressed (in session mode). Refer to "MPE XL System Dependencies" in Appendix H for more information on the ACCEPT statement and the receiving data item.
NOTE An ACCEPT operation prematurely terminated by a :EOD or :EOJ (in job mode) causes a read error condition and abort of the program.
You can use the linefeed key to continue the transmission of characters from your screen after you have reached the right margin. This allows you to enter up to 256 characters per line before you press the RETURN key. In most cases, this avoids the necessity of sending only part of the characters required to fill the receiving data item at a given time. In the second case, if the size of the transferred data exceeds the size of the receiving data item, or of the portion of the receiving data item not yet occupied, only the leftmost characters of the transferred data are stored in the area available in the receiving data item. The remaining characters are ignored. Programming Considerations The ACCEPT statement does not signal that it is waiting for a response. Therefore, a DISPLAY statement should usually precede an ACCEPT statement. This DISPLAY statement serves the dual purposes of warning you that a response is required to continue the program, and to indicate what the expected response might be. The maximum number of characters that can be read by an ACCEPT statement is 256; however, certain hardware constraints apply to the ACCEPT statement. For example, when the SYSIN device is a card reader, the maximum number of characters that can be transferred is 80. The maximum number of characters that can be transferred from a terminal depends on the width of the device's carriage; you must terminate responses from these devices. The ACCEPT statement issues multiple requests for data until sufficient data is read. If the identifier specifies 60 characters and the SYSIN device is a card reader, the last 20 characters on the card(s) are ignored. When numeric data is to be input through the ACCEPT statement, you must resolve the problems of decimal point alignment and negative input values as well as leading and trailing zero fill. The following conventions should be observed: * Identifier must be defined as X-type data or as a group item. * The number of characters input should always be equal to the length defined for the identifier. * If the period character is entered as a decimal point along with the significant data, the program must strip out the period before the numeric data can be used in arithmetic operations. This technique simplifies the task of data entry (and is, therefore, less error prone) at the cost of programming overhead. Examples The following coding is a typical example of an ACCEPT statement. Notice the use of the DISPLAY statement before the ACCEPT statement. DISPLAY "IS THIS END-OF-MONTH? REPLY YES OR NO". ACCEPT E-O-M-FLAG. The following example presents one technique for removing a period entered as a part of a numeric field that must be used for subsequent arithmetic operations. The following data description coding appears in the WORKING-STORAGE SECTION: 01 INPUT-AMOUNT. 02 FIELD-1 PIC XX. 02 FILLER PIC X. 02 FIELD-2 PIC XX. 01 HOLD-AMOUNT. 02 FIELD-A PIC 99. 02 FIELD-B PIC 99. 01 CALC-AMT REDEFINES HOLD-AMOUNT. 02 CALC-AMOUNT PIC 99V99. The following coding appears in the PROCEDURE DIVISION: GET-AMOUNT. DISPLAY "ENTER AMOUNT. FORMAT EQUALS 99.99.". DISPLAY "SUPPLY LEADING ZERO IF REQUIRED.". ACCEPT INPUT-AMOUNT. ERROR-CHECK. MOVE FIELD-1 TO FIELD-A. MOVE FIELD-2 TO FIELD-B. IF CALC-AMOUNT IS NOT NUMERIC GO TO BAD-AMOUNT. ADD CALC-AMOUNT TO FACTOR-X. : BAD AMOUNT. DISPLAY "AMOUNT ENTERED INCORRECTLY. TRY AGAIN.". GO TO GET-AMOUNT. The following two examples present possible techniques for handling the input of negative values. Example 1: Minus sign conversion method This example illustrates a method whereby the person entering the data precedes the quantity with a minus sign, and the program checks for the character and converts the value to an internal negative value. ID DIVISION. PROGRAM-ID. JUNK-1. ENVIRONMENT DIVISION. DATA DIVISION. WORKING-STORAGE SECTION. 01 IN-DATA. 02 SIGN-BYTE PIC X. 02 DATA-BYTES PIC 9(6). 01 DATA-VAL PIC S9(6). PROCEDURE DIVISION. 01-ENTER-DATA. DISPLAY "ENTER SIGN FOLLOWED BY SIX-DIGIT NUMBER". ACCEPT IN-DATA. 02-VALIDATE DATA. IF DATA-BYTES NOT NUMERIC THEN DISPLAY "ILLEGAL DIGITS IN INPUT--PLEASE RE-ENTER" GO TO 01-ENTER-DATA ELSE MOVE DATA-BYTES TO DATA-VAL IF SIGN-BYTE = "-" THEN COMPUTE DATA-VAL = - DATA-BYTES ELSE IF SIGN-BYTE NOT EQUAL TO "+" THEN DISPLAY "ILLEGAL SIGN IN INPUT--PLEASE RE-ENTER" GO TO 01-ENTER-DATA. 03-DISPLAY-RESULTS. DISPLAY "DATA-VAL = ", DATA-VAL. STOP RUN. Example 2: Use of SIGN IS LEADING SEPARATE phrase This example illustrates a method whereby the person entering the data precedes the quantity with a plus or minus sign. 01 IN-DATA-2 PIC S9(6) SIGN IS LEADING SEPARATE. ACCEPT IN-DATA-2. MOVE IN-DATA-2 TO DATA-VAL. ACCEPT Statement - Format 3 Click here to view figure. [REV BEG] Format 3 is used to transmit the date, day, day of the week, or time from the internal software clock of the system to the identifier named in the ACCEPT statement. The hardware clock is not used for these items.[REV END] Example ENVIRONMENT DIVISION. CONFIGURATION SECTION. SPECIAL-NAMES. FROM-TERMINAL IS SYSIN. DATA DIVISION. WORKING-STORAGE SECTION. 01 NUMBER-IN PIC 999V99. 01 DATE-IN. 02 YR PIC X(2). 02 MO PIC X(2). 02 DY PIC X(2). 01 DATE-OUT. 02 MONTH-OUT PIC X(2). 02 FILLER PIC X VALUE '/'. 02 DAY-OUT PIC X(2). 02 FILLER PIC X VALUE '/'. 02 YEAR-OUT PIC X(2). : PROCEDURE DIVISION. : ACCEPT DATE-IN FROM DATE. MOVE DY TO DAY-OUT. MOVE MO TO MONTH-OUT. MOVE YR TO YEAR-OUT. WRITE DATE-OUT AFTER ADVANCING 1 LINES. : ACCEPT NUMBER-IN. IF NUMBER-IN IS LESS THAN 125.50 THEN PERFORM BILL-LOW.


MPE/iX 5.0 Documentation