Professional Documents
Culture Documents
Micro Focus
®
Net Express
Solutions Guide
sgpubb.book Page 2 Friday, April 14, 2000 11:08 AM
MERANT has made every effort to ensure that this book is correct and accurate, but
reserves the right to make changes without notice at its sole discretion at any time.
The software described in this document is supplied under a license and may be used
or copied only in accordance with the terms of such license, and in particular any
warranty of fitness of MERANT software products for any particular purpose is
expressly excluded and in no event will MERANT be liable for any consequential loss.
Micro Focus®, Animator® and Forms-2® are registered trademarks, and AAI™,
Analyzer™, Animator Version 2™, Application to Application Interface™, AppTrack™,
CCI™, Co-Writer Builder™, Co-Writer Designer™, Co-Writer™, Co-Writer Report™,
Dialog System™, Directory Facility™, Forms™, LEVEL II COBOL™, LEVEL II COBOL/ET™,
Micro Focus COBOL™, Micro Focus COBOL/2™, Object COBOL™, Operating System
Extensions™, OSX™, Panels™, Panels Version 2™, Professional COBOL™, RTE™,
Screens™, Session Recorder™, Structure Animator™, Toolbox™, VS COBOL™,
Workbench™, Xilerator™, XM™ and MERANT™, are trademarks of MERANT. All
other trademarks are the property of their respective owners.
No part of this publication, with the exception of the software product user
documentation contained on a CD-ROM, may be copied, photocopied, reproduced,
transmitted, transcribed, or reduced to any electronic medium or machine-readable
form without prior written consent of MERANT.
Licensees may duplicate the software product user documentation contained on a CD-
ROM, but only to the extent necessary to support the users authorized access to the
software under the license agreement. Any reproduction of the documentation,
regardless of whether the documentation is reproduced in whole or in part, must be
accompanied by this copyright statement in its entirety, without modification.
U.S. GOVERNMENT RESTRICTED RIGHTS. It is acknowledged that the Software and the
Documentation were developed at private expense, that no part is in the public
domain, and that the Software and Documentation are Commercial Computer
Software provided with RESTRICTED RIGHTS under Federal Acquisition Regulations
and agency supplements to them. Use, duplication or disclosure by the U.S.
Government is subject to restrictions as set forth in subparagraph (c)(1)(ii) of The
Rights in Technical Data and Computer Software clause at DFAR 252.227-7013 et. seq.
or subparagraphs (c)(1) and (2) of the Commercial Computer Software Restricted
Rights at FAR 52.227-19, as applicable. Contractor is MERANT, 701 East Middlefield
Road, Mountain View, California 94043. Rights are reserved under copyright laws of
the United States with respect to unpublished portions of the Software.
sgpubb.book Page 3 Friday, April 14, 2000 11:08 AM
Table of Contents
1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
1.1 Purpose of this Book . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
1.2 Example Scenarios . . . ...... ...... ....... ...... ....... . 6
1.2.1 Gas Services . . . . ...... ...... ....... ...... ....... . 6
1.2.1.1 Phase 1 . . . ...... ...... ....... ...... ....... . 6
1.2.1.2 Phase 2 . . . ...... ...... ....... ...... ....... . 7
1.2.1.3 Phase 3 . . . ...... ...... ....... ...... ....... . 7
1.2.1.4 Phase 4 . . . ...... ...... ....... ...... ....... . 7
Solutions Guide
sgpubb.book Page 4 Friday, April 14, 2000 11:08 AM
4 Data Access . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
4.1 Challenge: Accessing an RDBMS . . . . . . . . . . . . . . . . . . . . . . . . . . 41
4.1.1 Solution: OpenESQL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
4.1.1.1 Practical Considerations . . . . . . . . . . . . . . . . . . . . . . . 42
4.1.1.2 Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
4.1.2 Solution: Internet Application Wizard . . . . . . . . . . . . . . . . 61
4.1.2.1 Practical Considerations . . . . . . . . . . . . . . . . . . . . . . . 62
Solutions Guide
sgpubb.book Page 5 Friday, April 14, 2000 11:08 AM
1 Introduction
This chapter explains the purpose of this book, who should read it, and
how it fits into the rest of the Net Express documentation. It also
explains the imaginary organization and scenarios that are used for the
examples in the rest of the book.
Solutions Guide
sgpubb.book Page 6 Friday, April 14, 2000 11:08 AM
6 Chapter 1 Introduction
1.2.1.1 Phase 1
Gas Services customers can currently supply their own meter reading by
using Gas Services’ telephone Helpline. There is a requirement,
however, for customers to be able to connect to a page on the World
Wide Web, and update their meter reading using a Web application.
The server-side program will be run on the existing Gas Services
Windows NT Web server.
Solutions Guide
sgpubb.book Page 7 Friday, April 14, 2000 11:08 AM
1.2.1.2 Phase 2
Gas Services require a client/server system to support their Helpline
operators in dealing with customer enquiries. Customers can call the
Helpline to give their own meter reading, to change their choice of gas
tariff, to make enquiries about their invoices, or to make general
enquiries. The Helpline operators need a system to provide the
necessary customer data from the operational database system, and to
accept changes they make to the data. The Helpline supervisor
additionally requires the system to generate follow-up letters at the
end of each working day to customers who have requested a change in
their gas supply tariff.
1.2.1.3 Phase 3
The merger with WestGas is complete.
1.2.1.4 Phase 4
Gas Services offers twelve standard gas tariffs. Due to difficult market
conditions, however, the corporation has had to introduce a special
tariff that can be tailored to the customer’s individual circumstances. A
telephone Helpline operator can find out how much gas a customer
has used over the last twelve months and, using this to represent a
typical year’s consumption, explore how the charges vary as the tariff
variables are adjusted.
Solutions Guide
sgpubb.book Page 8 Friday, April 14, 2000 11:08 AM
8 Chapter 1 Introduction
Solutions Guide
sgpubb.book Page 9 Friday, April 14, 2000 11:08 AM
2 Developing Client/Server
Applications
Solutions Guide
sgpubb.book Page 10 Friday, April 14, 2000 11:08 AM
Solutions Guide
sgpubb.book Page 11 Friday, April 14, 2000 11:08 AM
Solutions Guide
sgpubb.book Page 12 Friday, April 14, 2000 11:08 AM
Solutions Guide
sgpubb.book Page 13 Friday, April 14, 2000 11:08 AM
• Windows 2000
• Windows 98
• Windows 95
• SCO
• AIX
• HP/UX
• Sun Solaris
(Applications created with Internet Application Wizard are not
suitable for deploying on UNIX)
• TCP/IP
• Microsoft Network
• NetBEUI
Solutions Guide
sgpubb.book Page 14 Friday, April 14, 2000 11:08 AM
• Web servers:
• Web browsers:
• HTML Painters:
• Microsoft FrontPage 97
• NetObjects Fusion
• Middleware:
• Databases:
• Oracle V7 and V8
• Sybase V11.0.1
• Informix V9.x
Solutions Guide
sgpubb.book Page 15 Friday, April 14, 2000 11:08 AM
• VisualAge TeamConnection
Solutions Guide
sgpubb.book Page 16 Friday, April 14, 2000 11:08 AM
Solutions Guide
sgpubb.book Page 17 Friday, April 14, 2000 11:08 AM
17
Solutions Guide
sgpubb.book Page 18 Friday, April 14, 2000 11:08 AM
The Web browser knows what to do with all the many types of
document because the documents are all coded using a standard
language, Hypertext Markup Language, or HTML. HTML is a simple text
markup language, consisting of plain text surrounded by tags that mark
the beginning and end of meaningful constructions in the file. A sample
Solutions Guide
sgpubb.book Page 19 Friday, April 14, 2000 11:08 AM
HTML file and the result as it would appear if opened in a Web browser
are shown below.
<html>
<head>
<title>A Sample Web Page</title>
</head>
<body>
<h1>HTML Sample</h1>
<img src="nxbkcovr.gif">
<p>
This is an example of a simple Web page containing a graphic
and a paragraph of text.
</p>
</body>
</html>
Figure 3-1. How the sample HTML page looks in a Web browser
Solutions Guide
sgpubb.book Page 20 Friday, April 14, 2000 11:08 AM
• A form for the end-user to enter queries and updates, and for
display of data
• A server-side program.
Solutions Guide
sgpubb.book Page 21 Friday, April 14, 2000 11:08 AM
3 The user fills out the form and clicks the ’Submit’ button.
The Web browser takes care of how the controls on the form actually
work. For example, it ensures that only one radio button in each set
can be selected at a time; it automatically populates a listbox with the
data that you supply, and so on. When the user has entered all the
required data on the form, they click a ’Submit’ button, and the
information they entered is sent back to the Web server.
Solutions Guide
sgpubb.book Page 22 Friday, April 14, 2000 11:08 AM
Once the server-side program has processed the data sent in a form, it
can return any type of document supported by a Web browser. For
example, it could return an ordinary Web page containing the results,
or another HTML form requesting further information. If you have used
systems like CICS and IMS, you will immediately see the similarity
between them and a Web application. They all use a batch, or
transaction, processing system, where data is sent to and received from
the user interface in discrete chunks, and there is no communication
between the client and server except when a chunk of data is being
passed between them.
Creating the user interface for a Web application is very easy - you can
just paint the forms you require in Form Designer. Form Designer
creates the HTML files containing the markup for your forms, and also
the copyfiles that contain the data definitions you need in your
program to access the data from your forms. If you have an existing
application, use the Internet Application Wizard to create a simple
HTML form from it, then change the form to make it look how you
want using Form Designer. If you are creating a Web application from
scratch, use Form Designer directly to create your new form.
As well as HTML form controls, you can add ActiveX controls and Java
applets to your HTML forms. These are both different ways of adding
more interactivity to a form. For more information see the chapter
Forms and HTML in the Internet Applications online book.
You can use Form Designer to create two different types of output for
forms:
• Cross-platform HTML
• Dynamic HTML
Solutions Guide
sgpubb.book Page 23 Friday, April 14, 2000 11:08 AM
Overview of steps:
• Save form
• Save form
• Debug
Solutions Guide
sgpubb.book Page 24 Friday, April 14, 2000 11:08 AM
3.3.1.1 Example
Phase 1 of the Gas Services scenario (see the section Example Scenarios
in the chapter Introduction for more details) provides an example of a
Web application that uses a server-side CGI program. This application
consists of a form that the user can access using the World Wide Web.
The form has fields that enable the user to enter their account number
and a new meter reading. When the user clicks the ’Submit’ button, the
meter reading is updated in the Gas Services database, and a
confirmation page is sent back to the user. A prototype of the input
form for this application is shown below.
Figure 3-3. A prototype input form for the Gas Services Web
application
Solutions Guide
sgpubb.book Page 25 Friday, April 14, 2000 11:08 AM
Figure 3-4. Designing the Gas Services input form in Form Designer
Solutions Guide
sgpubb.book Page 26 Friday, April 14, 2000 11:08 AM
Solutions Guide
sgpubb.book Page 27 Friday, April 14, 2000 11:08 AM
Because the original application is unchanged, you can roll out the new
interface gradually, allowing users to choose either interface during
the transition period. Or, you can try out the new interface with a small
group of users on a live production application - it won’t affect other
users, who can still use the original interface.
Overview of steps:
• Create a project
• Select the .cbl file you want to generate the form from
Once you have created a form using the Internet Application Wizard,
you can import it into Form Designer to make final adjustments to its
appearence.
Solutions Guide
sgpubb.book Page 28 Friday, April 14, 2000 11:08 AM
These three interface standards are explained in more detail later in this
chapter, and in the chapter CGI, ISAPI and NSAPI Programs in the
Internet Applications online book. All three standards achieve a similar
end result, but the method of achieving it is different in each case. Net
Express enables you to easily create a server-side program that conforms
to any of these interface types just by changing a few build options.
Entry fields and controls for entering data. Clicking the submit
button posts the data to the Web server and starts the server-side
program.
Uses an ACCEPT statement to receive the data from the form, and a
DISPLAY statement to send back the output page. Two new clauses
enable you to tie group data items to HTML forms and pages, and
Solutions Guide
sgpubb.book Page 29 Friday, April 14, 2000 11:08 AM
• An output page
When the end-user submits the form, all the information entered onto
it is packaged into a single stream, and sent back to the Web server
with an instruction to run the server-side program. The server-side
program unpacks the stream and processes the user input, before
returning a result. The diagram below shows the way a Web
application is executed.
Solutions Guide
sgpubb.book Page 30 Friday, April 14, 2000 11:08 AM
1 The end-user fills in an HTML form and clicks a Submit Form button.
The information in the fields on the form is bundled into a single
stream of data, and sent to the Web server, which interprets it as a
request to run the server-side program.
2 The Web server starts the requested server-side program, and sends
it the data stream.
With most languages you need to write (or find) code to parse the data
stream into the server-side program. Net Express has server-side support
built in, using the familiar ACCEPT and DISPLAY verbs. A Net Express
COBOL server-side program can ACCEPT an input form, and DISPLAY an
output form.
Solutions Guide
sgpubb.book Page 31 Friday, April 14, 2000 11:08 AM
Solutions Guide
sgpubb.book Page 32 Friday, April 14, 2000 11:08 AM
3.5.1.3 Example
Phase 1 of the Gas Services scenario (see the section Example Scenarios
for more details) provides an example of a Web application that uses a
server-side CGI program. See the example in the section HTML Form for
details of how we used Form Designer to create the input form.
When the user has submitted the form, and the database has been
updated, a confirmation page is returned to the user. It looks like this:
Figure 3-6. A prototype HTML output page for the Gas Services Web
application
Solutions Guide
sgpubb.book Page 33 Friday, April 14, 2000 11:08 AM
1 With our project open, we created a new HTML page called gas1,
choosing Blank form and Cross-platform (table output).
Name COBOLPicture
ACNumber X(4)
Outputdate X(10)
MeterReading X(5)
Solutions Guide
sgpubb.book Page 34 Friday, April 14, 2000 11:08 AM
When the user clicks on the Submit button, the browser returns a
data item called ssubmit that contains the text of the caption that
appears on the Submit button. If, when we test this data item, it
consists entirely of spaces, we know that the user has not clicked the
Submit button. So the program must have been started by the Web
server, and we need to display the input form. If ssubmit contains
the text of the button caption (that is, it does not consist entirely of
Solutions Guide
sgpubb.book Page 35 Friday, April 14, 2000 11:08 AM
spaces), we know that the user has clicked the Submit button, so
we must query the database and send back the output form.
Solutions Guide
sgpubb.book Page 36 Friday, April 14, 2000 11:08 AM
Solutions Guide
sgpubb.book Page 37 Friday, April 14, 2000 11:08 AM
You can, however, use the Net Express Internet Application Wizard to
create an ISAPI application, in which case all of the build settings are
automatically created for you.
Solutions Guide
sgpubb.book Page 38 Friday, April 14, 2000 11:08 AM
Solutions Guide
sgpubb.book Page 39 Friday, April 14, 2000 11:08 AM
If you want the server to call functions in your DLL, you need to create
an import library for the Netsite server. If you want to access server
functions, you need to link the server import library to your DLL.
Solutions Guide
sgpubb.book Page 40 Friday, April 14, 2000 11:08 AM
Solutions Guide
sgpubb.book Page 41 Friday, April 14, 2000 11:08 AM
41
4 Data Access
Solutions Guide
sgpubb.book Page 42 Friday, April 14, 2000 11:08 AM
communicates only with the ODBC driver, it does not have to be aware
of the nature of the database, and so a database connected through an
ODBC driver is usually referred to as an ODBC data source.
Solutions Guide
sgpubb.book Page 43 Friday, April 14, 2000 11:08 AM
Of course, you can also write your own SQL statements or modify those
produced by OpenESQL Assistant. Most vendors provide SQL Reference
documentation with their ODBC driver software.You can find more
information about the supported statements, including their full
syntax, in this documentation. There are a number of useful sources of
SQL information on the Web. You can find these by entering SQL as the
search string in your favorite Web search engine - for example, Yahoo!
or Alta Vista. To get you started, try
http://www.merant.com/ads/docs/nx/links.htm#sql1
We advise you to use only a single SQL statement in each EXEC SQL /
END-EXEC statement. For example, if you want to define a cursor and
fetch multiple rows from a database, we advise you to use several EXEC
SQL statements, as follows:
EXEC SQL
DECLARE mycursor CURSOR
FOR SELECT mycolumn_NAME FROM mytable
END-EXEC
EXEC SQL
OPEN mycursor
END-EXEC
EXEC SQL
FETCH mycursor INTO :myfirstname
END-EXEC
EXEC SQL
FETCH mycursor INTO :mysecondname
END-EXEC
EXEC SQL
CLOSE mycursor
END-EXEC
Solutions Guide
sgpubb.book Page 44 Friday, April 14, 2000 11:08 AM
• Implicit connection.
Use this in the simple case where your program connects to only one
database, and always uses the same username. You need to know
the name of the ODBC data source, the username and the password
at the time you build your program. You can specify these
parameters using the SQL compiler directive - for example:
SQL(DBMAN=ODBC,INIT,DB=gasops,PASS=public.meters)
• Explicit connection.
Host variables
Host variables are data items defined in a COBOL program and used as
variable parameters in the ESQL section of the program. They are used
to pass values to and receive values from an ODBC data source. Host
variables can be defined in the File Section, Working-Storage Section,
Local-Storage Section or Linkage Section of your COBOL program and
have any level number between 1 and 48. Level 49 is reserved for data
items of the SQL data type varchar. When a host variable name is used
within an ESQL statement, the data item name must begin with a colon
Solutions Guide
sgpubb.book Page 45 Friday, April 14, 2000 11:08 AM
Note: If you design your input form in Form Designer and generate a
skeleton CGI program using the Internet Application Wizard, host
variables are automatically created to contain the data from any entry
fields on the form. The host variable name is the same as the name that
appears in the tree view of controls in Form Designer. You can control
the data type of the host variable by setting the COBOLPicture
property of the appropriate control.
COBOL does not allow the use of the characters "-" and ":" in an
edited field, so they must be defined using a group data item.
However, the ODBC standard requires that group data items are
expanded into their constituent parts when passed to the database. It
is therefore necessary to redefine the group item to create a single
data item. For example:
01 mydate.
03 myyear pic x(4).
03 filler pic x value "-".
03 mymonth pic x(2).
03 filler pic x value "-".
03 myday pic x(2).
01 SQLmydate redefines mydate pic x(10).
The Gas Services example later in this chapter shows how you can
ACCEPT a date and pass it to the database in the correct form.
Solutions Guide
sgpubb.book Page 46 Friday, April 14, 2000 11:08 AM
• Define a group item with usage comp or comp-5, where the first
item contains the length of the string and the second item contains
the string itself. Both items must have a level number of 49. For
example:
01 varchar1.
49 varchar1-len pic 9(4) comp-5.
49 varchar1-data pic x(200).
01 Longvarchar1.
49 Longvarchar1-len pic 9(4) comp.
49 Longvarchar1-data pic x(30000).
If the data being copied to an SQL char, varchar or long varchar data
type is longer than the defined length, the data is truncated and the
sqlwarn1 flag in the sqlca data structure is set. If the data is smaller than
the defined length, a receiving char data type might be padded with
blanks.
Error handling
If an SQL statement fails to complete, an error code is returned to your
program. You should check for an SQL error after each SQL statement.
The ODBC driver returns the error information in a data block called the
SQL communications area, or sqlca. The sqlca contains two variables
(sqlcode and sqlstate) plus a number of warning flags that indicate
whether an error has occurred in the most recently executed SQL
statement. For more detailed information on the SQL communications
area (sqlca) and the sqlstate variable, look up sqlcode and sqlstate in the
help index.
Solutions Guide
sgpubb.book Page 47 Friday, April 14, 2000 11:08 AM
Value Meaning
0 The statement ran without error.
1 The statement ran, but a warning was generated.
The values of the sqlwarn flags should be checked to
determine the type of error.
100 Data matching the query was not found or the end
of the results set was reached. No rows were
processed.
< 0 (negative) The statement did not run due to an application,
database, system, or network error.
To include the sqlca data block in your program, use the EXEC SQL
INCLUDE SQLCA END-EXEC statement in the data division, as in the
following example:
working-storage section.
...
EXEC SQL INCLUDE SQLCA END-EXEC
procedure division.
EXEC SQL
SELECT company, city INTO :pcompany, :pcity
FROM customer
WHERE custid = :pcustid
END-EXEC
if sqlcode not = 0
if sqlcode = 100
display "No customer found"
else
display sqlcode
display sqlerrmc
end-if
else
display "Company for " pcustid " is " pcompany
display "City for " pcustid " is " pcity
end-if
Solutions Guide
sgpubb.book Page 48 Friday, April 14, 2000 11:08 AM
procedure division.
EXEC SQL WHENEVER SQLERROR PERFORM ERROR-PROC END-EXEC
EXEC SQL
...
END-EXEC
stop run.
error-proc.
display "SQL Error"
display "SQLCODE = " sqlcode
display "SQLERRMC = " sqlerrmc
display "MFSQLMESSAGETEXT = "
display mfsqlmessagetext.
Porting to UNIX
If you are developing a program that will be ported to a UNIX server, we
recommend that you code and debug using Net Express on Windows,
and recompile the finished program on UNIX using the RDBMS vendor’s
COBOL ESQL precompiler for the target database. You need to ensure
that you use only SQL statements and data types that are supported by
the target database. In practise, most precompilers support ANSI SQL92
syntax, but you should be particularly careful in the following areas:
Solutions Guide
sgpubb.book Page 49 Friday, April 14, 2000 11:08 AM
You must also take care to use COBOL data types that are portable to
UNIX. In particular, be careful when using COBOL data items with
usage comp-5. These data items might not port as you expect, because
of the different default byte-ordering between the two platforms. Use
comp-x (or display) instead.
4.1.1.2 Example
The Web application for Phase 1 of the Gas Services scenario (see the
section Example Scenarios for more details) provides a simple example
of an OpenESQL query embedded in a COBOL server-side program. In
this case, the application updates an SQL database with data entered
by the user on an HTML form; then it queries the database to return
the updated information back to the user. The query is not necessary to
obtain the information, but is used to provide reliable confirmation
that the database was updated correctly.
The database, which has the ODBC data source name gasops, is
updated by adding a row to a table called transact. This table has one
row for each gas transaction, and consists of the following columns:
Solutions Guide
sgpubb.book Page 50 Friday, April 14, 2000 11:08 AM
• The unique transaction number for each row of the table must be
calculated by the COBOL program (that is, the database does not
create this number automatically)
The entry is confirmed to the user by querying the table for the latest
meter reading on the specified account number.
4 Read the database to check that the update has been correctly
made.
Solutions Guide
sgpubb.book Page 51 Friday, April 14, 2000 11:08 AM
linkage section.
copy "mycgi.cpy".
01 Outputdate pic x(10).
dbconnect section.
dbgettrans section.
dbupdate section.
dbread section.
dbdisconnect section.
This program will be called from the CGI program and will return its
results to the CGI program. The only data items in which the CGI
program knows about when it is first generated are those that are
represented on the input form. These are defined in the copyfile
mycgi.cpy that was automatically generated when the form was
created. We can obtain access to these data items simply by including
the copyfile in the linkage section of our new program. However, there
is a further data item that we want to return to our HTML output page
that is not represented on the form: the current date. We can arrange
to pass this back to our CGI program by defining it in the working-
storage section of the CGI program, and using it as one of the calling
parameters of metersql.cbl. This means that it must be declared in the
linkage section of metersql.cbl.
Solutions Guide
sgpubb.book Page 52 Friday, April 14, 2000 11:08 AM
4 We selected the correct data source name when the ODBC Select
Data Source dialog box appeared.
5 We entered our userid and password on the SQL Server Login dialog
box to gain access to the data source.
Solutions Guide
sgpubb.book Page 53 Friday, April 14, 2000 11:08 AM
There were also two SELECT statements to add to our program: one to
get the last transaction number and one to read back the data added
to the database by our program.
Solutions Guide
sgpubb.book Page 54 Friday, April 14, 2000 11:08 AM
Although most data sources support a MAX function, the syntax used
depends on the RDBMS. The syntax shown above is correct for our
target system, Microsoft SQLServer.
6 We clicked the > button to add this expression to the search criteria
listbox.
11 We clicked the Query tab, then we clicked the icon to add the
SQL statement to our program.
This query looks up the rows in the table transact where the account
number corresponds to the user’s account number, and the transaction
type code is 9 (customer meter reading). In practise, a customer might
Solutions Guide
sgpubb.book Page 55 Friday, April 14, 2000 11:08 AM
The host variables that correspond to columns in the database have the
same names as the columns (with underscores translated to hyphens),
but are prefixed by the table name. So, for example, the column
ACC_TRANS_NO has a corresponding host variable, transact-ACC-
TRANS-NO. The table-name prefix is an option that you can change by
clicking Embedded SQL on the Options menu of Net Express.
Solutions Guide
sgpubb.book Page 56 Friday, April 14, 2000 11:08 AM
The other variables used in this example are Input1, Input2 and
Outputdate. These are all related to the input form and output page of
the CGI program rather than with accessing the database, but as they
are used to pass data between the two programs we had to ensure the
data types were compatible.
Input1 holds data entered in the first entry field of the input form. It
contains the customer’s account number, and corresponds to the
ACCOUNT_NO column in the database. Input2 holds data entered in the
second entry field of the input form. It contains the customer’s meter
reading, and corresponds to the column TRANS_UNITS.
From this, you can see that we needed to define Input1 as a pic s9(9)
comp-5 and Input2 as a pic s9(9)v9(2) comp-3.
Solutions Guide
sgpubb.book Page 57 Friday, April 14, 2000 11:08 AM
Solutions Guide
sgpubb.book Page 58 Friday, April 14, 2000 11:08 AM
The size of this data item is calculated from the COBOLPicture property -
in our example, ACNumber is equivalent in size to a pic x(10), and
MeterReading is equivalent in size to a pic x(13) data item.
Because HTML consists of plain text, the pic x data item is the only one
that can be displayed by the browser. Data conversion routines in the
skeleton CGI program move the data from f-MeterReading to
MeterReading when the input form is submitted; and from
MeterReading to f-MeterReading when the output form is displayed.
Note that this means that if you create one of the forms outside of Form
Designer (as we have done, because we wanted an HTML page for the
output instead of a form), you must remember to use the correct data
name (the one with the f- prefix) as a placeholder in the HTML.
Solutions Guide
sgpubb.book Page 59 Friday, April 14, 2000 11:08 AM
linkage section.
*> This is the copyfile that was generated when we created
*> the input form
copy "mycgi.cpy".
01 Outputdate pic x(10).
dbconnect section.
EXEC SQL
CONNECT TO ’boxtest’ USER ’rjh.rtfm’
END-EXEC
.
dbgettrans section.
EXEC SQL
SELECT
MAX(A.ACC_TRANS_NO)
INTO
:transact-ACC-TRANS-NO
FROM transact A
END-EXEC
add 1 to transact-ACC-TRANS-NO
move function integer-part(Input2) to tempint
move tempint to mreading
.
dbupdate section.
move ACNumber to transact-ACCOUNT-NO
move 9 to transact-TRANS-TYPE
move SQLtextnote to transact-TRANS-TEXT
move MeterReading to transact-TRANS-UNITS
move SQLtoday to transact-TRANS-POST-DATE,
transact-TRANS-EFFECT-DATE
*> We have replaced three of the host variables in the
*> following statement with literals, because they are
Solutions Guide
sgpubb.book Page 60 Friday, April 14, 2000 11:08 AM
Solutions Guide
sgpubb.book Page 61 Friday, April 14, 2000 11:08 AM
Figure 4-3. Adding the SQL Compiler directive using the Advanced
Directives dialog box
Solutions Guide
sgpubb.book Page 62 Friday, April 14, 2000 11:08 AM
to find out your requirements, then generates the HTML forms and CGI
programs needed to run the application.
Solutions Guide
sgpubb.book Page 63 Friday, April 14, 2000 11:08 AM
63
Index
A Connection
explicit 44
implicit 44
Access 13 Copyfile
Accessing an RDBMS 41 automatically generated 56
ActiveX control 22 host variables 56
Advanced Directives dialog box 61 Cross-platform HTML 22
AIX 13 Cursor in SQL 43
Apache web server 13
Application
client/server 9
Architecture
client/server 9
D
Data
exchanging with a relational database
B 44
Data access 41
Data type
Benefits of client/server architecture 11 varchar 46
Building the example application 61 Dates in SQL 45
DB2 13
Deployment 13
Disconnecting from relational database 44
C Dynamic HTML 22
CGI program 30
Client
thick 12 E
thin 12
Client/server Error handling 46
application 9, 12 Errors in SQL 46
architecture 9 Event handler 26
benefits 11 Example scenario 6
Common gateway interface 30 Gas Services 6
Connecting to a relational database 44 Explicit connection 44
Solutions Guide
sgpubb.book Page 64 Friday, April 14, 2000 11:08 AM
64
F J
Form 20 Java applet 22
HTML 23 JavaScript 26
Form Designer 23
M
G
Message loop 26
Gas Services 6 mfsqlmessagetext 46
Phase 1 32, 49 Microsoft 13
H N
Host variables 44 Navigator 13
in copyfile 56 NetBEUI 13
HTML 18, 22 Netscape 13
HTML form 23 Netscape Server API 37
Hypertext markup language 18 Novell NetWare 13
NSAPI program 37
I
O
Implicit connection 44
Informix 13 ODBC 41
Internet 17 Open Database Connectivity 41
Internet Application Wizard 27, 61 OpenESQL 41
ISAPI applications 37 OpenESQL Assistant 52, 62
Internet Explorer 13 Oracle 13
Internet Server API 36
Intranet 17
IPX 13
ISAPI program 36 P
Platforms supported by Net Express 13
Program
CGI 30
ISAPI 36
NSAPI 37
Solutions Guide
sgpubb.book Page 65 Friday, April 14, 2000 11:08 AM
65
server-side 28
PVCS 13
U
Uniform resource locator 17
UNIX 13
R porting OpenESQL program 48
URL 17
User interface
RDBMS 41
Web application 21
Relational data 41
Remote procedure call 9
RPC 9
V
S Varchar data type 46
Visual SourceSafe 13
Scenario 6
SCO 13
Script Assistant 26
Server-side program 28
W
Service provider 9
Service requestor 9 Web application 20
Spyglass web server 13 flow of execution 21
SQL communications area 46 user interface 21
SQL Compiler directive 61 WHENEVER statement 46
SQL error 46 Windows 13
SQL Server 13 World Wide Web 17
SQL statements 42 WWW 17
sqlcode 46
sqlstate 46
Supported platforms 13
Sybase 13
T
TCP/IP 13
Thick client 12
Thin client 12
Time in SQL 45
Solutions Guide
sgpubb.book Page 66 Friday, April 14, 2000 11:08 AM
66
Solutions Guide