Running the Demonstration Programs [ Micro Focus COBOL for UNIX COBOL User Guide ] MPE/iX 5.0 Documentation
Micro Focus COBOL for UNIX COBOL User Guide
Running the Demonstration Programs
Compile the programs listed above in the usual way with this COBOL system
and move the resulting executable files to an area where users on two
terminals can access them. You must also make sure that both users are
accessing the same file. Invoke the multi-user demonstration programs on
both terminals. Both screens display the initial screen as shown in
Figure 6-2 .
Figure 6-2. Initial Screen of mudemo
When the initial screen is displayed, the user must choose the access and
lock mode by pressing the number associated with the required mode,
followed by Enter. When the user has chosen, the relevant subprogram is
called by the main program mudemo, and another screen is displayed. This
screen shows a stock control system with stock code, stock description,
stock held and cost per unit. The bottom of the screen shows the open
and lock modes, what the last operation was and whether it was
successful, and the file status. Again, there is a choice of operations
the user might want to perform.
Creating the file
The first thing you must do to set up the multi-user environment is to
create a data file that the two users can share. One user must create
this file by selecting input choice 4 to open the file for output.
Figure 6-3. Screen to Create a New Record
When the screen shown in Figure 6-3 is displayed, this user should
enter data in the stock code, stock description, stock held and cost per
unit fields using the Tab key to move forward from field to field.
When this user has entered data into these fields, the data can be
written into the data file mustock.dat by writing the record. To do
this, select option 1 (write record) and press Enter. We suggest that
this user should write five or six records in this way and then close the
file by exiting (selecting option 2).
While the first user is doing this, the second user can try to access the
data file mustock.dat, but the second user will fail to gain access to
this file at all. This is because opening a file for output locks the
file exclusively. The second user will receive a "file locked" status.
Now that the users have a data file they can share you can have them both
accessing the data file mustock.dat at the same time.
Sharing the file
If user one selects 2, for I-O Lock Mode Automatic at the initial screen,
the new screen is displayed as shown in Figure 6-4 . To access the
first record, the user must move down to the Input Choice field by
pressing End twice. Now press 2 to read the next record. The first
record in mustock.dat is displayed.
Figure 6-4. Preparing to Read the Next Record
The first record in the data file mustock.dat is now locked by user one,
and remains so until this user next accesses the file. User two can
access any other record in the file by also selecting to open the file
for I-O Lock Mode Automatic or for Input, for example. User two can
execute a "start not less than", thus avoiding the first record in the
file that is locked to user one.
User two can access the first record, but receives a file status of
"Record locked" and the access is unsuccessful. However, the data will
be returned unless the operating system does not support this.
Try the various combinations of locking and access for yourself so that
you become familiar with the way this COBOL system can lock data.
MPE/iX 5.0 Documentation