COBOL Compilers 2004
COBOL Compilers 2004
To load the environment, double-click on the Personal COBOL icon, or click on Start, then Programs, then
Personal COBOL, and then Personal COBOL again.
The Help menu offers a great deal of useful documentation. Click on Help for:
• Animator help (how to use the editor for creating and running COBOL programs),
• Keys help (summary of all function keys and keystroke combinations defined as shortcuts in the
animator),
• Start Here (obviously a good place to start - allows you to select from many beginner's topics to learn
how to use the environment),
• Online Tutorials and Reference,
• Standard COBOL reference,
• Object COBOL Reference, and
• Class Library Reference.
The animator has a Microsoft-type environment with the standard menu across the top of the screen and
various buttons below it. Point the mouse at a button, and an explanation of its function will be displayed at the
bottom of the animator screen.
Programming in COBOL
To create a new COBOL program, click on File and then New. The cursor will be positioned at column 8 of
line 1 (the line containing " ............................ Workfile empty ..........................").
Columns 1-6 and 73-80 are shaded out, and you will not normally make any entries in those areas. Begin
typing your program, pressing Enter after each line.
To load an existing COBOL program, click on File and then Open for Edit. A dialog box will pop up showing
all .CBL files in the current directory (c:\pcobwin\samples - there are lots of sample programs here to look at).
Change the subdirectory as needed to locate the file you want to load. Click on OK to load the file.
To compile your program, click on the checkmark button, or click on Compile/Run and then Compile this
program. A dialog box will pop up on the screen. If no errors are found, the dialog box will disappear after
compilation is complete. If an error is found, another dialog box will pop up with an error message, asking if you
want it to continue. It's probably better to click NO and fix this error. When you click NO, you're back in the
editor with the line where the error was found highlighted and "Error>" in the left margin of that line. The error
message is repeated in a small box at the bottom of the screen. Fix the error, save your program, and
recompile until the program compiles cleanly.
When the program compiles successfully, an executable file is created which has the same name as your
source program file and an extension of .INT. You are automatically placed into Edit+Execution mode with this
file. Click on Compile/Run and then Run to execute the program.
If there is any interactive input/output, a text window will pop up showing the display. At the end of the program,
a Run box will pop up showing the return code (+00000 means normal completion). Click on OK to return to
your source program. You will still be in Edit+Execution mode. If you wish to make further changes to your
program, click on Window and then on Edit for your program file to get back into edit mode.
1
Fujitsu COBOL (now called NetCOBOL)
Development and Execution Environment v 3.0
The COBOL files were downloaded from the Fujitsu web site:
www.adtools.com/products/downloadCOBV3.htm
To download Adobe Acrobat Reader, go to www.adobe.com
I had no problems in using this compiler with Windows XP, but their web site says:
If you are using Windows 2000 & Windows XP and have problems making Version 3 work, read the
Windows 2000 & Windows XP Application Compatibility Tips on this page:
http://www.adtools.com/student/index.htm
Sample programs can be downloaded from: http://www.adtools.com/student/samples/index.htm
Files Contents
COBOLV3.EXE Fujitsu COBOL version 3.0 development and execution
environment – includes all free tools apart from
PowerBSORT OCX .
Execute this file to install Fujitsu COBOL.
This is the only file needed for our programs.
Documentation:
COB_GSW.ZIP unzipped (using WinZIP) to COB_GSW.PDF
Fujitsu COBOL Getting Started
COB_WUG.ZIP unzipped to COB_WUG.PDF
Fujitsu COBOL User’s Guide
COB_LRF.ZIP unzipped to COB_LRF.PDF
Fujitsu COBOL Language Reference Manual
COB_DGW.ZIP unzipped to COB_DGW.PDF
Fujitsu COBOL Debugging Guide
The .EXE files are self-extracting executables. To install, run the .EXE file.
The .PDF files can be read with the Adobe Acrobat Reader
2
Using Fujitsu COBOL 3.0 for a Single-File Program (no subprograms)
Implementation Dependencies
1. The extension of a COBOL source program file may be .COB, .CBL, or (for Windows 95, NT, and later)
.COBOL .
2. The actual dataset names for files may be specified in the SELECT statements. We have encountered run-
time errors in trying to open data files located in folders whose names contained blank spaces, so it would
be
safer to store any COBOL-related files in folders whose names have no embedded blanks.
Examples:
Select DataFile assign to ‘c:\321cbl\data.txt’ organization is line sequential.
Select PrintFile assign to ‘c:\Output\report.txt’ organization is line sequential.
Alternately, you may choose to use external or link names in the Select statement(s) so that a program can
read from or write to different files without having to recompile the program. See the bottom of p. 5 and p. 6
for more information on using this option.
Getting Started
1. To start Fujitsu COBOL, click on Start, then Programs, then Fujitsu COBOL 3.0, then Programming
Staff. A window will open up for the Programming Staff. This is a standard environment with a menu bar
across the top.
General note:
In each of the dialog boxes to compile, link, and execute your program, there is an OK button at the top
right and a Compile, Link, or Execute button at the bottom right. Clicking on the OK button will
automatically close the dialog box after compiling/linking/executing. Clicking on the lower button will leave
the dialog box on screen after compiling/linking/executing.
2. To create a new COBOL program, select New from the Programming Staff File menu. An Editor
window will open up. You see a standard menu bar across the top and a toolbar with buttons underneath it.
Point the mouse at a button, and a box will appear under the button to describe its function. Below the
toolbar is a window where your source program will be entered.
Select New again from the Editor’s File menu. A dialog box gives you the opportunity to set the Undo level
(default is 0 which means Undo is not available) and Tab (if you specify a tab of n, it will mark every n
positions on the ruler bar and the tab key will take you to the next marked tab position). Click OK. You are
now in the Editor with the cursor positioned in column 7 of a line reading
“====== ======== END ========”.
When you begin to type, the END line will be positioned below the line you are currently typing. Type the
statements of your program, pressing enter after each line. Sequence numbers will be entered for you in
columns 1 - 6. Comments will be displayed in green. Reserved words will be displayed in blue if
entered in all uppercase (they're still reserved words and perfectly valid if typed in lower or mixed case; they
just won't be shown in color).
3. To load an existing program for editing, select Open from the Programming Staff File menu. Then
select Open from the Editor File menu. A dialog box will pop up listing all the .COB, .CBL, and .COBOL
files in the current directory. Type your program name or browse to locate the program you want to edit.
If the program file has no sequence numbers, has line numbers which are not sequential, or has code
beginning before column 7, another dialog box will pop up saying the line number in the specified file
is invalid. You are given the choice of
3
If you are sure your code does not begin before column 7, click Yes, and it will correct your line numbers. If
your code begins before column 7, it will overwrite your code with its line numbers. It's a good idea to have
a backup copy before loading the original into the editor just in case, though you can close the file without
saving it and have the original version back without the overwriting. You can then open the file in another
editor and shift statements to the proper columns. If your program doesn’t contain any line numbers, click
on NO and the program will be loaded with the editor’s line numbers before column 1 and no line numbers in
columns 1-6. It should compile okay like this.
4. To compile a program, first save the program in the editor and close the file or exit from the editor. Any
file, program or data, which is open in the editor is considered locked and may not be used by any other
program, such as the compiler, linker, or your executable.
Then in the Programming Staff window, select WINCOB [Compile]… from the Tools menu. A dialog
box will open up. Type the name of the file to be compiled or browse to locate it.
Each time you compile a program, you must identify it as either a main program or a subprogram.
After the source file is selected, click on the Options button. A Compiler Options window will open up.
If this is a main program, you want MAIN to be displayed in the inner window; if this is a subprogram, then
you want NOMAIN to be displayed in the inner window. The option chosen will remain selected for future
compilations unless you change it. If you compile a main program without specifying MAIN, it will cause a
linker error.
Click on either the OK button or the Compile button. A box will appear with a numeric countdown as the file
is compiled. A .MSG file will open up in the editor to show the results of the compilation. If there are any
errors, you will see DIAGNOSTIC MESSAGE at the top, followed by a list of errors. For each error, it will
show the filename, the line in the source program where the error was detected, and a message describing
the error.
Put the cursor on the first character of the file name for an error message and press F11 (or select Tag
Jump from the Locate menu). Another edit window will open up with the source file displayed and the
cursor on the statement where the error was detected. Fix the error.
4
Remember that one error can generate a great many messages, some of which may be the result of
assumptions made by the compiler rather than an actual error in your program. It's usually more
productive to fix the first few errors and recompile than to try to fix all the errors before recompiling.
From the Window menu, select the .MSG file again, move the cursor to the next error and press F11
again. Continue until you have fixed all the errors. Save the program, exit from the editor, and recompile
the program. When you have a clean compile, only the line beginning with STATISTICS will appear in the
.MSG file. HIGHEST SEVERITY CODE=I means only informational messages have been produced (no
errors). A code of W means only warning messages have been produced (no errors). Informational and/or
warning messages are listed at the beginning of the .MSG file. It’s a good idea to look at warning messages
to see if they are alerting you to a real problem, but they won't prevent a program from being executed.
A file with the same filename as your source file and an extension of .OBJ will be created and placed in
the same subdirectory as your source file. The .MSG file is also placed in the same subdirectory.
5. To link your program, select WINLINK from the Programming Staff Tools menu. The WINLINK window
opens up with the cursor blinking in the Link File box. Select EXE in the type box.
If there is a filename already in the list box that is left over from a previous project and is not part of the
current project, click on it to highlight it and then click on Delete to get rid of it.
Type the name of the file to be linked (same filename as your source program with an extension of .OBJ) or
browse to locate and select the object file to be linked. Click on the Add button. The object file is shown in
the list box and the executable file to be created is shown in the Target box. Click on either the OK button
or the Link button. The system creates a command prompt screen showing the linker messages, ending
with
If you have linker error messages, check pp. 129-132 of the User’s Guide document for explanations of the
messages. The only linker errors you should encounter are those regarding subprograms. See the section
on subprograms below for information on how to compile and link them.
Note: If you compiled a main program without the MAIN option or compiled a subprogram with the MAIN
option, you will probably get a linker error.
If the link is successful, close the WINLINK window and the command prompt screen window. A file with
the same name as your source file and an extension of .EXE should have been created and placed in the
same subdirectory as your source program.
6. To execute your program, select WINEXEC from the Programming Staff Tools menu. The WINEXEC
window opens up. If there is a filename already in the list box that is left over from a previous project and
is not part of the current project, click on it to highlight it and then click on Delete to get rid of it.
Type the name of the file to be executed or browse to locate it (COBOL executable files will be shown
preceded by a little blue globe icon and with no file extension shown).
Click on either the OK button or the EXECUTE button, and the Runtime Environment Setup window
appears.
If your program is interactive only (does not read from or write to files) or if you have specified the actual
dataset names in the program rather than using link names, you have nothing to specify here and can click
either on OK or on EXECUTE to execute your program. A DOS output window will open up where
interactive output is displayed and/or input accepted.
If you are not using any display statements in your program, it won’t look like anything happened and
there will be no indication that the program has executed successfully even if it has. Open your output file
to see what was written by the program.
If your program reads from and/or writes to a file and you used external/link names instead of the actual
dataset name in the program, you must now match the link name identifier you specified in the ASSIGN
clause of the SELECT statement in your program with the actual dataset name.
To make it easier to remember the identifiers you chose in the ASSIGN clause, you may want to use the
same link name identifiers for all your programs.
5
Example: Assume that your program contains these SELECT statements:
Select DataFile assign to infile organization is line sequential.
Select PrintFile assign to prtfile organization is line sequential.
and that the input file is c:\DataFiles\data.txt and the output file is to be a:report.txt.
infile=c:\DataFiles\data.txt
and click on Set. The line you typed will be added to the end of the list of environment variables in
the List window. Repeat this for the output file (the box is not automatically cleared and your new entry
does not overwrite the old entry, so you'll have to delete any extra characters).
Type in the Environment Variables Information box:
prtfile=a:report.txt
and click on Set. The line will be added to the end of the list in the lower box under your previous
line. Click on Save and then Yes and OK to save the environment variables.
Click on OK in the Runtime Environment Setup window to close the window and execute the program.
If you are not using any display statements in your program, it won’t look like anything happened and
there will be no indication that the program has executed successfully even if it has. Open your output file
to see what was written by the program.
6
Using Subprograms
Internal subprograms (subprograms coded in the same file as the main program) are perfectly legal in COBOL,
but I have not been able to figure out how to make Fujitsu COBOL handle such programs. It works fine,
though, when the subprogram is in a separate file and compiled separately. The subprogram source file names
should be the same as the PROGRAM-ID names with a .COB or .CBL extension, just like your main program.
Create each file separately in the editor and save the file (no particular order required). Compile the
subprogram(s) (in any order, if you have more than one) before you compile the main program.
To compile a subprogram:
2. If the word NOMAIN is already in the inner window, continue on with step 5.
5. Click on OK; the Compiler Options window disappears and you are back at the WINCOB window.
6. Click on Compile.
7. Fix any compile errors as described in the previous instructions for a single-file program.
Repeat this process as necessary to compile all the subprograms. The NOMAIN option will remain until you
change it. Then compile the main program with the MAIN option specified:
1. In the Programming Staff window, select WINCOB [Compile]… from the Tools menu. A dialog box
will open up. Type the name of the file to be compiled or browse to locate it.
2. After the source file is selected, click on the Options button. A Compiler Options window opens.
3. Click on NOMAIN to highlight it.
4. Click on Change. Another window will open up with a choice of
Compile program as main program or Compile program as subprogram.
5. Click on Compile program as main program
6. Click on OK; the Compiler Options window disappears and you're back at the WINCOB window.
7. Click on Compile.
8. Fix any compile errors as described in the previous instructions for a single-file program.
9. When you link the program, first add the main program’s .OBJ file to the link list (as described in the
previous instructions for a single-file program), and then add the .OBJ files for any subprograms which it
calls. The filename for the executable in the top display window should match the filename of your main
program, not the subprogram (this would cause a linker error).
10. Execute the main program as described in the previous instructions for a single-file program.
7
8