Net Cobol
Net Cobol
Net Cobol
The contents of this manual may be revised without prior notice. No part of this document may
be reproduced or transmitted in any form or by any means, electronic or mechanical, for any
purpose, without the express written permission of Fujitsu Limited.
Audience
Prior to using NetCOBOL, it is assumed that you have the following knowledge:
• You have some basic understanding as to how to navigate through and use the
Microsoft Windows product on your machine.
• You understand the COBOL language from a development perspective.
• If you plan on using Microsoft’s Visual Basic development environment, you
have spent some time using Visual Basic to get a feel for its interface and
capabilities.
The form acts as an application creation Italics are occasionally used for emphasis.
window.
“PowerCOBOL User’s Guide” References to other publications or chapters
See Chapter 6, “Creating an Executable within publications are in quotation marks.
Program.”
Trademarks
COBOL/2 is a registered trademark of Micro Focus International Ltd.
Microsoft, MS-DOS, Windows, Windows NT, Windows Server and Visual Basic are
trademarks or registered trademarks of Microsoft Corporation.
Oracle is a registered trademark of Oracle Corporation.
Other product names are trademarks or registered trademarks of each company.
Trademark indications are omitted for some system and product names described in
this manual.
Appendix B. Tips........................................................................................313
Index .........................................................................................................317
Product Reviewers
You may be reviewing NetCOBOL for the purpose of assessing its suitability for an
organization or writing an article. Chapters 1 and 2 aim to take you to the most
significant parts of the product's functionality as quickly as possible, so that your
time is used most effectively.
Because there is a wealth of functionality in the product, and your interest may be in
any part of the product, the guide may appear to be quite long. However, you will
find that you can work through the scripts quickly and can focus on the areas of
greatest interest by using the table of contents or the “Overview of the Guide
Through the Product” at the start of Chapter 2.
10 Chapter 1. Introduction
1
Partial dialect support. For full support see Fujitsu’s Dialect Converter and Processor
products.
12 Chapter 1. Introduction
A number of additional features are provided with the product and these are
described at the end of this chapter in the topic "Features of the Different NetCOBOL
Editions".
- You can specify the severity code at which runtime messages are output.
This makes it possible to output the level of messages appropriate to your
operating environment.
• Sanitizing is now supported in the Web programming subroutines, making it
possible to counter cross-site scripting vulnerabilities of Web applications.
Installing NetCOBOL
To install NetCOBOL insert the CD in your CD drive. The NetCOBOL Master Setup
should start. If it does not start, run “autorun.exe” from the root folder of the CD.
(For example, from the Start menu select Run, and enter “M:autorun.exe”, where
“M” is the drive letter of your CD-ROM drive.)
From the Master Setup screen select NetCOBOL Suite and follow the Setup
instructions in the dialog.
MAKE SURE YOU HAVE YOUR SERIAL NUMBER at hand when you run the setup as
you will be prompted to enter it.
The Master Setup screen gives you the option of installing other items such as online
documentation and add-on products that are provided with NetCOBOL. To install any
of these items simply select them and follow the installation instructions that are
displayed.
14 Chapter 1. Introduction
NetCOBOL Editions
NetCOBOL can be purchased in one of three editions: Standard, Professional and
Enterprise. The table below illustrates the contents of each of these editions.
Additional Features
The following list gives you brief descriptions of the more significant additional
features that make up your NetCOBOL product. The edition in which the feature
becomes available is shown in parentheses. Each of these features are described in
greater detail in feature-specific manuals or in the "NetCOBOL User's Guide", all of
which can be accessed from the Documentation Viewer, invoked from the Start,
Programs, Fujitsu NetCOBOL for Windows V8.0 menu.
• Precompiler Integration (Standard)
If your programs use features that need to be precompiled before compilation by
the NetCOBOL compiler, you can have the COBOL Project Manager invoke the
precompiler automatically whenever you build your application or compile your
program.
• Web Application Wizard (Standard)
Using HTML as input the Web Application Wizard can generate COBOL programs
that can support the data input and output using one of the following protocols:
CGI, ISAPI, and SAF
• CORBA Development Environment (Standard)
Tools and interfaces that support CORBA application development for both
traditional and OO COBOL programs.
• Project Browser and Class Browser (Standard)
Provide the ability to view relationships between classes and programs.
• COM/DCOM Integration (Standard)
Integration with products such as IIS2 and MTS3 is straightforward because of
the COM/DCOM support built into the product.
• COBOL Web Subroutines (Standard)
Subroutines are provided to simplify the process of writing Web-supporting
applications for CGI, ISAPI and SAF. Where appropriate the subroutines are
provided for other platforms, such as the CGI subroutines being available with
the Linux version of NetCOBOL, aiding application portability.
• GUI Application Development (Professional)
The PowerCOBOL component is a full wysiwyg development environment for GUI
applications. It uses COBOL to support the events and methods, enabling COBOL
programmers to quickly adapt to creating sophisticated GUI applications.
• GUI Report Design (Enterprise)
PowerFORM enables the creation of print forms and reports that can include
graphical elements such as lines, boxes, shading, pictures and bar codes. Its
programming interface is closely integrated with NetCOBOL.
• DB Access Class Library (Enterprise)
One of the foundation class libraries, provides the ability to access several
different DBMS's from OO COBOL applications.
2
Internet Information Server
3
Microsoft Transaction Server
16 Chapter 1. Introduction
Debugging
• Preparing for debugging - setting compiler options and building.
• Invoking the debugger - options available in setting the debugging
environment.
• Controlling execution - description of execution control functions and how to
access them.
• Breaking execution - setting simple breakpoints, breaking on change of data,
and breaking on a condition.
• Monitoring and changing data values - datatips, watching data, and the
detailed data dialog.
• Tracing execution path - overview of switching on recording and exploring
the execution path.
• Using the recording and playback functions - step-by-step instructions for
recording and playing back debugging commands or sessions.
• Debugging with Visual Basic - walk through a dual language debugging
session.
Using the configuration management functions
• Overview of PowerGEM structures - context setting for the configuration
management environment.
• How to set up a PowerGEM library - step-by-step instructions for setting up
a PowerGEM library.
• Using the configuration management functions from Project Manager -
how to check-out and check-in files, the effects of check-out, and overview of
other CM functions.
Working with OO COBOL
• Brief introduction to OO COBOL - concepts supported and a description of
the major constituents of OO COBOL.
• Guided tour of an OO COBOL application - an OO COBOL application
viewed from the Project Manager, COBOL editor, Project Browser and Class
Browser.
Chapter 2. A Quick Tour 19
2. Click on the Project Open button, , on the toolbar and navigate to the folder:
C:\Program Files\Fujitsu NetCOBOL for Windows\Samples\cobol\Sample05
- assuming that you used the default folder names when you installed the
products. Substitute your folder names if you overrode the defaults.
Chapter 2. A Quick Tour 21
Notice that you can immediately see that there are two parts to this project - an
EXE file and a DLL file. You would be correct in deducing that the program
within the EXE calls a program within the DLL!
22 Chapter 2. A Quick Tour
4. Fully expand the project tree by selecting View, Expand All from the menu bar.
(Or you can repeatedly click on the plus symbols, , in the project tree but that
takes longer!). The expanded tree looks like this:
Notice:
- You quickly have an overview of how the application sources are structured: a main
program, SAMPLE5.COB, calls a subprogram, PRINTPRC.COB, and they both share a
common copy library, S_REC.CBL.
- The chosen program structure uses a library file PRINTPRC.LIB.
- The different types of file are clearly distinguished by different icons.
- The icon for the main program, SAMPLE5.COB, stands out as it is colored red.
- The project tree is made up of folders and items. Folders contain collections of
associated items, and items are assembled from several collections. For example the
project folder contains two items, SAMPLE5.EXE and PRINTPRC.DLL. The
SAMPLE5.EXE item is made up of two collections: a collection of COBOL source files;
and a collection of library files (because the application is a simple one, each
collection only contains one item).
5. Right-click on various folders and items in the project tree.
Project Manager displays a pop-up menu with appropriate functions for the
selected folder or item.
You build project trees by using the New Folder and New/Add File functions.
Chapter 2. A Quick Tour 23
2. Make sure you select "Read as text without line numbers" and click OK.
The Editor displays the source code for SAMPLE5.COB.
Notice that readability of the code is aided by using different colors for
comments, reserved words and user-defined words.
We will make a trivial change to the program so that you can see Project
Manager's build function in action.
3. Make sure the status bar is visible by selecting View from the Editor menu bar.
If there is no check mark by "Status Bar" click on "Status Bar" and the status
bar will be displayed at the bottom of the window.
4. Scroll down until you get to line 61 (the line number is displayed in the status
bar). Line 61 contains the text:
Setting compiler and linker options: Had you wanted to change the
compiler or linker options before building, you would have selected
SAMPLE05.PRJ in the project tree view and, from the menu bar, selected
Project, Option, Compiler (or Linker) Options. These functions display dialogs in
which you can set the options. You are offered lists of all the compiler options
and dialogs explaining the supported options, so you do not have to remember
all those details.
Note: SAMPLE5 prints a single sheet of data to your default printer. If this is
likely to cause a problem do not execute the steps 4, 5 and 6.
Debugging
This section guides you through a number of the key debugging functions.
This dialog gives you the opportunity to specify information that may affect your
debugging session, such as: the locations of various source and system files, the
option to have the debugging session driven by a command file, and even which
program you first want to see in the debugger. Although the defaults will work
for you most of the time, the ability to configure this information at start-up is
invaluable in certain situations, such as debugging with other languages. (See
"Debugging with Visual Basic" below).
3. For this debugging session you do not need to specify any extra information so
click OK.
4. The COBOL Debugger displays Sample5.cob. It highlights the first executable
line in the procedure division.
Chapter 2. A Quick Tour 29
You are now ready to explore the program using the debugging features.
C. Controlling Execution
Location
The execution control functions are located on the Continue menu, and a number of
them are available on the toolbar:
Hover the mouse pointer over a button to display a tooltip confirming the function of
the button.
Description
Run to Cursor:
Runs the program up to the statement containing the cursor.
Step Over: Executes one statement and stops on the next statement in the
current program, regardless of whether the current statement
transfers control to another debuggable program.
Step Out: Runs the current program, interrupting execution when control
passes to the calling (debuggable) program.
D. Breaking Execution
In addition to specifying points to which execution should run in the execution
control functions, there are three other ways of breaking execution:
• Setting breakpoints
• Breaking on change of data
• Breaking on satisfaction of a specified condition
Breakpoints
1. To set a simple breakpoint - right click on the line to contain the breakpoint
and select "Set Breakpoint" from the pop-up menu.
2. To set a more complex breakpoint, select Breakpoint from the Debug menu.
You can specify that execution should only be interrupted at the line if a
condition is also satisfied, or if the line has been executed a particular number
of times. You can also maintain a list of breakpoints enabling and disabling them
depending on your debugging situation.
Break on Change of Data
To have the debugger interrupt execution when the value of a data item changes:
1. Right-click on the data item name, anywhere that it occurs in the text, and
select Add Watch Data from the pop-up menu.
The debugger displays the Add Watch Data dialog with the data and program
name fields already filled in:
2. Select any options you require, such as “Break at change of value” and click OK.
The item is added to the Watch window - shown below with two items:
MASTER-RECORD and PARAMETER-LEN.
32 Chapter 2. A Quick Tour
The check box indicates that any change in PARAMETER-LEN causes a break in
execution – the red colored text indicates a break on change of value has just
occurred.
The queries in the MASTER-RECORD entry indicate non-character values (in this
case LOW-VALUES as the record has not yet been read).
The “…” in the MASTER-RECORD entry indicates there is more data than
displayed in the window.
3. You can check and uncheck the checkboxes in the Watch window to monitor
different items for changes.
Break on Condition
To have the debugger interrupt execution when a particular condition is satisfied:
It then monitors the condition and interrupts execution when the condition is
satisfied.
Figure 2.14. Hover the mouse pointer I-bar over "PARAMETER-LEN" and the
debugger displays the value of that item.
34 Chapter 2. A Quick Tour
To add an item to the Watch Data window, right click on the item name, and select
"Add Watch Data" from the pop-up menu.
Alternatively display the Data dialog, enter the data name and click on the Watch
button.
To edit an item in the Watch Data window, just click on the value and enter the new
value.
Debug, Data Dialog
The Debug, Data dialog lets you:
• Enter a data name, including names of items in any loaded program.
• For recursive programs you can specify the call level at which to view the data
item.
• View the value of the item in character or hexadecimal formats.
• Edit the value.
• Add the item to the Watch Data window.
To display the Debug, Data dialog select Data from the Debug menu.
The following instructions record and playback a very simple sequence but they
demonstrate the principles required to set up much more complex debug recordings.
We will record some steps, and play the recorded file while recording a new file.
1. If you have been debugging using Sample5, select Continue, Redebug to
initialize the debugging session. If you have not been debugging Sample5 start
the debugger with Sample5.
2. From the Option menu select Output Log.
The debugger displays the Output Log dialog:
The History file is the file to which the debugger writes a record of the
operations performed with the results of those operations.
3. Enter "Recording1" for the name of the history file.
4. Click on the Start button to start recording.
5. Click on the Close button to close the Output Log dialog window.
6. Click on the Step Into button, , two times to execute two statements.
7. Right click on the data name "WORK-FILE-NAME" and select Data from the pop-
up menu.
The debugger displays the Data dialog.
There is nothing in WORK-FILE-NAME - it is all spaces (which you can check by
switching to Hexadecimal - an ASCII space is "20" in hex).
8. Click on the Output Log button in the Data dialog.
The debugger writes information about WORK-FILE-NAME to the log file.
9. Click on the Close button to close the Data dialog.
10. From the Option menu, select Output Log, and click on the End button.
This stops the debugger logging each operation.
11. Click on the Close button to close the Output Log dialog.
So, to recap, you have recorded stepping two statements, and checking the value of
WORK-FILE-NAME.
12. Now open the Recording1.log file by starting Windows Explorer (right click on
the Start button in the Windows task bar, and select Explore from the pop-up
menu) and navigating to the folder:
C:\Program Files\Fujitsu NetCOBOL for Windows\Samples\cobol\Sample05
36 Chapter 2. A Quick Tour
Then double click on the file "Recording1.log" to bring up the file in the COBOL
Editor.
Your recording should look something like this:
Notice that the log file consists essentially of two types of lines - debug commands or
operations (ENV, RUNTO, LIST), and comment lines starting with ";". The comments
describe the commands and display results of the commands. Because the results
are output as comments you can use the log file as input to the debugger - it ignores
the comments and executes the commands.
The command file is any file containing debug commands. We will use the first
log file we created.
16. Click on the Browse button to display a list of available command files.
The debugger displays all files with a .log extension.
If necessary navigate to the folder containing your log file.
17. Select Recording1.log and click on Open.
You return to the Automatic Debugging dialog with the file name in the
Command file entry field.
18. Click on OK to run the command file.
The debugger displays an information message that it is ignoring the DBTR
option in the command file. (The ENV, DBTR option starts history files, and is
not supported when running command files - we'd normally edit the log file to
remove this option.)
19. Respond OK to the message.
The debugger executes the commands in the Recording1.log file (two steps and
one check of data item contents).
20. Stop writing to the Recording2 output log by selecting Option, Output Log from
the menu bar, and clicking on End.
21. Now open the Recording2.log file by returning to Windows Explorer (select
Exploring from the Windows task bar) and double clicking on the Recording2.log
file to bring it up in the COBOL Editor.
38 Chapter 2. A Quick Tour
Figure 2.19. Log file resulting from playing back some recorded operations.
The form accepts two numbers and displays the result of multiplying those numbers
when the "=" button (Command1) is pressed.
The Command1 code invokes the Sample13 DLL created using NetCOBOL:
Chapter 2. A Quick Tour 41
There are two other pieces of code you should note, although we will not discuss
them further in this guide. They are the calls to JMPCINT2 and JMPCINT3. These
calls initialize and close the COBOL run-time system.
10. Execute the Visual Basic code by repeating the Debug, Step Into function
(available on the Visual Basic Debug menu, and the Debug toolbar).
11. When the Sample13 dialog displays, enter two numbers and click on the "="
button.
12. Continue stepping up to, and into, the statement:
Call SAMPLE13 (ar%, br%, C)
Debug the COBOL Code
13. Control passes to the COBOL code. The runtime system recognizes that the
COBOL debugger should be invoked (because the @CBR_ATTACH_TOOL
environment variable is set) so starts the debugger.
The debugger displays the Start Debugging window.
42 Chapter 2. A Quick Tour
Figure 2.23. The Start Debugging dialog when invoked from Visual Basic.
14. The debugger displays "VB6.EXE" as the application being executed. This is the
application to which the debugger attaches. You need to be aware of this
because you cannot close the debugger until you close Visual Basic.
You need to confirm two locations to the debugger: on the Source and
Debugging Information tabs.
15. Select the Source tab and click on the Browse button by the "Source file storage
folders" entry field.
The debugger displays the "Browse for Folder" dialog.
16. From the folder list select
C:\Program Files\Fujitsu NetCOBOL for Windows\Samples\cobol\sample13
17. Select the Debugging Information tab and click on the Browse button.
The debugger displays the "Browse for Folder" dialog.
18. Again select:
C:\Program Files\Fujitsu NetCOBOL for Windows\Samples\cobol\Sample13
19. You have now ensured that the debugger can find the COBOL source files and
debugging information.
20. Click on OK to display the source in the COBOL debugger.
Chapter 2. A Quick Tour 43
You can use all the COBOL debugging functions to debug this program. We will
simply step through its three statements.
21. On the COBOL debugger toolbar, click the Step Into button, , three times.
The debugger steps through the code. When the EXIT PROGRAM statement is
executed, control returns to the Visual Basic debugger (the Visual Basic button
on the task bar may flash to indicate you need to switch control to that
window).
22. Continue stepping through the Visual Basic code, and select the Sample 13
window to see the result displayed.
Through this simple example you have seen how complex mixed Visual Basic and
COBOL applications can be debugged effectively.
We'll work with Sample05 so click on the plus icons, , in the left-hand pane to
navigate to:
C:\Program Files\Fujitsu NetCOBOL for Windows\Samples\cobol\Sample05
Note: The controlling part of PowerGEM runs as a background task so you will see a
second task, PowerGEM Plus, on the Windows task bar. This continues to run while
tools that use it are running. However, it does not have an interface so selecting the
button on the task bar has no effect.
2. From the CM (Configuration Management) menu select Utility.
Development Manager invokes the CM Utility dialog.
46 Chapter 2. A Quick Tour
The Folder name indicates where the GEM library will be created.
The Browse button actually sets the Folder Name, not the Library Name as its
position might suggest.
4. We will create our GEM library in the C:\Program Files\Fujitsu NetCOBOL for
Windows\PGEM" folder, so click on Browse, navigate to the folder:
C:\Program Files\Fujitsu NetCOBOL for Windows\PGEM ,
and click on Open to select the folder.
Chapter 2. A Quick Tour 47
Figure 2.28. The Create GEM Library dialog after selecting the folder name and
entering the library name.
6. Click on OK.
PowerGEM creates a library called Samples.
Note: PowerGEM uses hidden folders for storing the library data. So you will not
see the Samples library in the PGEM folder unless you have configured your
listing program (e.g. Windows Explorer or Development Manager) to display
hidden files.
7. Close the CM Utility dialog by clicking on the Cancel button.
48 Chapter 2. A Quick Tour
Workspace Name is the name of the folder selected when the Map function is
invoked. The folder becomes a workspace at the completion of this function.
Folder Name and Library Name specify the PowerGEM library to be mapped.
These can be set by the Browse button.
The Member Name field can be used when existing libraries are mapped to new
folders. You can specify which members to map to the folder. As we do not yet
have any members in the Samples library we won't use this field.
Chapter 2. A Quick Tour 49
9. Click on Browse and select the Samples library from the PGEM folder. (The
"Select Library or Member" dialog uses the icon to indicate PowerGEM
libraries).
You are now ready to add files to the PowerGEM library. We will just add the
COB and CBL files. For a real project you would add all the files you wanted to
control including object files as well as source files.
19. In the right-hand pane of the Development Manager window select the following
files by keeping the Ctrl key depressed and clicking on each one in turn:
printprc.cob
s_rec.cbl
sample5.cob
20. From the CM menu select Add.
The selected files are added to the Samples library.
The file icons change from white, , to blue, .
You now have a PowerGEM library and workspace that you can use to review
the CM functions in Project Manager.
If you want to delve into Development Manager more deeply, see the topic
"Understanding PowerGEM Development Manager" in “Appendix B. Tips”.
Chapter 2. A Quick Tour 51
Figure 2.33. COBOL Project Manager displaying library control and check-out icons.
Now check the difference between a checked-out file and one that is not
checked-out.
8. Double-click on SAMPLE5.COB to invoke the editor.
SAMPLE5.COB is displayed in the editor.
9. Press a few character keys.
Text is entered in the file.
10. From the File menu select Exit Editor and respond No to the "Do you want to
save?" dialog, so that your arbitrary changes are not saved.
11. Double-click on S_REC.CBL to invoke the editor.
S_REC.CBL is displayed in the editor.
12. Press a few character keys.
Nothing happens - because the file is not checked out you are not allowed to
make changes to it.
Chapter 2. A Quick Tour 53
The tree is similar to those for standard COBOL applications. It shows that
MAIN.EXE is built from several COBOL source files (ALLMEM.COB,
BONU_MEM.COB, etc.) and uses .DLLs defined in COLLECT.LIB.
The tree is different from those for standard COBOL applications in that
repositories have been added to the tree. These nodes show the repositories
that are either created by a particular source file (target repositories) or that are
referenced by the source file (dependent repositories).
Once you specify an application's source structure you can have Project
Manager figure out the repository information by using the "Repository File
Search" function on Project Manager's Edit menu.
The repository information helps identify the function of the different source
files. For example:
MAIN.COB is a standard COBOL program that uses an OO class system for its
functions. It therefore references several different classes.
ADDRESS.COB is a class definition, hence it has a target repository. It only
inherits from the FJBASE root class so it does not have any dependent
repositories.
ALLMEM.COB has a target repository and is therefore a class definition. It
references an item in the ADDRESS class so has a dependent repository.
5. Double-click on ALLMEM.COB.
6. Scroll past the initial (green) comments to the (blue and black) COBOL source.
Notice:
- The CLASS-ID paragraph. This is actually part of the IDENTIFICATION DIVISION
but the IDENTIFICATION DIVISION header is optional so you will often see a new
code structure starting with its identifying paragraph (CLASS-ID, FACTORY, OBJECT,
or METHOD-ID).
- The INHERITS clause in the CLASS-ID paragraph indicating the class this class
inherits from - in this case the system base class FJBASE.
- The methods starting with METHOD-ID, ending with END METHOD, containing data
and procedure code.
- At the end of the source file, the END OBJECT and END CLASS, delimiters.
Although some new elements have been introduced, the general structure and layout
Chapter 2. A Quick Tour 57
10. You can invoke the Project Browser by selecting, Tools, Project Browser from
the Project Manager menu bar.
Project Manager invokes the Project Browser tool with the SAMPLE18 project
already loaded:
The left pane provides a tree view of the classes being used by the project.
The right pane provides details about the item selected in the left pane.
11. Expand one of the nodes in the left-hand pane, for example the ALLMEMBER-
CLASS.
The Project Browser expands the tree to show classes that inherit from this
class, referenced classes, methods, properties and inherited methods. See the
Project Browser Help for a description of the different icons. Sharp icons denote
items defined within the selected class, faded icons denote items defined
outside the class (generally these are inherited items).
12. Select different items in the left-hand pane and note the information that is
presented in the right-hand pane, such as arguments required for methods and
data descriptions of properties.
Notice that the Project Browser includes non-OO elements, like the MAIN
program - an essential part of the project, but not part of the OO system.
Now we'll switch to the Class Browser for a slightly different view on this
application.
13. Close the Project Browser and return to the COBOL Project Manager, where we
will create a class information database.
Chapter 2. A Quick Tour 59
The Class Browser has a similar appearance to the Project Browser with the
following differences:
- Class Browser only displays OO class information.
- Classes within class browser can come from many different projects and
application areas.
- Class Browser does not display source file name information.
- You can select whether Class Browser should expand classes up or down the
class hierarchy.
21. Experiment with browsing the Sample18 classes. Note how the Class Browser
helps you understand the relationships between the classes and the interfaces
available in each class.
For more information on OO COBOL consult chapters 14 - 17 in the "NetCOBOL
User's Guide".
Other Options
COBOL Project Manager provides many other functions such as:
• Invoking various tools individually from the Tools menu including the compiler,
linker, debugger and editor.
• Integrating pre-compilers into your system.
• Working with CORBA objects (Object Director).
• Configuring certain parts of your environment.
For details of these functions see the on-line help for COBOL Project Manager and
the “NetCOBOL User’s Guide”.
62 Chapter 2. A Quick Tour
Chapter 3. Developing GUI Applications
This chapter sets the context for developing GUI applications in COBOL. It is
descriptive in nature, providing a background for those who like to know more
details.
A Brief History
It is generally agreed that COBOL programs make up anywhere from 50-75% of the
world’s current business applications. Today COBOL programmers need a modern,
powerful, and easy to use development environment that fully exploits the Microsoft
Windows family of operating systems for both development and production.
The Microsoft Windows family of operating systems has become the preferred end
user platform for the vast majority of PC users. A number of pitfalls arose, however,
as traditional COBOL programmers from the mainframe world attempted to embrace
this exciting new platform.
Primarily, the intense time and complexity of low level Windows API (application
programming interface) programming prevents most developers from creating
sophisticated graphical user interfaces using traditional 3GL (3rd generation
language) compilers and tools.
Two approaches have been developed to deal with this problem. The first is to
extend the COBOL language itself to encompass GUI capability directly in the
language. This approach offers the advantage of using a single COBOL development
environment, and keeping the entire application in native COBOL. Fujitsu’s flagship
PowerCOBOL product is the best example of such an approach.
The second approach is to separate the user interface from the actual COBOL
application and have it managed by a wholly separate facility. Some COBOL vendors
have attempted to deliver such a combination, but these have fallen short for a
variety of reasons. Primarily, these environments have proven to be highly unstable,
lacking in many features, and very proprietary in nature. Additionally, these
environments have been in a constant state of flux as vendors attempted to deliver
better stability and a wider array of functionality. The results have typically been less
than successful for developers.
In recognizing these challenges, Fujitsu has developed the world’s premier COBOL
GUI and client/server application development environment -- Fujitsu’s flagship
PowerCOBOL product line.
Fujitsu has also recognized the need for a world class COBOL development product
that will integrate, coexist and exploit Microsoft’s Visual Basic development
environment.
If you want to develop full-fledged GUI applications, you should explore Fujitsu’s
PowerCOBOL product. If you have the Professional or Enterprise editions of
NetCOBOL, you have probably already installed the product. If you have NetCOBOL
Standard edition, you can check the NetCOBOL web site (www.netcobol.com) for
more details. You may additionally use Microsoft’s Visual Basic (version 4.0 or later)
with this product to develop GUI applications.
Visual Basic was an attempt to bring out a 4GL-like development environment that
would allow programmers and even non-programmers to develop GUI applications in
64 Chapter 1. Developing GUI Applications
the Windows environment. Users could visually ‘paint’ the user interface, and then
create the rest of the application by writing small snippets of code using a
proprietary scripting language that was loosely based upon the BASIC programming
language.
Initially, Visual Basic was lacking for serious business application development.
Microsoft has continued to evolve Visual Basic over the years into a serious
development environment. Today it is a strong development tool for a wide number
of professional developers who want to rapidly create GUI applications for the
Windows family of platforms.
For the users of COBOL applications, however, Visual Basic presents a number of
substantial challenges:
• Having no relationship to COBOL, Visual Basic presents an alien development
environment to COBOL programmers. They must learn an entirely new
development methodology and language.
• Visual Basic does not provide all of the facilities found in the COBOL language.
• Prior to NetCOBOL, Visual Basic could not easily be inter-mixed with COBOL
programs to combine the best of both worlds, and to allow the re-use of existing
COBOL programs.
Many COBOL programmers have requirements to re-host applications (move COBOL
applications from another platform such as the mainframe) to the PC environment.
At the same time they want to re-design traditional text-based interfaces to take
advantage of GUI.
While some COBOL vendors attempted to provide ‘bridges’ to allow Visual Basic to
intermingle with COBOL, these approaches typically fell short.
One of the major inhibiting factors in inter-mixing other vendor’s COBOL with Visual
Basic related to the fact that each had it own separate and complex run-time system.
Mixing two very proprietary run-time systems is a substantial undertaking. Most
legacy run-time systems were architected and developed by their respective vendors
long before PC’s, Windows and GUI’s were even invented.
NetCOBOL
NetCOBOL is a complete COBOL development environment that allows you to create
standalone COBOL applications and/or COBOL components for use with Microsoft
Visual Basic and Visual C++ applications.
The COBOL Project Manager is a 32-bit project-oriented development environment
that provides integrated access to an editor, compiler, interactive debugger,
execution environment, and other supporting tools. A sophisticated data file editor is
also included. It supports all COBOL data file types, and provides editing, conversion,
printing, sorting, reorganizing and recovery capabilities.
For previous users of Micro Focus’ or Microsoft’s COBOL/2, dialect conversion
products are available to aid in converting COBOL programs using some of the Micro
Focus proprietary extensions to run under NetCOBOL. See the www.adtools.com
Web site for more details.
Fujitsu PowerBSORT OCX is also included. PowerBSORT OCX is callable from any
Windows application that supports OCX’s (for example, Microsoft Visual Basic).
PowerBSORT OCX online help is provided along with sample applications for Visual
Basic 4.0 and 5.0. The online help and sample files are automatically installed along
with PowerBSORT OCX.
Event-driven Programming
In order to begin developing GUI COBOL applications in the Windows environments,
it is important to understand the concept of event -driven programming.
While the term ‘event driven’ may be somewhat new in the computer industry, the
concept has been around for a long time, and chances are that if you are a COBOL
programmer, you already understand it.
When COBOL programmers first began developing mainframe-based applications
that interacted with users (e.g. non-batch style applications), they were constrained
to simple line-oriented ACCEPT/DISPLAY syntax.
Later, on-line transaction monitoring systems such as IBM’s CICS and IMS/DC
enhanced this capability to handle full screen-oriented interaction (as opposed to line
oriented). Some PC COBOL vendors later enhanced the COBOL ACCEPT/DISPLAY
verbs in non-standard ways to provide full screen interaction.
While one could argue that none of these techniques qualified as event-driven
programming, they were in fact, a primitive form of this approach.
Event-driven programming breaks the user interface portion of a GUI application
(screen I/O, keyboard I/O, mouse I/O, and a few other possibilities), into a series of
possible events.
These events include user actions such as pressing a key on the keyboard, moving
the mouse, clicking the mouse on a screen object such as a button, holding the
mouse button down and dragging the mouse to move a window, and so forth.
Writing a proper Windows GUI application entails creating all of the potential
windows and objects that the user may interact with (including output objects as
66 Chapter 1. Developing GUI Applications
well), determining all of the possible events that may occur, and then creating a link
between each potential event and your application code to handle the event.
What you aim to end up with is an application that registers its user interface with
Windows (in much the same approach as CICS and IMS/DC applications register
themselves in the mainframe world). Once the application is registered, Windows
recognizes events and sends event driven messages to the application for resolution.
The registration and event handling processes are based upon the Windows message
queue paradigm.
include being forced to re-paint the screen because another application’s window
was placed on top of your application’s window. (Windows does not automatically
keep track of the layering of application windows and will not automatically restore
the prior contents of a window that was briefly overlaid.)
Using NetCOBOL
Creating COBOL applications to run standalone or under Visual Basic is a flexible and
straightforward process. Developers typically follow the steps below:
• Application analysis and design.
• For GUI applications, creation and testing of the user interface using Visual
Basic’s development environment.
• Creation and testing of the COBOL component(s) of the application using the
COBOL Project Manager development environment.
• Testing and continued development of the overall application that is run under
the initial control of Visual Basic when it is a GUI application.
It is worth noting that both Visual Basic and NetCOBOL offer extensive dynamic
development environments, making it easy to move between the two when creating
and testing applications.
Additionally, both environments provide extensive development support tools to aid
the process.
NetCOBOL standalone .EXE files (executables) or .DLL files (dynamic link libraries) do
not have to be physically linked into a Visual Basic application and may be called
dynamically at run- time by Visual Basic.
Doing away with the requirement to link all of this together allows you to work off-
line on either end of the application. That is, you may work on and test the user
interface under Visual Basic, or work on the COBOL component(s) in the COBOL
Project Manager without having first gone through Visual Basic.
Because of the dynamic nature of the two development environments, you do not
necessarily have to follow the above steps in order. You could first develop and test
the COBOL components and then design the user interface in Visual Basic. The
important point is that when it comes time to execute the overall application, you
should have the interface and the COBOL components available.
Chapter 4. Working with Visual Basic and
COBOL
This chapter teaches you how to mix COBOL and Visual Basic. It starts by walking
you through your first Visual Basic COBOL application it then precedes to the details
of integrating COBOL with Visual Basic.
The arrival of NetCOBOL has brought seamless integration with operating system
services and other languages to COBOL developers. Visual Basic integration is but
one example of the excellent mixed language programming support found in
NetCOBOL.
The integration point between NetCOBOL and Visual Basic is the creation of a DLL
(dynamic link library) file from NetCOBOL.
Instead of producing a standalone executable (EXE) file within the COBOL
development environment, you instead produce a DLL file. You can think of a DLL file
as a dynamically callable COBOL subprogram, which does not have to be physically
linked to a program that calls it and may even pass data back and forth.
To create a proper DLL, the linker needs to be given the name of the DLL to be
produced, and the names to export.
Exported names are the names of entry points contained within the DLL file which
are to be made public to allow other applications to call them after the DLL has been
identified to the operating system.
You are going to create a simple DLL file called HICOBOL.DLL, which will contain a
single exported entry point - the program name. The program name entry point will
cause a calling program to enter the program at its first executable statement in the
PROCEDURE DIVISION.
Once you have written the HICOBOL.COB program and have created the
HICOBOL.DLL executable, you will exit NetCOBOL and enter Visual Basic to design
the graphical interface.
While in Visual Basic, you will create a graphical user interface (GUI) for your COBOL
application, which will call the HICOBOL.DLL program. Data will be passed back and
forth as well.
To identify the NetCOBOL DLL to the Visual Basic program, you will code three
simple Visual Basic DEFINE statements. One is for the NetCOBOL run-time load
program. Another is for the NetCOBOL run-time unload program. The final DECLARE
statement is for the HICOBOL.DLL executable you are going to create.
In order to get a NetCOBOL DLL program to work with Visual Basic, you need to first
issue a single call from Visual Basic to ensure that the COBOL run-time support is
properly loaded.
You then code a single Visual Basic statement to call the HICOBOL.DLL program and
pass data to it.
Finally, you code a call to unload the COBOL run-time support when finished.
That’s all there is to it.
From an architectural standpoint, when you develop future, more complex Visual
Basic COBOL applications you will arrange things slightly differently than in the
following example. The main reason for this is that you only need to load the
NetCOBOL run-time once at the start of your application, and issue the unload call
just before you exit your Visual Basic application.
To keep the example simple and straightforward, you are going to code all three
calls together (load the COBOL run-time, call HICOBOL, unload the COBOL run-time).
Chapter 4. Working with Visual Basic and COBOL 71
4. Locate and click on the Create New Folder button to the upper right of the
dialog.
This creates a new folder in the Samples folder, called “New Folder”, with the
text already selected.
5. Change the name of the folder to HICOBOL, by typing:
HICOBOL, and click on ENTER.
7. In the File Name field, enter the name of the new project, HICOBOL, and click
on the Open button.
Project Manager displays the following message:
Because we are not planning to create any other executables, you will now define
the files that will be used to create this DLL.
11. Right-click the mouse on HICOBOL.DLL and select Create Folder from the pop-
up menu.
Project Manager displays the Create Folder sub-menu:
74 Chapter 4. Working with Visual Basic and COBOL
This menu offers the types of files upon which HICOBOL.DLL might depend. You
need to create just one folder - for the COBOL source file.
12. Select “COBOL Source File”.
Project Manager adds a “COBOL Source File” folder to the project tree.
13. Right click on “COBOL Source File” and select “New File” from the pop-up menu.
14. Overtype “NewFile.COB” with “HICOBOL.COB”.
The project tree should now look like this:
You are now ready to construct the HICOBOL.COB source program. The
quickest way to do this is to use the Editor’s template function.
16. From the Edit menu select Template.
The Editor displays the Template dialog.
17. Expand the COBOL basic functions, Source unit nodes in the Categorization of
template tree:
76 Chapter 4. Working with Visual Basic and COBOL
18. Select “Source program structure (External program definition)” from the list of
Template name and click the Expand button.
The Editor inserts the template code.
19. You can now see the code that has been inserted in the Editor:
Chapter 4. Working with Visual Basic and COBOL 77
20. Uncomment the LINKAGE SECTION header, delete other unwanted comment
lines, and insert the text shown below to create the HICOBOL program:
If you examine the HICOBOL program, you will understand what it does quite
easily. Note that it contains a LINKAGE SECTION and thus needs two
parameters passed to it, each time it is called.
The vbInteger parameter is always set to the value of 100. The vbString
parameter is always set to the value of "Hello from COBOL".
These parameters will be defined in the Visual Basic application and passed to
the COBOL program. They are passed by reference – meaning that the COBOL
program gains access to the data areas in the Visual Basic program. The COBOL
program updates the values and returns control to the Visual Basic program.
21. Select Save from the File menu to save the program.
22. Select Close from the File menu to close the Editor.
You are nearly ready to build the HICOBOL.DLL executable.
23. Return to the COBOL Project Manager window, select HICOBOL.PRJ in the
project tree and, from the Project menu, select Options, Linker Options.
Project Manager displays the Linker Options dialog:
Chapter 4. Working with Visual Basic and COBOL 79
Project manager recognizes that the source file has been updated since the last
build and recompiles and relinks the appropriate parts of the project (in this
case all the parts).
Once you have a successful build (or rebuild) of your application, the following is
displayed in the Builder window:
You have now completed the COBOL development side of this application.
This window asks you to specify which type of application you are going to
develop. You are going to develop a Standard EXE so:
2. Select Standard EXE and click on the Open button.
Visual Basic displays the following window (or one like it, depending on which
display options you have set):
82 Chapter 4. Working with Visual Basic and COBOL
You should already be familiar with this environment. If not, it is strongly suggested
that you go through the Visual Basic “Your First Visual Basic Application” tutorial in
“Getting Started with Visual Basic” (or “Visual Basic Programmer’s Guide” – earlier
versions).
In the center of this window is an object named Form1. This will become our main
application window. You are going to create a text box and two command buttons on
this form.
In the Properties window, enter "Hello from Visual Basic" in the Text property
value.
You will notice that it instantly changes in the text box on Form1.
7. Change the Caption value (the text displayed on the command button) from
Command1 to Hello COBOL, in the Properties window.
8. You may reposition the command button or the text box by selecting either with
the mouse and dragging the selected object to the position you desire on the
form.
9. Now place a second command button on Form1 between the text box and the
first command button by repeating steps 3 to 5 above. Change the caption value
to “Reset”.
Form1 should now look like this:
Figure 4.18. Reset command button added to the Visual Basic form.
12. Click the mouse on the Close button (the X in the upper right hand corner) of the
program code window you just typed in.
Implementing the Hello COBOL Button
The Hello COBOL command button is where most of the action in this application will
take place. When a user clicks on this button, Visual Basic will call the HICOBOL.DLL
executable and pass two parameters to it.
The COBOL program will update both parameters and return control to the Visual
Basic program. Visual Basic will take the value of the string parameter (which the
COBOL program will change to "Hello from COBOL") and update the text box value
with it.
You need to perform the following steps at this point:
13. Move the mouse over the Hello COBOL command button and double click on it to
open up a program code window.
86 Chapter 4. Working with Visual Basic and COBOL
14. Enter the following code in the new code window between the Private Sub and
End Sub statements:
Let’s look at what each of the above noted statements does at run-time:
Dim vbInteger as Integer - This defines a numeric data item named
vbInteger.
Dim vbString as String * 16 - This defines a character string of 16
characters named vbString.
Call JMPCINT2 - This calls the supplied NetCOBOL routine which initializes the
COBOL run-time support. It need only be called once per application.
Call HICOBOL (vbInteger, vbString) - This calls the COBOL DLL file you
previously created, and passes the two parameters to it.
Text1.Text = vbString - This command instructs Visual Basic to update the
Text string in the Text1 text box with the value contained in vbString, which will be
returned from the HICOBOL COBOL program.
Call JMPCINT3 - This calls the supplied NetCOBOL routine which unloads (exits)
the COBOL run-time support. It need only be called once per application.
Your Code window should look like this:
15. While the program code window shown above is still open, click on the small
down arrow to activate the drop down box that currently has the value
Command1. This box is located in the upper left of the project code window. It
should appear as follows:
This drop down list box allows you to navigate through your program source
code for each event subroutine you have defined. You need to go to the General
section of your program to create declarations for the external COBOL
executables.
16. Click on (General).
17. Enter the following 3 statements in any order (as one long string each) in the
program code window in the General Section area:
The three statements above have been wrapped to multiple lines because of the
page size of this manual. They should be entered into the program code window
as a single line each (not wrapped).
These statements define to Visual Basic where the external COBOL modules that
will be referenced at run-time reside. Be sure to alter the path settings above
when entering these if you changed the default installation directory when you
installed NetCOBOL to reflect your machine’s installation location.
88 Chapter 4. Working with Visual Basic and COBOL
the global module, and must be declared as Private. You can then call these routines
from your Visual Basic code like any other function call.
When a Visual Basic program calls a COBOL routine, you should call JMPCINT2
before calling the first COBOL routine, and call JMPCINT3 after calling the last COBOL
routine. JMPCINT2 is a subroutine that initializes the COBOL Run Time Environment
and JMPCINT3 is a subroutine that exits the COBOL Run Time Environment.
Calling COBOL routines without calling JMPCINT2 and JMPCINT3 may degrade
performance because the COBOL Run Time Environments will be initialized and
exited on every COBOL routine called.
NOTE: The above Declare statements should all be on a single line, they have been
wrapped in this text to fit the width of the page.
Parameter names need not be the same between Visual Basic and COBOL, however,
attribute, length, and number of corresponding data items must be identical.
Visual Basic declarations must exactly match the COBOL parameter lists defined in
the USING statement of the COBOL PROCEDURE DIVISION or ENTRY statements. No
parameter checking is done because the two are separate compilation units.
Visual Basic incorporates a rich assortment of data types, some of which are
currently not supported by NetCOBOL. These data types include variable-length
strings, Variants, and objects.
Similarly not all COBOL data types are supported by Visual Basic.
Passing Arrays
Visual Basic and COBOL can pass numeric arrays. This works because numeric array
data is always laid out sequentially in memory. A COBOL routine, if given the first
element of an array, has access to all of its elements.
92 Chapter 4. Working with Visual Basic and COBOL
You can pass Currency parameters if the receiving Linkage Section item has this
picture clause.
A Visual Basic declaration of a COBOL subroutine receiving the Currency data type
would look like the following:
NOTE: The above Declare statements should all be on a single line, they have been
wrapped in this text to fit the width of the page.
CSPRINT is the COBOL subroutine; JMPCINT2 and JMPCINT3 are required for mixed
language applications including Visual Basic and COBOL.
The code leading to, and including the subroutine call would look like this:
Dim cc As Currency
cc = 100.0001
Call CSPRINT(cc)
The COBOL program processing the COMP-5 equivalent of Currency would look the
following:
IDENTIFICATION DIVISION.
000020 PROGRAM-ID. CSPRINT.
000030 ENVIRONMENT DIVISION.
000061 DATA DIVISION.
000101 LINKAGE SECTION.
000102 01 CC PIC S9(14)V9(4) COMP-5.
000110 PROCEDURE DIVISION WITH STDCALL USING CC.
000150 ADD 1 TO CC.
000160 EXIT PROGRAM.
LIBRARY "dll-name"
EXPORTS PROG
You then save this file as “prog-name.DEF”, where prog-name is the name of your
program.
Add it to your project by right clicking on the DLL file node and select New Folder,
Module Definition File, from the pop-up menu. You then add the .DEF file to that
folder.
94 Chapter 4. Working with Visual Basic and COBOL
Chapter 5.
Using SQL with COBOL
This chapter describes the steps required to setup your environment to access SQL
databases using ODBC. It first gives you an overview of ODBC and the general mode
of working with SQL databases, then goes into the details of setting up your
environment. In particular it covers:
• Defining SQL databases.
• Defining an ODBC data source.
• Setting up NetCOBOL runtime information.
Introduction
NetCOBOL applications can contain sophisticated processing logic that interacts with
SQL database systems. The technology that is used to interface to these databases is
known as ODBC (Open Database Connectivity), which provides a standard and
generic mechanism for any number of applications to access SQL data in a relational
matter.
The following sections deal specifically with how to set up the interface between a
NetCOBOL SQL program and SQL databases. It concludes with some tips identifying
potential runtime problems with NetCOBOL SQL applications.
Note that the samples and screen pictures are from a Microsoft Windows 2000
environment. You may experience some differences on Windows 98, Windows Me,
Windows XP, Windows NT 4.0 and Windows Server 2003 systems, but these should
be easy to determine.
In NetCOBOL, you code your programs using embedded SQL statements and host
variables. For information on writing SQL code in NetCOBOL programs, refer to
“Chapter 19. Database (SQL)” of the “NetCOBOL User’s Guide for Windows”. This
chapter covers the information you need to know to set up an environment that
supports such programs.
Note that when creating NetCOBOL SQL applications you can access any number of
SQL databases available to you within a single application.
Figure 5.1. Checking for Data Sources (ODBC) software under Windows 2000.
If you do not have Data Sources (ODBC) installed on your Windows machine, check
with your software administrator about obtaining it and installing it properly.
Figure 5.2. The ODBC Data Source Administrator under Windows 2000.
Note that your Data Source Administrator may appear differently depending on the
Windows operating system that you are running and the version of ODBC you have
installed.
There are three tabs in this window for accessing User DSN’s, System DSN’s, and File
DSN’s.
A User DSN (Data Source Name) will only be visible to the same User ID who was
logged onto the current machine and previously created the DSN. For example, if
you log onto your Windows machine with a user ID of “Fred” create a new ODBC
User DSN, log off and log back on as “James”, you will not see or have access to the
just-created User DSN.
If you had instead logged on as Fred and created a System DSN, any subsequent
user who logged onto the same machine, regardless of their user ID would both see
and be able to access the newly created DSN.
While User and System DSN’s are specific to the current machine only, File DSN’s
may be shared by other users who have the same ODBC drivers installed on their
machines.
You can create ODBC DSN’s for any COBOL application using any of these three tabs,
but remember the ramifications if you change user ID’s or wish to export the DSN to
another machine.
Prior to creating a new DSN, you should click on the Drivers tab and ensure the
ODBC database driver for the actual type of database you wish to access is installed.
In the example below, we will set up a new DSN for connecting to a Microsoft SQL
Server database. Note in the Drivers panel shown in Figure 5.3 below that a SQL
Server driver is indeed installed as required.
100 Chapter 5. Using SQL with COBOL
Figure 5.3. The ODBC Data Source Administrator Drivers panel under Windows 2000.
If your system does not contain the required ODBC driver for the type of SQL
database system you wish to access, check with your SQL database administrator
about obtaining and installing the current driver.
Once you are satisfied that you have a proper driver installed, click back on one of
the three DSN tabs.
Chapter 5. Using SQL with COBOL 101
Figure 5.4. ODBC Data Source Administrator System DSN tab under Windows 2000.
102 Chapter 5. Using SQL with COBOL
Figure 5.5. The ODBC Data Source Administrator “Create New Data Source” dialog
box under Windows 2000.
2. Move down the list of available ODBC drivers and select the one for which you
wish to create the ODBC data source (in this example we will pick SQL Server).
3. Click on the Finish button. A dialog box appears as shown in Figure 5.6.
Chapter 5. Using SQL with COBOL 103
Figure 5.6. The ODBC Data Source Administrator “Create a New Data Source to SQL
Server” dialog box under Windows 2000.
4. In the Name field, enter the name you wish to use to access this DSN. In this
example, we will use “MySQL”.
5. In the Description field (which is optional), enter a meaningful description.
6. In the Server field, you can enter “(local)” if the database system resides on the
same system you are developing your application on, or enter the name of any
valid database server on your network. In this example, we will enter “(local)” to
indicate that the SQL Server resides on the same server as the application being
developed as shown in Figure 5.7.
104 Chapter 5. Using SQL with COBOL
Figure 5.7. The ODBC Data Source Administrator “Create a New Data Source to SQL
Server” dialog box with parameters entered under Windows 2000.
Chapter 5. Using SQL with COBOL 105
7. Now click on the Next button to bring up the dialog box shown in Figure 5.8.
Figure 5.8. The ODBC Data Source Administrator “Create a New Data Source to SQL
Server” subsequent dialog box under Windows 2000.
8. This is an important step in the process regarding security and user privileges.
The default for this is to login to the SQL Server you have previously specified
using your Windows user ID and password (With Windows 2000 authentication
using the network login ID).
The second option is “With SQL Server authentication using a login ID and
Password entered by the user”. If you wish to have the user of this data source
log in to SQL Server directly, you should select this second option. If you do so,
you will be able to specify a Login ID and Password. In this example, we will do
this and change the User ID to “sa” and leave the password blank.
Note that the Client Configuration button is for advanced users and will allow
you to check certain driver information and to change the default network
protocol to be used. You generally should not have to use this facility.
9. Once you have changed the authenticity option and altered the User ID and
Password, click on the next button.
Because we did not change the selection for the “Connect to SQL Server to
obtain default settings for the additional configuration options” checkbox, the
ODBC DSN setup process will connect to SQL Server and allow us to specify
some additional information. A dialog box appears as shown in Figure 5.9.
106 Chapter 5. Using SQL with COBOL
Figure 5.9. The ODBC Data Source Administrator “Create a New Data Source to SQL
Server” subsequent dialog box under Windows 2000.
This dialog box allows you to change certain installation specific options, and to
specify how to create and deal with temporary stored procedures. It also allows
you to change the default database to be accessed. In this case, we will change
the default database to be accessed to the Pubs database.
10. Select the check box “Change the default database to:”.
11. Select the Pubs database from the dropdown list that is enabled.
12. Click on the Next button and a subsequent dialog box appears as shown in
Figure 5.10.
Chapter 5. Using SQL with COBOL 107
Figure 5.10. The ODBC Data Source Administrator “Create a New Data Source to
SQL Server” subsequent dialog box under Windows 2000.
Once again some implementation specific options are made available to you.
This dialog box allows you to turn on some tracing options and to specify where
you want the trace information to be output.
The “Save long running queries to the log file:” option allows you to identify
long running queries so that you may examine them later. This is generally used
for performance tuning.
“Log ODBC driver statistics to the log file:” option allows you to have ODBC
statistical information recorded at run time. This can be useful in debugging
ODBC specific problems. You may also turn a tracing option on or off at any
time directly in the main ODBC Data Source Administrator window under the
Tracing tab.
13. When you have finished with the configuration of the new ODBC DSN, you
should click on the Finish button.
You will be presented with a dialog box containing an overview of the
information associated with the new ODBC DSN you’ve just created as shown in
Figure 5.11. More importantly, there is a Test Data Source button available.
Note that some versions of the ODBC software do not provide this option, so
don’t be alarmed if you do not have it.
108 Chapter 5. Using SQL with COBOL
Figure 5.11. The ODBC Microsoft SQL Server Setup overview dialog box under
Windows 2000.
14. If you have it available, go ahead and click on the Test Data Source button. This
connects to the SQL Server specified and tries out the data source. If it tests
correctly, you will be presented with the dialog box shown in Figure 5.12.
Chapter 5. Using SQL with COBOL 109
Figure 5.12. The SQL Server Setup ODBC Data Source Test results dialog box under
Windows 2000.
If you do not have the Test Data Source option available in your version of ODBC,
you can use a generic query tool such as Microsoft’s Query (MS Query) to quickly try
out a new data source.
Once you have successfully set up a new ODBC DSN for your NetCOBOL application,
you are ready to set up the NetCOBOL specific runtime configuration.
Identification Division.
Program-ID. MySQL
Environment Division.
Data Division.
Working-Storage Section.
01 Loop-Flag Pic 9 Value 0.
EXEC SQL BEGIN DECLARE SECTION END-EXEC.
01 EmpID Pic X(9) Value Spaces.
01 FName Pic X(20) Value Spaces.
01 LName Pic X(30) Value Spaces.
01 SQLSTATE Pic X(5) Value Spaces.
EXEC SQL END DECLARE SECTION END-EXEC.
Procedure Division.
Move 0 To Loop-Flag
SQLSTATE.
EXEC SQL
CONNECT TO Default
END-EXEC.
EXEC SQL
DECLARE CUR1 CURSOR FOR
SELECT emp_id, fname, lname FROM employee
END-EXEC.
EXEC SQL
OPEN CUR1
END-EXEC.
IF SQLSTATE = Zeroes
Display EmpID, " ", FName, " ", LName
Else
Move 1 To Loop-Flag
EXEC SQL CLOSE CUR1 END-EXEC
End-IF
End-Perform.
EXEC SQL
DISCONNECT DEFAULT
END-EXEC.
Exit Program.
Prior to running a NetCOBOL SQL application, you must set up the SQL database(s)
and table(s), ensure that your security and authorization information is properly
configured and available to you, and set up an ODBC DSN.
Once you have accomplished these tasks, you must make this information available
to your NetCOBOL SQL application at run time. This is done in 2 separate steps:
1. Create a NetCOBOL specific information file (.inf file) which will contain required
information.
Chapter 5. Using SQL with COBOL 111
Figure 5.13. Choosing the Customize Menu option from the Tools pull-down menu in
the COBOL Project Manager.
2. Click on the Add button to add a new menu item. Project Manager displays a
dialog box that allows you to enter the name of the executable file to be
associated with the new menu item. Fill in the fields as shown in Figure 5.15.
Figure 5.16. The Customize Menu dialog box with the new menu item added.
Figure 5.17. The Tools pull-down menu with the SQL .inf File Utility added.
114 Chapter 5. Using SQL with COBOL
Figure 5.18. The .inf file name specification dialog box for the SQLODBCS Utility.
Note that it is important to fully specify the drive and path of the .inf file you
wish to create or modify, to ensure it gets saved to the proper location. If you
fail to do this, your new .inf file may be saved to a different directory than
where you expect to find it later. For our example, we are going to create a .inf
file named C:\MYSQL\MySQL.inf.
2. Enter the name of the .inf file you wish to create as shown in Figure 5.19.
Figure 5.19. The .inf file name specification dialog box for the SQLODBCS Utility,
with a fully path qualified file name entered.
3. Click on the OK button, respond Yes to the message asking you if you wish to
create a new file, and OK to the message confirming that a file was created.
The SQLODBCS utility window appears as shown in Figure 5.20.
Chapter 5. Using SQL with COBOL 115
Figure 5.20. The dialog box for the .inf file configuration facility (SQLODBCS.EXE).
use at runtime. Another reason for this level of abstraction from the physical
server name is to allow you to set up multiple entries for the same physical
server. You might have many different ODBC data sources defined for a variety
of different databases and/or tables that exist on a single SQL Server. You
would thus require a method to be able to specify these different ODBC data
sources.
Another important point is the ability to connect to a default server. The code
for this looks like:
EXEC SQL
CONNECT TO DEFAULT
END-EXEC.
The value “ID0001” will be used as the User ID, and the value “PW01” will be
used as the password when connecting to the actual database server, regardless
of the User ID and Password currently specified in the .inf file.
Chapter 5. Using SQL with COBOL 117
If you code:
EXEC SQL
CONNECT TO ‘FRED’
USER ‘ID0001’
END-EXEC.
The value “ID0001” will be used for the User ID, but since you did not specify a
Password, the Password currently specified in the .inf file will be used when
connecting to the actual database server.
In neither case will the User ID or Password specified in the actual ODBC data
source be used – NetCOBOL will always override this.
This means that you must specify a User ID and Password in the SQLODBCS
utility for any .inf file you wish to create. If you leave these out, the SQLODBCS
utility will refuse to create your .inf file. If you manually delete these entries in a
.inf file, you will receive an error at runtime.
Our simple SQL COBOL application noted above connects to DEFAULT as shown
in the code below.
EXEC SQL
CONNECT TO DEFAULT
END-EXEC.
We now continue with the steps for creating the .inf file.
4. To create the appropriate .inf file, enter the parameters shown in Figures 5.21 to
5.24. If you are using multithreading or object oriented programs, see the
SQLODBCS Help for the appropriate Connection Scope settings.
118 Chapter 5. Using SQL with COBOL
Figure 5.21. The parameters entered for the sample application to create a .inf file
in the configuration facility (SQLODBCS.EXE) – Server Info tab.
Chapter 5. Using SQL with COBOL 119
Figure 5.22. The parameters entered for the sample application to create a .inf file
in the configuration facility (SQLODBCS.EXE) – Default Connection Info tab.
120 Chapter 5. Using SQL with COBOL
Figure 5.23. The parameters entered for the sample application to create a .inf file
in the configuration facility (SQLODBCS.EXE) – Connection Scope tab.
5. Click on the Apply button to create the .inf file and write it to disk.
The .inf file created by the above parameters will contain the following entries:
[SERVER LIST]
Default=Default
[Default]
@SQL_DATASRC=MySQL
@SQL_USERID=MySQL
@SQL_PASSWORD=BEINKAOHLEPJENBABBMM
@SQL_ACCESS_MODE=READ_ONLY
@SQL_COMMIT_MODE=MANUAL
@SQL_CONCURRENCY=READ_ONLY
@SQL_ODBC_CURSORS=USE_DRIVER
@SQL_QUERY_TIMEOUT=0
[SQL_DEFAULT_INF]
@SQL_SERVER=Default
@SQL_USERID=MySQL
@SQL_PASSWORD=BEINKAOHLEPJENBABBMM
[CONNECTION_SCOPE]
@SQL_CONNECTION_SCOPE=PROCESS
The Server List contains a line indicating that the server specified as the Default
connection (for any program trying to connect to DEFAULT) will be the symbolic
entry “Default” (Default=Default).
Following this is the entry information for the symbolic server name “Default”.
Note that Entry headings are designated with square brackets around them.
This entry contains the name of the ODBC data source to be used
Chapter 5. Using SQL with COBOL 121
[MYSQL]
@ODBC_Inf=c:\mysql\mysql.inf
The entry “[MYSQL] designates the name of the main program. The line
“@ODBC_Inf=c:\mysql\mysql.inf” tells the runtime which .inf file to use and where it
is located. That’s all there is to it.
Instead of editing the COBOL85.CBR file using a text editor, you can use the Runtime
Environment Setup Tool, available from COBOL Project Manager’s Tools menu. Keys
to using this tool are that:
• The file you want to edit/create is COBOL85.CBR.
• The Section you want to edit/create is MySQL.
• You can select @ODBC_Inf from the pull-down list.
• You can use the browse (…) button to select the .inf file.
• You MUST click Set to add this variable to the list.
• You MUST click Apply to save the setting.
122 Chapter 5. Using SQL with COBOL
@ODBC_Inf=c:\mysql\mysql.inf
in COBOL85.CBR, you will receive an error dialog box as shown in Figure 5.24.
This error occurs whenever no @ODBC_inf parameter is specified.
Figure 5.24. Error dialog for not specifying an @ODBC_inf parameter to the
Runtime Environment.
2. If you specify an @ODBC_inf parameter and it is found, but it contains the name
of a file that does not exist or cannot be found, you receive the error dialog box
shown in Figure 5.25.
Figure 5.26. Error Dialog for attempting to connect in COBOL program to server
that is not specified in your .inf file.
SQLMSG is of particular use. The ODBC driver will place descriptive error messages
in this variable. For example, if you code the name of an ODBC data source that does
not exist in the “@SQL_DATASRC=” parameter in your .inf file, you will not receive
an error dialog box. Instead you will receive a value of IM002 in SQLSTATE. This is
not very helpful. But if you look at the value contained in SQLMSG, it will be:
[Microsoft] [ODBC Driver Manager] Data source name not found and no
default driver specified.
There are some SQL syntax errors that will not be caught by the NetCOBOL compiler
and will only show up at runtime. For example, if you code an erroneous Where
clause in a Select statement such as:
124 Chapter 5. Using SQL with COBOL
EXEC SQL
DECLARE CUR1 CURSOR FOR
SELECT emp_id, fname, lname FROM employee
Where emp_id Not NULL
END-EXEC.
Note that “Not NULL” is invalid SQL Code. When this statement is executed at
runtime, you will receive a value of 37000 in SQLSTATE (again, not very helpful), but
SQLMSG will contain:
[Microsoft] [ODBC SQL Server Driver] [SQL Server] Incorrect syntax near
the keyword ‘Null’.
It is thus a good idea to always include SQLMSG in your COBOL program and to
interrogate it whenever error messages occur. You may wish to display SQLMSG
when debugging after key SQL statements in your program.
Appendix A. Sample Programs
The sample programs shipped with NetCOBOL are intended to give an overview of
the capabilities of NetCOBOL and COBOL Project Manager. Refer to the “NetCOBOL
User’s Guide for Windows” for further details on using NetCOBOL. The following table
details the sample programs available with NetCOBOL.
Function
Inputs an alphabetic character (lowercase character) from the console window, and
outputs a word beginning with the input alphabetic character to the console window.
2. The project file is selected, and "Compiler options" is selected from "Project"-
"Options" menu.
→ The "Compiler options" dialog is displayed.
3. Confirm compiler option TEST is specified. After confirming the information, click
the OK button.
→You are now returned to the Project Manager window.
4. Select "Build" from Project Manager's "Project" menu or click on the Build
button in the Project Manager toolbar.
→ After the build terminates, check that SAMPLE01.EXE is created.
130 Appendix A. Sample Programs
Figure A.3. The Builder window after Sample 1 is built into executable format
NOTES:
1. If the sample has already been built you will just see the “Build Start” and “Build
End” messages.
2. The MAIN compile option is needed to indicate the main program in a NetCOBOL
application run-unit. In COBOL Project Manager you select Main - Window or Main –
Console from the pop-up menu when the COBOL source program is selected. All
sample programs have the appropriate program set as the main program.
the next executable statement (Line 48). Step again to execute the Accept
statement on Line 48.
NOTE: The Accept statement requires user input.
4. Input the data item (a letter of the alphabet).
Make the console window active.
NOTE: The console window may be hidden behind the COBOL Debugger
window.
Type in any lowercase alphabetic character and then press the ENTER key. The
debugger automatically returns to the next executable statement (Line 52).
Change the value of the data in the data value area and click on the Modify
button. Click on the Close button to exit the Data dialog box. (Answer “Yes” to
save the changed data.)
6. Specify a breakpoint.
Move the cursor to Line 62, click on the right mouse button and select Set
Breakpoint from the pop-up menu.
Note that the statement changes color when a breakpoint has been applied.
To delete a breakpoint, right click on the line containing the breakpoint and
select Delete Breakpoint from the pop-up menu. You can also use the
Breakpoint dialog box that is displayed by selecting Breakpoint from the Debug
menu. Highlight the breakpoint you want to delete, click on the Delete button,
and then click on the Close button to exit the Breakpoint dialog box.
NOTE: You can delete more than one breakpoint at a time by highlighting multiple
items in the Breakpoint dialog box and clicking on the Delete button.
134 Appendix A. Sample Programs
Overview
Reads a data file (line sequential file) that contains product codes, product names,
and unit prices, and creates an indexed file with the product code as a primary
record key and the product name as an alternate record key.
2. Select "Build" from Project Manager's "Project" menu or click on the Build
button in the Project Manager toolbar.
→ After the build terminates, check that SAMPLE02.EXE is created.
Figure A.11. The Run-time Environment Setup Tool with COBO85.CBR for Sample02.
Execution Result
No termination message is displayed.
After completion of execution, an indexed file (MASTER) with a product code as a
key is created in the SAMPLE02 directory. Use Windows Explorer or File Manager to
check whether the indexed file was created.
Overview
When an employee's number and name are written to the screen, the program
creates an indexed file with the employee's number as a primary record key and the
name as an alternate record key.
2. Select "Build" from Project Manager's "Project" menu or click on the Build
button in the Project Manager toolbar.
→ After the build terminates, check that SAMPLE04.EXE is created.
Figure A.13. The Run-time Environment Setup Tool with COBO85.CBR for Sample04.
To register data, press the ENTER key. The input data is written to the master file,
and the screen is cleared for input of subsequent data.
To quit processing, press the F2 key.
Execution Result
Because the employee number becomes a main record key and the employee name
becomes a record sub key, you should use Windows Explorer to confirm that the
index file (MASTER) was created in the SAMPLE04 directory.
NOTE: You can edit the MASTER file using the Edit command in the COBOL File
Utility (available from the Tools menu in the COBOL Project Manager window).
Appendix A. Sample Programs 143
Overview
Reads the contents of the master file (indexed file created in Sample 2), stores the
records in a work file whose name is provided in the @MGPRM environment variable
(a way of passing information to a main program’s linkage section), then passes the
work file to a subprogram which prints the records.
The master file stores product codes, product names, and unit prices. The work file
name must be specified in the @MGPRM parameter at program execution.
NOTE: In the above figure, colons are used to denote sections of source code that
have been omitted.
In free format, COBOL statements can be written in any character position on the
line. Lines beginning with “*>“ are treated as comments.
NOTE: You must specify the SRF compiler option in order to use free format. The
SRF compiler option has two parameters; the first specifies the format for the source
program and the second specifies the format of copybooks. All copybooks must have
the same format type. The available types are FIX, for fixed format source, VAR, for
variable format source, and FREE, for free format source.
Appendix A. Sample Programs 145
File Interdependence
Figure A.17 shows the relationship between sources files used in Sample05.
COPY "S_REC".
Source file – PRINTPRC.COB
[Read master file]
IDENTIFICATION DIVISION.
[Create work file] PROGRAM-ID. PRINTPRC.
[Print processing]
3. The project file is selected, and "Compiler options" is selected from "Project"-
"Options" menu.
→ The "Compiler options" dialog is displayed.
3. Select "Build" from Project Manager's "Project" menu or click on the Build
button in the Project Manager toolbar.
→ After the build terminates, check that SAMPLE05.EXE and PRINTPRC.DLL are
created.
Figure A.20. The Run-time Environment Setup Tool with COBO85.CBR for Sample05.
Confirm the contents, then click on the OK button to close the message box.
Execution Result
The master file contents are written to the default printer at the completion of
program execution.
150 Appendix A. Sample Programs
Overview
The sample program calculates the number of days from the start date to the end
date. The start and end dates are specified as command arguments in the following
format:
START-DATE , END-DATE:
Specify a year, month, and day between January 1, 1900 and December 31,
2172 in the YYYYMMDD format.
2. Select "Build" from Project Manager's "Project" menu or click on the Build
button in the Project Manager toolbar.
→ After the build terminates, check that SAMPLE06.EXE is created.
After you type in the command-line parameters for the program in the “Execution-
time options” field, press the ENTER key. The Debugger starts as shown in the
following figure.
Refer to Chapter 2, “A Quick Tour” for details on using the COBOL Project Manager.
Appendix A. Sample Programs 153
Execution Result
Sample 6 displays the number of days from the specified start date to the specified
end date.
Overview
The sample program divides a master file (the indexed file created in Sample 2),
storing product codes, product names, and unit prices, into two master files
according to product codes. The following table shows the division method and the
names of the two new master files:
2. Select "Build" from Project Manager's "Project" menu or click on the Build
button in the Project Manager toolbar.
→ After the build terminates, check that SAMPLE07.EXE is created.
Figure A.28. The Run-time Environment Setup Tool with COBO85.CBR for Sample07.
Execution Result
The following two files are created in the directory of the master file created in
Sample 2:
• MASTER.A: Stores the data of products whose codes begin with 0.
• MASTER.B: Stores the data of products whose codes begin with a non-zero
value.
The contents of the newly created master files (MASTER.A and MASTER.B) can be
checked with the program in Sample 5, in the same manner as for the master file
created in Sample 2.
158 Appendix A. Sample Programs
Overview
The sample program inputs data of up to 40 alphanumeric characters from the
console window, and outputs the data to the printer.
2. Select "Build" from Project Manager's "Project" menu or click on the Build
button in the Project Manager toolbar.
Appendix A. Sample Programs 159
In the console window, enter the data to be printed . Data of up to 40 characters can
be entered at a time.
To terminate the program, press the RETURN key, type /END and press the
RETURN key. Click on the OK button to close the message window.
Execution Result
The input data is written to the printer at termination of the program.
12345678901234567890123456789
01234567890
abcd
*************SAMPLE8*********
***********
Refer to “Printing” in the “NetCOBOL User's Guide for Windows” for details on using
“print file 1” and “print file 2”.
Overview
Table A.3 below describes each of the tasks performed by this sample. The tasks
show a number of printing features. There are essentially four elements that give
you control over the various printing features:
1. COBOL syntax
- PRINTING MODE clauses in the SPECIAL-NAMES paragraph.
- ASSIGN TO PRINTER in the SELECT statement.
- CHARACTER TYPE and PRINTING POSITION clauses in data definitions.
2. The I-Control Record
A record that you write to the print file using the syntax:
“CTL IS page-cntl” in SPECIAL-NAMES
and
WRITE I-Control-Record AFTER ADVANCING page-cntl
3. Forms Control Buffers (FCBs)
These are form information buffers stored by the COBOL run-time system, using
information defined in environment variables of the form “FCBxxxx=”.
4. Environment variables
Environment variables define fonts, FCBs, document names and other printing
details.
Table A.3 indicates which of the above are used to provide a particular feature. You
will need to read the table, inspect the COBOL code, and consult the chapter on
“Printing” in the “NetCOBOL User's Guide for Windows” to fully understand all the
features being demonstrated.
162 Appendix A. Sample Programs
Impact half-size, }
Courier New, Courier {GOTHIC-HANKAKU} …
New half size. +
CHARACTER TYPE x
Courier New font PRINTING MODE x @PrinterFontName=
… WITH FONT (Courier New, …)
{MINCHOU
}
{MINCHOU-HANKAKU}
…
+
CHARACTER TYPE x
Full size PRINTING MODE x
… BY FORM F …
+
CHARACTER TYPE x
Half size PRINTING MODE x
… BY FORM H …
+
CHARACTER TYPE x
Legal size paper I-Control: @PRN_FormName_XXX
PAPER-SIZE (=”XXX”) =Legal 8 1/2 x 14 in
2e. Prints a
mixture of the
above
features: font
size, pitch,
half/full size
characters.
Appendix A. Sample Programs 167
2. Select "Build" from Project Manager's "Project" menu or click on the Build
button in the Project Manager toolbar.
→ After the build terminates, check that SAMPLE09.EXE is created.
168 Appendix A. Sample Programs
Execution Results
The sample pages described in table A.3 above are printed to the default printer.
Overview
The sample program accesses the database on the server and outputs all data stored
in the database table "STOCK" to the client console. When all data has been
referenced, the link to the database is disconnected.
Figure A.36. Control Panel with Data Sources (ODBC) Icon Highlighted
NOTE: Depending on the version of Microsoft Access, the ODBC drivers may not be
installed by default - you must manually select these options when you install
Microsoft Access (either from the Microsoft Access installation CD or the Office
Professional CD).
You will also require a sample Microsoft Access run-time enabled database called
"STOCK.MDB". This file can be found in the SAMPLE11 folder.
Once you have verified installation of 32 Bit ODBC, Microsoft Access and the
associated drivers, you are ready to proceed with executing the sample.
You will add a new User DSN. Select the User DSN tab, and click on the Add button.
ODBC Data Source Administrator displays the “Create New Data Source” dialog box.
Select the Microsoft Access Driver (*.mdb) and click on the Finish button.
The ODBC Microsoft Access Setup dialog box is displayed.
Enter Stock in the Data Source Name field and Sample 11 Database in the
Description field as shown above.
You also need to select a file (database) to bind this driver to. Click on the Select
button in the ODBC Microsoft Access Setup dialog box. The Select Database dialog
box is displayed. Navigate through the directories and find the "Stock.mdb" database
file:
Click on the OK button. This will take you back to the ODBC Microsoft Access Setup
dialog box.
Appendix A. Sample Programs 175
Click on the OK button. This will take you back to the main ODBC Source
Administrator window.
Note that "Stock" has been added to the list in User DSN. Although you should not
set any additional options for this exercise, you may wish to highlight “Stock” and
click on the Configure button.
This will give you an idea of some of the additional options that are available when
developing these types of applications. Once you are back to the main ODBC Source
Administrator window, click on the OK button. This will exit the ODBC configuration
facility. You have now defined the new ODBC Source (Stock) you are going to use
with COBOL.
2. Select "Build" from Project Manager's "Project" menu or click on the Build
button in the Project Manager toolbar.
→ After the build terminates, check that SAMPLE11.EXE is created.
Figure A.44. The Run-time Environment Setup Tool with COBO85.CBR for Sample11.
Execution Result
The data extracted from the table is displayed, as shown in the following figure.
Appendix A. Sample Programs 179
Overview
Sample 12 uses the STOCK table of the sample database. Refer to “Sample
Database” in the “NetCOBOL User’s Guide for Windows” for details of the sample
database. Sample 12 accesses and disconnects it after the following operation:
• Display of all data items in the database
• Fetch of the GNO value on a row with GOODS value "TELEVISION"
• QOH update on a row with the fetched GNO
• Deletion of lines with GOODS values "RADIO", "SHAVER", and "DRIER"
• Redisplay of all data items in the database
Part of the output result is output to a file by using compiler option SSOUT.
2. Select "Open" on the File menu and create an object initialization file
(COBOL85.CBR) in the folder that contains the executable program
(SAMPLE12.EXE).
3. Select a common tab and set data as shown below:
- Specify an ODBC information file name in environment variable information
@ODBC_Inf (ODBC information file specification).
- Specify a file to save the DISPLAY statement output result in environment
variable RESULT.
Figure A.48. The Run-time Environment Setup Tool with COBO85.CBR for Sample12.
Overview
At initialization the Visual Basic application calls a subroutine, JMPCINT2 that
initializes the COBOL run-time environment, ready for a call to a COBOL program.
The Visual Basic form shows a simple equation in which the user enters two numbers
(either side of a multiply “*” sign) and presses the “=” sign, which is a button. The
Visual Basic application passes the two values to the COBOL application which does
the multiplication and returns the result for the Visual Basic code to display.
In the Visual Basic application’s termination code, it calls the JMPCINT3 subroutine to
close the COBOL run-time environment.
2. The project file is selected, and "Linker options" is selected from "Project"-
"Options" menu.
→ The "Linker options" dialog is displayed.
Appendix A. Sample Programs 187
4. Select "Build" from Project Manager's "Project" menu or click on the Build
button in the Project Manager toolbar.
→ After the build terminates, check that SAMPLE13.dll is created.
5. When you rebuild executable file of Visual Basic, SAMPLE13.VBP (Visual Basic
project file) included in the "Other” folder of the project is selected and "Edit" is
selected from the project menu.
→ Visual Basic starts; "Make of SAMPLE13.EXE" is selected from the file menu.
1. Select "Run-time Environment Setup Tool" from the "Tools" menu of the Project
Manager.
→ The run-time environment setup tool is displayed.
2. Select "Open" on the "File" menu and select COBOL85.CBR in the folder that
contains the executable program (SAMPLE13.EXE).
3. Select the Common tab and enter data as shown below:
- For the environment variable @CBR_ATTACH_TOOL, specify TEST.
8. When you exit from the COBOL application control returns to the Visual Basic
code.
The section “H. Debugging with Visual Basic” in Chapter 2’s Quick Tour steps through
this example in some detail.
For more information on this topic, see Chapter 4, “Working with Visual Basic and
COBOL” and the “NetCOBOL Debugging Guide”.
Overview
The sample program performs the following account functions:
• Opening a new account
• Depositing funds
• Withdrawing funds
The account data, comprising account number, PIN number, name and balance, is
saved in an indexed file.
The structure of the indexed file is:
When functions are requested from the “ATM terminal” (user screens), the record
data for the account in the indexed file is updated.
Processing Overview
The Visual Basic application starts, and subroutine JMPCINT2 (which initializes the
COBOL run-time system) is called when the main form is loaded.
The Visual Basic forms manage the interface with the user – accepting input data,
transaction requests and displaying output data and messages. COBOL programs are
called to manage the account data in the indexed file.
When the Visual Basic application is closed, it calls subroutine JMPCINT3 (which
terminates the COBOL run-time).
Figure A.55 shows the structure of the application:
sample14.exe
|
COBOL initialization processing --- JMPCINT2 Initialization procedure subroutine
|
|
|
COBOL termination processing --- JMPCINT3 Termination subroutine
2. The project file is selected, and "Linker options" is selected from "Project"-
"Options" menu.
Appendix A. Sample Programs 193
4. Select "Build" from Project Manager's "Project" menu or click on the Build
button in the Project Manager toolbar.
→ After the build terminates, check that K_KEN .DLL is created.
5. When you rebuild executable file of Visual Basic, SAMPLE14.VBP (Visual Basic
project file) included in the "Other" folder of the project is selected and "Edit" is
selected from the project menu.
→ Visual Basic starts; "Make of SAMPLE14.EXE" is selected from the file menu.
194 Appendix A. Sample Programs
7. Start debugging the Visual Basic code when you execute the call to SAMPLE14
(the COBOL program) the COBOL debugger is invoked so that you can continue
debugging in the COBOL part of the application.
8. When you exit from the COBOL application control returns to the Visual Basic
code.
The section “H. Debugging with Visual Basic” in Chapter 2’s Quick Tour steps through
this example in some detail.
For more information on this topic, see Chapter 4, “Working with Visual Basic and
COBOL” and the “NetCOBOL Debugging Guide”.
Figure A.59. The Enter Account number and PIN number dialog box
4. Note the account number and the PIN number you used – you will need to enter
them in subsequent transactions.
5. Click on the OK button to return to the main Sample 14 dialog box.
6. You can now enter the account and PIN numbers and use the Withdrawal and
Deposit functions.
Appendix A. Sample Programs 197
Overview
In the sample program, three employee objects are generated. After an object has
been generated using the "NEW" method, the "Data-Set" method is invoked to set
the data.
Although all the employee objects have the same form, they have different data
(employee numbers, names, departments and sections, and address information).
Address information also belongs to an object, containing postal codes and
addresses.
Upon input of an employee number on the screen, the appropriate "Data-Display"
method in the employee object is invoked, with employee information in the object is
displayed on the screen.
The employee object invokes the "Data-Get" method of the associated address
object to acquire the address information.
The employee object consists of three pieces of data and an object reference to an
address object. The structure of the object is transparent to the main program user.
The user must, however, understand the two methods of "Data-Set" and "Data-
Display."
The encapsulation of data completely masks the information in the object.
2. Select "Build" from Project Manager's "Project" menu or click on the Build
button in the Project Manager toolbar.
→ After the build terminates, check that MAIN.EXE is created.
Overview
A collection class is the generic name of a class that handles a set of objects—it is
used to collectively handle and store many objects.
This sample covers the following classes.
• Collect (Collection)
• Dict (Dictionary)
• List (List)
Appendix A. Sample Programs 201
Class Layers
The following diagram shows the relationships between the class layers in Sample
16.
+--------------+
| FJBASE |
+--------------+
| Inherited
+---------------------------------------------------+
|Collect |
+---------------------------------------------------+
|CollectionSize-Get |
|FirstElement-Get |
|NextElement-Get |
|PreviousElement-Get |
+---------------------------------------------------+
| Inherited
+------------------+---------------+
| |
+-------------------------+ +---------------------------+
|List | |Dict |
+-------------------------| |---------------------------+
|Element-Get | |Element-Get |
|Element-Insert | |Element-PutAt |
|Element-PutAt | |FirstKey-Get |
|Element-PutLast | |LastKey-Get |
|ElementNo-Get | |Remove-All |
|LastElement-Get | |Remove-At |
|Remove-All | +---------------------------+
|Remove-At |
+-------------------------+
NOTE: In addition to the above classes, Sample 15 also includes the classes
BinaryTree-Class, DictionaryNode-Class and ListNode-Class. These classes, which
are used inside the List and Dict classes, are transparent to the collection class user,
and are not explained here.
Collect Class
This is the highest collection class. All collection classes inherit this class.
Collect is an abstract class, and does not create any objects.
202 Appendix A. Sample Programs
Since this class inherits the FJBASE class, all the methods defined in the FJBASE class
can be used.
Definitions
CLASS-ID. Collect INHERITS FJBASE.
ENVIRONMENT DIVISION.
CONFIGURATION SECTION.
REPOSITORY.
CLASS FJBASE.
OBJECT.
PROCEDURE DIVISION.
METHOD-ID. CollectionSize-Get.
METHOD-ID. FirstElement-Get.
METHOD-ID. NextElement-Get.
METHOD-ID. PreviousElement-Get.
END OBJECT.
END CLASS Collect.
CollectionSize-Get method
This method investigates the number of elements in a set.
Parameter
None
Return value
PIC 9(8) BINARY
Returns the number of elements in a set.
FirstElement-Get method
This method returns the first element in a set.
Parameter
None
Return value
USAGE OBJECT REFERENCE
Returns the first element in a set. If no element exists, NULL is returned.
NextElement-Get method
This method returns the element following the one currently pointed to.
Parameter
None
Appendix A. Sample Programs 203
Return value
USAGE OBJECT REFERENCE
Returns the element following the one currently pointed to. If a following
element does not exist, NULL is returned.
PreviousElement-Get method
This method returns the element immediately preceding the one currently pointed to.
Parameter
None
Return value
USAGE OBJECT REFERENCE
Returns the element immediately preceding the one currently pointed to. If a
previous element does not exist, NULL is returned.
Dict Class
This class has the following features:
• Each element has a key.
• The key value is unique.
• A key can be used for retrieval.
• The key is used for ordering.
Since this class inherits from the Collect class, all the methods defined in Collect can
be used as well.
Definitions
CLASS-ID. Dict INHERITS Collect.
ENVIRONMENT DIVISION.
CONFIGURATION SECTION.
REPOSITORY.
CLASS Collect.
OBJECT.
PROCEDURE DIVISION.
METHOD-ID. Element-Get.
METHOD-ID. Element-PutAt.
METHOD-ID. FirstKey-Get.
METHOD-ID. LastKey-Get.
METHOD-ID. Remove-All.
METHOD-ID. Remove-At.
END OBJECT.
END CLASS Dict.
204 Appendix A. Sample Programs
Element-Get method
This method returns elements for a specified key.
Parameter
Key: PIC X(10)
Specifies a key value for an element to be returned.
Return value
USAGE OBJECT REFERENCE
Returns an element for a specified key if it is found, and returns NULL if it is not
found.
Element-PutAt method
This method adds an element for a specified key. If an element with the same key
already exists, it is replaced by the new element.
Parameters
Key: PIC X(10)
Specifies the key value of the element to be added or replaced.
Element: USAGE OBJECT REFERENCE
Specifies the element to be added or replaced.
Return value
None
FirstKey-Get method
This method determines the key value for the first element.
Parameter
None
Return value
PIC X(10)
Returns the key value for the first element. If the number of elements is 0, or if
the key for the first element is a blank, a blank is returned.
LastKey-Get method
This method determines the key value for the last element.
Parameter
None
Return value
PIC X(10)
Returns the key value for the last element. If the number of elements is 0, or if
the key for the last element is a blank, a blank is returned.
Appendix A. Sample Programs 205
Remove-All method
This method deletes all elements contained in a set.
Parameter
None
Return value
None
Remove-At method
This method deletes an element for a specified key.
Parameter
Key: PIC X(10)
Specifies the key value for the element to be deleted.
Return value
None
List Class
This class has the following features:
• Elements are arranged in a certain order.
• Duplicate elements can be contained.
Since this class inherits from the Collect class, all the methods defined in the Collect
class can be used as well.
206 Appendix A. Sample Programs
Definitions
CLASS-ID. List INHERITS Collect.
ENVIRONMENT DIVISION.
CONFIGURATION SECTION.
REPOSITORY.
CLASS Collect.
OBJECT.
PROCEDURE DIVISION.
METHOD-ID. Element-Get.
METHOD-ID. Element-Insert.
METHOD-ID. Element-PutAt.
METHOD-ID. Element-PutLast.
METHOD-ID. ElementNo-Get.
METHOD-ID. LastElement-Get.
METHOD-ID. Remove-All.
METHOD-ID. Remove-At.
END OBJECT.
END CLASS List.
Element-Get method
This method returns the element at a specified location (index).
Parameter
Index: PIC 9(8) BINARY
Specifies the location of the element to be returned by an integer starting at 1.
Return value
USAGE OBJECT REFERENCE
Returns the specified element. If no element exists at the specified location,
NULL is returned.
Element-Insert method
This method adds an element at the specified location (index).
Parameters
Index: PIC 9(8) BINARY
Specifies the location at which the element is to be added by an integer
beginning with 1.
If a value greater than the number of elements plus 1 is specified, no element is
added.
Element: USAGE OBJECT REFERENCE
Appendix A. Sample Programs 207
Element-PutAt method
This method replaces the element at the specified location (index).
Parameters
Index: PIC 9(8) BINARY
Specifies the location of the element to be replaced by an integer beginning with
1. If a value greater than the number of elements is specified, no element is
replaced.
Element: USAGE OBJECT REFERENCE
Specifies the element to be replaced.
Return value
Returns the location of the replaced element using an integer beginning with 1.
If no element has been replaced, 0 is returned.
Element-PutLast method
This method adds an element after the last element.
Parameter
Element: Specifies the element to be added.
Return value
None
ElementNo-Get method
This method checks the location (index) of a specified element.
Parameter
Element: Specifies the element whose location is checked.
Return value
PIC 9(8) BINARY
Returns the location of the element using an integer beginning with 1.
If the specified element is not found, 0 is returned.
If duplicate elements exist, the first found location is returned.
LastElement-Get method
This method returns the last element.
208 Appendix A. Sample Programs
Parameter
None
Return value
USAGE OBJECT REFERENCE
Returns the last element. If the number of elements is 0, NULL is returned.
Remove-All method
This method deletes all the elements contained in a set.
Parameter
None
Return value
None
Remove-At method
This method deletes the element at the specified location (index).
Parameter
Index: PIC 9(8) BINARY
Specifies the location of the element to be deleted using an integer starting at 1.
If a value greater than the number of elements is specified, no element is
deleted.
Return value
Returns the location of the deleted element using an integer beginning with 1.
If no element has been deleted, 0 is returned.
− Inheritance
− Object creation
− Method calling
• Project management
• LIST.REP
NOTE: Some other files are also created, but they are not required when the class
library is used.
For Executing
• COLLECT.DLL (DLL file)
Appendix A. Sample Programs 211
Overview
The purpose of Sample 17 is to illustrate implementation of the object-oriented
concepts of aggregation, singleton and iteration (explained below). It uses a
conference room booking system to demonstrate these features. The user interface
is very basic as the focus is to demonstrate the OO concepts.
The conference room booking system provides functions for:
• Reserving a conference room.
• Canceling a conference booking.
• Reviewing conference room bookings.
• Listing, adding and deleting conference rooms.
• Updating conference room details.
Aggregation
Aggregation is a relation of "whole to part". The life of the downstream class
instance in the aggregate relation is controlled completely by the life of the
upstream class instance. In this sample, the following classes are in the aggregation
relation:
• Reservation-status-Date class (RSVSTATE-DATE-CLASS) and Reservation-status-
Conference-Room class (RSVSTATE-CFNROOM-CLASS).
• Reservation-status-Conference-Room class (RSVSTATE-CFNROOM-CLASS) and
Reservation-status-Time-Frame class (RSVSTATE-TIME-CLASS).
• Conference-Room-Information-Control calls (CFRINFO-CNT-CLASS) and
Conference-Room-Information class (CFRINFO-CLASS).
Singleton
Singleton refers to a mechanism that guarantees that only one object instance can
exist for a class.
This is implemented in the SINGLE-TON class in this sample. The SINGLE-TON class
is inherited by the following classes so that they can only create a single object
instance.
212 Appendix A. Sample Programs
Iteration
Iteration provides a means of accessing elements sequentially without having to be
aware of the internal structure of the aggregation object. In this sample, iteration is
implemented by the LIST-ITERATER class.
Two or more LIST-ITERATER class objects can be created for a single list object.
In this sample, iteration is used in the following functions:
• Display of reservation information
Method: RSV-SITUATION-LIST-DISP,
Class: RSVCNT-CLASS
• Deletion of reservation state objects (date, conference room and time frame)
Method: RSV-SITUATION-OBJ-DEL
Class: RSVCNT-CLASS
• Retrieval of conference room information and reservation information
Method: RSV-DATA-RETRIEVAL
Class: RSVINFO-CLASS
• Storing the information in an Excel file.
Entry: PRESERVATION-DATA
Program: EXCEL-EDIT
Appendix A. Sample Programs 213
Design of Sample 17
Figure A.63 shows the relationships between the classes used in Sample 17.
Main
Exception Object
Program
Error Class
Singleton Class
2. Retrieval
The retrieval function returns all conference room bookings for a given name.
3. Conference room control
The conference room control function lets you update, add and delete
conference room details.
Once you have entered the primary function you are prompted to enter data an item
at a time. Sometimes the interface introduces a set of information to be entered,
such as "Enter the conference room name, and time at which it should be booked"
and the prompts for the first piece of information (the conference room name). Just
enter the first piece of information and you will be prompted for the other pieces in
the set.
You'll be asked for the following information for the different functions:
Appendix A. Sample Programs 217
Retrieval
You are prompted to enter:
Subscriber name (10 digits) – the name entered when booking the room.
Information corresponding to the name is displayed.
If the conference room exists, details for that conference room are listed. If it
doesn't exist you are prompted to enter details to register the conference room. The
conference room details are:
Capacity (2 digits)
Extension (9 digits)
Type (N for general, T for video)
When changes are completed the appropriate updates are made to the Excel file to
reflect the changes.
End
The program saves reservation information objects in the Excel file and terminates.
218 Appendix A. Sample Programs
Overview
The application shows how an OO system can be set up to manage employee
information. It implements, in a basic manner, the functions of registering, deleting,
and modifying employee details, calculating salaries and printing a directory of
employee information.
The employees are classified into staff members and managers. Different data is
maintained and the pay calculation method differs between staff members and
managers. The elements of the application are:
• An employee class that defines the attributes common to all employees
(AllMember-class)
• A staff member class that defines the attributes particular to staff employees
(Member-Class)
• A manager class that defines the attributes particular to managers (Manager-
Class)
The staff member and manager classes inherit the employee class.
The addresses portion of the employee information is managed by an independent
class (Address-Class).
Address objects are referenced from employee objects (and their subclasses).
The employee object defines the employee data to be managed by the supervisor.
Sample 18 use the dictionary class (Dict) created in Sample 16, “Collection Class
(Class Library)”. It registers an employee object with the dictionary using the
employee number as the key. The dictionary class allows easy repeat processing of
two or more employee objects, and easy retrieval of an employee object.
To operate the program, enter the number of the desired process into “Select
number” and press ENTER.
Note that this sample does not implement object persistence so data is lost when the
application terminates. See Sample 19 for the same application with persistence
added.
Address list
An employee address list can be printed. Select Manager (1) or General employee
(2), and then press the F3 key.
End
Terminates processing.
Appendix A. Sample Programs 223
Overview
The function of this sample is identical to that of Sample 18 except that the
employee and address objects are stored in an index file, and persistence functions
are added.
Persistence is implemented by adding the following methods to the employee and
address objects.
• Store-Method (Object method)
Stores an object in the file.
• RetAt-Method (Factory method)
Loads an object from the file using the employee number as the key.
• Remove-Method (Factory method)
Deletes an object from the file using the employee number as the key.
Actually, the object saving and retrieving is implemented by using the employee
master class and the address master class. From the object user (the MAIN program
in this example), however, the process is viewed as if the employee object assumed
all the tasks.
Overview
The management of employee information (addition, deletion, and modification), the
salary calculations, and address are printed as was done in sample 18.
In addition to the functions above, in this example the employee object and the
address object stored in the database, and a permanent object function is added.
These functions have been created in the employee and the address objects by
adding the following methods.
• Store-Method (object method)
: The object is stored in a database.
• RetAt-Method (object method)
: The object is read from the database using the employee number as the key.
• RemoveAt-Method (object method)
: The object is removed from the database using the employee number as the
key.
• Update-Method (object method)
Appendix A. Sample Programs 227
Available Programs
• MAIN.COB (COBOL source program)
• ALLMEM.COB (COBOL source program)
• MEMBER.COB (COBOL source program)
• MANAGER.COB (COBOL source program)
• ADDRESS.COB (COBOL source program)
• SET.COB (COBOL source program)
• ALLMEM_M.COB (COBOL source program)
• BONU_MAN.COB (COBOL source program)
• BONU_MEM.COB (COBOL source program)
• MEM_SET.COB (COBOL source program)
• MEM_STOR.COB (COBOL source program)
• MAN_SET.COB (COBOL source program)
• MAN_STOR.COB (COBOL source program)
• ADDR_M.COB (COBOL source program)
• SALA_MAN.COB (COBOL source program)
• SALA_MEM.COB (COBOL source program)
• SAMPLE20.PRJ (project file)
• SAMPLE20.CBI (compilation option file)
• SAMPLE20.MDB (Microsoft Access Database file)
• COBOL85.CBR (initialization file for execution)
• SAMPLE20.KBD (key definition file)
• SAMPLE20.INF (ODBC information file)
Repository paragraph
Class definition, object definition, factory definition, and method definition
You will add a new User DSN. Select the User DSN tab, and click on the Add button.
ODBC Data Source Administrator displays the “Create New Data Source” dialog box.
Select the Microsoft Access Driver (*.mdb) and click on the Finish button.
The ODBC Microsoft Access Setup dialog box is displayed.
Enter Sample20 in the Data Source Name field and Sample20 Database in the
Description field as shown above.
You also need to select a file (database) to bind this driver to. Click on the Select
button in the ODBC Microsoft Access Setup dialog box. The Select Database dialog
box is displayed. Navigate through the directories and find the "Sample20.mdb"
database file:
Click on the OK button. This will take you back to the ODBC Microsoft Access Setup
dialog box.
Appendix A. Sample Programs 231
Click on the OK button. This will take you back to the main ODBC Source
Administrator window.
Note that "Sample20" has been added to the list in User DSN. Although you should
not set any additional options for this exercise, you may wish to highlight “Sample20”
and click on the Configure button.
This will give you an idea of some of the additional options that are available when
developing these types of applications. Once you are back to the main ODBC Source
Administrator window, click on the OK button. This will exit the ODBC configuration
facility. You have now defined the new ODBC Source (Sample20) you are going to
use with COBOL.
The initialization file for execution is updated with the Run-time Environment Setup
Tool. The content is shown below.
1. The Run-time Environment Setup Tool is started.
2. The initialization file for execution is opened. (COBOL85.CBR)
3. A common tab is selected.
4. The ODBC information file name is specified for @ODBC_Inf. (SAMPLE20.INF)
5. The key definition file name is specified for @CBR_SCR_KEYDEFFILE.
(SAMPLE20.KBD)
Figure A.73. The Run-time Environment Setup Tool with COBOL85.CBR for Sample
20
6. Click "Apply" button, and the content is saved in the execution initialization file.
7. Click "Exit" button in file menu, and the Run-time Environment Setup Tool ends.
Appendix A. Sample Programs 233
For Windows NT® 4.0, Microsoft® Windows NT® OptionPack 4.0 is necessary.
Overview
The sample program consists of the following three parts.
• Initialization processing
The resource (file data) between threads is acquired, and is initialized.
• Authorization processing
The authorization process is achieved by accessing the resource (file data) between
threads.
• Termination processing
Appendix A. Sample Programs 235
Available Programs
• Project files
− ISAPIAPL.PRJ
− MTHAPL.CBI
• Option files
− ISAPIAPL.CBI
− MTHAPL.CBI
• COBOL source files
− AUTH.COB
− ISAINIT.COB
− ISATERM.COB
− MTHEND.COB
− MTHSTR.COB
− MTHUSRINF.COB
− SHUTDOWN.COB
− STARTUP.COB
− STUPINIT.COB
• Library text
− User-Info.CBL
− User-Lock.CBL
• Module definition files
− AUTH.DEF
− SHUTDOWN.DEF
− STARTUP.DEF
• Data files
− USERINFO
• Run-time Initialization file
− COBOL85.CBR
• HTML files
− ADMIN.HTML
− AUTH.HTML
− AUTHFAIL.HTML
236 Appendix A. Sample Programs
− AUTHSUCESS.HTML
− NOTOPENED.HTML
− OPENED.HTML
− SHUTDOWN.HTML
− STARTUP.HTML
− SYSERROR.HTML
− SYSTEMERROR.HTML
Process Flow
1. Business start and end
2. Authorization service
3. The project file is selected, and "Compiler options" is selected from "Project"-
"Options" menu.
→ The "Compiler options" dialog is displayed.
7. The compiler option dialog is displayed as in step 3 above, showing that the
compiler options THREAD(MULTI), SHREXT, and ALPHAL(WORD) are specified.
Modify the folder name of the library file specified in the compiler option LIB.
Click the OK button.
→You are now returned to the Project Manager window.
240 Appendix A. Sample Programs
Address │ http://user/sample21/admin.html
The administrator menu screen is displayed. Click on the “Set Starting Business”
hyperlink.
Appendix A. Sample Programs 241
When clicked, the authentication service begins. Please do so before starting the
authentication service.
2. The authentication service is started.
The following information is set in the URL and the "Execute" key is pushed.
Address │ http://user/sample21/Auth.html
The authentication service screen is displayed. After the screen is displayed, input a
User ID and password, then click the "OK" button.
Valid User ID’s are USER0001 to USER0030. The password is the same as the User
ID.
242 Appendix A. Sample Programs
Address │ http://user/sample21/admin.html
For Windows NT® 4.0, Microsoft® Windows NT® OptionPack 4.0 is necessary.
Overview
The sample program consists of the following five parts.
• Begin processing
The resource (file data) between threads is acquired and initialized.
• Authorization processing
The authorization processing is achieved by referring to the resource (file data)
between threads.
• Order confirmation processing
The order confirmation processing is performed by referring to the resource (file
data) between threads.
246 Appendix A. Sample Programs
Available Programs
• Project files
− ISAPIAPL.PRJ
− OLSAPL.PRJ
• Option files
− ISAPIAPL.CBI
− OLSAPL.CBI
• COBOL source files
− AUTH.COB
− CONFIRM.COB
− ENTRY.COB
− ISAINIT.COB
− ISATERM.COB
− OLSEND.COB
− OLSPRDGT.COB
− OLSSTCGT.COB
− OLSSTCODR.COB
− OLSSTR.COB
− OLSUSRINF.COB
− SHUTDOWN.COB
− STARTUP.COB
− STUPINIT.COB
• Library text
− Order-Info.CBL
− Product-Info.CBL
− Stock-Info.CBL
− User-Info.CBL
− User-Lock.CBL
− User-Log.CBL
• Module definition files
− AUTH.DEF
Appendix A. Sample Programs 247
− CONFIRM.DEF
− ENTRY.DEF
− SHUTDOWN.DEF
− STARTUP.DEF
• Data files
− PRODUCTINFO
− STOCKINFO
− USERINFO
• Run-time Initialization file
− COBOL85.CBR
• HTML files
− ADMIN.HTML
− AUTH.HTML
− AUTHFAIL.HTML
− CATALOG.HTML
− CONFIRMDETAILPARTS.HTML
− CONFIRMHEAD.HTML
− CONFIRMTAIL.HTML
− ILLIGALACCESS.HTML
− ILLIGALSYSTEM.HTML
− NOTOPENED.HTML
− OPENED.HTML
− ORDERDETAILPARTS.HTML
− ORDERRESULTHEAD.HTML
− ORDERRESULTTAIL.HTML
− SHOPPINGMENU.HTML
− SHORTAGESTOCK.HTML
− SHUTDOWN.HTML
− STARTUP.HTML
− STARTMENU.HTML
− SYSERROR.HTML
− SYSTEMERROR.HTML
− UNDERCONSTRUCTION.HTML
• GIF files
− CATALOGTITLE.GIF
− FJLOGO.GIF
248 Appendix A. Sample Programs
− TITLE.GIF
− LifeBookE.GIF
• JPEG files
− LifeBookB.JPG
− LifeBookC.JPG
− LifeBookL.JPG
Process Flow
1. Business start and end
Figure A.85. The process flow for Business start and end
Appendix A. Sample Programs 249
2. Online store
3. The project file is selected, and "Compiler options" is selected from the "Project"-
"Options" menu.
→ The "Compiler options" dialog is displayed.
Appendix A. Sample Programs 251
7. The compiler option dialog is displayed as in step 3 above. The compiler option
THREAD(MULTI), SHREXT, and ALPHAL(WORD) are specified. Modify the folder
name of the library file specified with the compiler option LIB. After
confirmation, the OK button is clicked.
When clicked, the online store is started. Please do the "Set starting business"
before starting online shopping.
2. Online store is started.
The following information is set in URL and the "Execute" key is pushed.
http://user/sample22/startmenu.html
Because the screen of an online store is displayed, the catalog shopping is clicked.
254 Appendix A. Sample Programs
When the "OK" button is clicked, the catalog screen is displayed. The catalog screen
shows you the various PC’s and their quantities available for ordering. To place an
order, select one or more products and enter an order quantity, then press the
“Order” button.
When the "Order" button is clicked, the order confirmation screen is displayed. The
content of the order is confirmed and the "Order issue" button is clicked.
When the "Order issue" button is clicked, the order result screen is displayed.
Appendix A. Sample Programs 257
Because the administrator menu screen is displayed, the "Set ending business" is
clicked.
258 Appendix A. Sample Programs
2. Detailed information is displayed when the source selects the log of "NetCOBOL
Application", and double-clicks it.
Appendix A. Sample Programs 259
Overview
The sample program performs the operations listed below for Excel from a COBOL
application.
• Excel activation and termination
• Excel sheet open
• Work sheet selection and data insertion
• Graph creation
• Printing of a selected sheet
The COBOL COM client function supports the early binding and late binding methods
to recognize COM server methods and interfaces.
Late binding is used in this sample.
When late binding is used, usable COBOL descriptions are limited and execution
performance is slower than early binding, but late binding is freer from the effects of
COM server modifications than early binding. When using late binding this program
can operate Excel97 and Excel2000, which are different COM servers.
For details of early binding, see Sample 24, "COM Program to Control Excel (Early
Binding)."
Available Programs
• SAMPLE23.PRJ (Project file)
• SAMPLE23.COB (COBOL source file)
• GRAPHDATA.XLS (Excel file for test)
Building/Rebuilding
The Project Manager's Build function is used to compile and link this program.
Folder C:\NetCOBOL is assumed below as the location where NetCOBOL is installed.
Change the folder name C:\NetCOBOL to the name of the folder where NetCOBOL is
installed.
1. Start the Project Manager.
Figure A.101. The Excel file name input screen for sample 23
2. Use the full path-name to specify an Excel file for the test.
→ The specified Excel file is opened and the sample program controls Excel.
The following message is displayed on the COBOL console and the system
waits for input again.
Overview
The sample program performs the operations listed below for Excel from a COBOL
application.
• Excel activation and termination
• Excel sheet open
• Work sheet selection and data insertion
• Graph creation
• Printing of selected sheet
The COBOL COM client function supports the early binding and late binding methods
to recognize COM server methods and interfaces.
Early binding is used in this sample.
When early binding is used, object property and in-line method invocation can be
written. Also, the performance is better than that of late binding. However, the
early binding method requires a type library during development and is liable to be
influenced by COM server modifications. This program uses the COM server name
EXCEL to use the Excel functions. An Excel type library must be specified for this
COM server name before compiling the program. Excel97 cannot be operated with
an executable file built by referencing an Excel2000 type library. Also, Excel2000
cannot be used with an executable file built by referencing an Excel97 type library.
For details of late binding, see Sample 23, "COM Program to Control Excel (Late
Binding)."
Available Programs
• SAMPLE24.PRJ (Project file)
• SAMPLE24.COB (COBOL source file)
Appendix A. Sample Programs 265
• Type library
The type library of Excel2002 or later is Excel.exe. Set COM server name as
shown below, assuming that Excel2002 is installed in the "C:\Program
Files\Microsoft Office".
Figure A.105. The Excel file name input screen for sample
2. Use the full path-name to specify an Excel file for the test.
→ The specified Excel file is opened and the program controls Excel. The
following message is displayed on the COBOL console and the system waits
for input again.
Overview
The sample program consists of two class definitions.
The COBOL ONLINE_STORE class is the COM server class. The ONLINE_STORE
class provides the following functions for constructing an online store application:
• Authorization processing
• Stock check
• Order registration
• Order exact calculation
In addition to COBOL programs, programs generated with Visual C++®, programs
generated with Visual Basic®, and active server pages (ASP) Visual Basic® Scripting
Edition (VBScript) can be used as client programs to use these functions. See
Sample 26 and Sample 27 for examples of the COBOL client and ASP client.
270 Appendix A. Sample Programs
Available Programs
• DB_ACCESS.COB (COBOL source file)
• ONLINE_STORE.COB (COBOL source file)
• STORESV1.PRJ (project file)
• STORESV1.CBI (compiler option file)
• STORESV1_DLL.CSI (COM server information file)
• STORESV1.DEF (module definition file)
- STOCK table
Use the format shown below to create this table.
PRODUCTNUMBER QUANTITY ←Column name
Fixed-length character Fixed-length character ←Column attribute
10 bytes 10 digits
↑ Primary key
Store the data items shown below in the stock table.
PRODUCTNUMBER QUANTITY
FMV2TXH111 900000
FMV2TXH161 100000
FMV2TXH151 500000
FMV2TXF111 45000
FMV2TXF161 300000
FMV2TXF151 60000
FMV2DXH111 90000
FMV2DXH161 55000
FMV2DXH151 990000
FMV2DXF111 10000
FMV2DXF161 777700
FMV2DXF151 200000
FMV2DXD111 690000
FMV2DXD161 870000
FMV2DXD151 619000
FMV2DXA111 2900000
FMV2DXA161 8760000
FMV2DXA151 100000
FMV3NA3LC0 10000
FMV3NA3LC6 300
272 Appendix A. Sample Programs
- ORDERTABLE
Use the format shown below to create this table.
ORDERNUMBER USERID DATE ←Column name
Fixed-length Variable-length Fixed-length ←Column attribute
character character character
12 bytes 32 bytes 14 bytes
↑ Primary key
No data need be stored in the ORDERTABLE table.
- ORDERDETAIL table
Use the format shown below to create this table.
ORDERNUMBER PRODUCTNUMBER QUANTITY ←Column name
Fixed-length Fixed-length Decimal ←Column attribute
character character integer
12 bytes 10 bytes 10 digits
The "View" dialog is opened and the server information can be referenced.
Figure A.112. The Run-time Environment Setup Tool with COBOL85.CBR for Sample
25
Overview
The sample program uses the COBOL server program generated in Sample 25 to
create the online store application. The client program accepts data input on the
screen by using the screen operation function and requests the server program to
process the accepted data. The result of the server program processing is displayed
on the screen.
Available Programs
• CLMAIN.COB (COBOL source program)
• ORDERSHEET-INFO.CBL (COBOL library file)
• PRODUCT-TABLE.CBL (COBOL library file)
• SCREENS.CBL (COBOL library file)
• SAMPLE26.PRJ (Project file)
• SAMPLE26.CBI (compiler option file)
3. Select the project file and select "Compiler Options" from the "Project-Option"
menu.
→ The "Compiler Options" dialog is displayed.
4. Click the COM Server button in the "Compiler Options" dialog.
→ The "COM Server" dialog is displayed.
5. Specify STORESV1.DLL (type library) for COM server name STORESV1. Check
the entry, then click the OK button.
→ The "Compiler Options" dialog is redisplayed. Click the OK button to
redisplay the Project Manager window.
6. Select "Build" from the "Project" menu.
→ After build termination, check that SAMPLE26.EXE is created.
Figure A.116. The Run-time Environment Setup Tool with COBOL85.CBR for
Sample 26
Executing
1. Select "Execute" on the "Project" menu.
→ The screen shown below is displayed. Input the user ID and password and
press the ENTER key (use the CURSOR or TAB key to move among the input
fields). Valid user IDs are USER0001 to USER0010 and the password is the
same as the user ID. Note that the entered password is not displayed.
Appendix A. Sample Programs 281
2. The menu screen is displayed. Input "1" and press the ENTER key.
3. The catalog screen is displayed. Input the number of items to be ordered. Use
the CURSOR or TAB key to move among the input fields. After entering the
data, press the ENTER key.
282 Appendix A. Sample Programs
4. The order check screen is displayed. Input "Y" and press the ENTER key.
5. The order list screen is displayed. The (2) menu screen is redisplayed when the
ENTER key is pressed.
6. To terminate the processing, input "2" on the menu screen and press the ENTER
key.
284 Appendix A. Sample Programs
Overview
ASP is one of the methods of constructing dynamic Web applications by embedding
script language in the HTML document.
A COM server object can be created in ASP VBScript by using a server object in
which the CreateObject method is installed. The method provided by the COM
server can be called from the created object.
Use this function to create online store Web applications using the COBOL server
program in Sample 25.
Available Programs
• MENU.ASP (ASP page file)
• AUTH.ASP (ASP page file)
• CATALOG.ASP (ASP page file)
• CONFIRM.ASP (ASP page file)
• ORDER.ASP (ASP page file)
• STYLE.CSS (style sheet file)
• CATALOGTITLE.GIF (image file)
• FJLOGO.GIF (image file)
Appendix A. Sample Programs 285
2. Input a virtual directory name, and then specify the physical path of Sample 27
with the ASP page file.
286 Appendix A. Sample Programs
Execution
Domain name "user" and virtual directory name "sample27" are assumed.
Microsoft Internet Explorer is used as the WWW browser.
1. Input the URL as shown below.
The menu screen is displayed. Select "Catalog Shopping" and click the OK
button.
Appendix A. Sample Programs 287
3. The catalog screen is displayed. Input the number of items to be ordered and
click the Order button.
4. The order check screen is displayed. Click the Order Issue button.
Appendix A. Sample Programs 289
5. The order reception screen is displayed. The (2) menu screen is redisplayed
when the Menu button is clicked.
290 Appendix A. Sample Programs
Overview
As in Sample 25, this sample program provides the following functions for
constructing an online store application:
• Authorization processing
• Stock check
• Order registration
• Order calculation
However, this program manages transactions directly from a COBOL program by
using the MTS functions.
In Sample 25, the embedded SQL statements COMMIT/ROLLBACK are used and
transaction management depends on the database. This is a simple approach for
292 Appendix A. Sample Programs
someone who is familiar with embedded SQL statements but increases the database
processing load.
This program manages transactions by itself with MTS functions. This reduces the
database processing load and enables more detailed transaction management.
There are two methods of using the MTS function for transaction management from
a COBOL application:
• Control of transactions where the object is operating from the COM server object
• Control of transactions where the COM server is operating from the COM client
The first method is shown below.
Available Programs
• DB_ACCESS.COB (COBOL source file)
• ONLINE_STORE.COB (COBOL source file)
• STORESV2.PRJ (project file)
• STORESV2.CBI (compiler option file)
• STORESV2_DLL.CSI (COM server information file)
• STORESV2.DEF (module definition file)
Appendix A. Sample Programs 293
The "View" dialog is opened and the server information can be referenced.
Appendix A. Sample Programs 295
Figure A.134. The Run-time Environment Setup Tool with COBOL85.CBR for
Sample 28
2. Select "Open" on the "File" menu and create an object initialization file
(COBOL85.CBR) in the folder that contains the dynamic link library
(SAMPLE28.DLL).
3. Select the Common tab and enter data as shown below:
- Specify an ODBC information file name in the environment variable
@ODBC_Inf (ODBC information file specification).
4. Click the Apply button.
→ The data is saved in the object initialization file.
5. Select "Exit" on the "File" menu to exit the tool.
- Open the project file SAMPLE26.PRJ, delete COM server name STORESV1,
and enter STORESV2.
- Rebuild SAMPLE26.EXE.
- Create an installation program for client information on the Sample 28
program and install it in the client.
• Using the ASP client in Sample 27.
Modify the CreateObject argument for COM object creation as shown below.
Catalog.asp
Confirm.asp
Order.asp
Overview
The sample program transfers messages between SAMPLE29 and COMMU.
SAMPLE29 establishes a connection to server "SERVER1", writes messages to logical
destination "MYLD1", and reads messages from logical destination "MYLD2". If no
message comes from logical destination "MYLD2", SAMPLE29 waits for the message
arrival for up to 60 seconds. After reading messages from the logical destination
"MYLD2", SAMPLE29 reads messages from logical destination "MYLD1" in order of
priority.
COMMU establishes a connection to server "SERVER1", reads messages from logical
destination "MYLD1", then writes messages to logical destinations "MYLD1" and
“MYLD2”.
Available Programs
• SAMPLE29.COB (COBOL source program)
• COMMU.COB (COBOL source program)
• SAMPLE29.PRJ (Project file)
• PRM_REC.CBL (library text)
• SAMPLE29.INI (logical destination definition file)
Prerequisites to Execution
To make the Sample 29 programs ready for execution, execute the following utility:
• COBCISRV
After you run this, you can build and execute Sample 29.
You may refer to Chapter 18, “Communication Functions” in the “NetCOBOL User’s
Guide for Windows” for more general information on the following topics:
• Activating the server for simplified inter-application communication.
• Creating logical destinations "LD1" and "LD2" on the server for simplified inter-
application communication.
• Changing the information on the opponent machine name of the logical
destination definition file (SAMPLE29.INI) by using the logical destination
definition file creation utility (COBCIU32.EXE). Specify the host name of the
server as the opponent machine name and click on the Set button.
Figure A.138. The Run-time Environment Setup Tool with COBOL85.CBR for
Sample 29
2. Select "Open" on the "File" menu and create an object initialization file
(COBOL85.CBR) in the folder that contains the executable file (SAMPLE29.EXE).
3. Select the Common tab and enter data as shown below:
- The path name of the logical destination definition file of the @CBR_CIINF
environment variable has been pre-assigned to SAMPLE29.INI. This is the
default setting for both the SAMPLE29 and COMMU executable files.
4. Click the Apply button.
→ The data is saved in the run-time initialization file.
302 Appendix A. Sample Programs
5. Select "Exit" on the "File" menu to terminate the run-time environment setup
tool.
Execution Result
1. Messages from SAMPLE29 have been read from logical destination "MYLD1".
2. Messages have been written to logical destination "MYLD1" and logical
destination "MYLD2".
Overview
Sample 31 calls the Windows system function "MessageBoxA" to display a message
in a message box with YES,NO and Cancel buttons. (Note that an "A" needs to be
appended to the function call when the function call contains a character string
parameter and you are working in ASCII, as opposed to Unicode data, when the
suffix is "W".)
The call uses the STDCALL calling convention.
The message box returns a value indicating which button was pressed. This value is
returned in the data item specified in the RETURNING phrase.
It is possible to refer to this return value in a batch file. In a batch file, you can
access this return value by the name ERRORLEVEL. SAMPLE31.BAT demonstrates
this as follows.
NOTE:
1. Most Windows system functions (and C routines in general) require that strings
be terminated with a null byte (X"00" or LOW-VALUE). The sample shows how
you can place these bytes using reference modification.
2. The Windows system function names are case sensitive. So be sure to get the
case correct as in "MessageBoxA". You need to specify the compiler option
"NOALPHAL" or "ALPHAL(WORD)" to ensure the COBOL system uses mixed case
for the function name.
Library file "USER32.LIB" is required to link the program. It is used to ensure the
linker can resolve the external reference "MessageBoxA". If you installed the
product to something other than the default folder structure, you should change
the folder name to match the folder structure you are using.
306 Appendix A. Sample Programs
2. The following message boxes are displayed. Click one of the buttons.
3. The COBOL program detects which button was pressed and indicates such by
displaying a message.
Overview
When SAMPLE32 is executed, you are prompted for a program to run. If you enter
nothing, the program MSGBOX.EXE from the SAMPLE31 folder is executed. If you
specify a program name, you must enter the fully qualified path to the location of the
application (or batch file) to execute.
The Windows system function “CreateProcessA” is called specifying this for the
argument, and specified program or batch file is started.
If the specified program is successfully started, SAMPLE32 then waits until the
specified program terminates and then receives the completion code from the started
program.
2. Input the path and filename of an executable program or batch file. The
environment variable PATH is not referenced here, therefore it is necessary to
specify a relative path from the SAMPLE32 folder, or a fully qualified path name.
If nothing is entered, then MSGBOX.EXE of SAMPLE31 is executed. Press the
ENTER key.
3. The completion code of MSGBOX.EXE of SAMPLE31 is displayed (indicating what
button was pushed). In the following screen, the “No” button was pressed.
6. SAMPLE06.EXE requires two command line arguments. Please note that the
command line arguments are specified following the program name.
7. A message indicating that SAMPLE06 has been started is displayed. (The system
console is opened and the execution result of SAMPLE06 is output.) The
completion code of SAMPLE06.EXE is displayed and execution ends.
312 Appendix A. Sample Programs
314
Appendix C. Support
We want your evaluation to be productive so don't hesitate to contact us if there are
questions you need answered or points you believe we have missed in introducing
you to our products.
Use one of the following:
• Check our support pages at "www.netcobol.com/support/". They contain lists of
tips, frequently asked questions, white papers and other helpful information.
• Use the Question or Incident reporting forms supplied in the support pages to
shoot your question or problem into our tracking and answering system. We aim
to respond within 24 hours.
• Email our support group at: support@netcobol.com
• For more general COBOL questions email: COBOL@netcobol.com
• Call our support line on 1-408-428-0500.
316 Appendix C. Support
316
Index
@MGPRM, 143 class library, 200
A brief history of COBOL, 63 CLOSE, 135, 138
ACCEPT, 128, 138 CM, 45
FROM argument-name, 150 CM Status, 51
FROM environment-name, 154 COBOL
aggregation, 211 compiler, 11
ANSI 74, 19 dialects, 11
ANSI 85, 19 files, 26
application OO, 53
building, 24 COBOL DLL
execution, 25 interaction with Visual Basic, 89
argument COBOL File Utility, 26
command line, 150 collection class, 200
arrays, 91 command line argument, 150
benchmarks, 11 compiler
browse data files, 26 option setting, 25, 27, 313
building COMPUTE, 150
applications, 24 configuration management, 12, 43
errors, 24 adding files, 50
BY VALUE, 305 check in, 53
CALL, 143 check out, 52
calling configuring, 49, 313
COBOL from VB, 185, 190 free format code, 49
Windows system functions, 304 help, 313
calling convention in Development Manager, 313
STDCALL, 304 in Project Manager, 51
CHARACTER TYPE, 161 maintaining, 44
Class Browser, 58 CONNECT, 171
invoking, 59 convert data files, 26
window, 60 data file i/o function, 313
class information database, 59 data files
creating, 59 converting, 26
tip, 313 editing, 26
318 Index