PreviousLow-level Routines for Character Interfaces Adis Configuration Utility (Adiscf)Next"

Chapter 4: Adis

Adis is a run-time support module which is provided for Screen Section and enhanced ACCEPT/DISPLAY syntax. Adis can be configured to an application's requirements using its configuration utility Adiscf (see the chapter (Adis Configuration Utility (Adiscf)). Alternatively, calls can be made from the COBOL application to Adis to configure it at run time; for example, to enable function keys.

4.1 Overview

Adis provides the run-time support for Screen Section and enhanced ACCEPT/DISPLAY syntax. Adis consists of four modules:

Module
Description
adis The main support module.
adisinit The initialization module, used only when Adis is first loaded.
adiskey The keyboard-handling module.
adisdyna The Adis dynamic attributes module.



Figure 4-1: The Adis Modules

4.1.1 Enhanced ACCEPT/DISPLAY

The enhanced ACCEPT/DISPLAY syntax provides functionality beyond the standard ANSI ACCEPT syntax, which enables you to input a data item or accept the day, date or time into a data item, and the ANSI DISPLAY syntax, which enables you to output literals and the contents of data items.

With the enhanced ACCEPT/DISPLAY syntax supported by Adis, you can specify screen position and screen attributes. It also makes it possible to do either single-field or multiple-field ACCEPT operations. For multiple-field ACCEPT operations, FILLER describes the number of character positions to skip over to the next field. In a DISPLAY operation, FILLER defines the number of spaces between literals. All areas defined as FILLER are unaffected by the ACCEPT or DISPLAY operation.

4.1.2 Screen Section

The Screen Section is a section in the Data Division containing one or more screen definitions . A screen definition may contain fields, groups, text and attributes. Fields may have edited picture strings and may also have features such as NO-ECHO , JUSTIFIED RIGHT and BLANK WHEN ZERO . The effect of ACCEPT and DISPLAY statements on screen definitions is handled by Adis.

4.1.3 Configuration

Adis can be configured to affect the behavior of ACCEPT and DISPLAY statements at run time. You can configure Adis in two ways:

4.2 Operation

This section describes how enhanced ACCEPT and DISPLAY statements are handled at run time when used with:

The term field used in relation to screen handling refers to an area on the screen that corresponds to a single data item during ACCEPT and DISPLAY operations.

4.2.1 Single Field ACCEPT and DISPLAY Statements

This section describes how ACCEPT and DISPLAY statements in the following format are handled at run time:

display data-item at xxyy ...
accept data-item at xxyy ...

where the parameters are:

data-item An elementary item defined in the Data Division of your program.
xxyy Specifies the position on the screen (xx=line, yy=column) where the DISPLAY or ACCEPT field starts. The length of the field is governed by the length and type of data-item, and by the SIZE clause of the ACCEPT or DISPLAY statement.

UNIX:
On UNIX, Adis does not display a character at the last position on the screen (for example, line 25 column 80 on a 25 line screen). This is because some terminals scroll automatically when a character appears in this position, giving different results on different hardware. If a character is displayed at a position off the screen, Adis scrolls the display such that it is visible.

We also recommend you avoid displaying at the last position of the screen on some non-UNIX environments, since scrolling can also occur.

4.2.1.1 Single Field ACCEPT Statements

The following sections describe how the ACCEPT statement is executed on different types of fields.

4.2.1.1.1 Alphanumeric Fields

The term alphanumeric field is used here to cover all alphanumeric, alphabetic and alphanumeric-edited fields. For the purposes of an ACCEPT statement, an alphanumeric-edited field is treated as an alphanumeric field of the same length. Any insertion symbols such as the forward slash character (/) or zero are ignored and treated as an X. Therefore, a field defined as PIC XX0XX0XX is treated as if it was specified as PIC X(8).

If the field is defined as alphabetic, only the characters "A" to "Z", "a" to "z" and space are allowed into the field.

The cursor is initially placed at the start of the field.

As data is entered into the field, the cursor advances to the next character. The cursor can be moved back over the data in the field using the cursor keys, and editing functions such as backspace and delete are provided.

4.2.1.1.2 Numeric and Numeric-edited Fields

The form of data entry for numeric and numeric-edited fields can be one of the following:

Use Adiscf to select the style you want. The default form of data entry is Fixed-format. You should experiment with free-format to see which method you prefer, especially when accepting into simple numeric fields.

The three styles are described below, followed by notes on data entry in general.

4.2.1.1.3 Fixed-format Data Entry

Fixed-format mode is also known as formatted mode . It can best be described as "What you see is what you get". As each key is pressed, the field is automatically reformatted to conform to the picture string . Adis tries to ensure that the field always looks on the screen as it is stored in the Data Division, and its size is the same as the size of the data item.

Therefore, as with the DISPLAY statement, it is only really sensible to accept fields that are defined as USAGE DISPLAY with no implied sign or decimal point.

During data entry, characters other than numeric digits, the plus sign (+), minus sign (-) and the decimal point (.) are rejected. Insertion characters in edited fields are automatically skipped over as the cursor is moved backward and forward. Any sign indicator is automatically modified if a + or - is pressed, regardless of where the cursor is in the field.

Zeros are allowed as insertion characters only as a leading symbol before a decimal point, or as a trailing symbol following a decimal point. For example, PIC 0.9999 and PIC 999.90 are valid, but PIC 0.0009 and PIC 999.000 are not.

Data entry of simple numeric and numeric-edited fields with no zero suppression is similar to that for alphanumeric fields, except that insert mode is not supported in numeric and numeric-edited fields. If the decimal point character is pressed in a simple numeric field, the digits are right justified. For example, a field defined as PIC 9(5) which initially contains zeros is accepted as follows (underlined characters indicate cursor position):

Initial display           00000
Pressing 1 gives          10000
Pressing 2 gives          12000
Pressing 4 gives          12400
Pressing Backspace gives  12000
Pressing "." gives        00012

Data entry into zero-suppressed fields is handled differently. The cursor is initially placed on the first character position that is not zero-suppressed. If all the digits before the decimal point are suppressed, the cursor is positioned on the decimal point itself.

While the cursor is to the left of the decimal point; that is, in the integer part of the field, the cursor moves to the right as digits are entered until the decimal point is reached. Any further digits are inserted immediately before the decimal point until all the integer places are filled. The cursor is then automatically moved to the first decimal digit and advances as the decimal digits are entered.

If you wish to enter digits after the decimal point when there are integer places still unfilled, the decimal point (.) must be entered.

For example, assume that a numeric-edited data field is defined as PIC ZZZ99.99 and initially contains zeros, the field is displayed as follows during the ACCEPT:

Initial display             00.00
Pressing 1 gives            10.00
Pressing 2 gives            12.00
Pressing 3 gives           123.00
Pressing 4 gives          1234.00
Pressing Backspace gives   123.00
Pressing 5 gives          1235.00
Pressing 6 gives         12356.00
Pressing 7 gives         12356.70
Pressing 8 gives         12356.78

If you want to enter 123.45 into the same field, the field appears as follows:

Initial display        00.00
Pressing 1 gives       10.00
Pressing 2 gives       12.00
Pressing 3 gives      123.00
Pressing "." gives    123.00
Pressing 4 gives      123.40
Pressing 5 gives      123.45

Fixed format mode is only allowed on numeric-edited data items of up to 32 characters in length. If they are longer than 32 characters, they are automatically handled in free-format mode as described below. Fields are also automatically treated as free-format if a SIZE clause is specified in the ACCEPT statement.

4.2.1.1.4 Free-format Data Entry

Free-format mode can be selected for either numeric fields or numeric-edited fields or both. This can be done using Adiscf (see the section ACCEPT/DISPLAY Options in the chapter Adis Configuration Utility (Adiscf)) for more information.

During data entry into a free-format field, the field is treated as an alphanumeric field of the appropriate length. It is only when the user leaves the field that it is reformatted to comply with the picture string. Any characters other than the digits, the sign character and the decimal point character are discarded.

Fields occupy the same number of characters on the screen as they do bytes in memory, with the exception that an additional character is allocated for implied signs and decimal points. Therefore, a data item defined as PIC S99V99 occupies six characters on the screen in free-format mode as opposed to four characters in Fixed-format mode.

It is advisable to compile the program with the DE-EDIT"1" Compiler directive set, since free-format allows data that does not conform to the screen item's PICTURE clause; with DE-EDIT"2" this is interpreted as zeros when moved to the USING or TO data item.

Data entry is the same as for alphanumeric fields.

If an enhanced ACCEPT statement is being used, the clauses SPACE-FILL, ZERO-FILL, LEFT-JUSTIFY, RIGHT-JUSTIFY and TRAILING-SIGN are applicable only to free-format non-edited fields (and are ignored with fixed format fields). See the description of the ACCEPT statement in your Language Reference for further details of these clauses.

4.2.1.1.5 RM Style Data Entry

RM style data entry is selected using the appropriate Accept/Display option in Adiscf. It is provided for emulation of numeric and numeric-edited ACCEPT operations in RM/COBOL V2.0. If this mode is selected, all other Accept/Display option numeric and numeric-edited data entries are ignored. Data entry is the same as for alphanumeric fields. All ACCEPT and DISPLAY statements behave as if the phrase MODE IS BLOCK has been specified. See the section The MODE IS BLOCK Clause for more information.

This style of numeric input is not intended for use with the screen handling syntax in this COBOL system, only with programs originally written for RM/COBOL.

4.2.1.1.6 General Data Entry

These notes concern the accepting of data into fields:

4.2.1.2 Single Field DISPLAY Statements

The following sections describe the way that the DISPLAY statement functions.

4.2.1.2.1 Format of Displayed Data

When a data item is displayed on the screen, it normally occupies the same number of characters on the screen as it does bytes in memory. The only exceptions are DBCS encoding schemes such as EUC which includes characters which differ in storage space and display size. The following examples assume such characters do not occur.

Data Description Size on Screen Comment
X(5) 5 characters  
N(5) 10 characters Each PIC N character occupies 2 bytes in memory.
G(5) 10 characters Each PIC G character occupies 2 bytes in memory.
9(5) 5 characters  
99.99 5 characters  
Z(4)9 5 characters  
99V99 4 characters V is an implied decimal point and so is not displayed on the screen.
S9(4) 4 characters The sign is implied and so is not displayed on the screen.
S9(4) SIGN LEADING SEPARATE 5 characters  
9(4) COMP 2 characters COMP fields are stored in binary; a 9(4) COMP field occupies 2 bytes in memory.

As you can see from the above examples, it is only really sensible to display fields defined as USAGE DISPLAY which do not contain implied signs or decimal points. When the field is displayed, it is copied byte-for-byte from the data item onto the screen at the required position.


Note: ANSI DISPLAY operations convert non-USAGE DISPLAY numeric items to USAGE DISPLAY before displaying.


4.2.1.2.2 Control Sequences in Displayed Data

Control sequences cannot be embedded in the data that is displayed. If you do embed control codes (that is, ASCII codes less than 32) into the data, the character corresponding to that code is displayed. For example, displaying ASCII code 7 results in a diamond character being displayed instead of sounding the bell. (In some environments, such characters are replaced by a space.) All highlighting and cursor control must be done through the syntax provided.

4.2.1.2.3 Control Sequences Using the COBCTRLCHAR Environment Variable

UNIX:
On UNIX, the COBCTRLCHAR environment variable is provided for backward compatibility. When set to Y or y, control codes are passed transparently to the terminal. This has the following consequences:

To avoid these consequences, leave COBCTRLCHAR unset, or set it to N or n.

4.2.1.2.4 Displaying Highlighted Text

If you use the CRT-UNDER phrase in a DISPLAY statement, the data item is displayed with an attribute to make the display stand out from normal displayed text. Depending on your environment, use of the CRT-UNDER phrase might cause data items to be displayed underlined, highlighted, colorized or in reverse video. This can be changed using Adiscf. See the chapter Adis Configuration Utility (Adiscf) for more information.

4.2.2 Accepting and Displaying Group Items

When displaying or accepting group items, each elementary item within the group is treated as a separate field. If an elementary item is defined as FILLER, it is simply used as a positioning item of the appropriate size; that is, you cannot accept into or display FILLER items.

4.2.2.1 Accepting Into Group Items

When accepting into a group item, each field is accepted into as described for single-field ACCEPT statements (see the section Single Field ACCEPT Statements).

Unless you explicitly position the cursor (see the section The CURSOR IS Clause), the cursor is initially placed at the start of the first field.

When the end of a field is reached, the cursor is normally advanced to the beginning of the next field automatically. This action can be prevented by turning off auto-skip (Accept/Display option 7 in Adiscf, see the chapter Adis Configuration Utility (Adiscf)). The cursor keys, and the keys set up for next and previous field operations (usually Tab and Backtab) move the cursor around the fields.

4.2.2.2 Displaying Group Items

Consider the following group item:

 01 display-item.
     03 display-item-1                  pic x(20).
     03 filler                          pic x(35).
     03 display-item-2                  pic 9(10).
     03 filler                          pic x(105).
     03 display-item-3                  pic z(4)9.

    
    

If the following statement is executed on a screen 80 characters wide:

     display display-item at 0101

display-item-1 is displayed at row 1, column 1, display-item-2 is displayed at row 1, column 56, and display-item-3 is displayed at row 3, column 11

All other areas of the screen are unaffected by this DISPLAY statement. FILLER items do not cause any data to be displayed on the screen. Consequently, data already on the screen in the positions defined by each FILLER is not altered in any way by this DISPLAY statement.

If a data item is defined as follows :

 01 data-item.
    03 data-char                       pic x occurs 2000.

and the following statement is executed:

     display data-item at 0101

then this is treated as a display of 2000 fields, each defined as PIC X, which is unlikely to be what you require. To avoid this, either redefine data-item as a PIC X(2000) and display that, or use the MODE IS BLOCK clause described in the section The MODE IS BLOCK Clause.

4.2.2.3 The MODE IS BLOCK Clause

If the MODE IS BLOCK clause is added to an ACCEPT or DISPLAY of a group item, the group item is treated as if it was an elementary item of the total size of the group item.

Consider the following group item:

 01 display-item.
    03 display-item-1          pic x(20).
    03 filler                  pic x(35).  
    03 display-item-2          pic 9(10).
    03 filler                  pic x(105). 
    03 display-item-3          pic z(4)9.

If the following statement is executed:

     display display-item at 0101 mode is block.

display-item is treated as if it is an elementary item defined as:

 01 display-item            pic x(175).

Consequently, the contents of the FILLER items are also displayed.


Note: If a program is compiled with the IBM-MS, MS"1", MS"2" or RM directives set, the Compiler treats all DISPLAY and ACCEPT operations of group items as if MODE IS BLOCK had been specified.


4.2.3 Screen Section ACCEPT and DISPLAY Statements

ACCEPT and DISPLAY operations involving Screen Section items are treated like any other ACCEPT or DISPLAY operation, but with one important difference. Consider the following code:

 working-storage section.
 01 item-a          pic 9(5).
 01 item-b          pic 9(10).
 01 item-c          pic x(10).
 ...
 screen section.
 01 demo-screen.
     03 blank screen.
     03 line 1 column 1 pic z(4)9 from item-a.
     03 line 3 column 1 pic 9(10) to item-b.
     03 line 5 column 1 pic x(10) using item-c.

When this code is compiled, the Compiler sets up a work area for each Screen Section level-01 item (record). Therefore, in this example, a work area is set up for demo-screen, large enough to hold the data for the three fields.

When the following statement:

     display demo-screen

is executed, the contents of item-a and item-c are moved from Working-Storage Section into the work area, then the data in the work area for these two fields is displayed on the screen. item-b is not displayed because it is an ACCEPT-only field.

When the following statement:

     accept demo-screen

is executed, data is accepted into the work area for item-b and item-c and then the data for these two fields is moved from the work area into the Working-Storage Section. Data is not accepted into item-a because it is a DISPLAY-only field.

It is important to note that moves from the Data Division to the work area occur only on execution of a DISPLAY statement, and moves from the work area to the Data Division occur only during execution of an ACCEPT statement. Therefore, if two ACCEPT statements are executed one after another with no intervening DISPLAY statement, the initial contents of the fields at the start of the second ACCEPT are those which were put into the work area during the previous ACCEPT operation not the current contents of the Data Division items.

Another implication of this is that a field should not be defined as numeric-edited in both the Data Division Section and the Screen Section . This results in the compiler making numeric-edited to numeric-edited moves in order to move the Data Division item into the work area and back again. The action of such moves is undefined and has unpredictable results. This is the case even if both the Data Division item and the Screen Section item have the same picture.

Hence, if the following lines are coded in your program:

 working-storage section.
 01 ws-item         pic zz9.99 value 1.23
 screen section.
 01 demo-screen.
     03 pic zz9.99 using ws-item.
 procedure division.
     display demo-screen.

the result of the DISPLAY operation is undefined . The items used in the Data Division as source or target for Screen Section ACCEPT or DISPLAY statements should always be non-edited fields.

4.2.4 The CURSOR IS Clause

The CURSOR IS clause allows you to specify precisely where in a field you want the cursor to be positioned at the start of the ACCEPT operation, and returns where the cursor was left at the end of an ACCEPT operation. If you do not specify a CURSOR IS clause in your program, the cursor is always initially positioned at the start of the first field for every ACCEPT operation.

The CURSOR IS clause is defined in the Special-Names paragraph , as follows:

 special-names.
     cursor is cursor-position.

where cursor-position is a field defined in the Working-Storage Section of your program as follows:

 01 cursor-position.
     03 cursor-row         pic 99.
     03 cursor-column      pic 99.

or:

 01 cursor-position.
     03 cursor-row         pic 999.
     03 cursor-column      pic 999.

where:

cursor-row Specifies the row the cursor is positioned on. Valid values are between 1 and the number of lines on the screen.
cursor-column Specifies the column the cursor is positioned on. Valid values are between 1 and the number of columns on the screen.

Whenever an ACCEPT statement is executed, Adis attempts to initially position the cursor at the position specified in cursor-position. If the position specified is invalid (that is, either cursor-row or cursor-column does not contain a valid value), the cursor is positioned at the start of the first field on the screen.

If the value in cursor-position is valid, Adis searches through all of the fields to see if the requested cursor position lies within one of them. If it does, the cursor is positioned at the required point. If it does not, then the cursor is positioned at the start of the first field. Therefore, if you want the cursor to be positioned at the start of the first field, set both cursor-row and cursor-column to 1.

Where the defined position is on a suppressed character or insertion symbol in a numeric edited field, the cursor moves to the first available character to the right. If there is no further data item, the cursor returns to the first data item on the screen.

When the ACCEPT is terminated, if the value in cursor-position at the start of the ACCEPT was valid, the position of the cursor when the terminating key is pressed is returned in cursor-position. This might not be the same position as the current cursor position, since Adis usually moves the cursor to the end of the field upon termination of an ACCEPT operation to allow relative positioned ACCEPT statements to start at the correct point on the screen.

If the value in cursor-position at the start of the ACCEPT operation was invalid, then, when the ACCEPT operation is terminated, the contents of cursor-position are unchanged.

One example of the use of this facility is that in menu-type operations, the operator need only move the cursor to a position on the screen corresponding to the selection required. The operator's choice can be determined by the returned value of cursor-position.

4.2.5 Large Screens

Screens larger than 25 lines can be detected by your COBOL system.

16-bit:
On the 16-bit COBOL system, if you link with the static run-time system, large screens are detected automatically. If you link with the shared run-time system, you should use the +C switch at run time

32-bit:
On 32-bit COBOL systems, large screens are detected automatically.

UNIX:
On UNIX you can define the screen size in your terminfo entry or with the LINES and COLUMNS environment variables.

Programs using ANSI ACCEPT/DISPLAY statements, enhanced ACCEPT/DISPLAY syntax, Screen Section and the COBOL system library routines should run correctly on large screens. If an application is developed for a screen larger than the screen it is run on, the extra lines of a multiple-field ACCEPT or DISPLAY are lost. In addition, if the position specified by the AT clause of an ACCEPT or DISPLAY statement is off the screen, the screen is scrolled up by one line.

4.2.6 Data Division Size

16-bit:
On the 16-bit COBOL system, all parameters passed to Adis must be in the first 64K of the Data Division. Consequently, the Screen Section must not exceed 64K and any data items used in Enhanced ACCEPT and DISPLAY statements that are passed to Adis and any parameters passed to x"AF" calls must be in the first 64K.

32-bit:
On 32-bit COBOL systems, the restriction described in the paragraph above does not apply, hence this consideration is for compatibility purposes only. This restriction should be observed only for intermediate code compiled with the INTLEVEL"1" Compiler directive.

4.2.7 CONTROL Clause in ACCEPT/DISPLAY Statements

This system supports the CONTROL clause within the WITH phrase of Format 2 of the screen handling ACCEPT and DISPLAY statements, and within Adis ACCEPT and DISPLAY statements. This clause allows attributes associated with a Screen Section item to be defined at run time. See your Language Reference for details of format and syntax.

4.2.8 Adis Configuration

One of the powerful features of Adis is that it can be configured to tailor the behavior of ACCEPT and DISPLAY statements. Full configuration is possible using the Adiscf utility (supplied with this product) via the adisctrl file produced by this utility. Full details on how to do this are given in the chapter Adis Configuration Utility (Adiscf).

Adis is designed to operate with no adisctrl file present, using predefined defaults for all the configurable options. Applications that operate successfully using these default options can be shipped without the adisctrl file.

At run time, Adis searches for the adisctrl file in the current directory and then, if not found, in the COBOL system directory. Unless your applications all use the same nondefault configuration, you are advised to work without the adisctrl file, if possible, and only to create it in the current directory if it is needed.

Remember that during installation, the default adisctrl file is copied to the COBOL system directory only when the Adis configuration is selected. If you wish to alter the default configuration, you are advised to move adisctrl into your current directory before changing it, and not return it to the COBOL system directory.

UNIX:
On some UNIX environments you might have been supplied with a cobkeymp file. If this is the case, it is essential, for correct operation of ACCEPT statements, that you have this file in the COBOL system directory. The cobkeymp file is produced by the keyboard configuration utility Keybcf, which enables you to configure the behavior of your keyboard. See the chapter Keyboard Configuration Utility (Keybcf) for more information.

Altering the Adis Configuration From a Program

The adisctrl file contains a number of predefined Adis configurations. There is a library routine that your program can use to select which configuration to use during the execution of extended ACCEPT and DISPLAY statements. It overrides the configuration selected in Adiscf .

The routine is defined as:

call x"AF" using set-configuration
                
configuration-name

where set-configuration and configuration-name are defined in the Working-Storage Section of your program as follows:

 01 set-configuration       pic 9(2) comp-x value 59.
 01 configuration-name      pic x(70).

where:

set-configuration Contains the value 255 on return from the call if the name specified in configuration-name is not found in the adisctrl file.
configuration-name The name that appears on the F6=Choose menu in Adiscf.

Adis Run-time Configuration

This section describes features of Adis that are not available via COBOL syntax, but can be accessed with the x"AF" COBOL system library routine. Most of these features can also be set by configuring Adis using Adiscf. See the chapter Adis Configuration Utility (Adiscf) for more information.

All of these features are accessed by the following CALL statement:

call x"AF" using set-bit-pairs                 
parameter-block

where the parameters are defined as follows:

 01 set-bit-pairs          pic 9(2) comp-x value 1.
 01 parameter-block.
     03 bit-pair-setting   pic 9(2) comp-x.
     03 bit-map-section    pic x value "2".
     03 bit-pair-number    pic 9(2) comp-x.
     03 filler             pic 9(2) comp-x value 1.

The values to be set for the fields bit-pair-setting and bit-pair-number vary according to the function you want to perform. The required values for these two parameters are given in each of the descriptions below.

With all x"AF" calls, if an error occurs, set-bit-pairs is set to the value 255 on return from the call.

The following functions are available using this facility:

These functions are described in the following sections.


Note: The functions Timeout unit selection, Timer reset selection and Skip concealed fields use a different definition of parameter-block from that given above. See the sections Select Timeout Units, Timeout Reset Control and Skip Concealed Fields later in this chapter for details.


Enable or Disable Predisplay

This routine enables you to control whether or not the initial contents of fields are predisplayed before any data entry is allowed when an ACCEPT statement is executed. This is also controlled by ACCEPT/DISPLAY option 5 in Adiscf. See the section Altering ACCEPT/DISPLAY Options in the chapter Adis Configuration Utility (Adiscf) for more information.

This call overrides any value set in Adiscf.


Note: The predisplay of fields defined as Fixed-format numeric or numeric-edited cannot be turned off.


The fields in parameter-block should be set as follows:

bit-pair-number must be set to 76.

bit-pair-setting should be set to one of the following values:

0 Only Fixed-format numeric and Fixed-format numeric-edited fields are predisplayed.
1 Only numeric fields and Fixed-format numeric-edited fields are predisplayed.
2 A field is predisplayed as soon as the cursor is moved into it.
3 All of the fields in the ACCEPT operation are predisplayed before any data entry is allowed. This is the default.

Example

The following code turns off predisplay of fields for all following ACCEPT operations:

     move 76 to bit-pair-number
     move 0 to bit-pair-setting
     call x"AF" using set-bit-pairs
                      parameter-block

Enable or Disable Display of the Adis Indicators

These routines enable you to enable or disable the display of the indicators that Adis displays during an ACCEPT to indicate Insert/Replace mode, Autoclear mode or "Off end of field". These can also be controlled using the Alter Message/Indicator Positions menu in Adis. See the section The Alter Message/Indicator Positions Menu in the chapter Adis Configuration Utility (Adiscf) for more information.

These calls override any settings made in Adiscf.

There is a different call to control each of the three indicators, but they all have the same format.

The fields in parameter-block should be set as follows:

    bit-pair-number should be set to one of the following:

56 To control the Insert/Replace mode indicator .
57 To control the Off end of field indicator .
58 To control the Autoclear indicator.

bit-pair-setting should be set to one of the following:
0 The indicator is displayed if necessary.
3 The indicator is never displayed.

Example

The following code disables display of the Insert/Replace indicator and enables display of the Off end of field indicator:

    move 56 to bit-pair-number
    move 3 to bit-pair-setting
        call x"AF" using set-bit-pairs
                         parameter-block
    move 57 to bit-pair-number
    move 0 to bit-pair-setting
        call x"AF" using set-bit-pairs
                         parameter-block

Enable or Disable Display Adis Error Messages

This routine enables you to enable or disable the display of the messages that Adis outputs during execution of an ACCEPT statement. These can also be controlled by use of the Alter Message/Indicator Positions menu in Adiscf. See the section Altering Message/Indicator Positions in the chapter Adis Configuration Utility (Adiscf) for more information.

This call overrides any settings made in Adiscf. By default, these messages are displayed.

The fields in parameter-block should be set as follows:

bit-pair-number must be set to 44.
bit-pair-setting should be set to one of the following values:
0 Error messages are never displayed, but the bell is rung. Invalid data entered into a numeric or numeric-edited field in free-format mode is not reported as an error.
1 Error messages are never displayed, but the bell is rung. Invalid data entered into a numeric or numeric-edited field in free- format mode is reported as an error by ringing the bell.
2 Error messages are displayed and the bell is rung if the appropriate error occurs. Invalid data entered into a numeric or numeric-edited field in free-format mode is not reported as an error.
3 Error messages are displayed and the bell is rung if the appropriate error occurs. Invalid data entered into a numeric or numeric-edited field in free-format mode is reported as an error by ringing the bell.

Example

The following code disables the display of error messages and disables the reporting of invalid data in numeric and numeric-edited fields.

     move 44 to bit-pair-number
     move 0 to bit-pair-setting
     call x"AF" using set-bit-pairs
                      parameter-block

Enable or Disable Auto-skip Between Fields

This routine enables you to control circumstances in which auto-skip to a following or preceding field occurs during execution of an ACCEPT statement. This can also be controlled using ACCEPT/DISPLAY option 7 in Adiscf. See the section ACCEPT/DISPLAY Options in chapter Adis Configuration Utility (Adiscf) for more information.

This call overrides any settings made in Adiscf.

The fields in parameter-block should be set as follows:

bit-pair-number must be set to 81.
bit-pair-setting should be set to one of the following values:
1 No auto-skip. An explicit Tab or cursor key (but not Backspace) must be used to move between fields.
3 Auto-skip enabled. Any cursor movement or a character key causes auto-skip to the next field if at end of the current field. This is the default.

Example

The following code disables auto-skip between fields:

     move 81 to bit-pair-number
     move 1 to bit-pair-setting
     call x"AF" using set-bit-pairs
                      parameter-block

Enable or Disable Input Data Case Conversion

This routine enables you to control whether lower-case ASCII characters are automatically converted to upper case on entry during execution of an ACCEPT statement.

The fields in parameter-block should be set as follows:

bit-pair-number must be set to 85.
bit-pair-setting should be set to one of the following values:
0 No case conversion occurs. This is the default.
1 Lower-case alphabetic input data is converted to upper case on entry.

Example

The following code enables conversion to upper case of all alphabetic input:

     move 85 to bit-pair-number
     move 1 to bit-pair-setting
     call x"AF" using set-bit-pairs
                      parameter-block

Enable or Disable Password Concealment

This routine enables you to control whether or not characters input when an ACCEPT statement is executed should be echoed to the screen.

The fields in parameter-block should be set as follows:

bit-pair-number must be set to 84.
bit-pair-setting should be set to one of the following values:
0 Input is echoed to the screen. This is the default.
1 Input is not echoed to the screen only for the next ACCEPT statement encountered.
2 Input is not echoed to the screen for any following ACCEPT statements until it is re-enabled.

Example

The following code conceals the input for the next ACCEPT statement only:

     move 84 to bit-pair-number
     move 1 to bit-pair-setting
     call x"AF" using set-bit-pairs
                      parameter-block

Enable or Disable Pre-clear and Auto-clear

This routine enables you to control whether a field is cleared before data entry (pre-clear), or is cleared on entry of the first keystroke (auto-clear). This can also be controlled using the ACCEPT/DISPLAY option 15 in Adiscf. See the section ACCEPT/DISPLAY Options in the chapter Adis Configuration Utility (Adiscf) for more information.

The fields in parameter-block should be set as follows:

bit-pair-number must be set to 86.
bit-pair-setting should be set to one of the following values:
0 No pre-clear or auto-clear action occurs. This is the default.
1 Pre-clear mode. On moving forward into a field for the first time it is cleared to spaces or zeros. The original contents of the field can be recovered by pressing Undo.
2 Auto-clear mode. If the first keystroke after moving forward into a field for the first time is a valid data character, the field is cleared to spaces or zeros before processing the character. Any other type of key turns off auto-clear mode. The original contents of the field can be recovered by pressing Undo.
3 Pre-clear mode. As for option 2, except that Undo cannot be used to recover the original contents of the field.

Example

The following code enables pre-clear mode:

     move 86 to bit-pair-number 
     move 1 to bit-pair-setting
     call x"AF" using set-bit-pairs
                      parameter-block

Select Timeout Units

This routine enables you to determine whether the timeout value is interpreted as seconds or tenths of a second.

This can also be controlled using ACCEPT/DISPLAY option 32 in Adiscf. See the section ACCEPT/DISPLAY Options in the chapter Adis Configuration Utility (Adiscf) for more information.

For this routine, parameter-block should be defined as follows:

 01 parameter-block.
     03 bit-pair-setting    pic 9(2) comp-x.
     03 bit-map-section     pic x value "6".
     03 bit-pair-number     pic 9(2) comp-x.
     03 filler              pic 9(2) comp-x value 1.

The fields in parameter-block should be set as follows:

bit-pair-number must be set to 14.
bit-pair-setting should be set to one of the following values:
0 Units are seconds. This is the default.
1 Units are tenths of a second.

Example

The following code specifies that any subsequent timeout is specified in tenths of a second:

     move 14 to bit-pair-number
     move 1 to bit-pair-setting
     call x"AF" using set-bit-pairs
                      parameter-block

Timeout Reset Control

This routine enables you to control whether the timer is reset every time a character is entered, or times out after the specified period anyway.

This can also be controlled using ACCEPT/DISPLAY option 33 in Adiscf. See the section ACCEPT/DISPLAY Options in the chapter Adis Configuration Utility (Adiscf) for more information.

For this routine, parameter-block should be defined as follows:

 01 parameter-block.
     03 bit-pair-setting    pic 9(2) comp-x.
     03 bit-map-section     pic x value "6".
     03 bit-pair-number     pic 9(2) comp-x.
     03 filler              pic 9(2) comp-x value 1.

The fields in parameter-block should be set as follows:

bit-pair-number must be set to 15.
bit-pair-setting should be set to one of the following values:
0 Timer is never reset. Timeout occurs after the specified time from the start of the ACCEPT operation. This is the default.
1 The timer is reset each time a character is entered.

Skip Concealed Fields

This routine enables you to control circumstances in which you can skip to the following or preceding concealed field during execution of an ACCEPT statement. A concealed field is one which contains the NO-ECHO clause.

This can also be controlled using ACCEPT/DISPLAY option 30 in Adiscf. See the section ACCEPT/DISPLAY Options in the chapter Adis Configuration Utility (Adiscf) for more information.

For this routine, parameter-block should be defined as follows:

 01 parameter-block.
     03 bit-pair-setting    pic 9(2) comp-x.
     03 bit-map-section     pic x value "6".
     03 bit-pair-number     pic 9(2) comp-x.
     03 filler              pic 9(2) comp-x value 1.

The fields in parameter-block should be set as follows:

bit-pair-number must be set to 16
bit-pair-setting should be set to one of the following values:
0 Concealed fields are not skipped. This is the default.
1 Concealed fields are skipped.

Example

The following code enables skipping of concealed fields:

move 16 to bit-pair-number
move 1 to bit-pair-setting
call x"AF" using set-bit-pairs 
                 parameter-block

Enable or Disable Screen Read on Non-FED Terminals (UNIX only)

UNIX:
This function enables the initial field contents to be read from the current screen map held by the RTS, when predisplay is off during an ACCEPT operation.

The fields in parameter-block should be set as follows:

bit-map-section must be set to 6.
bit-pair-setting should be set to one of the following values:
0 No read takes place. This is the default.
1 During an ACCEPT operation, if predisplay is off, the initial field contents are read from the current screen map held by the RTS.

Note: bit-map-section is set to 6 for this function, but 2 for all the other functions listed in this section. Do not forget to restore it to 2 after using this function if you are going to use another one.


4.2.9 Keyboard Handling Via Adis

The following subjects are described in this section:

4.2.9.1 Types of Keys on the Keyboard

In general, the keys on the keyboard can be split into four groups:

4.2.9.1.1 Function Keys

The most general definition of a function key is any key you would not find on a typewriter keyboard. This definition includes explicit function keys on the keyboard (usually labeled F1, F2 ... F12) and such keys as Esc, the cursor keys, Tab, and Backspace. Enter is also treated as a function key, but with special considerations, described later.

In your COBOL system, these function keys are divided into two groups:

Adis Keys

Adis keys are those keys that are used by Adis during the execution of an ACCEPT statement. This includes the cursor keys, Tab, Backspace, Del and Enter.

Normally, these keys operate as defined during an ACCEPT operation. For example, the <left-arrow> key moves the cursor to the left, Backspace erases the previous character, and so on. With the exception of the Enter key, they do not normally terminate the ACCEPT operation. However, you can make these keys terminate the ACCEPT operation if required. This is described later in this section.

User Function Keys

User function keys are so called because you can decide what they are used for when you are writing an application. There is no predefined action assigned to these keys. The user function keys generally include the keys labeled F1, F2 ... F12, the Escape key, and any other special keys that are on the keyboard.

4.2.9.1.2 Data Keys

Data keys are those keys that generate characters that are in the extended ASCII character set; that is, those with ASCII codes in the range 32 to 255. During an ACCEPT operation, pressing one of these keys simply places the character into the field. However, it is possible to disable a key completely or make it terminate the ACCEPT operation (similar to the action of a function key). This is covered later in this section.

ASCII codes in the range 0 to 31 can be considered as either data keys or function keys. For most purposes, they are treated as function keys and are disabled as data keys.

4.2.9.1.3 Shift Keys

A shift key is a key whose depression and release are regarded as separate events. Examples of shift keys in Adis are Alt, Ctrl and Shift. See the section Shift Key Handling later in this chapter for more information on shift keys.

4.2.9.1.4 Lock Keys

A lock key is a key whose state is toggled when it is pressed. Examples of lock keys are Caps Lock, Insert, Num Lock and Scroll Lock. See the section Lock Key Handling later in this chapter for more information on lock keys.

4.2.9.2 Function Key Handling

This section describes how to use function keys in this COBOL system. It describes the portable method that works on all environments. There is another method, using the x"B0" routine, which is not described here as it is machine dependent. If you are using this routine, see the section Conflict with the x"B0" COBOL System Library Routine for details of how this could cause problems with certain configurations.

4.2.9.2.1 The CRT STATUS Clause

If you decide that you want your application to use function keys, it is highly likely that you will want to be able to determine exactly which key has been pressed. To do this you need to include the CRT STATUS clause in the Special-Names paragraph of your program as follows:

 special-names.
     crt status is key-status.

where the parameter is:

key-status A three-byte data item in the Working-Storage Section of your program with the following definition:

                     01 key-status.
                        03 key-type     pic x.
                        03 key-code-1   pic 9(2) comp-x.
                        03 key-code-2   pic 9(2) comp-x.

Whenever an ACCEPT statement is executed, key-status is set to indicate how the ACCEPT was terminated. The exact usage of the individual fields in key-status is described later. However, in general they have the following uses:

key-type Indicates how the ACCEPT was terminated. The values returned are as follows :

"0" - Normal termination of the ACCEPT.
"1" - Termination by a user function key.
"2" - Termination by an Adis key.
"3" - Termination by an 8-bit data key.
"4" - Termination by a 16-bit data key.
"5" - Termination by a shift key.
"6" - Termination by a lock key.
"9" - Error.

These different values are described fully later in this section.

key-code-1 Indicates the number of the key that terminated the ACCEPT operation. The exact meaning of this number depends on the value returned in key-type.
key-code-2 If key-type and key-code-1 are 0, key-code-2 contains the raw keyboard code for the key that terminated the ACCEPT operation. Where a sequence of keystrokes rather than a single key has been configured to perform a single function, only the code for the first keystroke is returned.

If key-type is 4, key-code-2 contains the second byte of the character which caused the ACCEPT operation to terminate.

Otherwise, the contents of key-code-2 are undefined.

See your Language Reference for more information on the CRT STATUS clause.

4.2.9.2.2 Normal Termination of an ACCEPT Operation

There are two cases of normal termination of an ACCEPT. They both return a value of 0 in key-type:

Example

     accept data-item at 0101
     if key-type = "0"
         if key-code-1 = 48
             display "Terminated by return key"
         else
             display "Terminated by auto-skip last field"
         end-if
     end-if.
4.2.9.2.3 Using the User Function Keys

There are up to 128 user function keys. The defaults supplied with your COBOL system differ on different operating environments, but the following keys are standard:

Keystroke
User Function Key Number
Escape 0
F1 1
F2 2
F3 3
F4 4
F5 5
F6 6
F7 7
F8 8
F9 9
F10 10

Your keyboard might not have these keys, but if they are there, they should be configured as above. Additionally, the following user function keys might be defined:

Keystroke
User Function Key Number
Shift+F1 - Shift+F10 11 - 20
Ctrl+F1 - Ctrl+F10 21 - 30
Alt+F1 - Alt+F10 31 - 40
Alt+1 - Alt+9 41 - 49
Alt+0 50
Alt+- 51
Alt+= 52
PgUp 53
PgDn 54
Ctrl+PgUp 55
Ctrl+PgDn 56
Alt+A - Alt+Z 65 - 90
F11 91
F12 92
Shift+F11 93
Shift+F12 94
Ctrl+F11 95
Ctrl+F12 96
Alt+F11 97
Alt+F12 98

UNIX:
On UNIX, the function keys are defined in your terminfo database. The default function keys depend on your operating system and terminal type, and on some of these shifted function keys are not available. See also the appendix UNIX Key Usage Chart in the Object COBOL User Guide.

Enabling and Disabling the User Function Keys

Before you can use any of the user function keys, they must be enabled. If a user key is enabled, it terminates the ACCEPT operation when pressed. If the key is disabled, the key is rejected and the bell rung.

By default, on DOS, Windows and OS/2 this COBOL system disables the user function keys; on UNIX the COBOL system enables the user function keys. Therefore, if you want to write programs that work in both environments, include code to enable the keys you want and disable all others.

The following call is used to selectively enable and disable the user function keys:

call x"AF" using    set-bit-pairs                    
user-key-control

where:

set-bit-pairs and user-key-control are defined in the Working-Storage Section of your program as follows:

 01 set-bit-pairs             pic 9(2) comp-x value 1.
 01 user-key-control.
     03 user-key-setting      pic 9(2) comp-x.
     03 filler                pic x value "1".
     03 first-user-key        pic 9(2) comp-x.
     03 number-of-keys        pic 9(2) comp-x.

where the parameters are:

user-key-setting Set to 0 to disable keys or 1 to enable keys.
first-user-key The number of the first key to be enabled or disabled.
number-of-keys The number of consecutive keys to enable or disable.

Function keys are enabled or disabled until explicitly changed by another call to x"AF" or until the application terminates. Calls to enable or disable function keys are cumulative. For example, if you call x"AF" to enable function key F1, then make a second call to enable F10, both keys are enabled.

Example

The following code enables the Escape key and function keys F1 and F10, but disables all other user function keys:

* Enable Escape key 
     move 1 to user-key-setting
     move 0 to first-user-key
     move 1 to number-of-keys
     call x"AF" using set-bit-pairs
                      user-key-control
* Disable 126 keys starting from key 1
     move 0 to user-key-setting
     move 1 to first-user-key
     move 126 to number-of-keys
     call x"AF" using set-bit-pairs
                      user-key-control.
* Enable F1 and F10.
     move 1 to user-key-setting
* Enable F1.
     move 1 to first-user-key
     move 1 to number-of-keys
     call x"AF" using set-bit-pairs
                      user-key-control
* Enable F10
     move 10 to first-user-key
     call x"AF" using set-bit-pairs
                      user-key-control
Detecting User Function Keys

If you press an enabled user function key during an ACCEPT operation, the ACCEPT operation is terminated and the fields in key-status are set as follows:

Data Item
Setting
key-type "1"
key-code-1 Set to the number of the user key that was pressed.
key-code-2 Undefined.

Example

The following code detects which function key is pressed, assuming that the only enabled function keys are Escape, F1 and F10:

     accept data-item at 0101
     if key-type = "1"
         evaluate key-code-1
           when 0
             display "escape was pressed"
           when 1
             display "F1 was pressed"
           when 10
             display "F10 was pressed"
         end-evaluate
     end-if.
The Compatibility Key List

Most of the time, you need to use only the one list of user function keys. However, if you are converting from another dialect of COBOL, you might be in the situation where you have some programs that expect the values returned from the standard user key list and some programs that expect the values returned by the function keys in some other dialect of COBOL. To enable you to do this, the compatibility key list is provided. This works in exactly the same way as the normal key list. Any program can use either the standard user key list or the compatibility list, but not both.

By default, a program uses the standard user key list. If you want all programs in your system to use the compatibility key list, you can use Adiscf to select its use. If you want different programs to use different lists, you can insert the following call into your programs to select the list you require:

call x"AF" using    set-bit-pairs                    
key-list-selection

where set-bit-pairs and key-list-selection are defined in the Working-Storage Section of your program as follows:

 01 set-bit-pairs         pic 9(2) comp-x value 1.
 01 key-list-selection.
     03 key-list-number   pic 9(2) comp-x.
     03 filler            pic x value "1".
     03 filler            pic 9(2) comp-x value 87.
     03 filler            pic 9(2) comp-x value 1.

where key-list-number should be set to one of the following values:

1 To select the standard user function key list.
2 To select the compatibility key list.

The default compatibility key list included in your COBOL system is set up to return the values provided by function keys in the UNIX version of RM/COBOL 2.0.

The User Function Keys and Validation Clauses

Normally, if a validation clause, such as FULL or REQUIRED, is specified in an ACCEPT statement, that clause must be satisfied before you can leave the field. For example, when the statement:

     accept data-item with required

is executed, you are not allowed to terminate the ACCEPT operation unless something has been entered into the field.

However, if an enabled user function key is pressed during an ACCEPT operation, it is regarded as an exception and terminates the ACCEPT operation even if the validation clause has not been satisfied. If you do not want function keys to terminate the ACCEPT operation without satisfying validation clauses, you can set ACCEPT/DISPLAY option 9 using Adiscf. See the section ACCEPT/DISPLAY Options in chapter Adis Configuration Utility (Adiscf) for more information.

4.2.9.2.4 Using the Adis Keys

As noted in the section Function Keys, the Adis keys are those keys that perform functions within an ACCEPT operation such as cursor movement, delete character, and backspace. However, it is possible to make these keys terminate an ACCEPT operation.

You must appreciate the distinction between the keys that perform the functions, and the functions themselves; there is actually a soft mapping between the keys and the functions they perform. This means that you can change the function that any of the Adis keys perform.

The Functions Performed by the Adis Keys

A full list of the functions performed by the Adis keys is given in the section List of Standard Adis Key Functions in the chapter Keyboard Configuration Utility (Keybcf). Functions 0 through 27 are simple functions. Functions 55 to 62 are complex functions which can perform different actions depending on some state. For example, those functions provided for RM compatibility have a different action depending on whether or not the UPDATE clause is specified in the ACCEPT statement.

The Adis Keys

There are 28 Adis keys (numbered 0 through 27) in DOS, Windows and OS/2 environments and 27 (numbered 0 through 26) Adis keys in UNIX environments. Each key is mapped onto a function, so that when a key is pressed, it performs the function it has been mapped to. The functions are described in the section List of Standard Adis Key Functions in the chapter Keyboard Configuration Utility (Keybcf).

You must also be aware that the Adis keys themselves are given names. However, this name is used to distinguish the different keys; it might not necessarily describe the function the key actually performs. The following list gives the names of the keys and the keystrokes required to obtain them. You might have a different configuration for your environment; refer to your Release Notes for details.

Key
Number
Function Default Key/Keystroke
  DOS, Windows and OS/2 UNIX
0 Terminate ACCEPT None Ctrl+J or KEY_ENTER or KEY_RETURN
1 Terminate program Ctrl+K Ctrl+K
2 Carriage return (mapped to function 00) Enter or Return Ctrl+M
3 Cursor left Cursor Left (left-arrow) KEY_LEFT
4 Cursor right Cursor Right (right-arrow) KEY_RIGHT
5 Cursor up Cursor Up (up-arrow) KEY_UP
6 Cursor down Cursor Down (down-arrow) KEY_DOWN
7 Home Home KEY_HOME
8 Tab (mapped to function 11) Tab Ctrl+I or KEY_TAB
9 Backtab (mapped to function 12) Backtab Ctrl+L or KEY_BACKTAB
10 End End KEY_LL or Ctrl+O or KEY_END
11 Next field None Ctrl+N
12 Previous field None Ctrl+P
13 Change case Ctrl+F Ctrl+F
14 Erase character Backspace KEY_BACKSPACE or Ctrl+H
15 Retype character Ctrl+Y Ctrl+R
16 Insert character Ctrl+O KEY_IC or Ctrl+V
17 Delete character Del KEY_DC or Del
18 Restore character Ctrl+R Ctrl+U
19 Clear to end of field Ctrl+Z KEY_EOL or Ctrl+Z
20 Clear field Ctrl+X KEY_DL or Ctrl+X
21 Clear to end of screen Ctrl+End KEY_EOS or Ctrl+D
22 Clear screen Ctrl+Home KEY_CLEAR or Ctrl+E
23 Set Insert mode Insert KEY_IL or Ctrl+T
24 Set Replace mode None Not defined
25 Reset field Ctrl+A Ctrl+A
26 Start of field None Ctrl+W
27 Move to Mouse position None Not applicable


Note: On some keyboards you can map different functions to the Enter and Return keys. In this case, map the Terminate ACCEPT function to the Enter key, and map the Carriage Return function to the Return key.

To change the UNIX mapping for the Enter and Return keys so that they behave the same as on DOS, Windows and OS/2, use Keybcf (see the chapter Keyboard configuration Utility). You must first delete all the key mappings for the Terminate ACCEPT function, and then map the Carriage Return function to the Enter and Return keys.


Mapping the Adis Keys to the Functions

In general, the Adis keys are mapped onto the function of the same name. Therefore, the <left-arrow> key moves the cursor to the left, the Backspace key erases a character and so on.

However, there are some functions that invoke other functions, thereby changing the effect of the key. The functions that invoke other functions are:

Function
Invoked Function
Carriage Return Terminate ACCEPT, function 0
Tab Move to next field, function 11
Backtab Move to previous field, function 12
Set Insert mode Insert Toggle, function 58

This means that when you press Enter on your keyboard, it terminates an ACCEPT operation, because Enter is mapped onto carriage return, and carriage return causes an ACCEPT operation to be terminated.

Note that because functions are mapped, you need to reference keys 11 and 12 in order to enable/disable respectively Adis keys 8 and 9 using the x"AF" call-by-number routine.

At this stage, the idea of mapping keys may seem an unnecessary complication. Where it becomes really useful is in the emulation of other dialects of COBOL. For example, in Microsoft COBOL V2.2, the Enter key moves to the next field rather than terminating an ACCEPT operation. This is easy to emulate by simply changing the mapping for key 2 (carriage return) from 0 (terminate ACCEPT) to 11 (move to next field). If you look at the function mappings screen in Adiscf for the Microsoft COBOL V2.2 compatibility configuration, you can see that this has been done.

The RM/COBOL V2.0 compatibility configuration contains even more changes to the default mappings to emulate the action of keys in RM/COBOL.

If a key is mapped on to a value of 255, that key does not perform any function during an ACCEPT operation.

Special Mappings

All of the standard functions described above always perform the same function, regardless of context. For example, the Move to next field function always attempts to move to the next field. However, there are some functions that behave differently depending on the context. These functions are described in the section Special Mapping Functions in chapter Keyboard Configuration Utility (Keybcf), but are summarized here:

Function Number
Function Name
55 RM clear field
56 RM Backspace
57 RM Tab
58 Insert toggle
59 Replace toggle
60 Forward Tab
61 Backward Tab
62 Restore

For example, the Set Insert mode key (key number 23) is normally mapped to function 58 (Insert toggle). This means that pressing the Insert key toggles between Insert and Replace mode.

Changing the Mappings From a Program

As well as changing the mappings through Adiscf, you can do this from an application program using the following call:

call x"AF" using    set-map-byte                    
adis-key-mapping

where set-map-byte and adis-key-mapping are defined in the Working-Storage Section of your program as follows:

 01 set-map-byte                pic 9(2) comp-x value 3.
 01 adis-key-mapping.
     03 adis-mapping-byte       pic 9(2) comp-x.
     03 adis-key-number         pic 9(2) comp-x.

where:

adis-mapping-byte should be set to the number of the function you wish the key to be mapped to
adis-key-number should be set to the number of the key you wish to change

Example

The following code changes the action of the Backspace key (key number 14) to simply move the cursor to the left (function 3), and changes the Tab key (key number 8) to perform the Tab function (function 8):

* Change mapping of Backspace key
     move 14 to adis-key-number
     move 3 to adis-mapping-byte
     call x"AF" using set-map-byte
                      adis-key-mapping
* Change mapping of the tab key
     move 8 to adis-key-number
     move 8 to adis-mapping-byte
     call x"AF" using set-map-byte
                      adis-key-mapping
Conflict With the x"B0" COBOL System Library Routine

The x"B0" COBOL system library routine is an alternative method of defining function keys. It is not supported under UNIX and some other environments. However, we recommend that you use the method of detecting function keys defined in this section rather than the x"B0" routine.

In general, you can use the x"B0" routine to define function keys which terminate an ACCEPT operation. However, there is one limitation. If you use x"B0", the carriage return key must be mapped on to the terminate ACCEPT function. This is the default for this product. If you change the mapping of carriage return or use a configuration that changes the mapping (such as Microsoft COBOL V2.2 or IBM COBOL 1.0 compatibility), then any key set up by the x"B0" call does not terminate the ACCEPT operation. Instead, it performs the function that carriage return has been mapped onto.

Enabling and Disabling the Adis Keys

By default, all of the Adis keys are enabled to perform their defined functions during an ACCEPT operation. However, it is possible to disable the keys or make them act as function keys instead. The call to do this is as follows:

 call x"AF" using   set-bit-pairs                    
adis-key-control

where set-bit-pairs and adis-key-control are defined in the Working-Storage Section of your program as follows:

 01 set-bit-pairs               pic 9(2) comp-x value 1.
 01 adis-key-control.
     03 adis-key-setting        pic 9(2) comp-x.
     03 filler                  pic x value "2".
     03 first-adis-key          pic 9(2) comp-x.
     03 number-of-adis-keys     pic 9(2) comp-x.

where:

adis-key-setting Defines the action of the keys affected, as follows:

0 The keys are disabled. If the key is pressed during an ACCEPT operation, the key is rejected.

1 The key acts like a function key. If pressed during an ACCEPT operation, the ACCEPT operation is terminated.

2 The key performs its normal action during an ACCEPT operation. This is the default.

3 The key performs its normal action unless it causes the cursor to leave the current field. If this happens, it behaves like a function key.
first-adis-key The number of the first key to be affected.
number-of-adis-keys The number of consecutive keys to be affected.

Detection of Adis Keys

If you have set up an Adis key to act as a function key, it terminates the ACCEPT operation and key-status is returned with the following values:

Data Item
Setting
key-type "2"
key-code-1 Set to the number of the pressed Adis key. This is the number of the key not the number of the function the key has been mapped to.
key-code-2 Undefined.

Example

The following code sets up Tab and Backtab to act as function keys and the <left-arrow> and <right-arrow> keys to act as function keys if they cause the cursor to leave the field.

* Set up Tab (key 8) and Backtab (Key 9) to act as function keys
     move 1 to adis-key-setting
     move 8 to first-adis-key
     move 2 to number-of-adis-keys
     call x"AF" using set-bit-pairs
                      adis-key-control
* Set up cursor-left (key 3) and cursor-right (key 4) to act as
* function keys ONLY if they cause the cursor to leave the field.
     move 3 to adis-key-setting
     move 3 to first-adis-key
     move 2 to number-of-adis-keys
     call x"AF" using set-bit-pairs
                      adis-key-control
     accept data-item at 0101
     if key-type = "2"
       evaluate key-code-1
         when 3
          display "cursor-left caused the cursor to
-          "leave the field"
         when 4
           display "cursor right caused the cursor to
-          "leave the field"
         when 8
          display "the tab key was pressed"
         when 9
          display "the back tab key was pressed"
       end-evaluate
     end-if.
4.2.9.2.5 Defining a Key in Both the User and Adis Key Lists

In general, a particular key is defined in either the user key list or the Adis key list, but not both. However, there is no reason why you should not define the same key in both lists. In fact, the default values in the compatibility list (set up for RM/COBOL V2.0 on UNIX compatibility) include the cursor keys which are also defined in the Adis key list.

If a key that is defined in both lists is pressed during an ACCEPT operation, the sequence of actions is as follows:

  1. Is the key defined in the user key list?

  2. If not, go to 5.

  3. Is the user key enabled?

  4. If it is, return "1" in key-type and the number of the key in key-code-1.

  5. Is the key defined in the Adis key list?

  6. If not, report to the user that the key is undefined.

  7. Perform the required action for the Adis key depending on whether it is disabled, enabled or to act as a function key.
4.2.9.2.6 Key Configuration on UNIX

UNIX:
On some UNIX terminals, you may find that some keys do not function as expected or do not function at all . This could be due to inconsistencies between the system terminfo database, the absolute control sequences generated by some keys and the default full screen ACCEPT/DISPLAY keys in this system (for example, change case of character).

You should first ensure that the appropriate terminal name is set in the TERM environment variable and that this gives access to a matching entry in either the COBOL or the system terminfo database. See the chapter Terminfo Database and Terminal Devices for more information on the search paths used.

You should then ensure that all the essential entries are present for the terminal in the terminfo database and that all the escape sequences match those generated by the appropriate terminal keys when in raw mode.

Some terminfo files might be supplied with this system. If so, they are in $COBDIR/terminfo. The Micro Focus Screen Handling Package, libscreen , searches for terminfo files in the following places in order, and stops searching as soon as it finds them:

  1. If set, $COBTERMINFO, or if not set $COBDIR/terminfo

  2. If set, $TERMINFO

  3. Default system terminfo database, /usr/lib/terminfo.

Solutions to some of the problems you may encounter are listed below:

Function Keys and COBKEYTIMEOUT (UNIX only)

UNIX:
On network based UNIX systems, information is split into packets, and thus under certain conditions it is possible for part of a function key sequence to be split across two packets. This can lead to incorrect key recognition. This typically occurs while using the telnet or the rlogin commands.

Your Micro Focus COBOL for UNIX system provides you with the COBKEYTIMEOUT environment variable, which you can use to determine the timeout between the arrival of the first key of a function or special key sequence and the arrival of the next. Setting this environment variable allows function key sequences to be recognized correctly. See the appendix Micro Focus Environment Variables in your Object COBOL User Guide for details on setting COBKEYTIMEOUT.

The timeout period, a value in the range 1 to 126, is dependent on the type of connection and the effective average baud rate. For example, ethernet connections should not require a value greater than 10. Using too small a value results in incorrect function and special key recognition; too large a value results in a delay when certain keys are pressed (such as Escape) unless they are followed by other keys (such as Escape).

If the value of the COBKEYTIMEOUT environment variable is outside the range 1 to 126, null, non-integer or the variable does not exist, then a direct connection between the terminal and the machine is assumed.

You could also use the COBKEYTIMEOUT environment variable to recognize function key sequences on terminals which do not send such sequences at the correct baud rate, but insert pauses between the characters instead.

This environment variable is read once only, when the screen handling subsystem is initialized. Changing its value after this has no effect.

4.2.9.3 Data Key Handling

The data keys are the 256 keys in the extended ASCII character set. Normally, when you press one of these keys during an ACCEPT operation, the character is simply put straight into the field. The exception to this is the keys with ASCII codes in the range 0 to 31, that is, the control keys. These are generally disabled.

4.2.9.3.1 Controlling the Data Keys

Like most other keys on the keyboard, it is possible to disable data keys or make them act like function keys, that is, terminate the ACCEPT operation. To do this, use the following call:

call x"AF" using    set-bit-pairs                    
data-key-control

where set-bit-pairs and data-key-control are defined in the Working-Storage Section of your program as follows:

 01 set-bit-pairs               pic 9(2) comp-x value 1.
 01 data-key-control.
    03 data-key-setting         pic 9(2) comp-x.
    03 filler                   pic x value "3".
    03 first-data-key           pic x.
    03 number-of-data-keys      pic 9(2) comp-x.

The fields in data-key-control should be set up as follows:

data-key-setting Defines the action of the keys affected, as follows:

0 The key is disabled. If it is pressed during an ACCEPT operation, the bell is rung and the key rejected.
1 The key acts as a function key. It terminates the ACCEPT operation.
2 The character is simply entered into the field. This is the default.
first-data-key The first character to be affected.
number-of-data-keys The number of characters to be affected.

4.2.9.3.2 Detecting Data Keys Set Up to Act as Function Keys

If a data key has been set up to act as a function key, it terminates the ACCEPT operation when pressed, and key-status is set up as follows:

Data Item
Setting
key-type "3"
key-code-1 Set to the ASCII code of the key that was pressed.
key-code-2 Undefined.

Example

* Set up the characters "A" through "Z" to terminate the
* ACCEPT operation
     move 1 to data-key-setting
     move "A" to first-data-key
     move 26 to number-of-data-keys
     call x"AF" using set-bit-pairs
                      data-key-control
     accept data-item at 0101
     if key-type = "3"
        evaluate key-code-1
          when 65
            display "A pressed"
          when 66
            display "B pressed"
          when 90
            display "Z pressed"
        end-evaluate
     end-if.

4.2.9.4 Shift Key Handling

Adis provides a number of routines to enable an applicaton to make use of the shift key capabilities of a keyboard. These routines are described in the following sections.

UNIX:
Most UNIX terminals cannot detect when the Alt or Ctrl keys are pressed unless they are pressed in conjunction with another valid key. You should, therefore, avoid using these keys by themselves in portable applications. Alternatively, the key sequences /a and /c can be used to simulate the use of Alt and Ctrl keys . See the appendix UNIX Key Usage Chart in the UNIX version of this manual for further details.

4.2.9.4.1 Determining Available Shift Keys

This routine enables you to find out which of the shift keys are detectable as unique events.

Use the following call to determine which shift keys are available to your program:

call x"AF" using    adis-function                    
adis-parameter

where adis-function and adis-parameter are defined in the Working-Storage Section of your program as follows:

 01 adis-function        pic 9(2) comp-x.
 01 adis-parameter       pic 9(4) comp-x.

where:

adis-function Must be 44.
adis-parameter Returns which shift keys are available to your program. The 16 bits in adis-parameter refer to shift keys as follows, with bit 0 the least significant:

Bit
Associated Key
4 - 15 Reserved
3 Alt
2 Ctrl
1 Left Shift
0 Right Shift

A value of 1 for any particular bit indicates that the associated key is uniquely detectable.

4.2.9.4.2 Detecting the Current State of the Shift Keys

This routine enables you to determine which, if any, of the shift keys are currently pressed.

Use the following call to determine which of the shift keys are currently pressed:

call x"AF" using    adis-function                    
adis-parameter

where adis-function and adis-parameter are defined in the Working-Storage Section of your program as follows:

 01 adis-function       pic 9(2) comp-x.
 01 adis-parameter      pic 9(4) comp-x.

where:

adis-function Must be 46.
adis-parameter Returns which of the shift keys are currently pressed. The 16 bits in adis-parameter refer to shift keys as follows, with bit 0 the least significant:

Bit
Associated Key
4 - 15 Reserved
3 Alt
2 Ctrl
1 Left Shift
0 Right Shift

A value of 1 for any particular bit indicates that the associated key is currently pressed.

4.2.9.4.3 Enabling or Disabling Shift Keys to Terminate an ACCEPT

By default, all of the shift keys are disabled during an ACCEPT operation, or the x"AF" call used to obtain a key. However, this routine enables you to enable or disable the shift keys dynamically.

Use the following call to enable or disable shift keys:

call x"AF" using    adis-function                    
adis-parameter

where adis-function and adis-parameter are defined in the Working-Storage Section of your program as follows:

  01 adis-function              pic 9(2) comp-x.
  01 adis-parameter.
     03 shift-key-setting       pic 9(2) comp-x.
     03 filler                  pic x value "4".
     03 first-shift-key         pic 9(2) comp-x.
     03 number-of-shift-keys    pic 9(2) comp-x.

where:

adis-function Must be 1.
shift-key-setting Defines the action of the keys affected, as follows:

0 The keys are disabled. If the key is pressed it will be ignored.

1 The keys are enabled.
first-shift-key The number of the first key to be affected. The events to enable are numbered as follows:

0 - Alt pressed
1 - Alt released
2 - Ctrl pressed
3 - Ctrl released
4 - Left Shift pressed
5 - Left Shift released
6 - Right Shift pressed
7 - Right Shift released

number-of-shift-keys The number of consecutive keys to be affected.

Example

The following code enables Ctrl so that it can terminate an ACCEPT operation, then checks to see whether an ACCEPT operation was terminated by Ctrl:

* Enable Ctrl
      move 1 to shift-key-setting
      move 2 to first-shift-key
      move 1 to number-of-shift-keys
      move 1 to adis-function
      call x"AF" using adis-function
                 adis-parameter
      accept data-item at 0101
      if key-type = "5"
          evaluate key-code-1
              when 2 
                  display "Ctrl pressed"
              when other
                  display "Other shift key pressed"
          end-evaluate 
      end-if.

4.2.9.5 Lock Key Handling

Adis provides a number of routines to enable an applicaton to make use of the lock key capabilities of a keyboard. These routines are described in the following sections.

4.2.9.5.1 Determining Available Lock Keys

This routine enables you to find out which of the lock keys are detectable as unique events.

Use the following call to determine which lock keys are available to your program:

call x"AF" using    adis-function                    
adis-parameter

where adis-function and adis-parameter are defined in the Working-Storage Section of your program as follows:

 01 adis-function       pic 9(2) comp-x.
 01 adis-parameter      pic 9(4) comp-x.

where:

adis-function Must be 45.
adis-parameter Returns which lock keys are available to your program. The 16 bits in adis-parameter refer to lock keys as follows, with bit 0 the least significant:

Bit
Associated Key
4 - 15 Reserved
3 Ins Lock
2 Caps Lock
1 Num Lock
0 Scroll Lock

A value of 1 for any particular bit indicates that the associated key is uniquely detectable.

4.2.9.5.2 Detecting the Current State of the Lock Keys

This routine enables you to determine which, if any, of the lock keys are currently active. For example, the Scroll Lock key is active when scroll lock is on.

Use the following call to determine which of the lock keys are currently active:

call x"AF" using    adis-function                    
adis-parameter

where adis-function and adis-parameter are defined in the Working-Storage Section of your program as follows:

 01 adis-function        pic 9(2) comp-x.
 01 adis-parameter       pic 9(4) comp-x.

where:

adis-function Must be 47
adis-parameter Returns which of the lock keys are currently active. The 16 bits in adis-parameter refer to lock keys as follows, with bit 0 the least significant:

Bit
Associated Key
4 - 15 Reserved
3 Ins Lock
2 Caps Lock
1 Num Lock
0 Scroll Lock

A value of 1 for any particular bit indicates that the associated key is currently active.

4.2.9.5.3 Enabling or Disabling Lock Keys to Terminate an ACCEPT

By default, all of the lock keys are disabled during an ACCEPT operation, or the x"AF" call used to obtain a key. However, this routine enables you to enable or disable the lock keys dynamically.

Use the following call to enable or disable lock keys:

call x"AF" using    adis-function
                    adis-parameter

where adis-function and adis-parameter are defined in the Working-Storage Section of your program as follows:

 01 adis-function             pic 9(2) comp-x.
 01 adis-parameter.
    03 lock-key-setting       pic 9(2) comp-x.
    03 filler                 pic x value "5".
    03 first-lock-key         pic 9(2) comp-x.
    03 number-of-lock-keys    pic 9(2) comp-x.

where:

adis-function Must be 1.
lock-key-setting Defines the action of the keys affected, as follows:

0 The keys are disabled. If the key is pressed it will be ignored.
1 The keys are enabled.

first-lock-key The number of the first key to be affected. The keys to enable are numbered as follows:

0 - Ins Lock
1 - Caps Lock
2 - Num Lock
3 - Scroll Lock
number-of-lock-keys The number of consecutive keys to be affected.

4.2.10 Get Single Character Routine

This routine enables you to get a single key from the keyboard. It uses Adis itself, so all of the function keys supported by Adis are supported. The routine only reads the keyboard and so does not echo the key to the screen.

The call used is:

call x"AF" using    get-single-char-func                    
key-status

where get-single-char-func and key-status are defined in the Working-Storage Section of your program as follows:

 01 get-single-char-func  pic 9(2) comp-x value 26.
 01 key-status.
     03 key-type          pic x.
     03 key-code.
         05 key-code-1    pic 9(2) comp-x.
         05 key-code-2    pic 9(2) comp-x.

The values returned in key-status are the same as those described previously, except that a value of "0" is never returned in key-type by this call. The carriage return key returns a value of "2" in key-type and a value of 2 in key-code-1.

The values returned in key-status are as follows:

key-type
key-code-1
"1" Returns the number of the user function pressed.
"2" Returns the number of the Adis key pressed. No mapping of keys occurs in this call. Therefore, the number returned is the number of the actual key pressed.
"3" Returns the ASCII code of the 8-bit data key pressed.
"4" Returns the first byte of the 16-bit data key pressed. The second byte is contained in key-code-2. This is only applicable on machines that support double-byte characters.
"5" The number of the shift key pressed.
"6" The number of the lock key pressed.
"9" Error condition. Values are:

8 Disabled character. The data key pressed is disabled.
9 Invalid keystroke. A function key has been pressed that is not defined in either the user or Adis function key list.

Example

      call x"AF" using get-single-char-func
                       key-status
      evaluate key-type
        when "1"
*         User function key pressed. Do required
*         action depending on value in key-code-1.
        when "2"
*         Adis function key pressed. Do required
*         action depending on value in key-code-1.
        when "3"
*          Data key pressed. Do required action
*          depending on the ASCII code in key-code-1.
        when "4"
*          Double byte data key pressed. Do required
*          action depending on the 16-bit character in
*          key-code.
         when "5" 
*          Shift key pressed/released. Do required action
*          depending on 
*          value in key-code-1 
       when "6" 
*          Lock key state changed. Do required action depending
*        on value in key-code-1 
       when "9"
*          Invalid or disabled key. Do required action.
      end-evaluate.

4.2.11 Sample Program

The following is an example of how to write programs that make use of function keys. It assumes that Escape is available, but any other function key can be selected either by pressing the function key or by pressing a slash (/) followed by the first letter of the option.

$set ans85
**************************************************
* This program assumes that the default 
* configuration has been selected using Adiscf.
***************************************************

 special-names.
     cursor is cursor-position
     crt status is key-status.
 data division.
 working-storage section. 
**************************************************
* Parameters to be used for the x"AF" calls.
**************************************************

 01 set-bit-pairs                        pic 9(2) comp-x value 1.
 01 get-single-character                 pic 9(2) comp-x value 26.

 01 enable-esc-and-f1.
    03 filler                            pic 9(2) comp-x value 1.
    03 filler                            pic x value "1".
    03 filler                            pic 9(2) comp-x value 0.
    03 filler                            pic 9(2) comp-x value 2.
 01 disable-all-other-user-keys.
    03 filler                            pic 9(2) comp-x value 0.
    03 filler                            pic x value "1".
    03 filler                            pic 9(2) comp-x value 2.
    03 filler                            pic 9(2) comp-x value 126.
 01 enable-slash-key.
    03 filler                            pic 9(2) comp-x value 1. 
    03 filler                            pic x value "3".
    03 filler                            pic x value "/".
    03 filler                            pic 9(2) comp-x value 1. 
**************************************************
* Status returned after termination of an ACCEPT.
**************************************************
 01 key-status.
    03 key-type                          pic x.
    03 key-code-1                        pic 9(2) comp-x.
    03 key-code-1-x                      redefines key-code-1 pic x.
    03 key-code-2                        pic 9(2) comp-x.

**************************************************
* Cursor-Position is returned by Adis containing 
* the position of the cursor when the ACCEPT was 
* terminated.
***************************************************
 01 cursor-position.
    03 cursor-row                        pic 99.
    03 cursor-column                     pic 99.

**************************************************
* Work areas used by the program.
************************************************** 
 01 work-areas.
    03 wa-name                           pic x(30).
    03 wa-address-line-1                 pic x(40).
    03 wa-address-line-2                 pic x(40).
    03 wa-address-line-3                 pic x(40).
    03 wa-address-line-4                 pic x(40).
    03 wa-age                            pic 999 value 0.

 01 exit-flag                            pic 9(2) comp-x value 0.
**************************************************
* Screen Section.
**************************************************
 screen section.

 01 main-screen.
    03 blank screen.
    03 line 2 column 27 
        value "Typical Data Entry Screen".
    03 line 3 column 27 
        value "-------------------------".
    03 line 5 column 1 value "name     [".
    03 pic x(30) using wa-name highlightprompt " ".
    03 value "]".
    03 line 7 column 1 value "address  [".
    03 pic x(40) using wa-address-line-1 highlight prompt " ".
    03 value "]".
    03 line 8 column 1 value "         [".
    03 pic x(40) using wa-address-line-2 highlight prompt " ".
    03 value "]".
    03 line 9 column 1 value "         [".
    03 pic x(40) using wa-address-line-3 highlight prompt " ".
    03 value "]".
    03 line 10 column 1 value "         [".
    03 pic x(40) using wa-address-line-4 highlight prompt " ".
    03 value "]".
    03 line 12 column 1 value "age      [".
    03 pic zz9 using wa-age highlight prompt " ".
    03 value "]".
    03 line 20 column 1 value
       "------------------------------------
-      "----------------------------------------".
    03 line 21 column 1 value "f1" highlight.
    03 value "=/help".
    03 column 75 value "esc" highlight.
    03 value "ape".
 01 help-screen.
    03 blank screen.
    03 line 1 column 34 value "help screen".
    03 line + 1 column 34 value "-----------".
    03 line 4 value "escape" highlight.
    03 value "     leave this program.".
    03 line 6 column 1 value "f1 or /h" highlight.
    03 value "   obtains this screen.".
    03 line 8 column 1 
        value "use cursor keys to move around ".
    03 value "the fields on the screen". 
    03 value "enter will".
    03 line + 1 column 1 value "accept the data ".
    03 value " present new blank form to fill in.".
    03 line 24 column 25 
        value "press any key to continue ...".
**************************************************
* Procedure Division.
**************************************************

 procedure division.
 entry-point section.

* First we want to ensure that the keys are enabled as we want
* them. Enable the Escape and F1 keys.

     call x"AF" using set-bit-pairs 
                      enable-esc-and-f1

* disable every other user function key. 
     call x"AF" using set-bit-pairs
                      disable-all-other-user-keys

* set up "/" key to act as a function key and terminate 
* the ACCEPT operation.

     call x"AF" using set-bit-pairs 
                      enable-slash-key

* Now ensure that the cursor position will be returned when an
* ACCEPT is terminated. Setting to row 1, column 1 will ensure
* that the cursor will be initially positioned at the start of 
* the first field.

     move 1 to cursor-row
     move 1 to cursor-column

* Loop until the Escape key is pressed.

     perform until exit-flag = 1
         display main-screen
         accept main-screen
         evaluate key-type
           when "0"
* The ACCEPT operation terminated normally; that is the Enter key
* was pressed. In this case, we simply blank out the work areas
* and restart in the first field.

             initialize work-areas
             move 1 to cursor-row
             move 1 to cursor-column
           when "1"

* A user function key has been pressed. This will either be
* Escape or F1 as all others have been disabled.

             if key-code-1 = 0
* Escape has been pressed, so we wish to leave the program.

                 move 1 to exit-flag
            else

* F1 has been pressed so display the help screen. 
                 perform display-help-screen
            end-if

           when "3"
* A data key has terminated the ACCEPT operation. It must be "/"
* as no other keys have been enabled to do this. Now get the 
* next character to see if "H" or "h" has been pressed.

             call x"AF" using get-single-character
                              key-status
             if key-type = "3" and
               (key-code-1-x = "h" or 
                key-code-1-x = "H")
                 perform display-help-screen
             end-if

         end-evaluate
     end-perform
     stop run.

display-help-screen section.

* Display the help screen and then wait for a key to be pressed.

     display help-screen
     call x"AF" using get-single-character
                      key-status.

4.2.12 Mouse Handling Via Adis

DOS, Windows and OS/2:
This section describes how to use a mouse with programs that use Adis to handle the screen and keyboard on DOS, Windows and OS/2 environments. It shows you how to activate the mouse, and use it in the Adis ACCEPT operation.

UNIX:
Mouse handling is not available in UNIX environments.

4.2.12.1 Using the Mouse

This section describes how to access the mouse for use in screen handling in this COBOL system. The mouse is not active by default, so the routines below must be called to allow the mouse to be used. The mouse is only available if the relevant mouse drivers, supplied with the mouse or the operating system, are installed.

Having the mouse pointer enabled during an Adis ACCEPT statement allows your user to alter the current input field by moving the mouse pointer over another field and pressing the left button on the mouse. This results in the text cursor being moved to the mouse pointer position.

The left button on the mouse is treated as Adis key number 27 and behaves in the same way as all other Adis keys. See the section Keyboard Handling Via Adis for details on using the Adis keys. The example at the end of this section shows how the action of the left button can be changed so the mouse can be used to terminate an ACCEPT operation.

Once the mouse is active (and enabled) the mouse cursor moves on the screen when the mouse is moved. This happens independently of any Adis operations. Adis takes notice of the mouse only when a mouse button is pressed. However, the program can determine the position of the mouse at any time using the appropriate routine described below.

4.2.12.2 Activating or Terminating Use of a Mouse

You control whether a mouse driver is in use or not as follows:

call x"AF" using use-mouse-function                 
usage-parameter

where use-mouse-function and usage-parameter are defined in the Working-Storage Section of your program as follows:

 01 use-mouse-function  pic 9(2) comp-x value 64.
 01 usage-parameter     pic 9(2) comp-x.

where usage-parameter should be set as follows:

0 Terminate mouse activity. The mouse pointer is deleted and no further mouse action is possible.
1
Activate the mouse. This activates the mouse driver and draws the mouse pointer.

On return from this call, use-mouse-function contains 255 if no mouse is present.

Example

The following code activates the mouse:

    move 1 to usage-parameter
    call x"AF" using   use-mouse-function
                       usage-parameter
4.2.12.2.1 Enabling or Disabling the Mouse

You disable or re-enable the mouse as follows:

 call x"AF" using  enable-mouse-function                   
enable-parameter

where enable-mouse-function and enable-parameter are defined in the Working-Storage Section of your program as follows:

 01 enable-mouse-function  pic 9(2) comp-x value 66.
 01 enable-parameter       pic 9(2) comp-x.

where enable-parameter should be set as follows:

0 Disables the mouse. The mouse pointer is hidden and all mouse movement and button presses are ignored until the mouse is reactivated.
1
Re-enables the mouse. This redraws the mouse pointer; that is, makes it visible, and re-enables the ability to detect mouse movement and button presses.

Example

The following code disables the mouse:

     move 0 to enable-parameter
     call x"AF" using enable-mouse-function
                      enable-parameter
4.2.12.2.2 Enabling the Right-hand Mouse Button

By default, enabling the mouse enables the left mouse button. However, you can enable the right mouse button as follows:

call x"AF" using set-bit-pairs                  
mouse-control 

where set-bit-pairs and mouse-control are defined in the Working-Storage Section of your program as follows:

 01 set-bit-pairs                pic x comp-x value 1.
 01 mouse-control.
     03 mouse-control-setting    pic x comp-x value 2.
     03 filler                   pic 9 value "7".
     03 mouse-control-bitpair    pic x comp-x value 5.
     03 mouse-control-count      pic x comp-x value 1.
4.2.12.2.3 Returning Mouse Status and Position

You query the position of the mouse pointer and the status of the mouse driver as follows:

call x"AF" using    get-mouse-details                    
mouse-details

where get-mouse-details and mouse-details are defined in the Working-Storage Section of your program as follows:

 01 get-mouse-details            pic 9(2) comp-x value 67.
 01 mouse-details.
     03 mouse-x-position         pic 9(4) comp-x.
     03 mouse-y-position         pic 9(4) comp-x.
     03 mouse-status             pic 9(4) comp-x.

where the bytes returned in mouse-status have the following meanings:

Bit Value Meaning
0 1 Mouse moved.
1 2 Button 1 pressed.
2 4 Button 2 pressed.
3 8+ Button 3 pressed.

Example

The following code displays the mouse pointer position:

     call x"AF" using get-mouse-details
                      mouse-details
     display "mouse-x-position is " at line 1 column 1
     display mouse-x-position at line 1 column 22
     display "mouse-y-position is " at line 2 column 1
     display mouse-y-position at line 2 column 22

4.2.12.3 Example of Using a Mouse

The following code sets up the mouse to act as a function key. Pressing the left mouse button terminates the ACCEPT operation and causes the the mouse coordinates to be displayed. The data items are as defined in the section Enabling or Disabling the Adis Keys and in the details of the routines above.

 special-names.
     crt status is key-status.

 working-storage section.
 01  key-status.
     03  key-type            pic x.
     03  key-code-1          pic 99   comp-x.
     03  key-code-2          pic 99   comp-x.

 01  data-item               pic x(10).
 01  set-bit-pairs           pic 99   comp-x value 1.
 01  adis-key-control.
     03  adis-key-setting    pic 99   comp-x.
     03  filler              pic x    value "2".
     03  first-adis-key      pic 99   comp-x.
     03  number-of-adis-keys pic 99   comp-x.
 01  get-mouse-details       pic 99   comp-x value 67.
 01  mouse-details.
     03  mouse-x-position    pic 9(4) comp-x.
     03  mouse-y-position    pic 9(4) comp-x.
     03  mouse-status        pic 9(4) comp-x.
 01  enable-mouse-function   pic 99   comp-x value 66.
 01  enable-parameter        pic 99   comp-x value 1.
 01  use-mouse-function      pic 99   comp-x value 64.
 01  usage-parameter         pic 99   comp-x.
 01  mouse-handle            pic x(4) comp-x.
 01  mouse-buttons           pic x(2) comp-x.
 procedure division.
 activate-mouse.
     move 1 to usage-parameter
     call x"AF" using use-mouse-function
                      usage-parameter
     if use-mouse-function = 255
         display "Mouse not present"
         stop run
     end-if
     .
 enable-mouse.
     call x"AF" using enable-mouse-function
                      enable-parameter
     .
 mouse-as-pfkey.
     move 3 to adis-key-setting
     move 27 to first-adis-key
     move 1 to number-of-adis-keys
     call x"AF" using set-bit-pairs
                      adis-key-control
     accept data-item at 0101
     if key-type = "2" and key-code-1 = 27
         display "Mouse terminated accept"
         call x"AF" using get-mouse-details
                          mouse-details
         display "mouse x-pos: "  at line 3 column  1
         display mouse-x-position at line 3 column 22
         display "mouse y-pos: "  at line 4 column  1
         display mouse-y-position at line 4 column 22
     end-if
     .
 terminate-mouse.
     move 0 to usage-parameter
     call X"AF" using use-mouse-function
                      usage-parameter
     stop run.


Copyright © 1999 MERANT International Limited. All rights reserved.
This document and the proprietary marks and names used herein are protected by international law.

PreviousLow-level Routines for Character Interfaces Adis Configuration Utility (Adiscf)Next"