![]() | Comparison of Methods for Creating User Interfaces | Low-level Routines for Character Interfaces | ![]() |
This chapter introduces you to specialized features in COBOL that make it easy for you to create sophisticated and user-friendly character user interfaces for your applications.
The available methods are:
Also, there is the ability to customize the behavior of ACCEPT and DISPLAY statements or modify a key on the keyboard
At the end of this chapter, there is a discussion of another Micro Focus product that enables you to create and manipulate user interfaces rapidly. This product is called Dialog System; it allows you to change your user's interface without changing the processing in your application. Dialog System also enables you to create and run user interfaces without having to write a program to drive them.
There are two types of ACCEPT and DISPLAY statements in COBOL: ANSI ACCEPT and DISPLAY and Micro Focus enhanced ACCEPT/DISPLAY. The enhanced ACCEPT/DISPLAY uses a run-time component called Adis.
Adis provides many enhancements and extensions over standard ANSI ACCEPT and DISPLAY statements. For instance, Adis provides screen positioning with ACCEPT and DISPLAY statements and performs formatting on numeric fields when accepting numeric data items.
The simplest form of an ACCEPT or DISPLAY statement is called an ANSI ACCEPT or DISPLAY. This statement meets the ANSI'85 requirements for an ACCEPT or DISPLAY statement and is very limited in scope.
For ACCEPT, there are two formats:
The following example shows typical use of ANSI ACCEPT and DISPLAY. Notice there is no facility for screen positioning of the data fields.
The following code is an example of the use of ANSI ACCEPT and DISPLAY operations.
working-storage section. 01 into-field pic x(10). procedure division. display "Enter data to be accepted" accept into-field display "The data you entered was " into-field stop run.
This is, of course, a very simple example, and does not show every feature of the ANSI ACCEPT and DISPLAY.
For screen handling potential, however, there is nothing else to show. The ANSI ACCEPT and DISPLAY is essentially a line mode feature. The programmer has no control over screen positioning - the data to be displayed and accepted is positioned at the current cursor position.
The Micro Focus Enhanced ACCEPT/DISPLAY facility contains extensive enhancements to the ANSI ACCEPT and DISPLAY base.
The example program below, smplaccp.cbl, illustrates some of the most commonly used features offered by the Micro Focus Enhanced ACCEPT/DISPLAY facility.
Micro Focus Enhanced ACCEPT/DISPLAY:
1$set ans85 noosvs mf 2 3********************************************************** 4* Copyright MERANT International 2000. All Rights * 5* Reserved. This demonstration program is provided for * 6* use by users of MERANT products and may be used, * 7* modified and distributed as part of your application * 8* provided that you properly acknowledge the copyright * 9* of MERANT in this material. * 10********************************************************** 11 12********************************************************** 13* SMPLACCP.CBL * 14* * 15* This program demonstrates some simple screen handling * 16* extensions. It uses DISPLAY and ACCEPT statements to * 17* show how you could achieve password masking and * 18* reverse-video. * 19* * 20********************************************************** 21 special-names. 22 console is crt. 23 24 working-storage section 25 01 into-field pic x(10). 26 01 pass-word pic x(08). 27 28 procedure division 29 display spaces upon crt. 30 display "Please enter your password" at 0310 upon 31 crt with underline. 32 accept pass-word at 0338 with no-echo. 33 display "Enter data to be accepted" at 0510. 34 accept into-field at 0538 with 35 reverse-video 36 blink. 37 display "The data you entered was =>" at 0710. 38 display into-field at 0738. 39 40 stop run.
The first line in the Procedure Division is DISPLAY SPACES UPON CRT. This statement is a Micro Focus Enhanced ACCEPT/DISPLAY to clear the screen.
The next two verbs (lines 30 through 32) show a common technique for having a user enter a password. The UPON CRT WITH UNDERLINE clause on the DISPLAY statement causes the literal to be underlined (on a monochrome terminal) or highlighted (on a color terminal). The WITH NO-ECHO clause on the ACCEPT statement prevents the user's response from being seen on the screen.
Also illustrated on these two lines, and in every ACCEPT and DISPLAY in the program, is the ability to position literals and variables (and the cursor) anywhere on the screen. For instance, AT 0310 means "At line 3 and column 10 on the CRT".
The ACCEPT INTO-FIELD statement (line 34) includes the phrases REVERSE-VIDEO and BLINK. These phrases state that the field where data is entered is in reverse video, and the data blinks when typed in.
This program gives an good idea of the control you have over a screen you design with COBOL.
Note: The use of Screen Section (a COBOL extension) provides more extensive screen control capabilities than ACCEPT and DISPLAY statements. You can find more information in the section Using the Screen Section and in your Language Reference.
If you are using the Micro Focus Enhanced ACCEPT/DISPLAY facility, you must be sure that certain submodules can be accessed at run time. These modules are called Adis modules (this is why the term "Adis" is sometimes used interchangeably with "Micro Focus Enhanced ACCEPT/DISPLAY").
This table shows how to determine if an ACCEPT or DISPLAY statement is ANSI or Micro Focus.
The general rule is, if the Special-Names paragraph is not present, then:
and if SPECIAL-NAMES. CONSOLE IS CRT is present, then:
This information can be useful both in debugging an existing application, or in creating a new application where you want to be sure if you are using ANSI or Micro Focus Enhanced ACCEPT/DISPLAY statements.
In the following table, a Micro Focus ACCEPT or DISPLAY statement is denoted by MF; an ANSI statement is denoted by ANSI.
Statement | Is Special-Names. CONSOLE IS CRT. coded in program? | Type |
---|---|---|
ACCEPT identifier | Yes No |
MF ANSI |
ACCEPT identifier FROM CONSOLE | Yes No |
ANSI ANSI |
ACCEPT identifier FROM CRT | Yes No |
MF MF |
ACCEPT identifier AT location | Yes No |
MF MF |
If the identifier is a Screen Section item, ACCEPT identifier is automatically a Micro Focus ACCEPT statement.
The use of any Micro Focus extensions (such as AT, UPON CRT-UNDER, WITH REVERSE-VIDEO, and so on) causes the ACCEPT statement to be treated as a Micro Focus ACCEPT statement.
This section illustrates the basic methods for function key handling in COBOL.
Note: Function-key handling might be restricted by hardware characteristics or the terminfo entry for the terminal type you are using; for example, on some systems you cannot handle F9, F10 and shifted function keys.
The basic process in function key handling with COBOL is to:
The following example program accepts and identifies a function key:
1$set noosvs mf ans85 2********************************************************** 3* Copyright MERANT International 2000. All Rights * 4* Reserved. This demonstration program is provided for * 5* use by users of MERANT products and may be used, * 6* modified and distributed as part of your application * 8* provided that you properly acknowledge the copyright * 9* of MERANT in this material. * 9********************************************************** 10 11********************************************************** 12* * 13* FUNKEY.CBL * 14* * 15* This program demonstrates how to decode function * 16* keys using the x"af" call. * 17* * 18********************************************************** 19 special-names. 20 crt status is key-status. 21 22 working-storage section. 23 01 flag pic 9(2) comp-x value 1. 24 01 user-key-control. 25 05 enable-fn-keys pic 9(2) comp-x value 1. 26 05 filler pic x value "1". 27 05 first-user-key pic 9(2) comp-x value 1. 28 05 number-of-keys pic 9(2) comp-x value 10. 29 30 01 key-status. 31 05 key-type pic x. 32 05 key-code-1 pic 9(2) comp-x. 33 05 filler pic x. 34 01 any-data pic x. 35 01 key-code-1-display pic z9. 36 37 procedure division. 38 perform enable-keys 39 perform accept-function-key 40 perform tell-which-key-was-pressed 41 perform stop-run. 42 43 enable-keys. 44 call x"af" using flag user-key-control. 45 46 accept-function-key. 47 display spaces upon crt 48 display "Press a function key: F1 to F10" at 0505 49 accept any-data at 0540. 50 51 tell-which-key-was-pressed. 52 evaluate key-type 53 when 0 display "You pressed <Enter>" at 0705 54 when 1 55 move key-code-1 to key-code-1-display 56 display "You pressed function key" at 0705 57 display key-code-1-display at 0730 58 end-evaluate. 59 60 stop-run. 61 stop run.
This program is discussed below.
Lines 19-20:
special-names crt status is key-status.
The Special-Names paragraph contains one clause: CRT STATUS IS
KEY-STATUS. The presence of this clause causes the system to update the
associated data item after every Micro Focus ACCEPT operation with
information as to which keystroke ended the ACCEPT operation. For our
purposes, key-status
contains the data that tells you which
function key was pressed.
Lines 23-28:
01 flag pic 9(2) comp-x value 1. 01 user-key-control. 05 enable-fn-keys pic 9(2) comp-x value 1. 05 filler pic x value "1". 05 first-user-key pic 9(2) comp-x value 1. 05 number-of-keys pic 9(2) comp-x value 10.
The first two items defined in the Working-Storage Section are flag
and user-key-control
. These two items are parameters to the
x"AF" routine, which turns function key handling on. (There is a
configuration option to do this permanently; for more details, see the
section Customizing Your ACCEPT/DISPLAY Environment
in this chapter.)
The flag
data item must always be equal to 1 when using x"AF"
for function key handling.
The data item user-key-control
is a four-byte group item.
The first byte, enable-fn-keys
, should be set to 1 for
enabling function keys, and to zero for disabling them.
Since we are enabling the keys here, it is set to 1.
The following elementary item is a FILLER item that must be set to 1.
The next two elementary items are first-user-key
and
number-of-keys
. As their data-names indicate, they contain
values for the first key to be enabled, and the number of keys to be
enabled. The values given for these keys are the user function key numbers
supplied with your COBOL system. For a quick reference of user function
key numbers mapped onto actual keys, see the chapter
Adis.
Lines 30-33:
01 key-status. 05 key-type pic x. 05 key-code-1 pic 9(2) comp-x. 05 filler pic x.
The key-status
group item (referred to by the CRT STATUS
clause in the Special Names paragraph) contains information about the type
of key that terminated the ACCEPT operation.
The first elementary item in this group item is key-type
.
If this value is 1, a function key was pressed. If key-type
is equal to 0, Enter was pressed.
The second elementary item is key-code-1
. If key-type
is 1, key-code-1
tells you which function key was pressed.
The next elementary item is a one-byte FILLER item. It has no function in your program, but must be in place.
Lines 34-35:
01 any-data pic x. 01 key-code-1-display pic z9.
The any-data
data item is a PIC X field that is accepted
into the program. This data item is not used afterward, because the
purpose of the program is to determine the function key pressed, which it
does through key-type
and key-code-1
.
The key-code-1-display
data item is a display field for
the function key.
Line 37:
procedure division.
The structure of the program can be seen from the PERFORM statements on lines 38 through 41. First, the function keys are enabled. Second, a function key is accepted. Third, the user is told which key was pressed; and fourth, the program is terminated.
Lines 43-44:
enable-keys. call x"af" using flag user-key-control
Function keys must always be enabled before they can be used in a program compiled with COBOL. They are enabled using a call to the x"AF" routine (or through Adiscf, as is described in the section Customizing Your ACCEPT/DISPLAY Environment later in this chapter).
The x"AF" routine gives you very fine control over your ACCEPT and DISPLAY options, but the use of x"AF" we discuss here is the enabling and disabling of function keys.
Note the parameters that are passed: flag
and user-key-control
.
All values for these parameters were established through VALUE clauses in
the Data Division.
However, if later calls to x"AF" are to be made, the parameter fields should be refreshed, as their values can be changed by the call under certain circumstances.
Lines 46-49:
accept-function-key. display spaces upon crt display "Press a function key: F1 to F10" at 0505 accept any-data at 0540.
The first statement in the accept-function-key
paragraph
is to clear the screen: display spaces upon crt
.
Following that, the user is asked to press a function key, and the
function is accepted into the crt-status
field. Any data
keyed in addition to the function key is accepted into the any-data
item.
The ACCEPT operation is not terminated until the user presses either a function key or Enter.
Lines 51-58:
tell-which-key-was-pressed. evaluate key-type when 0 display "You pressed <Enter>" at 0705 when 1 move key-code-1 to key-code-1-display display "You pressed function key" at 0705 display key-code-1-display at 0730 end-evaluate.
In this paragraph, the user is told which function key was pressed. If
key-type
is 0, the user is informed that Enter was
pressed, rather than a function key. If key-type
is 1, the
user is told which function key was pressed.
First, key-code-1
must be moved to key-code-1-display
,
to enable it to be displayed.
In a typical application, of course, you would probably perform an
EVALUATE on key-code-1
and perform the appropriate action in
your program, rather than simply telling the user which key was pressed.
The Screen Section is a collection of screen definitions; each definition describes the layout of a screen. The Screen Section is part of the Data Division.
data division. file section. ... working-storage section. ... screen section. 01 screen-1. ... 01 screen-2. ... procedure division.
There are many callable subroutines supplied with COBOL that provide sophisticated screen handling capabilities. These routines are called video I/O routines.
The capabilities of the video I/O routines include the ability to read and write characters and attributes, to scroll or clear the screen, manipulate the cursor, and perform other related functions.
This section gives an example of how to write screen attributes. It uses the following routines:
Note: Certain attributes (such as underline, reverse video and blink), the ability to turn off the cursor, and the sounding of the audible alarm are all dependent on the hardware and operating system, and might not be available on your system.
The following example, popup.cbl, shows you how to implement a pick-and-point menu system and construct popup panels.
1$set ans85 noosvs mf 2 3********************************************************* 4* Copyright MERANT International 2000. All Rights * 5* Reserved. This demonstration program is provided for * 6* use by users of MERANT products and may be used, * 7* modified and distributed as part of your application * 8* provided that you properly acknowledge the copyright * 9* of MERANT in this material. * 10********************************************************* 11 12********************************************************* 13* * 14* POPUP.CBL * 15* * 16* * 17* This program illustrates how to simulate POPUP MENUS * 18* * 19* Internal calls used by this program: * 20* * 21* x"af" - Used to detect the use of cursor * 22* keys. * 23* * 24* x"e5" - Used to sound the audible alarm. * 25* * 26* CBL_READ_SCR_CHATTRS - Used to read the characters * 27* and attributes on the screen. * 28* * 29* CBL_WRITE_SCR_CHATTRS- Used to write the characters * 30* and attributes on the screen. * 31* * 32* CBL_WRITE_SCR_ATTRS - Used to set the characters * 33* on the screen. * 34* * 35* CBL_SET_CSR_POS - Used to turn the cursor off. * 36* * 37* * 38********************************************************* 39 40 working-storage section. 41 01 screen-position.
42 05 screen-row pic 9(2) comp-x value 05. 43 05 screen-col pic 9(2) comp-x value 15. 44 01 string-length pic 9(4) comp-x value 15. 45 46 01 top-row pic 9(2) comp-x value 05. 47 01 bottom-row pic 9(2) comp-x value 14. 48 49 01 reverse-vid pic x(15) value all x"70". 50 01 black-and-white pic x(15) value all x"07". 51 52 01 screen-origin pic 9(4) comp-x value 0. 53 01 screen-buffer pic x(2000). 54 01 screen-attrs pic x(2000). 55 01 screen-string-length pic 9(4) comp-x value 2000. 56 57 01 get-single-char pic 9(2) comp-x value 26. 58 01 key-status. 59 05 key-type pic x. 60 05 key-code-1 pic 9(2) comp-x. 61 05 key-code-2 pic 9(2) comp-x. 62 63 01 set-bit-pairs pic 9(2) comp-x value 1. 64 01 user-key-control. 65 05 user-key-setting pic 9(2) comp-x value 1. 66 05 filler pic x value "1". 67 05 first-user-key pic 9(2) comp-x value 1. 68 05 number-of-keys pic 9(2) comp-x value 4. 69 70 78 user-fn-key value "1". 71 78 adis-fn-key value "2". 72 73 78 f1-key value 1. 74 78 f2-key value 2. 75 78 f3-key value 3. 76 78 f4-key value 4. 77 78 78 carriage-return value 0. 79 78 up-arrow value 5. 80 78 down-arrow value 6. 81 82 01 cursor-off-screen. 83 05 row-number pic 99 comp-x value 255. 84 05 col-number pic 99 comp-x value 255. 85 86 87 screen section. 88 01 g-picscrn. 89 05 blank screen.
90 05 line 6 col 16 value "Option one". 91 05 line 9 col 16 value "Option two". 92 05 line 12 col 16 value "Option three". 93 05 line 15 col 16 value "Option four". 94 05 line 21 col 10 value "F1=Help F2=Window1 95-" F3=Window3 F4=Clear windows". 96 05 line 22 col 10 value "Use or to point to an 97-"item, and <Enter> to Terminate.". 98 99 01 hilite3-00 highlight. 100 05 line 06 col 37 value "+----------------------+". 101 05 line 07 col 37 value "|this is popup menu #1 |". 102 05 line 08 col 37 value "| |". 103 05 line 09 col 37 value "|this menu could be |". 104 05 line 10 col 37 value "|your help menus |". 105 05 line 11 col 37 value "| |". 106 05 line 12 col 37 value "|It was brought up with|". 107 05 line 13 col 37 value "|F1. |". 108 05 line 14 col 37 value "+----------------------+". 109 05 line 15 col 37 value " ". 110 111 01 hilite4-00 reverse-video. 112 05 col 1. 113 05 line 04 value "+-----------------------+". 114 05 line 05 value "|this is popup menu #2 |". 115 05 line 06 value "| |". 116 05 line 07 value "|notice that the menus |". 117 05 line 08 value "|can overlay one another|". 118 05 line 09 value "| |". 119 05 line 10 value "|the attribute you use |". 120 05 line 11 value "|is determined in the |". 121 05 line 12 value "|screen section |". 122 05 line 13 value "| |". 123 05 line 14 value "|this screen is turned |". 124 05 line 15 value "|on by F2 |". 125 05 line 16 value "+-----------------------+". 126 127 01 hilite5-00 . 128 05 line 13 value "+-----------------------------+". 129 05 line 14 value "|This screen is popup menu 3 |". 130 05 line 15 value "| |". 131 05 line 16 value "|Take turns in pressing F1, F2|". 132 05 line 17 value "|F3 and F4 in any order. |". 133 05 line 18 value "|You can overlay any menus. |". 134 05 line 19 value "|F4 will clear to the |". 135 05 line 20 value "|original menu. |". 136 05 line 21 value "|function key #3 pops up |". 137 05 line 22 value "|this screen. |".
138 05 line 23 value "+-----------------------------+". 139 140 procedure division. 141 main-line. 142 perform start-up 143 perform which-key-loop 144 until key-type = adis-fn-key 145 and key-code-1 = carriage-return 146 stop run. 147 148 start-up. 149* Display user screen 150 display g-picscrn 151 152* Move cursor off screen 153 call "CBL_SET_CSR_POS" using cursor-off-screen 154 155* Read the current screen for later re-display 156 call "CBL_READ_SCR_CHATTRS" using screen-origin 157 screen-buffer 158 screen-attrs 159 screen-string-length 160* Display first block 161 perform mark-block 162 163* Enable function keys 164 call x"af" using set-bit-pairs 165 user-key-control 166 . 167 168 169 which-key-loop. 170 call x"af" using get-single-char 171 key-status 172 evaluate key-type 173 when user-fn-key 174 evaluate key-code-1 175 when f1-key display hilite3-00 176 when f2-key display hilite4-00 177 when f3-key display hilite5-00 178 when f4-key perform clear-pop-up 179 when other call x"e5" 180 end-evaluate 181 when adis-fn-key 182 evaluate key-code-1 183 when up-arrow perform move-block-up 184 when down-arrow perform move-block-down 185 when other call x"e5"
186 end-evaluate 187 end-evaluate. 188 189 pop-up-help. 190 191 pop-up-story1. 192 193 pop-up-story2. 194 195 clear-pop-up. 196* recover the original screen * 197 call "CBL_WRITE_SCR_CHATTRS" using screen-origin 198 screen-buffer 199 screen-attrs 200 screen-string-length 201 perform mark-block. 202 203 move-block-up. 204 perform clear-block 205 if screen-row top-row 206 subtract 3 from screen-row 207 else 208 move bottom-row to screen-row 209 end-if 210 perform mark-block. 211 212 move-block-down. 213 perform clear-block 214 if screen-row bottom-row 215 add 3 to screen-row 216 else 217 move top-row to screen-row 218 end-if 219 perform mark-block. 220 221 clear-block. 222 call "CBL_WRITE_SCR_ATTRS" using screen-position 223 black-and-white 224 string-length. 225 226 227 mark-block. 228 call "CBL_WRITE_SCR_ATTRS" using screen-position 229 reverse-vid 230 string-length.
The Working-Storage Section in popup.cbl is mostly parameters for video I/O routine calls, values returned from these calls, or parameters to and from other COBOL system library routines.
The Screen Section contains the user screens and panels that can appear during execution of the program.
In the start-up
paragraph, the following actions take
place:
g-picscrn
. The which-key-loop
is the main processing loop of the
program. This loop is performed until Enter is pressed to end the
program.
The popup menus are displayed if the user presses a user function key.
This is shown in the EVALUATE statement in which-key-loop
.
The video I/O routine CBL_READ_SCR_CHATTRS is used to save the initial
screen. In clear-pop-up
, the screen is redisplayed.
The video I/O routine CBL_WRITE_SCR_ATTRS is used in the clear-block
and mark-block
paragraphs to change the block designated by
the cursor position either to reverse video or black and white.
There is a configuration file for your Micro Focus Enhanced ACCEPT/DISPLAY facility. It is called ADISCTRL.
ADISCTRL is essentially a database that specifies the editing functions to be used by the Adis function keys. It is a file containing several possible configuration options, one of which you choose.
By editing this file using the Adis Configuration utility, you change the behavior of Adis, customizing it to your needs.
Adis was introduced briefly in the introduction to the section Using ACCEPT and DISPLAY earlier in this chapter. Here, Adis is described in more detail.
The term Adis refers to the component of COBOL that handles extended (that is, non-ANSI) ACCEPT and DISPLAY processing.
Adis needs to know about machine-independent information such as:
All of this information is stored in a modifiable file called ADISCTRL.
When Adis is executed, it reads this information from ADISCTRL, if an ADISCTRL file is present. ADISCTRL does not have to be present; the default values are available without ADISCTRL.
There are several reasons you might want to modify ADISCTRL:
You modify ADISCTRL through the Adis Configuration utility. You can invoke this utility directly from the command line.
When ADISCTRL is modified to change your Adis environment, you need to ensure that the modified copy is available to COBOL at run time. When you are testing, therefore, you need to have the modified copy either in your current directory or in a directory specified by the COBDIR environment variable.
When you hand the system over to your users, the same consideration applies: make sure they receive the modified ADISCTRL with the product you send.
You also can change the values of keys on your keyboard using the Keyboard Configuration utility.
For example, you can make your COBOL system treat F10 like Enter.
This is a much less commonly used feature, but you should know it is available.
When you run the Keyboard Configuration utility, there is a file that is created and maintained called cobkeymp. This is a control file containing the scan codes for the keys on your keyboard. Unlike ADISCTRL, cobkeymp is only created if the Keyboard Configuration utility is run.
The same considerations apply here as with ADISCTRL. That is, if you want a modified keyboard configuration for your users, you must ensure that the modified cobkeymp file is included with the product you provide. At run time, cobkeymp must either be in the current directory or the COBOL system directory.
If you run the example, simply delete cobkeymp at the end to restore your keys to their current values.
Character Dialog System is user interface management technology that provides portable user interface solutions across a variety of character-based operating environments. For detailed information on Character Dialog System, see your Dialog System Character Mode User's Guide.
Dialog System is a development and execution system that enables separation of the user interface from the underlying business application logic. Dialog System also supports multiple interfaces on the same business logic resulting in user interfaces that are flexible and able to change according to the needs of the people who use them.
When you need to change the user interface, Dialog System enables you to modify and test your changes without impacting the application code. This lets you change the look and feel of an application, without the risk of introducing errors to the application program.
Using Dialog System, changes can be made to the user interface independent of the underlying program code. This can result in a reduction of up to 70% in the amount of code in a typical business application.
Copyright © 2000 MERANT International Limited. All rights reserved.
This document and the proprietary marks and names
used herein are protected by international law.
![]() | Comparison of Methods for Creating User Interfaces | Low-level Routines for Character Interfaces | ![]() |