HP OpenVMS Systems Documentation

Content starts here

HP COBOL
User Manual


Previous Contents Index

11.2.5.3 Protecting the Screen

You can use the PROTECTED phrase in an ACCEPT statement to limit the number of characters that can be entered. This phrase prevents overwriting or deleting parts of the screen. For more information about using the PROTECTED phrase, refer to the ACCEPT statement in the HP COBOL Reference Manual.

If you use this phrase, and you try to type past the rightmost position of the input field or delete past the left edge of the input field, the terminal bell sounds and the screen cursor does not move. You can accept the data on the screen by pressing a legal terminator key, or you can delete the data by pressing the DELETE key. If you specify PROTECTED WITH AUTOTERMINATE, the ACCEPT operation terminates when the maximum number of characters has been entered unless a terminator has been entered prior to this point. For more information on legal terminator keys, refer to the CONTROL KEY phrase of the ACCEPT statement in the HP COBOL Reference Manual.

You can also use the REVERSED, BOLD, BLINKING, or UNDERLINED attributes with the PROTECTED phrase. Using these attributes lets you see the size of the input field on the screen before you enter data. The characters you enter also echo the specified attribute.

You can specify the NO BLANK and FILLER phrases with the PROTECTED phrase. The NO BLANK phrase specifies that the protected input field is not to be filled with spaces until after the first character is entered. The FILLER phrase initializes each character position of the input field with the filler character specified.

When you use the FILLER phrase with the NO BLANK phrase, the input field is filled with the filler character only after you have entered the first character.

The PROTECTED SIZE phrase sets the size of the input field on the screen and allows you to change the size of the input field from the size indicated by the PICTURE phrase of the destination item. Example 11-7 and Figure 11-8 show how to use the SIZE phrase with the PROTECTED phrase. When the example specifies SIZE 3, any attempt to enter more than three characters makes the terminal bell ring. When the example specifies SIZE 10, the ACCEPT statement includes the ON EXCEPTION phrase to warn you whenever you enter a number that will result in truncation at either end of the assumed decimal point. Figure 11-8 shows such an example in which the operator entered a 10-digit number, exceeding the storage capacity of the data item NUM-DATA on the left side of the assumed decimal point.

Note

The SIZE phrase controls only the number of characters you can enter; it does not alter any other PICTURE clause requirements. Truncation, space or zero filling, and decimal point alignment occur according to MOVE statement rules only if CONVERSION is specified.

Example 11-7 Using the SIZE and PROTECTED Phrases

IDENTIFICATION DIVISION.
PROGRAM-ID.  PROTECT.
ENVIRONMENT DIVISION.
DATA DIVISION.
WORKING-STORAGE SECTION.
01  NUM-DATA  PIC S9(9)V9(9) COMP-3.
PROCEDURE DIVISION.
A00-BEGIN.
    DISPLAY "Enter data item (NUM-DATA) but SIZE = 3:"
             LINE 1 COLUMN 14
             UNDERLINED
             ERASE SCREEN.
    PERFORM ACCEPT-THREE 5 TIMES.
    DISPLAY "Same data item (NUM-DATA) BUT SIZE = 10:" LINE PLUS 3
             COLUMN 14
             UNDERLINED.
    PERFORM ACCEPT-TEN 5 TIMES.
    STOP RUN.

ACCEPT-THREE.
    ACCEPT NUM-DATA WITH CONVERSION PROTECTED SIZE 3
           LINE PLUS COLUMN 14.
ACCEPT-TEN.
    ACCEPT NUM-DATA WITH CONVERSION PROTECTED SIZE 10
           LINE PLUS COLUMN 14
           ON EXCEPTION
               DISPLAY "TOO MANY NUMBERS--try this one again!!!"
                        COLUMN PLUS
                        REVERSED
                        GO TO ACCEPT-TEN.

Figure 11-8 Screen Display of NUM-DATA Using the PROTECTED Option


When you do not use the PROTECTED phrase, the amount of data transferred is determined according to the ACCEPT statement rules. (Refer to the HP COBOL Reference Manual.)

11.2.5.4 Using NO ECHO with ACCEPT Data

By default, the characters you type at the terminal are displayed on the screen. Example 11-8 shows how you can use the NO ECHO phrase to prevent the input field from being displayed; thus, the NO ECHO phrase allows you to keep passwords and other information confidential.

Example 11-8 Using the NO ECHO Phrase

IDENTIFICATION DIVISION.
PROGRAM-ID.  NOSHOW.
ENVIRONMENT DIVISION.
DATA DIVISION.
WORKING-STORAGE SECTION.
01  PASSWORD PIC X(25).
PROCEDURE DIVISION.
A00-BEGIN.
    DISPLAY "ENTER YOUR PASSWORD: " LINE 5 COLUMN 10
            ERASE SCREEN.
    ACCEPT PASSWORD WITH NO ECHO.
    STOP RUN.

11.2.5.5 Assigning Default Values to Data Fields

Use the DEFAULT phrase to assign a value to an ACCEPT data item whenever:

  • The program requires a value, and the operator does not have a value for the data item.
  • There is a high probability that the default value is identical in most of the records, as where a constant (such as a state's abbreviation) is used in a mailing list.

When you use the DEFAULT phrase, the program executes as if the default value had been typed in when you press Return. However, the value is not automatically displayed on the screen.

You can also use the CURRENT VALUE phrase with the DEFAULT phrase to specify that the default input value is the initial value of the ACCEPT destination item.

Example 11-9 and Figure 11-9 show how to use the DEFAULT phrase to specify default input values. (The value must be an alphanumeric data name, a nonnumeric literal, or figurative constant.) The example uses the "TO-BE-SUPPLIED" abbreviations "[TBS]" and " ***[TBS]****" and +00.00 as the default values for three data items in the program.

Example 11-9 Using the DEFAULT Phrase

IDENTIFICATION DIVISION.
PROGRAM-ID. TRYDEF.
ENVIRONMENT DIVISION.
DATA DIVISION.
WORKING-STORAGE SECTION.
01  DATA1A       PIC 9(12).
01  NAME1A       PIC XXXXX.
01  PRICEA       PIC S99V99.
01  DATA123.
    02  NAME1B   PIC XXXXX.
    02           PIC XX VALUE SPACES.
    02  DATA1B   PIC XXXXXXXXXXXX.
    02           PIC XXX VALUE SPACES.
    02  PRICEB   PIC $99.99-.
01  NAME-DEFAULT PIC XXXXX VALUE "[TBS]".
01  COL-NUM      PIC 99    VALUE 10.
PROCEDURE DIVISION.
A00-DEFAULT-TEST.
    DISPLAY "*********PLEASE ENTER THE FOLLOWING INFORMATION*********"
             LINE 5 COLUMN 15
             REVERSED BLINKING
             ERASE SCREEN.
    DISPLAY "********************************************************"
             LINE 7 COLUMN 15.
    DISPLAY " Part     Part     Part    ---------STORED AS-----------"
             LINE 9 COLUMN 15.
    DISPLAY " Name    Number    Price    Name    Number         Price"
             LINE 10 COLUMN 15.
    DISPLAY "Defaults --->[TBS] ***[TBS]**** +00.00"
             LINE 11 COLUMN 2.
    DISPLAY "----- ------------ ------"
             LINE 12 COLUMN 15.
    DISPLAY "********************************************************"
             LINE 20 COLUMN 15.
    DISPLAY "5. " REVERSED BLINKING LINE 18 COLUMN COL-NUM.
    DISPLAY "4. " REVERSED BLINKING LINE 17 COLUMN COL-NUM.
    DISPLAY "3. " REVERSED BLINKING LINE 16 COLUMN COL-NUM.
    DISPLAY "2. " REVERSED BLINKING LINE 15 COLUMN COL-NUM.
    DISPLAY "1. " REVERSED BLINKING LINE 14 COLUMN COL-NUM.
    DISPLAY " " LINE 13 COLUMN 15.
    PERFORM A05-GET-DATA 5 TIMES.
    DISPLAY " " LINE 22 COLUMN 1.
    STOP RUN.

A05-GET-DATA.
    ACCEPT NAME1A
           PROTECTED
           DEFAULT NAME-DEFAULT
           LINE PLUS COLUMN 15 ERASE TO END OF LINE.
    ACCEPT DATA1A
           PROTECTED
           DEFAULT "***[TBS]****"
           COLUMN 21.
    ACCEPT PRICEA
           PROTECTED
           WITH CONVERSION
           DEFAULT ZERO
           COLUMN 34.
    MOVE NAME1A TO NAME1B.
    MOVE DATA1A TO DATA1B.
    MOVE PRICEA TO PRICEB.
    DISPLAY DATA123 REVERSED COLUMN 44.

Figure 11-9 Accepting Data with the DEFAULT Phrase


11.2.6 Using Terminal Keys to Define Special Program Functions

Use the CONTROL KEY IN phrase of the ACCEPT statement to tailor your screen-handling programs to give special meanings to any or all of these keys on your terminal:

  • Cursor positioning keys (up arrow, down arrow, left arrow, and right arrow keys)
  • Program function keys (PF1, PF2, PF3, and PF4)
  • Function keys (F6 to F20)
  • Keypad keys (if in application keypad mode) 0 to 9, minus (--), comma (,), period (.), ENTER, FIND, INSERT HERE, REMOVE, SELECT, PREV SCREEN, NEXT SCREEN

You can use the CONTROL KEY IN phrase to accept data and to terminate it with a control key or to allow a user to press only a control key (for menu applications).

Table 11-2 lists the characters returned to the data name specified in the CONTROL KEY IN phrase.

Table 11-2 is for VT100 and later series terminals. Depending on your terminal type, certain keys listed in this table are not applicable to your terminal keyboard.

Table 11-2 HP COBOL Characters Returned for Cursor Positioning, Program Function, Function, Keypad, and Keyboard Keys
    Characters Returned in the Data Name Specified by CONTROL KEY IN
Key Name Keypad or Keyboard Name First1 Remaining (Notes)
Cursor up up arrow CSI A
Cursor down down arrow CSI B
Cursor right right arrow CSI C
Cursor left left arrow CSI D
Program function PF1 SS3 P
Program function PF2 SS3 Q
Program function PF3 SS3 R
Program function PF4 SS3 S
Keypad left blank SS3 P
Keypad center blank SS3 Q
Keypad right blank SS3 R
Keypad 0 SS3 p
Keypad 1 SS3 q
Keypad 2 SS3 r
Keypad 3 SS3 s
Keypad 4 SS3 t
Keypad 5 SS3 u
Keypad 6 SS3 v
Keypad 7 SS3 w
Keypad 8 SS3 x
Keypad 9 SS3 y
Keypad - SS3 m
Keypad , SS3 l
Keypad . SS3 n
Keypad ENTER SS3 M
Keypad FIND CSI 1~
Keypad INSERT HERE CSI 2~
Keypad REMOVE CSI 3~
Keypad SELECT CSI 4~
Keypad PREV SCREEN CSI 5~
Keypad NEXT SCREEN CSI 6~
Tab Tab 9  
Return Return 13  
Function key HOLD SCREEN Not Available  
Function key PRINT SCREEN Not Available  
Function key SET-UP Not Available  
Function key DATA/TALK Not Available  
Function key BREAK Not Available  
Function key F6 2 CSI 17~
Function key F7 CSI 18~
Function key F8 CSI 19~
Function key F9 CSI 20~
Function key F10 CSI 21~
Function key F11 (ESC) CSI 23~
Function key F12 (BS) CSI 24~
Function key F13 (LF) CSI 25~
Function key F14 CSI 26~
Function key F15 (HELP) CSI 28~
Function key F16 (DO) CSI 29~
Function key F17 CSI 31~
Function key F18 CSI 32~
Function key F19 CSI 33~
Function key F20 CSI 34~
Ctrl/A   1  
Ctrl/B   2  
Ctrl/C   Not Available  
Ctrl/D   4 (on Alpha, I64)
Ctrl/D   Results depend on presence or absence of the AT END phrase in the ACCEPT statement (on Tru64 UNIX)
Ctrl/E   5  
Ctrl/F   6  
Ctrl/G   7  
Ctrl/H   8  
Ctrl/I (Tab)   9  
Ctrl/J   10  
Ctrl/K   11  
Ctrl/L   12  
Ctrl/M (Return)   13  
Ctrl/N   14  
Ctrl/O   Not Available (on Alpha, I64)
Ctrl/O   15 (on Tru64 UNIX)
Ctrl/P   16  
Ctrl/Q   Not Available  
Ctrl/R   18  
Ctrl/S   Not Available  
Ctrl/T   Depends on SET CONTROL Setting (on Alpha, I64)
Ctrl/T   20 (on Tru64 UNIX)
Ctrl/U   21  
Ctrl/V   22  
Ctrl/W   23  
Ctrl/X   24  
Ctrl/Y   Not Available (on Alpha, I64)
Ctrl/Y   25 (on Tru64 UNIX)
Ctrl/Z   Results depend on presence or absence of the AT END phrase in the ACCEPT statement (on Alpha, I64)
Ctrl/Z   Not Available (on Tru64 UNIX)

1The CSI and SS3 characters are shown for your information only. You need not check for their presence because the remaining characters are unique and need no qualification.
2For F6, you must have specified $ SET TERMINAL/NOLINE_EDITING before running your program.


Previous Next Contents Index