Teach Yourself COBOL in 21 days, Second Edition

Previous chapterNext chapterContents


- C -
Editing, Compiling, and Linking

To use this book effectively, you need to set up an area on your computer's disks where you can do your work and become familiar with your tools.

Setting up includes installing the COBOL compiler and creating a directory where you can do the lessons and experiment with ideas you might have while studying. The tools you need to become familiar with are an editor, the COBOL compiler, and perhaps a linker. You also need to learn how to run the completed program.

You'll perform this edit-compile-run sequence many times before you complete this book. Get comfortable with these steps. Without them, you will be unable to see your programs running, and your study will become an exercise in theory without practice.

This appendix explains the steps you need to take to set up a development area for various different COBOL compilers and computer systems, and how to use the tools to edit, compile, and link your program. If you use Micro Focus Personal COBOL or Acucobol, refer to the installation instructions distributed with your package. If the system you are using is not included, you have to consult the COBOL manual, editor manual, and system administrator or course instructor to work out this process.

Installation

First, install the COBOL compiler and associated software. If you will be working on a system that already has a COBOL compiler installed, you can skip installation.

Workspace

On almost any system, the workspace is a directory.

Windows

Under Windows, most of the compilers that you use will run within an MS-DOS Window. For Windows 3.x, double-click the group named Main, and double-click the MS-DOS icon. For Windows 95, click the Start button and select Programs. Within the programs listed, you will find one for MS-DOS Prompt. Click this selection.

When you are running MS-DOS under Windows, the MS-DOS window might appear as a smaller window on the main screen, or it might fill the entire screen, replacing the Windows desktop with a blank MS-DOS screen. After you have an MS-DOS screen or window open, you may type commands in that window or screen as if you were in MS-DOS. Follow the directions in the section "MS-DOS." When you are finished with your MS-DOS or COBOL programming session, type exit at the prompt to close the MS-DOS window or screen and return to the Windows desktop.

MS-DOS

On an MS-DOS system, change to the root directory by entering the following:

cd \

Then create a working directory by entering the following:

mkdir cobol21

This creates a directory in which you can do all your development. Whenever you are ready to work on a lesson, start by changing to that directory by entering the following:

cd \cobol21

UNIX

If you work on a UNIX-based operating system, change to your home directory by entering the following:

cd

Then create a directory in which you can do all your development by entering the following:

mkdir cobol21

Whenever you are ready to work on a lesson, change to that directory by entering the following:

cd $HOME
cd cobol21

or

cd $HOME/cobol21

VAX VMS

Log on to the system so that you are in your home directory. Create a directory in which you can do all your development by entering the following:

CREATE /DIR [.COBOL21]

Whenever you plan to work on a lesson, change to that directory by entering the following:

SET DEFAULT [.COBOL21]

Editing

The editor is your most important tool when you are programming. It is important to become familiar with it and to be able to use it easily.

For any editor, make sure that you can create a new file, add text to it, and save it. Practice the following steps, using the correct name of your editor:

1. Change to your working directory.

2. Start the editor on a new text file. For example, for MS-DOS, type the following:
EDIT new.txt
3. After the screen comes up, type a couple of lines and then save the results.

Open an existing file (such as new.txt) that you already have created, make changes, and save it.

These are editor basics. As you work through the lessons, if you are not familiar with your editor, have the editor manual or a crib sheet handy so that you gradually can learn how to work with it (cutting and pasting, searching for text, and so on). The more you know about your editor, the easier the job of programming is; programmers spend 90% of their programming time working with a source code file (a text file) in the editor.

Filenames

Some versions of COBOL require that your COBOL source code files have a particular extension. Under VAX VMS, all COBOL source code files must be created with the extension .COB. The source code for a program called MATH is created with the following command:

EDIT MATH.COB

ACUCOBOL does not care what extension you use, but it is common to use .cob or .cbl for COBOL source code files to make them easier to identify. The ACUCOBOL examples in this book use the extension .cbl. The math program source code is edited with a command such as the following:

EDIT math.cbl

Compiling

After you create or edit a program, you must compile it. Unless you have a programming environment that enables you to compile from within the editor, you have to exit the editor and start the compiler as a separate action by doing the following:

ccbl -o progname progname.cbl
COBOL PROGNAME.COB

Linking

No linking is required for ACUCOBOL. Under VAX VMS, type the following:

LINK /EXE=PROGNAME PROGNAME.OBJ

This creates a program named PROGNAME.EXE.

Running

ACUCOBOL uses a runtime program, runcbl, that must be named on the command line. To execute the program, enter the following:

runcbl progname

On VAX VMS, enter the following:

RUN PROGNAME


Previous chapterNext chapterContents


Macmillan Computer Publishing USA

© Copyright, Macmillan Computer Publishing. All rights reserved.