INPUT
Syntax
INPUT input_var[MAXLEN=nn][prompt] [TYPE={CHAR|TEXT|NUMBER|INTEGER|DATE}] [STATUS=num_var][NOPROMPT][BATCH-MODE] [FORMAT={txt_lit|_var|_col}]
Description
Accepts data entered by the user at a terminal.
Use MAXLEN to prevent the user from entering data that is too long. If an INSERT or UPDATE command references a variable for which the length is greater than the length defined in the database, the SQL is rejected and SQR halts. If the maximum length is exceeded, the terminal beeps (on some systems, this may cause the screen to flash instead).
If prompt is omitted, SQR uses the default prompt. Enter [$|#]var: . In either case, a colon (:) and two spaces are added to the prompt.
Specifying TYPE causes data type checking to occur. If the string entered is not the type specified, the terminal beeps and an error message is displayed. The INPUT command is then rerun. If TYPE=DATE is specified, then input_var can be a date or text variable; however, TYPE=DATE is optional if input_var is a date variable. If a numeric variable is used, it is validated as a numeric variable. The types CHAR, TEXT, and DATE are invalid types. The data types supported are described in the following table:
| Data Type | Description |
|---|---|
|
CHAR, TEXT |
Any character. This is the default datatype. |
|
NUMBER |
A floating point number in the format [+|-]9999.999[E[+|- ]99] |
|
INTEGER |
An integer in the format [+|-]99999 |
|
DATE |
A date in one of the following formats:
|
Specifying STATUS causes the INPUT command to finish regardless of what the user enters. No error message is displayed. A nonzero error code is stored in the indicated numeric variable if the length or datatype entered is incorrect.
The following table lists the values of the STATUS argument of the INPUT command:
| Status Value | Indicates |
|---|---|
|
0 |
Successful. |
|
1 |
Bad type (did not match the datatype of TYPE). |
|
2 |
Too long (longer than MAXLEN, or the input for an INTEGER variable is < –2147483648 or > +2147483647). |
|
3 |
No arguments remain on the command line. The command was ignored. |
By using NOPROMPT and STATUS with the SHOW command, you can write a sophisticated data entry routine.
FORMAT can be used only with dates. It can be a date edit mask or the keyword DATE. Use the keyword DATE if the date must be in the format as specified with the INPUT-DATE-EDIT-MASK setting for the current locale. If FORMAT has not been set, use a database-independent format for the data as listed in the datatypes table.
Parameters
| Parameter | Description |
|---|---|
|
input_var |
Specifies a text, numeric, or date variable for the input data. |
|
MAXLEN |
Specifies the maximum length for the data. |
|
prompt |
Specifies the prompt displayed to the user. |
|
TYPE |
Specifies the datatype required for the input. |
|
STATUS |
Specifies a numeric variable for a return status code. |
|
NOPROMPT |
Prevents the prompt from being displayed before the INPUT command is processed. |
|
BATCH-MODE |
If BATCH-MODE is specified and no more arguments are in the command line, a value of 3 is returned in the STATUS variable and the user is not prompted for input. |
|
FORMAT |
Specifies the format for entering a date. The Date Edit Format Codes table lists date edit format codes. |
Example
The following example shows several INPUT commands:
input $state maxlen=2 'Please enter state abbreviation'
input #age 'Enter lower age boundary' type=integer
input $start_date 'Enter starting date for report' type=date
input $date_in format='Mon dd yyyy'
input $date format=date
The following example shows another INPUT command:
show clear-screen (5,32) reverse 'CUSTOMER SUMMARY' normal
Try_again:
show (12,20) 'Enter Start Date: ' clear-line
input $start-date noprompt status=#istat type=date
if #istat != 0
show (24,1) 'Please enter date in format DD-MON-YY' beep
goto try_again
end-if
show (24,1) clear-line ! Clear error message line.
The following example illustrates the use of the BATCH-MODE option:
begin-program
while (1)
input $A status=#stat batch-mode
if #stat = 3
break
else
do procedure ($a)
end-if
end-while
end-program
See ] ALTER-LOCALE
See The INPUT-DATE-EDIT-MASK
setting in the topic“Using the PSPSPSPSSQR.INI File and the PSSQR
Command Line