4.3. INTRODUCTION TO IBM / CMS

4.3.1. STARTING UP CMS

4.3.1.1. VM/SP CONCEPT

The following diagram illustrates the major operating system components of the 4381-R23 mainframe computer called Max.

Some further explanations:

VM/SP The operating system that Max runs. Its philosophy is that each user will have his own virtual machine.

CP The control program is run by VM/SP to manage system resources and the creation of virtual machines.

CMS Conversation Monitor System. The operating system that the virtual machine runs (this is the one that we use but there are others available).

Virtual Machine 370 on IBM is a design which treats the users as if each user has their own computer, a virtual machine.

`

CP (Control Program) manages the virtual devices. For example, when you send a file to your printer, CP routes the output to one of the system printers. Your console is in reality the terminal you use when you log on. Your mini disk is the segment of secondary storage allocated to your account. The reader is your input device; when another user sends you a message (referred to as a note), it is placed in your reader. Notes are discussed in Section 7 of this document.

CMS (Conversational Monitor System) allows you to manipulate files and access your reader.

4.3.1.2. LOGGING ON

STEP 1: inform the data switch that you want "MAX"

( the U of R IBM 4381 computer )

STEP 2: identify the type of terminal you are using;

xt100's are referred to as "VT100",

xt51's are referred to as "ACT4"

(Computer Science has set its lab xt51's to ACT4 mode. )

STEP 3: enter user name and password

The following are the screen images you will see as you go through the steps of logging on:

The screen clears and the following is displayed.

Type a [TAB] to move to the password field after entering the userid. Your password will NOT appear on the screen as you type it in. If the information you enter is correct, CP (the Control Program) will automatically start up CMS (the Conversational Monitor System). After the logon messages are displayed the cursor will be positioned in the bottom left corner of the screen. There is no prompt symbol in CMS.

The line:

R; T=0.00/0.00 HH:MM:SS

is displayed after every execution of every CMS command. It indicates that CMS is Ready for another command; the amount of CPU time the last command took to execute; and the current time. If the last command was not completed properly due to an error there will be an error number after the R i.e.

R (001); T=0.00/0.00 HH:MM:SS

Note: should the user make an error when entering the USERID and/or PASSWORD the system will respond with the following screen. This allows the user to reenter the information. The user must type the letter "L" (for LOGON) before typing his USERID.

The username entry is echoed at the top of the screen followed by a prompt to enter your password, then the cursor is moved to the bottom left again. Enter the password now. The system accepts what you type, however it is not printed on the screen.

You are now logged on and ready to use the CMS commands.

4.3.1.3. LOGGING Off

To logoff simply enter:

LOG [Return]

The system should respond with information in the following format.

CONNECT= hh:mm:ss VIR+CPU = mm m:ss.ss TDTCPU=mmn:ss.ss

LOGOFF AT hh:mm:ss CST day mm/dd/yy

Now you are logged off and have not left a line open to your account. Max does NOT allow multiple logons from one account so be sure to logoff properly. Sometimes it is desirable to logoff from one Max account and then logon to another Max account. To logoff and maintain the Develswitch connection to Max enter:

LOG HOLD [Return]

You can then proceed with another logon without having to go through the Develswitch request sequence.

4.3.1.4. SCREEN STATUS MESSAGES

Max is highly screen-oriented; for example when the first 24 lines (a 'screen-full') of a file are displayed, the display is stopped until you indicate that you wish to see the next 24 lines of information. The bottom right of the screen contains a status message indicating what is going on. This message can be any of:

CP

- This indicates that you are running the Control Program that you start with before you login. You either haven't logged in yet - or CMS (Conversational Monitor System) has died.

- To restart CMS enter the command to do an Inital Program Load (IPL) of CMS. This command is executed automatically when you first login.

IPL CMS [Return]

[Return]

MORE

- This indicates that the screen is full and there is more to see. In one minute the screen will clear and go to the next screen. You can type [PA1] on an IBM terminal ( [Enter] on the numeric keypad of a VT100 terminal, [Esc] [period] on most other terminals) to go to the next screen or type [Return] to leave the current display on the screen indefinitely.

HOLDING

- You get this message when you enter a [Return] at a MORE screen.

Type [PA1] on an IBM terminal ( [Enter] on the numeric keypad of a VT100 terminal, [Esc] [period] on most other terminals) to go to the next screen.

RUNNING

- CMS is busy doing something. You may enter another command and CMS will get to it as soon as possible.

NOT ACCEPTING

- CMS is very busy and will not accept another command. This can also appear when you have entered too many commands with a MORE or HOLDING status.

4.3.1.5. KEY SEQUENCES

Terminals at the University of Regina are not IBM terminals. Other terminals can be used to access Max, but alternate key sequences must be used. The appropriate key sequence depends on the type of terminal. Most terminals here are the VT100 type, although some XT51 (also referred to as 'ACT-4') types remain.

4.3.1.5.1. PA AND INSERT KEYS

There are two 'PA' keys: PA1 - clears the screen

PA2 - stops the current process

PA2 must be used instead of the traditional [CTRL [C)) sequence to terminate the current process; PA2 kills a process but unfortunately also kills CMS. (Remember that you must enter IPL CMS [Return] to restart CMS.)

The terminals at the University of Regina use the following methods to take the place of the IBM 'PA' keys.

Normally, whether in the editor or at the CMS level, whatever you type overwrites what is currently on the screen. However, it is convenient at times to be able to have what you typed inserted at the cursor position. To change the status of insert mode (i.e. to turn it off or on) enter

[dot] on a VT100 numeric keypad

or [CTRL [Y] ] on an XT51 terminal.


4.3.1.5.2. DELETE KEYS

The delete key does not function in the manner it does on a Unix or a VMS system i.e. you cannot simply type [Delete) to delete the last character that you typed in. If you make a typing mistake, you must use the left arrow key and then the delete key. Typing [Delete) removes the character 'under' the cursor and then moves all of the characters that are to the right of the cursor one position to the left.

4.3.1.5.3. PF KEYS

PF keys are used for such functions as moving backward and forward in a file when using the editor. The terminals at the University of Regina use the following methods to take the place of the IBM 'PF' keys.

To simulate the IBM PF keys on a VT100 terminal you type the key of the function or numeric keypad that corresponds to the PF key. For example. (refer to the following diagram) to perform PF8 you would type the "5" key on the VT100 numeric keypad.

The PF key equivalents on a VT100 are:

IBM VT100 (function and numeric keypad)

On an xt-51 terminal type the escape [Esc] key and then the number of the PF key required. DO NOT hold the escape key down while typing the number. The equivalences are:

IBM: PF1 PF2 . . . PF9 PF10 PF11 PF12

XT51: [Esc] then 1 2 9 0 - =

Remember that when the screen is filled, you must enter [Esc] [period) to get the next screen of information.

NOTE: If you have a terminal or micro at home that you want to try using on IBM,

set: 8 bit transmission

no parity

You must know what the terminal type is, or what terminal type can be emulated by your micro.

See "HELP YTERM" or "KEYS" at MAX CMS Command level for more information regarding keyboard layout. The following table illustrates key equivalencies for various terminals. Remember that most terminals in the Computer Science Department are VT100.

4.3.2. CMS USAGE

4.3.2.1. FILE SPECIFICATION

File specification provides the system with all the information it needs to identify a unique file. There are no punctuation marks in the file specification and each field is separated by at least one space. The format is:

fn ft fm

Constraints for the fields are:

fn 1 - 8 character file name

Valid characters are alphanumerics and/or $ @ + - # : -

ft 1 - 8 character file type

Valid characters are the same as those for filename.

fm 2 character file mode

The first character is a letter (A-Z) which indicates mini-disk.

The default is A.

The second character is a number between 0 and 6.

This indicates the access mode (1 is most common). When you create a file, the mode is A1 by default. It is not necessary for beginners to be concerned with a filemode other than A1.

The filename and filetype fields must be present in most cases. It is not always necessary to specify the filemode. If you enter a command which expects a filemode, the following message is displayed.

DMBRN054E INCOMPLETE FILEID SPECIFIED

Simply reenter the command with the complete file specification. A filemode specification of "A" is assumed to mean "A1".

Note that the wildcard character "*" can be used in place of a specific filename or filetype. For example to see the names of all files with filetype of PASCAL, you could enter:

LIST * PASCAL

Or if you want to see all files with a filename of say "LAB5", you could enter:

LIST LAB5

4.3.2.2. CMS COMMANDS

These are the essential commands needed for 'minimal survival'. They can be entered in either upper or lower case. Abbreviations (accepted for some commands) are not included here.

4.3.2.2.1. COPY

COPY fn1 ft1 fm1 fn2 ft2 fm2 [Return]

This will copy the file indicated by "fn1 ft1 fm1" into "fn2 ft2 fm2". Two copies of the file will then exist. An equal sign "=" can be used in place of fn2 and ft2, this is useful if you are copying a file from another mini-disk.

e.g. COPY info script E = = a [Return]

The file will be called INFO SCRIPT on the A disk.

4.3.2.2.2. ERASE

ERASE fn ft [Return]

To delete a file from your mini-disk use the ERASE command. A filemode is not required for this command unless you wish to delete a file on a mini-disk other than the A disk.

4.3.2.2.3. FLIST

For a screen oriented listing you can enter:

FLIST [Return]

The response will be a list of filenames at the top of the screen and a "menu" at the bottom of the screen. The cursor will be positioned beside the first file specification. You can move it to any filename by using the arrow keys. When the cursor is positioned beside a file specification, enter a PF key from the menu of PF keys illustrated at the bottom of the Flist screen.

Several PF key functions in Flist are similar to those in other utilities. For example when you call up the "browse" utility (by entering PF2 for "BRW") the screen clears and the first part of the file you wish to examine is displayed on the screen. A new menu of PF key settings appears at the bottom of the screen. Two of the more obviously useful PF keys are 7 and 8 which allow you to read forward and backward respectively in the file you are browsing. Another useful PF key is 3 which allows you to return to the FLIST menu. You will note once you are back to the FLIST menu, the purpose of PF3 is also End; in this case entering PF3 would return you to the CMS command level.

4.3.2.2.4. HELP

HELP [Return]

Use the arrow keys to position the cursor over the name of the area you want help with and then type PF1. For example, if you want information on the edit input command you would place the cursor under XEDIT and then enter PF1. The current screen image would be replaced by a menu of edit commands. You would look for INPUT and enter PF1 again. Enter PF3 to return to previous screen images. PF3 will also let you out of the HELP facility.

You can also specify an error code when you call help. Max may specify an error code for you if you enter a command incorrectly. For example if you might have intended to enter

COPY LAB1 COBOL A LAB2 COBOL A [Return]

but forgot to enter the complete file specification of the target file and entered

COPY LAB1 COBOL A LAB2 COBOL [Return]

Max would respond with:

DMSCPY054E Incomplete fileid specified

Ready(00024); T=0.01/0.01 12:54:31

You could then enter

HELP DMSCPY054E [Return]

And Max would respond with the following text.

(c) Copyright IBM Corporation 1982, 1986

(adapted from IBM Form SC19-6204)

054E Incomplete <fileid|execid> specified

Explanation: You must specify the filename and filetype or execname and exectype in order for the command to be executed. In addition, for some commands you must specify the filemode.

System Action: RC = 24

Execution of the command is terminated. The system status remains the same.

User Response: Check the description of the command, correct the command line, and reissue the command.

Ready; T=0.09/0.17 12:59:35

Max then leaves you in the Help facility, so you must choose one of the menu selections displayed at the bottom of the screen to quit or to continue in Help.

4.3.2.2.5. LIST

LIST [Return]

This provides a very simple listing of filenames. You can also use List with a wild-card specification for any one of the fields in a file specification. For example:

LIST * PASCAL [Return]

or LIST LAB1 * [Return]

or LIST * * E [Return]

4.3.2.2.6. LOG

LOG [Return]

This will log you off your account.

4.3.2.2.7. PASSWORD

PASSWORD [Return]

This will allow you to change your password.

4.3.2.2.8. PRINT

"PRINT" fn ft fm [Return]

The command PRINT is put in quotes because you must enter the name of a printer to get a paper listing of a file.

To get a paper copy on a printer in C135, enter:

C135LP fn ft fm [Return] sends the file to the big line printer

To get a paper copy on a printer in C115, enter:

C115LP fn ft fm [Return] sends the file to the big line printer

C115 fn ft fm [Return] sends the file to the smaller printer

4.3.2.2.9. QUERY DISK

QUERY DISK [Return]

This will tell you how much disk space you have and are using.

4.3.2.2.10. QUERY NAMES

QUERY NAMES [Return]

This will give you the names of those people currently logged on.

4.3.2.2.11. RENAME

RENAME fn1 ft1 fm1 fn2 ft2 fm2 [Return]

This will rename a file indicate by the "fn1 ft1 fm1" giving it the new designation of "fn2 ft2 fm2". Only one copy of the file remains.

4.3.2.2.12. TYPE

TYPE fn ft fm [Return]

This displays a file on the terminal. Remember that IBM stops when the screen is filled (a MORE message is printed on the bottom right corner).

Enter [[CTRL] A] or [[Esc].] on an XT51 to continue or the numeric keypad [PRINT/ENTER] on a VT100.

4.3.2.2.13. XEDIT

XEDIT fn ft fm [Return]

This will call up the editor. If the file does not exist the editor will create one according to your file specifications.

4.3.2.3. ACCESSING OTHER DISKS

There are other accounts on the system that you will need to access to get copies of assignments, data files, and other information. "CS271" is used by the CS271 instructors and "CS200" is used by the C200 instructors.

To access the CS271 account you must first LINK to the account and then issue an ACCESS command. The LINK command has a format of:

LINK accountname disk_number your_disk_number [Return]

where: accountname is the name of the account you want to access

disk_number is the disk number of the account you want to access.

This will most likely be the default disk in that account so the

number should be "191"

your_disk_number is a disk number that you do not currently have in use

Valid disk numbers are in the range of 192 to 299.

You cannot use 191 because that is your default mini-disk number.

Numbers from 300 and up are used by the operating system.

e.g. LINK CS271 191 271 [Return]

where: accountname is CS271

disk_number is 191 (the CS271 account's main disk)

your_disk_number is 271 (any number you are not using)

The ACCESS command has the format:

ACCESS your_disk_number drive_letter [Return]

where: your_disk_number is the same number you used in the LINK command

drive_letter is a letter you are not using.

e.g. ACCESS 271 E [Return]

where: your_disk_number is 271

drive_letter is E

You can now copy files from the CS271 accounts disk by specifying the E disk. To get a list of the files in the CS271 account enter:

LIST * * E [Return]

To copy a file to your account enter:

COPY filename filetype E = = A [Return]

The equal signs instruct Max to use the same filename and filetype when it copies the file.

When you are finished accessing the E disk you can RELEASE it with the command:

RELEASE E (DET [Return]

This releases the letter E for you to use for another Link / Access. Note however, that links are automatically released when you logoff.

4.3.2.4. HALTING AND RESTARTING PROCESSES

On many computer systems, typing [Ctrl [C]] terminates a process. However this is NOT the case on Max. In order to stop a process (a looping program etc) you can enter PA2 which is the [Esc] [comma] sequence on regular terminals. This kills the process but has the unfortunate side effect of killing CMS as well. Since CMS is your interface to your virtual machine, you must restart it. i.e. enter

IPL CMS [Return]

[Return]

It may be possible to stop an infinite loop, a lengthy TYPE command, or whatever with the CMS command:

HX [Return]

It can happen that CMS is alive and well but does not respond as you expect. As stated previously, this IBM operating system is highly screen oriented. A system command may have several different screens associated with it. Entering a sub-command can cause different screen image to be displayed corresponding to that level of the system command. If you get a message something like

INVALID SUBSET COMMAND

you must enter

RETURN [Return]

to get back to the previous command level.

4.3.3. SORT

4.3.3.1. SORT FROM CMS

A General Purpose (Generic) sort utility is provided with CMS to sort any file. This utility allows only for ascending sorts. The syntax is:

SORT fn1 ft1 a fn2 ft2 a

"fn1 ft2" refers to the filename and type of the file that contains the records to be sorted. The sorted records will be placed in the file you specify by "fn2 ft2". If the output file already exists, it is OVERWRITTEN so be careful in your choice of filename and filetype. ** The utility sort requires that you specify all three fields in a file specification i.e. filename, filetype, and filemode.

After you enter the SORT command, you will be asked to specify the fields to be used in the sort. Enter the start and end columns (pairs of numbers) for each field in the order of key precedence. Primary key first, then secondary key, and so on.

Note: a) the number of sort fields is limited to the length of the line given to enter column pairs

b) no provision is given for sorting by descending order

For example, suppose your input file called "lab4 data a"was formatted as follows:

1 20 40 44 <-- column numbers

name address dept <-- field names

paul jones 22 Shore Ave. Math

daphne cline 17 Lang Math

zap zoie 4 Blake CS

alphonse alpha 3 Zener CS

To sort this primarily on the department field (columns 40 to 44) and secondarily on the name field (columns 1 to 20) the following sequence would have to take place.

sort lab4 data a tmp tmp a [Return]

DMSSRT604R Enter sort fields:

40 44 1 20 [Return]

Ready; T=0.01/0.03 14:47:12

The output file resulting from the sort would contain:

alphonse alpha 3 Zener CS

zap zoie 4 Blake CS

daphne cline 17 Lang Math

paul jones 22 Shore Ave. Math

4.3.3.2. SORT FROM XEDIT

The syntax for sorting from within Xedit is:

SORT number-of lines start-column end-column

A number of column pairs can be entered. If the entire file is to be sorted then an asterisk can be used for the number of lines. If a specific number is used then the sort will start at the current line and continue for the number of lines specified.

The primary sort field ONLY can be set to descending order by preceding the column pair with "d".

For example:

SORT * d 40 44 1 20 [Return]

The following however is INVALID because only the first field can be set to descending.

SORT * 40 44 d 1 20 [Return]

4.3.4. PROGRAM DEVELOPMENT

Once you have learned the syntax of a particluar programming language, you must be able to interface with the operating system of a computer to actually run your program. You must know how to compile, link, and run your program as well as how to inform the operating system of any input and/or output files required by the program.

4.3.4.1. COMPILE / LINK / RUN

The first step towards running a program is to convert the source code file to an object file. You must then link your object file with programming language and/or user libraries. You may then run the resulting executable file; remember though, that the operating system must be informed of any input/output files (file I/O is the topic of the next section of this document).

The three steps necessary to compile, link, and run a program begin with a source code file. In the following diagram, please note that "file" is used to denote the 'file-name'.

Under CMS, the extension of the source code file is related to the name of the programming language; for example, the extension "COBOL' is used for a Cobol language source file. The results of a compilation are the object file (extension of "TEXT') and a compilation listing file (extension of "LISTING"). The listing file contains your source code plus any complier generated information such as errors in the code. The object file is taken in by the link step which produces an executable file (extension of "MODULE").

EXAMPLE 1. (COBOL)

a) Compile the source file (uses COBOL as the filetype)

COBOL2 filename [Return]

This produces:

filename LISTING -- listing file

filename TEXT -- object file

b) Link the object file

LOAD filename [Return]

GENMOD filename [Return]

c) Enter the necessary filedef's for I/O files

d) Run the executable file

filename [Return]

EXAMPLE 2. (PASCAL)

Note that the program name in the source file MUST be the same as the filename on disk.

a) Compile the source file (uses PASCAL as a filetype)

PASCAL filename [Return]

This produces:

filename LISTING -- listing file

filename TEXT -- object file

b) Link the object file

PASCMOD filename [Return]

This produces an executable file -- filename MODULE

c) Enter the necessary filedef's for I/O files

d) Run the executable file

filename [Return]

EXAMPLE 3. (FORTRAN)

Note that the file must be entered in upper case.

a) Compile the source file (use FORTRAN as filetype)

FORTRAN filename [Return]

This produces:

filename LISTING -- listing file

filename TEXT -- object file

b) Link the object file

LOAD filename [Return]

GENMOD filename [Return]

c) Enter the necessary filedef's for I/O files

d) Run the executable file

filename [Return]

4.3.4.2. FILE INPUT/OUTPUT

4.3.4.2.1. FILE DEF'S

In business, you would perform initial tests of your program on a small data file. When the program logic has been proven, you would then perform a "production run" using 'live' data. A file definition at the operating system level allows you to perform these different program runs using various data files. Xedit is used to create/modify source files and input data files. Input and/or output files must be defined to CMS before the program is run.

A file definition, "filedef" in CMS terminology, is a statement that connects the name of a data file in your program to the actual name of the data file on disk. The general form of a file definition command is:

FILEDEF name-in-pgm device name-on-disc options

where:

name-in-pgm is the file name as specified in the source code of the program to be run.

device is generally DISK but could also be PRINTER etc.

name-on-disc is a file specification of the form "filename filetype". It is not necessary to specify filemode.

options include RECFM (record format) and LRECL (logical record length). A list of options must be preceded by a left parenthesis "(".

It is important to be sure that the "options" you specify correspond to the data file. RECFM is the record format keyword that indicates the format of the file being used. Formats are F, for "fixed", and V, for "variable". LRECL refers to the logical record lenght. This is the maximum length of a record (line) in a variable format file, and the length of every record in a fixed record format. When you xedit a file you are shown the record format and logical record length.

e.g. FILENAME F (or V) 80 (or whatever length)

These values can be changed at the xedit command line:

===> RECFM F [Return]

or ===> LRECL 80 [Return]

EXAMPLE 1: (COBOL)

Given this "Select" statement from a COBOL source program:

SELECT INPUT-FILE1 ASSIGN TO SYS001-IFILE.

The following filedef would have to be entered just before the program is run:

FILEDEF IFILE DISK SALES DATA ( RECFM F LRECL 80

This would indicate that the input is to come from the disk file "SALES DATA" which is a fixed record format with a logical record length of 80. Actually fixed 80 is the default so this does not need to be specified. Record format can also be V for variable and record length depends on the disk file.

The following diagram illustrates the link between the Cobol FD name, the logical filename, and the name of the file as it exists on disk in an account.

Areas of Concern in Cobol:

a) "Select" Channel Indicator

Each file (either input or output) in the Cobol Select statement should be referenced by a unique 'channel number'.

e.g.

SELECT input-file1 ASSIGN TO SYS001-ifile.

Use a different number for each file. e.g. SYS002, SYS003, and so on.

b) Logical Name in "Select" Statement

A logical filename in a Cobol SELECT statement should NOT contain hyphens after the 'channel number' indicated by the "SYSnnn-" indicator..

e.g.

SYS001-ifile correct

SYS001-i-file WRONG!!!

This will not produce a compilation error but it will give problems when you try to run the program.

c) Record Length

If you specify a record length in your Filedef, be sure that the description in your Cobol program corresponds to that length.

e.g. If you entered the following Filedef:

FILEDEF ifile DISK sales data (RECFM F LRECL 80

then the entries describing record elements in your program must total 80.

i.e. FD input-file1

.

.

.

05 first-part PIC X(40). [TOTAL OF 80

05 second-part PIC X(40). CHARACTERS]

EXAMPLE 2: (PASCAL)

Given this first line from a PASCAL source program:

PROGRAM testing (infile)

The filedef would be

FILEDEF infile DISK numbs dat (RECFM F LRECL 80

EXAMPLE 3: (FORTRAN)

Given this line from a FORTRAN source program:

OPEN(UNIT=15,FILE='myfile',STATUS='OLD')

The filedef would be

FILEDEF myfile DISK XYZ DAT (RECFM F LRECL 80

4.3.4.2.2. TERMINAL I/O

If the program uses terminal I/O, you may want to get a copy of the run duplicated in a file which you can later send to the printer. The following dialogue shows how to do this.

Type:

CONSOLE ON [Return]

Run your program.

Type:

CONSOLE OFF [Return]

MAX responds:

YOUR CONSOLE OUTPUT IS IN FILE CONSOLE LOG A

Note: Before running a COBOL program which requires input from a terminal, you must enter

FILEDEF SYSIN TERMINAL [Return]

Note: Before running a PASCAL program which requires input from a terminal, you must enter

FILEDEF INPUT TERMINAL [Return]

and for output to a terminal:

FILEDEF OUTPUT TERMINAL [Return]

4.3.5. SOURCE LIBRARIES

Like a library, which contains books so that everyone may access one copy of the book (rather than each person buying their own copy), computer libraries contain code which can be used by many programs, without writing it separately into each program. In a university environment many of the programs you write are just small assignments; each with it's own data file. You run them once and that's it. However, in the "real world" programs you write will be part of large systems of programs that have data files in common. These programs which use the same data files, have much of their code in common (constants declarations and variables that define input records).You could manually type this code into each program that uses the constants and data file(s) but you are risking typing errors and non-standard data names.You could use an editor to cut the code out of one program and paste it into another. The ease of this depends upon your editor. However, it is much easier, and more consistent, to have one file that contains this type of code. This file could then be accessed by a variety of programs by including a statement in the programs to reference a collection of code in a library.

4.3.5.1. SETTING UP YOUR PROGRAM

You must first decide where, in your program you might have an area of code that could be common in more than one program. An area of 'common' code can be placed in a separate file (called a "copy member"); the rules for doing this are described later. For now, simply choose a name for your copy member, following the CMS rules for a filename specification.

Rather than placing the common code directly in your program, you enter a reference statement in the program where you want the code to go. The syntax of the reference statement depends on the specific compiler; refer to the following examples. This procedure can be used for ANY part of a program. For example, a program might have a copy member for some print-lines that are standard (a company letter-head).

4.3.5.2. CREATING COPY MEMBERS

The program segment to be placed in each program is referred to as a copy member. Under CMS, each program segment (copy member), must be placed in a library. A library is a collection of program segments (members).

A program segment (copy member) is created using XEDIT with the same rules as that of the programming language that is referencing the copy member. In general, the copy member must be:

- fixed record format (RECFM F)

- the member must have the filetype COPY.

This gives you a valid program segment "member COPY" that you must install as the member of a library.

NOTE: when you xedit a file you are shown the record format and logical record length.

e.g. FILENAME F (or V) 80 (or whatever length)

These values can be changed at the xedit command line:

===> RECFM F [Return]

or ===> LRECL 80 [Return]

4.3.5.3. CREATING A SOURCE LIBRARY

"MACLIB" is a CMS program that maintains user defined source libraries (collections of COPY members). Use the Maclib command with its various options, to create, modify, or examine a library. Have your copy members ready before you begin to use any MACLIB commands.

To create a new library , enter the following command:

MACLIB GEN libname member [Return]

Where: "libname" is what you want to call your library, and "member" is a copy member you want to start creating the library with.

This command generates "libname MACLIB" as the library and inserts the file "member COPY". Note: ** MACLIB does not like you to enter any filetypes.

After the library is created, you can use other MACLIB options to maintain it.

To add a new member enter:

MACLIB ADD libname member [Return]

To delete an existing member enter:

MACLIB DEL libname member [Return]

To replace an existing member with an updated version enter:

MACLIB REP libname member [Return]

To see the names of the members in a library enter:

MACLIB MAP libname (TERM [Return]

This lists the names of all the members in the library (the filename before it was inserted is the name that becomes the member name), the length of each member in lines, and the location of the macro in the library relative to the beginning.

4.3.5.4. COMPILING YOUR PROGRAM

Now that you have a program that references copy members, and a source library that contains the correct member(s), you want to compile your program. The compiler needs to be informed as to which source library you are using:

Define your library:

GLOBAL MACLIB libname [Return]

Link your library name to disk name:

FILEDEF libname DISK libname MACLIB [Return]

Compile your program with the source "LIB" option:

compiler-call pgmname (LIB [Return]

4.3.5.5. RUNNING WITH A LIBRARY

Link and run your program as you would normally. If you find that code contained in a copy member needs to be changed follow these steps:

1. Xedit the copy member file,

2. use the MACLIB command with the REP option to replace the copy member in your library,

3. define and link your library before re-compiling,

4. link and run your program as usual.

4.3.5.6. EXAMPLE 1. (COBOL)

1. Set up your program.

Suppose the following segment of code is in common with more than one program. (The description of fields in an "FD" area is often common among different programs.)

01 EMP-FIELDS.

05 FIELD-1 PIC X(20).

05 FIELD-2 PIC X(05).

05 FIELD-3 PIC X(45).

Choose a name for this code segment, say: "EMPFILE". Later you will place this code into a file called "EMPFILE COPY". Rather than placing the common code directly in the program called "PROG1 COBOL", you enter the Cobol "COPY membername" statement in the program where you want the code to go.

IDENTIFICATION DIVISION.

PROGRAM-ID. PROG1.

.

.

.

FD EMPLOYEE-FILE.

COPY EMPFILE.

In this example, the COPY statement began in Area A (column 8) of the program. However if your copy member contained code that begins in Area B (column 12), you place the COPY statement beginning in Area B of the program.

2. Create the copy member.

Create the copy member "EMPFILE COPY" using XEDIT with the same rules as that of a Cobol program. It must be:

- entered in UPPER CASE characters

- follow COBOL area A and area B format correctly

3. Create a source library.

Use the Maclib command with the 'GEN" (generate) option, to create a library called 'MYLIB MACLIB".

MACLIB GEN mylib empfile [Return]

4. Compile your program with the library.

Define your library:

GLOBAL MACLIB mylib [Return]

Link your library name to disk name:

FILEDEF mylib DISK mylib MACLIB [Return]

Compile your program with the source "LIB" option:

COBOL2 prog1 (LIB [Return]

4.3.5.7. EXAMPLE 2. (PASCAL)

1. Set up your program.

Suppose the following segment of code is in common with more than one program.

CONST

line_length = 80;

digits = 9;

name_length = 25;

Choose a name for this code segment, say: "CONST". Later you will place this code into a file called "CONST COPY". Rather than placing the common code directly in the program called "PROG PASCAL", you enter the Pascal "%INCLUDE libname(membername)" statement in the program where you want the code to go.

program prog (input, output);

%include anyname(const)

begin

.

.

end.

The %include statement must begin in column 1 in the Pascal program.

2. Create the copy member.

Create the copy member "CONST COPY" using XEDIT with the same rules as that of a Pascal program.

3. Create a source library.

Use the Maclib command with the 'GEN" (generate) option, to create a library called 'ANYNAME MACLIB".

MACLIB GEN anyname const [Return]

4. Compile your program with the library.

Define your library:

GLOBAL MACLIB anyname [Return]

Link your library name to disk name:

FILEDEF anyname DISK anyname MACLIB [Return]

Compile your program with the source "LIB" option:

PASCAL prog (LIB (anyname [Return]

4.2.5.8. SUMMARY

The following steps are required to use source libraries.

1. Place the copy membername reference statements at appropriate locations in your main program.

2. Create copy members with xedit according to these rules:

- ensure fixed record format (RECFM F)

- the member must have the filetype COPY.

3. Create a source library with the MACLIB command, and add any relevant other copy members.

MACLIB GEN libname member [Return]

MACLIB ADD libname member [Return]

4. Compile the main program with your library.

GLOBAL MACLIB libname [Return]

FILEDEF libname DISK libname MACLIB [Return]

compiler-call pgmname (LIB [Return]

5. Link and run your program as usual.

6. If you find that some copy members need modification, use xedit to make the changes and then replace the updated copy members in your library before recompiling.

MACLIB REP libname member [Return]

4.3.6. OBJECT LIBRARIES

Why Object Libraries - Separate Compilation?

In many data processing shops, computer time is rented. You are charged $MONEY$ for CPU time and also for I/O. During the development and testing stage the CPU and I/O cost for compiling your program can become huge. Often, many compiles are required each day to test small changes. The cost of compiling and testing this small change is amplified when you are working on a large program. The whole program (all - say - 10,000 lines) must be recompiled just to test a simple change in output format. There is also time lost while the programmer waits for the compile of a large program - it can take literally hours.

To keep compile costs down during the development stages it is possible to compile a program in segments. Then - when you make a change to a segment you need only recompile that segment and not the whole thing.

Separate compilation also corresponds nicely to modular programming techniques which tend to produce better code.

A practical reason in our lab, is that if the file gets too big the printer will not accept it.

4.3.6.1. ORGANIZATION

These program segments must be organized logically - (like paragraphs).

This way each is separately compiled. A change to one line of one subprogram means that only one block of code needs to be recompiled.

A quick 'aside' on top-down design and stub-testing: In a large program the subroutines would be 'stubs' in the testing stages of the driver program. Each subroutine might initially have nothing more in it than a print statement indicating that the routine had been called.

4.3.6.2. SET UP MAIN AND SUBPROGRAMS

*

*

*

references to sub-programs

*

*

*

sub-program indicator sub-program indicator

* *

* *

* *

NOTE:

* each subprogram is a COMPLETE program that will compile.

* the syntax of the reference statement and sub-program indicators depends on the specific compiler; refer to the following examples for details.

4.3.6.3. COMPILE

Compile each of the programs as you normally would. Then create object and executable files using the name of the main (the 'calling') program.

compiler-call main-program [Return]

compiler-call subroutine1 [Return]

compiler-call subroutine2 [Return]

4.3.6.4. SETUP THE TXTLIB

If you have a large number of TEXT files which you keep in your account because you often reuse them, a better way to store them would be to keep them in a text library. They are like the MACLIBs we looked at previously but they store compiled programs instead of source code.

TXTLIB is the name of the program that manages TEXT(object) libraries. It works in (almost) exactly the same way as MACLIB.

TXTLIB GEN libname member [Return]

TXTLIB ADD libname member [Return]

TXTLIB DEL libname member [Return]

TXTLIB MAP libname (TERM [Return]

Example

TXTLIB GEN lib sub1

TXTLIB ADD lib sub2

NOTE: the REP option is not available with TXTLIB so you have to DEL and ADD to do a replace.

4.3.6.5. LOADING WITH A TEXT LIBRARY

GLOBAL TXTLIB language-lib libname [Return] <- define your new text library (refer to examples for

name of the language library)

LOAD main-program (noauto [Return] <- only specify main program

GENMOD main-program [Return] <- only specify main program

The NOAUTO option prevents LOAD from checking your account for the missing TEXT code.

Example of where noauto is necessary

Given:

* a text library of math routines called MATHLIB

*a program main that calls the MULT routine in MATHLIB

*in your directory a program you wrote called MULT TEXT

Doesn't work

GLOBAL TXTLIB language-lib MATHLIB

LOAD MAIN (this loads MULT TEXT from your directory

GENMOD MAIN

Does work

GLOBAL TXTLIB language-lib MATHLIB

LOAD MAIN (NOAUTO (the noauto prevents load from using your dir)

GENMOD MAIN

4.3.6.6. EXAMPLE 1. (COBOL)

1. Setup main and subprograms.

The statement CALL "subprogram-name" is used to invoke the subprogram.

IDENTIFICATION DIVISION.

PROGRAM-ID. MAIN.

*

*

*

CALL "sub1".

CALL "sub2".

*

*

*

STOP RUN.

Instead of using the STOP RUN statement in each subprogram, use EXIT PROGRAM.

IDENTIFICATION DIVISION IDENTIFICATION DIVISION.

PROGRAM-ID. SUB1. PROGRAM-ID. SUB2.

* *

* *

* *

EXIT PROGRAM. EXIT PROGRAM.

NOTE:

* each subprogram is a COMPLETE Cobol program that will compile.

* CALL is used instead of PERFORM (much like a COPY).

* the subroutine name must be quoted in the CALL.

* called subprogram uses EXIT PROGRAM instead of STOP RUN.

* EXIT statements must be in a separate paragraph.

This is the simplest way of using subprograms but it is very limited as the called program has no way to access data in the calling program.

Accessing Data By A Called Subprogram:

Data is "passed" from the calling program to the called program through:

* a section in the DATA DIVISON called the LINKAGE SECTION

* some extra clauses added to the CALL statement

* the PROCEDURE DIVISION statement of the Called program.

The LINKAGE SECTION is located after the Working Storage Section.

Example

Cobol Calling Program Description Called Program Description

WORKING-STORAGE SECTION. WORKING-STORAGE SECTION.

LINKAGE SECTION.

01 Param-list. 01 Using-list.

05 Partcode Pic A. 10 Part-id Pic X(5).

05 Partno Pic X(4). 10 Sales Pic 9(5).

05 U-Sales Pic 9(5).

* *

* *

PROCEDURE DIVISION. PROCEDURE DIVISION USING Using-list.

CALL "subpgm" USING Param-list.

* *

* *

* *

STOP RUN. EXIT PROGRAM.

2. Compile

Compile each of the programs as you normally would. Then create object and executable files using the name of the main (the 'calling') program.

COBOL2 main [Return]

COBOL2 sub1 [Return]

COBOL2 sub2 [Return]

3. Setup your Library

TXTLIB GEN lib sub1

TXTLIB ADD lib sub2

NOTE: the REP option is not available with TXTLIB so you have to DEL and ADD to do a replace.

4. Load with the Text Library

GLOBAL TXTLIB VSC2LTXT lib [Return] <- define your new text library

LOAD main (noauto [Return] <- only specify main program

GENMOD main [Return] <- only specify main program

4.3.6.7. EXAMPLE 2. (PASCAL)

1. Setup main and subprograms.

In the main program, declare the subprogram (whether it is a Pascal function or procedure) as "external" in place of the usual definition.

program pasprog (input, output);

function gcd(a,b:integer):integer,external;

*

*

*

Instead of using the program keyword in each subprogram, use segment. Declare the function or procedure as EXTERNAL before defining it.

segment seg1; segment seg2;

function gcd (a,b:integer):integer;external; function gcd2 (a,b:integer):integer;external;

function gdc; function gcd2;

* *

* *

* *

NOTE:

* replace "function" with "procefure" if you are doing a procedure defiintion.

2. Compile

Compile each of the programs as you normally would. Then create object and executable files using the name of the main (the 'calling') program.

PASCAL pasprog [Return]

PASCAL seg1 [Return]

PASCAL seg2 [Return]

3. Setup your Library

TXTLIB GEN lib seg1

TXTLIB ADD lib seg2

NOTE: the REP option is not available with TXTLIB so you have to DEL and ADD to do a replace.

4. Load with the Text Library

GLOBAL TXTLIB PASCALVS lib [Return] <- define your new text library

LOAD pasprog (noauto [Return] <- only specify main program

GENMOD pasprog [Return] <- only specify main program

4.3.6.8. SUMMARY

1. Set up your main and subprograms.

2. Compile each of the main and subprograms separately.

3. Set up your library with the TXTLIB command.

4. Load with the TEXT library.

5. Enter any necessary Filedef's and run your program as usual.

4.3.7. SYNONYMS

If you are accustomed to another operating system it's handy to be able to set up a list of aliases for system commands. For example if you wanted to rename a file and you would rather type 'mv' than 'rename'. You want the system to equate 'mv' with the command 'rename'. You create a file called 'unix SYNONYM' (the filename is your choice but the filetype must be "SYNONYM"). Enter all commands and aliases in upper case.

e.g.

unix SYNONYM A

RENAME MV

where:

* RENAME - is the existing name

* MV - is what you want to call it

In your 'profile exec' file add the line:

'SYNONYM unix'

Your 'PROFILE EXEC' must be executed in order for your synonym file to be recognized. If you wish to test your new or modified synonym file without logging off and back on again you can enter:

PROFILE [Return]

to get the 'PROFILE EXEC' executed.

To see system and user synonyms type:

SYNONYM [Return]

If a user defined synonym doesn't work:

1) it could be a valid command already

For example: CP can't be used for 'copy'.

2) it may already be an abbreviation

For example: LIST LS will not work because

LIST is already an abbrev for LISTFILE so you must say

LISTFILE LS [Return]

4.3.7.1. EXAMPLE

Create a file using Xedit as described previously. You can choose any filename you wish but you must use the filetype 'synonym'. Once out of Xedit you can view the entire file by entering the TYPE command.

For example:

TYPE unix SYNONYM [Return]

LISTFILE LS

RENAME MV

ERASE RM
TYPE CAT