INPUT

Function

Accepts data entered by the user at a terminal.

Syntax

INPUT input_var[MAXLEN=nn][prompt]
[TYPE={CHAR|TEXT|NUMBER|INTEGER|DATE}]
[STATUS=num_var][NOPROMPT][BATCH-MODE]
[FORMAT={txt_lit|_var|_col}]

Arguments

input_var

Text, numeric, or date variable for the input data.

MAXLEN

Maximum length for the data.

prompt

Prompt (literal not variable) displayed to the user.

TYPE

Datatype required for the input.

STATUS

Numeric variable for a return status code.

NOPROMPT

Prevents the prompt from displaying before INPUT 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

Format for entering a date (see Table 57, Date Edit Format Characters).

Description

Use MAXLEN to prevent entering data that is too long. If INSERT or UPDATE references a variable whose length is greater than that defined in the database, the SQL is rejected and Production Reporting 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, Production Reporting uses the default prompt, Enter [$|#]var:. In any 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. INPUT is then re-executed. 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. CHAR, TEXT, and DATE are invalid types.

Table 43. Data Types Supported by INPUT

Datatype

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:

 

MM/DD/YYYY [BC|AD] [HH:MI[:SS[.NNNNNN]] [AM|PM]]

 

MM-DD-YYYY [BC|AD] [HH:MI[:SS[.NNNNNN]] [AM|PM]]

 

MM.DD.YYYY [BC|AD] [HH:MI[:SS[.NNNNNN]] [AM|PM]]

 

SYYYYMMDD[HH24[MI[SS[NNNNNN]]]]

Specifying STATUS causes INPUT to complete 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.

Table 44. 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 SHOW, you can write a sophisticated data entry routine.

FORMAT can only be used 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 INPUT-DATE-EDIT-MASK for the current locale. If FORMAT has not been set, use a database-independent format for the data in Table 43, Data Types Supported by INPUT.

Examples

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 BATCH-MODE:

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 Also