Sei sulla pagina 1di 69

INFORMIX

INFORMIX PRODUCT LINE OVERVIEW


Informix provides leading-edge products for developing and implementing information
management applications for open systems. The core products include application development
tools, database servers, and connectivity software.
?
?
?

The application tools provide the user interface to build and run applications.
The database server handles all data management, including the storage and retrieval of
data.
Connectivity software provides the ability to access data in both Informix and nonInformix databases across a broad range of hardware platforms.
Application
Development
Tools
Connectivity

Database
Servers
Informix tools can access non-Informix databases through emerging industry standards,
such as ODBC and DRDA, while allowing third-party tools to access our database servers.
Industry-standard SQL is used to communicate requests for data from the application to
the database server. All products are based on ANSI-standard Structured Query Language
(SQL) and run on a variety of operating systems including UNIX, Windows, Windows NT,
OS/2, and Machintosh.
APPLICATION DEVELOPMENT TOOLS
The application tools allow you to:
? Design and build data entry and query screens
? Create reports
? Build robust applications
Wide choice of tools including:
? INFORMIX-NewEra
? INFORMIX-4GL
? INFORMIX-SQL
? INFORMIX-ESQL
? Third-party tools

Ordnance Factories Institute of Learning, Ambajhari

INFORMIX

The tools you will use depends on:


? The application requirements
? The hardware environment (graphical vs. character)
? The expertise and preferences of the development staff
DATABASE SERVERS
Informix offers a choice of database servers, allowing systems to be tailored to match
available resources and technical expertise.
The database server is responsible for providing:
? Optimal data access
? Data integrity
? Data security
? Data availability
Types of Database Servers:
? INFORMIX-SE
? INFORMIX-OnLine
? INFORMIX-OnLine Dynamic Server
CONNECTIVITY PRODUCTS
Informix connectivity products provide SQL-based connectivity to Informix and nonInformix databases on a broad range of hardware platforms.
ODBC-ENABLED APPLICATIONS
Open Database Connectivity (ODBC) is an interface which permits a single application
to access multiple database management systems using SQL. With ODBC, you can connect MS
Access, Visual Basic, Lotus Notes, and many other ODBC-enabled applications to an Informix
server. This technology gives you the freedom to choose your favorite Windows application
tool, and the power and flexibility of an Informix database server across a full range of scalable
platforms.
RELATIONAL DATABASE CONCEPTS
In relational database systems such as Informix, the data is organized and stored in tables
or entities, which are just a collection of columns and rows. Rows are the horizontal parts of the
table or are otherwise referred to as instances. Columns are the vertical parts of the table, which
are also known as attributes. Tables, rows, and columns are a way of organizing the data and
giving you an understanding of a relational model.

Ordnance Factories Institute of Learning, Ambajhari

INFORMIX

USER REFERENCE
CONNTECTING WINDOWS 98 CLIENT TO SCO UNIX SERVER:
Boot the Windows 98 machine and no need to Login into NT Network. Now, follow the
step below:
Start ? Run ? Type telnet 192.177.166.20 ? OK

LOGIN INTO INFORMIX:


To login into informix, the system asks login and password from the user. If both of
them are correct only, the user is permitted to login into the INFORMIX system.
Login :
Password:

user1
123

STARTUP & SHUTDOWN OF INFORMIX SERVER:


After the successful login, the DBA has to startup the INFORMIX server daily in the
morning. Then only any INFORMIX commands may work with database. Daily evening the
INFORMIX server should be shoutdown in the proper method.
Command
Description
oninit v
Initialise INFORMIX server online in verbose mode
onmode ky To shutdown the INFORMIX server
STARTING INFORMIX TOOLS:
To start INFORMIX tools, type the following commands at the UNIX command prompt.
Command
dbaccess
isql
r4gl

Description
To start dbaccess tool
To start INFORMIX-SQL tool
To start INFORMIX-4GL tool

Ordnance Factories Institute of Learning, Ambajhari

INFORMIX

USER LOGOUT FROM INFORMIX:


To logout from INFORMIX, the user has to type exit (or) ctrl+d
command prompt. The connection to host is lost.

in the UNIX

SHUT DOWN SCOUNIX SERVER (SUPER USER):


To shutdown the UNIX server, the super user has to type
shutdown y g0 i6
-g0
-y
-g2

shutdown & reboot ( init level 6 )


immediate shutdown
shutdown confirmation
Powers down machine after 2 minuties

FREQUENTLY USED VI EDITOR COMMANDS:


Command
i
I
a
A
o
O
rch
R
:w
:x (or) :wq
:q
:sh
x
dd
h (or backspace)
l (or spacebar)
k
j

Function
Input Mode
Inserts text to left of cursor
Inserts text at beginning of line
Appends text to right of cursor
Appends text at end of line
Opens line below
Opens line above
Replaces single character under cursor with ch
Replaces text from cursor to right
ex Mode
Saves file and remains in editing mode
Saves file and quits editing mode
Quits editing mode when no changes are made to file
Escape to the UNIX shell
Command mode
Deletes a single character under the cursor
Deletes the current line
Moves cursor left one position
Moves cursor right one position
Moves cursor up one position
Moves cursor down one position

Ordnance Factories Institute of Learning, Ambajhari

INFORMIX

DBACCESS
INTRODUCTION
DBaccess is a tool designed to enable you to access and manipulate the structure of the
database as well as the data within the database. It provides menu-driven access to basic
database functionality. DBaccess supports a query option to allow you to issue SQL commands
against the data in the database tables. It also supports altering tables through a menu-driven
environment. DBaccess supports most actions that can be performed against a database table,
including create, drop, alter, and fragment. DBaccess can also be used to gather information
about a table including the current table size, active constraints, current triggers, indexes, and
existing security privileges.
The specific functions supported depend on the release of the engine you are operating.
The options also vary depending on the type of engine running. The INFORMIX-SE engine and
the OnLine engine have different capabilities and, therefore, different options within the
DBaccess tool.
WHEN IS DBACCESS THE RIGHT TOOL SET ?
DBaccess is the right tool set for many database administrator (DBA) activities, including
database maintenance and table maintenance. By using the menu options, you can easily
perform these tasks. DBaccess automatically formats complicated SQL statements such as alter
table. In general, the purpose of the DBaccess tool is to make the syntax of table and database
maintenance less complicated.
DBaccess also allows you to create tables and databases rapidly. It provides a screen
interface so that you can enter the information for a new table. You also can use DBaccess to
test SQL statements rapidly.
DBaccess is not the appropriate tool if your goal is to create a report output from a query
or a data entry screen. It does not have formatting or screen-painting capabilities.
To start DBACCESS, type dbaccess in the unix command prompt.
MAIN MENU

Ordnance Factories Institute of Learning, Ambajhari

INFORMIX

Options
Query-language
Connection
Database
Table
Session
Exit

Description
allows you to use SQL query language.
allows you to connect or disconnect from a database
environment.
allows you to select, create, info, drop or close a database.
allows you to create, alter or drop a database table.
allows you to retrieve information about the current DBACCESS session.
allows you to exit from DBACCESS.

QUERY LANGUAGE

The first option on the DBaccess main menu is Query language. You can find this same
Query language tool in the ISQL tools. The following options are on this menu:
Options
New
Run
Modify
Use-editor
Output
Choose
Save
Info
Drop
Exit

Description
allows you to enter a new query by using a rudimentary text
editor (SQL editor).
submits the query currently visible on the screen to the engine
for execution.
allows you to modify the query currently visible on the screen by
using the SQL editor.
allows you to specify a text editor to be used in creating and
editing SQL statements.
allows you to send the results of the query to an output device, a
printer, a file, or pipe.
allows you to choose a command file as the current SQL
statements.
allows you to save the query currently visible on the screen to an
operating system file.
allows you to select a table and display information about that
table.
allows you to delete an operating system file storing a query
previously saved using the Save option.
returns you to the main DBaccess menu.

Ordnance Factories Institute of Learning, Ambajhari

INFORMIX

CONNECTION
The connection option of the main DBaccess menu is useful in connecting to alternative
database engines or servers. This option allows to connect or disconnect from a database
environment. When you choose Connect, a list of valid connections or servers is displayed.
Simply select the connection you want. You are allowed to enter a user ID and pass- word for
verification purposes. After successful validation of user ID and password, you are connected.
You can then access the databases valid to that connection as if they were on the same machine
and database server as when you initially entered DBaccess. This capability allows DBAs to do
remote database administration.
DATABASE
The Database option of DBaccess is primarily used by DBAs. This option allows to
select, create, info, drop or close a database. The following options are on this menu.

Options
Select
Create
Info
Drop
Close
Exit

Descriptions
allows you to select a database to work with.
allows you to create a new database.
allows you to retrieve information about the database.
allows you to delete a database.
allows you to close the current database.
allows you to return to the DBACCESS menu.

These are the primary uses of this command:


?
?
?

It prevents DBAs from needing to remember the details of the create database command.
It displays rudimentary statistics about a database.
It allows DBAs to view stored procedures.

Creating a database by using DBaccess has two advantages. You don't need to remember
the exact syntax of the create database statement., and the system prompts you for the dbspace.
The ability to view stored procedures is valuable. You can analyze the stored procedure
without having to remember the exact SQL syntax to retrieve the procedure from the database.

Ordnance Factories Institute of Learning, Ambajhari

INFORMIX

If a copy of the procedure is required, you can use cut and paste or command-line options of
DBaccess to place the stored procedure code in an operating system file.
TABLE
Both DBAs and programmers will find constant use for this option. Whether it is to look
up a table and column name or perform complex database maintenance, this option has
capabilities to perform the needed work. The various options of the Table selection under
Informix are given below:

Options
Create
Alter
Info
Drop
Exit

Descriptions
allows you to create a new table.
allows you to alter the structure of the existing table.
allows you to display information about the tables in the
current database.
allows you to drop a table.
allows you to return to the DBACCESS menu.

The Info option of DBaccess is read-only, and creating a new table using DBaccess
usually doesn't affect others on the system. DBaccess makes the job of creating and altering
tables significantly easier than directly typing standard SQL statements, you must use DBaccess
with the same caution and care required of all system utilities.
SESSION
The Session command displays information about the Informix session you're currently
connected to. This information helps you keep straight what the settings are in the current
environment.

CREATING A TABLE
In your database, you can proceed to create and populate tables. From the main menu,
choose "Table" option.

Ordnance Factories Institute of Learning, Ambajhari

INFORMIX

This is the place you do all kinds of operation on tables, such as creating a new table,
altering the schema of a table, dropping a table, and checking the information of a table.
?

To create a table:
? Choose "Create" option.
? Enter the name of the table after the prompt "CREATE TABLE >> ".
? Choose "Add" option to add a new column. Enter the column name, and
column type.
About Index, you can choose "No" not to add index for the column. After you
learn the knowledge of index, you can modify it later.
About Nulls, choose "Yes" to allow the column has null values, or "No" to
forbid.
Repeat the above for adding remaining columns.
Press Esc key to go back to parent menu.
? Choose "Modify" option to modify the definitions of existing columns.
? Choose "Drop" option to remove existing columns.
? Choose Exit option and choose Build-new-table to save changes made to
the table.

To alter the structure of existing table


? Choose "Alter" option.
? Select the name of the table you want to modify.
? Choose "Add", "Modify", "Drop", or other options the same as creating a table to
alter the structure of the table.
? Choose Exit option and choose Build-new-table to save changes made to the
table.

USING SQL QUERY


From the main menu, choose "Query-language" option.
This is the place you execute SQL query. You can construct a new SQL query, make
modification on the query, and run the query.
To create a new SQL query:
? Choose "New" option
? Enter the SQL query
? After editing the query, press <escape> key.

Ordnance Factories Institute of Learning, Ambajhari

10

INFORMIX

To run a current SQL query:


? Select "Run" option to execute the SQL query.

To modify the current query:


? Select "Modify" option to goto SQL editor.
? After editing the query, press <escape> key.
To save the current query:
? Select "Save" option.
? Give name to the command file and press Enter key.
? The message Script saved in <filename>.sqldisplays at the bottom row.

To choose a command file:


? Select "Choose" option.
? Select the query command file and press Enter key.

SQL editor commands:


Command
Esc
Ctrl X
Ctrl A
Ctrl D
Ctrl R

Operation
Done editing
Delete character
Typeover / Insert
Delete rest of line
Redraw the screen

Ordnance Factories Institute of Learning, Ambajhari

INFORMIX

11

INFORMIX-SQL
INTRODUCTION
INFORMIX-SQL, commonly known as ISQL, is a set of tools provided by Informix
Software to support developers. ISQL has a long history with Informix. These tools were
provided with Informix software products before the corporation was named Informix. Prior to
the advent of INFORMIX-4GL, they were the only fourth-generation tools available through
Informix.
WHEN IS ISQL THE RIGHT TOOL SET ?
ISQL is a set of tools, and each tool has its unique purpose. In general, ISQL is the right
set of tools when you need a quick prototype or a simple application.
The Report option invokes the ACE report generator. ACE is excellent for generating
quick reports. It supports SQL select statements, including the creation of temporary tables.
Some very complex SQL select logic is supported with ACE. It also contains good report
formatting capabilities with built-in control break logic for totals and subtotals. It does have
some limited logic capabilities, including temporary variables.
The Form option creates Perform screens. Perform is a screen-generation utility. The
entry screens created by Perform can facilitate data validation, enable intelligent cursor
movement, and process multiple table relationships. They are excellent for quick data
maintenance screens for data entry tables such as state abbreviations. They are also effective if
the application requires no major logic supporting the data entry process.
The User-menu option creates quick, hierarchically based menu structures. They are
reasonably flexible and often sufficient for the menuing needs of a system. However, the
presentation of the menus is not customizable.
To start INFORMIX SQL, type isql in the unix command prompt.
INFORMIX-SQL MENU

Ordnance Factories Institute of Learning, Ambajhari

12

INFORMIX

Options
Form
Report
Query-language
User-menu
Database
Table
Exit

Description
Run, Modify, Create or Drop a form
Run, Modify, Create or Drop a report
Use Informix Structured Query Language
Run or modify a custom-built menu
Select, Create or Drop a database
Create, Alter or Drop a database table
Exit Informix-SQL

Options
Select
Create
Drop
Exit

Description
Select a database to work with
Create a new database
Drop a database
Return to the INFORMIX-SQL main menu

DATABASE

TO SELECT ANY DATABASE:


Database
Enter key.

Select

Select any database (say Stores7@bnm) and press

TO EXIT FROM DATABASE MENU:


Database

Exit

Ordnance Factories Institute of Learning, Ambajhari

INFORMIX

TABLE

Options
Create
Alter
Info
Drop
Exit

Description
Create a new table
Alter the structure of an existing table
Retrieve information about the tables in the current database
Drop a table from the database
Return to the INFORMIX-SQL main menu

CREATE A NEW TABLE


To create a new table
Table
Create

Options
Add
Modify
Drop
Screen
Exit
i)
ii)
iii)
iv)
v)

Type table name (say san1) followed by Enter key

Description
Adds columns to the table above the line with the highlight
Modify column definitions
Drop the highlighted column from the table
Displays the next screen of the table
Leaves the CREATE TABLE menu

choose the option Add followed by Enter key


Column: Type column name (say PerNo) followed by Enter key
Data type: Select any data type using space bar.
Press Del key for go back to parent menu.
Length: Type length for the field if applicable
Index: Add index san1: Yes / No:
Yes : for specifying this column to have an index. Otherwise select No.

Ordnance Factories Institute of Learning, Ambajhari

13

14

vi)

INFORMIX

If Yesis selected, the following options appears:


a)
Add Duplicates san1: Yes / No
Yes : Permits duplicate values in this column
No : Does not permit duplicate data values in this column
b)
Add Fill Factor percentage: Just press Enter key.
Null:
Add Nulls : Yes / No
Yes: Permits null values in this column
No: Does not permit null values in this column

Repeat steps i) to v) for adding remaining columns.


Press Del key to goto parent menu and select Exit

Build-new-table: Builds a new table and returns to the table menu


Discard-new-table: Keeps the old table (discard changes) and returns to the Table menu
select Build-new-Table followed by Enter key
AVAILABLE DATA TYPES
ADD TYPE san1: Char Number Serial Date Money date-Time Interval
Variable-length
------------------------------------------------------------------------- Press CTRL-W for Help ---------Options
Char
Number
Serial
Date
Money
date-Time
Interval
Variable-length

Description
Permits any combination of letters, numbers and symbols
Displays the NUMBER menu
Permits sequential serial numbers starting with any positive value
Permits dates
Permits dollars and cents
Permits datetime values
Permits interval values
Displays the VARIABLE-LENGTH menu for the variable length columns

Ordnance Factories Institute of Learning, Ambajhari

INFORMIX

15

DATA TYPE : NUMBER :


Integer
Smallint
Decimal
Float

Permits whole numbers in the approximate range 2 billion to 2 billion


Permits whole numbers in the range 32,767 to 32,767
Permits numbers with a decimal point and upto 32 significant digits
Displays the PRECISION menu.
Permits numbers with a decimal point and 8 significant digits
Smallfloat
Permits numbers with a decimal point and 16 significant digits
Float

DATA TYPE : VARIABLE-LENGTH:


Varchar
Text
Byte

Variable-length data containing a maximum of 255 characters


Variable-length data containing a maximum of 2 giga bytes
user-defined type containing a maximum of 2 giga bytes

ALTER ANY EXISTING TABLE


To alter the structure of any existing table
Table
Alter
Select the table (say san1) followed by Enter key

The options available in the alter table menu and its functions are same as create table
menu options.
INFORMATION ABOUT TABLE
To retrieve information about the tables in the current database
Table
Info
Select the table (say san1) followed by Enter key

Ordnance Factories Institute of Learning, Ambajhari

16

INFORMIX

Options

Columns
Indexes
Privileges
Status
Table
Exit

Description
Display column names and data types for a table
Display information about indexes for the columns in a table
Display user access privileges for a table
Display status information for a table
Select a table from the current database
Return to the SQL menu

COLUMNS:

INDEXES:

PRIVILEGES:

Ordnance Factories Institute of Learning, Ambajhari

INFORMIX

STATUS:

DROP TABLE
To drop a table from the database
Table

Drop

Select the table (say san1) followed by Enter key

No: No, I do not want to drop it


Yes: Yes, I do want to drop it.
Select Yes to drop the table.
FORM

Options
Run
Modify
Generate
New
Compile
Drop
Exit

Description
Use a form to enter data or query a database
Modify a form specification
Generate a default form
Create a new form specification
Compile a form
Drop a form from the database
Return to the INFORMIX-SQL main menu

Ordnance Factories Institute of Learning, Ambajhari

17

18

INFORMIX

GENERATE A DEFAULT FORM:


Form

Generate

Enter the name to assign to the form (say sanfrm)


followed by Enter key

Choose Table >> Choose the table to be used (say san1) followed by Enter key

Options
Table-selection-complete
Select-more-tables
Exit

Description
Continue creating a default form with the selected tables
Select another table to include in the default form
Returns to the FORM menu

Select Table-selection-complete followed by Enter key.


The message The screen form specification was successfully compiled displays.
RUN AN EXISTING FORM
Form

Run

Options
Query
Next
Previous
View
Add
Update
Remove
Table
Screen
Current

Select the form (say sanfrm) followed by Enter key

Description
Searches the active database table
Shows the next row in the current list
Shows the previous row in the current list
Runs editor commands to display BLOB contents
Adds a row to the active database table
Changes a row in the active database table
Deletes a row from the active database table
Selects the current table
Shows the next page of the form
Displays the current row of the current table

Ordnance Factories Institute of Learning, Ambajhari

INFORMIX

Master
Detail
Output
Exit

19

Selects the master table of the current table


Selects a detail table for the current table
Outputs selected rows in form or report format
Returns to the INFORMIX-SQL menu

ADD NEW RECORD


To add a new record in the current table, select Add and start entering data.
Use Arrow keys to move cursor and Escape key to add new record.
The message Row added appears at the bottom row after adding each record.

QUERY IN THE CURRENT FORM


To make any queries in the current form, select Query and start typing any criteria in
the relevant column(s) and press Esc key to execute the query. The criteria may be any value
or any relational expression. The criteria is case sensitive.
If you type CM-II in the design column and press Esc key, you may get all the
employee rows having designation CM-II having displayed one record at a time. If more than
one row is found, select Next / Previous options to see the Next / Previous rows which satisfies
the given criteria.

Ordnance Factories Institute of Learning, Ambajhari

20

INFORMIX

UPDATING CURRENT ROW


To update any values of current row, select Update option and change any value in the
respective columns. You press Esc key to save the changes (or) Del key to abandon changes.

REMOVING CURRENT ROW


To remove the current row, select Remove option. It deletes the current row from the
active database table.
OUTPUT SELECTED ROWS
To output selected rows in form or report format, select Output option.

Enter output file name say sample.out and press enter key.

Ordnance Factories Institute of Learning, Ambajhari

INFORMIX

Options
Append
Create

21

Description
Adds new data to an existing output file
Creates a new output file

Select Create and current-list options.

Options
Current-list
One-page

Options
Unload-format
Screen-format

Description
Writes the current list to the file
Writes the displayed screen to the file

Description
Writes the selected output in ascii format
Writes the selected output in screen format

Select Unload-format option and Exit to exit from the Run menu.
In the UNIX command prompt, type vi sample.out (or) cat sample.out to see the
contents of output file sample.out.

Ordnance Factories Institute of Learning, Ambajhari

22

INFORMIX

REPORT
The Report menu takes you into a submenu that allows you to generate, edit, compile,
and run ACE reports. The ACE report writer quickly formats simple reports. You can enter a
sequence of SQL statements that generate a final sorted output. This single output thread is used
as the input to the report formatting section of the report. Complex selection logic can be
supported if it can be accommodated using multiple select statements and temporary tables to
generate a final single output stream.
ACE does not support table updating. If the application requires the ability to update
tables, ACE is not the appropriate tool. ACE can do the selection and create an output file that
can be used as input to an update procedure, but updating within an ACE report is not supported.
ACE does not support extensive logic. Although ACE does support if -then - else
constructs, its ability to do extensive logic handling is limited. ACE has a built-in limit of SQL
variables. It also has a tendency to fail on deeply nested if statements.
ACE has a built-in totaling mechanism for control breaks. These control breaks must be
specified in the order by clause of the final SQL statement. Complex totaling can be
cumbersome in ACE. If totaling must be done on fields outside the control breaks, you must use
defined variables. The built-in limit can restrict the flexibility and quantity of such totals.

Options
Run
Modify
Generate
New
Compile
Drop
Exit

Description
Runs a report
Modify a report specification
Generate a default report
Create a new report specification
Compile a report
Drop a report from the database
Return to the INFORMIX-SQL Main menu

GENERATE A DEFAULT REPORT:


Report

Generate

Enter the name to assign to the report (say sanrep)


followed by Enter key

Ordnance Factories Institute of Learning, Ambajhari

INFORMIX

23

Choose Table >> Choose the table to be used (say san1) followed by Enter key

The report specification was successfully compiled message appears at the bottom row.

RUN AN EXISTING REPORT:


Run

Choose a report (say sanrep) then press Return key

This report continues to print on the screen until it is complete. If you have more data
than will appear onscreen, the generated report allows the data to scroll off the screen.

Ordnance Factories Institute of Learning, Ambajhari

24

INFORMIX

MODIFY AN EXISTING REPORT:


Modify
Choose a report (say sanrep) then press Return key. Press Return key
in the USE-EDITOR option to select the default vi editor.

Using vi commands, you can edit the report coding.

After modification is over, press Esc x (:x) to save and exit from vi editor.

Options
Compile
Save-and-exit
Discard-and-exit

Description

Compile the report specification


Save the report & return to REPORT menu
Discard changes and return to REPORT menu
Select Compile followed by Save-and-exit option.

DROP AN EXISTING REPORT:


Drop

Choose a report (say sanrep) then press Return key.


Options
Description
No, I do not want to drop it
No
Yes, I do want to drop it
Yes

Select Yes to drop the selected report, otherwise No to cancel the drop operation.

Ordnance Factories Institute of Learning, Ambajhari

INFORMIX

25

USER-MENU
By using the User-menu, you can quickly create a hierarchically based menu system. To
utilize the tool, your menuing design must be entirely based on a master menu/detail menu
relationship. Each entry on the main menu can be one of the following types:
?
?
?
?
?
?

F: Run a form
M: Call another menu
P: Execute another program or operating system command
Q. Execute an ISQL query or other command file
R: Run a report
S: Execute a script menu

The menus are stored in the database. You should have the menu structure designed
before entering the menu items. To begin entering the information, select the lowest level menu
and give it a name. This menu does not call any other subordinate menus.
Press M for Master, and then press A for Add. Type the name of the menu and the title
you want the user to see on the screen. The title can be long and descriptive; the name is limited
in length. The name is used only within by the menuing system to track relationships between
menus. Next, press the Esc key.
You have added your first menu. Next, add the individual items for the menu. It is best
if they already exist or if you at least know the exact names the called programs, reports,
procedures, and so on will have. You can always modify the menus, but planning ahead is best.
To begin entering the menu selections, press D for Detail. The cursor then moves to the bottom
half of the screen on Selection Number. Press A for Add. Then type the selection number and
selection type. Next, enter the selection text as you want it to appear to the user. The final entry
is the exact command string as it should be executed from the operating system.
Continue to enter your menu one item at a time. To test the current Structure at any time,
exit from the entry modification screen and choose Run. Your menu is then displayed on screen.
You can test your work immediately.
The User-menu option is a great tool for creating menus quickly. Its flexibility in calling
any type of operating system program enhances its ability to support any type of application
developed in the UNIX environment.

Ordnance Factories Institute of Learning, Ambajhari

INFORMIX

26

STRUCTURED QUERY LANGUAGE (SQL)


SQL statements are used to perform all direct functions on the database. The statements
and keywords used will lead to the database operations being performed. SQL commands
consist of command verbs, optional clauses, keywords. and parameter operands. The use of
these in SQL syntax permits exact specification of the data requests. The language allows single
and double byte characters to be used in identifiers and variables. SQL has many types of
commands; some are for handling the data, and some are for controlling administrative matters.
FEATURES:
A significant feature of SQL is that it can be used by two different interfaces. SQL is
both an interactive query language and a database Programming language. This means that any
SQL statement that can be entered at a terminal can also be embedded in a program.
Finally, SQL processing is also known as a set level language, which means your
updates will change records and return the results. You simply state what you want without
specifying a procedure, and the system automatically completes the process.
SQL is the communicating device to the relational database management system. You
will find SQL to be a simplified and straightforward process for accessing data. When you are
familiar with the language, fairly sophisticated data processing can be done. The following list
logically summarizes the SQL language:
?
?
?
?

Simple flexible database access language


Standard relational language
English-like query language
Supports many relational products, such as DB2, Oracle, Informix, Sybase.

CREATING A TABLE
To create a simplest table, it is very easy:
Syntax: CREATE TABLE <tableName> (
< list of column definitions including column name and data type >
);

Example: CREATE TABLE test (


i integer,
s varchar(10)
);
For each column, you can also add any of the following property or column-level
constraint:

Ordnance Factories Institute of Learning, Ambajhari

INFORMIX

?
?
?
?
?

27

DEFAULT <value> to set the default value.


NOT NULL -- the column value can not be null;
UNIQUE -- the column value can not be duplicated
PRIMARY KEY -- the column acts as key
REFERENCES <referenced table name>(<column name>) -- the columns refer to
a column in another table. The referenced key must have UNIQUE or PRIMARY
KEY constraints.

If you have all the above definitions, the order to write it is DEFAULT clause the first,
then NOT NULL, and other constraints at last.
Example: CREATE TABLE accounts (
acc_num integer PRIMARY KEY,
acc_code integer UNIQUE,
open_date date DEFAULT TODAY
);
You can also specify any of the following table-level constraints:
?
?
?
?
?

UNIQUE(<column name>)
DISTINCT (<column name>)
PRIMARY KEY(<column name>)
FOREIGN KEY(<column names>) REFERENCES <referenced table
names>(<column name>)
CHECK(<condition>) -- check the constraints be met before data be assigned

Example:

CREATE TABLE customer (


ssn
char(9),
name varchar(20) NOT NULL,
acct integer,
age
integer,
PRIMARY KEY(ssn),
FOREIGN KEY(acct) REFERENCES accounts(acc_num),
CHECK( age>=18 )
);

You can also use CHECK (<conditions>) to check constraints to designate conditions
that must be met before data can be assigned to a column during an INSERT or UPDATE
statement.
Example:

CREATE TABLE people (


id
serial PRIMARY KEY,
name
varchar(20),
age
int CHECK (age>0),

Ordnance Factories Institute of Learning, Ambajhari

28

INFORMIX

sex
char CHECK (sex='M' OR sex='F'),
birthday date,
working boolean,
salary
money,
descript text,
CHECK ( (working AND (salary IS NOT NULL)) OR
(NOT working AND salary IS NULL) )
);
GETTING RID OF A TABLE
To remove a table from your database, execute
Syntax:

DROP TABLE <tableName>;

Example:

DROP TABLE test;

CREATING A VIEW
You can use CREATE VIEW statement to create a new view based on existing tables and
views in the database.
Syntax:

CREATE VIEW <viewName> (


<list of column names and their data types>
) AS <SELECT list of column names> FROM <tableName> ;

Example:

CREATE VIEW student( id, name )


AS SELECT * FROM test;

CREATING AN INDEX
An important technique for improving the performance of queries is to create indexes. An
index on an attribute of a relation allows the database to quickly find the data in the relation with
a given value for the indexed attribute.
Syntax:

CREATE INDEX <indexName> ON <tableName>


(<a list of key attributes>);

Example:

CREATE INDEX sid_index ON student(id);

It may be useful if the queries involved in the student id such as the following query:
SELECT *
FROM student
WHERE id = 10;

Ordnance Factories Institute of Learning, Ambajhari

INFORMIX

29

SQL - DATA MANIPULATION STATEMENTS


SQL is the data access language used to communicate with the database manager. You
use SQL's data manipulation statements to view and store rows in a table, as well as modify and
delete these rows. Here are the statements you use:
? SELECT
? INSERT
? UPDATE
? DELETE
SELECT statement is the definitive command found in SQL. Not only does it allow you
to see anything within the database, but it also helps the next three commands to be more precise.
You use the INSERT statement to store rows in a table. The statement can add a row to an empty
table or a table that already has populated data. You use the UPDATE statement if you want to
change any of the existing rows in a table. You use the DELETE Statement to delete one or more
rows in a table. This chapter reviews the execution of each statement.
Informix uses an enhanced version of the industry standard query language product.
Putting SQL statements into a program allows you to query a database as well as make
modifications to existing rows.
QUERYING DATA (SELECT STATEMENT)
Using the SELECT statement is the primary way to query your database. It is the most
important SQL statement and can be the most complex. The SELECT statement does not
modify data in the database; you use it only to query the data. You can select from a database
table, a view, or the system catalog tables.
You can use the SELECT statement in the following ways:
?
?
?

Retrieve data from a database


Create new rows with the INSERT statement.
Update data with the UPDATE statement.

There are five SELECT statement clauses, even though only two clauses--SELECT and
FROM--are required. You must use the clauses in the following order:
?
?
?
?
?

SELECT
FROM
WHERE
ORDER BY
INTO TEMP

Ordnance Factories Institute of Learning, Ambajhari

30

INFORMIX

You can run a query on a single table of a database to retrieve all or specific columns or
rows and order the data in different ways. If you specify an asterisk (*) in your select statement,
all the columns are returned in their defined order. You can specify which columns you want by
including the list of column names immediately after the SELECT keyword in the statement.
The order in which the columns are selected is the order in which they are returned by default.
eg.

SELECT * FROM tablel


SELECT column1, column2, column3 FROM tablel

You can eliminate duplicate rows from being returned by using the DISTINCT or
UNIQUE keyword in your SELECT statement.
WHERE Clause of the SELECT statement
It is useful for two specific purposes:
? Specify the criteria for searching specific rows.
? Create join conditions with multiple tables.
You can use many keywords and operators to define your search criteria:
Keywords

Results in

BETWEEN
IN
LIKE
MATCHES
IS NULL
IS NOT NULL
AND / OR / NOT

Range of values
Subset of values
Variable text search
Variable text search
Search for NULL strings
Search for non-NULL Strings
Logical operators used to connect two or more conditions

Relational Operators
=
!= or <>
>
>=
<
<=

Description
Equals
Does not equal
Greater than
Greater than or equal to
Less than
Less than or equal to

Arithmetic Operators
+
*
/

Description
Addition
Subtraction
Multiplication
Division

Ordnance Factories Institute of Learning, Ambajhari

INFORMIX

31

In addition to using the LIKE and MATCHES keywords, you can use a wildcard for
variable text search strings.
Use
with
MATCHES
*
?
[ ]
\

Description
Evaluates to 0 or,more characters
Evaluates to a single character
Specifies valid values for a single character or a range of values
Specifies a literal for the next character

ORDER BY Clause of the SELECT statement


You can instruct the system to sort the selected data in a specific order by using the
ORDER BY clause on the SELECT statement. By default, data that is retrieved is sorted in
ascending order. You can add the DESC keyword to your SELECT statement to sort the data in
descending order. The ORDER BY column must be in the select list. Columns that are
frequently used with the ORDER BY clause should be indexed for best performance of the
query.
FUNCTIONS AVAILABLE IN THE SELECT STATEMENT
You can use additional functions with the SELECT statement.
functions to summarize groups of selected rows in a table.
Function
COUNT
SUM
AVG
MAX
MIN

You use aggregate

Description
Counts the number of rows that are a result of
the SELECT statement
Sums the value of a given numeric column
Arithmetic means of a given numeric column
Maximum value of a given column
Minimum value of a given column

The next set of functions is the time functions:


Function
DAY
MONTH
WEEKDAY
YEAR
MDY
DATE
CURRENT

Description
Integer that represents the day
Integer that represents the month
Integer that represents the day of the week (values
0 through 6 (Sun-Sat))
Four digit integer that represents the year
Returns the date in mm/dd/yyyy format
Returns a date value
Returns a date/time value that represents the current
date and time

Ordnance Factories Institute of Learning, Ambajhari

32

INFORMIX

In addition to the aggregate and time functions, you can also use the following functions:
Function
LENGTH
USER
TODAY
SITENAME

HEX
ROUND
TRUNC

Description
Returns the length of a character column
Returns the login account name of the current user
Returns the system data
Returns the server name for the INFORMIX-OnLine
system (defined in the onconfig file where the current
database resides)
Returns the hexadecimal encoding of an expression
Returns the rounded value of an expression
Returns the truncated value of an expression

GROUP BY and HAVING Clause of the SELECT statement


Two additional clauses for more advanced queries are GROUP BY and HAVING. The
GROUP BY clause produces a single row for each group of rows that have the same value in a
given column. The data is sorted into groups and then compressed into a single row for end
results.
A GROUP BY clause does not order the result data. If you include an ORDER BY
statement in the select after the GROUP BY clause, the rows are sorted in the specified order.
The HAVING clause provides a filter for the grouped-by results. This works in
conjunction with the GROUP BY clause to apply conditions on the groups after they are formed.
You do not need to use a HAVING clause with a GROUP BY clause, but in most cases they
appear in the query together.
MULTIPLE TABLE SELECT STATEMENTS
You can select data from two or more tables by using the SELECT statement with the
FROM and WHERE clauses. The SELECT clause lists the columns from each table that you
want, the FROM clause lists the tables you are selecting from, and the WHERE clause lists the
matching columns in order to join the tables.
A simple join gets the information from two or more tables with a basis of one column
for each table. A composite join is a join between two or more tables with two or more columns
in each table used for the relationship. The following is an example of a simple join to get
customer information from two tables:
SELECT * FROM customer_table, address_table
WHERE customer_table.cust_num = address_table.cust_num;

Ordnance Factories Institute of Learning, Ambajhari

INFORMIX

33

INSERTING DATA
The SQL INSERT statement allows a user to enter a row or rows of values into a table.
The INSERT statement has two functions: The first is creating one single new row by supplying
the column values and the second is creating a group of new rows with values derived from
another table.
SINGLE ROW INSERTS
Adding a single row is the simplest form of the INSERT statement. The statement
creates one new row in a table from a list of defined column values. You use a VALUES clause
in the statement, and the values to be inserted must have a one-to-one equivalence with the
columns of the table.
The following code shows an example of the syntax:
INSERT INTO tablel
VALUES (123, ABC")
If you do not want to specify every column of the table where you insert a row, you can
list the column names after the table name and then supply the values for the columns you list.
The VALUES clause accepts only constant values. You can use the following values:
?
?
?
?
?
?

Literal numbers, date and time values, and interval values


Strings of characters (quoted)
NULL for null values
TODAY for today's date
CURRENT for the current date and time
USER for the user's name

When inserting a value into a column, you might find that restrictions were placed on the
column. For example, some columns might not allow null values or duplicate values. Also, a
column restriction can specify the exact values that are allowed to be inserted.
One column in a table can be defined as a SERIAL data type. The database server
generates values for a serial column. When you specify 0 as the value, the database server
generates the next value in the sequence. Serial columns do not allow you to insert NULL
values.
When performing inserts, the database server makes conversions if necessary. For
example. when you insert a number or date into a character column, the server converts the
values to character strings. The database server can also convert between numeric and character
data types.

Ordnance Factories Institute of Learning, Ambajhari

INFORMIX

34

MULTIPLE ROW INSERTS


For the more enhanced INSERT statements, you can replace the VALUES clause with a
SELECT statement. This option allows you to insert multiple rows of data with only one
statement.
Using the SELECT clause in the INSERT Statement has the following restrictions..
?
?
?
?

You cannot use the INTO clause.


You cannot use the INTO TEMP clause.
You cannot use the ORDER BY clause.
You cannot use the same table in the INTO clause of the INSERT statement and the
FROM clause of the SELECT statement.

When inserting multiple rows, you have a risk of including invalid data. so the database
server terminates the statement if it reaches an invalid value.
INSERT STATEMENT WITHIN A PROGRAM
You can embed an INSERT statement in a program just as if you were performing any
simple SQL statement. An additional feature allows you to use host variables in expressions for
both the VALUES and WHERE clauses.
UPDATING DATA
You use the SQL UPDATE statement to change the values of one or more rows of a
table. The two forms of the UPDATE statement are uniform value updates and select value
updates.
To update data in a table, you must be the owner of the table or have the UPDATE
privilege for that table. If you update rows in a database without transactions and the update
fails, your database can be in a state with a half-processed update, and it is not rolled back. If
your database has transactions, you do the update with the ROLLBACK WORK statement,
which automatically rolls back any modifications if the statement fails or does not completely
finish processing.
The UPDATE statement can end in a WHERE clause, which determines what rows are
affected. If you do not include a WHERE clause, then all rows of the table are modified. The
WHERE clause consists of standard search criteria.
UNIFORM VALUE UPDATES
Updating with uniform values happens when you use the SET keyword to add a value for
a column. The value is uniformly added to every row unless you state a WHERE clause to be
more specific on your UPDATE statement:

Ordnance Factories Institute of Learning, Ambajhari

INFORMIX

35

UPDATE tablel
SET fieldl = ABC
The SET clause identifies each column to be changed and specifies the value that is used
in making the change. You can have any amount of single-column-to-single-expression
functions in an UPDATE statement.
You can use the NULL keyword as a column value with the UPDATE Statement.
SELECTED VALUE UPDATES
Updating with selected values happens when you take a list of columns and set them to a
list of values. This method is basically the same as the first form of updates, but it assigns bulk
values to existing columns:
UPDATE tablel
SET (fieldl, field2, field3) = ('ABC, DEF, GHI)
DELETING DATA
The SQL DELETE statement removes one or more rows from a table. If you use
transaction processing, you cannot recover the deleted rows after the statement is committed.
Also, when you delete a row, the row is locked for the duration of the transaction. If a large
number of rows are deleted, keep in mind that all rows are locked. You can lock the entire table
prior to deleting if you know you are processing a lot of rows.
The advantage of using transaction processing is that, regardless of what happens during
your process, the database is left in the original state if the statement cannot be completely
processed correctly.
If the WHERE clause is not on the statement, all rows are automatically deleted from the
table. If you are using INFORMIX-SQL or Informix DBaccess when you use the DELETE
statement without a WHERE clause, you are asked to confirm that Do you want to delete all
rows in the existing table? Please note that if you use the DELETE clause in a program, you are
not asked for confirmation, and the DELETE processes automatically.
eg.
DELETE FROM tablel
The general Syntax for a DELETE statement is simple, but you must be careful that you
accurately delete the rows that you want. The DELETE keyword identifies the operation you are
to perform. The FROM clause is next followed by the table name. The WHERE clause
identifies the rows to be deleted. The search conditions are the same as those in the SELECT
and UPDATE statements; they can be used to identify many rows, and therefore an accurate
deletion process takes place.
eg.

DELETE FROM tablel


WHERE balance = 0;

Ordnance Factories Institute of Learning, Ambajhari

36

INFORMIX

INFORMIX-4GL
INFORMIX 4-GL AND CLIENT/SERVER ARCHITECTURE
Informix-4GL allows you to both provide a far friendlier mode of interaction, and protect
valuable data from end user errors.
Server

Client

Informix
Server
SQL
4 GL

Because of its role in the client/server architecture, the 4GL code you write is actually a
4GL/SQL hybrid. It contains:
? 4GL logic for screen handling and the user interface
? SQL statements which are sent to the Informix Server to be processed
TYPES OF INFORMIX-4GL
There are actually two kinds of INFORMIX-4GL.
? INFORMIX-4GL Rapid Development System (RDS) and
? INFORMIX-4GL C Compiler Version.
RAPID DEVELOPMENT SYSTEM
RDS compiles the source program into pseudo-code (p-code). The time line for
compiling into p-code is very small. The p-code is later executed through a p-code runner. The
runner takes the statements that you have written in INFORMIX-4GL and translates them at runtime into something the computer can understand. Thus it takes longer time to execute. How
much longer depends on the type of hardware you are using and what the actual INFORMIX4GL code is doing.
Informix 4GL-GX
An important advantage to RDS is ready to access to a graphical presentation of your
RDS application by means of INFORMIX-4GL/GX. Some of the features are as follows:
? 3-D shading enhances the appearance of your 4GL forms
? Text fields and their delimiters are replaced by visually distinct form fields offset by
color or highlighting
? Help text is displayed in a separate window, allowing the user to simultaneously view
and use Help and the RDS application.

Ordnance Factories Institute of Learning, Ambajhari

INFORMIX

37

Informix-4GL Interactive Debugger


The debugger can be used to trace run-time bugs in your source code. The interactive
debugger allows you as much control over your program as you need:
? You can actually watch the code you have written as it executes, stopping it at any
time along the way
? You can trace variables so that the execution will stop whenever the value of a
variable changes
? You can step through the execution line by line, look at the value of a program
variable at any time, and use a host of other commands
C COMPILER VERSION
The INFORMIX-4GL code is first translated into ESQL/C Code, then C Code, then
object, and then into an executable program. So that the compile time is longer. The execution
time of the finished program is faster than the p-code generated by INFORMIX-4GL RDS. This
is because the compilation sequence takes the code you have written and translates it directly
into machine executable code.
INFORMIX-4GL MAIN MENU

Options
Module
Form
Programs
Query-language
Exit

Description
Create, modify, or run individual 4GL program modules
Create or modify 4GL screen forms
Create, compile or run 4GL application programs
Use Informix Structured Query Language
Exit INFORMIX-4GL

Ordnance Factories Institute of Learning, Ambajhari

38

INFORMIX

Options
Modify
New
Compile
Programcompile
Run

Options
Modify
Generate
New
Compile
Exit

Options
Modify
New
Compile
Planned_Compile
Run
Drop
Exit

Description
Change an existing 4GL Program module
Create a new 4GL Program module
Compile an existing 4GL Program module
Compile an existing 4GL application program
Execute an existing 4GL program module or application
program

Description
Change an existing form specification
Generate & compile a default form specification
Create a new form specification
Compile an existing form specification
Returns to the INFORMIX-4GL menu

Description
Change the compilation definition of a 4GL application
program
Add the compilation definition of a 4GL application program
Compile a 4GL application program
Show the planned compile actions of a 4GL application
program
Execute a 4GL application program
Drop the compilation definition of a 4GL application program
Returns to the INFORMIX-4GL menu

Ordnance Factories Institute of Learning, Ambajhari

INFORMIX

Options
New
Run
Modify
Use-editor
Output
Choose
Save
Info
Drop
Exit

39

Description
Enter new SQL statements using the SQL editor
Run the current SQL statements
Modify the current SQL statements using the SQL editor
Modify the current SQL statements using a user-specified editor
Run & send query results to a printer, file or a pipe
Choose a command file as the current SQL statements
Save the current SQL statements in a command file
Retrieve information about tables in the current database
Drop an SQL command file
Returns to the INFORMIX-SQL main menu

BASIC COMPONENTS OF INFORMIX-4GL


?
?
?
?

PROGRAM
MODULE
FUNCTION
FORM

PROGRAM
A logical sequence of operations to be performed by a computer in solving a problem or
in processing data.
MODULE
A module is a computer file with a specific purpose or function consists of INFORMIX4GL instructions. It is one piece of the entire program. Program contains at least one module.
A module contains a collection of one or more functions.
FUNCTION
A routine that performs a specific duty or job which may be required in a program. The
function is the basic unit of INFORMIX-4GL code. It is used to set off a series of INFORMIX4GL statements which should be executed when called upon.

Ordnance Factories Institute of Learning, Ambajhari

INFORMIX

40

TYPES OF FUNCTIONS:
GLOBALS
The GLOBALS function tells INFORMIX-4GL that the only statement it should find in
this function is a variable declaration statement. Every program is only allowed one GLOBALS
function.
MAIN
The MAIN function gives INFORMIX-4GL a place to start. INFORMIX-4GL will
always read the module with the MAIN function in it first. Every program requires exactly one
MAIN function (otherwise INFORMIX-4GL would not know where to start).
FUNCTION
A FUNCTION is the basic unit for INFORMIX-4GL code. Programmer has to define
what each functions purpose is going to be.
REPORT
The REPORT function tells INFORMIX-4GL that additional report formatting
statements may be encountered. Other functions, MAIN, GLOBALS and FUNCTION, will not
understand these report statement.
FORM
The form is a separate file that is used to specify what the appearance of the visual screen
display will look like during data entry and manipulation. Forms are a separate entity from the
rest of your program. Forms are compiled separately and are used by your program. Forms can
be used to display information from a database as well as to update, delete and insert
information.
Program
Modules
Cust_main.4gl

Cust_add.4gl

Cust_edit.4gl

GLOBALS
4GL CODE
END GLOBALS

FUNCTION add_cust()
4GL code
END FUNCTION

FUNCTION delete_cust()
4GL code
4GL code
END FUNCTION

MAIN
4GL CODE
END MAIN

REPORT cust_list()
4GL code
END REPORT

FUNCTION update_cust()
4GL code
END FUNCTION

Ordnance Factories Institute of Learning, Ambajhari

INFORMIX

41

SCOPE OF ELEMENTS
The scope of an element deals with where that particular element is known, or can be
used, in an INFORMIX-4GL program. There are three basic types of SCOPE. These can be
broken down like this:
Global
Module

Local

Element is known throughout all modules and functions.


Element is known to all functions within the module in which the element
was defined or declared.
Element is known only to the function in which it was defined or declared.

DATA TYPES IN INFORMIX-4GL


There are eight categories of data types available in INFORMIX-4GL. These categories are
explained below.
CHAR
NUMERIC
SERIAL
DATE
MONEY
DATETIME
INTERVAL
VARIABLE-LENGTH

Category
CHAR
NUMERIC

Stores any combination of letters, numbers and symbols


There are several numeric data types designed to store different
kinds of numeric data
Stores sequential integers assigned by 4GL. Usually a primary
key column.
Stores calendar dates.
Stores currency amounts.
Stores point in time.
Stores values representing a span of time.
There are several variable-length data types unique to the
INFORMIX-OnLine engine.

Data types
CHAR
INTEGER
SMALLINT
FLOAT
SMALLFLOAT
DECIMAL

MONEY
SERIAL

MONEY
SERIAL

DATE
DATETIME

DATE
DATETIME

This is fixed-length data type


Stores whole numbers only Four bytes
Stores whole numbers only Two bytes
Stores binary floating point numbers Double
precision, 14 significant digits
Stores binary floating point numbers Single
precision, 7 significant digits
Stores numbers with number of digits specified by the
user
Stores currency amounts
Contains unique numbers that are assigned by the
system to each row of the table, and stored as
INTEGERS
Stores calendar dates
It is used when you want to store values that represent
a specific point in time

Ordnance Factories Institute of Learning, Ambajhari

42

INFORMIX

INTERVAL
VARIABLELENGTH

INTERVAL
VARCHAR
BLOB

It is used to store values that represent a span of time


This can store between 0 and 255 bytes of character
data.
Binary Large Objects are streams of bytes of arbitrary
value and length. A BLOB can be any arbitrary
collection of bytes for any purpose.

DEFINING PROGRAM VARIABLES


The placement of the DEFINE statement is what gives a variable its scope. Placing a
DEFINE in the globals function will make that variable known to all the other functions. It gives
the variable global scope.
A DEFINE function can be placed after the globals reference, but before the MAIN. This
placement of the DEFINE gives the variable module scope.
If the DEFINE is placed after a FUNCTION keyword, it will have a local scope. It can
be referenced in the function where it was defined.
GLOBAL
MODULE
LOCAL

Element is known throughout all modules and functions


Element is known to all functions within the module in which the element
was defined or declared
Element is known only to the function in which it was defined or declared

DEFINING EXPLICIT VARIABLES


The DEFINE keyword is followed by the name of a variable and the data type you would
like to assign. You may use any valid data type except SERIAL. The variable is explicit
because the name and data type are included in the definition.
Syntax:

DEFINE

variable-list

data-type

Example:

DEFINE

fname
Start_date
x, y, z

CHAR(15),
DATE,
INTEGER

Variable Name
? May be a maximum of 18 characters in length
? First eight characters must be unique (this may be system dependent)
? Must begin with a letter, then can contain letters, numbers and underscores (_)
? May be upper or lowercase

Ordnance Factories Institute of Learning, Ambajhari

INFORMIX

43

DEFINING IMPLICIT VARIABLES


The DEFINE keyword can be followed by the name of a variable. The data type is
assigned by using the keyword LIKE followed by a table.column-name. This is an implicit
definition because the data type is not plainly expressed, but rather, it is assumed to be the same
as the data type of the column being referenced.
Syntax:

DEFINE

variable-name LIKE table.column-name

Example:

DATABASE stores
DEFINE
fname
start_date
x,y,z

LIKE customer.fname,
LIKE orders.order_date,
LIKE orders.order_num

INITIALIZING VARIABLES
There are two statements that can be used to initialize your variables, LET and
INITIALIZE.
The LET Statement
It is a standard programming statement. It means to take what is on the right side of the
equal sign and assign it to the variable on the left side. In most cases, you will want to assign a
NULL as the initial value for a variable.
The INITIALIZE Statement
The INITIALIZE statement is used specifically for initializing variables and records to
NULL.
Example:
LET X = 5
LET fname
LET lname
INITIALIZE
INITIALIZE

= John
= Smith
lname TO NULL
nr_customer.* TO NULL

Ordnance Factories Institute of Learning, Ambajhari

44

INFORMIX

SCREEN INTERACTION STATEMENTS


THE SCREEN:
The screen is that area of the terminal where information can be displayed. By default,
the area of the screen in INFORMIX-4GL is 24 rows by 80 columns. INFORMIX-4GL allows
you to break the screen area into smaller sections called windows.
THE WINDOW:
When you create a window in INFORMIX-4GL, you are actually creating a mini-screen.
You are reducing the area in which statements can be placed.
? You can have as many windows as you want (memory is the only limitation)
? Only one window is active at a time
? You can change the active window
? You can decide what size to make a window
? The size of a window can affect other INFORMIX-4GL statements
THE MESSAGE STATEMENT:
Syntax:
MESSAGE display_list

[ ATTRIBUTE (attribute list) ]

Example:
MESSAGE Press the first letter of an option. ATTRIBUTE (REVERSE)
Use the MESSAGE statement to display a character string on the Message line. The
default Message line is line two of the active window. You can change this through the use of
the OPTIONS window.
The message will remain on the screen until another MESSAGE statement is used. This
means the only way to clear a message is to display another message of zero or more characters.
Attributes:
UNDERLINE
REVERSE
INVISIBLE
BOLD
BLINK
NORMAL
DIM
THE ERROR STATEMENT:
Syntax:
ERROR display_list [ ATTRIBUTE (attribute list) ]
Example:
ERROR No Rows Found

Ordnance Factories Institute of Learning, Ambajhari

INFORMIX

45

Use the ERROR statement to display a character string on the Error line. The default
Error line is the last line of the screen. You can change this through the use of the OPTIONS
statement. The Error line is always relative to the screen, regardless of the number of windows
you have open. The ERROR statement always displays text in reverse video and sounds the
terminal bell.
An error message remains on the screen until another key is pressed by the user
Attributes:
UNDERLINE
REVERSE
INVISIBLE
BOLD
BLINK
NORMAL
DIM
THE DISPLAY STATEMENT:
Syntax:
DISPLAY message AT row, column
[ ATTRIBUTE (attribute list) ]
Example:
DISPLAY Row Added. AT 22, 3 ATTRIBUTE (reverse)
Use the DISPLAY statement to display a character string to a specific location on the
screen. With DISPLAY, you specify exactly where you want your message to be displayed by
giving a row and column location. If no row and column location is specified, DISPLAY will
display your message where the cursor is currently pointing.
Attributes:

UNDERLINE
BLINK

REVERSE
NORMAL

INVISIBLE
DIM

BOLD

THE PROMPT STATEMENT:


Syntax:
PROMPT message [ ATTRIBUTE (attribute list) ]
FOR CHAR variable
[ HELP help-no ]
[ ATTRIBUTE (attribute list)]
[ ON KEY (Key-list) ]
statement . . .
END PROMPT
Example:
PROMPT Are you sure? (Y/N) :
FOR CHAR answervar
The PROMPT statement not only displays a line of text, but waits for the user to reply.
The users reply is stored in a variable. The default display for PROMPT is the first line of the
window.

Ordnance Factories Institute of Learning, Ambajhari

INFORMIX

46

The CHAR option

The HELP # option

The ON KEY option


Attributes

Attributes:

UNDERLINE
BLINK

When INFORMIX-4GL encounters a prompt statement,


it will wait for the user to enter a response and press
RETURN. If the CHAR option is used, the PROMPT
statement expects the variable to be defined as a single
character, and will not wait for RETURN to be pressed.
A Help number will find the numbered message created
using mkmessage utility and displays it to the user
when the Help key (CONTROL-W by default) is
pressed.
The ON KEY option is used to define an action that will
occur when the key listed in the key-list is pressed.
You can associate two sets of attributes with the
PROMPT statement. The first attribute applies to the
message; the second attribute is for the variable or
users response to the PROMPT statement.
REVERSE
INVISIBLE
BOLD
NORMAL
DIM

THE OPTIONS STATEMENT


The OPTIONS statement can be used to change default values associated with some
commands. Defaults that can be changed include:
?
?
?

The line messages are displayed to


The line error messages are displayed on
The location of user prompts
The default lines on which the MESSAGE statement, PROMPT statement and the
ERROR statement display can be changed using the OPTIONS statement.
eg.
OPTIONS
MESSAGE LINE FIRST + 2,
ERROR LINE 23,
PROMPT LINE LAST - 3

The help key


By default, the help key is CONTROL-W. The HELP KEY option allows you to
define a different help key.
eg.
OPTIONS
HELP KEY CONTROL-B

The location of menus


The MENU LINE option allows you to direct the menu lines to any lines of your
current screen or window. Either of the reserved words, FIRST or LAST, can be used
with MENU LINE. The values of FIRST and LAST are always relative to the current
screen or window.
eg.
OPTIONS
MENU LINE LAST - 1

Ordnance Factories Institute of Learning, Ambajhari

INFORMIX

47

THE MENU STATEMENT


A menu in an INFORMIX-4GL program can contain as many options as you need.
Sample:
MAIN
CALL main_menu()
CLEAR SCREEN
END MAIN
FUNCTION main_menu()
MENU MAIN MENU
COMMAND Customer Go to the CUSTOMER menu
CALL dummy()
COMMAND Orders Add a new order
CALL dummy()
COMMAND Stock Go to the STOCK menu
CALL dummy()
COMMAND Reports Go to the REPORTS menu
CALL dummy()
COMMAND Exit Return to the operating system
EXIT MENU
END MENU
END FUNCTION
FUNCTION dummy()
ERROR Function not yet implemented.
END FUNCTION
In the code above, the MENU keyword is followed by the menu title. This starts
the menu structure. From that point, the COMMAND keyword is used once for each option that
appears on the menu.
?
?
?
?
?

You may want to specify the menu name in uppercase so that it is easily
differentiated from the menu commands.
INFORMIX-4GL adds a colon (:) after the menu name and two spaces between each
command option. If the menu exceeds 80 characters, an ellipse ( ) indicates that
additional command options exist.
The menu name (MAIN MENU) will be displayed to the left of the command options
when your menu is displayed.
END MENU is a required syntax when you use the MENU statement
The EXIT MENU statement terminates the menu statement.

Ordnance Factories Institute of Learning, Ambajhari

48

INFORMIX

THE COMMAND CLAUSE


The clause, COMMAND menu-option, displays the stated options as a choice to the user
on a ring menu.
EXIT MENU
It terminates the MENU statement and executes the next line of code following the END
MENU statement.
The dummy function
The dummy function uses an ERROR statement to display a message in reverse video on
the last line of the screen, it will also ring the terminal bell.
SHOW OPTION AND HIDE OPTION
You can display subsets of menu options using SHOW OPTION and HIDE OPTION.
The SHOW OPTION and HIDE OPTION statements can appear in a BEFORE MENU
clause or in a COMMAND clause.
THE BEFORE MENU CLAUSE
The BEFORE MENU clause executes INFORMIX-4GL statements contained in the
clause just before the menu is displayed. This makes it a logical place for the execution of HIDE
OPTION and SHOW OPTION statements.
eg.
FUNCTION main_menu()
MENU MAIN MENU
BEFORE MENU
HIDE OPTION ALL
SHOW OPTION Query, Add, Exit

COMMAND Query Query for a row in the customer table


IF query_cust() = TRUE THEN
SHOW OPTION Next, Previous, Update, Delete
ELSE
HIDE OPTION ALL
HIDE OPTION Next, Previous, Update, Delete
END IF
END MENU
END FUNCTION

Ordnance Factories Institute of Learning, Ambajhari

INFORMIX

49

THE COMMAND KEY


If you prefer to provide your users with a one-stroke option, use the COMMAND KEY
(key-list) menu-option clause to redefine which key should be pressed to execute the given
command option. When a COMMAND clause includes a key list, the first letter of the option
name no longer activates the option.
eg.

COMMAND KEY(T) sTates Go to the STATE menu


CALL dummy()

A HIDDEN COMMAND OPTION


A hidden option can be created on a menu by not including an option name next to the
COMMAND KEY clause.
eg.

COMMAND KEY (CONTROL-B)


CALL dummy()

If the user presses CONTROL-B, the function dummy will be called. The user has to
know that this command option exists; it does not show up on the menu the way the other
options do.
MULTIPLE MENUS
It is quite common in INFORMIX-4GL to have one menu call another.
eg.
FUNCTION main_menu()
MENU MAIN MENU
COMMAND Customer Go to the CUSTOMER menu
CALL cust_menu()
NEXT OPTION Orders
COMMAND Orders Add a new order
CALL dummy ()
. . .
END MENU
END FUNCTION
FUNCTION cust_menu()
MENU CUSTOMER
COMMAND Query Search for a customer
CALL dummy()
COMMAND Next Go to the Next customer
CALL dummy()
COMMAND Exit Return to the Main menu
EXIT MENU
END MENU
END FUNCTION

Ordnance Factories Institute of Learning, Ambajhari

50

INFORMIX

PROCEDURAL LOGIC
INFORMIX-4GL procedural logic statements are similar to those found in other
programming languages. They are used to guide the path of a program during its execution.
IF STATEMENT:
Syntax:
IF expression THEN
Statement(s)
END IF
Example:
IF prompt_answer MATCHES [Yy] THEN
ERROR Customer will be deleted
ELSE
ERROR Delete cancelled
END IF
An IF statement is an instruction to execute a statement conditionally. It involves a twoway logical choice. During program execution, when the test expression evaluates to TRUE,
INFORMIX-4GL executes the statements following the keyword THEN and terminating with
the keyword END IF or ELSE. With an ELSE clause, whenever the test expression evaluates to
FALSE (or NULL), INFORMIX-4GL executes the ELSE clause statements. The ELSE clause is
optional.
IF WITHIN OTHER STATEMENTS
Syntax:
IF .... THEN
IF ... THEN
...
END IF
END IF
Example:
IF state = CA THEN
IF zipcode MATCHES 940* THEN
MESSAGE City is Redwood City.
END IF
END IF
IF statements can be nested within other IF statements. A frequent mistake (generic
syntax error) is to forget the END IF keywords or, in the case of nested IF statements, to fail to
match each IF with an END IF.

Ordnance Factories Institute of Learning, Ambajhari

INFORMIX

51

CASE STATEMENT:
Syntax:
CASE
WHEN { expr / Boolean expr }
....
[ EXIT CASE ]
[ OTHERWISE ]
statement(s)
[ EXIT CASE ]
END CASE
Example:
CASE
WHEN answervar = Y
MESSAGE Answered Yes
WHEN answervar = N
MESSAGE Answered No
OTHERWISE
MESSAGE BAD Answer
END CASE
The CASE statement can be reduced to multiple IF statements. However, it is often more
coherent to express a series of related choices in one statement.
The CASE statement repeats the variable or expression once for each WHEN clause as
illustrated above. This can be eliminated by using the variable or expression in the CASE
statement only once. The WHEN statement then checks the possible values for the given
expression.
The OTHERWISE clause is optional. It is triggered when all the preceding WHEN
clause conditions test FALSE. Statements made in the OTHERWISE clause execute if all the
listed conditions fail.
There is an implied EXIT CASE statement at the end of each sequence of statements
following a WHEN clause. Thus, when conditions are met and statements associated with a
WHEN clause execute, program control passes to the sequence of statements following the END
CASE statement. You do not need an explicit EXIT CASE.

Ordnance Factories Institute of Learning, Ambajhari

52

INFORMIX

WHILE LOOP
Syntax:
WHILE Boolean expression
Statement(s)
[ EXIT WHILE ]
[ CONTINUE WHILE ]
END WHILE
Example:
WHILE boss_in_office = TRUE
CALL act_busy() RETURNING boss_in_office
END WHILE
CALL sneak_out()
Use a WHILE loop to execute a statement or group of statements for as many times as
the stated Boolean condition tests TRUE.
The optional statement EXIT WHILE moves program control to the first statement
following END WHILE.
The optional statement CONTINUE WHILE interrupts the sequence and causes program
control to return to the top of the sequence and to test the Boolean expression.
If the Boolean expression is FALSE, then the program control skips to the first statement
after the END WHILE.
FOR LOOP:
Syntax:
FOR integer_variable = integer_expression to integer_expression
STEP integer_expression
Statement(s)
[ CONTINUE FOR ] ....
[ EXIT FOR ] ...
END FOR
Use the FOR loop to specify a number of times an iteration should occur. If you use the
keyword STEP with an integer expression, the loop is incremented in steps of the value you
state.
Since integer expression can be a variable, you can set the count dynamically.

Ordnance Factories Institute of Learning, Ambajhari

INFORMIX

53

FORMS
CREATING A DEFAULT FORM
To create a default form, select Form from the INFORMIX-4GL menu. The Generate
option of the FORM menu will take you through the following steps to create a default form.
CHOOSE DATABASE >>
NEW FORM >>
CHOOSE TABLE >>
Table-selection-complete / select-more-tables
INFORMIX-4GL will then compile the form into a usable state.
MODIFYING A DEFAULT FORM
When you select the Modify option from the FORM menu, you are presented with a list
of forms that can be modified. Highlight the form you want to work with and press RETURN.

COMPILING A FORM SPECIFICATION


Once you have modified the screen section to the desired appearance, the Programmers
environment presents you with the MODIFY FORM menu. There are three options.
Compile

Translates the form specification file into a format that INFORMIX-4GL


can use.

Save-and-exit

Saves the changes you have made, but will not compile the form.

Discard-and-exit -

Discards any changes you have made during your editing session.

DISPLAYING FORMS AND WINDOWS


OPEN FORM STATEMENT
Syntax:

OPEN FORM form-name FROM form-file

eg.

OPEN FORM cust_form FROM cust_form

The OPEN FORM statement is used to associate an INFORMIX-4GL form name with a
previously compiled form.

Ordnance Factories Institute of Learning, Ambajhari

54

INFORMIX

Form-name is the name you want to assign to the form for use in your program. It is an
identifier for the form. It is quite common to have form-name and form-file be the same name,
but it is not required.
Form-file is the name of the previously compiled form that was created from the FORM
menu.
DISPLAY FORM STATEMENT
Syntax:

DISPLAY FORM form-name

eg.

OPEN FORM cust_form FROM cust_form


DISPLAY FORM cust_form

The DISPLAY FORM statement is used to display a form on the screen. Before a form
can be displayed, it must first be opened using the OPEN FORM statement.
CLOSE FORM STATEMENT
Syntax:

CLOSE FORM form-name

eg.

CLOSE FORM cust_form

The CLOSE FORM statement is used to release the memory associated with a form. It
does not clear the form from the screen.
Sample Program:
MAIN
CALL prog_init()
CALL main_menu()
CALL prog_wrapup()
CLEAR SCREEN
END MAIN
FUNCTION prog_init()
OPEN FORM custform FROM custform
END FUNCTION

Ordnance Factories Institute of Learning, Ambajhari

INFORMIX

FUNCTION main_menu()
MENU MAIN MENU
COMMAND Customer Go to the CUSTOMER menu
CALL cust_menu()
NEXT OPTION Orders
COMMAND Orders Add a new order
CALL dummy()
COMMAND Exit Return to the operating system
EXIT MENU
END MENU
END FUNCTION
FUNCTION cust_menu()
DISPLAY FORM custform
MENU CUSTOMER
COMMAND Query Search for a customer
CALL dummy()
COMMAND Next Go to the next customer
CALL dummy()
COMMAND Exit Exit to MAIN MENU
EXIT MENU
END MENU
CLEAR SCREEN
END FUNCTION
FUNCTION dummy()
ERROR Function not yet implemented
END FUNCTION
FUNCTION prog_wrapup()
CLOSE FORM custform
END FUNCTION

Ordnance Factories Institute of Learning, Ambajhari

55

INFORMIX

56

THE INPUT STATEMENT


The process of entering information into the database has two basic steps.
1.
2.

Inputting information into program variables


Inserting the data in those program variables into the database

Since there are two basic steps, keywords that handle this transfer of information: the
INPUT statement and the INSERT statement.
The INPUT statement is used to retrieve information from the user via the screen, and
transfer it to the program variables. The INPUT statement:
?
?
?
?
?
?

Initialize the program variables to NULL by default


Turns control of the program over to the user
Displays any default values which may have been specified by the DEFAULT
attribute of a form specification file
Lets the user enter information into the fields of the form
Transfers the information automatically into the program variables as the user leaves
each field
Waits for a signal from the users that they have finished their data entry

Before using the INPUT statement, you must have satisfied a few requirements:
? There must be a form open and displayed
? There must be a program variable assigned to each field in which you are going to
allow data entry
INPUT PROGRAM VARIABLE
Syntax:

INPUT program-variable FROM field-list

Example:

INPUT

gr_customer.fname,
gr_customer.lname,
gr_customer.company,
gr_customer.address1,
gr_customer.address2,
gr_customer.city,
gr_customer.state,
gr_customer.zipcode,
gr_customer.phone

Ordnance Factories Institute of Learning, Ambajhari

INFORMIX

FROM

57

fname,
lname,
company,
address1,
address2,
city,
state,
zipcode,
phone

The program variables listed have been defined in an INFORMIX-4GL module, and field
list comes from the ATTRIBUTES section of a form specification file. For every program
variable listed in the INPUT statement, there must be a corresponding field in the FORM, and
they must be in the same sequence. The cursor will move in field-list order.
The INPUT statement takes the information from the form and puts it into a
corresponding program variable as the user goes from field to field.
EXITING FROM THE INPUT STATEMENT
The Default Condition
The ACCEPT Key
The INTERRUPT Key

Pressing the RETURN key after entering data in the last field of
the form automatically causes the program to continue.
If the user presses the ACCEPT key (ESC by default), the
program will continue to the next line of code.
When the INTERRUPT key is pressed, the program proceeds to
the statement immediately following the END INPUT
statement. Any clauses within the INPUT statement will be
skipped. This effectively aborts the INPUT statement.

THE INPUT STATEMENT USING THE BY NAME SYNTAX


Syntax:

INPUT BY NAME program-variable.*

Example:

INPUT BY NAME gr_customer.*

The program-variable is a record that has been defined in an INFORMIX-4GL module.


Using the syntax shown in the above requires that the names of the variables defined in the
gr_customer record must be the same as those in the field list of the form. The cursor will go
through the fields based on the order of the DEFINE statement for the program variables.

Ordnance Factories Institute of Learning, Ambajhari

58

INFORMIX

THE INPUT STATEMENT BY NAME WITH THRU


Syntax:

INPUT BY NAME program-variable

Example:

INPUT BY NAME gr_customer.fname THRU

Program variables:

THRU

program-variable
gr_customer.phone

DATABASE stores
GLOBALS
DEFINE gr_customer
RECORD LIKE customer.*
END GLOBALS

This method of using INPUT allows you to enter specific fields while still using the BY
NAME syntax.
INPUT STATEMENT CLAUSES
ATTRIBUTE (attribute-list)
HELP help-number

BEFORE INPUT
AFTER INPUT

BEFORE FIELD field-name

AFTER FIELD field-name

ON KEY (key-list)

This is an optional keyword you can use to specify


screen input attributes.
This is used to specify a help message. The message
associated with the help number should apply to the
INPUT statement as a whole.
This clause is executed before the control of the program
is turned over to the end user
The statements following the keywords will execute if
the user presses the ACCEPT key or the INTERRUPT
key.
The BEFORE FIELD clause transfers control to an
INFORMIX-4GL statement when the cursor enters the
specified field.
The AFTER FIELD clause transfers control to an
INFORMIX-4GL statement when the cursor leaves the
specified field.
The ON KEY clause transfers control to an INFORMIX4GL statement when a user presses the key or key
sequence listed to the (key-list).

Ordnance Factories Institute of Learning, Ambajhari

INFORMIX

59

INSERT STATEMENT
Syntax:

Example:
i)

ii)

INSERT INTO table-name [(column-list)]


VALUES (values list)

INSERT INTO customer


VALUES (gr_customer.*)
INSERT INTO customer(customer_num, fname, lname)
VALUES (0, gr_customer.fname, gr_customer.lname)

The INSERT statement is used to place the values stored in program variables into the
columns of a database table. If the column list is omitted, it is implied that one value will be
supplied for every column in the specified table. If a column list is specified but not all columns
in the table are listed, then a NULL value will be inserted into the omitted columns.
Note: If a table contains a column of SERIAL data type, the program variables for that column
must be set to zero for the proper number to be assigned.
Example:
GLOBALS
cust_globs.4gl
FUNCTION input_cust()
INPUT BY NAME gr_customer.*
LET gr_customer.customer_num = 0
INSERT INTO customer
VALUES (gr_customer.*)
END FUNCTION
AN OVERVIEW OF CURSORS
CURSOR
You can think of a cursor as a marker that points to a row retrieved by a SELECT
statement. In its simplest form, a cursor is a pointer. It points to a row, called the current row; in
a set of rows, called the active set.
A cursor must be declared to retrieve rows that satisfy the criteria of a multi-row
SELECT statement. Selecting multiple rows without a cursor results in a run-time error. The
scope of cursors is Module

Ordnance Factories Institute of Learning, Ambajhari

INFORMIX

60

TYPES OF CURSORS
There are three types of cursors available in INFORMIX-4GL. Each cursor has its own
unique set of characteristics. The three cursors are:
?
?
?

SCROLL cursors
Non-scrolling cursors
FOR UPDATE cursors

SCROLL CURSOR
The SCROLL cursor can be used to access a set of rows. A SCROLL cursor points at
one row at a time.
Using a SCROLL cursor, you can move through a set of rows in either a backward or
forward direction. It does this by creating a temporary table consisting of a snapshot of the
appropriate rows. Once this snapshot is created, it will not include any changes to the rows by
other users as long as you are looking at them.
NON-SCROLLING CURSOR
A Non-scrolling cursor will only go down (next) in the list of active rows. This type of
cursor is used when you do not need to move back and forth within the active set. A nonscrolling cursor is most commonly associated with a report.
FOR UPDATE CURSOR
A FOR UPDATE cursor (also called a locking cursor) is similar to a non-scrolling cursor
in that it can only retrieve the rows in a forward direction. However, a FOR UPDATE cursor
will place a lock on the row that the cursor is pointing to and hold that lock until the next row
becomes the current row.
A FOR UPDATE cursor is used for UPDATE or DELETE statements. You do not want
other users deleting or changing the row you are using. It can be used in conjunction with the
other types of cursors. For example, you might use a SCROLL cursor to browse the rows, and
when you find the row that you want to change, use a FOR UPDATE cursor to lock the row
during your change.

Ordnance Factories Institute of Learning, Ambajhari

INFORMIX

61

SCROLL CURSOR
CURSOR STATEMENTS
DECLARE
OPEN
FETCH
CLOSE
FREE

Assigns a cursor name to a SELECT statement


Checks the syntax of the SELECT statement. Opens logical set of rows that
satisfy the SELECT
Retrieves the actual rows from the database
Puts the cursor in a closed state, and releases the active set
Releases database server resources allocated to a cursor

THE DECLARE STATEMENT


Syntax:

DECLARE cursor-name SCROLL CURSOR [WITH HOLD] FOR


Select-statement

Example:

DECLARE cust_ptr SCROLL CURSOR FOR


SELECT * FROM customer

The DECLARE statement is used to associate a cursor name with a SELECT statement.
The keyword SCROLL is used so that you can move the cursor in any direction.
The WITH HOLD is optional syntax to prevent the cursor from being closed when a
transaction completes. Unless you include the WITH HOLD keywords, INFORMIX-4GL closes
the cursor when the transaction is terminated with either a ROLLBACK or COMMIT WORK
statement. You must explicitly CLOSE a cursor WITH HOLD.
THE OPEN STATEMENT
Syntax:

OPEN cursor-name

Example:

DECLARE cust_ptr SCROLL CURSOR FOR


SELECT * FROM customer
OPEN cust_ptr

?
?
?

The OPEN statement does the following:


Checks the validity of table and column names from the SELECT statement
Determines the active set
Sets up memory needed for a SELECT statement

THE FETCH STATEMENT


Syntax:

FETCH [NEXT | {PREVIOUS | PRIOR} | LAST | CURRENT |


RELATIVE m | ABSOLUTE n ] cursor-name [ INTO program-variable ]

Example:

FETCH cust_ptr INTO gr_customer.*

Ordnance Factories Institute of Learning, Ambajhari

62

INFORMIX

The FETCH statement retrieves a row and puts its values into the program variables
specified in the INTO clause.
A SCROLL cursor uses a temporary table when fetching rows from the database. This
allows a user to fetch in both a forward and backward direction when using a SCROLL cursor.
The SCROLL cursor gives you the ability to move around in the active set of the cursor.
Using one of the keywords with the FETCH statement will move you to the appropriate location
in the active set.
FIRST

PRIOR / PREVIOUS

NEXT
LAST
CURRENT

FETCH FIRST moves the cursor to the top of the active set. The
FIRST row is determined by your SELECT statement (ORDER BY
clause)
FETCH PRIOR or PREVIOUS will move the cursor from the
current row to the row just before the current row. The keywords
PRIOR and PREVIOUS are interchangeable
FETCH NEXT moves the cursor from the current row, down one, to
the next row in the active set
FETCH LAST moves the cursor to the bottom row in the active set
FETCH CURRENT indicates the current row of the active set

RELATIVE and ABSOLUTE


There are two additional keywords that can be used with the FETCH statement and a
SCROLL cursor.
FETCH ABSOLUTE

FETCH RELATIVE

FETCH ABSOLUTE, followed by a number, looks at the active list


of rows and will move to the ABSOLUTE # from the top of the
active list
FETCH RELATIVE # moves # of rows from the cursors current
position.

You can use negative numbers with a FETCH RELATIVE but not with a FETCH
ABSOLUTE.
THE CLOSE STATEMENT
The CLOSE statement deactivates the active set. After you CLOSE a SELECT cursor,
you cannot execute a FETCH statement until you reopen the cursor. The CLOSE statement must
be physically located after the DECLARE, OPEN and FETCH statements.
Syntax:

CLOSE cursor-name

THE FREE STATEMENT


The FREE statement can be used to release the memory associated with cursors.

Ordnance Factories Institute of Learning, Ambajhari

INFORMIX

CASE STUDY IN INFORMIX 4GL


I.

II.

III.

Structure of table : stock

Column Name

Data type

stock_num
manu_code
description
unit_price
unit
unit_descr

smallint
character
character
money
character
character

Size

3
15
4
15

Structure of table : manufact


Column Name

Data type

Size

manu_code
manu_name

character
character

3
15

File: stock.per

DATABASE stores
SCREEN SIZE 24 by 80
{
================ STOCK MAIN ENTRY SCREEN ================
Stock #
[f000 ]
MF Code
[a0
]
Description
[f001
]
Unit Price
[f002
]
Unit Type
[f003 ]
Unit Description
[f004
]
===========================================================
}
END
TABLES
stock

Ordnance Factories Institute of Learning, Ambajhari

63

64

INFORMIX

ATTRIBUTES
f000 = stock.stock_num, REQUIRED;
a0 = stock.manu_code, REQUIRED, UPSHIFT;
f001 = stock.description, DOWNSHIFT;
f002 = stock.unit_price;
f003 = stock.unit;
f004 = stock.unit_descr;
END

IV.
1.
2.
3.
4.
5.
6.
7.
8.
9.

V.

File: stock_glob.4gl
stock_glob.4gl
DATABASE stores
GLOBALS
DEFINE gr_stock RECORD LIKE stock.*
DEFINE nr_stock RECORD LIKE stock.*
END GLOBALS

File: stock_main.4gl

1. stock_main.4gl
2.
3. GLOBALS
4.
stock_glob.4gl
5.
6. MAIN
7.
8.
CALL set_options( )
9.
CALL main_init( )
10.
CALL main_menu( )
11.
CLEAR SCREEN
12.
13. END MAIN

Ordnance Factories Institute of Learning, Ambajhari

INFORMIX

14. FUNCTION main_init( )


15.
16.
INITIALIZE nr_stock.* TO NULL
17.
LET gr_stock.* = nr_stock.*
18.
OPEN FORM f_stock FROM stock
19.
20. END FUNCTION
21.
22. FUNCTION set_options( )
23.
24.
OPTIONS
25.
MESSAGE LINE LAST 1,
26.
HELP KEY CONTROL-B
27.
28. END FUNCTION
29.
30. FUNCTION main_menu( )
31.
32. MESSAGE Type the first letter of the option you want, ,
33.
or CONTROL-B for help.
34.
35. MENU STOCK MAIN
36.
37.
COMMAND One-Stock Go to the Single Row maintenance menu.
38.
CALL one_menu( )
39.
COMMAND Multiple-Stock
40.
Go to the Multiple Row maintenance menu.
41.
CALL dummy( )
42.
COMMAND Report Go to the Report menu.
43.
CALL dummy( )
44.
COMMAND Exit Return to the Operating System.
45.
EXIT MENU
46.
47.
END MENU
48.
49. END FUNCTION
50.
51. FUNCTION dummy( )
52.
53.
ERROR Function not yet implemented.
54.
55. END FUNCTION

Ordnance Factories Institute of Learning, Ambajhari

65

66

VI.

INFORMIX

File: stock_one.4gl

1. stock_one.4gl
2.
3. GLOBALS
4.
stock_glob.4gl
5.
6. FUNCTION one_menu( )
7.
8.
CLEAR SCREEN
9.
OPEN WINDOW w_stock AT 2,2 WITH 15 ROWS, 70 COLUMNS
10.
ATTRIBUTE(BORDER)
11. DISPLAY FORM f_stock
12.
13. LET gr_stock.* = nr_stock.*
14.
15. MENU STOCK ONE
16.
17.
BEFORE MENU
18.
HIDE OPTION ALL
19.
SHOW OPTION Query, Add, Exit
20.
21.
COMMAND Query Query for a row in the stock table.
22.
MESSAGE
23.
24.
IF query_stock( ) THEN
25.
SHOW OPTION Next, Previous, Update, Delete
26.
ELSE
27.
HIDE OPTION ALL
28.
SHOW OPTION Query, Add, Exit
29.
END IF
30.
31.
COMMAND Next Find the NEXT stock item from the list.
32.
CALL fetch_rel_stock(1)
33.
34.
COMMAND Previous Find the PREVIOUS stock item from the list.
35.
CALL fetch_rel_stock(-1)
36.
37.
COMMAND Update Change an existing stock item.
38.
CALL dummy( )

Ordnance Factories Institute of Learning, Ambajhari

INFORMIX

39.
40.
41.
42.
43.
44.
45.
46.
47.
48.
49.
50.
51.
52.
53.
54.
55.
56.
57.
58.
59.
60.
61.
62.
63.
64.
65.
66.
67.
68.
69.
70.
71.
72.
73.
74.

COMMAND Delete Delete an existing stock item.


CALL dummy( )
COMMAND Add Add a new stock item.
MESSAGE
CALL input_stock( )
COMMAND Exit Return to the STOCK MAIN menu.
CALL clean_up( )
EXIT MENU
END MENU
CLOSE WINDOW w_stock
END FUNCTION
FUNCTION input_stock( )
OPTIONS
MESSAGE LINE LAST 2
DISPLAY Press ACCEPT to add a row, INTERRUPT to cancel. AT 1,1
DISPLAY AT 2,1
INPUT BY NAME gr_stock.*
CALL insert_stock( )
END FUNCTION
FUNCTION insert_stock( )
INSERT INTO stock VALUES (gr_stock.*)
MESSAGE The stock item has been added to the database.
END FUNCTION

Ordnance Factories Institute of Learning, Ambajhari

67

68

VII.

INFORMIX

File: stock_brws.4gl

1. stock_brws.4gl
2.
3. GLOBALS
4.
stock_glob.4gl
5.
6. FUNCTION query_stock( )
7.
8.
DEFINE fetch_ok SMALLINT
9.
10. DECLARE stock_ptr SCROLL CURSOR FOR
11.
SELECT * FROM stock
12. OPEN stock_ptr
13.
14. CALL fetch_stock(1) RETURNING fetch_ok
15.
16. IF fetch_ok THEN
17.
CALL display_stock( )
18. ELSE
19.
ERROR No rows found.
20.
CLOSE stock_ptr
21.
FREE stock_ptr
22.
END IF
23.
24.
RETURN fetch_ok
25.
26. END FUNCTION
27.
28. FUNCTION fetch_stock (fetch_flag)
29.
30.
DEFINE fetch_flag SMALLINT, fetch_ok SMALLINT
31.
LET fetch_ok = TRUE
32.
FETCH RELATIVE fetch_flag stock_ptr INTO gr_stock.*
33.
34.
IF SQLCA.SQLCODE = NOTFOUND THEN
35.
LET fetch_ok = FALSE
36.
END IF
37.
38.
RETURN fetch_ok
39.
40. END FUNCTION
41.

Ordnance Factories Institute of Learning, Ambajhari

INFORMIX

42.
43.
44.
45.
46.
47.
48.
49.
50.
51.
52.
53.
54.
55.
56.
57.
58.
59.
60.
61.
62.
63.
64.
65.
66.
67.
68.
69.
70.
71.
72.
73.
74.

FUNCTION fetch_rel_stock(fetch_flag)
DEFINE fetch_flag SMALLINT, fetch_ok SMALLINT
CALL fetch_stock(fetch_flag) RETURNING fetch_ok
IF fetch_ok THEN
CALL display_stock( )
ELSE
IF fetch_flag = 1 THEN
ERROR You are at the end of the list.
ELSE
ERROR You are at the beginning of the list.
END IF
END IF
END FUNCTION
FUNCTION display_stock( )
DISPLAY BY NAME gr_stock.*
END FUNCTION
FUNCTION clean_up( )
CLOSE stock_ptr
FREE stock_ptr
END FUNCTION

***********

Ordnance Factories Institute of Learning, Ambajhari

69

Potrebbero piacerti anche