Compaq COBOL
User Manual


Previous Contents Index

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:

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:

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 Compaq 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 OpenVMS Alpha)
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 OpenVMS Alpha)
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 OpenVMS Alpha)
Ctrl/T   20 (on Tru64 UNIX)
Ctrl/U   21  
Ctrl/V   22  
Ctrl/W   23  
Ctrl/X   24  
Ctrl/Y   Not Available (on OpenVMS Alpha)
Ctrl/Y   25 (on Tru64 UNIX)
Ctrl/Z   Results depend on presence or absence of the AT END phrase in the ACCEPT statement (on OpenVMS Alpha)
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.

The definition and value of the CSI and SS3 characters used in Table 11-2 follow:


01  SS3X                 PIC 9999 COMP VALUE 143. 
01  SS3 REDEFINES SS3X   PIC X. 
01  CSIX                 PIC 9999 COMP VALUE 155. 
01  CSI REDEFINES CSIX   PIC X. 

Figure 11-10 and Figure 11-11 show the Compaq COBOL control keys for various terminals. The shaded keys correspond to the keypad names in Table 11-2, which lists the characters returned to the application program.

Note

In Figure 11-11, your keyboard may differ slightly, but the Compaq COBOL control keys are as pictured.

Figure 11-10 Compaq COBOL Control Keys on the Standard VT100 Keypad and Keyboard


Figure 11-11 Compaq COBOL Control Keys on a Typical VT200 or Later Keypad and Keyboard


Example 11-10 shows you how to use the CONTROL KEY phrase to handle arrow keys, program function keys, keypad keys, Ctrl/Z, Tab, and Return.

When you use this phrase, you allow program function keys and arrow keys, as well as Return and Tab keys, to terminate input. This phrase also permits you to use those keys to move the cursor and to make menu selections without typing any data on the screen.

Note

To activate the auxiliary keypad, your program must execute DISPLAY ESC "=". You must also define ESC as the escape character. Refer to Example 11-10.

In Example 11-10, the terminator key codes are displayed on the screen.

Example 11-10 Using the CONTROL KEY IN Phrase

IDENTIFICATION DIVISION. 
PROGRAM-ID.  SPECIAL. 
ENVIRONMENT DIVISION. 
CONFIGURATION SECTION. 
SPECIAL-NAMES. 
    SYMBOLIC CHARACTERS 
        CR-VAL  CSI-VAL  Ctrl-Z-VAL  SS3-VAL  TAB-VAL  ESC 
    ARE 14      156      27          144       10      28. 
DATA DIVISION. 
WORKING-STORAGE SECTION. 
* 
*      The code returned will be the same regardless of 
*      terminal type. 
* 
01 CONTROL-KEY. 
   02  FIRST-CHAR-CONTROL-KEY  PIC X. 
        88 CR             VALUE CR-VAL. 
        88 CSI            VALUE CSI-VAL. 
        88 Ctrl-Z         VALUE Ctrl-Z-VAL. 
        88 SS3            VALUE SS3-VAL. 
        88 TAB            VALUE TAB-VAL. 
   02  REMAINING-CHAR-CONTROL-KEY PIC XXXX. 
        88 UP-ARROW       VALUE "A". 
        88 DOWN-ARROW     VALUE "B". 
        88 RIGHT-ARROW    VALUE "C". 
        88 LEFT-ARROW     VALUE "D". 
        88 PF1            VALUE "P". 
        88 PF2            VALUE "Q". 
        88 PF3            VALUE "R". 
        88 PF4            VALUE "S". 
        88 AUX0           VALUE "p". 
        88 AUX1           VALUE "q". 
        88 AUX2           VALUE "r". 
        88 AUX3           VALUE "s". 
        88 AUX4           VALUE "t". 
        88 AUX5           VALUE "u". 
        88 AUX6           VALUE "v". 
        88 AUX7           VALUE "w". 
        88 AUX8           VALUE "x". 
        88 AUX9           VALUE "y". 
        88 AUXMINUS       VALUE "m". 
        88 AUXCOMMA       VALUE "l". 
        88 AUXPERIOD      VALUE "n". 
        88 AUXENTER       VALUE "M". 
 
PROCEDURE DIVISION. 
P0. 
* 
* DISPLAY ESC "=" puts you in alternate keypad mode 
* 
    DISPLAY ESC "=". 
    DISPLAY " "  ERASE SCREEN. 
P1. 
 
    DISPLAY "Press a directional arrow, PF, Return, Tab,  " 
             LINE 3 COLUMN 4. 
    DISPLAY "or auxiliary keypad key (Ctrl/Z stops loop)" 
             LINE 4 COLUMN 4. 
 
    ACCEPT CONTROL KEY IN CONTROL-KEY AT END GO TO P2. 
    IF CR DISPLAY "RETURN" LINE 10 COLUMN 5 ERASE LINE GO TO P1. 
    IF TAB DISPLAY "\TAB" LINE 10 COLUMN 5 ERASE LINE GO TO P1. 
    IF PF1 DISPLAY "PF1" LINE 10 COLUMN 5 ERASE LINE GO TO P1. 
    IF PF2 DISPLAY "PF2" LINE 10 COLUMN 5 ERASE LINE GO TO P1. 
    IF PF3 DISPLAY "PF3" LINE 10 COLUMN 5 ERASE LINE GO TO P1. 
    IF PF4 DISPLAY "PF4" LINE 10 COLUMN 5 ERASE LINE GO TO P1. 
    IF UP-ARROW DISPLAY "UP-ARROW" LINE 10 COLUMN 5 ERASE LINE 
       GO TO P1. 
    IF DOWN-ARROW DISPLAY "DOWN-ARROW" LINE 10 COLUMN 5 
       ERASE LINE GO TO P1. 
    IF LEFT-ARROW DISPLAY "LEFT-ARROW" LINE 10 COLUMN 5 
       ERASE LINE GO TO P1. 
    IF RIGHT-ARROW DISPLAY "RIGHT-ARROW" LINE 10 COLUMN 5 
       ERASE LINE GO TO P1. 
    IF AUX0 DISPLAY "AUXILIARY KEYPAD 0" LINE 10 COLUMN 5 
       ERASE LINE GO TO P1. 
    IF AUX1 DISPLAY "AUXILIARY KEYPAD 1" LINE 10 COLUMN 5 
       ERASE LINE GO TO P1. 
    IF AUX2 DISPLAY "AUXILIARY KEYPAD 2" LINE 10 COLUMN 5 
       ERASE LINE GO TO P1. 
    IF AUX3 DISPLAY "AUXILIARY KEYPAD 3" LINE 10 COLUMN 5 
       ERASE LINE GO TO P1. 
    IF AUX4 DISPLAY "AUXILIARY KEYPAD 4" LINE 10 COLUMN 5 
       ERASE LINE GO TO P1. 
    IF AUX5 DISPLAY "AUXILIARY KEYPAD 5" LINE 10 COLUMN 5 
       ERASE LINE GO TO P1. 
    IF AUX6 DISPLAY "AUXILIARY KEYPAD 6" LINE 10 COLUMN 5 
       ERASE LINE GO TO P1. 
    IF AUX7 DISPLAY "AUXILIARY KEYPAD 7" LINE 10 COLUMN 5 
       ERASE LINE GO TO P1. 
    IF AUX8 DISPLAY "AUXILIARY KEYPAD 8" LINE 10 COLUMN 5 
       ERASE LINE GO TO P1. 
    IF AUX9 DISPLAY "AUXILIARY KEYPAD 9" LINE 10 COLUMN 5 
       ERASE LINE GO TO P1. 
    IF AUXMINUS DISPLAY "AUXILIARY KEYPAD -" LINE 10 COLUMN 5 
       ERASE LINE GO TO P1. 
    IF AUXCOMMA DISPLAY "AUXILIARY KEYPAD ," LINE 10 COLUMN 5 
       ERASE LINE GO TO P1. 
    IF AUXPERIOD DISPLAY "AUXILIARY KEYPAD ." LINE 10 COLUMN 5 
       ERASE LINE GO TO P1. 
    IF AUXENTER DISPLAY "AUXILIARY KEYPAD ENTER" LINE 10 COLUMN 5 
       ERASE LINE GO TO P1. 
 
    DISPLAY "Not an allowable control key -" 
             "press the Return key to continue" 
 
            LINE 10 COLUMN 5 
            WITH BELL ERASE LINE. 
    ACCEPT CONTROL-KEY. 
    GO TO P1. 
P2. 
    DISPLAY "Press the Return key to end this job" 
            LINE 11 COLUMN 5 ERASE LINE. 
    ACCEPT CONTROL KEY IN CONTROL-KEY LINE 12 COLUMN 5 ERASE LINE. 
    IF NOT CR GO TO P0 
       ELSE 
          DISPLAY "END OF JOB" LINE 13 COLUMN 35 
                   BOLD BLINKING REVERSED BELL 
                   ERASE SCREEN. 
P3. 
* DISPLAY ESC ">" WITH NO puts you out of alternate keypad mode 
* 
     DISPLAY ESC ">" WITH NO. 
     STOP RUN.                                           

Figure 11-12 shows a sample run of the program in Example 11-10 using the right arrow terminal key.

To expand upon Example 11-10, you can, for example, accept data in addition to specifying the CONTROL KEY phrase. This enables you to accept data and determine what to do next based on the data. You can use the CONTROL KEY phrase to move the cursor around on the screen or take a specific course of action.

Figure 11-12 Screen Display of Program SPECIAL



Previous Next Contents Index