Professional Documents
Culture Documents
Manual Informix 4gl
Manual Informix 4gl
Reference Manual
INFORMIX-4GL
Version4.0
March 1990
Part No. 000-7044
ii
Table of
Contents
INFORMIX-4GL
Reference Manual
Introduction
About This Manual Intro-3
Related Informix Products and Documentation
Database Management Systems Intro-5
Process Architecture Intro-5
Informix Database Engines Intro-6
Summary of Chapters Intro-8
Syntax Conventions Intro-9
The Demonstration Database Intro-11
Chapter 1
Intro-4
iv Table of Contents
INFORMIX-4GL Programming
Chapter Overview 2-3
Language Conventions 2-3
Comments 2-3
INFORMIX-4GL Identifiers 2-4
Scope of Identifiers 2-4
Constants 2-5
Program Variables 2-6
Data Types 2-7
Data Conversion 2-10
Operators and Expressions 2-11
Binding to Database and Forms 2-14
The THRU Keyword and the .* Notation
INFORMIX-4GL Statements 2-16
Variable Definition 2-17
Assignment 2-17
Program Organization 2-17
Program Flow 2-18
Screen Interaction 2-19
Report Generation 2-21
Error and Exception Handling 2-21
Data Validation 2-23
Built-in Functions 2-24
ASCII 2-25
CLIPPED 2-27
COLUMN 2-29
CURRENT 2-30
DATE 2-32
DATE( ) 2-33
DAY( ) 2-34
EXTEND( ) 2-35
LENGTH( ) 2-38
MDY( ) 2-39
MONTH( ) 2-40
TIME 2-41
TODAY 2-42
2-15
1-54
UNITS 2-43
USING 2-44
WEEKDAY( ) 2-53
YEAR( ) 2-54
C Functions 2-55
Chapter 3
Using SQL
Chapter Overview 3-5
Relational Databases 3-5
SQL Identifiers 3-6
Owner Naming 3-7
Database Data Types 3-8
SQL Statement Summary 3-10
Data Definition 3-11
Data Manipulation 3-12
Cursor Management 3-13
SELECT Cursors 3-13
INSERT Cursors 3-25
Dynamic Management 3-28
Preparing Statements 3-29
Executing PREPAREd Statements 3-33
Preparing Multiple SQL Statements 3-38
The FREE Statement 3-39
Data Access 3-40
User Status and Privileges 3-41
Data Integrity 3-42
Transactions 3-42
Transaction Log File Maintenance 3-45
Audit Trails 3-45
Comparison of Transactions and Audit Trails
Locking 3-47
Row-Level Locking 3-48
Table-Level Locking 3-49
Wait for Locked Row 3-50
Indexing Strategy 3-50
Query Optimizer 3-52
Auto-Indexing 3-52
Clustered Indexes 3-52
NULL Values 3-53
Default Values 3-54
The NULL in Expressions 3-54
The NULL in Boolean Expressions 3-55
The NULL in WHERE Clauses 3-55
3-47
Table of Contents
vi Table of Contents
3-57
Chapter 5
Chapter 6
Report Writing
Chapter Overview 5-3
Calling a REPORT Routine 5-4
Structure of a REPORT Routine 5-5
DEFINE Section 5-7
OUTPUT Section 5-9
REPORT TO 5-10
LEFT MARGIN 5-12
RIGHT MARGIN 5-13
TOP MARGIN 5-15
BOTTOM MARGIN 5-16
PAGE LENGTH 5-17
ORDER BY Section 5-18
FORMAT Section 5-20
EVERY ROW 5-21
Control Blocks 5-23
AFTER GROUP OF 5-25
BEFORE GROUP OF 5-27
FIRST PAGE HEADER 5-29
ON EVERY ROW 5-31
ON LAST ROW 5-33
PAGE HEADER 5-34
PAGE TRAILER 5-36
Statements 5-37
NEED 5-38
PAUSE 5-39
PRINT 5-40
PRINT FILE 5-42
SKIP 5-43
Expressions and Built-in Functions
Aggregates 5-46
LINENO 5-48
PAGENO 5-49
SPACES 5-50
WORDWRAP 5-51
4GL Function Library
Chapter Overview 6-3
The 4GL Library Functions
ARG_VAL 6-4
ARR_COUNT 6-6
ARR_CURR 6-7
DOWNSHIFT 6-9
5-44
6-3
ERR_GET 6-10
ERR_PRINT 6-11
ERR_QUIT 6-12
ERRORLOG 6-13
INFIELD 6-14
LENGTH 6-16
NUM_ARGS 6-17
SCR_LINE 6-18
SET_COUNT 6-20
SHOWHELP 6-21
STARTLOG 6-23
UPSHIFT 6-25
Chapter 7
viii
Table of Contents
7-7
DELETE 7-73
DISPLAY 7-75
DISPLAY ARRAY 7-79
DISPLAY FORM 7-83
DROP AUDIT 7-85
DROP DATABASE 7-86
DROP INDEX 7-88
DROP SYNONYM 7-89
DROP TABLE 7-90
DROP VIEW 7-91
ERROR 7-92
EXECUTE 7-94
EXIT 7-96
FETCH 7-98
FINISH REPORT 7-101
FLUSH 7-102
FOR 7-104
FOREACH 7-106
FREE ( O ) 7-109
FUNCTION 7-110
GLOBALS 7-112
GOTO 7-114
GRANT 7-115
IF 7-118
INITIALIZE 7-120
INPUT 7-122
INPUT ARRAY 7-129
INSERT 7-138
LABEL 7-141
LET 7-142
LOAD 7-143
LOCK TABLE 7-146
MAIN 7-148
MENU 7-149
MESSAGE 7-154
OPEN 7-156
OPEN FORM 7-159
OPEN WINDOW 7-160
OPTIONS 7-165
OUTPUT TO REPORT 7-170
PREPARE 7-171
PROMPT 7-173
PUT 7-177
Table of Contents ix
Table of Contents
Appendix A
Appendix B
System Catalogs
Appendix C
Environment Variables
Appendix D
Reserved Words
Appendix E
Appendix F
Appendix G
Outer Joins
Appendix H
Appendix I
Appendix J
Table of Contents xi
xii
Table of Contents
Introduction
Introduction
About This Manual
8
9
11
Introduction
Create interactive screen forms that provide an interface between the user
of your application and the database.
Introduction
Introduction
Process Architecture
A database engine performs SQL operations. The database engine is a process
that handles storage and retrieval of data and other DBMS functions. The following figure shows this implementation for products on INFORMIX-SE.
MULTIPLE PROCESSES
INFORMIX-4GL
Pipes
INFORMIX-SE
INFORMIX-SQL
INFORMIX-SE
INFORMIX-SE
INFORMIX-ESQL
In Host Language
Fi
Acc le
ess
Data
C-ISAM
Introduction
Processes that use the database engine are implemented as applications in the
following ways:
automatically and transparently, and it does not require any special instructions in your programs. Its easy setup and use make INFORMIX-SE an ideal
engine for developing small- to medium-size applications that do not require
maximum performance nor an extensive range of data-integrity options.
INFORMIX-OnLine is a transaction-processing database engine that manages
I/O operations directly so that performance is maximized. It is designed to
handle the high performance requirements and integrity concerns of many
large applications. Most applications can run on either engine because few
differences affect the programmer. INFORMIX-OnLine, however, provides
features that increase performance, extend available data types, and improve
the administrative aspects of database management. The following features
are available only with INFORMIX-OnLine:
Introduction
Introduction
Summary of Chapters
Summary of Chapters
The INFORMIX-4GL Reference Manual is divided into the following chapters
and appendices:
Introduction
Introduction
Chapter 1
Chapter 2
Chapter 3
describes how to interact with databases by using the Informix extension to IBMs Structured Query Language (SQL).
This chapter also explains the interrelationships among various types of SQL statements and illustrates the use of the
4GL Programmers Environment.
Chapter 4
Chapter 5
Chapter 6
Syntax Conventions
Chapter 7
Appendix A
Appendix B
Appendix C
Appendix D
Appendix E
Appendix F
Appendix G
Appendix H
Appendix I
Appendix J
Syntax Conventions
This section explains how to interpret the listings of statement syntax that
appear throughout this manual.
Introduction
Syntax Conventions
ABC
abc
Substitute a value for any term that appears in lowercase italic letters.
In the previous example, you should substitute a value for indname. In
each statement description in Chapter 7, the section Explanation
describes what values you can substitute for italicized terms.
()
Enter parentheses as shown. They are part of the syntax of a statement, not special symbols.
[]
Select one of the options shown. The vertical bar indicates a choice
among several options. For example,
[ ONE | TWO [ THREE ] | FOUR ]
means that you can enter ONE or TWO or FOUR , and that, if you enter
TWO, you can also enter THREE. (Because all the choices are enclosed
in square brackets, you can also choose to omit them completely.)
{}
Choose one of the listed options. When the options are enclosed in
braces and separated by vertical bars, you must select one of the
options. For example,
{ ONE | TWO | THREE }
means that you must enter ONE or TWO or THREE, and that you cannot enter more than one selection. Unless advised otherwise, do not
enter braces in a statement.
ABC
means that you can select any of the three options, but that if you do
not enter any of them, VANILLA is the default.
10
Introduction
...
Enter additional items like those preceding the ellipsis, if you want.
The ellipsis indicates that the immediately preceding item can be
repeated indefinitely. For example,
statement
...
means that there can be a series of statements following the one that
is listed. Do not enter ellipsis symbols in a statement or program,
unless you want to enter them as literal string values.
Enter all other symbols, such as - / ; > . = % : * " and , exactly
as they appear in the syntax statement.
The notation (O) sometimes follows the name of a statement at the beginning of a syntax description in Chapter 7. This means that additional options
or features are supported by INFORMIX-4GL on the INFORMIX-OnLine database engine. Refer to the INFORMIX-OnLine Programmers Manual for details
of the additional functionality available with INFORMIX-OnLine.
orders
items
stock
11
manufact
state
Note: The stores demonstration database includes additional system catalogs and
the source code modules of several INFORMIX-4GL application programs.
12
Introduction
Chapter
1
Compiling 4GL
Source Files
Chapter Overview
36
35
65
72
1-3
1-4
Chapter Overview
This chapter describes how to create INFORMIX-4GL source-code modules,
and how to produce executable 4GL programs from these source-code
modules, both at the operating system prompt and from within the INFORMIX-4GL Programmers Environment.
The procedures to do this are described for the INFORMIX-4GL C Compiler
Version, as well as for the INFORMIX-4GL Rapid Development System.
These two implementations of INFORMIX-4GL differ in how they process
4GL source-code modules.
1-5
RDS
Effect of Command
i4gl
r4gl
Enter Programmers Environment
c4gl sfile.4gl
fglpc sfile
Compile 4GL source file sfile.4gl
xfile.4ge
fglgo xfile
Execute compiled 4GL program xfile
i4gldemo
r4gldemo
Create the demonstration database
The INFORMIX-4GL C Compiler Version requires no equivalent to the
fglgo command, since its compiled object files are executable without a
runner. The INFORMIX-4GL Rapid Development System also contains a
command-file script to compile and execute 4GL programs that call C
functions or INFORMIX-ESQL/C functions, as described near the end of
this chapter.
RDS
.4go
.4gi
Significance of Extension
Compiled 4GL source-code module
Executable (runable) 4GL program file
The backup file extensions .4bo and .4be for compiled modules and
programs have the same names in both implementations. These
1-6
designate files that are not interchangeable between the two 4GL implementations, however, because object code produced by a C compiler is
different from p-code.
Other filename extensions that are the same in both the C Compiler Version and Rapid Development System Version designate interchangeable
files, if you use both implementations of INFORMIX-4GL to process the
same 4GL source-code module.
It identifies and illustrates all the menu options and screen form fields
of the Programmers Environment.
1-7
This is the highest menu, from which you can reach any other menu of the
Programmers Environment. You have five options:
Module
Form
Program
Query-language
Use the SQL interactive interface, if you have INFORMIX-SQL installed on your system.
Exit
The first three options display new menus that are described in the pages that
follow. (You can also press CTRL-W at any menu to display an on-line help
message that describes your options.) As at any 4GL menu, you can select an
option in either of two ways:
1-8
Run
Exit
New
Compile
Program_Compile
Run
Exit
As in all of the menus of the Programmers Environment except the INFORMIX-4GL Menu, the Exit option returns control to the higher menu from
which you accessed the current menu.
You can use these options to create and compile source-code modules of
a 4GL application. See The FORM Design Menu later in this chapter for
information on creating 4GL screen forms. See also The mkmessage Utility
section in Appendix E for information on how to create and compile
programmer-defined help messages for an INFORMIX-4GL application.
1-9
Discard-and-exit
If you press RETURN or type c or C to select the Compile option, INFORMIX-4GL displays the COMPILE MODULE Menu:
COMPILE MODULE: Object Runable Exit
Create object file only; no linking to occur.
-------------------------------------------------Press CTRL-W for Help------
The Object option creates a compiled file with the .o extension but makes no
attempt to link the file with other files.
The Runable option creates a compiled file with the .4ge extension. INFORMIX-4GL assumes that the current module is a complete 4GL program, and
that no other module needs to be linked to it. Select the Runable option if the
current program module is a stand-alone 4GL program. If this is not the case,
(that is, if the file is one of several 4GL source-code modules within a multimodule program), then you should use the Object option instead, and you
must use the PROGRAM Design menu to specify all the component modules.
After you select Object or Runable, a message near the bottom of the screen
will advise you if INFORMIX-4GL issues a compile-time warning or error. If
there are warnings (but no errors), an executable file is produced. Select the
1-10
Exit option of the next menu, and then Save-and-exit at the MODIFY
MODULE Menu, if you want to save the executable file without reading the
warnings.
Alternatively, you can examine the warning messages by selecting Correct at
the next menu. When you finish editing the .err file that contains the warnings, you must select Compile again from the MODIFY MODULE Menu, since
the Correct option deletes the executable file.
If there are compilation errors, the following menu appears:
COMPILE MODULE: Correct Exit
Correct errors in the 4GL module.
-------------------------------------------------Press CTRL-W for Help------
If you choose to correct the errors, an editing session begins on a copy of your
source module with embedded error messages. You do not need to delete the
error messages, since INFORMIX-4GL does this for you. Correct your source
file, save your changes, and exit from the editor. The MODIFY MODULE Menu
reappears, prompting you to recompile, or to save or discard your changes
without compiling.
If there are no compilation errors, the MODIFY MODULE Menu appears with
the Save-and-Exit option highlighted. Select this option to save the current
source-code module as a file with extension .4gl, and create an object file with
the same filename, but with the extension .o. If you specified Runable when
you compiled, the executable version is saved with the extension .4ge. The
Discard-and-Exit option discards any changes to your file since you selected
the Modify option.
Run
Exit
This option resembles the Modify option, but NEW MODULE is the menu
title, and you must enter a new module name, rather than select it from a list.
If you have not designated an editor previously in this session or with
DBEDIT, you are prompted for an editor. Then an editing session begins.
Run
Exit
After you specify the name of a 4GL source-code module to compile, the
screen displays the COMPILE MODULE Menu. Its Object, Runable, and Exit
options were described earlier in the discussion of the Modify option.
1-12
The RUN PROGRAM screen presents a list of compiled modules and programs, with the highlight on the module corresponding to the current file, if
any has been specified. Compiled programs must have the extension .4ge to
be included in the list. If you compile a program outside the Programmers
Environment and you want it to appear in the program list, give it the extension .4ge. If no compiled programs exist, INFORMIX-4GL displays an error
message and restores the MODULE Design Menu.
1-13
Run
Exit
You can use this menu to create, modify, and compile screen form specifications. These define visual displays that 4GL applications can use to query and
modify the information in a database. INFORMIX-4GL form specification files
are ASCII files that are described in Chapter 4 of this manual, and in
Chapters 6 and 7 of the INFORMIX-4GL User Guide.
The FORM Design Menu supports the following options:
1-14
Modify
Generate
New
Compile
Exit
Readers familiar with INFORMIX-SQL may notice that this resembles the
menu displayed by the Form option of the INFORMIX-SQL Main Menu.
If you select this option, you are prompted to select the name of a form
specification file to modify. Source files created at the FORM Design Menu
have the file extension .per. (If you use a text editor outside of the Programmers Environment to create form specification files, you must give them the
extension .per before you can compile them with the FORM4GL screen form
facility.)
If you have not already designated a text editor in this INFORMIX-4GL
session or with DBEDIT, you are prompted for the name of an editor. Then an
editing session begins, with the form specification source-code file that you
specified as the current file. When you leave the editor, INFORMIX-4GL
displays the MODIFY FORM Menu with the Compile option highlighted.
Now you can press RETURN to compile the revised form specification file.
MODIFY FORM: Compile Save-and-exit
Compile the form specification.
Discard-and-exit
1-15
1-16
When you select this option, INFORMIX-4GL prompts you to select a database, to choose a filename for the form specification, and to identify the tables
that the form will access. After you provide these data, INFORMIX-4GL creates and compiles a form specification file. (This is equivalent to running
the -d (default) option of FORM4GL, as described near the end of Chapter 4,
Form Building and Compiling.)
Exit
After prompting you for the name of your form specification file, INFORMIX-4GL places you in the editor where you can create a form specification
file. When you leave the editor, INFORMIX-4GL transfers you to the NEW
FORM Menu that is like the MODIFY FORM Menu. You can compile your form
and correct it in the same way.
1-17
INFORMIX-4GL compiles the form specification file whose name you specify.
If the compilation fails, INFORMIX-4GL displays the COMPILE FORM Menu
Exit
1-18
You can use this menu to create or modify a multi-module 4GL program specification, to compile and link a program, or to execute a program.
The PROGRAM Design Menu supports the following options:
Modify
New
Compile
Planned_Compile
Run
Drop
Exit
You must first use the MODULE Design Menu and FORM Design Menu to
enter and edit the INFORMIX-4GL statements within the component sourcecode modules of a 4GL program. Then you can use the PROGRAM Design
Menu to identify which modules are part of the same application program,
and to link all the modules as an executable command file.
1-19
Libraries
Compile_Options
Rename
Exit
]
]
]
]
]
Other Source
[cfunc
]
[
]
[
]
[
]
Libraries [m
[
Figure 1-1
]
]
]
]
]
]
]
]
]
]
]
Compile Options [
[
]
]
]
]
]
]
The name of the program appears in the Program field. In Figure 1-1 the name
is myprog. You can change this name by selecting the Rename option.
INFORMIX-4GL assigns the program name, with the extension .4ge, to the
executable program produced by compiling and linking all the source files
and libraries. (Compiling and linking occurs when you select the Compile
option, as described later in this chapter.) In this example, the resulting executable program would have the name myprog.4ge.
Use the 4GL option to update the entries for the 4GL Source fields and the 4GL
Source Path fields on the form. The five rows of fields under these labels form
a screen array. When you select the 4GL option, INFORMIX-4GL executes an
INPUT ARRAY statement so you can move and scroll through the array. See
the INPUT ARRAY statement in Chapter 7 for information about how to use
your function keys to scroll, delete rows, and insert new rows. (You cannot
redefine the function keys, however, as you can with an INFORMIX-4GL
program.)
1-20
The INFORMIX-4GL source program that appears in Figure 1-1 contains three
modules:
1-21
The submenu screen forms displayed by the New and the Modify options of
the PROGRAM Design Menu are identical, except that you must first supply
a name for your program when you select the New option. (INFORMIX-4GL
displays a blank form in the NEW PROGRAM Menu.) The NEW PROGRAM
Menu has the same options as the MODIFY PROGRAM Menu, as illustrated
earlier.
Run
Drop
Exit
1-22
In this instance, changes were made to all the components of the 4GL
program that were listed in Figure 1-1. This display indicates that no
source-code module has been compiled since the program was changed.
1-23
Run
Drop
Exit
1-24
1-25
If you are creating a new .4gl source module, press n to select the New
option of the MODULE Design Menu. The screen prompts you for a name
to assign to the new module.
Enter a name for the new module. The name must begin with a letter and
can include letters, numbers, and underscores. The name must be unique
among the files in the same directory, and among the other program modules, if it will be part of a multi-module program. INFORMIX-4GL attaches
extension .4gl to this identifier, as the filename of your new source
module.
Specify the name of a text editor, or press RETURN for vi, the default
editor. Now you can begin an editing session by entering 4GL statements.
(The chapters that follow describe INFORMIX-4GL statements and
programs.)
When you have finished entering or editing your 4GL code, use an
appropriate editor command to save your source file and end the text
editing session.
1-26
Select the Compile option to compile the module. After you select
Compile, the screen prompts you to select among three options:
Object, Runable, and Exit.
What you should do depends on whether your module is a complete
program, or whether it is one of several .4gl modules that together
comprise a complete program.
Select Correct to resume the previous text editing session, with the same
4GL source code, but with error messages in the file.
Edit the file to correct the error, and select Compile again. If an error message appears, repeat the previous steps, until the module compiles
without error.
After the module compiles successfully, the screen prompts you again to
Compile, or to Save-and-exit, or to Discard-and-exit. Select the second
option, to save the compiled program. The MODULE Design Menu
appears again on your screen.
If your program requires screen forms, you must select Exit to return to the
INFORMIX-4GL Menu, and then select Form to display the FORM Design
Menu. See Chapter 4 for information about designing and creating screen
forms.
If your program displays help messages, you must create a help file and
compile it with the mkmessage utility. See Chapter 8 of the INFORMIX-
1-27
4GL User Guide for more information about help messages in INFORMIX-4GL programs.
If you are not at the INFORMIX-4GL Menu, select Exit until that menu
appears. Then select the Program option, to display the PROGRAM
Design Menu.
Select the New option if you are creating a new multi-module 4GL
program, or select Modify if you are modifying an existing one. In either
case, the screen prompts you for the name of a program.
Enter the name (without a file extension) of the program that you are
modifying, or the name to be assigned to a new program. Names must
begin with a letter, and can include letters, underscores ( _ ), and numbers.
After you enter a valid name, the PROGRAM screen appears, with your
program name in the first field.
If you selected Modify, the names and pathnames of the source-code
modules are also displayed. In that case, the PROGRAM screen appears
below the MODIFY PROGRAM Menu, rather than below the NEW
PROGRAM Menu. (Both menus list the same options.)
1-28
Other Source
[
]
[
]
[
]
[
]
Ext
[
[
[
[
Libraries [
[
]
]
]
]
]
]
]
]
]
]
]
Compile Options [
[
]
]
]
]
]
]
To specify new 4GL modules or edit the list of 4GL modules, press
RETURN to select the 4GL option. You can enter or edit the name of a
module, without the .4gl file extension. Repeat this step for every module.
If the module is not in the current directory nor in a directory specified by
the DBPATH environment variable, enter the pathname to the directory
where the module resides.
If your program includes any modules that are not 4GL source files, you
should select the Other option. This option enables you to specify each
filename in the Other Source field, the filename extension in the Ext field,
and the pathname in the Other Source Path field.
These fields are part of an array that can specify up to 100 other modules, such as C language source files or object files. If you have the INFORMIX-ESQL/C product installed on your system, you can also specify ESQL/
C source modules (with extension .ec) here.
After you have correctly listed all of the modules of your program, select
the Exit option to return to the PROGRAM Design Menu.
1-29
Select the Compile option of the PROGRAM Design Menu. This option
produces an executable file that contains all your 4GL program modules.
Its filename is the program name that you specified, with extension .4ge.
The screen lists the names of your .4gl source modules, and displays the
PROGRAM Design Menu with the Run option highlighted.
See also the section Program Filename Extensions (C Compiler Version)
later in this chapter for information about the backup files that are produced automatically when you work at the Programmers Environment
of the INFORMIX-4GL C Compiler Version.
TEXT
EDITOR
.4gl
Source
Files
.err
Error
File
Figure 1-2
1-30
.c, .ec
Files
PREPROCESSOR
& COMPILER
c4gl
.o
Object
Files
.4ge
Compiled
Program
File
The cycle begins in the upper left corner with a text editor, such as vi,
to produce a 4GL source module.
The program module can then be compiled, by invoking the c4gl preprocessor and compiler command. (If error messages result, find them in the
.err file and edit the source file to correct the errors. Then recompile the
corrected source module.)
The resulting compiled .4ge program file is an executable command file
that you can run by entering its name at the system prompt:
filename.4ge
where filename.4ge specifies your compiled 4GL file.
The correspondence between commands and menu options of the Programmers Environment is summarized by the following list:
Command
vi
c4gl
filename.4ge
Invokes
UNIX System Editor
4GL Preprocessor/Compiler
4GL Application
Menu Option
Module New/Modify
Compile
Run
1-31
The c4gl command compiles your 4GL source-code module (here called
source.4gl) and produces an executable program called filename.4ge. The complete syntax of the c4gl command appears on the next page.
Syntax
c4gl { -V |
[ -ansi] [-e ] [ -a ] [ -otherargs . . . ] [ -o outfile ] source.4gl . . .
[ otheresql.ec . . . ] [ othersrc.c . . . ] [ otherobj.o . . . ] [ yourlib . . . ] }
Explanation
1-32
-V
-ansi
instructs the compiler to check all SQL statements for compliance with ANSI standards.
-e
-a
-otherargs
outfile
source.4gl
otheresql.ec
othersrc.c
otherobj.o
yourlib
Notes
1. If you specify the -V option to display the version number, all other
arguments are ignored, and no output files are produced.
2. Since the -a option requires additional run-time processing, you may
want to use this option only during development to debug your program.
3. The c4gl command passes all C compiler arguments (otherargs) and other
C source and object files (othersrc.c, otherobj.o) directly to the C compiler
(cc).
4. You can compile INFORMIX-4GL modules separately from your MAIN
program block. If there is no MAIN program block in source.4gl, your code
is compiled to source.o, but not linked with other modules or libraries.
You can use c4gl to link your code with a module that includes the MAIN
program block at another time. (Chapter 2 of the INFORMIX-4GL User
Guide describes the MAIN program block.)
5. If you specify the -ansi option, it must appear first in your list of c4gl
command arguments. The -ansi option asks for compile-time warning
messages if your source code includes Informix extensions to the ANSI
standard for SQL. (Chapter 7 lists the Informix syntax extensions.) Compiler warnings and error messages are saved in a file called source.err.
6. If you omit the -o outfile option, the default filename is a.out.
1-33
Examples
The simplest case is to compile a single-module INFORMIX-4GL program.
This command produces an executable program called single.4ge:
c4gl single.4gl -o single.4ge
In the next example, the object files mod1.o, mod2.o, and mod3.o are previously compiled INFORMIX-4GL modules, and mod4.4gl is a source-code
module. Suppose that you want to compile and link mod4.4gl with the three
object modules to create an executable program called myappl.4ge. To do so,
enter the following command line:
c4gl mod1.o mod2.o mod3.o mod4.4gl -o myappl.4ge
1-34
file.o
file.4ge
file.err
file.ec
file.c
file.erc
form.per
form.frm
form.err
The last three files do not exist unless you create or modify a screen form
specification file, as described in Chapter 4.
The next page lists the corresponding file extensions for the backup files
that INFORMIX-4GL automatically creates when you use the Programmers
Environment to process 4GL source files.
The following list identifies the backup files that are produced when you use
INFORMIX-4GL from the Programmers Environment.
file.4bl
file.4bo
1-35
file.4be
file.pbr
file.fbm
1-36
This is the highest menu, from which you can reach any other menu of the
Programmers Environment. You have five options:
Module
Form
Program
Query-language
Use the SQL interactive interface, if you have INFORMIX-SQL installed on your system.
Exit
The first three options display new menus that are described in the pages that
follow. (You can also press CTRL-W at any menu to display an on-line help
message that describes your options.) As at any 4GL menu, you can select an
option in either of two ways:
1-37
Run
Debug
Exit
New
Compile
Program_Compile
Run
Debug
Exit
As in all of the menus of the Programmers Environment except the INFORMIX-4GL Menu, the Exit option returns control to the higher menu from
which you accessed the current menu.
You can use these options to create and compile source-code modules of a
4GL application. (See The FORM Design Menu later in this chapter for
information on creating 4GL screen forms. Refer also to The mkmessage
Utility section of Appendix E for information on creating and compiling
programmer-defined help messages for an INFORMIX-4GL application.)
1-38
Discard-and-exit
If you press RETURN or type c or C to select the Compile option, INFORMIX-4GL displays the COMPILE MODULE Menu:
COMPILE MODULE: Object Runable Exit
Create object file (.4go suffix).
-------------------------------------------------Press CTRL-W for Help------
The Object option creates a file with a .4go extension. The Runable option
creates a file with a .4gi extension. Select the Runable option if the current
program module is a stand-alone 4GL program. If this is not the case, (that is,
if the file is one of several 4GL source-code modules within a multi-module
program), then you should use the Object option instead, and you must use
the PROGRAM Design Menu to specify all the component modules.
1-39
After you select Object or Runable, a message near the bottom of the screen
will advise you if INFORMIX-4GL issues a compile-time warning or error. If
there are warnings (but no errors), a p-code file is produced. Select the Exit
option of the next menu, and then Save-and-exit at the MODIFY MODULE
Menu, if you want to save the p-code file without reading the warnings.
Alternatively, you can examine the warning messages by selecting Correct
at the next menu. When you finish editing the .err file that contains the
warnings, you must select Compile again from the MODIFY MODULE Menu,
since the Correct option deletes the p-code file.
If there are compilation errors, the following menu appears:
COMPILE MODULE: Correct Exit
Correct errors in the 4GL module.
-------------------------------------------------Press CTRL-W for Help------
If you choose to correct the errors, an editing session begins on a copy of your
source module with embedded error messages. (You do not need to delete
error messages, since INFORMIX-4GL does this for you.) Correct your source
file, save your changes, and exit from the editor. The MODIFY MODULE Menu
reappears, prompting you to recompile, or to save or discard your changes
without compiling.
If there are no compilation errors, the MODIFY MODULE Menu appears
with the Save-and-Exit option highlighted. If you select this option, INFORMIX-4GL saves the current source-code module as a disk file with the filename extension .4gl, and saves the compiled version as a file with the same
filename, but with the extension .4go or .4gi. If you select the Discard-and-Exit option, INFORMIX-4GL discards any changes made to
your file since you selected the Modify option.
1-40
Run
Debug
Exit
This option resembles the Modify option, but NEW MODULE is the menu
title, and you must enter a new module name, rather than select it from a list.
If you have not designated an editor previously in this session or with
DBEDIT, you are prompted for an editor. Then an editing session begins.
Run
Debug
Exit
After you specify the name of a 4GL source-code module to compile, the
screen displays the COMPILE MODULE Menu. Its Object, Runable, and Exit
options were described two pages earlier in the discussion of the Modify
option.
1-41
program specification database, taking into account the time when the modules were last updated. This option is useful when you have just modified a
single module of a complex program and want to test it by compiling it with
the other modules.
Run
Debug
Exit
1-42
Run
Debug
Exit
You can use this menu to create, modify, and compile screen form specifications. These specifications define visual displays that 4GL applications can
use to query and modify the information in a database. INFORMIX-4GL
screen form specifications are ASCII files that are described in Chapter 4 of
this manual, and in Chapters 6, 7, and 11 of the INFORMIX-4GL User Guide.
The FORM Design Menu supports the following options:
Modify
Generate
1-43
New
Compile
Exit
If you select this option, you are prompted to select the name of a form
specification file to modify. Source files created at the FORM Design Menu
(or at the command line by the FORM4GL screen form facility) have the file
extension .per.
1-44
Discard-and-exit
Now you can press RETURN to compile the revised form specification file.
If the compiler finds errors, the COMPILE FORM Menu appears:
COMPILE FORM: Correct Exit
Correct errors in the form specification.
-------------------------------------------------Press CTRL-W for Help------
1-45
When you select this option, INFORMIX-4GL prompts you to select a database, to choose a filename for the form specification, and to identify the tables
that the form will access. After you provide this information, INFORMIX-4GL
creates and compiles a form specification file. (This is equivalent to running
the -d (default) option of FORM4GL, as described near the end of Chapter 4,
Form Building and Compiling.)
Exit
After prompting you for the name of your form specification file, INFORMIX-4GL places you in the editor where you can create a form specification
file. When you leave the editor, INFORMIX-4GL transfers you to the NEW
FORM Menu that is like the MODIFY FORM Menu. You can compile your form
and correct it in the same way.
1-46
INFORMIX-4GL prompts you for the name of the form specification file and
then performs the compilation. If the compilation is not successful, INFORMIX-4GL displays the COMPILE FORM Menu with the highlight on the Correct option.
Exit
1-47
Exit
You can use this menu to create or modify a multi-module 4GL program
specification, to compile a program, or to execute or analyze a program.
The PROGRAM Design Menu supports the following eight options:
1-48
Modify
New
Compile
Planned_Compile
Run
Debug
Undefine
Exit
You must first use the MODULE Design Menu and FORM Design Menu
to enter and edit the INFORMIX-4GL statements within the component
source-code modules of a 4GL program. Then you can use the PROGRAM
Design Menu to identify which modules are part of the same application
program, and to combine all the 4GL modules in an executable program.
Other
Program_Runner
Rename
Exit
Figure 1-3
]
]
]
]
]
]
]
]
]
]
Global Source
[
]
[
]
]
]
Other .4go
[obj
]
[
]
]
]
The name of the program appears in the Program field. In Figure 1-3 this name
is myprog. You can change the name by selecting the Rename option. The
program name, with extension .4gi, is assigned to the program produced by
compiling and combining all the source files. (Compiling and combining is
done by the Compile option, as described later in this chapter, or by the
Program_Compile option of the MODULE Design Menu.) In this case, the
runable program would have the name myprog.4gi.
Compiling 4GL Source Files
1-49
The 4GL option enables you to update the entries for 4gl Source and 4gl Source
Path. The five rows of fields under these labels form a screen array. If you
select the 4GL option, INFORMIX-4GL executes an INPUT ARRAY statement
so you can move through the array and scroll for up to a maximum of 100
entries.
The INPUT ARRAY statement description in Chapter 7 explains how to use
function keys to scroll, delete rows, and insert new rows. (You cannot redefine function keys, however, as you can with an INFORMIX-4GL program.)
In the example shown in Figure 1-3, the 4GL source program has been
broken into three modules: a module containing the MAIN program block
(main.4gl), a module containing functions (funct.4gl), and a module containing REPORT statements (rept.4gl). These modules are all located in the directory /u/john/appl/4GL. If a module contains only global variables, you can
list it here or in the Global Source array.
The Globals option enables you to update the Global Source array. If you use
the Global Source array to store a globals module, any modification of the globals module file causes all 4GL modules to be recompiled when you select the
Compile option.
The Other option enables you to update the entries for the Other .4go and
Other .4go Path fields. This is where you specify the name and location of
other 4GL object files (.4go files) to include in your program. Do not specify
the filename extensions. You can list up to 100 files in this array.
The Program_Runner option enables you to specify the name and location
of the p-code runner to execute your program. You can run INFORMIX-4GL
programs with fglgo (the default) or with a customized p-code runner. A customized p-code runner is an executable program that you create to run 4GL
programs that call C functions, as described later in this chapter. If you do not
modify the Runner field, your program is executed by fglgo when you select
the Run option from the PROGRAM Design Menu.
The MODIFY PROGRAM screen form contains two additional fields labeled
Debugger and Debugger Path. If you have the INFORMIX-4GL Interactive
Debugger, you can also use the Program_Runner option to enter the name
of a customized Debugger. See the section RDS Programs That Call C Functions later in this chapter for information about the use of a customized
Debugger. For the procedures to create a customized Debugger, refer to
Appendix C of the Guide to the INFORMIX-4GL Interactive Debugger, which
includes an example.
The Exit option of the MODIFY PROGRAM Menu returns you to the
PROGRAM Design Menu.
1-50
Exit
The New option is identical to the Modify option, except that you must first
supply a name for your program. INFORMIX-4GL then displays a blank form
with a NEW PROGRAM Menu that has the same options as the MODIFY
PROGRAM Menu.
Run
Debug
Undefine
Exit
The Compile option produces a runable p-code file with a .4gi extension.
INFORMIX-4GL lists each step of the compilation as it occurs.
1-51
Exit
If you have made changes in all the components of the program listed in
Figure 1-3 since the last time they were compiled, INFORMIX-4GL displays
the previous screen.
Undefine Exit
The screen lists any compiled programs (files with the extension .4gi)
and highlights the current program, if one has been specified. This option
resembles the Run option of the MODULE Design Menu.
Although .4go files are not displayed, you can also enter the name and
extension of a .4go file. Whatever compiled program you select is executed
by fglgo, or by the runner that you specified in the Runner field of the
Program Specification screen. This screen was illustrated earlier, in the
description of the MODIFY PROGRAM Menu.
1-52
Exit
Exit
1-53
1-54
If you are creating a new .4gl source module, press n to select the New
option of the MODULE Design Menu. The screen prompts you for a name
to assign to the new module.
Enter a name for the new module. The name must begin with a letter, and
can include letters, numbers, and underscores. The name must be unique
among the files in the same directory, and among the other program modules, if it will be part of a multi-module program. INFORMIX-4GL attaches
extension .4gl to this identifier, as the filename of your new source
module.
Specify the name of a text editor, or press RETURN for vi, the default editor. Now you can begin an editing session by entering 4GL statements.
(The chapters that follow describe INFORMIX-4GL statements and
programs.)
When you have finished entering or editing your 4GL code, use an appropriate editor command to save your source file and end the text editing
session.
1-55
Select the Compile option to compile the module. After you select
Compile, the screen prompts you to select among Object, Runable,
and Exit options.
What you should do depends on whether your module is a complete
program, or whether it is one of several .4gl modules that together
comprise a complete program.
Select Correct to resume the previous text editing session, with the
same 4GL source code, but with error messages in the file.
Edit the file to correct the error, and select Compile again. If an error
message appears, repeat the previous steps, until the module compiles
without error.
After the module compiles successfully, the screen prompts you again to
Compile, or to Save-and-exit, or to Discard-and-exit. Select the second
option to save the compiled program. The MODULE Design Menu
appears again on your screen.
If your program requires screen forms, you must select Exit to return to the
INFORMIX-4GL Menu and then select Form to display the FORM Design
Menu. See Chapter 4 for information about designing and creating screen
forms.
If your program displays help messages, you must create a help file and
compile it with the mkmessage utility. See Chapter 8 of the INFORMIX4GL User Guide for more information about implementing help messages
in INFORMIX-4GL programs.
1-56
If you are not at the INFORMIX-4GL Menu, select Exit until that menu
appears. Then select the Program option to display the PROGRAM Design
Menu.
Select the New option if you are creating a new multi-module 4GL
program, or select Modify if you are modifying an existing one. In either
case, the screen prompts you for the name of a program.
Enter the name (without a file extension) of the program that you are
modifying, or the name to be assigned to a new program. Names must
begin with a letter, and can include letters, underscores ( _ ), and numbers.
After you enter a valid name, the PROGRAM screen appears, with your
program name in the first field.
If you selected Modify, the names and pathnames of the source-code
modules are also displayed. The PROGRAM screen appears below the
MODIFY PROGRAM Menu, rather than below the NEW PROGRAM Menu.
(Both menus list the same options.)
NEW PROGRAM:
4GL Globals
Edit the 4GL sources list.
Other
Program_Runner
Rename
Exit
]
]
]
]
]
]
]
Other .4go
[
]
[
]
]
]
1-57
To specify new 4GL modules or edit the list of 4GL modules, press
RETURN to select the 4GL option. You can enter or edit the name of a module, without the .4gl file extension. Repeat this step for every module. If
the module is not in the current directory or in a directory specified by the
DBPATH environment variable, enter the pathname to the directory
where the module resides.
The name of the runner (and of the Debugger, if you have the INFORMIX-4GL Interactive Debugger) are usually as illustrated in the
PROGRAM screen, unless your 4GL program calls C functions. A later sec-
tion of this chapter, RDS Programs That Call C Functions, explains how
to create a customized runner or Debugger, which you can then specify
by selecting the Program_Runner option.
If your program includes any .4go modules that you have already compiled, you can select the Other option to enter or edit their filenames and
pathnames.
After you correctly list all of the modules of your 4GL program, select the
Exit option to return to the PROGRAM Design Menu.
Select the Compile option of the PROGRAM Design Menu. This produces
a file that combines all of your .4gl source files into an executable program. Its filename is the program name that you specified, with extension
.4gi. The screen lists the names of your .4gl source modules and displays
the PROGRAM Design Menu with the Run option highlighted.
See also the section Program Filename Extensions (C Compiler Version)
later in this chapter for information about the backup files that are produced
automatically when you work at the Programmers Environment of the
INFORMIX-4GL Rapid Development System.
1-58
1-59
TEXT
EDITOR
.4gl
Source
File
P-CODE
COMPILER
fglpc
DEBUGGER
fgldb
.4go
Compiled
p-code
File
P-CODE
RUNNER
fglgo
Figure 1-4
The cycle begins in the upper left corner with a text editor, such as vi,
to produce a 4GL source module.
The program module can then be compiled, using the fglpc p-code
compiler. (If error messages are produced by the compiler, find them in
the .err file, and edit the .4gl file to correct the errors. Then recompile the
corrected .4gl file.)
1-60
vi
fglpc
fglgo
fgldb
Invokes
UNIX System Editor
4GL P-Code Compiler
4GL P-Code Runner
4GL Interactive Debugger
Menu Option
Module New/Modify
Compile
Run
Debug
Syntax
fglpc { -V | [ -ansi ] [ -a ] [ -p pathname ] source [ .4gl ] . . . }
1-61
Explanation
-V
-ansi
-a
-p pathname
stores object (.4go) files and error (.err) files in the directory
specified by pathname.
source.4gl
Notes
1. The fglpc command reads source.4gl files and creates a compiled version
of each, with the filename source.4go. You can specify any number of
source files, in any order, with or without their .4gl filename extensions.
2. If you specify the -V option, the screen displays the version number of
your SQL and p-code compiler software. Any other command options are
ignored. After displaying this information, the program terminates without compiling.
3. If you specify the -ansi option, it must appear first in your list of fglpc
command arguments. The -ansi option asks for compile-time warning
messages if your source code includes Informix extensions to the ANSI
standard for SQL. (Chapter 7 lists the Informix syntax extensions.)
4. If an error or warning occurs during compilation, INFORMIX-4GL creates
a file called source.err. Look in source.err to find where the error or warning occurred in your code.
5. You can use the -p pathname option to specify a non-default directory for
the .4go and .err files. Otherwise, any files produced by fglpc are stored
in your current working directory.
6. Since the -a option requires additional processing, you may want to use
this option only for debugging during development.
Examples
The following command compiles a 4GL source file single.4gl, and creates a
file called single.4go in the current directory:
fglpc single.4gl
The next command line compiles two 4GL source files:
fglpc -p /u/ken fileone filetwo
1-62
TEXT
EDITOR
.4gl
Source
Files
P-CODE
COMPILER
fglpc
.4go
p-code
Object
Files
CONCATENATION
UTILITY
.4gi
p-code
Executable
Files
P-CODE
RUNNER
fglgo
Figure 1-5
1-63
The UNIX cat command combines the listed files into the file specified after
the redirect symbol (>) in a command line of the form
cat file1.4go file2.4go ... fileN.4go > new.4gi
Syntax
fglgo { -V | [ -a ] filename[.4go|.4gi ] [ args ] }
Explanation:
1-64
-V
-a
filename
args
Notes
1. If you do not specify a filename extension in the command line, fglgo
looks first for the filename with a .4gi extension, and then for the filename
with a .4go extension.
2. To run a 4GL program that calls programmer-defined C functions, you
cannot use fglgo. You must instead use a customized p-code runner. The
section RDS Programs That Call C Functions describes how to create a
customized runner.
Examples
To run a compiled program named myprog.4go, enter the following command line at the operating system prompt:
fglgo myprog
or
fglgo myprog.4go
You can then run the mods.4gi program by using the command lines:
fglgo mods
or
fglgo mods.4gi
1-65
If you have the Debugger, you can invoke it at the system prompt by a command line of the form:
fgldb filename
Here filename is any runable 4GL file that you produced by an fglpc command. See Chapter 8 of the Guide to the INFORMIX-4GL Interactive Debugger
for the complete syntax of the fgldb command.
1-66
The fgiusr.c file is a C language file that you can edit to declare any number
of programmer-defined C functions.
1-67
To edit fgiusr.c, you can copy the file to any directory. (Unless this is your
working directory at compile time, you must specify the full pathname of the
edited fgiusr.c file when you compile.) Edit fgiusr.c to specify the following:
int function-name( );
Three initializers for each function:
" function-name ", function-name, [ - ] integer,
You can create one customized p-code runner. In this case, you can edit
fgiusr.c to specify all the C functions called from all your 4GL programs.
After you create one comprehensive runner, you can use it to execute all
your 4GL applications.
You can create several application-specific runners. In this case, you can
either make a copy of the fgiusr.c file (with a new name) for each custom1-68
Syntax
cfglgo { -V | fgiusr.c cfile. { ec | c | o } [ . . . ] [ -o newfglgo ] }
Explanation
-V
fgiusr.c
cfile
-o newfglgo
Notes
1. The cfglgo command compiles and links the edited fgiusr.c file with
your C program files into an executable program that can run your 4GL
application.
2. You can rename an edited structure definition file. If you do so, specify its
new filename in place of fgiusr.c.
3. If you do not specify the -o newfglgo option, the new runner is given the
default name a.out.
4. You can specify any number of uncompiled or compiled C or INFORMIX-ESQL/C files in a cfglgo command line.
5. You must have the INFORMIX-ESQL/C product to compile INFORMIX-ESQL/C files with cfglgo.
Compiling 4GL Source Files
1-69
6. If the fgiusr.c file to be linked is not in the current directory, you must
specify a full pathname.
7. The customized runner can also run 4GL programs that do not call C
functions.
8. The -V option displays the release version numbers of your p-code and
SQL software and returns the system prompt. All other arguments are
ignored, and no other output is produced.
Examples
The following example 4GL program calls the C function prdate( ):
prog.4gl:
main
. . .
call prdate()
. . .
end main
1-70
line 3:
line 4:
line 6:
line 7:
In this example, you can use the following commands to compile the 4GL
program, to compile the new runner, and to run the program:
To compile the example 4GL program:
fglpc prog.4gl
1-71
file.4go
file.4gi
file.err
file.erc
The last three files do not exist unless you create or modify a screen form
specification file, as described in Chapter 4.
The next page lists the corresponding file extensions for the backup files that
INFORMIX-4GL automatically creates when you use the Programmers Environment to process 4GL source files.
The following list identifies backup files that are produced when you use
INFORMIX-4GL from the Programmers Environment.
file.pbr
is an INFORMIX-4GL source backup file, created during the modification and compilation of a .4gl program module.
is an object backup file, created during the compilation of a .4go
program module.
is an object backup file, created during the compilation of a .4gi
program module.
is a FORM4GL source backup file.
file.fbm
file.4bl
file.4bo
file.4be
Under normal conditions, INFORMIX-4GL creates the backup files and intermediate files as necessary, and deletes them upon a successful compilation. If
you interrupt a compilation, you may find one or more of the files in your
current directory.
If you compile with a fglpc command line that includes the p pathname
option, INFORMIX-4GL creates the .4gi, .4go, .err, and corresponding backup
files in the directory specified by pathname, rather than in your current
directory.
During the compilation process, INFORMIX-4GL stores a backup copy of the
file.4gl source file in file.4bl. The time stamp is modified on the (original)
file.4gl source file, but not on the backup file.4bl file. In the event of a system
crash, you may need to replace the modified file.4gl file with the backup copy
contained in the file.4bl file.
The Programmers Environment does not allow you to begin modifying a
.4gl or .per source file if the corresponding backup file already exists in the
same directory. After an editing session terminates abnormally, for example,
you must delete or rename any backup file before you can resume editing
your 4GL module or form from the Programmers Environment.
This concludes the description of the Rapid Development System. Except as
otherwise noted, the descriptions of INFORMIX-4GL elsewhere in this manual describe features that are identical in both the C Compiler Version and
Rapid Development System implementations of INFORMIX-4GL.
1-73
1-74
Chapter
INFORMIX-4GL
Programming
Chapter Overview
Language Conventions 3
Comments 3
INFORMIX-4GL Identifiers 4
Scope of Identifiers 4
Constants 5
String Constants 5
Integer Constants 5
Floating Number Constants 5
Date and Time Constants 6
Program Variables 6
Data Types 7
SMALLINT 7
INTEGER 7
DECIMAL [ (m [, n ] ) ] 7
SMALLFLOAT 8
FLOAT [ ( n ) ] 8
MONEY [ ( m [ , n ] ) ] 8
CHAR [ ( n ) ] 8
DATE 9
DATETIME 9
INTERVAL 9
LIKE table.column 9
RECORD 9
ARRAY [i, j, k] OF type 10
Data Conversion 10
21
Built-in Functions 24
ASCII 25
CLIPPED 27
COLUMN 29
CURRENT 30
DATE 32
DATE( ) 33
DAY( ) 34
EXTEND( ) 35
LENGTH( ) 38
MDY( ) 39
MONTH( ) 40
TIME 41
TODAY 42
UNITS 43
USING 44
Formatting Number Expressions 44
Formatting DATE Expressions 46
WEEKDAY( ) 53
YEAR( ) 54
C Functions
2-2
INFORMIX-4GL Programming
55
13
Chapter Overview
An INFORMIX-4GL program consists of one or more source files, each
containing a series of English-like statements that obey a well-defined syntax.
This chapter describes the syntax rules and gives an overview of those statements that do not apply directly to a database. It lists the built-in 4GL functions and describes how to write C functions that can be called by
INFORMIX-4GL programs, if you have a C compiler.
Language Conventions
The INFORMIX-4GL programming language contains identifiers, keywords,
constants, operators, and expressions. It makes no distinction between
uppercase and lowercase letters. It is completely free-form, like C or Pascal,
and ignores any extra spaces, tabs, linefeeds, and comments. When necessary, it uses the keyword END in association with the statement type to terminate a statement. Apart from this, it has no statement terminators such as the
semicolon.
Comments
For clarity and to simplify program maintenance, it is recommended that you
document your code by including comments in your 4GL source files. You
can also use comment symbols during program development to disable
statements without deleting them. You can indicate comments in any of three
ways:
A comment can begin with the left brace ( { ) and end with the right brace
( } ). You cannot use braces to nest comments.
You can also use the pound sign ( # ) to begin a comment. The comment
terminates at the end of the line.
INFORMIX-4GL Programming
2-3
INFORMIX-4GL Identifiers
You can also use a pair of hyphens or minus signs (--) to begin a comment that terminates at the end of the line. (Use of this comment indicator
conforms to the ANSI standard.)
All text between the braces (or from the # or -- indicator to the end of the
line) is ignored.
INFORMIX-4GL Identifiers
INFORMIX-4GL programs can reference constants, local, module, and global
Scope of Identifiers
Program variables can be either local, modular, or global in their scope of
reference.
Module variables must be defined before the first program block (that is,
before the MAIN statement or before any REPORT or FUNCTION statement). They can be referenced only by statements in the same module.
2-4
INFORMIX-4GL Programming
Constants
Forms, cursors, functions, reports, windows, and some 4GL statements have
identifiers that are not program variables. The scope of reference for identifiers of forms, windows, functions, and reports is the entire program. The
scope of the identifiers of cursors and PREPAREd statements is from where
you DECLARE or PREPARE them until the end of the same module.
Constants
4GL supports string, integer, floating number, and date and time constants.
INFORMIX-4GL recognizes three predefined constants: TRUE = 1, FALSE = 0,
and NOTFOUND = 100. It also permits the assignment of the value NULL to
variables and to database columns. NULL values are distinct from blank
strings or zeros for number variables and columns, and represent unknown
values. See the section NULL Values in Chapter 3 for details about the
behavior of NULL values in expressions.
String Constants
String constants are sequences of up to 80 characters enclosed within double
quotes. The constant must be written on a single line (no embedded new
lines). You can create longer string variables by concatenating string constants. To include a double quote in a string, precede the double quote with
the backslash or repeat the double quote, as in these two equivalent strings:
"Enter \"y\" to select this row"
"Enter ""y"" to select this row"
Integer Constants
You must express integer constants in decimal notation without embedded
commas and without a decimal point. You can precede the integer with a
minus or plus sign, but there can be no space, tab, or new line between the
sign and the first digit:
15
-12
13938
INFORMIX-4GL Programming
2-5
Program Variables
where type is the keyword DATETIME or INTERVAL, values are a list of calendar date values and/or time-of-day values for DATETIME, or else date or time
values for INTERVAL; and qualifier identifies the largest and smallest units
that the values describe. The following example specifies an instant in time on
March 6th, 1989, and illustrates the delimiters that separate fields within the
values:
DATETIME (89-3-6 09:55:30.825) YEAR TO FRACTION(3)
Here expression is a number expression, and field is one of the keywords YEAR,
MONTH, DAY, HOUR, MINUTE, SECOND, or FRACTION (n). (The last designates n decimal-place fractions of a second, for 1 n 5.) For example, this
means six months:
6 UNITS MONTH
Program Variables
Information transfer among a 4GL screen, report, and database occurs
through named memory locations called program variables. You must
define the data storage required by a program variable before you can
2-6
INFORMIX-4GL Programming
Data Types
Data Types
INFORMIX-4GL variables must have one of the following data types:
SMALLINT
MONEY [ (m [ , n ] ) ]
INTEGER
INT
CHAR [ ( n ) ]
CHARACTER [ (n ) ]
DECIMAL [ (m [ , n ] ) ]
DEC [ ( m [ , n ] ) ]
NUMERIC [ (m [ , n ] ) ]
DATE
SMALLFLOAT
REAL
RECORD [ LIKE table. * ]
FLOAT [ ( n ) ]
DOUBLE PRECISION [ ( n ) ]
DATETIME qualifier
INTERVAL qualifier
ARRAY [ i , j , k ] OF type
SMALLINT
This data type includes whole numbers in the range -32,767 to +32,767.
INTEGER
This data type includes whole numbers in the range -2,147,483,647 to
+2,147,483,647.
You can use the INT keyword as a synonym for INTEGER.
DECIMAL [ (m [, n ] ) ]
This data type includes decimal floating-point numbers with a total of
m ( 32) significant digits (the precision) and n ( m) digits to the right of the
decimal point (the scale). When you give values for both m and n, the decimal
variable obeys fixed-point arithmetic. All numbers with an absolute value
less than 0.5 10-n have the value zero. The largest absolute value of a
variable of type DECIMAL that can be stored without an error is 10m-n -10-n.
The second parameter is optional. If it is missing, INFORMIX-4GL treats the
variable as a floating decimal. DECIMAL(m) variables have a precision of m,
and a range in absolute value from 10-128 to 10126 When printed without formatting instructions, DECIMAL(m) variables have two decimal places to the
INFORMIX-4GL Programming
2-7
Data Types
SMALLFLOAT
This data type includes binary floating-point numbers corresponding to the
float data type of the C language.
You can use the keyword REAL as a synonym for SMALLFLOAT.
FLOAT [ ( n ) ]
This data type includes floating-point numbers corresponding to the
double C data type. Here (n), a whole number between 1 and 14, is an
optional parameter to specify the precision. INFORMIX-4GL does not use this
parameter, which is provided for compatibility with the ANSI standard.
You can use the keywords DOUBLE PRECISION as a synonym for FLOAT.
MONEY [ ( m [ , n ] ) ]
Like the DECIMAL data type, the MONEY data type can also take two parameters. The range of values for columns of type MONEY(m, n) is the same as for
columns of type DECIMAL(m, n), but variables of type MONEY are displayed
with a currency symbol (by default, the dollar sign). The type MONEY(m) is
defined as DECIMAL(m, 2) and, if no parameter is given, MONEY is taken to
be DECIMAL(16, 2). Regardless of the number of parameters, INFORMIX-4GL
always treats the data type MONEY as a fixed decimal number.
CHAR [ ( n ) ]
These are character strings of length n (where 1 n 32,767). If you use the
keyword CHAR and do not specify a length, INFORMIX-4GL interprets this to
mean CHAR(1). You can refer to substrings of CHAR type program variables
in LET, ERROR, MESSAGE, and PROMPT statements with the notation charvariable[m,n], which selects the mth through the nth components of the variable char-variable. (The square brackets are literal, not symbols to indicate an
option.)
You can use the keyword CHARACTER as a synonym for CHAR.
2-8
INFORMIX-4GL Programming
Data Types
DATE
These are dates from a DATE column or expression, or entered as a character
string in one of the formats described earlier in the DATE subsection of Date
and Time Constants. INFORMIX-4GL stores a DATE variable as an integer,
whose value is the number of days since December 31, 1899.
DATETIME
These are instants in time, including both the date and the time-of-day
specifications. A DATETIME value specifies a contiguous sequence of the
fields: YEAR, MONTH, DAY, HOUR, MINUTE, SECOND, and FRACTION (of a
second). A value is entered as a character string, in one of the formats
described earlier in the section Date and Time Constants. Values are stored
internally as decimal numbers with a scale of zero, with a precision factor
corresponding to the number of digits implied by the fields. See Appendix J,
Working with DATETIME and INTERVAL Data.
INTERVAL
This data type includes signed intervals of time, measured in one or more
of the same units as DATETIME. A value is entered as a character string in
one of the formats described earlier in the section Date and Time
Constants. INTERVAL values specify a contiguous sequence from one
of these lists of fields: YEAR and MONTH, or DAY, HOUR, MINUTE, SECOND,
and FRACTION (of a second), but you can specify a non-default precision for
a field. Internal storage is the same as for DATETIME values. See also
Appendix J, Working with DATETIME and INTERVAL Data.
LIKE table.column
You can define the data type of a variable indirectly by indicating that it
should have the same data type as a column in the database. If the column
has type SERIAL, INFORMIX-4GL assigns it the data type INTEGER but
enforces none of the other restrictions on SERIAL types. (Chapter 3 contains
the definition of the SERIAL data type.)
RECORD
This data type describes a set of variables of possibly differing data
types, including other records. You can refer to individual elements as
record_name.element_name and often to record-name.* for the entire set. (But see
The THRU Keyword and the .* Notation, later in this chapter for limitations on using record-name.*.) You can define a record by listing its elements
INFORMIX-4GL Programming
2-9
Data Conversion
and their types, or by defining it to be LIKE table.* , where table is a table in the
database. If defined LIKE table.*, the elements of the record have the same
names as the columns of table, and the same corresponding data types.
Data Conversion
INFORMIX-4GL performs data-type conversion without objection when the
process makes sense. If you assign a number expression to a CHAR variable,
INFORMIX-4GL converts the resulting number to a string. If you use a string
representation of a number or a date in an arithmetic expression, INFORMIX-4GL converts the string or date to an appropriate number. INFORMIX-4GL produces an error message only if it could not make the conversion.
stored or printed result. The following rules apply to the precision and scale
of the DECIMAL variable that results from an arithmetic operation on two
numbers:
All operands, if not already DECIMAL, are converted to DECIMAL, and the
resulting number is DECIMAL.
Convert Type
FLOAT
SMALLFLOAT
INTEGER
SMALLINT
To
DECIMAL(16)
DECIMAL(8)
DECIMAL(10,0)
DECIMAL(5,0)
INFORMIX-4GL Programming
expression. The rules are summarized in the table at the end of this section for arithmetic operations on operands with definite scale. When one
of the operands has no scale (floating decimal), the result is a floating
decimal.
If the type of the result of an arithmetic operation requires the loss of significant digits INFORMIX-4GL reports an error.
Leading or trailing zeros are not considered significant digits, and do not
contribute to the determination of precision and scale.
In this table, p1 and s1 are the precision and scale of the first operand, and p2
and s2 are the precision and scale of the second operand.
Operation
Addition and
Subtraction
Multiplication
Precision:
Scale:
Division
Precision:
Scale:
32
32 - p1 + s1 - s2 (This cannot be negative.)
Number Expressions
A number expression consists of a number constant, variable, column name, or
function that returns a number value; or one of these, connected to a number
expression by one of these arithmetic operators:
INFORMIX-4GL Programming
2-11
Operator
**
Operation
Exponentiation
*
/
mod
Multiplication
Division
Modulus
+
-
Addition
Subtraction
String Expressions
A string expression is a string constant, a CHAR type variable or column, or a
function returning a CHAR type; or any combination of these, combined or
altered by the following string operators:
Operator
,
[m,n]
CLIPPED
USING
WORDWRAP
Operation
Concatenation
Substring where m is the starting position
and n is the ending position
Drop trailing blanks
Formatting
Display long strings in multiple lines
INFORMIX-4GL Programming
Boolean Expressions
A Boolean expression evaluates to TRUE or FALSE (or UNKNOWN, if NULL values
are involved) and can take any of the following forms:
Operation
Equal to
Not equal to
Greater than
Greater than or equal to
Less than
Less than or equal to
(For string expressions, greater than means after in the ASCII collating
order, as listed in Appendix H. Lowercase letters are after uppercase
letters, which are after numerals. For DATE and DATETIME values,
greater than means later in time.)
The last four expressions apply only in WHERE clauses of SELECT statements.
(See The SELECT Statement near the end of Chapter 7 for details and for
an explanation of the ESCAPE keyword.)
Boolean expressions can be compounded with the operators NOT, AND,
and OR:
[ NOT ] Boolean-expr [ { AND | OR } Boolean-expr ]
INFORMIX-4GL Programming
2-13
Some statements permit temporary binding through the identity of the variable name and the screen field name. (See the individual statement descriptions in Chapter 7 for the appropriate syntax.) The following statement could
replace the previous INPUT statement:
INPUT BY NAME lname
2-14
INFORMIX-4GL Programming
The INITIALIZE statement above sets to NULL the values of program variables pr_rec.element4, pr_rec.element5, pr_rec.element6, pr_rec.element7,
and pr_rec.element8. The DISPLAY statement lists the entire record pr_rec on
the screen fields described by the screen record sc_rec. (Chapter 4 describes
screen records.)
With one exception, discussed at the end of this section, these devices
are a shorthand for writing out a partial or full list of record elements or the
columns of a table, with comma ( , ) separating individual items. The order
of the items in the list is the order they had when defined. There are, however,
the following limitations on their use:
In the definition of a screen record, THRU runs through all the fields in the
order that they are listed in the ATTRIBUTES section of the form specification file, from the field first named to the last. An example follows:
ATTRIBUTES
...
f002=tab1.aa;
f003=tab1.bb;
f004=tab1.cc;
f005=tab2.aa;
f006=tab2.bb;
f007=tab3.aa;
f008=tab3.bb;
f009=tab3.cc;
...
INSTRUCTIONS
SCREEN RECORD sc_rec (tab1.cc THRU tab3.bb)
INFORMIX-4GL Programming
2-15
INFORMIX-4GL Statements
The previous excerpt from a form specification file leads to the following
list of elements of sc_rec:
tab1.cc
tab2.aa
tab2.bb
tab3.aa
tab3.bb
You cannot use THRU to indicate a partial list of screen record elements
when displaying to a form or inputting from a form.
You cannot use either THRU or the .* notation on a record that contains an
array among its elements. For example, you cannot use myrec.* to refer
to all the elements of a record defined as follows:
DEFINE myrec RECORD
ri INTEGER,
ra ARRAY[2] OF INTEGER
END RECORD
You can use the .* or THRU notation, however, for records that contain
records as elements.
You cannot use THRU or the .* notation in the argument list when defining
a function or report program block. You can, however, list a record as an
argument of a function or of a report.
The exception to .* expanding to a list occurs when you use it in a 4GL
UPDATE statement. The notation
UPDATE table1 SET table1.* = pr_rec.*
but with all SERIAL columns omitted. (The SERIAL data type is described in
Chapter 3.)
INFORMIX-4GL Statements
Eight statement types in INFORMIX-4GL do not deal with the database. These
statement types are listed in the sections that follow:
2-16
INFORMIX-4GL Programming
Variable Definition
Variable Definition
You must define all program variables before you can use them.
DEFINE
Assignment
You can assign values directly to program variables with one of two
statements:
LET
INITIALIZE
Program Organization
INFORMIX-4GL programs can have three different types of program blocks:
MAIN, FUNCTION, and REPORT. Programs can also contain global declara-
tion statements.
MAIN
FUNCTION
contains a sequence of INFORMIX-4GL statements that perform a desired task and terminates with the END FUNCTION
statement. A function can return zero or more values to the
INFORMIX-4GL Programming
2-17
Program Flow
routine that called it. You can pass the values of variables to
functions as parameters.
REPORT
GLOBALS
A program must contain only one MAIN statement, and can have at most one
GLOBALS statement that includes DEFINE statements. No restrictions apply
to the number of FUNCTION or REPORT program blocks that can appear in a
program or in a module. (A module is a system file that contains one or more
program segments.) You can place all program blocks in a single module, or
put each function in a separate module, or use any combination in between.
A GLOBALS statement containing DEFINE statements must either be in
a module by itself or be the first statement (or the second if a DATABASE
statement also appears in the module) in the module containing the MAIN
program block. Any module containing routines that refer to global variables
must begin with a GLOBALS statement giving the pathname of the module
that defines the global variables. (See the GLOBALS statement in Chapter 7
for full details.)
Modules can be compiled separately and linked later, permitting you to
create a library of INFORMIX-4GL functions and to call them from different
modules. In addition, your program can call C functions. See the section C
Functions, later in this chapter, for the rules governing C functions called by
INFORMIX-4GL programs.
Program Flow
INFORMIX-4GL has many statements that control the flow of a program.
These statements are included in INFORMIX-4GL because they simplify
2-18
CALL
FOR
FOREACH
INFORMIX-4GL Programming
Screen Interaction
WHILE
CONTINUE
EXIT
IF
CASE
GOTO
LABEL
SLEEP
RUN
Screen Interaction
The next 18 statements allow the program to interact with the screen. The first
statement constructs a menu; the next five statements provide control over
clearing the screen, printing messages, retrieving user input, and setting up
default values for screen parameters, special keys, and help files. The next
three statements are window management statements. The last nine statements handle the entry and retrieval of data from screen forms.
MENU
CLEAR
ERROR
MESSAGE
PROMPT
INFORMIX-4GL Programming
2-19
Screen Interaction
OPTIONS
OPEN
WINDOW
CURRENT
WINDOW
CLOSE
WINDOW
OPEN FORM
DISPLAY
FORM
opens the compiled screen form and associates an INFORMIX-4GL identifier with the form.
displays the named form on the screen or in a window,
displacing whatever was on the screen or window below the
Form line.
CLOSE FORM
closes the file containing the named screen form and releases
its association with the INFORMIX-4GL identifier.
CONSTRUCT
DISPLAY
DISPLAY
ARRAY
INPUT
INPUT
ARRAY
2-20
INFORMIX-4GL Programming
takes user-entered data from a screen form and puts the data
into program variables. You can specify sequences of statements to be executed during the INPUT statement before or
after the cursor enters any field or after the user indicates
that entry is complete. You can also trap function or control
keys and specify an appropriate sequence of statements.
is an extension of the INPUT statement that takes data
entered by a user into a screen array and puts the information into an array of program variables. The user can scroll
through the array, insert new rows into the array, and delete
rows from the array by using function keys.
Report Generation
SCROLL
Report Generation
There are three statements in INFORMIX-4GL that control report writing.
signals INFORMIX-4GL to initialize the report. Optionally,
START
you can specify the output device in the START REPORT
REPORT
statement.
passes a row of the report variables to the report. This stateOUTPUT TO
ment is usually found within a FOREACH loop where the
REPORT
report row is the current row of a query.
handles the end of report summaries and, if necessary, secFINISH
ond passes through the data so that aggregate values can be
REPORT
calculated.
allows you to trap errors, warnings, and NOTFOUND conditions, and to instruct INFORMIX-4GL to call a function, go to
a statement, terminate the program, or ignore the problem.
In the last case (WHENEVER ERROR CONTINUE), you must
test for errors explicitly after every statement where an error
would produce difficulties in your program.
DEFER
INFORMIX-4GL Programming
2-21
Error Handling
INFORMIX-4GL sets the global variable status following the execution of
every SQL or form-related INFORMIX-4GL statement. status is zero when the
statement executes correctly, negative when there is an error, and equal to
NOTFOUND (= 100) when you attempt a FETCH outside the range of the
active list of rows, or when a SELECT statement can find no rows. (See
Chapter 3 for more information on the FETCH and SELECT statements.)
INFORMIX-4GL Programming
Data Validation
where filename is a quoted string that specifies the name of the error log file,
or a CHAR variable that evaluates to the name of the error log file. If you do
not want the error log file to reside in the current directory, you must specify
a pathname.
Another library function, errorlog("message"), appends the quoted string or
CHAR variable message to the error log. This function allows you to write
directly to the error log file.
Chapter 6 describes these and three other 4GL library functions that deal
with errors:
err_print( )
If passed the error code, prints the message on the Error line.
err_get( )
err_quit( )
If passed the error code, prints the message on the Error line,
and exits from the program.
Exception Handling
You can also trap Interrupt (usually DEL or CTRL-C) and Quit signals
(CTRL-\) that users send to your INFORMIX-4GL program. The syntax is
DEFER { INTERRUPT | QUIT }
The DEFER keyword means that a global flag (int_flag for INTERRUPT and
quit_flag for QUIT) is set to non-zero and can be checked by the program. It
is the programmers responsibility to reset the flags to zero. The default for
either an Interrupt or a Quit signal is to cause the INFORMIX-4GL program to
stop immediately.
If the user enters an Interrupt during an INPUT or INPUT ARRAY statement
and you have executed the DEFER INTERRUPT statement, the program control leaves the INPUT statement and INFORMIX-4GL sets int_flag.
You can enter the DEFER INTERRUPT statement only once in a program,
and then only in the MAIN program block. This restriction applies to the
DEFER QUIT statement as well.
Data Validation
You can ensure that data entered through a form conform to appropriate
limits or have permitted values by setting up the INCLUDE attribute in the
form specification or in the syscolval table. (See in Chapter 4 for a discussion
INFORMIX-4GL Programming
2-23
Built-in Functions
of these concepts.) If your program inserts data into the database from
sources other than a form, you can check that the data meets these same
restrictions by using the VALIDATE statement.
VALIDATE
issues an error if the value of a program variable is not consistent with limitations set for the corresponding column in
syscolval.
If the current database is not MODE ANSI, then the upscol utility creates
a single syscolval table that can specify acceptable values or ranges of values
for any or all database columns. The VALIDATE statement enforces the
limitations specified in this table.
In a MODE ANSI database, however, each user of upscol creates an individual
owner. syscolval table. When INFORMIX-4GL subsequently processes a
VALIDATE statement of the form:
VALIDATE variable-list LIKE [ owner. ] table. column
Built-in Functions
In addition to functions that you create with a FUNCTION statement and C
functions that you can call, INFORMIX-4GL provides a number of pre-defined
functions, operators, and keyword expressions. You can use the following
functions, operators, and keywords in expressions.
ASCII
CLIPPED
COLUMN
CURRENT
DATE
DATE( )
DAY( )
EXTEND( )
LENGTH( )
MDY( )
MONTH( )
TIME
TODAY
UNITS
USING
WEEKDAY( )
YEAR( )
These are described in the sections that follow. There are additional functions
that can be used only within REPORT program blocks (described in
Chapter 4) and INFORMIX-4GL library functions that cannot be used in SQL
statements (described in Chapter 6).
Note: INFORMIX-OnLine supports additional functionality. Refer to the INFORMIX-OnLine Programmers Manual for more information.
2-24
INFORMIX-4GL Programming
ASCII
ASCII
Overview
This function evaluates an integer argument as the corresponding ASCII
character.
Syntax
ASCII num-expr
Explanation
ASCII
is a required keyword.
Notes
INFORMIX-4GL evaluates this function as a single character. You can use it to
display CTRL characters.
Examples
The following DISPLAY statement rings the terminal bell (ASCII value of 7).
DEFINE bell CHAR(1)
LET bell = ASCII 7
DISPLAY bell
The next REPORT program block fragments show how to implement special
printer or terminal functions. They assume that, when the printer receives the
sequence of ASCII characters 9, 11, and 1, it will start printing in red, and
INFORMIX-4GL Programming
2-25
Examples
when it receives 9, 11, and 0, it will revert to black printing. The values used
in the example are hypothetical; refer to your printer or terminal manual for
information on your printer or terminal.
FORMAT
FIRST PAGE HEADER
LET red_on = ASCII 9, ASCII 11, ASCII 1
LET red_off = ASCII 9, ASCII 11, ASCII 0
ON EVERY ROW
...
PRINT red_on,
"Your bill is overdue.",
red_off
...
2-26
INFORMIX-4GL Programming
CLIPPED
CLIPPED
Overview
CLIPPED displays the character expression that precedes it without any
trailing blanks.
Syntax
char-expr CLIPPED
Explanation
char-expr is a required character expression.
CLIPPED
is a required keyword.
Notes
1. You normally use CLIPPED after a variable name in a LET or DISPLAY
statement, or in a PRINT section of a REPORT program block.
2. CLIPPED affects the value of a character variable when it is used as an
expression. CLIPPED does not affect the value when it is stored in a
variable (unless you are concatenating CLIPPED values together).
For example, if CHAR variable b contains a string that is shorter than the data
type of a, the following LET statement pads a with trailing blanks, despite the
CLIPPED keyword:
LET a = b CLIPPED
INFORMIX-4GL Programming
2-27
Example
Example
The following example is from a REPORT program block that prints mailing
labels.
FORMAT
ON EVERY ROW
IF (city IS NOT NULL)
AND (state IS NOT NULL) THEN
PRINT fname CLIPPED, 1 SPACE, lname
PRINT company
PRINT address1
IF (address2 IS NOT NULL) THEN
PRINT address2
END IF
PRINT city CLIPPED, ", " , state,
2 SPACES, zipcode
SKIP TO TOP OF PAGE
END IF
2-28
INFORMIX-4GL Programming
COLUMN
COLUMN
Overview
The COLUMN function returns a string of spaces long enough to begin
the next item in the designated column.
Syntax
COLUMN integer-expr
Explanation
COLUMN
is a required keyword.
integer-expr
is a required positive integer expression that specifies the initial column number of the next item to be printed.
Notes
1. In REPORT program blocks, INFORMIX-4GL calculates the column
number by adding integer-expr to the left margin that you set in the
OUTPUT section. Otherwise, the column number is counted from
the left edge of your screen.
2. If INFORMIX-4GL has already printed past the column specified by
integer-expr, INFORMIX-4GL ignores the COLUMN expression.
3. If you use the COLUMN function in a DISPLAY statement, you must
specify an integer instead of an integer expression after the COLUMN
keyword.
Example
PAGE HEADER
PRINT "NUMBER", COLUMN 12, "NAME", COLUMN 35,
"CITY", COLUMN 57, "ZIP", COLUMN 65, "PHONE"
SKIP 1 LINE
ON EVERY ROW
PRINT customer_num, COLUMN 12, fname CLIPPED,
1 SPACE, lname CLIPPED, COLUMN 35, city CLIPPED,
", ", state, COLUMN 57, zipcode, COLUMN 65, phone
INFORMIX-4GL Programming
2-29
CURRENT
CURRENT
Overview
The CURRENT function returns a DATETIME value with the date and time of
day of the current instant.
Syntax
CURRENT [ first TO last ]
Explanation
CURRENT is a required keyword.
first
TO
last
Notes
1. The value returned is the date and time (from the system clock) when
the CURRENT function executes.
2. You can use the CURRENT function in any context in which you can use a
DATETIME literal.
3. The first qualifier must specify a field that is more significant than or equal
to the last qualifier.
4. If the function is executed more than once in a statement, identical values
may be returned at each point of the call. You cannot rely on CURRENT to
provide distinct values each time that it executes in the same statement.
5. INFORMIX-4GL may not execute the CURRENT function in the physical
order in which it appears in a statement. You should not use the function
to mark the start, the end, or any specific point in the execution of the 4GL
statement.
6. If no first TO last qualifiers are specified, the default qualifiers are
YEAR TO FRACTION(3).
2-30
INFORMIX-4GL Programming
Examples
Qualified Data
A number of years.
A number of months.
A number of days.
A number of hours.
A number of minutes.
A number of seconds.
A decimal fraction of a second with n (up to 5) digits of
precision. The default precision is 3 digits (thousandths of
a second).
Examples
-- SQL statement
SELECT prog_title from tv_programs where
air_date > CURRENT YEAR TO DAY
ATTRIBUTES -- FORM4GL field
timestamp = formonly.tmstmp type DATETIME HOUR TO SECOND,
default = CURRENT HOUR TO SECOND;
PAGE HEADER -- Report control block
print column 40, CURRENT MONTH TO MONTH,
column 42, "/",
column 43, CURRENT DAY TO DAY,
column 45, "/",
column 46, CURRENT YEAR TO YEAR
Note: The last example would not produce the correct results if its execution
spanned midnight.
INFORMIX-4GL Programming
2-31
DATE
DATE
Overview
The DATE function returns a character string that has the format Wed Sep 20
1989 and whose value is the current date.
Syntax
DATE
Explanation
DATE
is a required keyword.
Note
This function reads the current date from the system clock.
Example
The following example displays the current calendar date:
DEFINE p_date CHAR(15)
LET p_date = DATE
. . .
DISPLAY "Today is ", p_date AT 5,14
2-32
INFORMIX-4GL Programming
DATE( )
DATE( )
Overview
The DATE( ) function returns a type DATE value, corresponding to the expression with which you call it.
Syntax
DATE ( expr )
Explanation
DATE
is a required keyword.
expr
Note
The expr is usually of type CHAR, DATETIME, or INTEGER.
Examples
The following example uses DATE to convert a string to a date:
WHERE end_date > DATE("12/13/1989")
This expression returns the 100th day after December 31, 1899:
DATE(100)
INFORMIX-4GL Programming
2-33
DAY( )
DAY( )
Overview
The DAY( ) function returns an integer that represents the day of the month,
when you call it with a type DATE argument.
Syntax
DAY ( dtime-expr )
Explanation
DAY
is a required keyword.
dtime-expr
Examples
The first example extracts the day of the month from a DATETIME literal
expression:
DEFINE d_var
INTEGER,
date_var DATETIME YEAR TO SECOND
LET date_var = DATETIME (89-12-09 18:47:32) YEAR TO SECOND
LET d_var = DAY(date_var)
DISPLAY "The day of the month is: ", d_var USING "##"
The next example uses the DAY ( ) function with the CURRENT function to
display the day of the month:
DEFINE dayvar CHAR(2)
LET dayvar = DAY(CURRENT)
DISPLAY "The day of the month is: ", dayvar USING "##"
2-34
INFORMIX-4GL Programming
EXTEND( )
EXTEND( )
Overview
The EXTEND function adjusts the precision of a DATETIME value.
Syntax
EXTEND ( value [ , first TO last ] )
Explanation
EXTEND
is a required keyword.
value
is a DATE or DATETIME value (column name, variable, or expression) of any valid precision.
first
TO
last
is an optional qualifier that specifies the last field in the result. (See
Note 6.)
Notes
1. The value can also be a DATETIME literal, or a character string that consists
of valid and unambiguous DATETIME values and separators. It cannot be
a string constant in DATE format.
2. If no first TO last qualifiers are specified, the default qualifiers are YEAR
TO FRACTION(3).
3. The first qualifier must specify a field that is more significant than or equal
to the last qualifier.
4. If the value contains fields not specified by the qualifiers, the unwanted
fields are discarded.
5. If the first qualifier specifies a field to the left of (that is, more significant
than) what exists in value, the new fields are filled with values returned
by the CURRENT function.
6. If the last qualifier specifies a field to the right of (that is, less significant
than) what exists in value, the new fields are filled in with constant values.
INFORMIX-4GL Programming
2-35
Examples
A missing MONTH or DAY is filled in with 1, and the missing fields HOUR
to FRACTION are filled in with 0.
7. The following qualifiers are valid:
Identifier
YEAR
MONTH
DAY
HOUR
MINUTE
SECOND
FRACTION (n)
Qualified Data
A number of years.
A number of months.
A number of days.
A number of hours.
A number of minutes.
A number of seconds.
A decimal fraction of a second with n (up to 5) digits of
precision. The default precision is 3 digits (thousandths of
a second)
Examples
In the first example, the EXTEND function returns the MONTH and DAY fields
from a column that contains YEAR, MONTH, and DAY data. In this instance,
the YEAR field is not returned.
SELECT EXTEND(air_date, MONTH TO DAY)
FROM tv_programs;
In the next example, the EXTEND function returns a YEAR from CURRENT; it
retains the MONTH, DAY, and HOUR values that are already in start_date, and
it supplies a MINUTE value of zero.
UPDATE class_sched SET start_date =
EXTEND(DATETIME(9-6 9)MONTH TO HOUR,
YEAR TO MINUTE);
INFORMIX-4GL Programming
Examples
INFORMIX-4GL Programming
2-37
LENGTH( )
LENGTH( )
Overview
This function returns the number of bytes in its string argument after deleting
all trailing spaces.
Syntax
LENGTH ( str )
Explanation
str
Notes
1. In a SELECT or UPDATE statement, with str the identifier of a character
column, this function returns the number of bytes in the CLIPPED data
value.
2. The LENGTH function must be within an SQL statement if str is a database
column.
Examples
These statements center a report title on an 80-column page:
LET title = "Invoice for ", fname CLIPPED,
" ", lname CLIPPED
LET offset = (80 - length(title))/2
PRINT COLUMN offset, title
The next statement retrieves the value in column1 and the length in bytes of
the string in column2 (excluding trailing blanks).
SELECT column1, LENGTH(column2) FROM mytable
2-38
INFORMIX-4GL Programming
MDY( )
MDY( )
Overview
The MDY( ) function returns a type DATE value when you call it with three
expressions that evaluate to integers representing the month, day of the
month, and year.
Syntax
MDY ( expr1, expr2, expr3 )
Explanation
MDY
is a required keyword.
expr1
is an expression that evaluates to an integer representing the number of the month (1-12).
expr2
is an expression that evaluates to an integer representing the number of the day of the month (1-28, 29, 30, or 31, depending on the
month).
expr3
Notes
1. Enclose the list of integer expressions expr1, expr2, and expr3 in parentheses, separated by commas.
2. The value of expr3 cannot be the abbreviation for the year. For example,
89 is a year in the first century.
INFORMIX-4GL Programming
2-39
MONTH( )
MONTH( )
Overview
The MONTH( ) function returns an integer corresponding the month portion
of its type DATE or DATETIME argument.
Syntax
MONTH ( dtime-expr )
Explanation
MONTH
is a required keyword.
dtime-expr
Notes
1. This function extracts the month from a DATE or DATETIME value, returning an integer m in the range 1 <= m <= 12.
2. The dtime-expr cannot be an INTERVAL argument.
Examples
If the program variable then contains a DATE or DATETIME value, the Boolean expression
MONTH(then) > 9
2-40
INFORMIX-4GL Programming
TIME
TIME
Overview
TIME evaluates as a character string whose value is the current time-of-day
from the system clock.
Syntax
TIME
Explanation
TIME
is a required keyword.
Note
The value of TIME is a character string, representing the current time in the
format hh:mi:ss, based on a 24-hour clock.
Example
DEFINE p_time char(15)
LET p_time = TIME
DISPLAY "The time is ", p_time
INFORMIX-4GL Programming
2-41
TODAY
TODAY
Overview
TODAY evaluates as type DATE with a value of the current date, as supplied
Syntax
TODAY
Explanation
TODAY
is a required keyword.
Example
The following example is from a REPORT program block:
SKIP 1 LINE
PRINT COLUMN 15, "FROM: ", begin_date USING "mm/dd/yy",
COLUMN 35, "TO: ", end_date USING "mm/dd/yy"
PRINT COLUMN 15, "Report run date: ",
TODAY USING "mmm dd, yyyy"
SKIP 2 LINES
PRINT COLUMN 2, "ORDER DATE", COLUMN 15, "COMPANY",
COLUMN 35, "NAME", COLUMN 57, "NUMBER",
COLUMN 65, "AMOUNT"
2-42
INFORMIX-4GL Programming
UNITS
UNITS
Overview
The UNITS keyword returns an INTERVAL value with one qualifier.
Syntax
expr UNITS qualifier
Explanation
expr
is a number expression.
UNITS
is a required keyword.
qualifier
Notes
1. The expr can be a program variable, a constant, an expression, a column
name, or a function that evaluates to a number.
2. An expression that includes the UNITS keyword can be added to or subtracted from a DATETIME or INTERVAL expression, provided that the
UNITS operand follows the arithmetic operator (either + or - ) as the second operand.
3. The qualifier can be any one of the following field keywords:
YEAR
HOUR
MONTH
MINUTE
DAY
SECOND
FRACTION ( n )
Example
LET fortnite = CURRENT + 14 UNITS DAY
INFORMIX-4GL Programming
2-43
USING
USING
Overview
The USING operator specifies a format for number, MONEY, or DATE expressions. With a number or MONEY expression, you can use USING to line up
decimal points or currency symbols, to right- or left-justify numbers, to put
negative numbers in parentheses, and to perform other formatting tasks.
USING can convert a DATE value to a variety of formats.
Syntax
expr USING "format-string"
Explanation
expr
USING
is a required keyword.
format-string
2-44
&
This character fills with zeros any positions in the display field
that would otherwise be blank.
This character does not change any blank positions in the display
field. You can use this to specify a maximum width for a field.
<
INFORMIX-4GL Programming
Explanation
Refer to the Examples section for examples of formatting number expressions. Since format strings interact with data to produce visual effects, some
readers may find that the examples are easier to follow than the descriptions
of format string characters listed previously.
INFORMIX-4GL Programming
2-45
Notes
Figure 2-1
dd
ddd
mm
mmm
yy
year as a 2-digit number in the 1900s (00-99)
yyyy
year as a 4-digit number (0001-9999)
Combinations of DATE Format Strings
Notes
1. The format-string must appear between quotation ( " ) marks.
2. Although USING is generally used as part of a DISPLAY or PRINT
statement, you can also use it with LET.
3. If you attempt to display a number that is too large for the display field,
INFORMIX-4GL fills the field with asterisks ( * ) to indicate an overflow.
Examples
The following example prints the balance field using a format string that
allows values up to $9,999,999.99 to be formatted correctly.
DISPLAY "The current balance is ",
23485.23 USING "$#,###,##&.&&"
Following is the result of executing this DISPLAY statement with the value
23,485.23:
The current balance is $
23,485.23
2-46
INFORMIX-4GL Programming
Examples
the currency symbol floats with the size of the number, so that it appears
immediately to the left of the most significant digit in the display, as shown
here:
The current balance is
$23,485.23
The following examples show valid conversions for December 25, 1989:
Format String
"mmddyy"
"ddmmyy"
"yymmdd"
"yy/mm/dd"
"yy mm dd"
"yy-mm-dd"
"mmm. dd, yyyy"
"mmm dd yyyy"
"yyyy dd mm"
"mmm dd yyyy"
"ddd, mmm. dd, yyyy"
"(ddd) mmm. dd, yyyy"
Formatted Result
122589
251289
891225
89/12/25
89 12 25
89-12-25
Dec. 25, 1989
Dec 25 1989
1989 25 12
Dec 25 1989
Mon, Dec. 25, 1989
(Mon) Dec. 25, 1989
INFORMIX-4GL Programming
2-47
Examples
The following example is from a more complex REPORT program block and
illustrates several different formats:
SKIP 1 LINE
PRINT COLUMN 15, "FROM: ", begin_date USING "mm/dd/yy",
COLUMN 35, "TO: ", end_date USING "mm/dd/yy"
PRINT COLUMN 15, "Report run date: ",
TODAY USING "mmm dd, yyyy"
skip 2 lines
PRINT COLUMN 2, "ORDER DATE", COLUMN 15, "COMPANY",
COLUMN 35, "NAME", COLUMN 57, "NUMBER",
COLUMN 65, "AMOUNT"
BEFORE GROUP OF days
SKIP 2 LINES
AFTER GROUP OF number
PRINT COLUMN 2, order_date, COLUMN 15, company CLIPPED,
COLUMN 35, fname CLIPPED, 1 SPACE, lname CLIPPED,
COLUMN 55, number USING "####",
COLUMN 60, GROUP SUM (total_price)
USING "$$,$$$,$$$.&&"
AFTER GROUP OF days
SKIP 1 LINE
PRINT COLUMN 21, "Total amount ordered for the day: ",
GROUP SUM (total_price) USING "$$$$,$$$,$$$.&&"
SKIP 1 LINE
PRINT COLUMN 15,
"====================================================="
ON LAST ROW
SKIP 1 LINE
PRINT COLUMN 15,
"======================================================"
SKIP 2 LINES
PRINT "Total Amount of orders: ", SUM (total_price)
USING "$$$$,$$$,$$$.&&"
PAGE TRAILER
PRINT COLUMN 28, PAGENO USING "page <<<<"
The displays on the next three pages illustrate the full power of the USING
operator.
2-48
INFORMIX-4GL Programming
Examples
Format String
Data Value
Formatted Result
"#####"
"&&&&&"
"$$$$$"
"*****"
"<<<<<"
0
0
0
0
0
bbbbb
00000
bbbb$
*****
bbbbb
(null string)
"<<<,<<<"
"<<<,<<<"
"<<<,<<<"
"<<<,<<<"
12345
1234
123
12
12,345
1,234
123
12
"##,###"
"##,###"
"##,###"
"##,###"
"##,###"
"##,###"
"##,###"
12345
1234
123
12
1
-1
0
12,345
b1,234
bbb123
bbbb12
bbbbb1
bbbbb1
bbbbbb
"&&,&&&"
"&&,&&&"
"&&,&&&"
"&&,&&&"
"&&,&&&"
"&&,&&&"
12345
1234
123
12
1
0
12,345
01,234
000123
000012
000001
000000
"$$,$$$"
12345
******
(overflow)
"$$,$$$"
"$$,$$$"
"$$,$$$"
"$$,$$$"
"$$,$$$"
1234
123
12
1
0
$1,234
bb$123
bbb$12
bbbb$1
bbbbb$
"**,***"
"**,***"
"**,***"
"**,***"
"**,***"
"**,***"
12345
1234
123
12
1
0
12,345
*1,234
***123
****12
*****1
******
INFORMIX-4GL Programming
2-49
Examples
Format String
Data Value
Formatted Result
"##,###.##"
"##,###.##"
"##,###.##"
"##,###.##"
"##,###.##"
"##,###.##"
"##,###.##"
"##,###.##"
"##,###.##"
12345.67
1234.56
123.45
12.34
1.23
0.12
0.01
-0.01
-1
12,345.67
b1,234.56
bbb123.45
bbbb12.34
bbbbb1.23
bbbbb0.12
bbbbbb.01
bbbbbb.01
bbbbb1.00
"&&,&&&.&&"
"&&,&&&.&&"
"&&,&&&.&&"
"&&,&&&.&&"
12345.67
1234.56
123.45
0.01
12,345.67
01,234.56
000123.45
000000.01
"$$,$$$.$$"
12345.67
"$$,$$$.$$"
"$$,$$$.##"
"$$,$$$.##"
"$$,$$$.&&"
"$$,$$$.&&"
1234.56
0.00
1234.00
0.00
1234.00
*********
(overflow)
$1,234.56
$.00
$1,234.00
$.00
$1,234.00
"-##,###.##"
"-##,###.##"
"-##,###.##"
"--#,###.##"
"---,###.##"
"---,-##.##"
"---,--#.##"
-12345.67
-123.45
-12.34
-12.34
-12.34
-12.34
-1.00
-12,345.67
-bbb123.45
-bbbb12.34
-bbb12.34
-bb12.34
-12.34
-1.00
"-##,###.##"
"-##,###.##"
"-##,###.##"
"-##,###.##"
"--#,###.##"
"---,###.##"
"---,-##.##"
"---,---.##"
"---,---.--"
12345.67
1234.56
123.45
12.34
12.34
12.34
12.34
1.00
-.01
12,345.67
1,234.56
123.45
12.34
12.34
12.34
12.34
1.00
-.01
2-50
INFORMIX-4GL Programming
Examples
Format String
Data Value
Formatted Result
"----,---.&&"
"-$$$,$$$.&&"
"-$$$,$$$.&&"
"-$$$,$$$.&&"
"--$$,$$$.&&"
"--$$,$$$.&&"
"--$$,$$$.&&"
"--$$,$$$.&&"
"--$$,$$$.&&"
-.01
-12345.67
-1234.56
-123.45
-12345.67
-1234.56
-123.45
-12.34
-1.23
-.01
-$12,345.67
-b$1,234.56
-bbb$123.45
-$12,345.67
-$1,234.56
-bb$123.45
-bbb$12.34
-bbbb$1.23
"----,--$.&&"
"----,--$.&&"
"----,--$.&&"
"----,--$.&&"
"----,--$.&&"
"----,--$.&&"
-12345.67
-1234.56
-123.45
-12.34
-1.23
-.12
-$12,345.67
-$1,234.56
-$123.45
-$12.34
-$1.23
-$.12
"$***,***.&&"
"$***,***.&&"
"$***,***.&&"
"$***,***.&&"
"$***,***.&&"
"$***,***.&&"
12345.67
1234.56
123.45
12.34
1.23
.12
$*12,345.67
$**1,234.56
$****123.45
$*****12.34
$******1.23
$*******.12
"($$$,$$$.&&)"
"($$$,$$$.&&)"
"($$$,$$$.&&)"
"(($$,$$$.&&)"
"(($$,$$$.&&)"
"(($$,$$$.&&)"
"(($$,$$$.&&)"
"(($$,$$$.&&)"
-12345.67
-1234.56
-123.45
-12345.67
-1234.56
-123.45
-12.34
-1.23
($12,345.67)
(b$1,234.56)
(bbb$123.45)
($12,345.67)
($1,234.56)
(bb$123.45)
(bbb$12.34)
(bbbb$1.23)
"((((,(($.&&)"
"((((,(($.&&)"
"((((,(($.&&)"
"((((,(($.&&)"
"((((,(($.&&)"
"((((,(($.&&)"
-12345.67
-1234.56
-123.45
-12.34
-1.23
-.12
($12,345.67)
($1,234.56)
($123.45)
($12.34)
($1.23)
($.12)
INFORMIX-4GL Programming
2-51
Examples
Format String
Data Value
Formatted Result
"($$$,$$$.&&)"
"($$$,$$$.&&)"
"($$$,$$$.&&)"
"(($$,$$$.&&)"
"(($$,$$$.&&)"
"(($$,$$$.&&)"
"(($$,$$$.&&)"
"(($$,$$$.&&)"
12345.67
1234.56
123.45
12345.67
1234.56
123.45
12.34
1.23
$12,345.67
$1,234.56
$123.45
$12,345.67
$1,234.56
$123.45
$12.34
$1.23
"((((,(($.&&)"
"((((,(($.&&)"
"((((,(($.&&)"
"((((,(($.&&)"
"((((,(($.&&)"
"((((,(($.&&)"
12345.67
1234.56
123.45
12.34
1.23
.12
$12,345.67
$1,234.56
$123.45
$12.34
$1.23
$.12
2-52
INFORMIX-4GL Programming
WEEKDAY( )
WEEKDAY( )
Overview
The WEEKDAY( ) function returns an integer that represents the day of the
week, when you call it with a type DATE or DATETIME expression.
Syntax
WEEKDAY ( dtime-expr )
Explanation
WEEKDAY
is a required keyword.
dtime-expr
Notes
1. WEEKDAY returns an integer in the range 0-6. Zero represents Sunday,
1 represents Monday, and so on.
2. The dtime-expr cannot be a type INTERVAL argument.
Example
LET tag = WEEKDAY(p_orders.order_date)
INFORMIX-4GL Programming
2-53
YEAR( )
YEAR( )
Overview
The YEAR( ) function returns an integer that represents the year (four digits
for 1989) when you call it with a type DATE or DATETIME expression.
Syntax
YEAR ( dtime-expr )
Explanation
YEAR
is a required keyword.
dtime-expr
Note
The dtime-expr cannot be an INTERVAL argument.
Example
LET y_var = YEAR(TODAY)
2-54
INFORMIX-4GL Programming
C Functions
C Functions
INFORMIX-4GL programs can call C language functions. To provide a transparent function-calling mechanism, INFORMIX-4GL requires that C functions
follow a calling convention that allows data to be passed between the INFORMIX-4GL program and the C function.
This calling convention that is described in this section applies to both the
C Compiler Version and Rapid Development System implementations of
INFORMIX-4GL. If you have the Rapid Development System, see also the
sectionRDS Programs That Call C Functions in Chapter 1, which describes
the additional procedures that are required to compile and run such
programs.
The convention uses a stack, which is a data structure that can be accessed in
a predefined way by both INFORMIX-4GL programs and C functions. You
can perform two classes of operations on a stack:
push
pop
The stack acts as a LIFO (last-in, first-out) queue. The variable added to the
stack by the last push is the next variable to be removed from the stack if you
do a pop. The next page lists functions that are provided with INFORMIX-4GL
to perform pushes and pops on specific data types.
Consider the following INFORMIX-4GL statement:
CALL myfunc (a,b,c)
Part of the calling convention is that function arguments are pushed from left
to right onto the stack. INFORMIX-4GL automatically pushes the variables a,
b, and c onto the stack, in that order. Another part of the calling convention
requires INFORMIX-4GL to automatically pass the number of calling parameters as the only real argument to the C function. This tells the C function how
many values to pop.
The C functions designed to work with INFORMIX-4GL must obey the calling
convention by complementing the actions of INFORMIX-4GL. All compatible
C functions have only one argument, which is the number of parameters that
INFORMIX-4GL placed on the stack. You use this argument to pop the calling
parameters. INFORMIX-4GL supplies the following library of functions to
assist this process.
INFORMIX-4GL Programming
2-55
C Functions
Popping Functions
popint(&i)
popshort(&s)
poplong(&l)
popflo(&f)
popdub(&d)
popquote(str, len)
Pushing Functions
retint(i)
retshort(s)
retlong(l)
retflo(&f)
retdub(&d)
retquote(str)
popdec(&dm)
popdtime(&dt, qual)
retdec(&dm)
retdtime(&dt)
popinv(&inv, qual)
retinv(&inv)
Argument Types
int
i;
short
s;
long
l;
float
f;
double
d;
char
*str;
int
len;
dec_t
dm;
dtime_t
dt;
int
qual;
intrvl_t
inv;
int
qual;
2-56
INFORMIX-4GL Programming
Examples
When using the C library functions, you must be aware of the following
factors:
If you use the retquote(str) function, you must null-terminate the string.
The string str in popquote will be null-terminated, so you should allow
for that in the value of m.
Examples
The first example (which only schematically represents actual C code) shows
the basic structure for C functions that you can call from an INFORMIX-4GL
program.
myfunc(n)
int n;
{
/* n specifies how many 4gl parameters
*
were passed by the calling 4gl statement
*/
test that the value of n is correct
pop n 4gl parameters in reverse order,
right to left
... code
push x returning 4gl parameters, left to right
return(x)
/* must return the number x, specifying how many 4gl
*
variables are "RETURNING"
*/
INFORMIX-4GL Programming
2-57
Examples
#
#
#
END MAIN
The function sndmsg checks that the correct number of arguments are
passed. INFORMIX-4GL cannot guarantee recovery of the stack if a function
is called with the wrong number of arguments, since that is a failure to follow
the calling convention between INFORMIX-4GL and C functions. The
sndmsg function terminates the program if the wrong number of arguments
is passed.
2-58
INFORMIX-4GL Programming
Examples
msg_number, retcode */
{
char
int
int
input[80];
msg_number;
len, retcode;
*/
popquote(input,len);
/* Finished with function calling convention */
/* Start function processing
*/
msg_number =-1;
retcode = cvtebcd (&input, len);
/* user-written function */
if (retcode != 0)
msg_number = sndrmt (input,len); /* user-written function */
/* Finished processing */
/* Return (push) leftmost argument */
retint(msg_number);
/* Return next argument */
retint(retcode);
/* Finished returning arguments */
/* Return from function giving number of arguments */
return(2);
}
To return values to the program, the C function uses appropriate push functions for the data type and pushes return arguments onto the stack from left
to right. The last statement executed by the function returns the number of
INFORMIX-4GL Programming
2-59
Examples
2-60
INFORMIX-4GL Programming
Chapter
Using SQL
Chapter Overview
Relational Databases
SQL Identifiers 6
Owner Naming
Database Data Types
5
7
8
10
11
Data Manipulation
12
Cursor Management 13
SELECT Cursors 13
Associating a Cursor with a SELECT Statement
Retrieving and Processing Rows 15
The SCROLL Cursor 20
The Cursor WITH HOLD 23
INSERT Cursors 25
Dynamic Management 28
Preparing Statements 29
Statements That Require No Input 30
Statements That Require Input for Values 30
Statements That Require Input
for SQL Identifiers 32
Executing PREPAREd Statements 33
The EXECUTE Statement 33
Running PREPAREd SELECT Statements 35
Running PREPAREd INSERT Statements 37
Preparing Multiple SQL Statements 38
The FREE Statement 39
14
Data Access
40
41
Data Integrity 42
Transactions 42
Databases Without Transactions 43
Databases with Implicit Transactions 43
Databases with Explicit Transactions 44
Using Transactions 44
Transaction Log File Maintenance 45
Audit Trails 45
Creating an Audit Trail 46
Recovering a Table 46
Comparison of Transactions and Audit Trails 47
Locking 47
Row-Level Locking 48
Row-Level Locking in Transactions
Table-Level Locking 49
Wait for Locked Row 50
49
Indexing Strategy 50
Query Optimizer 52
Auto-Indexing 52
Clustered Indexes 52
NULL Values 53
Default Values 54
The NULL in Expressions 54
The NULL in Boolean Expressions 55
The NULL in WHERE Clauses 55
The NULL in ORDER BY Clauses 56
The NULL in GROUP BY Clauses 56
The NULL Keyword in INSERT and UPDATE Statements
Views 57
Creating and Deleting Views 58
Querying Through Views 58
Modifying Through Views 59
Privileges with Views 60
Data Constraints Using Views 60
3-2
Using SQL
57
Outer Joins
61
62
63
65
Using SQL
3-3
3-4
Using SQL
Chapter Overview
Informix Software, Inc. has developed an implementation of SQL that
extends the Structured Query Language (SQL) developed by IBM. The Informix Software additions to the language permit you to change databases, to
change the names of tables and columns, and to increase the functionality of
ANSI standard SQL statements.
In the family of Informix Software database products, SQL plays several roles.
In INFORMIX-SQL, SQL is both the interactive query language and the language you use to choose the data for ACE, the INFORMIX-SQL report-writing
program. You can read about these uses of SQL in the INFORMIX-SQL User
Manual. In INFORMIX-ESQL/C, SQL is the database query language that you
embed in C programs to create an application. In INFORMIX-4GL, SQL statements are combined with those described in Chapter 2 to form an almost
seamless fourth-generation language.
This chapter describes SQL and gives an overview of its statements. The full
syntax and rules governing SQL statements are located in Chapter 7 of the
INFORMIX-4GL Reference Manual.
Relational Databases
SQL statements create and manipulate relational databases. A relational
Using SQL
3-5
SQL Identifiers
You have the option of specifying a MODE ANSI database. A database created
or started as MODE ANSI supports implicit transactions and enforces ownernaming. (See the section Data Integrity for more information about transactions in a MODE ANSI database. See the section Owner Naming for more
information about owner-naming.)
INFORMIX-4GL provides several ways to check for Informix extensions to the
ANSI standard for SQL syntax in your programs:
If you use the -ansi flag in the command line that invokes the 4GL
compiler, you receive a compile-time warning, in the form of messages
to a diagnostic file, if the program includes Informix extensions to the
ANSI standard for SQL syntax.
SQL Identifiers
An SQL identifier is the name of an object. It can consist of letters, numbers,
and underscores ( _ ). The first character must be a letter. Unless otherwise
indicated, an identifier can have from one to 18 characters.
Database
Table
Column
Using SQL
Owner Naming
Owner Naming
In a database created as MODE ANSI, the name of each object (table, view,
index, synonym, and constraint) is qualified by the name of the owner of
the object. The combined owner.object must be unique within the database.
The following rules apply to the naming of an object:
owner is the login name of the owner of the object. The name must begin
with a letter. It can contain underscores, letters, and numbers, and can be
up to 8 characters long. Alternatively, the name can be a quoted string.
This allows you to preserve uppercase characters in user names or to
include a user name in which the first character is a digit. The quoted
string can be up to 8 characters long.
An object receives its owner when it is CREATEd. You cannot change the ownership of an object.
By default, ownership is assigned to the individual who creates the object.
However, a user with database administrator (DBA) privilege can create an
object and assign ownership of the object to another user.
In a database created as MODE ANSI, you must specify owner when referring
to an object created by another user. As with non-MODE ANSI databases, you
may specify owner when referring to your own objects.
In the following example, the UPDATE statement modifies rows in the stock
table owned by the user james:
UPDATE james.stock
SET price = price * 1.05
Using SQL
3-7
Quoted strings allow you to retain case sensitivity when case is important. In
the following examples, the SELECT statements retrieve rows from different
tables:
SELECT * FROM "Smith".stock
SELECT * FROM Smith.stock
Note that "Smith" is in quotes in the first SELECT statement but not in the second. Because of the quotes, the case distinction is preserved in the first
SELECT; therefore, the first SELECT retrieves rows from the Smith.stock table
while the second SELECT retrieves rows from the smith.stock table.
The engine assumes an object is owned by the user if you do not include the
owner prefix. As the owner of the system catalog tables is informix, you must
include the owner name informix when querying each system catalog.
You do not have to supply owner names when working with a non-MODE
ANSI database. However, if you specify the owner along with the object
name, the engine will check for the accuracy of the owner name.
Note: In a MODE ANSI database, you receive an error if you do not use the
owner.object naming convention to refer to an object owned by another user. If you
start a database as MODE ANSI, you must modify existing queries that reference a
table, view, or synonym owned by another user to include the owner prefix.
3-8
Using SQL
CHAR [(n)]
CHARACTER
SMALLINT
INTEGER
INT
DECIMAL [(m[,n])]
value less than 0.5 10-n have the value zero. The
largest absolute value of a DECIMAL variable that can
be stored without an error is 10m-n - 10-n.
The second parameter is optional and, if missing, the
variable is treated as a floating decimal. DECIMAL(m)
variables have a precision of and a range in absolute
value from 10-128 to 10126 If no parameters are designated, DECIMAL is treated as DECIMAL(16), a floating
decimal.
DEC
NUMERIC
SMALLFLOAT
REAL
FLOAT [(n)]
DOUBLE PRECISION
SERIAL [ (n) ]
is a date entered as a character string in one of the formats described in Chapter 2, and stored as an integer
number of days since December 31, 1899.
Using SQL
3-9
DATETIME
first TO last
INTERVAL
first TO last
Note: INFORMIX-OnLine supports additional data types. Refer to the INFORMIX-OnLine Programmers Manual for more information.
3-10
Using SQL
Data definition
Data manipulation
Cursor management
Dynamic management
Data access
Data integrity
Data Definition
Data Definition
Data definition statements include those that create and drop a database
and its tables, views, and indexes, modify tables, indexes, and columns,
or rename tables and columns. Of this list, only the DATABASE statement
is required before manipulating the data of an existing database or defining
program variables LIKE columns in the database.
creates a database directory, sets up the system catalogs, and
CREATE
makes the new database the current database. There can be no
DATABASE
more than one current database at any time.
DATABASE
CLOSE
DATABASE
DROP
DATABASE
CREATE
TABLE
ALTER
TABLE
RENAME
TABLE
DROP
TABLE
CREATE
VIEW
DROP
VIEW
CREATE
SYNONYM
START DATABASE
deletes all tables, indexes, and system catalogs. If no other
files are present in the database subdirectory, the subdirectory is also deleted.
creates a table and defines the columns and their data types.
adds or drops columns and constraints from a table, and
modifies data types of existing columns.
changes the name of a table, replacing the old name with the
new name in the system catalogs.
deletes all data and indexes for a table and erases its entry in
the system catalogs.
defines a table selected from rows and columns of existing
tables and views. As the underlying tables change, so does
the view built on them. See the section Views later in this
chapter for more information about views.
deletes the definition of the view from the system catalogs,
along with any views defined in terms of the one that is
dropped. The underlying tables are unaffected.
defines an alternative name for a table or a view. For INFORMIX-4GL programs, the creator of the synonym is the user
who runs the program that creates the synonym.
Using SQL
3-11
Data Manipulation
DROP
SYNONYM
RENAME
COLUMN
CREATE
INDEX
ALTER
INDEX
DROP
INDEX
UPDATE
STATISTICS
Data Manipulation
The data manipulation statements are the most frequently used SQL
statements:
DELETE
INSERT
LOAD
SELECT
UNLOAD
UPDATE
SELECT is the most important and the most complex SQL statement.
3-12
Using SQL
Cursor Management
This statement queries the customer table and returns the single row for
which the customer number is 101. From that row, it selects and places the
values in the columns corresponding to the last name and company name of
the contact in the program variables p_lname and p_company.
SELECT @quantity, @total_price
INTO quantity, total_price
FROM items
WHERE order_num = 1001
This example shows another SELECT statement that returns a single row. In
this example, the program variables quantity and total_price have the same
identifier as the corresponding columns in the items table. There is no conflict
here, since the prefix @ distinguishes the column name from the program
variable.
A SELECT statement that returns a single row is called a singleton SELECT
statement and can stand alone. The section Cursor Management that
follows describes how to handle SELECT statements that return more than
one row.
Cursor Management
INFORMIX-4GL provides two functional types of cursors:
A SELECT cursor, which you must use to handle a SELECT statement that
returns more than one row.
An INSERT cursor, which you can use to insert rows into the database as
a block.
The section SELECT Cursors describes how to associate a cursor with a
SELECT statement and gives examples of the uses of the SELECT cursor. The
section INSERT Cursors explains how to associate a cursor with an INSERT
statement and describes the advantages of using an INSERT cursor.
SELECT Cursors
When a SELECT statement returns exactly one row, the values returned to the
program variables are unambiguous. However, when more than one row can
be returned, it is necessary to have a device to distinguish one row from
another. This device is called a cursor.
Using SQL
3-13
SELECT Cursors
The set of rows returned by a SELECT statement is called the active set for the
statement. Within an INFORMIX-4GL program, you can work with only one
row of the active set at a time. This row is called the current row, and it is referenced by a cursor.
A cursor can be in one of two states: open or closed. When a SELECT cursor
is in an open state, it is associated with an active set and can point to the
current row, between two rows, before the first row, or after the last row.
When it is in a closed state, the cursor is no longer associated with an active
set, although it remains associated with the SELECT statement.
The following sections describe how to use the cursor management
statements to process rows returned by a SELECT statement. (For complete
information on the syntax of each statement, see Chapter 7.)
The SCROLL cursor allows rows to be retrieved from the active set in random order.
A regular or SCROLL cursor can be specified as WITH HOLD. Unlike regular or SCROLL cursors that are not WITH HOLD, a cursor DECLAREd as
WITH HOLD is not closed at the end of a transaction.
For example, the following DECLARE statement associates a SCROLL cursor
named q_curs with a SELECT statement that retrieves all the rows from the
customer table:
DECLARE q_curs SCROLL CURSOR FOR
SELECT * FROM customer
3-14
Using SQL
SELECT Cursors
A cursor name has meaning only from the point at which it is DECLAREd
to the end of the source-code file. The DECLARE statement for a cursor must
physically appear before any statement that refers to it. For example, the
following program will not compile because the DECLARE statement for
q_curs appears after the FOREACH statement that refers to it. (See the
following section, Retrieving and Processing Rows for more information
about FOREACH.
DATABASE stores
MAIN
DEFINE p_customer RECORD LIKE customer.*
OPEN FORM custform FROM "customer"
DISPLAY FORM custform
CALL get_curs() -- INCORRECT
FOREACH q_curs INTO p_customer.*
DISPLAY BY NAME p_customer.*
. . .
END FOREACH
END MAIN
FUNCTION get_curs()
DECLARE q_curs CURSOR FOR
SELECT * FROM customer
END FUNCTION
Using SQL
3-15
SELECT Cursors
Retrieves the next row from the active set and stores it in the p_customer
record
3-16
Using SQL
OPEN
puts the cursor in an open state with regard to the SELECT statement. The OPEN statement causes the SELECT statement to run
with the current program variables and leaves the cursor pointing
just before the first row of the resulting active set. While the cursor
is in an open state, subsequent changes to any program variables
that appear in the SELECT statement associated with the cursor do
not affect the active set.
FETCH
advances the cursor to the specified row (either FIRST, LAST, NEXT,
PRIOR or PREVIOUS, ABSOLUTE n, or RELATIVE m) and retrieves
SELECT Cursors
the values from that row. If a FETCH statement moves the cursor
before the first row or after the last row, the error variable status
has the value NOTFOUND (= 100), as does the SQLCODE component of the SQLCA record. (See the section SQLCA Record later
in this chapter for more information.) NOTFOUND indicates that
either end of the active list has been reached.
CLOSE
puts the cursor in a closed state and releases the active set. No
statements referring to the cursor, other than OPEN, are operative.
This statement names a cursor x and associates it with the SELECT statement
that follows the FOR keyword. The SELECT statement returns the order number and order date for those unpaid orders whose shipping date was later
than the date in the program variable p_date. The statement also enables a
future UPDATE statement to modify the paid_date column. The DECLARE
statement does not perform the query; it simply assigns the cursor to the
SELECT statement.
OPEN x
When you execute the OPEN statement later in your program, the Boolean
expression in the WHERE clause of the SELECT statement uses the value of the
variable p_date at the time of the OPEN statement.
FETCH x INTO order_num, order_date
The FETCH statement retrieves the rows of the active set, moves x to point to
the first row, and assigns to the program variables order_num and
order_date the values of the columns order_num and order_date in the
first row:
UPDATE orders
SET paid_date = TODAY
WHERE CURRENT OF x
The UPDATE statement substitutes the current date (returned by the TODAY
function) for the existing NULL value of paid_date in the current row (that is,
the first row) of the active set. The cursor remains pointing to the first row:
CLOSE x
Using SQL
3-17
SELECT Cursors
The cursor x is now put into a closed state, and the active set is effectively dissolved. An immediate FETCH statement would be an error because a cursor
in a closed state cannot point to anything. If, at a later time, you should execute the statement
OPEN x
the cursor x would be put back into an open state with a new active set that
depends on the value of the program variable p_date when the OPEN statement was executed.
cust_rec
3-18
Using SQL
SELECT Cursors
The cursor remains between rows after a DELETE WHERE CURRENT OF statement is executed. This means that you cannot refer to the cursor in another
DELETE or UPDATE statement until you use a FETCH statement to advance
the cursor to the next row.
You can update the current row if you include a FOR UPDATE clause in the
DECLARE statement for a non-SCROLLing cursor, and a WHERE CURRENT OF
clause in a subsequent UPDATE statement. The following example allows the
user to update the address information in the current row:
DECLARE q_curs CURSOR FOR
SELECT * FROM customer
FOR UPDATE
If you specify one or more columns in the FOR UPDATE clause of the
DECLARE statement, you can only update those columns in a subsequent
UPDATE WHERE CURRENT OF statement. If you do not list columns in a
FOR UPDATE OF column-list clause, you can update any column retrieved
in the query.
Using SQL
3-19
SELECT Cursors
The following example allows the user to update the fname and lname
columns of the current row:
BEGIN WORK
DECLARE q_curs CURSOR FOR
SELECT * FROM customer
FOR UPDATE OF fname, lname
FOREACH q_curs INTO cust_rec
IF status <> 0)
EXIT FOREACH
-- Display customer values here.
. . .
PROMPT "Do you want to change the name (y/n) ? "
FOR answer
IF answer= "y"
-- Input the new customer values here.
. . .
UPDATE customer
SET fname = cust_rec.fname,
lname = cust_rec.lname
WHERE CURRENT OF q_curs
END IF
END FOREACH
The position of the cursor does not change after an UPDATE WHERE
CURRENT OF statement is executed.
If your database has a transaction log but is not MODE ANSI, you must issue
a BEGIN WORK statement before you OPEN a cursor DECLAREd FOR UPDATE
that is not WITH HOLD. This requirement does not apply to cursors
DECLAREd WITH HOLD, or to cursors that are not FOR UPDATE. In a
MODE ANSI database, this distinction disappears because INFORMIX-4GL
automatically includes all statements within transactions. You must not
use the BEGIN WORK statement in the previous example with a MODE ANSI
database. (The section Data Integrity later in this chapter describes
transactions.)
Using SQL
SELECT Cursors
When you initially FETCH a row with a SCROLL cursor, all the rows in the
active set up to and including the FETCHed row are placed in a temporary file
and remain there until you close the cursor. If you then FETCH the same row
or any row prior to it, INFORMIX-4GL retrieves the row from the temporary
file instead of from the database.
The temporary file allows you to retrieve rows in a random order. It also
means, however, that subsequent changes to the database may not be
reflected in the active set used by a SCROLL cursor. Thus, you cannot
DECLARE a SCROLL cursor FOR UPDATE. Instead, you must DECLARE FOR
UPDATE a regular cursor or a cursor WITH HOLD when you plan to perform
a subsequent UPDATE WHERE CURRENT OF or DELETE WHERE CURRENT OF
action.
The following example shows how to use a SCROLL cursor and various
cursor management statements to retrieve and display rows in the customer
table.
MAIN
. . .
DECLARE q_curs SCROLL CURSOR FOR
SELECT * FROM customer
WHERE lname MATCHES last_name
OPEN q_curs
FETCH FIRST q_curs INTO p_customer.*
IF status = NOTFOUND THEN
CALL mess("No customers found.")
ELSE
DISPLAY BY NAME p_customer.*
CALL viewcust()
END IF
CLOSE q_curs
. . .
END MAIN
The OPEN statement runs the SELECT statement with the current value of
last_name and leaves the cursor pointing just before the first row of the
active set.
The FETCH FIRST statement attempts to retrieve the first row of the
active set.
Using SQL
3-21
SELECT Cursors
The CLOSE statement releases the active set after all rows have been
processed.
The viewcust function displays a menu that lets the user view the rows
in the active set:
FUNCTION viewcust()
MENU "BROWSE:"
COMMAND "Next" "View the next customer in the list"
FETCH NEXT q_curs INTO p_customer.*
IF status = NOTFOUND THEN
CALL mess("No more customers in this direction.")
FETCH LAST q_curs INTO p_customer.*
END IF
DISPLAY BY NAME p_customer.*
COMMAND "Previous" "View the previous customer in the list"
FETCH PREVIOUS q_curs INTO p_customer.*
IF status = NOTFOUND THEN
CALL mess("No more customers in this direction.")
FETCH FIRST q_curs INTO p_customer.*
END IF
DISPLAY BY NAME p_customer.*
COMMAND "First" "View the first customer in the list"
FETCH FIRST q_curs INTO p_customer.*
DISPLAY BY NAME p_customer.*
COMMAND "Last" "View the last customer in the list"
FETCH LAST q_curs INTO p_customer.*
DISPLAY BY NAME p_customer.*
COMMAND "Exit" "Leave the menu"
EXIT MENU
END MENU
END FUNCTION
Using SQL
SELECT Cursors
sor to the first row, and displays a message if the value of the status variable indicates that the cursor has moved beyond the first
row of the active set. The DISPLAY BY NAME statement displays
on the screen the row retrieved by the appropriate FETCH
statement.
First
includes a FETCH FIRST statement that retrieves the first row in the
active set and displays it on the screen.
Last
includes a FETCH LAST statement that retrieves the last row in the
active set and displays it on the screen.
Exit
All FETCH statements except the default FETCH NEXT statement require that
you first DECLARE a SCROLL cursor. The default FETCH statement works
with all cursors.
Note: When you open a cursor that identifies a SELECT statement containing a program variable, INFORMIX-4GL runs the SELECT statement with the current value
of the program variable. In the following example, the active set produced by the first
OPEN statement differs from the active set produced by the second OPEN statement
because the value of last_name changes from Baxter to Grant:
LET last_name = "Baxter"
DECLARE q_curs SCROLL CURSOR FOR
SELECT * FROM customer
WHERE lname MATCHES last_name
OPEN q_curs
. . .
CLOSE q_curs
LET last_name = "Grant"
OPEN q_curs
Using SQL
3-23
SELECT Cursors
The following example outlines a typical program structure that uses a cursor WITH HOLD.
LET sel1 = "SELECT order_date FROM orders WHERE customer_num = ? FOR UPDATE"
PREPARE st1 from sel1
DECLARE c_master CURSOR WITH HOLD FOR
SELECT customer_num FROM customer WHERE city = "Redwood City"
DECLARE c_detail CURSOR FOR st1
OPEN c_master
WHILE TRUE
FETCH c_master INTO p_custnum
IF status = NOTFOUND
THEN EXIT WHILE
END IF
BEGIN WORK
OPEN c_detail USING p_custnum
WHILE true
FETCH c_detail INTO p_orddate
IF status = NOTFOUND
THEN EXIT WHILE
END IF
UPDATE orders SET order_date = "02/02/90"
WHERE CURRENT OF c_detail
END WHILE
COMMIT WORK
END WHILE
CLOSE c_master
In this program, the cursor WITH HOLD provides the following advantages:
You can open the c_master cursor outside a transaction. The BEGIN WORK
statement appears after you OPEN the c_master cursor and perform a
FETCH.
The COMMIT WORK at the end of each iteration of the first WHILE loop
does not close the c_master cursor. The cursor remains open to FETCH the
next master row after the COMMIT WORK has closed the c_detail cursor
and released all locks. The updated rows are now available to other users
on the system.
If you do not use a cursor WITH HOLD, you must place the BEGIN WORK and
COMMIT WORK statements completely outside the first WHILE loop. You
would open both the c_master and c_detail cursors, FETCH all master rows,
and FETCH and UPDATE all detail rows within the single transaction. This
approach has the following drawback: it holds all locks for the duration of the
entire loop. If your program updates a large number of rows, you can
3-24
Using SQL
INSERT Cursors
approach the limits that your operating system places on the number of rows
that can be locked at one time. In addition, the locked rows are unavailable
to other users on the system.
INSERT Cursors
You can associate a cursor with an INSERT statement as well as a SELECT
statement. The INSERT cursor permits data to be more efficiently inserted into
a database by buffering the data in memory and writing to the disk only
Using SQL
3-25
INSERT Cursors
when the buffer is full. The following statements allow you to declare and
manipulate an INSERT cursor. (For complete information about the syntax of
each statement, see Chapter 7 of the INFORMIX-4GL Reference Manual).
DECLARE
OPEN
PUT
stores a row in the INSERT buffer for later insertion into the
database. When you fill the buffer (by executing a series of
PUT statements), INFORMIX-4GL automatically inserts the
rows into the appropriate table as a block.
FLUSH
CLOSE
For databases with transactions, you must issue the OPEN, PUT, FLUSH, and
CLOSE statements within a transaction.
For example, you can use these cursor management statements to insert customers into the customer table, block by block. See the following example:
DECLARE ins_curs CURSOR FOR
INSERT INTO customer VALUES (p_customer.*)
OPEN ins_curs
LET answer = "y"
WHILE answer = "y"
INPUT BY NAME p_customer.fname
THRU p_customer.phone
LET p_customer.customer_num = 0
PUT ins_curs
PROMPT "Do you want to enter ",
"another customer (y/n) ? "
FOR answer
END WHILE
CLOSE ins_curs
3-26
Using SQL
INSERT Cursors
The OPEN statement sets up the insert buffer for the INSERT cursor.
The WHILE loop includes statements that insert information entered
on a screen form into the customer table, block by block. Specifically, the
INPUT statement allows the user to enter customer information on a
screen form and stores the information in the p_customer record. The PUT
statement stores the current values in the p_customer record in the insert
buffer. If the insert buffer becomes full as the result of a PUT statement, the
rows are automatically inserted into the customer table as a block.
The CLOSE statement inserts any rows that remain in the insert buffer into
the customer table and closes the INSERT cursor.
When you use an INSERT cursor, you should CLOSE the cursor to insert any
buffered rows into the database before allowing your program to end. The
user can lose data if the cursor is not closed properly. For example, if the user
presses the Interrupt key during input in the following program, INFORMIX-4GL closes the INSERT cursor before leaving the program. (Any remaining rows in the insert buffer are inserted into the database before the program
stops.)
DEFER INTERRUPT
. . .
DECLARE ins_curs CURSOR FOR
INSERT INTO customer VALUES (p_customer.*)
OPEN ins_curs
LET answer = "y"
WHILE answer = "y"
INPUT BY NAME p_customer.fname THRU p_customer.phone
ON KEY (INTERRUPT)
CLOSE ins_curs
EXIT PROGRAM
END INPUT
LET p_customer.customer_num = 0
PUT ins_curs
PROMPT "Do you want to enter another customer (y/n) ?
FOR answer
END WHILE
CLOSE ins_curs
. . .
"
Using SQL
3-27
Dynamic Management
Dynamic Management
The preceding discussion assumes that you know what the SQL statements
are when you write your 4GL programs. That is the case for most applications
where you are performing predetermined activities on your database. In
some advanced applications, however, you will not know the statement at
compile time:
Interactive programs, where the user supplies input at run time from the
keyboard
EXECUTE
3-28
Using SQL
Preparing Statements
FREE
Preparing Statements
You can use the PREPARE statement with either a character string or a
character variable that evaluates to an SQL statement. The form of the
PREPARE statement that you choose depends on the type of input (if any)
required by the statement. You can use either form of the PREPARE statement
if the statement requires no input or input for values. If the statement requires
input for SQL identifiers such as column names, you must use the PREPARE
statement with a character variable.
In general, you can improve the performance of your programs by
PREPARing statements that you plan to execute many times. Specifically,
you might want to PREPARE a statement that requires different input each
time it is executed.
Note: You can PREPARE any SQL statements except these:
CLOSE
DECLARE
EXECUTE
FETCH
LOAD
OPEN
PREPARE
SELECT (with INTO variable clause)
UNLOAD
See the section SQL Statement Summary earlier in this chapter for more
information about SQL statements. Chapter 2 describes the INFORMIX-4GL
statements which you cannot PREPARE.
Note: When you issue a DECLARE statement that includes the INSERT or SELECT
keywords, you declare a cursor that can perform an associated PUT or FETCH statement, even though you do not explicitly PREPARE the statement. For example,
DECLARE m_curs CURSOR FOR
INSERT INTO state VALUES (code, sname)
is a cursor declaration that specifies an INSERT statement. When you OPEN this cursor, INFORMIX-4GL automatically PREPAREs the INSERT statement. Implicitly
PREPAREd statements become an issue only if you exceed the engine resources allocated for such statements. If this happens, you can use the FREE statement to release
the resources. The FREE statement is described later in this chapter.
Using SQL
3-29
Preparing Statements
When you PREPARE a statement from a character string, you do not need to
supply values for the question marks until you execute the PREPAREd statement. (See the section Executing PREPAREd Statements later in this chapter for more information.)
3-30
Using SQL
Preparing Statements
Second, you PREPARE the character variable that contains the resulting
SQL statement.
The following example shows how to use this approach to PREPARE a statement that selects rows from the customer table based on a customer number
that the user supplies:
DEFINE cust_num INTEGER,
sel_stmt CHAR(100)
PROMPT "Enter a customer number: "
FOR cust_num
LET sel_stmt =
"SELECT * FROM customer WHERE customer_num = ",
cust_num USING "###"
PREPARE sel1 FROM sel_stmt
When INFORMIX-4GL encounters the LET statement in this example, it concatenates a character string containing part of the SELECT statement to the
variable cust_num, which contains a customer number that the user supplies. INFORMIX-4GL then assigns the resulting string to the large character
variable sel_stmt and PREPAREs it.
When you use this approach, you must supply input values when you assign
the SQL statement to the character variable that you will later PREPARE.
Note: If you use the LET statement to concatenate strings to variables that contain
CHAR or DATE values, or DATETIME or INTERVAL constants, make sure that
quotes appear around those values in the resulting character string. To embed a quote
in a character string, you must enter a backslash (\) followed by a double quote (").
For example, the LET statement
LET sel_stmt = "SELECT * FROM customer WHERE lname MATCHES \"",
last_name CLIPPED, "\""
PREPARE s1 FROM sel_stmt
Using SQL
3-31
Preparing Statements
In contrast, the statements like the following do not require quotation marks around
placeholders for values:
DECLARE q_curs CURSOR FOR
SELECT * FROM customer WHERE lname MATCHES last_name
PREPARE s1 FROM
"SELECT * FROM customer WHERE lname MATCHES ?"
Second, you assign the resulting string to a large character variable and
PREPARE it.
3-32
Using SQL
SELECT statements
INSERT statements that require a cursor
The DECLARE statement has a special form designed to work with PREPAREd
SELECT and INSERT statements.
Using SQL
3-33
"
3-34
Using SQL
Using SQL
3-35
When INFORMIX-4GL opens the cursor for the PREPAREd SELECT statement
in this example, it substitutes the current value of zip for the question mark
in the character string.
A Note on Preparing and Executing SELECT Statements for Update:
A previous section entitled Deleting or Updating the Current Row
describes how to use the DECLARE FOR UPDATE statement and a subsequent
DELETE or UPDATE statement to delete or update the current row. If you
want to use DECLARE FOR UPDATE with a PREPAREd SELECT statement,
3-36
Using SQL
make sure that the FOR UPDATE clause appears as part of the PREPAREd character string or character variable and not as part of the DECLARE statement.
An example follows:
PREPARE s1 FROM "SELECT * FROM customer FOR UPDATE"
DECLARE q_curs CURSOR FOR s1
FOREACH q_curs INTO p_customer.*
. . .
DELETE FROM customer WHERE CURRENT OF q_curs
END FOREACH
Using SQL
3-37
clause. This clause consists of the FROM keyword, followed by one or more
program variables representing the values that replace the question marks in
the character string. An example follows:
PREPARE s1 FROM
"INSERT INTO customer (customer_num, company) VALUES (0, ?)"
"
END WHILE
CLOSE ins_curs
When INFORMIX-4GL executes the PUT statement in this example, it substitutes the current value of p_customer.company for the question mark in the
PREPAREd INSERT statement and stores the row in the insert buffer for later
insertion into the database.
3-38
Using SQL
The following example updates the stores database by replacing the existing
manufacturer codes with new codes. Since the manu_code columns are
potential join columns that link three of the tables, the task of replacing
the old codes with the new must be performed in three tables.
DATABASE stores
MAIN
DEFINE code_change
RECORD new_code LIKE manufact.manu_code,
old_code LIKE manufact.manu_code
END RECORD,
sqlmulti CHAR(250)
PROMPT "Enter new manufacturer code: "
FOR code_change.new_code
PROMPT "Enter old manufacturer code: "
FOR code_change.old_code
LET sqlmulti =
"UPDATE manufact SET manu_code = ? WHERE manu_code = ?;",
"UPDATE stock
SET manu_code = ? WHERE manu_code = ?;",
"UPDATE items
SET manu_code = ? WHERE manu_code = ?"
This program prompts the user for both the new and the old three-letter code.
It then updates all corresponding rows in three tables (manufact, stock, and
items) as a single action.
Using SQL
3-39
Data Access
The FREE statement is useful in this situation where you are at the engines
limit on the number of PREPAREd objects. In effect, it unPREPAREs a
statement, releasing the resources that had been allocated to that statement,
so that you can use them to PREPARE something else. The FREE statement
supports two formats:
FREE statement-name
FREE cursor-name
Always use the first form if you explicitly PREPAREd the statement. The
second form is for implicitly PREPAREd statements to which you assigned
no statement-name. If you assigned a statement-name with PREPARE, freeing
an associated cursor does not release the PREPAREd statement.
After a successful FREE statement, you cannot use statement-name with a
cursor or with EXECUTE unless you PREPARE it again. If you FREE a cursor,
you cannot use it again until you OPEN it.
Data Access
A user has access to the database, a table, and to specific columns within a
table only when the DBA or the owner of the table specifically grants these
privileges. You can temporarily limit access to a table by executing the
LOCK TABLE statement. (Under transactions, the affected rows are locked
until the transaction is complete. Explicit table/record locking is generally
not required.) The following SQL statements affect data access:
GRANT
REVOKE
LOCK
TABLE
UNLOCK
TABLE
3-40
Using SQL
See the next section, User Status and Privileges, for further information.
Use of the LOCK TABLE and UNLOCK TABLE statements is described in the
section Locking later in this chapter.
Chapter 7 identifies the various keywords that can specify user privileges
in the GRANT and REVOKE statements.
In addition to these database-level privileges, the owner of the table can grant
a collection of table-level privileges . These privileges permit the grantee
access to specific columns to execute SELECT or UPDATE statements, or give
the grantee authority to insert new rows, delete old rows, create indexes, and
alter the structure of the table.
In a non-MODE ANSI database, the default is to grant all table-level privileges
(except ALTER) to all users (PUBLIC). In a MODE ANSI database, no default
table-level privileges are granted. You must explicitly grant these privileges.
However, if you use START DATABASE to convert your database to MODE
ANSI, the existing privileges remain in effect unless you specifically revoke
them.
Using SQL
3-41
Data Integrity
Several of the SQL statements (ALTER TABLE, ALTER INDEX, DROP INDEX,
DROP TABLE, DROP VIEW, GRANT, RENAME COLUMN, RENAME TABLE,
REVOKE) can be executed only by the DBA or by the owner of the specified
table or index. (You can give others the privilege of executing the ALTER
TABLE, GRANT, and REVOKE statements, with certain restrictions.) The
owner of a table is the username of the person who executed the CREATE
TABLE statement. The owner of an index is the one who executed the CREATE
INDEX statement. Execution occurs when the compiled INFORMIX-4GL program containing the CREATE statements is run, not when the INFORMIX-4GL
program is compiled.
Data Integrity
INFORMIX-4GL has features to protect the integrity of your data. These
features include recovery procedures through transaction logs and audit trails,
and concurrency control through record locking and table locking.
Transactions
INFORMIX-4GL supports data integrity by implementing the idea of transactions. A transaction is a series of database operations (SQL statements) that
Using SQL
Transactions
cations to the database. If you also specify the MODE ANSI option, transactions are implicit, and you are always within a transaction. You terminate the
transaction when you issue a COMMIT WORK or ROLLBACK WORK
statement.
In terms of transactions, there are three kinds of 4GL databases:
Using SQL
3-43
Transactions
Using Transactions
The number of rows that can be locked at one time by all users is limited. The
actual limit depends on your operating system. Try to restrict the definition
of a transaction to a few statements that involve only a few rows. If you
expect that the number of rows to be entered during the transaction will be
large, LOCK the tables involved until the transaction is completed.
Regardless of whether a transaction is explicit or implicit, you can terminate
the transaction with a COMMIT WORK statement when you are satisfied that
the series of operations has produced the desired results. If you are not satisfied with the results, you can terminate the transaction with a ROLLBACK
WORK statement. With the exceptions stated in the next paragraph, this statement restores the database to the state that existed immediately before the
transaction began. Both the COMMIT WORK and the ROLLBACK WORK statements release all row and table locks, making the data accessible for modification by others.
On INFORMIX-SE, you cannot roll back GRANT or REVOKE statements, nor
any of the data definition statements. These statements alter the number or
names of tables, or change the number, names, data types, or indexes of columns. If they were executed successfully, they are committed, and the ROLLBACK WORK statement cannot undo them. If your database supports explicit
transactions, you should not use these statements within a transaction.
3-44
Using SQL
To change the name of the log file, the DBA must execute the START
DATABASE statement just before making a backup of the database. The
START DATABASE statement locks the database in EXCLUSIVE MODE while it
is operating so that no further changes can be made. If START DATABASE
fails, no database is open.
If the database is without transactions and you want to use transactions, the
DBA must execute the START DATABASE command just before making a copy
of the database.
If there is a backup copy of the database and a transaction log file that begins
with the operations executed immediately after the backup was made, the
DBA can bring the backup database up to date with the ROLLFORWARD
DATABASE statement. This statement recovers the database through the last
terminated transaction. The DBA must load the backup database files and
execute the ROLLFORWARD DATABASE statement. After rolling the database
forward, the DBA is the only one who has access to the database, since it is left
in an exclusive mode. This state allows the DBA to check the database for
errors before making it generally available. Logging does not occur during
this checking phase. The DBA must close the database when it has been
restored correctly.
Audit Trails
An audit trail is a file that contains a history of all additions, deletions,
updates, and manipulations to a database table. An audit trail serves a purpose similar to that of a transaction log: each is used to maintain a record of
modifications to a database, and each can be used to update backup copies of
a database.
Three audit trail statements are available to protect the integrity of a table:
CREATE AUDIT
DROP AUDIT
3-45
Audit Trails
Here table-name is the name of the table for which you want to create an audit
trail file and pathname is the full pathname of the audit trail file. The audit trail
file should be on a physical device other than the one that holds the data so
that a system failure affecting the device that holds the data does not also
damage the audit trail. If your computer system has more than one hard disk,
the audit trails should be written to a disk not containing the data.
To use the audit trail, make a backup copy of the table after you have executed
a CREATE AUDIT statement, but before you have made any changes to the
table. Once you have started the audit trail and have made a backup, you are
ready to work with the table.
You can drop and create an audit trail file whenever you want. Drop and create the audit trail files just before you make a complete backup of the device
containing the data file. If a system failure should occur, you can use the audit
trail to back up the table from the time of the last backup to the time when the
failure occurred.
Recovering a Table
In the event of a system failure, you can use the RECOVER TABLE statement
to restore a database table by using a backup copy of the table and an audit
trail file. You must first restore a backup copy of the table. The backup copy
must be in the original state that it was in when the audit trail was started. If
it is not in the original state, the recovery fails. The format of the recovery
statement is
RECOVER TABLE table-name
3-46
Using SQL
Locking
INFORMIX-4GL uses locking to prevent different users from executing conflicting operations on the same data. Without locking, for example, two users
could be allowed to update the same row at the same time. In this situation,
the computer memory contains two different versions of the rows (the one
updated by user A and the one updated by user B). Without some method of
concurrency control, the user whose row is the last one actually written to the
file wins and overwrites changes by the other user.
Using SQL
3-47
Row-Level Locking
SET LOCK
MODE
In addition, in the rare instance in which you need to limit access to the entire
database to a single user, you can open the database in EXCLUSIVE mode.
INFORMIX-4GL provides two levels of locking:
can differ slightly, depending on whether or not the database uses transaction
management. Data definition statements, such as ALTER TABLE, CREATE
INDEX, and so on, use implied table-level locking. You can explicitly specify
table-level locking. The following sections describe each level of locking and
the methods for its use.
Note: INFORMIX-OnLine supports additional functionality. Refer to the INFORMIX-OnLine Programmers Manual for more information.
Row-Level Locking
Ordinarily, INFORMIX-4GL locks a row when you execute an UPDATE statement, or when you execute a FETCH statement and the cursor is DECLAREd
with a FOR UPDATE clause. If the UPDATE statement affects only one row,
INFORMIX-4GL releases the lock immediately after performing the update.
Locking the row prevents two programs from attempting to update the same
row at the same time. One program receives the lock and can proceed with
the update. The other program either fails in its attempt or waits for that program to release the lock. (See the section Wait for Locked Row later in this
chapter.)
If the UPDATE statement affects more than one row, INFORMIX-4GL uses the
same row-locking strategy. As soon as a row is UPDATEd, the lock is released
and the next row is locked and UPDATEd. When the UPDATE finishes, all
rows are unlocked.
If you want more control over the update of multiple rows, you can DECLARE
a cursor FOR UPDATE. The WHERE clause of the SELECT statement specifies
the rows you want to update. After you OPEN the cursor and FETCH a row,
that row remains locked until you either CLOSE the cursor or FETCH the next
row.
3-48
Using SQL
Table-Level Locking
Table-Level Locking
Use table-level locking to lock an entire table and prevent others from
altering or seeing rows in that table.
You may want to use this form of locking, for example, during batch operations that affect every row in a table. If the operations must be completed as
a single transaction, it may be more efficient to lock the entire table before
beginning the transaction. Normally, under transactions, INFORMIX-4GL
locks each row manipulated by an UPDATE, DELETE, or INSERT statement. If
you lock the entire table, however, INFORMIX-4GL does not use row-level
locking, because it is not necessary. As a result, you are not likely to reach the
limit that your operating system can place on the number of rows that can be
locked at any one time. INFORMIX-4GL performs table-level locking automatically as part of the following statements: ALTER TABLE, DROP TABLE,
CREATE INDEX, ALTER INDEX, and DROP INDEX.
The LOCK TABLE statement has two extensions:
If you lock the table IN SHARE MODE, other users are able to SELECT data
from the table, but they are not able to INSERT, DELETE, or UPDATE rows
in the table.
If you lock the table IN EXCLUSIVE MODE, other users are not able to
access the table at all until you execute an UNLOCK TABLE statement.
Because locking an entire table prevents others from adding or altering data
in the table, use this feature sparingly. Lock the entire table only when rowlevel locking (as described in the previous section) is not sufficient.
Using SQL
3-49
Indexing Strategy
There are two major purposes for creating an index on columns of a database
table: to speed sorting of rows and to optimize the performance of queries.
When your application writes reports involving complex queries through a
large database, significant time savings can result from judicious indexing.
The drawback to having an index is that indexes slow down the process of
inserting new data into the database. When you update a table, its indexes
can also be modified. This is not a problem when you are adding information
interactively, a row at a time, but can become serious when it is necessary to
insert a large number of rows from one table into another.
The solution to this potential conflict between needs is to take a dynamic
approach to indexing. One of the advantages of an Informix relational database is that you do not have to decide issues like which columns to index at
the time that you create your tables. You should write your applications to
create indexes when you need them and to drop them when they get in the
way. It takes time to create an index on a table already containing data, and
you should create only those indexes that optimize the queries you make. For
example, by judicious scheduling, you can create your indexes in anticipation of batch report writing during the night and drop them the next morning
before there are huge data-entry needs.
3-50
Using SQL
Indexing Strategy
The following are hints for strategic indexing. Although the last two items
refer to a single query, they apply when you anticipate making a number of
queries with the same qualities.
Do not create indexes for small tables with fewer than 200 rows. Speed
that you gain from using an index does not overcome the time required
to open and search the index file on small tables.
Do not create indexes on a column that has only a few possible values.
Such columns are those that contain data like sex, marital status, yes/no
responses, or zip codes in a small city. Because data like this produces
skewed indexes, indexing can cause the optimizing strategy of INFORMIX-4GL to fail and queries to take longer than if the columns were not
indexed. If you have a frequent need to have data sorted on columns with
a small range of possible values, create a temporary table of the sorted
data. Another approach is to redesign the database with separate tables
for each alternative value.
If the WHERE clause of a SELECT statement imposes a condition on a single column, put an index on that column. If conditions are placed on
several columns, make a composite index on all the affected columns. For
the SELECT statement
SELECT * FROM items WHERE order_num > 1015
place an index on stock_num in the items table, since it has many more
rows than the stock table. You should execute the UPDATE STATISTICS
Using SQL
3-51
Query Optimizer
Query Optimizer
It is not always easy to know how indexes are used during a query, but you
can determine this by issuing the SET EXPLAIN statement. When you set this
statement to ON, a file called sqexplain.out is created in the current directory.
A description of the decisions made by the query optimizer, a feature of the
database engine to improve performance, is written into this file for each subsequent query. The recorded information includes the order of table access,
how filters are applied, and what (if any) indexes are used in processing the
query.
For example, if your queries seem to be taking longer than necessary, you
may choose to change your indexing strategy. However, in a complex query,
it may be difficult to predict the actual order of actions taken by the optimizer,
thus making it difficult to determine what (if any) indexes should be added
or dropped. The SET EXPLAIN statement provides you with information to
determine exactly how the database is being accessed and to help you assess
whether changing indexes may improve the decisions of the optimizer.
Auto-Indexing
If you execute a SELECT statement that includes a join between two tables and
there are no indexes on the joined columns, INFORMIX-4GL creates a temporary index on the table with the larger number of rows before performing the
join. The index disappears when the query finishes. This enhancement
is transparent to the user, except for a dramatic improvement in the speed
of unindexed joins.
Clustered Indexes
Since UNIX systems extract information from the disk in blocks, rows physically on the same block and already in the order of an index are retrieved
more quickly. Ordinarily, no relationship need exist between the physical
3-52
Using SQL
NULL Values
order of the data in the .dat file and the order in an index. You can, at least
temporarily, make the physical order in the table the same as the order in an
index through clustering.
INFORMIX-4GL orders, or clusters, the physical data in a table when you
create a new index by executing a variant of the CREATE INDEX statement
or when you execute the new ALTER INDEX statement for an existing index.
Since users who have access to the table can add additional rows or update
the information in existing rows, a table that you cluster according to an
index does not stay that way. Over time, you can expect the benefit of an
earlier clustering to disappear and you may want to cluster the table again
using an ALTER INDEX TO CLUSTER statement.
Since a table can have only one physical order, you can have only one clustered index on a table at any given time. You can change the physical order
to reflect a different index by executing two ALTER INDEX statements:
1. Execute an ALTER INDEX TO NOT CLUSTER statement to release the cluster attribute from the first index.
2. Execute an ALTER INDEX TO CLUSTER statement to attach the cluster
attribute to the second index.
You cannot execute the ALTER INDEX or CREATE INDEX statements on a
view.
NULL Values
The basic purpose of introducing NULL values in a database is to indicate
when no value has been assigned to a particular column in a particular row
of a table. Your reasons for not having assigned a value could include not
knowing the correct value, or that no value yet exists. The NULL can also
indicate that no value is appropriate for a given column because of the values
that were entered into other columns.
As an example, consider entering data for a bank customer who is requesting
a loan. If the customer, Mr. Farthing, is not employed, the employer column
in the client table will have no entry for this customer. This CHAR column
will have the value NULL. The hire_date column is meaningless if
Mr. Farthing is not employed. There is no appropriate date to enter; the value
is NULL.
Using SQL
3-53
Default Values
Default Values
In INFORMIX-4GL, the default value for a column is NULL. INFORMIX-4GL
makes a distinction for number values between zero and NULL, and for character values between blanks and NULL. You do not need to know how
INFORMIX-4GL implements the value NULL to make use of it.
By definition, type SERIAL columns can never contain the NULL value. Columns of type SERIAL always contain integers greater than or equal to one.
You can insist that a column of any type not have NULL values by using the
NOT NULL clause in the CREATE TABLE statement. INFORMIX-4GL will prevent a NULL from being entered into any column that is declared NOT NULL.
You cannot, however, use a NOT NULL clause in an ALTER TABLE statement
when you add a new column. The reason is that INFORMIX-4GL enters a
NULL value into that column for all rows that already exist.
A column for which you create a unique index can have, at most, one NULL
value.
Note for Users with an SQL Version 1 Database:
When no value is provided for a column entry in a row of a table in an SQL Version
1 database, INFORMIX-4GL enters a blank for type CHAR columns, zeros for number columns, and a very large negative value for type DATE columns. Since zero
could well be an acceptable value for a number column (for example, the value for a
type MONEY column), there is no way to distinguish an unknown value from zero.
To incorporate an existing SQL Version 1 database into INFORMIX-4GL programs,
you must execute the dbupdate utility described in Appendix E. (The discussion of
the dbupdate utility describes how you can avoid using NULL values.)
If ship_weight is NULL because the order with number 1023 is new and the
shipping charge has not yet been determined, the value returned for
ship_charge/ship_weight will also be NULL.
3-54
Using SQL
The situation is different when you use one of the aggregate functions. (See
Chapter 7 for a description of the aggregate functions.) COUNT(*) counts all
rows, even if the value of every column in the row is NULL. COUNT
(DISTINCT column-name), AVG, SUM, MAX, and MIN ignore rows with NULL
values for the column in their argument and return the appropriate value
based on the rest of the rows. If, however, a column contains only NULL values, then COUNT (DISTINCT column-name) returns zero, and the other four
aggregate functions return NULL for that column.
has the truth value UNKNOWN for the order in the previous example.
If you combine Boolean expressions using the operators AND, OR, and NOT,
the following tables give the resulting truth value (where T corresponds to
TRUE, F to FALSE, and ? to UNKNOWN).
Figure 3-1
AND
OR
NOT
T
F
?
T
F
?
F
F
F
?
F
?
T
F
?
T
T
T
T
F
?
T
?
?
T
F
?
F
T
?
Using SQL
3-55
The row where order_num = 1023 is the row where ship_weight is NULL.
Since ship_weight is NULL, ship_charge/ship_weight is also NULL, and the
truth value of ship_charge/ship_weight < 5 is UNKNOWN. Since order_num =
1023 is TRUE, the preceding AND truth table states that the truth value of the
entire search condition is UNKNOWN. Consequently, that row will not be chosen. If the search condition had used an OR in place of the AND, the search
condition would be TRUE.
You can select (or reject) rows containing NULL values with a new type of
search condition:
column IS [ NOT ] NULL
You must use the keyword IS. It is not permitted to write the condition as
follows:
column = NULL
column != NULL
(Incorrect)
(Incorrect)
If you perform a join between two tables using the WHERE clause,
WHERE column1 = column2
INFORMIX-4GL will not select the rows where either column1 or column2 is
NULL. In particular, no row will be returned if both column1 and column2
are NULL. This is merely a special case of the more general rule that Boolean
expressions containing NULL values have an UNKNOWN truth value.
3-56
Using SQL
All other columns in the orders table will be filled with NULL values. Similarly, you can use the NULL keyword to modify a column value when using
the UPDATE statement. For a customer whose previous address required two
address lines, but now requires only one, you would use the following entry:
UPDATE customer
SET address1 = "123 New Street",
address2 = NULL,
city
= "Palo Alto",
zipcode = "94303"
WHERE customer_num = 134
Views
Views are constructs on a database that allow you to do the following tasks:
Using SQL
3-57
Views are therefore dynamic windows into the database and are not static
snapshots. They differ in this respect from a temporary table created by the
INTO TEMP clause of a SELECT statement or the CREATE TEMP TABLE statement. Such temporary tables show you only the state of the database when
the temporary table was created.
Although views appear to be tables in the database, they differ in several
important ways. You cannot create an index on a view. Under certain conditions, you cannot update or modify the data perceived through a view. An
obvious case occurs when the column seen in a view is really an expression
generated from actual database tables. Generally speaking, there is no way
to determine the appropriate change in the underlying columns involved
in such an expression if you want to change the value of the column.
The next sections describe how to create and delete views, how to query the
database through views, how to modify the database through a view, and
how to set up privileges for a view.
Using SQL
You cannot modify the database through a view if the view definition
involves joins, the GROUP BY clause, the DISTINCT keyword, or an aggregate function. If any of these features appears in the view definition, the
creator of the view cannot execute INSERT, DELETE, or UPDATE statements on the view. You can define a view, however, using a subquery that
refers to another table. This approach can often circumvent the restriction
on joins. (See the section Data Constraints Using Views, later in this
chapter.)
A view column can be UPDATEd only if it is derived directly from a database table and not as a result of an expression. Expression-derived
columns are called virtual columns. You cannot INSERT rows through
a view that contains virtual columns, although you can DELETE a row that
contains a virtual column.
You cannot execute the ALTER TABLE, CREATE INDEX, ALTER INDEX, or
UPDATE STATISTICS statements on a view. You do, however, receive the
benefit of existing indexes on the underlying tables.
You can use an INSERT statement on a view that shows only a portion of an
underlying table. When you do so, the unmentioned columns of the underlying table will receive NULL values. If one of the unmentioned columns does
not permit NULL values, INFORMIX-4GL will not permit you to INSERT to the
view.
If you drop a column from a table underlying a view and you have defined
the view in terms of that column, INFORMIX-4GL issues an error if you subsequently refer to the view (other than with the DROP VIEW statement).
Unless you create the view with a WITH CHECK OPTION clause, it is possible
to INSERT or UPDATE data through a view that does not satisfy the limitations on the view. A row inserted or updated in this manner is no longer
accessible through the view. For example, a view could be created that allows
the user access only to customers from Palo Alto. If, when using the view, the
user creates a new row with a customer from Menlo Park, the user cannot
Using SQL
3-59
select the row through the view. If the city column on an existing row is
updated to Menlo Park, the row disappears from the view. The WITH
CHECK OPTION clause in the CREATE VIEW statement causes INFORMIX-4GL
to reject an UPDATE or INSERT that violates the restrictions of the view.
You must be careful when you UPDATE a table through a view that can
contain duplicate rows. Duplicate rows can occur in a view even if the
underlying table has unique rows. If a view is defined on the items table
and contains only the columns order_num and total_price, the view contains
duplicate rows if two items from the same order have the same total price. If
you put the cursor on one of the rows where total_price = $1234.56 and
update the total_price to $1250.00 through the view, you have no way of
knowing which item you have increased.
3-60
Using SQL
Outer Joins
If you do all data entry and data modification through the safe_items view,
4GL will reject all data that does not meet the requirements of the WHERE
clause. Because of the dynamic nature of views, the view will only contain
rows corresponding to current stock items if you change the stock table by
adding rows corresponding to new stock items or deleting old ones. By
extending the WHERE clause, this example can be expanded to cover very
general data-constraint needs.
Outer Joins
An outer join between two tables treats the two tables unsymmetrically. One
of the tables is dominant (often referred to as preserved), and the other
table is subservient. If the subservient table has no rows satisfying the join
condition, the outer join attaches a row of NULL values to the row of the dominant table before projecting the desired columns. To illustrate, let a be a column from tab1 and b a column in tab2. Further, let the values in the two
tables be as shown in the following display:
tab1.a
2
3
5
tab2.b
4
2
6
5
Using SQL
3-61
statement contains an outer join between tab1 (the dominant table) and tab2
(the subservient table):
SELECT a, b
FROM tab1, OUTER tab2
WHERE a = b
b
2
5
Every value for a is present, and only those values for b that correspond to a
value in a are present. When there is no value in column b that satisfies the
join condition, a NULL value (shown here as -) is substituted.
A WHERE clause is required in the case of outer joins and must set a condition
between the two tables.
See Appendix G for more information about outer joins.
to get the ROWID value for each row. You can also determine the ROWID of
the last row that INFORMIX-4GL dealt with by examining the SQLCA record.
See the next section for how to do this.
You can also use ROWID in WHERE clauses to select rows based on their internal record number. This feature is useful when there is no other unique column in a table.
If a row is deleted from the table, its ROWID can be assigned to a new row.
You should not attribute chronological or other significance to the sequential
values of ROWID.
3-62
Using SQL
SQLCA Record
SQLCA Record
Proper database management requires that all logical sequences of statements that modify the database continue successfully to completion. If, for
example, you UPDATE a customer account to show a reduction of $100 in the
payable balance and the next step, to UPDATE the cash balance, fails for some
reason, your books will be out of balance. It is prudent to check that every
SQL statement executes as you anticipated.
INFORMIX-4GL provides two ways to do this: the global variable status that
indicates errors both from form-related statements and SQL statements; and
a global record SQLCA that allows you to test the success of SQL statements.
The status variable provides the primary information, and SQLCA provides
additional information.
INFORMIX-4GL returns a result code into the SQLCA record after executing
every SQL statement except DECLARE. This record is shown here:
DEFINE SQLCA
SQLCODE
SQLERRM
SQLERRP
SQLERRD
SQLAWARN
END RECORD
RECORD
INTEGER,
CHAR(71),
CHAR(8),
ARRAY [6]
CHAR (8)
OF
INTEGER ,
SQLCODE
SQLCODE
SQLERRP
SQLERRD
SQLERRD[2]
SQLERRD[3]
SQLERRD[4]
3-63
SQLCA Record
SQLERRD[5]
SQLERRD[6]
signal various warning conditions (as opposed to errors) following the execution of an SQL statement. The characters are
blank if no problems were detected.
SQLAWARN[1] is set to W if one or more of the other warning
characters has been set to W. If SQLAWARN[1]
with transactions.
SQLAWARN[3] is set to W if an aggregate function ( SUM, AVG,
MAX, or MIN ) encountered a NULL value in its
evaluation, or if a DATABASE statement
selected a MODE ANSI database.
SQLAWARN[4] is set to W if a DATABASE statement selected an
INFORMIX-OnLine database, or when the
number of items in the select-list of a SELECT
clause is not the same as the number of program variables in the INTO clause. The number
of values returned by INFORMIX-4GL is the
smaller of these two numbers.
SQLAWARN[5] is set to W if float-to-decimal conversion is
used.
SQLAWARN[6] is set to W when your program executes an
INFORMIX-4GL extension to ANSI standard
syntax, and the DBANSIWARN environment
variable is set.
SQLAWARN[7] is not used at present.
SQLAWARN[8] is not used at present.
3-64
Using SQL
You can use these functions in SQL statements wherever you can use a constant of a similar data type. TODAY returns a DATE, CURRENT a DATETIME,
and USER a CHAR value. You can also use CURRENT and TODAY (but not
USER) in 4GL statements.
For example, if you wish to retrieve the rows that you have inserted into a
table, you must define a CHAR column to contain the USER name. When you
insert new rows into the table, use the USER function as follows:
INSERT INTO table VALUES ( . . . , USER , . . . )
With a SELECT statement, you can retrieve the rows that you entered:
SELECT * FROM table WHERE user_col = USER
The next statement retrieves all rows with the current date from table:
SELECT * FROM table WHERE date_col = TODAY
You can use CURRENT to insert the system date and time:
INSERT INTO table VALUES ( . . . , CURRENT , . . . )
The next query selects rows whose DATETIME value is within a range from
the beginning of 1989 to the current instant.
SELECT * FROM table WHERE dt_col
BETWEEN "1989-1-1 00:00:00" AND CURRENT
See the section Built-in Functions in Chapter 2 for more information about
the TODAY and CURRENT functions.
Using SQL
3-65
3-66
Using SQL
Chapter
Form Building
and Compiling
Chapter Overview
4
18
WORDWRAP 48
INSTRUCTIONS Section 52
Field Delimiters 53
Screen Records 55
Screen Arrays 56
Default Screen Attributes 57
The upscol Tables in a MODE ANSI Database
60
4-2
Chapter Overview
A screen form is a terminal screen display that can support input or output
tasks within a 4GL application program. You can use screen forms in
conjunction with screen interaction and data manipulation statements
of INFORMIX-4GL to enter, retrieve, modify, or delete data.
Before you can use a customized screen form in your INFORMIX-4GL program, you must create a form specification file and use FORM4GL to compile
this file. The form specification file is an ASCII file that contains the screen format and the instructions to INFORMIX-4GL about how to display the data.
The first and longest section of this chapter, Structure of a Form Specification File, describes the function and syntax of each of the required and
optional components of a 4GL form specification file. Another part of this
chapter, Default Screen Attributes, describes the syscolval and syscolatt
tables into which you can insert default attributes, formats, and values for
screen fields of 4GL applications.
The section Creating and Compiling a Form describes how to use
FORM4GL to compile form files for use in INFORMIX-4GL programs. The last
section, Using PERFORM Forms in INFORMIX-4GL describes what happens when an INFORMIX-4GL program uses screen forms designed for PERFORM, the screen transaction program of INFORMIX-SQL.
Note: The FORM4GL syntax for forms that you design to work with INFORMIX-4GL is different in several significant ways from the syntax of PERFORM. You
can use PERFORM forms with INFORMIX-4GL, but you must recompile them
using FORM4GL. In addition, not all of the PERFORM features are operative.
4-3
SCREEN Section: The SCREEN section appears next, showing the exact
layout of the form as you want it to appear on the screen. You must specify the position of the screen fields for data entry and display, and any
additional text or graphic characters.
TABLES Section: A TABLES section must follow the SCREEN section if you
define any field with the name of a column in a database table. The
TABLES section identifies all the tables whose columns are associated
with screen fields in the ATTRIBUTES or INSTRUCTIONS sections, and
defines aliases for any table names or synonyms that require an owner
qualifier.
ATTRIBUTES Section: The ATTRIBUTES section describes each field on
the form and assigns names to fields. The field specifications can include,
for example, appearance, acceptable input values, on-screen comments,
and default values.
specify non-default field delimiters and can define screen records and
screen arrays.
Each section must begin with the keyword for which it is named. After you
create a form specification file, you use the FORM4GL utility to compile it.
Your INFORMIX-4GL application can then use program variables to transfer
information between a database and the fields of the screen form, as is illustrated by the examples that appear in Chapters 7, 11, 12, and 13 of the
INFORMIX-4GL User Guide.
4-4
field-tag =
{ table.column
| FORMONLY. field-name
[ TYPE [ data-type [ NOT NULL ] | LIKE table.column ] ] }
[ , attribute-list ] [ = . . . ] [ ; ] [ = . . . ] ;
...
[ END ]
[ INSTRUCTIONS
[ DELIMITERS "ab" ]
[ SCREEN RECORD record-name [ [ n ] ]
( { table.*
| table.column1 THRU table.column2
| table.column } [ , . . . ] )
...]
[ END ] ]
This summary includes three exceptions to the usual syntax notation of this
manual. The following are literal characters to be entered in your file, rather
than conventional symbols to mark optional terms:
4-5
Example
Figure 4-1 illustrates the overall structure of form specification files:
DATABASE stores
SCREEN
{
-------------------------------------------------------------------------CUSTOMER INFORMATION:
Customer Number: [c1
]
Telephone: [c10
]
...
SHIPPING INFORMATION:
Customer P.O.: [o20
}
TABLES
customer orders items manufact
ATTRIBUTES
c1 = customer.customer_num
= orders.customer_num;
...
c10 = customer.phone, PICTURE = "###-###-####x#####";
...
o20 = orders.po_num;
o21 = orders.ship_date;
o22 = orders.paid_date;
INSTRUCTIONS
SCREEN RECORD sc_order[5] (orders.order_date THRU orders.paid_date)
Figure 4-1
In this example, the screen form will display columns from several tables in
the stores database. The file is for a default physical screen size (24 lines of 80
characters) and includes all five of the required and optional sections that are
described in the pages that follow.
This example is incomplete, since it omits portions of the SCREEN and
ATTRIBUTES sections that describe some of the screen fields. The ellipsis
notation ( . . . ) in those sections is a typographic device to simplify this
illustration.
4-6
DATABASE Section
DATABASE Section
Overview
The DATABASE section of a form specification file identifies the database (if
any) with which the form is designed to work. You must include this section,
even if your screen form does not refer to the tables of any database. The
DATABASE section has this structure.
Syntax
DATABASE
{ database-name | FORMONLY } [WITHOUT NULL INPUT]
Explanation
DATABASE
database-name
WITHOUT
NULL INPUT
FORMONLY
is a keyword to indicate that the screen form is not associated with any database.
Notes
1. You should use the WITHOUT NULL INPUT option only if you have
elected to create and work with a database that does not have NULL
values. (See the description of dbupdate in Appendix E for the other
required steps.) For fields that have no other defaults, this option causes
INFORMIX-4GL to display zeros as default values for number and
INTERVAL fields, and blanks for character fields. The default DATE value
is 12/31/1899, and the default for DATETIME is
1899-12-31 23:59:59.99999.
2. It is possible to create a form that is not related to a database. To do so,
specify FORMONLY after the DATABASE keyword, and omit the TABLES
section of the form specification file. Use the table name formonly in
the ATTRIBUTES section in naming fields that are not linked to specific
columns of a database.
Form Building and Compiling
4-7
DATABASE Section
Examples
The following DATABASE section specifies that any columns referenced in
the TABLES section are in the stores demonstration database:
database
stores
The next example of a DATABASE section specifies that the screen form is not
associated with any database:
database
formonly
4-8
SCREEN Section
SCREEN Section
Overview
The SCREEN section of the form specification file specifies the vertical and
horizontal dimensions of the physical screen, and the position of display
fields and other information that will appear on the screen form. This section
is required. It has the following syntax:
Syntax
SCREEN [ SIZE lines [ BY cols ] ]
{
screen-layout
}
[ END ]
Explanation
SCREEN
SIZE
lines
BY
cols
{
screen-layout
}
END
4-9
SCREEN Section
Notes
1. If you omit the SIZE keyword, lines defaults to 24, and cols defaults to
the maximum number of characters in any line of your screen-layout.
If you specify a default form at the Programmers Environment, as
described near the end of this chapter, these SIZE defaults appear
explicitly in the file.
2. Your form4gl command line can override either or both of the lines
or cols dimensions of the SCREEN section by specifying:
form4gl -l lines -c cols form-name
Here lines and cols are defined as above, and form-name is the filename
(without the .per extension) of a form specification file.
3. Specify lines as the total screen height. Four lines are reserved for the
system, so no more than ( lines - 4 ) can display data.
4. If ( lines - 4 ) is less than the number of lines in the screen-layout, FORM4GL
splits your form into a new page after every (lines - 4) lines. INFORMIX-4GL does not support multiple-page forms, so any lines beyond the
first page will overlay the last line of the first page if your screen-layout is
too large for your screen. (Create several form specification files if you
need to display more data than can fit on one form.)
5. If the SIZE clause or command line specify dimensions too small for the
screen-layout, FORM4GL issues a compile-time warning, but still produces
the compiled form that your file specified.
6. The screen-layout must be enclosed in braces ( { } ). It consists of display
fields and (optionally) textual information and graphics characters. Display
fields must be indicated by brackets ( [ ] ) that define the field length and
the position within a line of the form, and by field tag labels within the
field.
7. Do not use braces as comment indicators in the screen-layout.
8. As in the other sections of a form specification file, the keyword END is
not required, but it is recognized by FORM4GL to provide compatibility
with earlier Informix products.
4-10
SCREEN Section
Example
This figure schematically illustrates the structure of a SCREEN section. Here
the SCREEN SIZE dimensions specify a physical screen that can display up to
35 lines of data, with up to 80 characters in each line. (Four of the 39 lines
specified here are reserved for the system.)
SCREEN SIZE 39 BY 80
{
.
.
.
Screen layout
.
.
.
}
[ END ]
Textual Information
A screen layout can specify strings of ASCII characters that appear on the
screen form. These characters can label the form and its fields, or otherwise
improve the display. Except for the displacements described later in Graphics Characters in Forms, position in the screen layout determines where text
appears on the screen. Text cannot overlap display fields, but the PICTURE
attribute (described in Attributes Syntax later in this chapter) can specify
literal characters within CHAR fields.
Display Fields
You can indicate where data will be displayed on the screen by using brackets
( [ ] ) to delimit fields in the screen layout. You must label each field with an
associated field tag to identify the field.
Syntax
[fieldtag
Explanation
[
fieldtag
are delimiters for a field. The width of the field is the number of
characters that can be placed between the brackets. (The brackets
are required in this context, and do not signify an optional syntax.)
is the field tag that labels the display field.
Form Building and Compiling 4-11
SCREEN Section
Notes
1. Each field must have a field tag, enclosed within brackets.
2. The field tag is from 1 to 50 characters long. It must fit within the brackets.
The first character must be a letter. The rest of the field tag can include
letters, numbers, and underscores ( _ ).
3. Field tags are labels; they are not the same as field names. The
ATTRIBUTES section links each field tag to a field name.
4. The same field tag can be used at more than one position in the SCREEN
section of the form specification, if you want the same information to
appear in more than one screen field, or if you define a multiple-line field,
or a screen array. (Multiple-line fields and screen arrays are described
later in this chapter.)
5. The case of a field tag is ignored (so a1 and A1 are the same).
6. You can give single-character fields the tags a through z (so a form can
include no more than 26 single-character fields.)
7. In a default form specification file, the widths of all fields are determined
by the data type of the corresponding columns in the database tables.
(See Creating and Compiling a Form for more information about
default form specification files.)
8. If you create your own form, you normally should set the width of each
display field in the SCREEN section to be equal to the width of the program variable or column to which it corresponds.
9. Fields corresponding to number columns should be large enough to
contain the largest number that you might display. If the field is too small
to display an assigned number, INFORMIX-4GL fills the field with
asterisks ( * ) to indicate the overflow.
10. Fields intended to display character data can be shorter than the defined
column length. INFORMIX-4GL fills a field from the left, and truncates
from the right any character string that is longer than the field to which it
is assigned. Through subscripting, you can assign portions of a character
column to one or more fields. (See the ATTRIBUTES Section later in this
chapter.)
11. If you edit and modify the default form specification file or create a new
file, you can verify that the field widths match the width requirements of
the corresponding CHAR columns by using the -v option of FORM4GL. At
the system prompt, enter:
form4gl -v form-name
FORM4GL reports any discrepancies in the file form-name.err.
4-12
SCREEN Section
Example
The SCREEN section listed below appears in the orderform.per form specification file in the INFORMIX-4GL demonstration application. This uses
default screen dimensions (24 by 80). Notice the use of textual information for
field labels, a screen title, and ornamental lines. (The INSTRUCTIONS Section later in this chapter describes how repeated field tags are used in forms
that define screen arrays.)
SCREEN
{
------------------------------------------------------------------------------ORDER FORM
------------------------------------------------------------------------------Customer Number:[f000
] Contact Name:[f001
][f002
]
Company Name:[f003
]
Address:[f004
][f005
]
City:[f006
] State:[a0] Zip Code:[f007 ]
Telephone:[f008
]
------------------------------------------------------------------------------Order No:[f009
] Order Date:[f010
] Purchase Order No:[f011
]
Shipping Instructions:[f012
]
------------------------------------------------------------------------------Item No. Stock No. Code
Description
Quantity
Price
Total
[f013 ] [f014 ] [a1 ] [f015
] [f016 ] [f017
] [f018
]
[f013 ] [f014 ] [a1 ] [f015
] [f016 ] [f017
] [f018
]
[f013 ] [f014 ] [a1 ] [f015
] [f016 ] [f017
] [f018
]
[f013 ] [f014 ] [a1 ] [f015
] [f016 ] [f017
] [f018
]
Running Total including Tax and Shipping Charges:[f019
]
===============================================================================
}
END
p
q
b
d
|
Purpose
Use p to mark the upper-left corner.
Use q to mark the upper-right corner.
Use b to mark the lower-left corner.
Use d to mark the lower-right corner.
Use hyphens ( - ) to indicate horizontal line segments.
Use vertical ( | ) bars to indicate vertical line segments.
Form Building and Compiling
4-13
SCREEN Section
The meanings of these six special characters are derived from the gb or acsc
specifications in the termcap or terminfo files, respectively. INFORMIX-4GL
substitutes the corresponding graphics characters when you display the
compiled form.
Once the form has the desired configuration, use the \g string to indicate
when to begin graphics mode and when to end graphics mode.
Insert a \g string before the first p, q, d, b, hyphen, or vertical bar that represents a graphics character. To leave graphics mode, insert the string \g after
the p, q, d, b, hyphen, or vertical bar.
Do not insert a \g string into original white space of a screen layout. The
backslash should displace the first graphics character in the line, and push
the remaining characters to the right. The process of indicating graphics distorts the appearance of a screen layout in the SCREEN section, compared to
the corresponding display of the screen form.
You can include other graphics characters in a form specification file. The
meaning, however, of a character other than the p, q, d, b, hyphen, and
vertical bar is terminal-dependent.
To use graphics characters, the system termcap or terminfo files must include
entries for the following variables:
termcap:
gs
ge
gb
terminfo:
smacs
rmacs
acsc
See Appendix I, Modifying termcap and terminfo, and the manual that
comes with your terminal for information about making changes to your termcap or terminfo files to support these graphics characters.
4-14
TABLES Section
TABLES Section
Overview
The third section of the form specification file lists all the tables that you
reference elsewhere in the screen form. You do not need to display in the
screen form every column of every table listed, but any table or view whose
columns are referenced in the form must be included.
In a MODE ANSI database, a form must qualify any table name with the owner
prefix if the form will be run by users other than owner. If a prefix is needed,
you must specify a simple alias for owner.table-name in the TABLES section
to reference the table in other sections of the form specification file. The
structure of the TABLES section is shown below:
Syntax
TABLES
[tab-alias = [ owner.] ] table . . .
[ END ]
Explanation
TABLES
tab-alias
owner
table
END
Notes
1. If the DATABASE section specifies FORMONLY, no TABLES section is
needed unless you give a field the VALIDATE LIKE or DISPLAY LIKE
attribute in the ATTRIBUTES section, or type a field LIKE a database
column.
2. Every table listed in the TABLES section must be part of the database that
you specify in the DATABASE section.
3. Every database column referenced in the ATTRIBUTES section must be
part of some table specified in the TABLES section.
4-15
TABLES Section
4. The table identifier is the name listed in the tabname column of the systables catalog, or else a synonym. You do not need to specify tab-alias,
unless the form will be used in a MODE ANSI database by a user who did
not create table.
5. Except to assign a tab-alias in the TABLES section, a form file cannot qualify table with an owner prefix. You must define a tab-alias to reference the
owner of a table or synonym. (This alias can be the same identifier as table,
for example stock can be the alias for tom.stock)
6. Statements in INFORMIX-4GL programs or in other sections of the
form specification file can reference screen fields as column or as table.
column, but they cannot specify owner. table. column. You cannot specify
table. column as a field name if you define a different tab-alias for table.
7. INFORMIX-4GL allows you to specify up to 20 tables, but the actual limit
on the number of tables and views in a form is machine-dependent.
8. The END keyword is not required.
Examples
The file orderform.per in Appendix A lists four tables:
TABLES
customer
orders
items
stock
tab1
tab2
=
=
refdpt.booktab
athdpt.balltab
Note: INFORMIX-OnLine supports additional functionality. Refer to the INFORMIX-OnLine Programmers Manual for more information.
4-16
ATTRIBUTES Section
ATTRIBUTES Section
Overview
The ATTRIBUTES section associates an identifier and a data type with every
field in the SCREEN section. You can also describe the behavior and appearance of each field by using attributes to describe how INFORMIX-4GL should
display the field, specify a default value, limit the values that can be entered,
or set other parameters. Attributes are described later in this chapter, in the
sectionAttributes Syntax.
Syntax
ATTRIBUTES
field-tag = field-description ;
...
[ END ]
Explanation
ATTRIBUTES
field-tag
Notes
1. The ATTRIBUTES section must describe every field-tag from the SCREEN
section. (Tags with more than one field-description are described later in
Multiple-Column Fields.)
2. The order in which you list the field tags determines the order of fields in
the default screen records. (See the INSTRUCTIONS Section for more
information about screen records.)
3. The equal ( = ) sign and the semicolon ( ; ) are required symbols.
4. A field not associated with any column is called a form-only field.
4-17
ATTRIBUTES Section
Syntax
field-tag = [ table.] column [ , attr-list ] ;
Explanation
field-tag
table
column
is the name of a column in table or, if you omit table, in some table
listed in the TABLES section. This name can also appear in 4GL
statements that reference the field.
attr-list
Notes
1. Although you must include an ATTRIBUTES section that names every
field-tag, you are not required to specify any attributes.
2. You need to specify table only if column occurs in more than one table of
the TABLES section. FORM4GL issues an error during compilation if there
is ambiguity. Because you can refer to field names collectively through
a screen record built upon all the fields related to a single table, your
forms may be easier to work with if you specify table for each field.
4-18
ATTRIBUTES Section
Examples
The ATTRIBUTES section in the following file lists fields linked to columns in
the customer table. The UPSHIFT and PICTURE attributes listed here are
described later in this chapter.
DATABASE stores
SCREEN
{
Customer Name:[f000
Address:[f002
City:[f004
Telephone:[f006
}
TABLES
][f001
]
][f003
]
] State:[a0] Zip Code:[f005 ]
]
customer
ATTRIBUTES
f000 = customer.fname;
f001 = customer.lname;
f002 = customer.address1;
f003 = customer.address2;
f004 = customer.city;
a0 = customer.state, UPSHIFT;
f005 = customer.zipcode
f006 = customer.phone, PICTURE = "###-###-#### XXXXX";
Form-Only Fields
Form-only fields are not associated with columns of any database. They can
be used to enter or display the values of program variables. If the DATABASE
section specifies FORMONLY, this is the only kind of field description that you
can specify in the ATTRIBUTES section.
Syntax
fieldtag = FORMONLY. field-name
[ TYPE [ data-type [ NOT NULL ] | LIKE [ table. ] column ] ] [ , attr-list ] ;
4-19
ATTRIBUTES Section
Explanation
field-tag
FORMONLY
field-name
TYPE
data-type
LIKE
table
column
NOT NULL
attr-list
is a list of one or more FORM4GL display field attribute specifications, separated by commas. (See the section Attributes
Syntax for a list of FORM4GL attributes.)
Notes
1. You must specify a data-type only if you use the INCLUDE or DEFAULT
attribute for this field. Otherwise, FORM4GL assumes the field is a CHAR
type whose length is the width of the field. INFORMIX-4GL performs the
necessary data conversion for the corresponding program variable during input or display.
2. When describing data-type, do not give a length to type CHAR, DECIMAL,
or MONEY fields, since the length is determined by the display width in
the SCREEN section.
3. If you specify one or more FORMONLY fields, INFORMIX-4GL behaves as
if they formed a database table named formonly, with the field names as
column names.
4. When the DATABASE section has the WITHOUT NULL INPUT clause, the
NOT NULL keyword instructs INFORMIX-4GL to use zero (number types)
or blanks (character types) as a default value for this field in INPUT or
INPUT ARRAY statements. If you do not specify any type, INFORMIX-4GL
treats the field as type CHAR.
4-20
ATTRIBUTES Section
Examples
The following form-only fields could be used in an order entry form to display information about items:
f020 =
f021 =
f022 =
f023 =
f024 =
TYPE
formonly.manu_name;
formonly.description;
formonly.unit_price;
formonly.unit_descr;
formonly.order_placed
DATETIME YEAR TO HOUR NOT NULL, DEFAULT = CURRENT;
The demonstration application uses the following form-only field to store the
running total price for the order as items are entered:
f019 = formonly.t_price;
Multiple-Line Fields
If you need to enter or display long character strings from program variables,
you can specify multiple-line fields that occupy several lines. To create a multiple-line field, repeat the same field tag in different fields of the layout in the
SCREEN section, typically on successive lines. You must also specify the
WORDWRAP attribute for that field tag in the ATTRIBUTES section. During
input and display, INFORMIX-4GL treats these fields as segments of a single
field.
The following example shows only the SCREEN and ATTRIBUTES sections of
a form specification file that specifies a multiple-line field:
SCREEN SIZE 24 BY 80
{
title: [title
author: [author
]
synopsis: [synopsis
[synopsis
[synopsis
[synopsis
[synopsis
}
. . .
ATTRIBUTES
title = booktab.title;
author = booktab.author;
synopsis = booktab.synopsis, WORDWRAP COMPRESS;
]
]
]
]
]
]
Since the screen field whose tag is synopsis appears in five physical segments
in the screen layout and has the WORDWRAP attribute, it is a multiple-line
field. Its value is composed of the physical segments taken in top-to-bottom,
left-to-right order. The field should ordinarily be as long or longer than the
column, so it can display all of the text. Users of your 4GL application pro-
4-21
ATTRIBUTES Section
gram may expect all segments to be the same size and laid out in vertical
alignment, as in the example, but that is not required. Segments can be of
different sizes, and distributed over the screen in any arrangement.
In the description of the field in the last line of the ATTRIBUTES section, the
keyword WORDWRAP enables a multiple-line editor. If you omit it, words
cannot flow from segment to segment of the field, and users must move the
cursor from field to field with Arrow keys or the RETURN key to edit values
in the form. (See the description of the WORDWRAP attribute later in this
chapter for more information about the multiline editor and about the
COMPRESS keyword.)
Multiple-Column Fields
A screen form that contains information from several database tables can
include screen fields that display data via program variables from two or
more database columns.
The database columns that you assign to the same field must have the same
field size. Usually they also have the same data type. If they are character
columns, they must have the same length. The following specification in the
ATTRIBUTES section assigns two column names to a field tag, so that the
names table1. column and table2. column both reference the same field:
field-tag = table1.column = table2.column;
You can also include one or more attribute lists in field descriptions when you
assign several columns to the same field. The placement of attributes determines when they take effect. When INFORMIX-4GL executes an INPUT,
INPUT ARRAY, DISPLAY, or DISPLAY ARRAY statement, the screen fields
listed (explicitly or implicitly) in the 4GL statement are called active fields.
If you want an attribute to apply regardless of which field name is active,
place the attribute in an attr-list after the last field name:
field-tag = table1.column = table2.column, attr-list;
If you want different attributes to apply for each of the field names, place a
semicolon ( ; ) after the attribute list for each field name:
field-tag = table1.column, attr-list1;
= table2.column, attr-list2;
Here attr-list1 is effective when table1.column is active, and attr-list2 is effective only when table2.column is active. (The FORMAT and REVERSE attributes,
described later in this chapter, always take effect if you include them in the
description of a multiple-column field, regardless of their placement.)
4-22
ATTRIBUTES Section
Attributes Syntax
FORM4GL recognizes the following display field attributes:
AUTONEXT
COLOR
COMMENTS
DEFAULT
DISPLAY LIKE
DOWNSHIFT
FORMAT
INCLUDE
NOENTRY
PICTURE
REQUIRED
REVERSE
UPSHIFT
VALIDATE LIKE
VERIFY
WORDWRAP [ COMPRESS ]
Syntax for assigning each of these attributes is described in the sections that
follow. For simplicity and clarity, these descriptions of the attributes that you
can assign to a screen field use the following syntax format:
field-tag = [ table. ] column, attr ;
Here field-tag is a field tag that was specified in the SCREEN section, column or
table.column is the name of a screen field (either linked to a database column
or FORMONLY ), and attr specifies an attribute. This format is simplified by
ignoring multiple-column fields, and by omitting terms that specify the
data-type and NOT NULL keywords of a form-only field. Here is the complete
syntax of a field description that assigns one or more attributes.
Syntax
field-tag =
{ [ table. ] column
| FORMONLY. field-name
[ TYPE [ data-type [ NOT NULL ] | LIKE [ table. ] column ] ] }
, attr [ , attr ] [ = . . . ] [ ; ] [ = . . . ] ;
Refer to this complete syntax if you need to specify a form-only field or a multiple-column field.
Note: INFORMIX-OnLine supports an additional attribute, PROGRAM. Refer to
the INFORMIX-OnLine Programmers Manual for more information.
4-23
AUTONEXT
AUTONEXT
Overview
Use the AUTONEXT attribute to cause the cursor to advance automatically
during input to the next field when the current field is full.
Syntax
field-tag = [ table. ] column, AUTONEXT;
Explanation
field-tag
table.column
AUTONEXT
Notes
1. You specify the order of fields in each INPUT or INPUT ARRAY statement.
2. AUTONEXT is particularly useful with character fields in which the input
data are of a standard length, such as numeric postal codes, or the abbreviations in the state table. It is also useful if a character field has a length
of one, since only one keystroke is required to enter the data and to move
to the next field.
3. If data entered in the field does not meet requirements of other attributes
like INCLUDE or PICTURE, the cursor does not automatically move to the
next field, but remains in the current field.
4. If the most recent OPTIONS statement specifies INPUT WRAP, the next
field after the last field is the first field.
4-24
AUTONEXT
Example
The demonstration application uses the customer form to enter all the names
and addresses of the customers. The following excerpt from the ATTRIBUTES
section of the customer form uses the AUTONEXT attribute:
...
a0 = customer.state, DEFAULT = "CA", AUTONEXT;
f007 = customer.zipcode, AUTONEXT;
f008 = customer.phone;
...
When two characters are entered into the customer.state field (thus filling
the field), the cursor moves automatically to the beginning of the next field
(the customer.zipcode field). When five characters are entered into the
customer.zipcode field (filling this field), the cursor moves automatically
to the beginning of the next field (the customer.phone field).
4-25
COLOR
COLOR
Overview
You can use the COLOR attribute to display field text in color on color monitors, or to specify other video attributes for field text.
Syntax
field-tag = [ table. ] column, COLOR = dispmode [ . . . ] [ WHERE condition ] ;
Explanation
field-tag
table.column
COLOR =
dispmode
WHERE
condition
Notes
1. The condition can be a Boolean expression of the following forms:
expr relop expr
expr IS [ NOT ] NULL
( bool-expr )
NOT bool-expr
expr { + | - | * | / } expr
- expr
2. In a condition, a field tag evaluates to the current value in the field.
3. If you do not specify a condition, the intensity and/or color in your
dispmode list applies to the field.
4-26
COLOR
Text Display
White
Yellow
Magenta
Red
Cyan
Green
Blue
Black
Intensity
BLINK
* UNDERLINE
* REVERSE
LEFT
Text Display
Blinking
Underlined
Reverse (inverse) video
Left-justified
Examples
This example specifies that field text appears in red:
f000 = customer.customer_num, color = red;
The next lines specify various field displays if conditions are TRUE:
f002
f003
f004
f005
=
=
=
=
Related Attribute
REVERSE
4-27
COMMENTS
COMMENTS
Overview
You can use the COMMENTS attribute to cause INFORMIX-4GL to display a
message on the Comment line at the bottom of the screen. The message is
displayed when the cursor moves to the associated field and is erased when
the cursor moves to another field.
Syntax
field-tag = [ table. ] column, COMMENTS = "message" ;
Explanation
field-tag
table.column
COMMENTS =
message
Notes
1. The message must appear between quotation ( " ) marks on a single line of
the form specification file.
2. The default position of the Comment line on the screen is line 23. You can
reset this position with the OPTIONS statement.
3. The default position of the Comment line in a window is LAST. You
can reset this position in the OPTIONS statement (if you want the new
position in all windows) or in the ATTRIBUTE clause of the appropriate
OPEN WINDOW statement (if you want the new position in a specific
window). See Chapter 7 for a description of the OPTIONS and OPEN
WINDOW statements of INFORMIX-4GL.
4. The most common application of the COMMENTS attribute is to give
information or instructions to the user. This is particularly appropriate
when the field accepts only a limited set of values. (See the description
of the INCLUDE attribute later in this section for details of how to specify
a range or a list of acceptable values for data entry.)
4-28
COMMENTS
5. 4GL programs can use the same screen form to support distinct task
(for example, data input and query by example). Do not specify the
COMMENTS attribute in a field description unless the message is
appropriate to all of the tasks in which the message can appear.
If the same field requires a different message for various tasks, you
should specify each message using the INFORMIX-4GL MESSAGE or
DISPLAY statements, rather than in the form specification file.
Example
This field description specifies a message for the Comment line. The message
will appear when the screen cursor enters the field that displays the first
name of a customer:
c2 = customer.fname, comments =
"Please enter initial if available.";
Related Attribute
INCLUDE
4-29
DEFAULT
DEFAULT
Overview
Use the DEFAULT attribute to assign a default value to a display field.
Syntax
field-tag = [ table. ] column, DEFAULT = value;
Explanation
field-tag
table.column
DEFAULT =
value
Notes
1. Default values have no effect when you execute the INPUT statement
using the WITHOUT DEFAULTS option. In this case, INFORMIX-4GL displays the values in the program variables list on the screen. The situation
is the same for the INPUT ARRAY statement, except that INFORMIX-4GL
displays the default values when you insert a new row.
2. If you use the WITHOUT NULL INPUT option in the DATABASE section
and you do not use the DEFAULT attribute, then character fields default
to blanks, number and INTERVAL fields to 0, and MONEY fields to $0.00.
The default DATE value is 12/31/1899, and the DATETIME default value
is 1899-12-31 23:59:59.99999.
3. If you do not use the WITHOUT NULL INPUT option in the DATABASE
section, all fields default to NULL values unless you use the DEFAULT
attribute.
4. If table is FORMONLY, you must specify a data type when you assign the
DEFAULT attribute to a field. (See the syntax in the section Form-Only
Fields earlier in this chapter.)
5. For CHAR or DATE fields, enclose value in quotes ( " ).
4-30
DEFAULT
6. If the field type is DATETIME or INTERVAL, you can enclose value in quotation ( " ) marks, or enter it as an unquoted literal:
DATETIME (values) qualifier
[ + | - ]INTERVAL (values) qualifier
Here values and qualifier are terms described in Appendix J. Besides these
quoted and literal formats, a value of data type INTERVAL can also be
specified in the format:
expression UNITS field
Here expression can be a literal number, or the name of a number column
or variable, or an expression in parentheses that evaluates to a number.
UNITS is a keyword, and field is a DATETIME element name, such as
MONTH, DAY, HOUR, and so forth. (Here field is neither a field name nor
field tag.)
7. If both the DEFAULT attribute and the REQUIRED attribute are assigned to
the same field, the REQUIRED attribute is ignored.
8. Use the TODAY keyword as the value to assign the current date as the
default value of a DATE field.
9. Use the CURRENT keyword as the value to assign the current date and
time as the default for a DATETIME field.
Example
The following field descriptions specify DEFAULT values:
c8 = state, UPSHIFT, AUTONEXT,
DEFAULT = "CA";
o12 = order_date, DEFAULT = TODAY;
f019 = formonly.timestamp TYPE DATETIME YEAR TO DAY
COLOR = red, DEFAULT = CURRENT;
4-31
DISPLAY LIKE
DISPLAY LIKE
Overview
Use the DISPLAY LIKE attribute to display the field by using the attributes
assigned to a database column in the syscolatt table.
Syntax
field-tag = [ table. ] column, DISPLAY LIKE tbl.col;
Explanation
field-tag
table.column
DISPLAY LIKE
tbl.col
Notes
1. This attribute is equivalent to listing all the attributes that you have
assigned to tbl.col in the syscolatt table. See the section Default Screen
Attributes for details of the syscolatt table.
2. You do not need the DISPLAY LIKE attribute if table.column is the same
as tbl.col.
3. Do not use a column of type DATETIME or INTERVAL for tbl.col.
Example
s12 = formonly.total, DISPLAY LIKE items.total_price;
Related Attribute
VALIDATE LIKE
4-32
DOWNSHIFT
DOWNSHIFT
Overview
Assign the DOWNSHIFT attribute to a character field when you want INFORMIX-4GL to convert uppercase letters entered by the user to lowercase letters,
both on the screen and in the corresponding program variable.
Syntax
field-tag = [ table. ] column, DOWNSHIFT;
Explanation
field-tag
table.column
DOWNSHIFT
Note
Because uppercase and lowercase letters have different ASCII values, storing
character strings in one or the other format can simplify sorting and querying
a database.
Related Attribute
UPSHIFT
4-33
FORMAT
FORMAT
Overview
Use the FORMAT attribute with a DECIMAL, SMALLFLOAT, FLOAT, or DATE
field to control the format of output displays.
Syntax
field-tag = [ table. ] column, FORMAT = " format-string" ;
Explanation
field-tag
table.column
FORMAT =
format-string
Notes
1. For DECIMAL, SMALLFLOAT, or FLOAT data types, the format-string
consists of pound signs (#) that represent digits, and a decimal point. For
example, "###.##" produces at least three places to the left of the decimal
point and exactly two to the right.
2. If the actual number displayed is shorter than the format-string, INFORMIX-4GL right justifies it and pads the left with blanks.
3. If the format-string is smaller than the display width, FORM4GL gives a
warning, but the form is usable. INFORMIX-4GL displays the data right
justified in the field.
4. If necessary to satisfy the format, INFORMIX-4GL rounds numbers before
displaying them.
5. For DATE data types, INFORMIX-4GL recognizes the following symbols
as special in the format-string:
4-34
mm
mmm
produces a three-letter abbreviation of the month; for example, Jan, Feb, and so on.
FORMAT
dd
ddd
yy
yyyy
Examples
For DATE fields:
Input
no FORMAT attribute
FORMAT = "mm/dd/yy"
FORMAT = "mmm dd, yyyy"
FORMAT = "yymmdd"
FORMAT = "dd-mm-yy"
FORMAT = "(ddd.) mmm. dd, yyyy"
Result
09/15/1989
09/15/89
Sep 15, 1989
890915
15-09-89
(Sat.) Sep. 15, 1989
Related Attribute
PICTURE
4-35
INCLUDE
INCLUDE
Overview
Use the INCLUDE attribute to specify acceptable values for a field, and to
cause INFORMIX-4GL to check before accepting an input value.
Syntax
field-tag = [ table. ] column, INCLUDE = ( { value | value TO value } [ , . . . ] );
Explanation
field-tag
table.column
INCLUDE =
value
TO
Notes
1. If table is FORMONLY, you must specify a data type when you assign the
INCLUDE attribute to a field. (See the syntax in the section Form-Only
Fields earlier in this chapter.)
2. When you specify a range of values, the lower value must appear first.
(Here lower means the number closer to zero or with the larger negative value; or the earlier DATE or DATETIME value; or the string that starts
with a character closer to the beginning of the ASCII collating sequence.)
3. For ranges of character values, INFORMIX-4GL uses dictionary order
within the printable ASCII character set. (See Appendix H for the ASCII
collating sequence.) In a number field, the range 5 TO 10 is acceptable.
In a character field, it is incorrect. The character string 10 is less than the
string 5, since 1 comes before 5 in the ASCII character set.
4-36
INCLUDE
Example
i18 = items.quantity, include = (1 to 50),
comments = "Acceptable values are 1 through 50";
Related Attributes
COMMENTS, REQUIRED
4-37
NOENTRY
NOENTRY
Overview
Use the NOENTRY attribute to prevent data entry during an INPUT or
INPUT ARRAY statement.
Syntax
field-tag = [ table. ] column, NOENTRY;
Explanation
field-tag
table.column
NOENTRY
Note
The NOENTRY attribute does not prevent data entry into a field during a
CONSTRUCT statement (for a query by example).
Example
i13 = items.stock_num;
= stock.stock_num, NOENTRY;
When you are entering data into the stock table, the stock_num column is not
available, since this SERIAL column gets its value from INFORMIX-4GL during the INSERT statement. You can, however, use the same field to enter the
stock number intended for the items table.
4-38
PICTURE
PICTURE
Overview
Use the PICTURE attribute to specify the character pattern for data entry to a
character field.
Syntax
field-tag = [ table. ] column, PICTURE = "format-string";
Explanation
field-tag
table.column
PICTURE =
format-string
Notes
1. A format-string can include three special symbols:
Symbol
A
#
X
Meaning
Any letter
Any digit
Any character
4-39
PICTURE
Examples
The field specification
c10 = customer.phone,
picture = "###-###-####x#####";
As another example, if you specify a field for part numbers like this
f1 = part_no, picture = "AA#####-AA(X)";
INFORMIX-4GL accepts any of the following inputs:
LF49367-BB(*)
TG38524-AS(3)
YG67489-ZZ(D)
The user does not enter the - or the parentheses, but INFORMIX-4GL
includes them in the string that it passes to the program variable.
Related Attribute
FORMAT
4-40
REQUIRED
REQUIRED
Overview
Use the REQUIRED attribute to force data entry in a particular field during
an INPUT or INPUT ARRAY statement.
Syntax
field-tag = [ table. ] column, REQUIRED;
Explanation
field-tag
table.column
REQUIRED
Notes
1. The REQUIRED keyword is effective only when table.column occurs in
the list of screen fields of an INPUT or INPUT ARRAY statement.
2. There is no default value for a REQUIRED field. If you assign both the
REQUIRED attribute and the DEFAULT attribute to the same field, INFORMIX-4GL assumes that the DEFAULT value satisfies the REQUIRED
attribute.
3. The REQUIRED attribute requires only that the user enter a printable
character in the field. If the user subsequently erases the entry during the
same input, INFORMIX-4GL considers the REQUIRED attribute satisfied. If
you want to insist on a non-NULL entry, make the field form-only and
NOT NULL.
Example
If your ATTRIBUTES section includes the field description
o20 = orders.po_num, REQUIRED;
INFORMIX-4GL requires the entry of a purchase order value when you collect
information for a new order.
Form Building and Compiling
4-41
REQUIRED
Related Attribute
NOENTRY
4-42
REVERSE
REVERSE
Overview
Assign the REVERSE attribute to fields that you want INFORMIX-4GL to
display in reverse video (dark characters in a bright field).
Syntax
field-tag = [ table. ] column, REVERSE;
Explanation
field-tag
table.column
REVERSE
Notes
1. On terminals that do not support reverse video, fields having the
REVERSE attribute are enclosed in angle brackets ( < > ) .
2. If REVERSE is an attribute of any field name of a multiple-column field,
the field is displayed in reverse video, regardless of which column is
active.
Example
f000 = customer.customer_num, reverse;
Related Attribute
COLOR
4-43
UPSHIFT
UPSHIFT
Overview
Assign the UPSHIFT attribute to a character field when you want INFORMIX-4GL to convert lowercase letters in data entry to uppercase letters, both
on the screen and in the program variable corresponding to that field.
Syntax
field-tag = [ table. ] column, UPSHIFT;
Explanation
field-tag
table.column
UPSHIFT
Note
Because uppercase and lowercase letters have different ASCII values, storing
all character strings in one or the other format can simplify sorting and querying a database.
Example
c8
4-44
UPSHIFT
Related Attribute
DOWNSHIFT
4-45
VALIDATE LIKE
VALIDATE LIKE
Overview
Use the VALIDATE LIKE attribute to cause INFORMIX-4GL to validate the
data entered into the field, using the default attributes assigned to a database
column in the syscolval table.
Syntax
field-tag = [ table. ] column, VALIDATE LIKE tbl.col;
Explanation
field-tag
table.column
VALIDATE LIKE
tbl.col
Notes
1. This attribute is equivalent to listing all the attributes that you have
assigned to tbl.col in the syscolval table. A later section, Default Screen
Attributes, describes the syscolval table.
2. You do not need the VALIDATE LIKE attribute if table.column is the same
as tbl.col.
3. Do not use columns of type DATETIME or INTERVAL for tbl.col.
Example
s13 = formonly.state, VALIDATE LIKE customer.state;
Related Attribute
DISPLAY LIKE
4-46
VERIFY
VERIFY
Overview
Use the VERIFY attribute when you want INFORMIX-4GL to require users to
enter data twice for a particular field, in order to reduce the probability of
erroneous data entry.
Syntax
field-tag = [ table. ] column, VERIFY;
Explanation
field-tag
table.column
VERIFY
Note
Since some data are critical, this attribute supplies an additional step in data
entry to ensure the integrity of your data. After the user enters a value into a
VERIFY field and presses RETURN, INFORMIX-4GL erases the field and
requests reentry of the value. The user must enter exactly the same data each
time, character for character: 15000 is not exactly the same as 15000.00.
Example
If you specify a field for salary information like this:
s10 = quantity, VERIFY;
INFORMIX-4GL requires the entry of exactly the same data twice.
4-47
WORDWRAP
WORDWRAP
Overview
Use the WORDWRAP attribute in a multiple-line field to enable the multiline
editor. This attribute wraps a long character string to the next line of a multiple-line field for data entry and display.
Syntax
field-tag = [ table. ] column, WORDWRAP [ COMPRESS ] ;
Explanation
field-tag
table.column
WORDWRAP
is a keyword to wrap long character strings to the next segment of a multiple-line field.
COMPRESS
Notes
1. When a 4GL program uses a multiple-line field to display output, the data
is poured out into the segments of the multiple-line field, in left-to-right
and top-to-bottom order.
2. When text is entered into a multiple-line field whose attributes include
WORDWRAP, the multiline editor breaks character strings into segments
at blanks (if it can), padding field segments with blanks at the right.
Where possible, contiguous non-blank substrings (here called words)
within a string are not broken at display line boundaries.
3. When keyboard input reaches the end of a line, the multiline editor brings
the current word down to the next line, moving text down to subsequent
lines as necessary. When the user deletes text, the editor pulls words up
from lower lines whenever it can.
4. Text in WORDWRAP fields can have printable ASCII characters, the TAB,
and NEWLINE. These are retained in the program variable. The TAB
character aligns the display at the next tab stop, while NEWLINE moves
4-48
WORDWRAP
5.
6.
7.
8.
9.
10.
11.
the display to the start of the next line. Tab stops are in every eighth
column, beginning at the left-hand edge of the field.
Ordinarily, the length of the variable should not be greater than the total
length of the field. When the data is longer than the field (or if too much
padding is required for WORDWRAP), the multiline editor fills the field
and discards the excess data. This allows a long variable to be shown in
summary form. If a truncated variable is used to update the database,
however, data will be lost.
The editor distinguishes between intentional blanks (from the database or
typed by the user) and editor blanks (inserted at the ends of lines for wordwrap or to align after a NEWLINE). Intentional blanks are retained as part
of the data. Editor blanks are inserted and deleted automatically as
required for word-wrapping.
When designing a multiple-line field, you should allow room for editor
blanks, over and above the variable length. The expected number of editor blanks is half the length of an average word per line. Text that requires
more space than you expect might be truncated after the final line of the
field.
The COMPRESS keyword prevents blanks produced by the editor from
being included in the program variable. If you specify COMPRESS, truncation occurs only if the sum of intentional characters exceeds the column
size. But the stored data does not correspond to its multiline display, so a
report cannot display it in identical form.
If you omit COMPRESS, all blanks are retained in the variable, even editor
blanks, and the contents of a variable reflect its multiline display. For
example, a report could duplicate its appearance by printing successive
substrings the width of a display segment. If the sum of the field segment
lengths exceeds the length of the variable, some trailing characters might
be truncated.
An earlier section, Multiple-Line Fields, describes the SCREEN section
specifications for multiple-line fields.
When data is entered or updated in a WORDWRAP field, the user can use
keys that are described in this note to move the screen cursor over the
data, and to insert, delete, and type over the data. The cursor never
pauses on editor blanks.
The editor has two modes, insert (to add data at the cursor) and typeover
(to replace existing data with entered data). You cannot overwrite a
NEWLINE. If the cursor in typeover mode encounters a NEWLINE character, the cursor mode automatically changes to insert, pushing the
NEWLINE character to the right. Some keystrokes behave differently in
the two modes.
Form Building and Compiling
4-49
WORDWRAP
When the cursor first enters a multiline field, it is positioned on the first
character of the first segment, and the mode is set to typeover. The cursor
movement keys are as follows:
RETURN
BACKSPACE
or
LEFT ARROW
RIGHT ARROW
UP ARROW
DOWN ARROW
TAB
The character keys enter data. Any following data shifts right, and words
can move down to subsequent segments. This can result in characters
4-50
WORDWRAP
being discarded from the final segment of the field. The other keystrokes
that alter data are:
CONTROL-A
CONTROL-X
deletes the character under the cursor, possibly causing words to be pulled up from subsequent segments.
CONTROL-D
deletes all text from the cursor to the end of the multiple-line field (not merely to the end of the current field
segment).
CONTROL-N
12. The appearance on the screen of a character value can vary, depending on
whether or not it is displayed in a multiple-line WORDWRAP field. For
instance, if a value prepared using WORDWRAP is displayed without it,
words will be broken, not wrapped, and tabs and newlines will display
as question marks. This does not represent any loss of data, only a different mode of display.
If a value prepared under the multiline editor is again edited without
WORDWRAP, however, some formatting may be lost. For example, a user
might type over a TAB or NEWLINE, not realizing what it was. A user
might remove a blank from the first column of a line, and thus join a word
to the last word on the previous line. These mistakes will be visible when
the value is next displayed in a WORDWRAP field or in a 4GL report that
uses the WORDWRAP function.
13. If you also have INFORMIX-SQL installed on your system, you can use
the SQL Interactive Editor to display character data that you prepared
using WORDWRAP. Since the default screen display of the Interactive Editor does not wrap words, words will appear broken, not wrapped, and
TAB and NEWLINE characters will appear as question marks ( ? ). This
does not represent any loss of data, only a different mode of display.
4-51
INSTRUCTIONS Section
Example
In the following form specifications, a CHAR value in the column charcolm is
displayed in the multiple-line field whose tag is mlf.
SCREEN SIZE 24 by 80
{
Enter text:
[mlf
]
[mlf
]
. . .
[mlf
]
[mlf
]
}
TABLES
tablet . . .
ATTRIBUTES
mlf = tablet.charcolm, WORDWRAP COMPRESS;
If the data string is too long to fit in the first line, successive segments will be
displayed in successive lines, until all of the lines are filled, or until the last
text character is displayed (whichever happens first).
If the form is used to insert data into tablet.charcolm, the keyword
COMPRESS specifies that INFORMIX-4GL will not store editor blanks. Do not
use a comma between the keywords WORDWRAP and COMPRESS.
Note: INFORMIX-OnLine supports additional data types. Refer to the
INFORMIX-OnLine Programmers Manual for more information.
INSTRUCTIONS Section
The INSTRUCTIONS section is the optional final section of a form specification
file. You can use this section to specify non-default field delimiters, and to
define screen records and screen arrays. It appears after the last field description (or after the optional END keyword) of the ATTRIBUTES section. It has
this structure:
Syntax
INSTRUCTIONS
{ delimiters
| record
| array }
...
[ END ]
4-52
INSTRUCTIONS Section
Explanation
INSTRUCTIONS
delimiters
record
array
END
Notes
1. Specify no more than one delimiters instruction.
2. The END keyword is optional and can be omitted.
The pages that follow describe these three types of instructions.
Field Delimiters
You can change the delimiters that INFORMIX-4GL uses to enclose fields
when the form appears on the screen from brackets ( [ ] ) to any other printable character, including blank spaces.
Syntax
DELIMITERS "ab"
Explanation
DELIMITERS
Notes
1. The DELIMITERS instruction tells INFORMIX-4GL what symbols to use as
field delimiters when it displays the form on the screen.
2. FORM4GL requires brackets ( [ ] ) in the SCREEN section of a form
specification file, regardless of any DELIMITERS instruction.
3. You must enclose the pair of ab symbols in quotation ( " ) marks.
4-53
INSTRUCTIONS Section
4. Each delimiter occupies a space, so two fields on the same line are
ordinarily separated by at least two spaces. If you want only one space
between consecutive screen fields, follow these two steps:
(1) In the SCREEN section, substitute a vertical bar ( | ) for paired
back-to-back ( ][ ) brackets that separate adjacent fields.
(2) In the INSTRUCTIONS section, define some symbol as both the
beginning and ending delimiter. For example, you could specify
"| |" or "/ /" or ": :" or " " (blanks).
Examples
The following specifications display < and > as opening and closing delimiters of screen fields:
INSTRUCTIONS
DELIMITERS "<>"
END
|f012
Here the fields whose tags are f011 and f012 will be displayed as:
Full Name-:
4-54
INSTRUCTIONS Section
Screen Records
You can collect groups of screen fields into screen records. Define any screen
records in the INSTRUCTIONS section of a form specification file, and refer to
them in your INFORMIX-4GL program.
Syntax
SCREEN RECORD record-name
( { table.*
| table.column1 THRU table.column2
| table.column } [ , . . . ] )
Explanation
SCREEN
RECORD
record-name
table
column1,
column2,
column
THRU
Notes
1. A screen record or screen array can include fields with different table
specifications, including FORMONLY.
2. FORM4GL automatically creates a default screen record for each table that
is used to identify a field in the form specification file. The default record,
which has the name of the table, contains components corresponding to
only those columns in the table that are fields on the form. The order of
components in a screen record is the order of the field names in the
ATTRIBUTES section. Use table.* to denote the same fields as the default
record for table.
3. FORM4GL returns an error if you define a screen record with the same
name as a table in the form.
4. The option of giving a range of field names with the THROUGH (or THRU)
keyword assumes the order in which the fields are listed in the
ATTRIBUTES section. The THRU keyword is shorthand for listing all fields
Form Building and Compiling
4-55
INSTRUCTIONS Section
Examples
This example creates a screen record called address from fields linked to
some columns of the customer table. This record can simplify 4GL statements
to update customer address and telephone data.
SCREEN RECORD address
(customer.address1 THRU customer.phone)
All the fields linked to columns from the customer table constitute a default
screen record whose record-name is customer.
Screen Arrays
You can collect groups of screen fields into screen arrays. A screen array is
usually an array of lines on the form, each containing identical groups of
screen fields. Each column of a screen array consists of fields with the same
tag. Define screen arrays in the INSTRUCTIONS section, and refer to them in
your INFORMIX-4GL program.
Syntax
SCREEN RECORD record-name [ n ]
( { table.*
| table.column1 THRU table.column2
| table.column } [ , . . . ] )
Explanation
Syntax terms are the same as for screen records on the previous page, with the
addition of [ n ] as a required integer parameter, enclosed in brackets. (In
this context, the brackets are required, and do not signify an optional syntax.)
Notes
1. The integer n specifies the number of rows in the screen array.
2. You can reference record-name in the DISPLAY, DISPLAY ARRAY, INPUT,
and INPUT ARRAY statements of INFORMIX-4GL.
4-56
Example
To illustrate a typical screen array, consider the following fragment of a form
specification file:
SCREEN
{
...
Item 1
Item 2
Item 3
Item 4
Item 5
}
[p
[p
[p
[p
[p
][q
][q
][q
][q
][q
][u
][u
][u
][u
][u
][t
][t
][t
][t
][t
]
]
]
]
]
The sc_items screen array has five rows and four columns and includes fields
linked to columns from two database tables. The rows are numbered from
1 to 5.
If there are no other columns of the items table in the form, the default
screen record items contains two fields, corresponding to the quantity
and total_price columns of the items table.
4-57
syscolatt
tabname
char(18)
colname
char(18)
seqno
serial
color
smallint
inverse
char(1)
underline
char(1)
blink
char(1)
left
char(1)
def_format
char(64)
condition
char(64)
Here tabname and colname are the names of the table and column to which
the attributes apply. Here colname cannot be a DATETIME or INTERVAL column. Permissible values for the attrname and attrval columns in syscolval
are shown in the following table:
attrname
INCLUDE
PICTURE
DEFAULT
COMMENTS
SHIFT
VERIFY
AUTONEXT
attrval
as in this chapter
as in this chapter
as in this chapter
as in this chapter
UP, DOWN, NO (the default)
YES, NO (the default)
YES, NO (the default)
The color column in syscolatt stores an integer that describes color (for color
terminals) or intensities (for monochrome terminals).
The next table shows the displays specified by each value of color, and the
correspondence between default color names and intensities.
Number
0
1
2
3
4
5
6
7
4-58
Color Terminal
White
Yellow
Magenta
Red
Cyan
Green
Blue
Black
Monochrome Terminal
Normal
Bold
Bold
Bold
Dim
Dim
Dim
Invisible
The background for colors is BLACK in all cases. The signifies that, if the
keyword BOLD is indicated as the attribute, the field will be RED on a color
terminal; or, if the keyword DIM is indicated as the attribute, the field will be
BLUE on a color terminal.
You can also define non-default names for colors, by associating different
names with the color number codes in a file named colornames.
Appendix I describes the format of the colornames file. If this exists in
$INFORMIXDIR/incl (see Appendix C), INFORMIX-4GL examines
colornames at compile time to obtain the correspondence between the numbers 0 through 7 and the color names. Those names can appear in the
ATTRIBUTE clause of a 4GL statement. (But you cannot use numbers or nondefault colors from colornames to specify the COLOR attribute in a form
specification file.)
The values for inverse, underline, and blink are Y (yes) and N (no). The
default for each of these columns is N, that is, normal display (bright characters in a dark field), no underline, and steady font. Which of these attributes
can be displayed simultaneously with the color combinations or with each
other is terminal-dependent.
The def_format column takes the same string that you would enter for the
FORMAT attribute in a screen form. Do not use quotation marks.
The condition column takes string values that are a restricted set of the
WHERE clauses of a SELECT statement, except that the WHERE keyword and
the column name are omitted. INFORMIX-4GL assumes that the value in the
column identified by tabname and colname is the subject of all comparisons.
Examples of permitted entries for the condition column follow:
<= 100
BETWEEN 101 AND 1000
>= 1001
MATCHES "[A-M]*"
IN ("CA", "OR", "WA")
NOT LIKE "%analyst%"
BLUE = DIM
BLACK = INVISIBLE
REVERSE
BLINK
UNDERLINE
4-59
4-60
use upscol tables (if they exist) owned by the user who runs FORM4GL,
unless table is an alias that specifies a different owner. If table is an alias for
owner.table, FORM4GL uses the upscol tables of the owner specified by table.
If the upscol tables do not exist, the statements take no action. If owner is not
the correct owner, the compilation fails and an error message is issued.
See also the notes in Chapter 7 on the VALIDATE and INITIALIZE statements
of INFORMIX-4GL.
4-61
4-62
Syntax
form4gl { [ -l lines ] [ -c cols ] [ -v ] form-name | -d }
Explanation
-l lines
-c cols
-v
form-name
-d
at the operating system prompt. FORM4GL asks for the name of your
form specification file, the name of your database, and the name of a table
whose columns you want in your form. It continues to ask for another
table name until you enter a RETURN for the name of a table. FORM4GL
then creates a default form specification file and appends the
extension .per to its name. It also creates a compiled default form with
the extension .frm.
2. Use the system editor to modify the default form specification file to meet
your specifications. If, as an alternative, you create a new form specification file and skip Step 1, be sure to give the filename the extension .per.
4-63
Here myform is the name of your form specification file (without the .per
extension).
If the compilation is successful, FORM4GL creates a compiled form file
called myform.frm and you are finished creating your customized screen
form. If not, FORM4GL instead creates a file named myform.err, and you
need to go on to Step 4.
4. Review the file myform.err to discover the compilation errors. Make
corrections in the file myform.per. Go to Step 3.
keywords in that section are ignored. For the same effects, you must code
them into your INFORMIX-4GL program. (See the BEFORE and AFTER
clauses of the INPUT statement.)
Joins defined in the PERFORM form specification are ignored in INFORMIX-4GL. You can associate two field names with the same field tag, using
the same notation as in a PERFORM join, but no join is effected. On the
other hand, you can create more complex joins and look-ups
in INFORMIX-4GL using the full power of SQL.
Chapter
Report Writing
Chapter Overview
5
37
Aggregates 46
LINENO 48
PAGENO 49
SPACES 50
WORDWRAP 51
5-2
Report Writing
Chapter Overview
INFORMIX-4GL provides all the tools of a general-purpose relational report
writer. Reports in INFORMIX-4GL have the following features:
You have full control over page layout for your 4GL report. This includes
first-page headers that differ from headers on subsequent pages, page
trailers, columnar data presentation, special formatting before and after
groups of sorted data, and conditional formatting that depends on the
data.
You can use the WORDWRAP function to display long character strings
that occupy multiple lines of output.
You can use all the built-in functions of INFORMIX-4GL and the USING
operator. (Chapter 2 describes USING and the built-in 4GL functions and
expressions.)
You can create the report either from the rows returned by a cursor or
from report records assembled from any other source, such as the output
of several different SELECT statements.
You can update the database or perform any other sequence of INFORMIX-4GL statements in the middle of writing a report if the intermediate
values calculated by the report meet your criteria. For example, you could
even write an alert message containing a second report.
This chapter describes the rules for calling and writing 4GL REPORT routines.
(See also Chapter 9 of the INFORMIX-4GL User Guide for additional examples of REPORT routines.)
Report Writing
5-3
The basic loop structure (whether a FOR, FOREACH, or WHILE loop) is illustrated as follows:
START REPORT report1
begin loop
-- of whatever kind
. . .
OUTPUT TO REPORT report1(customer.*)
. . .
end loop
FINISH REPORT report1
The FINISH REPORT statement causes the ON LAST ROW control block
to be executed, if it is present, so that INFORMIX-4GL can produce the
end-of-report summaries.
You can find the full syntax for these statements in Chapter 7.
5-4
Report Writing
DEFINE Section: This section declares the data types of any program
variables or records that are passed as arguments to the report by the
calling statement, and of any local variables or records that are used
within the report. Reports that do not have such arguments or local
variables do not require a DEFINE section.
OUTPUT Section: This optional section specifies a non-default page
length and margins for the physical format of the report, and specifies
whether INFORMIX-4GL sends the report to the screen, to a file, or to
another program.
Syntax
REPORT report-name (argument-list)
[ DEFINE section ]
[ OUTPUT section ]
[ ORDER BY section ]
FORMAT section
END REPORT
Report Writing
5-5
Explanation
REPORT
is a required keyword.
report-name
is an INFORMIX-4GL identifier.
(argument-list) is a list of variables or record identifiers, enclosed in parentheses and separated by commas.
END REPORT
Notes
1. Record identifiers cannot have the asterisk ( .* ) extension in argument-list.
2. The DEFINE, OUTPUT, ORDER BY, and FORMAT sections are described in
later sections of this chapter.
3. A minimal report consists only of the FORMAT section. You can include
other sections as needed.
Examples
Several REPORT routines are included with the demonstration application
listed in Appendix A. They illustrate many of the commands available for
writing reports with INFORMIX-4GL, and provide some of the examples that
appear in this chapter.
5-6
Report Writing
DEFINE Section
DEFINE Section
An INFORMIX-4GL REPORT routine requires a DEFINE section when you pass
arguments to the report or use local variables in the report.
Syntax
DEFINE
Explanation
DEFINE
is a required keyword.
variable-list
type
MONEY [ (m [ , n ] ) ]
INTEGER
INT
CHAR [ ( n ) ]
CHARACTER [ (n ) ]
DECIMAL [ (m [ , n ] ) ]
DEC [ ( m [ , n ] ) ]
NUMERIC [ (m [ , n ] ) ]
DATE
SMALLFLOAT
REAL
RECORD [ LIKE table. * ]
FLOAT [ ( n ) ]
DOUBLE PRECISION [ ( n ) ]
INTERVAL qualifier
DATETIME qualifier
LIKE
table.column
RECORD
table
END RECORD
Report Writing
5-7
DEFINE Section
Notes
1. The DEFINE section obeys the same rules as given in Chapter 7 for the
DEFINE statement, except that report parameters cannot be of type
ARRAY, nor can they be records with ARRAY members.
2. The variable-list must include any local variables that you use in
the report, and any variables or record identifiers that appear in the
argument-list of the REPORT statement. You are required to specify an
argument-list if any of the following conditions are true:
When you use the FORMAT EVERY ROW control block. In this case,
you must pass all the values for each row of the report.
When you use the AFTER GROUP OF control block. In this case, you
must pass at least the parameters named in that block.
Example
REPORT r_invoice (c, stock_tot)
DEFINE c RECORD LIKE customer.*, stock_tot
SMALLINT
Note: INFORMIX-OnLine supports additional functionality. Refer to the INFORMIX-OnLine Programmers Manual for more information.
5-8
Report Writing
OUTPUT Section
OUTPUT Section
An INFORMIX-4GL REPORT routine can contain an OUTPUT section. This
optional section controls the width of the margins and the length of the page,
and allows you to direct the output from the report to a file, to a printer, or to
an operating system pipe.
The OUTPUT section consists of the OUTPUT keyword, followed by one or
more statements. The OUTPUT section has this structure:
OUTPUT
[ REPORT TO statement ]
[ LEFT MARGIN statement ]
[ RIGHT MARGIN statement ]
[ TOP MARGIN statement ]
[ BOTTOM MARGIN statement ]
[ PAGE LENGTH statement ]
The REPORT TO statement specifies where to send output from the report
routine. If you omit this section, output is to the screen.
The LEFT MARGIN statement specifies how many blank spaces to include
at the left of each line of output. The default is 5 spaces.
The RIGHT MARGIN statement specifies the maximum number of characters in each line of output, including the left margin. The default is 132
characters.
The TOP MARGIN statement specifies how many blank lines appear
before the first line on each page of output. The default is 3 lines.
The BOTTOM MARGIN statement specifies how many blank lines follow
the last line on each page of output. The default is 3 lines.
The PAGE LENGTH statement specifies the total number of lines on each
page of output, including lines of data, the top and bottom margins, and
any page headers or page trailers that you define in the FORMAT section.
The default is 66 lines.
The pages that follow describe these OUTPUT statements.
Report Writing
5-9
REPORT TO
REPORT TO
Overview
This optional statement directs the output of the INFORMIX-4GL report to a
file, an operating system pipe, or the system printer.
Syntax
REPORT TO { "filename" | PIPE "program" | PRINTER }
Explanation
REPORT TO
filename
PIPE
is an optional keyword.
program
PRINTER
is an optional keyword.
Notes
1. You cannot use more than one of the REPORT TO options in a REPORT
routine. When you do not use this optional statement, INFORMIX-4GL
sends the report to your screen.
2. If the START REPORT statement has a TO clause directing output of the
report to a file, pipe, or printer, INFORMIX-4GL ignores the REPORT TO
statement of the OUTPUT section.
3. If filename is a variable, you must pass it as an argument to the REPORT
routine.
4. The REPORT TO PRINTER statement causes INFORMIX-4GL to send the
report to the program named by the DBPRINT environment variable. If
you do not set this variable, INFORMIX-4GL sends the report to the lp
program, or to whatever program is the default to access the system
printer on your implementation of UNIX.
5-10
Report Writing
REPORT TO
5. If you want to send the report to a printer other than the system printer,
you can use the REPORT TO filename option to send output to a file, and
then send the file to a printer of your choice. You can also use the REPORT
TO PIPE option to direct the output to a program that sends the output to
the correct printer.
Examples
The following OUTPUT section directs the report output to the label.out
system file.
OUTPUT
REPORT TO "label.out"
LEFT MARGIN 0
TOP MARGIN 0
BOTTOM MARGIN 0
PAGE LENGTH 6
The following OUTPUT section directs the output from the INFORMIX-4GL
report to the more utility.
OUTPUT
REPORT TO PIPE "more"
LEFT MARGIN
LEFT MARGIN
Overview
This statement sets a left margin for a report.
Syntax
LEFT MARGIN integer
Explanation
LEFT MARGIN
integer
Notes
1. The default left margin is five spaces.
2. All columnar displacement indicated by the COLUMN function starts at
the margin set by LEFT MARGIN.
Example
The following LEFT MARGIN statement instructs INFORMIX-4GL to print the
left side of the report as far to the left as possible.
OUTPUT
REPORT TO "label.out"
LEFT MARGIN 0
TOP MARGIN 0
BOTTOM MARGIN 0
PAGE LENGTH 6
5-12
Report Writing
RIGHT MARGIN
RIGHT MARGIN
Overview
This statement sets a right margin for a report.
Syntax
RIGHT MARGIN integer
Explanation
RIGHT MARGIN
integer
Notes
1. The RIGHT MARGIN determines the right margin by specifying the width
of the page, in characters. This is not dependent on the LEFT MARGIN, but
always starts its count from the left edge of the page, so that the columns
of the LEFT MARGIN are included in the value of RIGHT MARGIN.
2. The RIGHT MARGIN is effective only when the FORMAT section contains
an EVERY ROW statement.
3. The default RIGHT MARGIN is 132 characters.
4. INFORMIX-4GL attempts to produce an EVERY ROW report by listing the
variable names across the top of the page, and presenting the data in columns beneath these headings. If there is not sufficient room between the
LEFT MARGIN and the RIGHT MARGIN to do this, INFORMIX-4GL produces a report that lists the variable names and the data of each row in
two columns.
Report Writing
5-13
RIGHT MARGIN
Example
The following example demonstrates the use of the RIGHT MARGIN statement. After it processes the OUTPUT section, INFORMIX-4GL sets the right
margin for the report at 70 characters.
REPORT simple(customer)
DEFINE customer LIKE customer.*
OUTPUT
RIGHT MARGIN 70
FORMAT
EVERY ROW
END REPORT
5-14
Report Writing
TOP MARGIN
TOP MARGIN
Overview
This statement sets a top margin for a report.
Syntax
TOP MARGIN integer
Explanation
TOP MARGIN
integer
Notes
1. The default top margin is three lines.
2. The top margin appears above any page header that you specify in the
FORMAT section.
Example
The following TOP MARGIN statement instructs INFORMIX-4GL to begin
printing at the top of each page.
OUTPUT
REPORT TO "label.out"
LEFT MARGIN 0
TOP MARGIN 0
BOTTOM MARGIN 0
PAGE LENGTH 6
Report Writing
5-15
BOTTOM MARGIN
BOTTOM MARGIN
Overview
This statement sets a bottom margin for a report.
Syntax
BOTTOM MARGIN integer
Explanation
BOTTOM MARGIN
integer
Notes
1. The default bottom margin is three lines.
2. The bottom margin appears below any page trailer.
Example
The following BOTTOM MARGIN statement instructs INFORMIX-4GL to
continue printing to the bottom of each page.
OUTPUT
REPORT TO "label.out"
LEFT MARGIN 0
TOP MARGIN 0
BOTTOM MARGIN 0
PAGE LENGTH 6
5-16
Report Writing
PAGE LENGTH
PAGE LENGTH
Overview
This statement sets the number of lines on each page of a report.
Syntax
PAGE LENGTH integer
Explanation
PAGE LENGTH are required keywords.
integer
Notes
1. The default page length is 66 lines.
2. The PAGE LENGTH includes both the TOP MARGIN and BOTTOM
MARGIN.
Example
The following example includes a PAGE LENGTH statement:
OUTPUT
PAGE LENGTH 22
TOP MARGIN 0
BOTTOM MARGIN 0
This example specifies that INFORMIX-4GL print each page with 22 lines. On
a standard 24-line video screen, 22 lines is the maximum that you can use
with the PAUSE statement without causing undesirable scrolling.
Report Writing
5-17
ORDER BY Section
ORDER BY Section
The optional ORDER BY section specifies variables on which to sort rows, and
the order in which to process group control blocks in the FORMAT section. Its
format is
Syntax
ORDER [ EXTERNAL ] BY sort-list
Explanation
ORDER BY
EXTERNAL
is an optional keyword.
sort-list
Notes
1. Include an ORDER BY section if your report uses group control blocks,
and:
5-18
Report Writing
ORDER BY Section
4. If there is an ORDER BY section without the EXTERNAL keyword, INFORMIX-4GL makes two passes through the input data. During the first pass,
it sorts the data and stores it in a temporary file. During the second pass,
it prints the report.
If the input rows for your report come from the rows returned by only one
cursor, you should use the ORDER BY clause in the SELECT statement
associated with the cursor, and use the EXTERNAL keyword in the ORDER
BY section of your report.
5. If you have just one variable named in group control blocks and the input
rows are already sorted, then you do not need an ORDER BY section.
Example
REPORT r_invoice (c, stock_tot)
DEFINE c RECORD LIKE customer.*,
stock_tot SMALLINT
ORDER BY stock_tot
. . .
Report Writing
5-19
FORMAT Section
FORMAT Section
An INFORMIX-4GL REPORT routine must contain a FORMAT section. The
FORMAT section determines what a report will look like. It works with the
data that are passed to the routine through the argument list, or with data
that you put in global variables for each row of the report. The FORMAT
section begins with the FORMAT keyword, and ends with the END REPORT
keywords.
Two major types of FORMAT sections exist, both of which are described in the
following sections. The simplest contains just one EVERY ROW statement
between the FORMAT and END REPORT keywords. If you use an EVERY ROW
statement, you cannot use any other statements or control blocks:
Syntax
FORMAT
EVERY ROW
END REPORT
Syntax
FORMAT
[ PAGE HEADER control block ]
[ PAGE TRAILER control block ]
[ FIRST PAGE HEADER control block ]
[ ON EVERY ROW control block ]
[ ON LAST ROW control block ]
[ BEFORE GROUP OF control block
...]
[ AFTER GROUP OF control block
...]
END REPORT
5-20
Report Writing
EVERY ROW
EVERY ROW
Overview
The EVERY ROW statement causes INFORMIX-4GL to output every row that
you pass to the report. It uses a default format.
Syntax
EVERY ROW
Explanation
EVERY ROW
Notes
1. The report consists of only the data that you pass to the routine through
its arguments.
2. This statement is useful when you want to run a quick report using a
default format.
3. The EVERY ROW statement stands by itself. You cannot modify it with any
of the statements listed in the Statements section that appears later in
this chapter.
4. When you use the EVERY ROW statement, you cannot use any control
blocks in the FORMAT section.
5. A report generated by an EVERY ROW statement uses the variable names
that you pass as arguments to the routine at run time as column headings.
6. If the variables passed as arguments fit on a line, INFORMIX-4GL produces a report with variable names across the top of each page; otherwise,
it produces a report with the variable names down the left side of the
page.
7. You can use the RIGHT MARGIN statement in the OUTPUT section to
control the width of a report that uses the EVERY ROW statement.
8. To display every row in a format other than the default format, use the
ON EVERY ROW control block (discussed in the Control Blocks section
later in this chapter.)
Report Writing
5-21
EVERY ROW
Examples
This minimal REPORT routine uses the EVERY ROW statement:
REPORT minimal(customer)
DEFINE customer RECORD LIKE customer.*
FORMAT
EVERY ROW
END REPORT
101
Ludwig
Pauli
All Sports Supplies
213 Erstwild Court
customer.customer_num
customer.fname
customer.lname
customer.company
customer.address1
customer.address2
customer.city
customer.state
customer.zipcode
customer.phone
102
Carole
Sadler
Sports Spot
785 Geary St
Sunnyvale
CA
94086
408-789-8075
San Francisco
CA
94117
415-822-1289
. . .
INFORMIX-4GL prints only the column name when the column contains a
NULL value.
5-22
Report Writing
Control Blocks
The following display shows the output from the preceding REPORT routine.
order_num customer_num order_date
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
104
101
104
106
116
112
117
110
111
115
104
117
104
106
110
01/20/1989
06/01/1989
10/12/1989
04/12/1989
12/04/1989
09/19/1989
03/25/1989
11/17/1989
02/14/1989
05/29/1989
03/23/1989
06/05/1989
09/01/1989
05/01/1989
07/10/1989
Control Blocks
Control blocks provide the structure for a customized report. Each control
block is optional but, if you do not use the EVERY ROW statement, you must
include at least one control block in a REPORT routine.
Each control block must include at least one statement. (See the Statements
section later in this chapter.)
When you use the BEFORE GROUP OF, AFTER GROUP OF, and ON EVERY ROW
control blocks in a single REPORT routine, INFORMIX-4GL processes all
BEFORE GROUP OF blocks before the ON EVERY ROW block and the ON
EVERY ROW block before all AFTER GROUP OF blocks. The order in which
INFORMIX-4GL processes the BEFORE GROUP OF control blocks and AFTER
GROUP OF control blocks depends upon the hierarchy of variables listed in
the ORDER BY section or, in the absence of an ORDER BY section, implied by
the order of first mention of variables in either BEFORE or AFTER GROUP OF
control blocks.
Report Writing
5-23
Control Blocks
Assume that the ORDER BY section orders by variables a, b, and c. Then the
following display indicates the order by which INFORMIX-4GL processes
control blocks:
Figure 5-1
BEFORE GROUP OF a
BEFORE GROUP OF b
BEFORE GROUP OF c
ON EVERY ROW
AFTER GROUP OF c
AFTER GROUP OF b
AFTER GROUP OF a
Order of Group Processing
The pages that follow describe these control blocks in alphabetical order.
5-24
Report Writing
AFTER GROUP OF
AFTER GROUP OF
Overview
The AFTER GROUP OF control block specifies the action that INFORMIX-4GL
takes after it processes a group of rows. Grouping is determined by the
ordering that you did earlier.
Syntax
AFTER GROUP OF variable-name
statement
...
Explanation
AFTER GROUP OF
variable-name
statement
Notes
1. You must pass at least the value of variable-name through the arguments
of the REPORT routine.
2. A group of rows is all rows that contain the same value for a given
variable. INFORMIX-4GL automatically groups rows when you use an
ORDER BY section in a REPORT routine, or the ORDER BY clause in a
SELECT statement. That is, groups are formed when you order a list.
When you specify more than one column in the ORDER BY section or
clause, INFORMIX-4GL orders the rows first by the first variable that you
specify (most significant). Rows having the same value on the first variable are then ordered by the second variable that you specify, and so on,
until rows having the same value on all variables but the last are ordered
by the last (least significant) variable that you specify.
INFORMIX-4GL processes the statements in an AFTER GROUP OF control
block each time the specified column changes value, each time a more
significant column changes value, and at the end of a report. (See Figure
5-1 at the beginning of the Control Blocks section.)
Report Writing
5-25
AFTER GROUP OF
3. You can have one AFTER GROUP OF control block for each variable on
which you have ordered the data.
4. If you have an ORDER BY section and you have more than one AFTER
GROUP OF control block, their order within the FORMAT section is not
significant.
5. When INFORMIX-4GL finishes generating a report, it executes all of the
statements in the AFTER GROUP OF control blocks before it executes those
in the ON LAST ROW control block.
6. Group aggregates can be used only in AFTER GROUP OF control blocks.
You cannot use group aggregates in any other type of control block.
7. When INFORMIX-4GL processes the statements in an AFTER GROUP OF
control block, the variables of the report still have the values from the last
row of the group. From this perspective, the AFTER GROUP OF control
block could be called the on last row of group control block.
Examples
AFTER GROUP OF r.order_num
PRINT " ",r.order_date,7 SPACES,
r.order_num USING "###&",
8 SPACES,r.ship_date," ",
GROUP SUM(r.total_price) USING "$$$$,$$$,$$$.&&"
AFTER GROUP OF r.customer_num
PRINT 42 SPACES,"---------------"
PRINT 42 SPACES,GROUP SUM(r.total_price)
USING "$$$$,$$$,$$$.&&"
5-26
Report Writing
BEFORE GROUP OF
BEFORE GROUP OF
Overview
The BEFORE GROUP OF control block specifies the action that INFORMIX-4GL
takes before it processes a group of rows. Grouping is determined by the
ordering that you did earlier.
Syntax
BEFORE GROUP OF variable-name
statement
...
Explanation
BEFORE GROUP OF
variable-name
statement
Notes
1. You must pass at least the value of variable-name through the arguments
of the REPORT routine.
2. A group of rows is all rows that contain the same value for a given variable. INFORMIX-4GL automatically groups rows when you use an ORDER
BY section of a REPORT routine or the ORDER clause of a SELECT statement. That is, groups are formed when you order a list.
When you specify more than one variable in an ORDER BY section or
clause, INFORMIX-4GL orders the rows first by the first variable that you
specify (most significant), second by the second variable, and so on, until
the last variable that you specify (least significant) is ordered.
INFORMIX-4GL processes the statements in a BEFORE GROUP OF control
block at the start of a report, each time the specified variable changes
value, and each time a more significant variable changes value.
(See Figure 5-1 at the beginning of the Control Blocks section.)
3. You can have one BEFORE GROUP OF control block for each variable that
you order.
Report Writing
5-27
BEFORE GROUP OF
4. If you have an ORDER BY section and you have more than one BEFORE
GROUP OF control block, their order within the FORMAT section is not
significant.
5. When INFORMIX-4GL starts to generate a report, it executes all the
statements in the BEFORE GROUP OF control blocks before it executes
those in the ON EVERY ROW control block.
6. You can use a SKIP TO TOP OF PAGE statement in a BEFORE GROUP OF
control block to cause each group to start at the top of a page.
7. When INFORMIX-4GL processes the statements in a BEFORE GROUP OF
control block, the report variables have the values from the first row of the
new group. From this perspective, the BEFORE GROUP OF control block
could be called the on first row of group control block.
Example
BEFORE GROUP OF r.customer_num
SKIP TO TOP OF PAGE
5-28
Report Writing
Syntax
FIRST PAGE HEADER
statement
...
Explanation
FIRST PAGE HEADER
statement
Notes
1. The TOP MARGIN (set in the OUTPUT section) affects how close to the top
of the page INFORMIX-4GL displays the header.
2. The FIRST PAGE HEADER control block overrides a PAGE HEADER control
block on the first page of a report.
3. You cannot use the SKIP TO TOP OF PAGE statement in a FIRST PAGE
HEADER control block.
4. If you use an IF THEN ELSE statement in a FIRST PAGE HEADER control
block, the number of lines displayed by the PRINT statements following
the THEN keyword must be equal to the number of lines displayed by the
PRINT statements following the ELSE keyword.
5. You cannot use the PRINT filename statement to read and display text from
a file in a FIRST PAGE HEADER control block.
6. You can use a FIRST PAGE HEADER control block to produce a title page,
as well as column headings.
Report Writing
5-29
Example
This example is from a report that produces multiple labels across the page.
FIRST PAGE HEADER
{Nothing is displayed in this
control block. It just
initializes variables that are
used in the ON EVERY ROW
control block.}
{Initialize label counter.}
LET i = 1
{Determine label width (allow
eight spaces total between labels).}
LET l_size = 72/count1
{Divide the eight spaces between
the number of labels across the page.}
LET white = 8/count1
This FIRST PAGE HEADER does not display any information. Because INFORMIX-4GL executes the FIRST PAGE HEADER control block before it generates
any output, you can use this control block to initialize variables that you use
in the FORMAT section.
5-30
Report Writing
ON EVERY ROW
ON EVERY ROW
Overview
The ON EVERY ROW control block specifies the action to be taken by INFORMIX-4GL for every row of data that you pass to the routine.
Syntax
ON EVERY ROW
statement
...
Explanation
ON EVERY ROW
statement
Notes
1. INFORMIX-4GL processes the statements in an ON EVERY ROW control
block as each new row is formatted.
2. If a BEFORE GROUP OF control block is triggered by a change in column
value, all appropriate BEFORE GROUP OF control blocks are executed (in
the order of their significance) before the ON EVERY ROW control block is
executed.
3. If an AFTER GROUP OF control block is triggered by a change in column
value, all appropriate AFTER GROUP OF control blocks are executed (in
the reverse order of their significance) after the ON EVERY ROW control
block is executed.
Examples
The following example is from a report that lists all the customers, their
addresses, and their telephone numbers across the page.
ON EVERY ROW
PRINT customer_num USING "####",
COLUMN 12, fname CLIPPED, 1 SPACE,
lname CLIPPED, COLUMN 35, city CLIPPED,
", " , state, COLUMN 57, zipcode,
COLUMN 65, phone
Report Writing
5-31
ON EVERY ROW
5-32
Report Writing
ON LAST ROW
ON LAST ROW
Overview
The ON LAST ROW control block specifies the action that INFORMIX-4GL
is to take after it processes the last row passed to the REPORT routine and
encounters the FINISH REPORT statement.
Syntax
ON LAST ROW
statement
...
Explanation
ON LAST ROW are required keywords.
statement
Notes
1. INFORMIX-4GL executes the statements in the ON LAST ROW control
block after it executes those in the ON EVERY ROW and AFTER GROUP OF
control blocks.
2. When INFORMIX-4GL processes the statements in an ON LAST ROW
control block, the columns that the report is processing still have the
values from the final row that the report processed.
3. The ON LAST ROW control block can display report totals.
Example
ON LAST ROW
SKIP 1 LINE
PRINT COLUMN 12, "TOTAL NUMBER OF CUSTOMERS:",
COLUMN 57, COUNT(*) USING "##"
Report Writing
5-33
PAGE HEADER
PAGE HEADER
Overview
The PAGE HEADER control block specifies what information (if any) appears
at the top of each page of the report.
Syntax
PAGE HEADER
statement
...
Explanation
PAGE HEADER are required keywords.
statement
Notes
1. The TOP MARGIN (in the OUTPUT section) affects how close to the top of
the page INFORMIX-4GL displays the page header.
2. The FIRST PAGE HEADER control block overrides a PAGE HEADER control
block on the first page of a report.
3. You cannot use the SKIP TO TOP OF PAGE statement in a PAGE HEADER
control block.
4. The number of lines produced by the PAGE HEADER control block cannot
change from page to page, and must be expressed unambiguously. The
following rules are special cases of this general principle:
You cannot have a SKIP integer LINES statement inside a loop in the
PAGE HEADER control block.
You cannot use a NEED statement in the PAGE HEADER control block.
If you use an IF THEN ELSE statement in a PAGE HEADER control
block, the number of lines displayed by the PRINT statements
following the THEN keyword must be equal to the number of lines
displayed by the PRINT statements following the ELSE keyword.
Report Writing
PAGE HEADER
in the loop, keeping the number of lines in the header constant from
page to page.
You cannot use a PRINT filename statement to read and display text
from a file in a PAGE HEADER control block.
5. You can use a PAGE HEADER control block to display column headings in
a report.
6. You can use the PAGENO expression in a PRINT statement within a PAGE
HEADER control block to display the page number automatically at the
top of every page.
Example
The following example produces the column headings for printing the
customer data across the page.
PAGE HEADER
PRINT "NUMBER",
COLUMN 12, "NAME",
COLUMN 35, "LOCATION",
COLUMN 57, "ZIP",
COLUMN 65, "PHONE"
SKIP 1 LINE
Report Writing
5-35
PAGE TRAILER
PAGE TRAILER
Overview
The PAGE TRAILER control block specifies what information, if any, appears
at the bottom of each page of the report.
Syntax
PAGE TRAILER
statement
...
Explanation
PAGE TRAILER are required keywords.
statement
Notes
1. The BOTTOM MARGIN (in the OUTPUT section) affects how close to the
bottom of the page INFORMIX-4GL displays the page trailer.
2. You cannot use the SKIP TO TOP OF PAGE statement in a PAGE TRAILER
control block.
3. The number of lines produced by the PAGE TRAILER control block cannot
change from page to page and must be unambiguously expressed. The
following rules are special cases of this more general principle:
You cannot have a SKIP integer LINES statement inside a loop in the
PAGE TRAILER control block.
You cannot use a NEED statement in the PAGE TRAILER control block.
If you use an IF THEN ELSE statement in a PAGE TRAILER control
block, the number of lines displayed by the PRINT statements following the THEN keyword must be equal to the number of lines displayed
by the PRINT statements following the ELSE keyword.
5-36
Report Writing
Statements
RETURNs in the loop, keeping the number of lines in the header con-
You cannot use a PRINT filename statement to read and display text
from a file in a PAGE TRAILER control block.
4. INFORMIX-4GL executes the PAGE TRAILER control block before the
PAGE HEADER control block when you issue a SKIP TO TOP OF PAGE
statement anywhere.
5. You can use the PAGENO expression in a PRINT statement within a PAGE
TRAILER control block to display the page number automatically at the
bottom of every page.
Example
PAGE TRAILER
PRINT COLUMN 28,
PAGENO USING "page <<<<"
Statements
The control blocks determine when INFORMIX-4GL takes an action in a
report, while the statements determine what action INFORMIX-4GL takes.
You can use any INFORMIX-4GL statement in a control block, as well as a
number of statements that can be used only in the FORMAT section of a
REPORT routine.
PRINT FILE
SKIP
5-37
NEED
NEED
Overview
This statement causes subsequent display to start on the next page if there is
not the specified number of lines remaining on the current page.
Syntax
NEED num-expr LINES
Explanation
NEED
is a required keyword.
num-expr
LINES
is a required keyword.
Notes
1. The NEED statement can prevent INFORMIX-4GL from splitting parts of
the report that you want to keep together on a single page.
2. INFORMIX-4GL does not include the BOTTOM MARGIN value in the number of lines counted.
3. If INFORMIX-4GL triggers the NEED statement in printing a report, it
prints both the PAGE TRAILER and the PAGE HEADER.
4. You cannot use this statement in PAGE HEADER or PAGE TRAILER control
blocks.
Example
NEED 6 LINES
5-38
Report Writing
PAUSE
PAUSE
Overview
This statement causes output to the terminal to pause until the user presses
RETURN.
Syntax
PAUSE [ "string" ]
Explanation
PAUSE
is a required keyword.
string
Notes
The PAUSE statement works only if the report goes to the screen. It has no
effect if you include a REPORT TO clause in the OUTPUT section, or a TO
clause in the START REPORT statement.
Example
The following example causes INFORMIX-4GL to pause while running the
report.
AFTER GROUP OF item_num
.
.
.
SKIP TO TOP OF PAGE
PAUSE "Press RETURN to continue"
Report Writing
5-39
PRINT
Overview
This statement displays information, as specified in the OUTPUT section.
Syntax
PRINT [ exprlist ] [ ; ]
Explanation
PRINT
is a required keyword.
exprlist
Notes
1. One PRINT statement displays its output on one line, no matter how
many lines the statement occupies in the report specification, unless the
exprlist includes the WORDWRAP function.
2. When a PRINT statement specifies WORDWRAP, it can also specify a
temporary right margin. The character position of the current column
becomes the temporary left margin, and the contents of the character
string are then displayed on as many lines as necessary between these
temporary margins.
After the PRINT statement with WORDWRAP has executed, any explicit
or default margins from the OUTPUT section are restored.
3. Unless you use the keyword CLIPPED or USING following an expression,
INFORMIX-4GL displays variables with a width that depends on their
data type, as shown in Figure 5-2.
5-40
Report Writing
Data Type
CHAR
DATE
DATETIME
INTERVAL
FLOAT
SMALLINT
INTEGER
SMALLFLOAT
DECIMAL
SERIAL
MONEY
Figure 5-2
Examples
The following example is from a mailing label report:
FORMAT
ON EVERY ROW
PRINT fname, lname
PRINT company
PRINT address1
PRINT address2
PRINT city, ", " , state, 2 SPACES, zipcode
SKIP 2 LINES
The following example is from a report that prints the customer list.
FIRST PAGE HEADER
PRINT COLUMN 30, "CUSTOMER LIST"
SKIP 2 LINES
PRINT "Listings for the State of ", thisstate
SKIP 2 LINES
PRINT "NUMBER", COLUMN 12, "NAME", COLUMN 35, "LOCATION",
COLUMN 57, "ZIP", COLUMN 65, "PHONE"
SKIP 1 LINE
PAGE HEADER
PRINT "NUMBER", COLUMN 12, "NAME", COLUMN 35, "LOCATION",
COLUMN 57, "ZIP", COLUMN 65, "PHONE"
SKIP 1 LINE
ON EVERY ROW
PRINT customer_num USING "####",
COLUMN 12, fname CLIPPED, 1 SPACE,
lname CLIPPED, COLUMN 35, city CLIPPED, ", " , state,
COLUMN 57, zipcode, COLUMN 65, phone
Report Writing
5-41
PRINT FILE
PRINT FILE
Overview
This statement displays the contents of a text file in a report.
Syntax
PRINT FILE "filename"
Explanation
PRINT FILE
filename
Note
You can use the PRINT FILE statement to include the body of a form letter in
a report that generates custom letters.
Example
PRINT FILE "/u/claire/occupant.let"
5-42
Report Writing
SKIP
SKIP
Overview
This statement skips lines in a report or skips to the top of the next page.
Syntax
SKIP { integer LINE[S] | TO TOP OF PAGE }
Explanation
SKIP
is a required keyword.
integer
LINES
TO TOP OF PAGE
Notes
1. You cannot use a SKIP LINES statement inside a CASE, FOR, or
WHILE statement.
2. You cannot use a SKIP TO TOP OF PAGE statement in a FIRST PAGE
HEADER, PAGE HEADER, or PAGE TRAILER control block.
Report Writing
5-43
Examples
The following example is from a report that prints the customer list.
FIRST PAGE HEADER
PRINT COLUMN 30, "CUSTOMER LIST"
SKIP 2 LINES
PRINT "Listings for the State of ", thisstate
SKIP 2 LINES
PRINT "NUMBER", COLUMN 12, "NAME", COLUMN 35, "LOCATION",
COLUMN 57, "ZIP", COLUMN 65, "PHONE"
SKIP 1 LINE
PAGE HEADER
PRINT "NUMBER", COLUMN 12, "NAME", COLUMN 35, "LOCATION",
COLUMN 57, "ZIP", COLUMN 65, "PHONE"
SKIP 1 LINE
ON EVERY ROW
PRINT customer_num USING "####",
COLUMN 12, fname CLIPPED, 1 SPACE,
lname CLIPPED, COLUMN 35, city CLIPPED, ", " , state,
COLUMN 57, zipcode, COLUMN 65, phone
5-44
Report Writing
There are also built-in functions that you can use only in a REPORT routine.
The following table lists all the functions that you can use in a REPORT routine. (The letter superscripts indicate where their descriptions appear in this
manual.)
ASCIIa
AVG()rs
CLIPPEDa
COLUMNa
COUNT(*)rs
CURRENTa
DATEa
DATE()a
DAY()a
EXTEND()a
GROUPr
LENGTH()a
LINENOr
MAX()rs
MIN()rs
MDY()a
MONTH()a
PAGENOr
PERCENT(*)rs
SPACESr
SUM()rs
TIMEa
TODAYa
UNITSa
USINGa
WEEKDAY()a
WORDWRAPr
YEAR()a
You can use these functions only within the FORMAT section of a
REPORT routine. A description of these functions follows.
rs
You can use these functions only within the FORMAT section of a
REPORT routine or in INSERT, SELECT, or UPDATE statements elsewhere. They are described both in the following pages and in
Chapter 7.
Report Writing
5-45
Aggregates
Aggregates
Overview
Aggregate functions can summarize information in a report.
Syntax
[ GROUP ]
{ COUNT ( * ) | PERCENT ( * ) | { SUM | AVG | MIN | MAX } ( expr1 ) }
[ WHERE expr2 ]
Explanation
5-46
Report Writing
GROUP
COUNT ( * )
PERCENT ( * )
SUM
AVG
MIN
MAX
expr1
Aggregates
WHERE
is an optional keyword.
expr2
Note
The WHERE clause allows you to select among the rows passed to the report.
(See The SELECT Statement in Chapter 7 for the syntax of the WHERE
clause. See also the section Boolean Expressions in Chapter 2.)
Examples
This fragment of a REPORT statement uses the AFTER GROUP OF control
block and GROUP keyword to sum items within each order. The last PRINT
statement calculates the total price of each order, then adds a shipping
charge, and prints the result.
ON EVERY ROW
PRINT snum USING "###", COLUMN 10, manu_code, COLUMN 18,
description CLIPPED, COLUMN 38, quantity USING "###",
COLUMN 43, unit_price USING "$$$$.&&",
COLUMN 55, total_price USING "$$,$$$,$$$.&&"
AFTER GROUP OF number
SKIP 1 LINE
PRINT 4 SPACES, "Shipping charges for the order: ",
ship_charge USING "$$$$.&&"
PRINT 4 SPACES, "Count of small orders: ",
count(*) WHERE total_price < 200.00 USING "##,###"
SKIP 1 LINE
PRINT 5 SPACES, "Total amount for the order: ",
ship_charge + GROUP SUM(total_price) USING "$$,$$$,$$$.&&"
Report Writing
5-47
LINENO
LINENO
Overview
This expression has the value of the line number of the report line that
INFORMIX-4GL is currently printing.
Syntax
LINENO
Explanation
LINENO
is a required keyword.
Note
INFORMIX-4GL computes the current line number by calculating the number
of lines from the top of the page, including the TOP MARGIN.
Example
PRINT COLUMN 10, LINENO USING "Line <<<"
5-48
Report Writing
PAGENO
PAGENO
Overview
This expression has the value of the page number of the page that INFORMIX-4GL is currently printing.
Syntax
PAGENO
Explanation
PAGENO is a required keyword.
Note
You can use PAGENO in a PRINT statement in the PAGE HEADER or PAGE
TRAILER control block to number the pages of a report. (You can also use
PAGENO in other control blocks.)
Example
PAGE TRAILER
PRINT COLUMN 28, PAGENO USING "page <<<<"
Report Writing
5-49
SPACES
SPACES
Overview
This function returns a string of spaces. It is identical to a quoted string
of spaces.
Syntax
num-expr SPACE[S]
Explanation
num-expr is a number expression.
SPACES
Example
The following example is from a mailing label report.
FORMAT
ON EVERY ROW
PRINT fname, lname
PRINT company
PRINT address1
PRINT address2
PRINT city, ", " , state, 2 SPACES, zipcode
SKIP 2 LINES
5-50
Report Writing
WORDWRAP
WORDWRAP
Overview
The WORDWRAP function automatically wraps successive segments of long
character strings to the next line of a report. If the string is too long to fit in
the current line, lines are broken between words at temporary left and right
margins.
Syntax
char-expr WORDWRAP [ RIGHT MARGIN col ]
Explanation
char-expr
WORDWRAP
RIGHT
MARGIN
col
Notes
1. The char-expr can include printable ASCII characters, and the TAB
(ASCII 9), NEWLINE (ASCII 10), and RETURN (ASCII 13). A line break
is forced wherever char-expr contains a NEWLINE, a RETURN, or a
NEWLINE/ RETURN pair.
2. If you specify WORDWRAP RIGHT MARGIN in a report, the value of col
overrides the specified or default right margin, until all of char-expr has
been included in the report.
3. If you do not specify RIGHT MARGIN, the specified or default right
margin of the report remains in effect.
4. The left margin is the current printing column. The contents of char-expr
are displayed on as many lines as necessary between the temporary left
and right margins.
5. When displaying text with WORDWRAP, INFORMIX-4GL starts a new line
when a word plus the following space will not fit on the current line,
Report Writing
5-51
WORDWRAP
thereby assuring an even left margin when all words are separated by a
single space. When a string of spaces will not fit on a line, INFORMIX-4GL
prints enough of the spaces to fill the line, starts a new line, and prints the
rest of the spaces. INFORMIX-4GL expands a TAB down to enough spaces
to reach the next TAB stop. When the next TAB stop is past the right margin, INFORMIX-4GL expands just to the right margin, starts a new line,
and fetches the next word.
6. INFORMIX-4GL will maintain page discipline while printing data with
the WORDWRAP utility; it will print page footers, page trailers, page
numbers, and page headers.
Examples
The following PRINT statement specifies a left margin in column 10 and a
temporary right margin in column 70 to display the character string that is
stored in the variable called mynovel:
print column 10, mynovel WORDWRAP RIGHT MARGIN 70
If the data string is too long to fit in the first line, successive segments
are displayed in successive lines, until the last character of the string is
displayed.
Note: INFORMIX-OnLine supports additional data types. Refer to the INFORMIX-OnLine Programmers Manual for more information
5-52
Report Writing
Chapter
4GL Function
Library
Chapter Overview
6-2
Chapter Overview
This chapter describes the INFORMIX-4GL library functions. You can include
any of these functions in your 4GL source code. The 4GL compiler recognizes
the name of the library function and automatically includes the function in
your final program.
See also the section Expressions and Built-in Functions near the end of
Chapter 5 for a list of additional functions that you can include in 4GL
programs.
*
*
*
*
*
*
ARG_VAL
ARG_VAL
Overview
The arg_val function returns an argument of the command line that executes
your INFORMIX-4GL application program.
Syntax
arg_val ( expr )
Explanation
expr
is an integer expression.
Notes
1. You can design your 4GL program to expect or allow arguments after the
name of the program in the command line. Use the arg_val function to
retrieve individual arguments during program execution. The num_args
function can determine how many arguments followed the program
name on the command line.
The arg_val and num_args functions allow you to pass data to a compiled
4GL program from the command line that executes the program.
2. The function arg_val(n) returns the nth command-line argument as a
CHAR variable.
3. The value of expr must be between 0 and the value returned by num_args,
which is the number of command-line arguments. The value returned by
arg_val(0) is the name of your 4GL application program.
Examples
Suppose that your 4GL program called myprog can accept one or more usernames as command-line arguments. Each of the following command lines
includes four arguments:
myprog.4ge joe bob sue les
(C Compiler Version)
fglgo myprog joe bob sue les (Rapid Development System)
6-4
ARG_VAL
In either case, statements in the following program fragment use the arg_val
function to store in an array of CHAR variables all the names that the user
entered as command-line arguments:
. . .
DEFINE args ARRAY[8] OF CHAR(10),
i
SMALLINT
. . .
FOR i = 1 TO num_args()
LET args[i] = arg_val(i)
END FOR
. . .
Value
joe
bob
sue
les
Related Function
NUM_ARGS
6-5
ARR_COUNT
ARR_COUNT
Overview
The arr_count function returns the number of rows that are entered in a program array during or after an INPUT ARRAY statement.
Syntax
arr_count ( )
Notes
You can use arr_count to record the number of rows that are currently stored
in a program array. The arr_count function returns an integer value.
Example
The following function uses the value returned by arr_count to set the upper
limit of a FOR statement:
FUNCTION insert_items()
DEFINE counter SMALLINT
FOR counter = 1 TO arr_count()
INSERT INTO items
VALUES (p_items[counter].item_num,
p_orders.order_num,
p_items[counter].stock_num,
p_items[counter].manu_code,
p_items[counter].quantity,
p_items[counter].total_price)
END FOR
END FUNCTION
Related Functions
ARR_CURR, SCR_LINE
6-6
ARR_CURR
ARR_CURR
Overview
The arr_curr function returns the number of the row within the program
array that corresponds to the current screen array row, during or immediately after the INPUT ARRAY or DISPLAY ARRAY statement.
Syntax
arr_curr ( )
Notes
1. The current screen row is the row where the cursor is located at the beginning of a BEFORE ROW or AFTER ROW clause.
2. The arr_curr function returns an integer value. The first row of both the
program array and the screen array is numbered 1.
3. The library functions arr_curr and scr_line can return different values if
the program array is larger than the screen array.
6-7
ARR_CURR
Example
The following program segment tests the user input and rejects it if the customer is not from California. (See also the definition of the scr_line function
later in this chapter.)
DEFINE p_array ARRAY[90] OF RECORD
fname
CHAR(15),
lname
CHAR(15),
state
CHAR(2)
END RECORD,
pa_curr,
sc_curr SMALLINT
INPUT ARRAY p_array FROM scr_array.*
AFTER FIELD state
LET pa_curr = arr_curr()
LET sc_curr = scr_line()
IF upshift(p_array[pa_curr].state) != "CA" THEN
ERROR "Customers must be from California"
INITIALIZE p_array[pa_curr].* TO NULL
CLEAR scr_array[sc_curr].*
NEXT FIELD fname
END IF
END INPUT
Related Functions
ARR_COUNT, SCR_LINE
6-8
DOWNSHIFT
DOWNSHIFT
Overview
The downshift function returns a string value in which all uppercase characters in its argument are converted to lowercase.
Syntax
downshift ( str )
Explanation
str
Notes
1. Non-alphabetic characters in str are not altered by downshift.
2. You can use the downshift function in an expression (when such usage
is allowed), or you can assign the value returned by the function to a
variable.
3. The maximum length of str is 512 characters.
4. See also the DOWNSHIFT field attribute in Chapter 4.
Example
Suppose that the CHAR value GEAR_4 is stored in the program variable
p_string. The following statement takes the value of the expression
downshift(p_string), namely gear_4, and assigns it to another CHAR variable called d_str:
LET d_str = downshift(p_string)
Related Function
UPSHIFT
6-9
ERR_GET
ERR_GET
Overview
The err_get function returns a CHAR string that is the 4GL error message corresponding to its argument.
Syntax
err_get ( expr )
Explanation
expr
is an integer expression.
Notes
1. The expr is usually the global status variable.
2. The err_get function is most useful when you are developing a program.
The message that it returns is probably not helpful to the user of your
application.
Example
The LET statement in this segment assigns the text of a 4GL error message to
errtext, a CHAR variable:
IF status < 0 THEN
LET errtext = err_get(status)
END IF
Related Functions
ERR_PRINT, ERR_QUIT, STARTLOG
6-10
ERR_PRINT
ERR_PRINT
Overview
The err_print function displays on the Error line the INFORMIX-4GL error
message that corresponds to its argument.
Syntax
CALL err_print ( expr )
Explanation
expr
is an integer expression.
Notes
1. The expr is usually the global status variable.
2. The err_print function is most useful when you are developing a program. The message that it returns is probably not helpful to the user of
your application.
Example
This program segment sends any error message to the Error line:
IF status < 0 THEN
CALL err_print(status)
END IF
Related Functions
ERR_GET, ERR_QUIT, STARTLOG
6-11
ERR_QUIT
ERR_QUIT
Overview
The err_quit function prints on the Error line the INFORMIX-4GL error message specified by its argument, and then terminates the program.
Syntax
CALL err_quit ( expr )
Explanation
CALL
is a required keyword.
expr
is an integer expression.
Notes
1. The expr is usually the global status variable.
2. The err_quit function is most useful when you are developing a program.
The message that it returns is probably not helpful to the user of your
application.
Example
If an error occurs, these statements display the error message on the Error
line, and then terminate program execution:
IF status < 0 THEN
CALL err_quit(status)
END IF
Related Functions
ERR_GET, ERR_PRINT, STARTLOG
6-12
ERRORLOG
ERRORLOG
Overview
The errorlog function writes its argument in the current error log file.
Syntax
CALL errorlog ( str )
Explanation
CALL
is a required keyword.
str
Notes
1. The error log file is created by the startlog function.
2. You can use the errorlog function to identify errors in programs that you
are developing and to customize error handling.
Example
Here the errorlog function has a string constant argument:
CALL startlog("/usr/steve/error.log")
...
FUNCTION start_menu()
CALL errorlog("Entering start_menu function")
Related Function
STARTLOG
6-13
INFIELD
INFIELD
Overview
The infield function tests whether its argument is the identifier of the current
screen field.
Syntax
infield ( field-name )
Explanation
field-name is the name of a screen field.
Notes
1. The infield function is a Boolean function that returns the value true if
field-name is the name of the current screen field. Otherwise infield
returns the value false. (The ATTRIBUTES Section in Chapter 4
describes how to assign a field-name to a display field of a screen form.)
2. You can use infield during an INPUT or INPUT ARRAY statement to take
field-dependent actions.
3. Outside of an INPUT or INPUT ARRAY statement, infield returns a true
or false value, based on whether field-name corresponds to the screen
field that was current when the user terminated the most recent INPUT
or INPUT ARRAY statement. Be sure to specify the field-name, not the
field tag.
4. If the current field is a multiple-column field, infield returns true only if
field-name is the active name.
6-14
INFIELD
Example
The following INPUT statement uses infield with showhelp to give fielddependent help messages.
INPUT p_rec.* FROM sc_rec.*
ON KEY(CONTROL-B)
CASE
WHEN infield(field1)
CALL showhelp(101)
WHEN infield(field2)
CALL showhelp(102)
WHEN infield(field3)
CALL showhelp(103)
...
END CASE
END INPUT
Related Function
SCR_LINE
6-15
LENGTH
LENGTH
Overview
The length function returns the number of bytes in its string argument, after
deleting all trailing spaces.
Syntax
length ( str )
Explanation
str
Note
In a SELECT statement, with str the name of a character column, this function
returns the number of bytes in each CLIPPED value. (This is an exception to
the rule that library functions cannot occur in SQL statements.)
Examples
These statements center a report title on an 80-column page:
LET title = "Invoice for ", fname CLIPPED,
" ", lname CLIPPED
LET offset = (80 - length(title))/2
PRINT COLUMN offset, title
The next statement retrieves the value in column1 and the length in bytes of
the string in column2 (excluding trailing blanks).
SELECT column1, LENGTH(column2) FROM mytable
Note: INFORMIX-OnLine supports additional functionality. Refer to the INFORMIX-OnLine Programmers Manual for more information.
6-16
NUM_ARGS
NUM_ARGS
Overview
The num_args function returns the number of command-line arguments
with which your INFORMIX-4GL program is run.
Syntax
num_args ( )
Note
The num_args function returns an integer, indicating the number of command-line arguments that followed the name of your program when the user
invoked it. (You can use the arg_val library function to retrieve individual
arguments.)
Example
Each of the following command lines includes three arguments:
myprog.4ge kim sue joe
fglgo myprog kim sue joe
(C Compiler Version)
(Rapid Development System)
After either of these command lines, num_args sets 3 as the upper limit of i
in the FOR statement of the program fragment that follows.
DEFINE args ARRAY[8] OF CHAR(10),
i
SMALLINT
FOR i = 1 TO num_args()
LET args[i] = arg_val(i)
END FOR
Related Function
ARG_VAL
6-17
SCR_LINE
SCR_LINE
Overview
The scr_line function returns the number of the current screen row within its
screen array during a DISPLAY ARRAY or INPUT ARRAY statement.
Syntax
scr_line ( )
Notes
1. The current screen row is the row where the cursor is located at the beginning of a BEFORE ROW or AFTER ROW clause.
2. The first row of both the program array and of the screen array is numbered 1.
3. The library functions scr_line and arr_curr can return different values if
the program array is larger than the screen array.
6-18
SCR_LINE
Example
The following program segment tests the user input and rejects it if the customer is not from Alaska. (See also the definition of the arr_curr library function earlier in this chapter.)
DEFINE p_array ARRAY[90] OF RECORD
fname
CHAR(15),
lname
CHAR(15),
state
CHAR(2)
END RECORD,
pa_curr,
sc_curr SMALLINT
INPUT ARRAY p_array FROM scr_array.*
AFTER FIELD state
LET pa_curr = arr_curr()
LET sc_curr = scr_line()
IF upshift(p_array[pa_curr].state) != "AK" THEN
ERROR "Customers must be from Alaska"
INITIALIZE p_array[pa_curr].* TO NULL
CLEAR scr_array[sc_curr].*
NEXT FIELD fname
END IF
END INPUT
Related Functions
ARR_COUNT, ARR_CURR
6-19
SET_COUNT
SET_COUNT
Overview
The set_count function tells INFORMIX-4GL the number of filled rows in a
program array.
Syntax
CALL set_count ( expr )
Explanation
CALL
is a required keyword.
expr
is an integer expression.
Note
Before you use an INPUT ARRAY WITHOUT DEFAULTS or a DISPLAY ARRAY
statement, you must call the set_count function with an integer argument
that specifies the total number of filled rows in the program array. This function supplies an initial value for the arr_count library function to return.
Example
CALL set_count(23)
INPUT ARRAY p_array WITHOUT DEFAULTS
FROM s_array.*
Related Functions
ARR_COUNT, ARR_CURR
6-20
SHOWHELP
SHOWHELP
Overview
The showhelp function displays a help screen. When the user clears the help
screen, INFORMIX-4GL restores the previous screen.
Syntax
CALL showhelp ( expr )
Explanation
CALL
is a required keyword.
expr
is an integer expression.
Notes
1. When called with an argument that is the number of a help message in the
help file named in an OPTIONS statement, showhelp clears the screen,
displays the help message, and presents the user with a menu of help
options.
2. If the help message is too long to fit on one screen, a Screen option of the
HELP Menu allows the user to display the next part of the message.
3. When the user selects Resume from the HELP Menu, the help screen is
cleared, and the previous screen is restored.
4. For information on setting up a help file, see the description of the
mkmessage utility in Appendix E, or the section entitled Creating Help
Messages in Chapter 8 of the INFORMIX-4GL User Guide.
6-21
SHOWHELP
Example
The following example uses infield with showhelp to display field-dependent help messages.
INPUT p_rec.* FROM sc_rec.*
ON KEY(CONTROL-B)
CASE
WHEN infield(field1)
CALL showhelp(101)
WHEN infield(field2)
CALL showhelp(102)
WHEN infield(field3)
CALL showhelp(103)
...
END CASE
END INPUT
Related Function
INFIELD
6-22
STARTLOG
STARTLOG
Overview
The startlog function opens an error log file.
Syntax
CALL startlog ( filename )
Explanation
CALL
is a required keyword.
filename
Notes
1. If filename does not exist, startlog creates it. If the file exists, startlog opens
it, and positions the file pointer so that subsequent error messages are
appended to it.
2. If you do not want the error log file to reside in the current directory, you
must specify a full pathname.
3. After you call the startlog function, a record of every subsequent error
that occurs during the execution of your program is written to the error
log file.
4. The error record consists of the date, time, source-module name and line
number, error number, and error message.
5. You can write your own messages in the error log file by using the
errorlog function.
6-23
STARTLOG
Example
In the following example, a CALL statement invokes the startlog library function, specifying the name of the error log file in a quoted string that includes
a pathname and file extension.
...
CALL startlog("/usr/steve/error.log")
...
FUNCTION start_menu()
CALL errorlog("Entering start_menu function")
...
Related Function
ERRORLOG
6-24
UPSHIFT
UPSHIFT
Overview
The upshift function returns a string in which all lowercase characters in its
argument are converted to uppercase characters.
Syntax
upshift ( str )
Explanation
str
Notes
1. Non-alphabetic characters in str are not altered.
2. You can use the upshift function in an expression (when such usage is
allowed) or in a statement that assigns the value returned by the function
to a program variable.
3. The maximum length of str is 512 characters.
4. See also the UPSHIFT field attribute in Chapter 4.
Example
Here the CHAR variables u_str and str are equivalent, except that u_str substitutes uppercase letters for any lowercase letters in str.
LET u_str = upshift(str)
DISPLAY u_str
Related Function
DOWNSHIFT
6-25
UPSHIFT
6-26
Chapter
INFORMIX-4GL
Statement Syntax
Types of Statements 5
Statements Supported Only on INFORMIX-SE 6
Statements Supporting INFORMIX-OnLine
Enhancements 7
INFORMIX-4GL Extensions to ANSI Syntax 7
SELECT Statement 8
DECLARE Statement 9
UPDATE Statement 9
GRANT Statement 9
CREATE TABLE Statement 10
CREATE VIEW Statement 10
Definition of Statements 11
ALTER INDEX 12
ALTER TABLE ( O ) 14
BEGIN WORK 18
CALL 19
CASE 21
CLEAR 23
CLOSE 25
CLOSE DATABASE 27
CLOSE FORM 28
CLOSE WINDOW 30
COMMIT WORK 31
CONSTRUCT 32
CONTINUE 38
CREATE AUDIT 39
CREATE DATABASE ( O )
CREATE INDEX 44
CREATE SYNONYM 47
7
41
CREATE TABLE ( O ) 49
CREATE VIEW 57
CURRENT WINDOW 60
DATABASE 62
DECLARE 64
DEFER 69
DEFINE 71
DELETE 73
DISPLAY 75
DISPLAY ARRAY 79
DISPLAY FORM 83
DROP AUDIT 85
DROP DATABASE 86
DROP INDEX 88
DROP SYNONYM 89
DROP TABLE 90
DROP VIEW 91
ERROR 92
EXECUTE 94
EXIT 96
FETCH 98
FINISH REPORT 101
FLUSH 102
FOR 104
FOREACH 106
FREE ( O ) 109
FUNCTION 110
GLOBALS 112
GOTO 114
GRANT 115
IF 118
INITIALIZE 120
INPUT 122
INPUT ARRAY 129
INSERT 138
LABEL 141
LET 142
LOAD 143
LOCK TABLE 146
MAIN 148
MENU 149
MESSAGE 154
OPEN 156
7-2
190
228
7-3
7-4
Types of Statements
Twelve types of INFORMIX-4GL statements are available:
REPORT
GLOBALS
Assignment Statements
INITIALIZE
LET
IF
LABEL
RETURN
RUN
SLEEP
WHENEVER
WHILE
INPUT
INPUT ARRAY
MENU
MESSAGE
OPEN FORM
OPEN WINDOW
OPTIONS
PROMPT
SCROLL
START REPORT
7-5
DROP DATABASE
DROP INDEX
DROP SYNONYM
DROP TABLE
DROP VIEW
RENAME COLUMN
RENAME TABLE
SET EXPLAIN
UPDATE STATISTICS
SELECT
UNLOAD
UPDATE
OPEN
PUT
SET EXPLAIN
PREPARE
ROLLBACK WORK
ROLLFORWARD DATABASE
START DATABASE
VALIDATE
are listed here. They are identified in the following descriptions with an ( O )
after the name of the statement. Do not include the (O) when you type the
statement.
ALTER TABLE ( O )
CREATE DATABASE ( O )
CREATE TABLE ( O )
FREE ( O )
SET LOCK MODE ( O )
(C Compiler Version)
When you compile with the -ansi flag or with the DBANSIWARN environment variable set, SQL statements that include Informix extensions to ANSI
syntax cause warning messages to be written to the .err file. (See Appendix C
for more information about DBANSIWARN.)
Note: You cannot use the -ansi flag with i4gl or r4gl.
When you run a compiled program after you have set DBANSIWARN, any
extension to ANSI syntax in an SQL statement causes the characters
SQLAWARN[1] and SQLAWARN[6] to be set to W.
7-7
FLUSH
FREE
GRANT
LOAD
LOCK TABLE
PUT
RECOVER TABLE
RENAME COLUMN
RENAME TABLE
REVOKE
ROLLFORWARD DATABASE
SET EXPLAIN
SET LOCK MODE
START DATABASE
UNLOAD
UNLOCK TABLE
UPDATE STATISTICS
Note: The BEGIN WORK, LOAD, and UNLOAD statements generate warnings at
compile time only.
The next section lists keywords or features of INFORMIX-4GL that are extensions to ANSI standard syntax. A warning is generated if you include these
keywords or features in an SQL statement, and then initiate Informix extension checking with the -ansi flag or with the DBANSIWARN environment
variable.
SELECT Statement
The following keywords or features are Informix extensions to the SELECT
statement:
Column labels
Column subscripts
Numbers as position indicators (for example, in a GROUP BY clause)
INTO TEMP clause
MATCHES keyword
OUTER keyword
UNIQUE keyword
UNITS keyword
7-8
INSERT
SCROLL
WITH HOLD
FOR UPDATE clause
UPDATE Statement
Specifying multiple columns in an UPDATE statement is an extension to the
ANSI standard.
GRANT Statement
The following keywords are extensions to the GRANT statement:
AS
CONNECT
DBA
RESOURCE
7-9
Manual.
DISTINCT keyword
IN keyword
UNIQUE CONSTRAINT keywords
TEMP keyword
The following data types:
DATE
MONEY
SERIAL
SMALLFLOAT
DATETIME
INTERVAL
Use of the CREATE TABLE statement in INFORMIX-4GL always generates a
warning when Informix extension checking is initiated. The ANSI standard
requires that the CREATE TABLE statement be issued within the CREATE
SCHEMA AUTHORIZATION statement. For more information about the
CREATE SCHEMA AUTHORIZATION statement, refer to the INFORMIX-SQL
Reference Manual.
7-10
Definition of Statements
Definition of Statements
The following section describes the INFORMIX-4GL statements. The statements appear in alphabetical order. (See also Chapter 5, which describes
additional statements that can only appear in the FORMAT section of a
REPORT routine, such as NEED, PAUSE, PRINT, PRINT FILE, and SKIP.)
7-11
ALTER INDEX
ALTER INDEX
Overview
Use the ALTER INDEX statement to cluster a table in the order of an existing
index, or to release an index from the clustering attribute.
Syntax
ALTER INDEX index-name TO [ NOT ] CLUSTER
Explanation
ALTER INDEX
index-name
TO
is a required keyword.
NOT
is an optional keyword.
CLUSTER
is a required keyword.
Notes
1. The TO CLUSTER option causes INFORMIX-4GL to reorder the rows in the
physical table to agree with the order of index-name. Reordering causes
the entire file to be rewritten. This process may take a long time and
requires sufficient disk space to maintain two copies of the table. After all
rows have been copied to the reordered table, the original version of the
table is automatically deleted, releasing the additional disk space.
2. Since there can be only one clustered index per table, you must use the
NOT option to release the cluster attribute from one index before assigning it to another. The NOT option does not affect the physical table; it
merely drops the cluster attribute on index-name from the system catalogs.
3. When INFORMIX-4GL executes ALTER INDEX with the TO CLUSTER
option, it locks the table in EXCLUSIVE MODE. If some other process is
using the table to which index-name belongs, INFORMIX-4GL cannot execute ALTER INDEX with the TO CLUSTER option and returns an error.
4. You cannot use a ROLLBACK statement to undo the effect of the ALTER
INDEX statement.
7-12
ALTER INDEX
5. As rows are added and deleted, you can expect the benefit of an earlier
clustering to disappear. You can recluster the table by issuing another
ALTER INDEX TO CLUSTER statement on the clustered index.
6. You do not need to drop a cluster index before issuing another ALTER
INDEX TO CLUSTER statement on a currently clustered index.
Example
The following example creates two indexes on the orders table and clusters
the physical table in ascending order on the customer_num column. Later,
the example clusters the physical table in ascending order on the order_num
column.
CREATE UNIQUE INDEX ix_ord
ON orders (order_num)
CREATE CLUSTER INDEX ix_cust
ON orders (customer_num)
...
ALTER INDEX ix_cust TO NOT CLUSTER
ALTER INDEX ix_ord TO CLUSTER
Related Statement
CREATE INDEX
7-13
ALTER TABLE ( O )
ALTER TABLE ( O )
Overview
Use the ALTER TABLE statement to add a column to a table, delete a column
from a table, modify the data type of a column, add a UNIQUE CONSTRAINT
to a column or a composite list of columns, or drop a UNIQUE CONSTRAINT
associated with a column or composite list of columns.
Syntax
ALTER TABLE table-name { ADD ( newcol-name newcol-type [NOT NULL]
[ UNIQUE [ CONSTRAINT constr-name ] ] [ , . . . ] )
[ BEFORE oldcol-name ]
| DROP ( oldcol-name [ , . . . ] )
| MODIFY ( oldcol-name newcol-type [ NOT NULL ] [ , . . . ] )
| ADD CONSTRAINT UNIQUE ( oldcol-name [ , . . . ] )
[ CONSTRAINT constr-name ]
| DROP CONSTRAINT ( constr-name [ , . . . ] ) } [ , . . . ]
Explanation
7-14
ALTER TABLE
table-name
ADD
newcol-name
newcol-type
is either the data type of the column you are adding or the
data type of the column you are modifying.
NOT NULL
UNIQUE
is a keyword specifying that the column or composite column list accepts only unique values.
CONSTRAINT
constr-name
BEFORE
oldcol-name
DROP
ALTER TABLE ( O )
MODIFY
ADD
CONSTRAINT
DROP
CONSTRAINT
Notes
1. In a MODE ANSI database, the name of a table is qualified by the owner of
the table (owner. table-name). You must specify owner when you refer to a
table owned by another user.
The use of the prefix owner. is optional in a non-MODE ANSI database.
INFORMIX-4GL does check the accuracy of owner, however, if you include
it in a statement. See the section Owner Naming in Chapter 3 for more
information.
2. You can use one or more of the ADD, DROP, MODIFY, ADD CONSTRAINT,
or DROP CONSTRAINT clauses, and you can place them in any order. Use
a comma ( , ) to separate clauses. The actions are performed in the order
specified. If any of the actions fail, the entire operation is canceled.
3. You cannot add a SERIAL column to a table. You must create a SERIAL column with the CREATE TABLE statement. You cannot add it with the
ALTER TABLE statement.
4. You can modify an existing column that formerly permitted NULLs to be
NOT NULL, provided that it does not already contain any NULL values.
Specify MODIFY with the same oldcol-name and data type and the NOT
NULL keywords.
5. You can modify an existing column that did not permit NULLs to permit
NULLs. Specify MODIFY with the oldcol-name and the existing data type
and omit NOT NULL.
6. When you add a new column to an existing table, it is filled with NULL
values. Therefore, you cannot use the NOT NULL option or specify a
UNIQUE CONSTRAINT when you add a column unless the table contains
no data.
7. If you change the data type of an existing column, all data are converted
to the new data type, including number to character and character to
number (if the characters represent numbers).
When there is a UNIQUE CONSTRAINT, however, conversion takes place
only if it does not violate the constraint. If a data conversion would result
in duplicate values (by changing FLOAT to SMALLFLOAT, for example, or
INFORMIX-4GL Statement Syntax
7-15
ALTER TABLE ( O )
by truncating CHAR values), then the ALTER TABLE command fails. You
will receive error 212 (Cannot add index) and ISAM error 100 (There
is already a record with the same value in a unique
index).
8. When you drop a column that is part of a multiple-column constraint,
you automatically drop the corresponding UNIQUE CONSTRAINT.
9. You can use ALTER TABLE with the ADD and CONSTRAINT keywords to
specify a UNIQUE CONSTRAINT on a new or existing column, or on a
composite list of columns. The following rules apply when adding a
UNIQUE CONSTRAINT:
10. To drop an existing constraint, specify DROP CONSTRAINT and the name
of the constraint. If no constr-name name was specified when the constraint was created, the system generated the name. You can query the
sysconstraints system catalog for the names (including the owner) of
constraints.
11. If you own the table or have alter permission on the table, you can create
a constraint on the table and specify yourself as the owner. If you have
DBA permission, you can create constraints for other users.
12. You must own table-name, have DBA privilege, or be granted ALTER permission to use ALTER TABLE.
13. Altering a table on which a view depends may invalidate the view.
14. You cannot use a ROLLBACK WORK statement to undo an ALTER TABLE
statement.
15. The keyword DISTINCT is a synonym for UNIQUE.
7-16
ALTER TABLE ( O )
Examples
ALTER TABLE items
ADD (item_weight DECIMAL(6,2)
BEFORE total_price)
ALTER TABLE items
DROP (total_price)
ALTER TABLE items
MODIFY (manu_code CHAR(4))
ALTER TABLE manufact
ADD CONSTRAINT UNIQUE (manu_name) CONSTRAINT con_name
ALTER TABLE manufact
DROP CONSTRAINT (con_name)
Since they refer to the same table, you can combine the first two examples
into a single statement:
ALTER TABLE items
ADD (item_weight DECIMAL(6,2) BEFORE total_price),
DROP (total_price)
Related Statements
CREATE TABLE, CREATE INDEX, RENAME COLUMN, RENAME TABLE
7-17
BEGIN WORK
BEGIN WORK
Overview
Use the BEGIN WORK statement to start a transaction (a sequence of database
operations that are terminated by the COMMIT WORK or ROLLBACK WORK
statement) in a non-MODE ANSI database. See the section Transactions in
Chapter 3 for a description of transactions.
Syntax
BEGIN WORK
Explanation
BEGIN WORK
Notes
1. Each row affected by an UPDATE, DELETE, or INSERT statement during a
transaction is locked and remains locked throughout the transaction. A
transaction that contains a large number of such statements, or that contains statements affecting a large number of rows, may exceed the limits
placed by your operating system on the maximum number of simultaneous locks. If you encounter this error, you may need to lock the entire
table immediately after beginning the transaction. See the section Locking in Chapter 3 for a more detailed description of table-level and rowlevel locking in INFORMIX-4GL.
2. Do not use the BEGIN WORK statement with a database CREATEd or
STARTed as MODE ANSI. In a program that accesses a MODE ANSI database, the BEGIN WORK statement generates a run-time error unless it
appears immediately after one of the following statements:
CREATE DATABASE
DATABASE
START DATABASE
COMMIT WORK
ROLLBACK WORK
Related Statements
COMMIT WORK, ROLLBACK WORK
7-18
CALL
CALL
Overview
Use the CALL statement to invoke a function.
Syntax
CALL function ( [ argument-list ] ) [ RETURNING variable-list ]
Explanation
CALL
is a required keyword.
function
argument-list
RETURNING
variable-list
Notes
1. You can use the CALL statement to call INFORMIX-4GL functions and C
language functions. See C Functions in Chapter 2 for the rules on using
such functions in INFORMIX-4GL programs.
2. The arguments specified in argument-list will be passed by value.
3. You can define INFORMIX-4GL functions in the same source file as the
MAIN program block, or you can compile them separately and link them
later to the MAIN program block.
Example
CALL statistics(rec.*) RETURNING mean, std_dev
7-19
CALL
Related Statements
DEFINE, FUNCTION
7-20
CASE
CASE
Overview
Use the CASE statement to select a sequence of statements, depending on the
current value of an expression.
Syntax
CASE [ ( expr ) ]
WHEN { expr | Boolean-expr }
statement
...
[ EXIT CASE ]
...
WHEN { expr | Boolean-expr }
statement
...
[ EXIT CASE ]
...
...
[ OTHERWISE ]
statement
...
[ EXIT CASE ]
...
END CASE
Explanation
CASE
is a required keyword.
expr
WHEN
is a required keyword.
Boolean-expr
statement
is an INFORMIX-4GL statement.
EXIT CASE
OTHERWISE
END CASE
7-21
CASE
Notes
1. The CASE statement is equivalent to a set of nested IF statements.
2. If you use the OTHERWISE option, it must be the last in the list.
3. If the optional parenthesized expression following the CASE keyword is
missing, you must follow the WHEN keyword with a Boolean expression.
If there is an expression following the CASE keyword, you must follow
the WHEN keyword with an expression that evaluates to the same data
type.
4. There is an implied EXIT CASE statement at the end of each sequence of
statements following a WHEN clause. Program control will pass to the
sequence of statements following the END CASE statement.
Example
LABEL question:
...
CASE
WHEN answer MATCHES "[Yy]"
CALL process()
WHEN answer MATCHES "[Nn]"
CALL abort()
OTHERWISE
CALL retry()
END CASE
Related Statements
IF, EXIT
7-22
CLEAR
CLEAR
Overview
Use the CLEAR statement to clear the whole screen, a window, all fields in a
screen form, or a set of fields.
Syntax
CLEAR { SCREEN | WINDOW window-name | FORM | field-list }
Explanation
CLEAR
is a required keyword.
SCREEN
WINDOW
window-name
is the name of the window that you want to clear, or the keyword SCREEN.
FORM
field-list
Notes
1. The CLEAR statement does not change the value of any variable. It simply
clears the display from the region indicated.
2. The CLEAR SCREEN statement makes the screen the current window and
clears it.
3. The CLEAR WINDOW statement clears the specified window, retaining
any border. (The specified window need not be the current window. This
option does not affect which window is the current window.)
4. If you specify SCREEN as the window-name in a CLEAR WINDOW statement, INFORMIX-4GL clears the screen, except for the area occupied by
any open windows.
5. CLEAR FORM and CLEAR field-list apply to the form in the current
window.
7-23
CLEAR
Examples
CLEAR fname, lname, address1,
city, state, zipcode
CLEAR FORM
CLEAR SCREEN
CLEAR WINDOW win1
CLEAR WINDOW SCREEN
7-24
CLOSE
CLOSE
Overview
Use the CLOSE statement when you no longer need to refer to the active set
of a SELECT cursor, or when you want to flush the insert buffer and close an
INSERT cursor.
Syntax
CLOSE cursor-name
Explanation
CLOSE
is a required keyword.
cursor-name
Notes
1. If cursor-name is associated with a SELECT statement, the CLOSE statement
puts the cursor in a closed state and leaves the active set undefined.
2. After you CLOSE a SELECT cursor, you cannot execute a FETCH statement
until you reopen the cursor.
3. If cursor-name is associated with an INSERT statement, the CLOSE statement flushes any rows in the buffer into the database (writes to disk) and
closes the cursor.
4. After you CLOSE an INSERT cursor, you cannot execute a PUT or FLUSH
statement until after you use an OPEN command to reopen the cursor.
5. The global variables status (whose value is taken from the SQLCA.SQLCODE ) and SQLCA. SQLERRD [3] indicate the result of each FLUSH and
CLOSE statement for an INSERT cursor. If INFORMIX-4GL successfully
inserts the buffered rows into the database, it sets status to zero, and
SQLCA. SQLERRD [3] to the number of rows that were inserted into the
database.
If INFORMIX-4GL encounters an error while inserting the buffered rows
into the database, it sets status to a negative number (specifically, the
number of the error message) and sets variable SQLCA. SQLERRD [3] to the
number of rows successfully inserted into the database. Any buffered
INFORMIX-4GL Statement Syntax
7-25
CLOSE
rows following the last successfully inserted row are discarded. In this
case, the cursor remains open.
6. Although the COMMIT WORK and ROLLBACK WORK statements CLOSE
all open cursors (except cursors declared WITH HOLD ), do not use them
for this purpose. You should explicitly CLOSE each INSERT cursor before
committing the work, so that you can verify that the insertion was
successful.
7. INFORMIX-4GL does not provide a global variable containing the total
number of rows successfully inserted into the database with an INSERT
cursor. If you want to know the total number of inserts performed, you
must set a counter in your program and increment it upon each PUT
statement.
8. If your database is not MODE ANSI but has transactions, you must issue
the CLOSE statement within a transaction.
Examples
CLOSE query_cursor
CLOSE icurs
Related Statements
DECLARE, FETCH, FLUSH, OPEN, PUT
7-26
CLOSE DATABASE
CLOSE DATABASE
Overview
Use the CLOSE DATABASE statement to close the current database.
Syntax
CLOSE DATABASE
Explanation
CLOSE DATABASE
Notes
1. Following the CLOSE DATABASE statement, the only legal SQL statements
are CREATE DATABASE, DATABASE, DROP DATABASE, ROLLFORWARD
DATABASE, and START DATABASE.
2. Issue the CLOSE DATABASE statement before you DROP the current
database.
3. The CLOSE DATABASE statement cannot appear in a multi-statement
PREPARE.
Example
CLOSE
DATABASE
Related Statements
CREATE DATABASE, DROP DATABASE, ROLLFORWARD DATABASE,
START DATABASE
7-27
CLOSE FORM
CLOSE FORM
Overview
Use the CLOSE FORM statement to release the memory required for a screen
form.
Syntax
CLOSE FORM form-name
Explanation
CLOSE FORM
form-name
Notes
1. After you execute the CLOSE FORM statement, form-name is no longer
associated with a screen form. Executing a subsequent DISPLAY FORM
statement will give an error message.
2. If you execute a new OPEN FORM statement with the same form-name,
INFORMIX-4GL will close the existing form before opening the new one.
3. When you execute the OPEN FORM statement, the compiled form is
loaded into memory, where it remains until you execute a CLOSE FORM
statement for that form. If you have displayed another form and wish to
regain the memory allocated to the first form, you can execute CLOSE
FORM on the old form.
4. The CLOSE FORM statement affects memory use only and does not affect
the logic of the program. Since allocating memory and reading a form
from the disk takes time, you should leave forms open that you use
repeatedly.
5. The CLOSE WINDOW statement closes any open form in the specified
window, releasing the memory allocated to that form.
Example
CLOSE FORM order_entry
7-28
CLOSE FORM
Related Statements
CLOSE WINDOW, DISPLAY FORM, FREE, OPEN FORM
7-29
CLOSE WINDOW
CLOSE WINDOW
Overview
Use the CLOSE WINDOW statement to close a window.
Syntax
CLOSE WINDOW window-name
Explanation
CLOSE WINDOW
window-name
Notes
1. When you close a window, INFORMIX-4GL frees all resources used by the
window, including forms, and restores the underlying display.
2. When you close the current window, the next window on the stack
becomes the current window. When you close any other window, INFORMIX-4GL simply removes the window from the stack, leaving the current
window unchanged. In both cases, INFORMIX-4GL restores the underlying display.
3. If you close a window that is currently being used for input, INFORMIX-4GL generates a run-time error. For example, closing the current
window in the middle of a DISPLAY ARRAY, INPUT, INPUT ARRAY, or
MENU statement produes a run-time error.
4. You cannot issue a CLOSE WINDOW screen command.
Example
CLOSE WINDOW win 1
Related Statements
CLEAR WINDOW, CURRENT WINDOW, OPEN WINDOW, OPTIONS
7-30
COMMIT WORK
COMMIT WORK
Overview
Use the COMMIT WORK statement to commit all modifications made to the
database during a transaction.
Syntax
COMMIT WORK
Explanation
COMMIT WORK
Notes
1. Use the COMMIT WORK statement when you are satisfied with all
changes made during the transaction to the database. Use the ROLLBACK
WORK statement if you do not want to commit modifications made during the transaction to the database.
2. The COMMIT WORK statement closes all open cursors, except cursors
declared WITH HOLD. Do not use the COMMIT WORK statement within a
FOREACH loop.
3. The COMMIT WORK statement releases all row and table locks.
4. See the section Transactions in Chapter 3 for details of how the the
COMMIT WORK statement works.
Related Statements
BEGIN WORK, ROLLBACK WORK
7-31
CONSTRUCT
CONSTRUCT
Overview
Use the CONSTRUCT statement to create a CHAR variable that contains the
Boolean expression constructed from a screen-generated query by example.
The resulting CHAR variable contains conditions for the WHERE clause of a
SELECT statement, corresponding to user-specified selection criteria.
Syntax
CONSTRUCT
{ BY NAME char-variable ON column-list |
char-variable ON column-list FROM
{ field-list | screen-record [ [ n ] ].* } [ , . . . ] }
[ ATTRIBUTE ( attribute-list) ]
Explanation
7-32
CONSTRUCT
is a required keyword.
BY NAME
char-variable
ON
column-list
FROM
field-list
screen-record
[n]
ATTRIBUTE
(attribute-list)
CONSTRUCT
Notes
1. The CONSTRUCT statement allows the user to enter query-by-example
search parameters in a screen form, with this syntax:
Symbol
=
>
<
>=
<=
<>
:
..
*
?
|
Name
equal to
greater than
less than
greater than or equal to
less than or equal to
not equal to
range
range
Data Types
all
all
all
all
all
all
all
DATETIME
and
INTERVAL
CHAR
CHAR
all
Pattern
=x
>x
<x
>=x
<=x
<>x
x:y
x..y
*x, x*, *x*
?x, x?, ?x?, x??
a|b...
Explanation of Symbols
The equal sign ( = ) is the default query symbol for non-character columns, and for character columns in which the user enters a search
value that does not contain wildcards:
char-column = "value"
If the user enters a character value that contains a wildcard character
(either * or ? ), then MATCHES is the default query symbol:
char-column MATCHES "value"
The equal ( = ) sign with no value searches for a database row that contains a NULL column. Enter = * to find a row that contains a column
with only an asterisk.
The x means any value of the appropriate data type for the search field.
Enter the value immediately after any one of the first six query symbols in the preceding table. Do not leave a space between the query
symbol and the value.
The symbols >, <, > =, and < = imply an ordering of the data in the column. For CHAR data, greater than means later in the ASCII collating
7-33
CONSTRUCT
Asterisk ( * ) is the string wildcard, representing zero or more characters. An *ts* search value in the field corresponding to the lname
column of the customer table would find two names, Watson and
Albertson. An S* search value in the same field would find Sadler and
Sipes. An *er search value would find the four names Sadler, Miller,
Jaeger, and Baxter.
The symbo| between values a and b means the logical OR. In the field
corresponding to the column customer_num, this entry retrieves any
of three numbers: 102|105|118
2. You can use the BY NAME option when the field names on the screen form
have the same names as the corresponding column names in column-list.
If you do not, you must specify a screen record or name the fields explicitly in field-list.
3. The CONSTRUCT statement is terminated when the user enters ESC or the
key specified as the Accept key in the OPTIONS statement. For single-item
CONSTRUCTs, pressing RETURN is equivalent to pressing the Accept key,
unless the INPUT WRAP option is in effect. For multiple-item CONSTRUCTs, a RETURN after the last item is equivalent to pressing the Accept
key, unless INPUT WRAP is in effect.
4. By default, both ESC and Interrupt exit from CONSTRUCT statements. If
the DEFER INTERRUPT statement has been executed, an Interrupt sets the
global variable int_flag to nonzero and terminates the CONSTRUCT statement (but not the 4GL program). Otherwise, an Interrupt causes an
immediate program stop.
7-34
CONSTRUCT
5. In addition to the RETURN, ESC, ARROW, and Interrupt keys, the user can
employ the following keys for editing during a CONSTRUCT statement:
CTRL-A
CTRL-D
CTRL-H
CTRL-L
CTRL-R
CTRL-X
6. The user can query for only those fields displayed on the screen that you
have specified in the FROM clause or implied in the BY NAME clause. The
number of fields in the FROM clause must be the same as the number of
columns in the ON clause. The order of fields in the FROM clause must
match the order of columns in the ON clause. INFORMIX-4GL constructs
char-variable by associating the column name in the ON clause with the
search condition that the user entered into the corresponding field in the
FROM clause.
7. The UPSHIFT and DOWNSHIFT attributes work during a CONSTRUCT
statement. The COMMENTS attribute works, but with the following
restriction: if a field that displays a comment is too short to hold the
search criteria that the user enters, INFORMIX-4GL opens a work space on
the Comment line, erasing any comment that is displayed.
8. If the column names in a CONSTRUCT BY NAME statement are associated
with field names in a screen array, the construct takes place in the first row
of the screen array.
If you want to use screen-array field names in the FROM clause of a
CONSTRUCT statement, then you must use the notation screen-record [n ].
field-name to specify the row in which the construct takes place.
9. You can use the information stored in char-variable in the WHERE clause of
a PREPAREd SELECT statement to retrieve a set of rows from the database.
10. A compile-time error results if you use the BY NAME clause when the column names include an owner name. You must use the FROM clause to
specify table aliases in the field-list when any column names contain an
owner name.
7-35
CONSTRUCT
11. When you use screen-record.* or table.* as shorthands for explicit lists, be
sure that the order of the fields implied in the screen-record.* notation corresponds to the order of the columns implied in the screen-record.*
notation. The order of the fields in screen-record.* depends on its definition
in the screen form.
The order of the columns in table.* depends on the order in the syscolumns system catalog at the time you compile your program. If you have
used ALTER TABLE to change the order or number of the columns in table
since you compiled your program, you may need to modify your program and the forms that depend on it.
12. Any screen attributes specified in attribute-list apply to all the fields in
field-list or screen-record.
13. If you use the ATTRIBUTE clause, none of the default attributes listed in
syscolatt or in the form specification file for fields in field-list or screenrecord apply. The attribute-list temporarily overrides any attributes specified in an OPTIONS, DISPLAY FORM, or OPEN WINDOW statement for
these fields.
14. These keywords can appear in the ATTRIBUTE clause:
WHITE = NORMAL
YELLOW = BOLD
MAGENTA = BOLD
RED = BOLD
CYAN = DIM
GREEN = DIM
BLUE = DIM
BLACK = INVISIBLE
REVERSE
BLINK
UNDERLINE
You can specify zero or one of the keywords in the left-hand columns, and
from zero to three from the right-hand column (but some terminals may
not support some combinations). On color terminals, NORMAL is interpreted as WHITE, BOLD as RED, DIM as BLUE, and INVISIBLE as BLACK.
Do not include the equal ( = ) sign, which in this table shows the effect on
monochrome terminals of keywords that specify color.
These keywords cannot produce the effects indicated unless the termcap
or terminfo files and the physical terminals support the attribute. (See
Appendix I, Modifying termcap and terminfo.)
15. On UNIX systems that use terminfo files rather than termcap, INFORMIX-4GL does not support attributes that specify colors, and the only
valid attribute-list keywords are REVERSE and UNDERLINE.
16. You must first execute OPEN FORM or OPEN WINDOW WITH FORM before
you can use the CONSTRUCT statement.
7-36
CONSTRUCT
Example
The following program fragment illustrates the use of the CONSTRUCT statement to specify the search condition of a WHERE clause. The cursor_1 cursor
is DECLAREd and used to execute the query.
CONSTRUCT query_1
ON order_num, customer_num, order_date,
ship_date
FROM order_num, customer_num, order_date,
ship_date
ATTRIBUTE(BOLD)
LET s1 = "select * from orders where ", query_1
PREPARE s_1 FROM s1
DECLARE cursor_1 CURSOR FOR s_1
FOREACH cursor_1 INTO order_rec.*
...
END FOREACH
Related Statements
DECLARE, PREPARE, OPEN FORM, OPTIONS, SELECT
7-37
CONTINUE
CONTINUE
Overview
Use the CONTINUE statement to cause a FOR, FOREACH, or WHILE statement
to start a new cycle immediately, if the conditions permit, or to return to the
menu from an option in the MENU statement.
Syntax
CONTINUE { FOR | FOREACH | MENU | WHILE }
Explanation
CONTINUE
is a required keyword.
FOR
FOREACH
MENU
WHILE
Related Statements
END, EXIT
7-38
CREATE AUDIT
CREATE AUDIT
Overview
Use the CREATE AUDIT statement to create an audit trail file, and to start writing the audit trail.
Syntax
CREATE AUDIT FOR table-name IN "pathname"
Explanation
CREATE
AUDIT FOR
table-name
is the name of the table for which to create an audit trail file.
IN
is a required keyword.
pathname
Notes
1. You create audit trails to keep a record of all modifications of a table. An
audit trail is a complete history of all additions, deletions, and updates to
the table. INFORMIX-4GL can use the audit trail to reconstruct the table
from a backup copy made at the time the audit trail is created. (See the
RECOVER TABLE statement.) See the section Audit Trails in Chapter 3
for more information.
2. If an audit trail file with the same pathname already exists for the same
table, the CREATE AUDIT statement does nothing. If an audit trail file for
the same table exists with a different pathname, INFORMIX-4GL displays
an error message.
3. Make a backup copy of your database files as soon as you run the CREATE
AUDIT statement, but before you make any further changes to the database. (See the RECOVER TABLE statement for an example.) If possible,
put the audit trail file on a different physical device from the one that
holds your data, so that a failure of one does not damage the data on the
other.
4. Audit trails slow INFORMIX-4GL slightly because each alteration of the
table is recorded in the audit trail file, as well as in the database files.
INFORMIX-4GL Statement Syntax
7-39
CREATE AUDIT
5. You must own table-name or have DBA status to use the CREATE AUDIT
statement.
6. You must set execute permission for all directories below root in pathname
for each class of user (owner, owners group, and public) that accesses
your database.
7. You cannot create an audit file for a view.
8. You cannot create a cluster index on a table that has an audit trail.
Example
CREATE AUDIT FOR orders IN "/dbdir/safe"
Related Statements
DROP AUDIT, RECOVER TABLE
7-40
CREATE DATABASE ( O )
CREATE DATABASE ( O )
Overview
Use the CREATE DATABASE statement to create a new database. INFORMIX-4GL will create the system catalogs that will contain the data dictionary
describing the structure of the database. The database that you create automatically becomes the current database.
Syntax
CREATE DATABASE database-name
[ WITH LOG IN "pathname" [ MODE ANSI ] ]
Explanation
CREATE
DATABASE
database-name
is the name that you assign to the database. The databasename can be a program variable of type CHAR containing the
name of the database you want to create.
WITH LOG IN
pathname
MODE ANSI
Notes
1. INFORMIX-4GL creates a subdirectory in the current directory with the
name database-name.dbs. All of the system catalogs, data, and index files
will be placed in this subdirectory, except for tables that you explicitly
instruct INFORMIX-4GL to create elsewhere.
2. A database name can be up to 10 characters long and can contain only letters, digits, and underscores ( _ ). The first character must be a letter. If you
store more than one database in a single directory, the database names
must be unique.
7-41
CREATE DATABASE ( O )
3. For a user to have access to a database, the user must have execute
(search) permission for each directory in the full pathname of database-name.dbs, as well as appropriate database privileges. (See the
GRANT statement later in this chapter.)
4. See Appendix B for a description of the system catalogs.
5. The WITH LOG IN clause creates a transaction log file. Without this file,
you cannot use the BEGIN WORK, COMMIT WORK, or the ROLLBACK
WORK statements. You can use the START DATABASE statement to assign
a log file to an existing database. See the section Transactions in
Chapter 3 for further details.
You must include the WITH LOG IN keywords and specify a transaction
log file when you use the MODE ANSI keywords in the CREATE
DATABASE statement.
6. A database created as MODE ANSI supports implicit transactions. All
statements automatically appear within a transaction. (Do not use the
BEGIN WORK statement in a program that accesses a MODE ANSI database.) You explicitly terminate a transaction when you issue a COMMIT
WORK or ROLLBACK WORK statement.
7. You can determine the type of database that a user selects by checking the
warning flag after a DATABASE statement in the SQLCA.SQLAWARN
structure. See the section SQLCA Record in Chapter 3 for more information about the SQLCA.SQLAWARN character string.
8. You cannot drop MODE ANSI from a database. Once created or started as
such, a database remains MODE ANSI.
9. The CREATE DATABASE statement cannot appear in a multi-statement
PREPARE.
Examples
This CREATE DATABASE statement creates the stores database with a transaction log file:
CREATE DATABASE stores
WITH LOG IN "/s/log/stores.log"
7-42
CREATE DATABASE ( O )
Related Statements
DROP DATABASE, GRANT, START DATABASE
7-43
CREATE INDEX
CREATE INDEX
Overview
Use the CREATE INDEX statement to create an index for one or more columns
in a table, and optionally to cluster the physical table in the order of the index.
When more than one column is listed, the concatenation of the set of columns
is treated as a single composite column for indexing.
Syntax
CREATE [ UNIQUE ] [ CLUSTER ] INDEX index-name
ON table-name ( column-name [ ASC | DESC ] [ , . . . ] )
Explanation
CREATE INDEX are required keywords.
7-44
UNIQUE
CLUSTER
index-name
ON
is a required keyword.
table-name
column-name
ASC
DESC
CREATE INDEX
Notes
1. When INFORMIX-4GL executes the CREATE INDEX statement, it locks
table-name in EXCLUSIVE mode. If another process is using table-name,
INFORMIX-4GL cannot execute CREATE INDEX and returns an error.
2. You can include up to eight columns in a composite index.
3. The total length of all columns indexed in a single CREATE INDEX statement cannot exceed 120 bytes.
4. See the section Indexing Strategy in Chapter 3 for a discussion of indexing strategy.
5. The CREATE CLUSTER INDEX statement fails if a CLUSTER index already
exists.
6. The CREATE CLUSTER INDEX statement fails if the table has an audit trail.
7. Only one index on a particular sequence of columns is allowed.
8. You cannot use the ROLLBACK WORK statement to undo a CREATE INDEX
statement.
9. When you create a table, you can specify that a column or composite column will allow only unique values. You use the UNIQUE keyword in the
CREATE TABLE statement.
10. You cannot create an ascending index on a column defined as UNIQUE in
a CREATE TABLE statement.
11. A column list defined as having a UNIQUE CONSTRAINT in a CREATE
TABLE statement receives a unique ascending composite index. You cannot use the CREATE INDEX statement to create an identical unique
composite index.
12. In a composite index, you can include a column defined as UNIQUE. Similarly, in a composite index you can include a composite column list
defined as UNIQUE. However, the column list in the CREATE INDEX statement cannot be identical to the column list defined as UNIQUE in the
CREATE TABLE statement.
13. When more than one column is listed, the concatenation of the set of columns is treated as a single composite column for the purpose of indexing.
14. DISTINCT is a synonym for UNIQUE.
7-45
CREATE INDEX
Examples
CREATE UNIQUE INDEX i_ordnum
ON orders (order_num)
Related Statements
ALTER INDEX, CREATE TABLE, DROP INDEX
7-46
CREATE SYNONYM
CREATE SYNONYM
Overview
Use the CREATE SYNONYM statement to provide an alternative name for a
table or view.
Syntax
CREATE SYNONYM synonym FOR table-name
Explanation
CREATE SYNONYM
synonym
is an SQL identifier.
FOR
is a required keyword.
table-name
Notes
1. In a MODE ANSI database, the name of a synonym is qualified by the
owner of the synonym (owner. synonym). You must specify owner when
you refer to a synonym owned by another user.
The use of the prefix owner is optional in a non-MODE ANSI database.
INFORMIX-4GL does check the accuracy of owner, however, if you include
it in a statement. See the section Owner Naming in Chapter 3 of this
manual.
2. A user has no privileges under a synonym that were not granted for the
table to which it applies.
3. When a synonym is created in an INFORMIX-4GL program, the owner of
the synonym is the person who runs the program.
4. Synonyms are not to be confused with table aliases in SELECT statements.
A synonym persists until you drop it with the DROP SYNONYM statement. Table aliases are useful only in the SELECT statement.
5. The CREATE SYNONYM statement cannot be rolled back.
6. For a database created or started as MODE ANSI, owner.synonym must be
unique among all the synonyms, tables, and views in the database. In a
non-MODE ANSI database, synonym must be unique.
INFORMIX-4GL Statement Syntax
7-47
CREATE SYNONYM
Example
CREATE SYNONYM cust FOR customer
Related Statements
DROP SYNONYM, SELECT
Note: Synonyms are very useful for referencing external objects with INFORMIX-OnLine. Refer to the INFORMIX-OnLine Programmers Manual for more
information.
7-48
CREATE TABLE ( O )
CREATE TABLE ( O )
Overview
Use the CREATE TABLE statement to create a new table in the current
database.
Syntax
CREATE [ TEMP ] TABLE table-name
( column-name datatype
[ NOT NULL ] [ UNIQUE [ CONSTRAINT constr-name ] ] [ , . . . ]
[ UNIQUE ( unique-col-list ) [ CONSTRAINT constr-name ] ] [ , . . . ] )
[ WITH NO LOG ]
[ IN pathname ]
Explanation
CREATE TABLE
TEMP
is an optional keyword.
table-name
is the SQL identifier that you assign to the table. The first
ten characters must be unique within a database.
column-name
datatype
specifies the data type for each column. (See the following
list for valid SQL data types.)
NOT NULL
UNIQUE
(unique-col-list)
CONSTRAINT
constr-name
7-49
CREATE TABLE ( O )
WITH NO LOG
IN
is an optional keyword.
pathname
CHARACTER
SMALLINT
INTEGER
INT
NUMERIC
SMALLFLOAT
REAL
FLOAT [(n)]
DOUBLE
PRECISION
MONEY [(m[,n])]
7-50
CREATE TABLE ( O )
SERIAL [(n)]
DATE
DATETIME
INTERVAL
Notes
1. In a database created as MODE ANSI, the name of a table is qualified by
the owner of the table (owner. table-name). You must specify owner when
you refer to a table owned by another user.
The use of the prefix owner is optional in a non-MODE ANSI database.
INFORMIX-4GL checks the accuracy of owner, however, if you include it in
a statement. See the section Owner Naming in Chapter 3 of this
manual.
2. Table names must be unique within a database. If the database is MODE
ANSI, the combination owner.tablename must be unique.
3. Column names must be unique within each table, but you can use duplicate names in different tables in the same database. See SQL Identifiers
in Chapter 3 for guidelines on table names and column names.
4. Temporary tables created with the TEMP option exist for the duration of
the program.
5. Users with CONNECT privilege can create temporary tables.
6. The default value in a column is NULL unless you include the NOT NULL
keywords after the data type of the column.
7. If you designate a column as NOT NULL, users must enter a value into this
column when performing an INSERT or UPDATE to the table.
7-51
CREATE TABLE ( O )
8. When you create a table in a database that is not MODE ANSI, all tablelevel privileges (except ALTER) are automatically granted to all users
(PUBLIC). To restrict access privileges at the table level, you must revoke
all privileges and grant those you want. In a database created as MODE
ANSI, no default table-level privileges exist. You must explicitly grant
these privileges.
9. You can specify no more than one SERIAL column in a table.
10. Enter DATE data type values in the sequence of month, day, and year,
with any non-numeric character, including a blank, as a separator. Represent the month as the number of the month (January = 1 or 01,
February = 2 or 02, and so on). Represent the day as the day of the month
(1 or 01, 2 or 02, and so on). The year is stored as a four-digit number
(0001 to 9999). If you enter two digits yy for the year, INFORMIX-4GL
assumes that the year is 19yy.
The following values are all acceptable representations of June 1, 1989:
06/01/89, 6.1.89, and 6-1-1989.
11. The DATE type is actually stored as the integer number of days since
December 31, 1899. You can sort DATE columns and make chronological
comparisons between two DATE columns.
12. The following table shows the file space requirements (in bytes) for each
data type:
SERIAL
SMALLINT
INTEGER
SMALLFLOAT
FLOAT
CHAR(n)
DECIMAL(m,n)
MONEY(m,n)
DATE
DATETIME
INTERVAL
4
2
4
4
8
n
1 + m/2
1 + m/2
4
Depends on precision (see below)
Depends on precision (see below)
CREATE TABLE ( O )
7-53
CREATE TABLE ( O )
25. The pathname in an IN clause can specify any valid directory and is not
restricted to the directory that contains the current database. Use this feature if your database is becoming too large for your current disk volume.
26. If you use the WITH NO LOG keywords in a CREATE TABLE statement and
the database does not use logging, the WITH NO LOG option is ignored.
The WITH NO LOG option is supported on a MODE ANSI database.
27. Once you create a temporary table WITH NO LOG, you cannot turn on logging. A temporary table is, therefore, always logged or never logged.
Examples
The sequence of statements that creates the stores database follows:
CREATE DATABASE stores
CREATE TABLE customer
(
customer_num
SERIAL(101),
fname
CHAR(15),
lname
CHAR(15),
company
CHAR(20),
address1
CHAR(20),
address2
CHAR(20),
city
CHAR(15),
state
CHAR(2),
zipcode
CHAR(5),
phone
CHAR(18)
)
CREATE TABLE orders
(
order_num
order_date
customer_num
ship_instruct
backlog
po_num
ship_date
ship_weight
ship_charge
paid_date
)
SERIAL(1001),
DATE,
INTEGER,
CHAR(40),
CHAR(1),
CHAR(10),
DATE,
DECIMAL(8,2),
MONEY(6),
DATE
SMALLINT,
INTEGER,
CREATE TABLE ( O )
stock_num
manu_code
quantity
total_price
)
CREATE TABLE stock
(
stock_num
manu_code
description
unit_price
unit
unit_descr
)
SMALLINT,
CHAR(3),
SMALLINT,
MONEY(8)
SMALLINT,
CHAR(3),
CHAR(15),
MONEY(6),
CHAR(4),
CHAR(15)
CHAR(2),
CHAR(15)
The following statement creates the tab1 table. In tab1, column c1 is UNIQUE
and the constraint is named uc1. A UNIQUE CONSTRAINT is also applied to
the composite columns c3 and c4.
CREATE TABLE tab1
(
c1 INTEGER NOT NULL UNIQUE CONSTRAINT uc1,
c2 INTEGER,
c3 INTEGER NOT NULL,
c4 CHAR(10) NOT NULL,
UNIQUE (c3,c4)
)
7-55
CREATE TABLE ( O )
The following statement creates the employee table. The data for the table is
stored in the file /a/work/employ.dat. The index information is stored in the
file /a/work/employ.idx.
CREATE TABLE employee
(
employ_num
SERIAL(101),
fname
CHAR(15),
lname
CHAR(15),
address
CHAR(20),
city
CHAR(15),
state
CHAR(2),
zipcode
CHAR(5),
phone
CHAR(18)
hire_date
DATE
)
IN "/a/work/employ"
The following example shows a use of the DATETIME and INTERVAL data
types:
CREATE TABLE tv_programs
(
prog_title CHAR(32),
air_date DATETIME YEAR TO DAY NOT NULL,
air_time DATETIME HOUR TO MINUTE,
duration INTERVAL HOUR TO SECOND
)
Related Statements
ALTER TABLE, CREATE DATABASE, CREATE INDEX, DROP DATABASE,
DROP TABLE, GRANT, REVOKE
7-56
CREATE VIEW
CREATE VIEW
Overview
Use CREATE VIEW to create a new view based on existing tables and views
in the database.
Syntax
CREATE VIEW view-name [ ( column-list ) ]
AS SELECT-statement [ WITH CHECK OPTION ]
Explanation
CREATE VIEW
view-name
is an SQL identifier.
column-list
AS
is a required keyword.
SELECT-statement
is a SELECT statement.
WITH CHECK
OPTION
Notes
1. In a database created as MODE ANSI, the name of a view is qualified by
the owner of the view (owner.view-name). You must specify owner when
you refer to a view owned by another user.
The use of the prefix owner. is optional in a non-MODE ANSI database.
INFORMIX-4GL does check the accuracy of owner if you include it in a
statement, however. See the section Owner Naming in Chapter 3 of this
manual.
2. Except for the statements in the following list, you can use a view in any
SQL statement (including form specifications) where you can use a table.
ALTER TABLE
ALTER INDEX
CREATE INDEX
DROP INDEX
LOCK TABLE
RENAME TABLE
The view behaves like a table with the name view-name and consists of the
set of rows and columns returned by the SELECT-statement each time the
INFORMIX-4GL Statement Syntax
7-57
CREATE VIEW
SQL statement is executed using the view. The view reflects changes to the
Example
CREATE VIEW palo_alto AS
SELECT * FROM customer
WHERE city = "Palo Alto"
7-58
CREATE VIEW
Related Statements
CREATE TABLE, DROP VIEW
7-59
CURRENT WINDOW
CURRENT WINDOW
Overview
Use the CURRENT WINDOW statement to make a window the current or topmost window.
Syntax
CURRENT WINDOW IS { window-name | SCREEN }
Explanation
CURRENT
WINDOW IS
window-name
SCREEN
Notes
1. A window becomes completely visible when it becomes the current window. In the process, other inactive windows may be obscured.
2. All input and output is done in the current window.
3. If window-name contains a screen form, the screen form becomes the current form.
4. The terminal screen is the current window when a program starts.
5. If you specify SCREEN as the window-name, the entire screen becomes the
current window.
6. See also the CLEAR statement, which removes any text from the screen,
and makes the entire screen the current window.
7. The DISPLAY ARRAY, INPUT, INPUT ARRAY, and MENU statements run in
the current window. When you change the current window while one of
these statements is active and then resume the statement, the original
window is restored as the current window. For example, you can use an
ON KEY clause in an INPUT statement to allow the user to open a new win-
7-60
CURRENT WINDOW
dow by pressing a specific key during input. When the user presses the
designated key, INFORMIX-4GL executes the statements in the ON KEY
clause and then resumes input from the window that was current before
the ON KEY break.
8. The context of each window includes the values for the Prompt, Message,
Form, and Comment lines. When a window becomes the current window,
these values are restored.
9. When working with multiple windows, INFORMIX-4GL maintains a list
or stack of all open windows. It adds the current window to its window
list whenever you open a new window. The new window then becomes
the current window. When you close a window, INFORMIX-4GL removes
it from its window list. The topmost window (of those that remain)
becomes the current window.
10. When you specify a current window, INFORMIX-4GL adjusts the window
list by moving the new current window to the top, and closing the gap in
the list left by this window.
Examples
CURRENT WINDOW IS win1
CURRENT WINDOW IS SCREEN
Related Statements
CLEAR WINDOW, CLOSE WINDOW, OPEN WINDOW, OPTIONS
7-61
DATABASE
DATABASE
Overview
Use the DATABASE statement to declare an accessible database as the current
database.
Syntax
DATABASE database-name [ EXCLUSIVE ]
Explanation
DATABASE
is a required keyword.
database-name
is the name of a database, or a program variable that evaluates to the name of a database.
EXCLUSIVE
is an optional keyword.
Notes
1. If you want to specify a database that does not reside in your current
directory or in a directory specified by the DBPATH environment variable
(described in Appendix C), you must follow the DATABASE keyword
with a program variable that evaluates to the full pathname of the database (excluding the .dbs extension).
2. In an INFORMIX-4GL program, the DATABASE statement can serve two
purposes, one procedural and the other non-procedural. It makes the
named database the current database (procedural), and it tells the compiler where to find information about variables defined LIKE columns in
a table (non-procedural).
To serve the non-procedural purpose, the DATABASE statement must
occur outside any routine and precede the GLOBALS statements when
you use indirect data typing with the LIKE clause. The database-name must
be explicitly expressed and not given as a program variable. You cannot
use the EXCLUSIVE keyword in this context. If you use the DATABASE
statement in this non-procedural way, INFORMIX-4GL begins the MAIN
program block with the database-name as the current database.
Ordinarily, you use only one database, and the preceding procedure is
enough. If you do not have global variables defined LIKE database columns, but still want to interact with a database, you can use the
7-62
DATABASE
Example
DATABASE stores
Related Statements
CREATE DATABASE, DROP DATABASE, CLOSE DATABASE
7-63
DECLARE
DECLARE
Overview
Use the DECLARE statement to assign a cursor name to a SELECT or INSERT
statement. A cursor is required for a SELECT statement that selects more than
one row.
Syntax
DECLARE cursor-name [ SCROLL ] CURSOR [ WITH HOLD ] FOR
{ SELECT-statement [ FOR UPDATE [ OF column-list ] ] |
INSERT-statement | statement-id }
Explanation
DECLARE
is a required keyword.
cursor-name
is an INFORMIX-4GL identifier.
SCROLL
is an optional keyword that can be used only with a statement or a statement_id of a SELECT statement that you
PREPAREd.
CURSOR FOR
WITH HOLD
SELECT-statement
is a SELECT statement.
FOR UPDATE
OF
is an optional keyword.
column-list
INSERT-statement
is an INSERT statement.
statement-id
Notes
1. You must DECLARE a SELECT cursor before you can use it in an OPEN,
FETCH, FOREACH, DELETE, UPDATE, or CLOSE statement. You must
7-64
DECLARE
DECLARE an INSERT cursor before you can use it in an OPEN, PUT, FLUSH,
or CLOSE statement.
You must OPEN and CLOSE a regular cursor that is FOR UPDATE and
an INSERT cursor within a transaction.
You can OPEN and CLOSE a cursor WITH HOLD that is FOR UPDATE
outside a transaction. Any FETCH using it, however, must take place
within a transaction.
These requirements are automatically satisfied if the current database is a
MODE ANSI database.
6. Unlike other cursors, a cursor WITH HOLD is not closed when you execute
a COMMIT WORK or ROLLBACK WORK statement. You must explicitly
CLOSE a cursor WITH HOLD. (A CLOSE DATABASE statement closes all
cursors, including cursors WITH HOLD.)
7. You must include the SCROLL keyword in the DECLARE statement for a
SELECT cursor if you are going to issue a statement that includes the
PREVIOUS, LAST, FIRST, CURRENT, RELATIVE, or ABSOLUTE keywords.
SCROLL enables a cursor to FETCH rows in random order.
8. You must specify the statement-id to identify a SELECT or INSERT statement in a previous PREPARE statement.
9. The column names in an OF column-list clause do not need to be in the
select-list of the SELECT clause.
10. If the SELECT statement has no INTO clause, the subsequent FETCH statement must specify INTO variable-list.
7-65
DECLARE
11. Do not use INTO with an array element subscripted by a variable in the
SELECT statement because the subscript is evaluated at the time of the
DECLARE, not at the time of any subsequent FETCH. You can use a constant to indicate the array element.
Use FETCH INTO when the output variable is an array element subscripted by a variable or a constant.
12. You cannot use the FOR UPDATE clause in the DECLARE statement for a
SELECT cursor that includes the SCROLL keyword or an ORDER BY clause.
13. If you use the FOR UPDATE clause, the SELECT statement is limited to a
single table.
14. You must use the FOR UPDATE clause in the DECLARE statement for a
non-scrolling SELECT cursor if you will later use either the UPDATE or the
DELETE statement with the WHERE CURRENT OF cursor-name option. The
cursor FOR UPDATE can include or omit WITH HOLD.
15. If you specify one or more columns in the FOR UPDATE clause, you can
update only those columns in a subsequent UPDATE WHERE CURRENT
OF statement. (If you do not specify any columns in the FOR UPDATE
clause, you can update any column in a subsequent UPDATE WHERE
CURRENT OF statement.)
16. When you DECLARE a cursor FOR UPDATE, each FETCH executed on that
cursor locks the FETCHed row in exclusive mode. For a database without
transactions, the lock is released when you execute the next FETCH statement or when you CLOSE the cursor (whichever occurs first), regardless
of whether you UPDATE the row.
For a database with transactions, each row that you UPDATE remains
locked for the duration of the transaction. These locks are released only
when you end the transaction (issue a COMMIT WORK or ROLLBACK
WORK statement).
See the sectionLocking in Chapter 3 for a more detailed description of
table-level and row-level locking.
17. If your database has a transaction log but is not MODE ANSI, you must
issue a BEGIN WORK statement before you OPEN a cursor that you
DECLAREd FOR UPDATE but not WITH HOLD. (You can DECLARE a cursor WITH HOLD FOR UPDATE outside a transaction, but you cannot roll
back any changes to a non-MODE ANSI database that the cursor performs
outside a transaction. In this situation, each UPDATE is automatically
committed as a singleton transaction.)
7-66
DECLARE
In the next example, INFORMIX-4GL selects rows where the value in the
customer_num column equals a[5]:
LET i = 5
DECLARE q_curs CURSOR FOR
SELECT * FROM orders WHERE customer_num = a[i]
LET i = 2
OPEN q_curs
19. You cannot DECLARE a cursor for an INSERT statement that contains an
embedded SELECT statement.
20. If you DECLARE a cursor for an INSERT statement that has a VALUES
clause containing only constants, INFORMIX-4GL does not create a buffer,
but merely keeps count of the number of inserts. Such inserts are never
flushed as the result of a PUT statement. Flushing occurs when you issue
a FLUSH or CLOSE cursor statement.
21. The DECLARE statement for a cursor must physically appear before any
statement that specifies the cursor. The cursor-name has meaning from the
point at which you DECLARE it, to the end of the same source file. It is not
a global identifier that can be referenced in a separate source file.
22. You cannot specify a SCROLL INSERT cursor.
7-67
DECLARE
Examples
DECLARE scurs CURSOR FOR
SELECT * FROM customer
DECLARE wh_curs CURSOR WITH HOLD FOR st_1
DECLARE ucurs CURSOR FOR
SELECT * FROM customer WHERE customer_num > 110
FOR UPDATE OF fname, lname
DECLARE icurs CURSOR FOR
INSERT INTO stock
VALUES (stock_no, man_code, descr, u_price,
unit, u_desc)
DECLARE s_curs SCROLL CURSOR FOR
SELECT * FROM orders
WHERE customer_num = 104
Related Statements
CLOSE, DELETE, FETCH, FLUSH, FOREACH, FREE, OPEN, PREPARE, PUT,
SELECT, UPDATE
7-68
DEFER
DEFER
Overview
Use the DEFER statement to keep INFORMIX-4GL from terminating your program whenever a user presses the Interrupt key (usually CTRL-C or DEL) or
the QUIT key (usually CTRL-\).
Syntax
DEFER { INTERRUPT | QUIT }
Explanation
DEFER
is a required keyword.
INTERRUPT
is an optional keyword.
QUIT
is an optional keyword.
Notes
1. In the absence of the DEFER statement, your program will stop immediately whenever Interrupt or Quit is pressed.
2. The DEFER statement sets a global flag (int_flag for INTERRUPT and
quit_flag for QUIT) to non-zero whenever the user presses the Interrupt
or Quit key. The programmer must reset the flags to zero.
3. If the DEFER INTERRUPT statement has been executed and the user subsequently enters an Interrupt during an INPUT statement, program control
will leave the INPUT statement and int_flag will be set. This applies to the
CONSTRUCT, INPUT ARRAY, and PROMPT statements, as well.
4. The DEFER INTERRUPT statement can occur only once in a program, and
then only in the MAIN program block. After being executed, it remains in
effect for the duration of the program. This characteristic applies as well
to the DEFER QUIT statement.
Example
DEFER INTERRUPT
7-69
DEFER
Related Statement
WHENEVER
7-70
DEFINE
DEFINE
Overview
Use the DEFINE statement to define identifiers in your program and to set
aside adequate memory for each 4GL program variable.
Syntax
DEFINE variable-list { type
| LIKE table.column
| RECORD { LIKE table.* | variable-list [ , . . . ]
END RECORD } } [ , . . . ]
Explanation
DEFINE
is a required keyword.
variable-list
type
MONEY [ (m [ , n ] ) ]
INTEGER
INT
CHAR [ ( n ) ]
CHARACTER [ ( n ) ]
DECIMAL [ (m [ , n ] ) ]
DEC [ ( m [ , n ] ) ]
NUMERIC [ (m [ , n ] ) ]
DATE
DATETIME qualifier
SMALLFLOAT
REAL
RECORD [ LIKE table. * ]
FLOAT [ ( n ) ]
DOUBLE PRECISION [ ( n ) ]
INTERVAL qualifier
ARRAY [ i , j , k ] OF type
LIKE
table.column
RECORD
table
END
RECORD
7-71
DEFINE
Notes
1. Elements of records are addressed as record_name. column_name.
2. If the DEFINE statement is used in a function or MAIN program block, it
must be the first statement to appear in that function or MAIN program
block.
3. See the Data Types section in Chapter 2 for a full discussion of 4GL data
types for 4GL variables.
4. The section Language Conventions in Chapter 2 describes the identifiers of 4GL variables and their scope of reference.
Example
DEFINE p_customer RECORD LIKE customer.*,
p_orders RECORD
order_num LIKE orders.order_num,
order_date LIKE orders.order_date,
po_num LIKE orders.po_num,
ship_instruct LIKE orders.ship_instruct
END RECORD,
p_stock ARRAY[30] OF RECORD
s_num LIKE stock.stock_num,
m_code LIKE stock.manu_code
END RECORD,
stock_tot SMALLINT
Related Statements
GLOBALS, LET
Note: INFORMIX-OnLine supports additional data types. Refer to the INFORMIX -Online Programmers Manual for more information.
7-72
DELETE
DELETE
Overview
Use the DELETE statement to delete one or more rows from a table.
Syntax
DELETE FROM table-name
[ WHERE { condition | CURRENT OF cursor-name } ]
Explanation
DELETE FROM are required keywords.
table-name
is the name of the table from which you want to delete rows.
WHERE
is a keyword.
condition
CURRENT OF
are keywords.
cursor-name
Notes
1. When you create a database with transactions that is not MODE ANSI,
each DELETE statement you execute is treated as a single transaction, even
if you do not use the BEGIN WORK and COMMIT WORK or ROLLBACK
WORK statements.
2. Each row affected by a DELETE statement within a transaction is locked
for the duration of the transaction; therefore, a single DELETE statement
that affects a large number of rows locks the rows until the entire operation is completed. If the number of rows affected is very large, you might
exceed the limits that your operating system places on the maximum
number of simultaneous locks. If you exceed these limits, you may want
to either reduce the scope of the DELETE statement or lock the entire table
before executing the statement.
See the section Locking in Chapter 3 for a more detailed description of
table-level and row-level locking in INFORMIX-4GL.
INFORMIX-4GL Statement Syntax
7-73
DELETE
Examples
DELETE FROM items
WHERE order_num = onum
DELETE FROM orders
WHERE CURRENT OF query_cursor
These statements remove all items belonging to the order number set in the
program variable onum from the items table and remove the row from the
orders table pointed to by the cursor query_cursor.
Related Statements
DECLARE, INSERT, UPDATE
7-74
DISPLAY
DISPLAY
Overview
Use the DISPLAY statement to display data values on the screen.
Syntax
DISPLAY{ BY NAME variable-list |
variable-list [ TO { field-list | screen-record [ [ n ] ].* } [ , . . . ]
| AT row, column ] }
[ ATTRIBUTE ( attribute-list ) ]
Explanation
DISPLAY
is a required keyword.
BY NAME
variable-list
TO
field-list
screen-record
[n]
AT
row
column
ATTRIBUTE
(attribute-list)
7-75
DISPLAY
Notes
1. The DISPLAY statement (without the BY NAME, TO, or AT keywords)
displays variable-list on the next line. This can format displayed values
with CLIPPED, USING, and COLUMN, but not with the ATTRIBUTE
(attribute-list) clause.
2. Changing the data stored in program variables has no effect on the current screen display until this statement is executed again.
3. INFORMIX-4GL displays number values right justified, and character
strings left justified in the screen field.
4. If a character value does not fit in the field, its display is truncated. If a
number value does not fit in the field, INFORMIX-4GL fills the field with
asterisks (*) to indicate an overflow.
5. The DISPLAY BY NAME option selects screen fields, based on the identity
of the program variable name and the field name. INFORMIX-4GL uses
only the suffix portion of these variable names and field names. This
option results in an error (setting status < 0) unless the suffixes are unique
and unambiguous.
6. The DISPLAY TO screen-record [n].* option lists constants or program variables on the nth row of a screen array. You can move such values up or
down with the SCROLL statement.
7. You can use the DISPLAY AT statement to display variable-list at a specified
location on the screen or in the current window. You can use CLIPPED and
USING to format displayed values.
8. The coordinates start with row 1 and column 1 in the upper left corner
of the screen or current 4GL window. The row coordinates increase as you
go down, and the column coordinates increase as you move from left to
right. On a standard terminal screen, the lower right corner has the
coordinates (24, 80).
9. An error occurs (setting status < 0 ) if either the row or column exceeds the
dimensions of the screen or of the current window.
10. If you use the AT option when the last element of variable-list is a NULL
CHAR value, INFORMIX-4GL clears to the end of the line. For example,
DISPLAY "" AT n,1
7-76
DISPLAY
REVERSE
BLINK
UNDERLINE
You can specify zero or one of the keywords in the left-hand columns, and
from zero to three from the right-hand column (but some terminals may
not support some combinations). On color terminals, NORMAL is interpreted as WHITE, BOLD as RED, DIM as BLUE, and INVISIBLE as BLACK.
Do not include the equal ( = ) sign, which in this table shows the effect on
monochrome terminals of keywords that specify color.
These keywords cannot produce the effects suggested by their names
unless the termcap or terminfo files and the physical terminals support
the attribute. (See Appendix I, Modifying termcap and terminfo.)
Note: Some terminal entries in termcap or terminfo include the sg#1 or
xmc#1 capabilities. On these terminals, the first character of variable-list is
replaced by a blank if you use the DISPLAY AT statement with any display
attribute. To be safe, make sure that the first character of the variable-list is a
blank if you specify any display attributes.
16. On UNIX systems that use terminfo files rather than termcap, INFORMIX-4GL does not support attributes that specify colors, and the only
valid attribute-list keywords are REVERSE and UNDERLINE.
7-77
DISPLAY
Examples
DISPLAY BY NAME lname, fname
DISPLAY "There are ", num USING "-####",
" items in the list" AT 12,1
ATTRIBUTE(REVERSE, BLUE)
DISPLAY add_cust.* TO sc_addr[4].*
Related Statements
INPUT, DISPLAY ARRAY, DISPLAY FORM, OPEN WINDOW
7-78
DISPLAY ARRAY
DISPLAY ARRAY
Overview
Use the DISPLAY ARRAY statement to display a program array in a screen
array, and to permit scrolling through the array.
Syntax
DISPLAY ARRAY record-array TO screen-array.*
[ ATTRIBUTE ( attribute-list ) ]
{ ON KEY ( key-list )
statement
...
[ EXIT DISPLAY ]
...
END DISPLAY | [ END DISPLAY ] }
Explanation
DISPLAY ARRAY
record-array
TO
is a required keyword.
screen-array
is the name of a screen record, defined in a form specification file, that corresponds to the fields in a row of a screen
array.
ATTRIBUTE
is an optional keyword.
attribute-list
ON KEY
key-list
is usually a list of one or more function or CTRL key designations. It can also include ESC (if you have specified
another key as the Accept key in the OPTIONS statement)
or INTERRUPT (if you have executed a DEFER INTERRUPT
statement).
statement
is an INFORMIX-4GL statement.
EXIT DISPLAY
END DISPLAY
is a statement that terminates a DISPLAY ARRAY statement. It is required only when an ON KEY clause is used,
INFORMIX-4GL Statement Syntax
7-79
DISPLAY ARRAY
Notes
1. You must call set_count() with the number of filled rows in record-array
prior to executing DISPLAY ARRAY.
2. The user can use the [ ] key to move the cursor down one row at a time
and to scroll to the bottom of the screen array; the [ ] key to move the
cursor up one row at a time and to scroll to the top of the screen array;
[ F3 ] to scroll to the next page; and [ F4 ] to scroll to the previous page. You
can use the OPTIONS statement to assign these functions to other keys. In
addition, you must define the key assignments properly in the termcap or
terminfo files.
3. The user can exit from the DISPLAY ARRAY statement by pressing ESC, or
by pressing the key specified as the ACCEPT KEY in the OPTIONS statement. The program should tell the user to do this.
4. The following conditions require that an END DISPLAY statement appear
in your program:
7-80
DISPLAY ARRAY
9. The following list shows the screen attributes allowed in the ATTRIBUTE
clause:
WHITE = NORMAL
YELLOW = BOLD
MAGENTA = BOLD
RED = BOLD
CYAN = DIM
GREEN = DIM
BLUE = DIM
BLACK = INVISIBLE
REVERSE
BLINK
UNDERLINE
ESCAPE, if you have specified another key as the Accept key in the
OPTIONS statement.
[ F3 ], if you have specified another key as the Next key in the OPTIONS
statement.
The Interrupt key, if you have executed a DEFER INTERRUPT statement. (When the user presses the Interrupt key under these
conditions, INFORMIX-4GL executes the statements in the ON KEY
7-81
DISPLAY ARRAY
clause and sets int_flag to non-zero but does not terminate the
DISPLAY ARRAY statement.)
Do not use the following keys in a key-list:
Other keys that have special meaning for your operating system.
14. Do not execute PROMPT, INPUT, or INPUT ARRAY statements within the
ON KEY clause of a DISPLAY ARRAY statement. You can, however, call a
function that executes one of these statements.
Examples
DISPLAY ARRAY pa_array TO sc_array.*
DISPLAY ARRAY p_items TO s_items.*
ON KEY (CONTROL-E)
MESSAGE "Highlight an item and ",
"press the ACCEPT key."
END DISPLAY
INPUT BY NAME p_customer.*
AFTER FIELD company
...
DISPLAY ARRAY pa_array TO sc_array.*
END DISPLAY
ON KEY (CONTROL-B)
...
END INPUT
Related Statements
DISPLAY, SCROLL
7-82
DISPLAY FORM
DISPLAY FORM
Overview
Use the DISPLAY FORM statement to display a pre-compiled screen form.
Syntax
DISPLAY FORM form-name [ ATTRIBUTE ( attribute-list ) ]
Explanation
DISPLAY FORM are required keywords.
form-name
ATTRIBUTE
is an optional keyword.
attribute-list
Notes
1. DISPLAY FORM displays the screen form starting on the third line of the
terminal screen or window. You can change the starting line for all windows (including the screen) by using the OPTIONS statement or for a
specific window by using an ATTRIBUTE clause in the appropriate OPEN
WINDOW statement.
2. The following list shows the screen attributes allowed in the ATTRIBUTE
clause:
WHITE = NORMAL
YELLOW = BOLD
MAGENTA = BOLD
RED = BOLD
CYAN = DIM
GREEN = DIM
BLUE = DIM
BLACK = INVISIBLE
REVERSE
BLINK
UNDERLINE
7-83
DISPLAY FORM
Examples
DISPLAY FORM order_entry
DISPLAY FORM inventory ATTRIBUTE(BLUE)
Related Statements
CLEAR, CLOSE FORM, OPEN FORM, OPEN WINDOW
7-84
DROP AUDIT
DROP AUDIT
Overview
Use the DROP AUDIT statement to delete an audit trail file.
Syntax
DROP AUDIT FOR table-name
Explanation
DROP AUDIT FOR
table-name
is the name of the table whose audit trail file you want
to delete.
Notes
1. Us e the DROP AUDIT statement to remove the old audit trail file when
you have made a backup of your database files. Use the CREATE AUDIT
statement to start a new audit trail and then back up the table. See the section Audit Trails in Chapter 3 for more information.
2. You must own table-name or have DBA status to use the DROP AUDIT
statement.
Example
DROP AUDIT FOR orders
Related Statements
CREATE AUDIT, RECOVER TABLE
7-85
DROP DATABASE
DROP DATABASE
Overview
Use the DROP DATABASE statement to delete an entire database, including all
system catalogs, indexes, data, and the transaction log.
Syntax
DROP DATABASE { database-name | char-variable }
Explanation
DROP DATABASE
database-name
char-variable
Notes
1. You must own all the tables in the database or have DBA status to run the
DROP DATABASE statement.
2. The DROP DATABASE statement does not delete the database directory if
there are any files in the database directory other than those created for
database tables and their indexes.
3. You cannot drop the current database. You must execute the CLOSE
DATABASE statement first.
4. The DROP DATABASE statement cannot be rolled back.
5. For databases with transactions, the DROP DATABASE statement deletes
the transaction log.
6. The DROP DATABASE statement cannot appear in a multi-statement
PREPARE.
Example
DROP DATABASE stores
7-86
DROP DATABASE
Related Statements
CREATE DATABASE, CLOSE DATABASE
7-87
DROP INDEX
DROP INDEX
Overview
Use the DROP INDEX statement to delete an index.
Syntax
DROP INDEX index-name
Explanation
DROP INDEX
index-name
Notes
1. You must own the index or have DBA privilege to use the DROP INDEX
statement.
2. You cannot roll back the DROP INDEX statement.
3. You cannot drop the index created when a column or composite column
list is identified as having a UNIQUE CONSTRAINT in the CREATE TABLE
statement.
Example
DROP INDEX i_ordnum
Related Statement
CREATE INDEX
7-88
DROP SYNONYM
DROP SYNONYM
Overview
Use the DROP SYNONYM statement to delete a previously defined synonym
for a table or view.
Syntax
DROP SYNONYM synonym
Explanation
DROP SYNONYM are required keywords.
synonym
is a 4GL identifier.
Notes
1. You must be the owner of the synonym or have DBA status to use the
DROP SYNONYM statement.
2. When you compile a program containing a synonym, the synonym is
replaced in the compiled program by the real identifier of the table or
view (as listed in the systables system catalog). If you subsequently drop
the synonym, the compiled program will still run.
3. The DROP SYNONYM statement cannot be rolled back.
Example
DROP SYNONYM cust
Related Statement
CREATE SYNONYM
7-89
DROP TABLE
DROP TABLE
Overview
Use the DROP TABLE statement to delete a table, along with its associated
indexes and data.
Syntax
DROP TABLE table-name
Explanation
DROP TABLE
table-name
Notes
1. When you delete a table, you also delete the data stored in it, the indexes
on columns, any synonyms assigned to it, and any authorizations you
have granted on the table. You also delete all views based on the table.
2. You cannot drop any of the system catalog tables.
3. You must be the owner of a table or have DBA privilege to use the DROP
TABLE statement.
4. The DROP TABLE statement cannot be rolled back.
Example
DROP TABLE customer
Related Statement
CREATE TABLE
7-90
DROP VIEW
DROP VIEW
Overview
Use the DROP VIEW statement to delete a view from the database.
Syntax
DROP VIEW view-name
Explanation
DROP VIEW
view-name
Notes
1. You must be the owner of the view or have DBA status to use the DROP
VIEW statement.
2. When you drop view-name, you also drop all views that have been defined
in terms of view-name.
3. You cannot roll back the DROP VIEW statement.
4. See the section Views in Chapter 3 for more information.
Example
DROP VIEW cust1
Related Statements
CREATE VIEW, DROP TABLE
7-91
ERROR
ERROR
Overview
Use the ERROR statement to display an error message on the Error line (by
default, the bottom line of the screen), and to ring the terminal bell.
Syntax
ERROR display-list [ ATTRIBUTE ( attribute-list ) ]
Explanation
ERROR
is a required keyword.
display-list
is a list of one or more program variables and/or string constants (enclosed in quotation marks), separated by commas.
ATTRIBUTE
is an optional keyword.
attribute-list
Notes
1. The string generated by substituting values for the variables in display-list
must fit on a single display line. The string is displayed in a window on
the Error line.
2. You can change the position of the Error line with the OPTIONS statement.
The location of the Error line is relative to the screen, rather than to the
current window.
3. The display-list can contain the CLIPPED and USING functions.
4. REVERSE is the default attribute for the ERROR display. You can alter the
default attribute with the ATTRIBUTE clause.
7-92
ERROR
5. The following list shows the screen attributes allowed in the ATTRIBUTE
clause:
WHITE = NORMAL
YELLOW = BOLD
MAGENTA = BOLD
RED = BOLD
CYAN = DIM
GREEN = DIM
BLUE = DIM
BLACK = INVISIBLE
REVERSE
BLINK
UNDERLINE
Example
ERROR "There is no match for ", pattern
Related Statements
DISPLAY, MESSAGE, OPTIONS
7-93
EXECUTE
EXECUTE
Overview
Use the EXECUTE statement to run a statement specified by a previous
PREPARE statement.
Syntax
EXECUTE statement-id [ USING input-list ]
Explanation
EXECUTE
is a required keyword.
statement-id
USING
is an optional keyword.
input-list
Notes
1. After you PREPARE an SQL statement, you can EXECUTE it as often as you
desire.
2. To use the USING clause, you must know the number of the parameters of
the PREPAREd statement. The data type of each variable in input-list must
be compatible with the value expected in the PREPAREd statement for the
corresponding parameter.
3. You cannot EXECUTE a PREPAREd SELECT statement. You must use
DECLARE with a FOREACH loop, or use the OPEN, FETCH, and CLOSE
statements to execute a statement-id that references a SELECT statement.
4. You cannot EXECUTE a PREPAREd INSERT statement that uses a cursor.
You must use DECLARE with a FOREACH loop, or else use the OPEN, PUT,
and CLOSE statements to execute INSERT statements that you want to process as a group.
7-94
EXECUTE
Example
LET s1 = "UPDATE orders SET po_num = ?, order_date = ?"
PREPARE statement_1 FROM s1
EXECUTE statement_1 USING purchase_num, order_date
Related Statements
DECLARE, FREE, PREPARE
7-95
EXIT
EXIT
Overview
Use the EXIT statement to terminate the program; to break out of a FOR, a
FOREACH, or a WHILE loop; to leave the CASE statement; to leave the INPUT
or INPUT ARRAY statement; or to leave a menu.
Syntax
EXIT { CASE | DISPLAY | FOR | FOREACH | INPUT | MENU
| PROGRAM [ ( integer-expr ) ] | WHILE }
Explanation
EXIT
is a required keyword.
CASE
is an optional keyword.
DISPLAY
is an optional keyword.
FOR
is an optional keyword.
FOREACH
is an optional keyword.
INPUT
is an optional keyword.
MENU
is an optional keyword.
PROGRAM
is an optional keyword.
integer-expr
WHILE
is an optional keyword.
Notes
1. You can use the CASE option only within a CASE statement, the DISPLAY
option only within a DISPLAY ARRAY statement, the FOR option only
within a FOR statement, the FOREACH option only within a FOREACH
statement, the INPUT option only within an INPUT or INPUT ARRAY
statement, the MENU option only following a COMMAND clause of a
MENU statement, and the WHILE option only within a WHILE statement.
In each case, program control passes to the first statement following the
END CASE, END DISPLAY, END FOR, END FOREACH, END INPUT, END
MENU, or END WHILE statements, respectively.
7-96
EXIT
Related Statement
CONTINUE
7-97
FETCH
FETCH
Overview
Use the FETCH statement to move the cursor to a new row in the active set
and to retrieve the values from that row.
Syntax
FETCH [ NEXT | { PREVIOUS | PRIOR } | FIRST | LAST | CURRENT |
RELATIVE m | ABSOLUTE n ] cursor-name
[ INTO variable-list ]
Explanation
7-98
FETCH
is a required keyword.
NEXT
PREVIOUS
PRIOR
FIRST
LAST
CURRENT
RELATIVE m
ABSOLUTE n
cursor-name
INTO
is an optional keyword.
variable-list
FETCH
Notes
1. FETCH NEXT is the default condition.
2. You must DECLARE a SCROLL cursor before issuing a FETCH statement
that includes the PRIOR, PREVIOUS, FIRST, LAST, CURRENT, RELATIVE m,
or ABSOLUTE n keywords.
3. If the SELECT statement associated with the cursor has an INTO clause,
there must be no INTO clause in any FETCH statement referring to that
cursor. If the SELECT statement has no INTO clause, the FETCH statement
must have one.
4. You can FETCH into a program array element only by using an INTO
clause in the FETCH statement. Do not refer to an array element in the
SELECT-statement of a DECLARE statement.
5. Under any of the following circumstances, INFORMIX-4GL returns a row
not found code (status = NOTFOUND ).
You issue a FETCH NEXT statement when the cursor points to the last
row in the active set.
7-99
FETCH
Examples
FETCH query_curs INTO cnum, lname
FETCH PREVIOUS q_curs INTO orders.*
FETCH LAST q_curs INTO orders.*
FETCH ABSOLUTE 8 q_curs INTO orders.*
FETCH RELATIVE -10 q_curs INTO orders.*
Related Statements
CLOSE, DECLARE, DELETE, FOREACH, OPEN, PREPARE, PUT, SELECT,
UPDATE, WHENEVER
7-100
FINISH REPORT
FINISH REPORT
Overview
Use the FINISH REPORT statement to cause INFORMIX-4GL to finish
processing a report.
Syntax
FINISH REPORT report-name
Explanation
FINISH REPORT
report-name
Note
You must use the FINISH REPORT statement to let INFORMIX-4GL know that
no more statements are to be included in the report processing.
Example
FINISH REPORT cust_ords
Related Statements
OUTPUT TO REPORT, START REPORT
7-101
FLUSH
FLUSH
Overview
Use the FLUSH statement to force INFORMIX-4GL to insert the buffered rows
into the database without closing the cursor.
Syntax
FLUSH cursor-name
Explanation
FLUSH
is a required keyword.
cursor-name
Notes
1. The global variables status (whose value is taken from SQLCA.SQLCODE)
and SQLCA.SQLERRD[3] indicate the result of each FLUSH statement. If
INFORMIX-4GL successfully inserts all the buffered rows into the database, it sets status to zero and sets SQLCA.SQLERRD[3] to the number of
rows inserted. If INFORMIX-4GL is unsuccessful in its attempt to insert
the rows into the database, it sets status to a negative number (specifically, the number of the error message) and sets SQLCA.SQLERRD[3] to the
number of rows successfully inserted into the database.
2. You can use the FLUSH statement to force the insertion. You cannot delay
insertion by not using the FLUSH statement. INFORMIX-4GL automatically flushes the buffer when it is full.
3. Insert cursors that contain only constants in the values clause are not buffered. INFORMIX-4GL keeps a count of the number of rows to be inserted
into the database, and the database is updated only when you issue a
FLUSH or CLOSE statement.
4. If you exit a program without closing the cursor, the buffer is left
unflushed. Rows inserted into the buffer and remaining since the last
flush are lost. Do not expect the end of program to close the cursor and
flush the buffer.
7-102
FLUSH
Example
FLUSH icurs
Related Statements
CLOSE, DECLARE, OPEN, PUT
7-103
FOR
FOR
Overview
Use the FOR statement to cause a sequence of statements to be executed a
specified number of times.
Syntax
FOR integer-var = integer-expr TO integer-expr
[STEP integer-expr]
statement
...
[CONTINUE FOR]
...
[EXIT FOR]
...
END FOR
Explanation
FOR
is a required keyword.
integer-var
integer-expr
7-104
TO
is a required keyword.
STEP
is an optional keyword.
statement
is an INFORMIX-4GL statement.
CONTINUE FOR
is an optional statement.
EXIT FOR
is an optional statement.
END FOR
FOR
Notes
1. The FOR statement repeats the sequence of statements up to the END FOR
as integer-var takes on the values of the first integer-expr TO the second
integer-expr in STEPs of the third integer-expr. The default STEP is 1.
2. The CONTINUE FOR statement interrupts the sequence and causes the
program control to return to the top of the sequence and to increment and
test the counter integer-var.
3. The EXIT FOR statement interrupts the sequence and causes the program
control to jump to the first statement following the END FOR keywords.
4. If integer-var is greater than the TO integer-expr upon entry and the STEP
value is positive, none of the statements up to END FOR is executed.
5. The STEP value may be negative.
Example
DEFINE order_total MONEY(8),
i INTEGER
LET order_total = 0.00
FOR i = 1 TO ARR_COUNT()
LET order_total = order_total
+ p_items[i].total_price
END FOR
Related Statements
CONTINUE, EXIT, FOREACH, WHILE
7-105
FOREACH
FOREACH
Overview
Use the FOREACH statement to cause a sequence of statements to be executed
for each row returned from a query.
Syntax
FOREACH cursor-name [INTO variable-list]
statement
...
[CONTINUE FOREACH]
...
[EXIT FOREACH]
...
END FOREACH
Explanation
7-106
FOREACH
is a required keyword.
cursor-name
INTO
is an optional keyword.
variable-list
CONTINUE FOREACH
is an optional statement.
EXIT FOREACH
is an optional statement.
END FOREACH
FOREACH
Notes
1. The FOREACH statement repeats the sequence of statements up to END
FOREACH for each row returned by the query associated with cursorname. The FOREACH statement OPENs the cursor and performs successive FETCHes until the active list of the cursor is exhausted.
2. The INTO clause is required only if there is no INTO clause in the SELECT
statement associated with cursor-name, and vice versa. It lists the variables
into which INFORMIX-4GL places the values returned by the query.
3. When FETCHing into a program array, you must place the INTO clause on
the FOREACH statement and not on the SELECT-statement of a DECLARE
statement.
4. The CONTINUE FOREACH statement interrupts the sequence and causes
program control to return to the top of the sequence and to FETCH the
next row of the query.
5. The EXIT FOREACH statement interrupts the sequence and causes program control to jump to the first statement following the END FOREACH
keywords.
6. If the query returns no rows, none of the statements up to the END
FOREACH is executed, and program control passes immediately to the
first statement following END FOREACH. If you need to know whether
any rows were returned, you can set up a flag or a counter as in the example that follows these notes.
7. The FOREACH statement performs an implied OPEN statement. You cannot use the FOREACH statement if the OPEN statement must have a USING
clause to define unknown parameters in the SELECT statement.
8. If your database has transactions, the FOREACH statement must appear
inside a transaction.
9. If, within the FOREACH statement, the WHENEVER NOT FOUND statement evaluates to TRUE, the open cursor is automatically closed.
7-107
FOREACH
Example
PROMPT "Enter cut-off date for query: "
FOR o_date
DECLARE q_curs CURSOR FOR
SELECT order_num, o.customer_num, company
FROM orders o, customer c
WHERE o.customer_num = c.customer_num
AND order_date < o_date
LET counter = 0
FOREACH q_curs INTO ord_num, cust_num, comp
LET counter = counter + 1
CALL scan(ord_num, cust_num, comp)
END FOREACH
IF counter = 0 THEN
ERROR "No orders before ", o_date
END IF
Related Statements
CONTINUE, EXIT, FETCH, FOR, OPEN, WHILE, WHENEVER
7-108
FREE ( O )
FREE ( O )
Overview
The FREE statement releases database engine resources allocated to a
PREPAREd statement or to an OPENed and CLOSEd cursor.
Syntax
FREE { statement-id | cursor-name }
Explanation
FREE
is a required keyword.
statement-id
cursor-name
Notes
1. After you FREE statement-id, a cursor or EXECUTE statement cannot use it
until you PREPARE it again.
2. If cursor-name is DECLAREd FOR SELECT or FOR INSERT, a statement is
automatically PREPAREd when you OPEN the cursor. The statement has
no programmer-assigned statement-id. To release engine resources from
that statement, use FREE cursor-name. Afterward, you cannot use the cursor unless you OPEN it again.
3. Do not FREE a cursor-name that was DECLAREd FOR statement-id. Use
instead FREE statement-id.
Examples
FREE query_2
FREE scurs
7-109
FUNCTION
FUNCTION
Overview
Use the FUNCTION statement to define a function.
Syntax
FUNCTION function-name ( [ argument-list ] )
statement
...
[ RETURN expr-list ]
...
END FUNCTION
Explanation
FUNCTION
is a required keyword.
function-name
(argument-list)
statement
is an INFORMIX-4GL statement.
RETURN
expr-list
END FUNCTION
Notes
1. All arguments are passed by value.
2. You must DEFINE the arguments to the function, as well as other variables
used locally within the function.
7-110
FUNCTION
Related Statement
CALL
GLOBALS
GLOBALS
Overview
Use the GLOBALS statement to DEFINE one or more variables to be global
variables or to refer to the file where global variables are DEFINEd.
Syntax
GLOBALS {filename |
DEFINE-statement
...
END GLOBALS}
Explanation
GLOBALS
is a required keyword.
filename
DEFINE-statement
END GLOBALS
Notes
1. You may have at most one GLOBALS statement where global variables are
defined. This statement may be in a separate file or in the file containing
the MAIN program block.
2. The GLOBALS filename statement must occur earlier in every file than any
function that makes reference to a global variable.
3. The GLOBALS statement must lie outside the MAIN program block and
any FUNCTION or REPORT routines.
4. If any global variable is DEFINEd LIKE a database column, the DATABASE
statement naming the database must precede the GLOBALS statement.
7-112
GLOBALS
Examples
DATABASE stores
GLOBALS
DEFINE p_customer RECORD LIKE customer.*
...
END GLOBALS
GLOBALS "d4_globals.4gl"
Related Statement
DEFINE
7-113
GOTO
GOTO
Overview
Use the GOTO statement to transfer program control unconditionally to a
designated point.
Syntax
GOTO [ : ]label-id
Explanation
GOTO
is a required keyword.
label-id
is a 4GL identifier.
Notes
1. After a GOTO label-id statement successfully executes, program control is
transferred to the statement that follows LABEL label-id:. See the syntax of
the LABEL statement later in this chapter.
2. The label-id must be in the FUNCTION, REPORT, or MAIN routine in
which the GOTO statement is used. You cannot transfer into or out of
a FUNCTION or a REPORT with a GOTO statement.
Related Statements
LABEL, WHENEVER
7-114
GRANT
GRANT
Overview
Use the GRANT statement to specify user access privileges to a database or to
the tables and views in a database.
Syntax
GRANT tab-privilege ON table-name TO { PUBLIC | user-list }
[ WITH GRANT OPTION ] [ AS grantor ]
GRANT db-privilege TO { PUBLIC | user-list }
Explanation
GRANT
is a required keyword.
tab-privilege
is one or more of the following table-level access types (multiple privileges must be separated by commas):
ALTER
DELETE
Delete rows.
INDEX
Create indexes.
INSERT
Insert rows.
arguments, allowing you to specify columns that the user may select or update.
Separate column names with commas.
The keyword PRIVILEGES following ALL is
optional.
ON
is a required keyword.
table-name
is the name of the table or view for which you are granting
access privileges.
TO
is a required keyword.
INFORMIX-4GL Statement Syntax
7-115
GRANT
PUBLIC
user-list
is a list of login names for the users to whom you are granting access privileges. You can enter one login name or a
series of login names, separated by commas.
WITH GRANT
OPTION
AS
is an optional keyword.
grantor
db-privilege
Allows access to database tables without permission to create permanent tables and
indexes.
RESOURCE
Allows access to database tables with permission to create permanent tables and indexes.
DBA
Notes
1. Database-level permissions (CONNECT, RESOURCE, and DBA) control
access to the database. Table-level permissions (ALTER, DELETE, INDEX,
INSERT, SELECT, UPDATE, and ALL) control access to a table.
2. With CONNECT privilege, you can create views and temporary tables.
(The table-level SELECT privilege is required, however, on all columns
from which the view is derived.)
3. The RESOURCE privilege includes the CONNECT privilege and adds the
permission to create tables and indexes.
4. The DBA privilege includes the following:
Permission to grant and revoke CONNECT, RESOURCE, and DBA privileges to and from other users.
5. When you create a database, you are the Database Administrator and
have DBA privileges.
6. A DBA can use the AS keyword to grant table-level privileges on behalf of
another user.
7-116
GRANT
7. You can grant privileges only on tables or views that you create, or on
tables or views for which you have been given the GRANT OPTION.
8. When you use the WITH GRANT OPTION phrase to GRANT table-level
privileges to another user, you give that user the power to GRANT the
same privileges to another user.
9. If you do not specify one or more column names, the SELECT or UPDATE
access that you grant applies to all columns.
10. You cannot roll back the GRANT statement.
11. The most restrictive privileges always take precedence. For example, if
you grant RESOURCE privileges to a user but do not grant INDEX privileges at the table level, that user is not able to create indexes for that table.
12. You can grant DELETE, INSERT, or UPDATE privileges only on a simple
view. You can grant SELECT privilege on a simple or complex view.
Examples
The following statements grant all table-level privileges (except ALTER) to all
users who have CONNECT privileges to the database:
GRANT ALL ON customer TO PUBLIC
REVOKE ALTER ON customer FROM PUBLIC
When you create a table in a database that is not MODE ANSI, all table-level
privileges except ALTER are automatically granted to all users (PUBLIC). To
restrict access privileges at the table level, you must revoke all privileges and
grant those that you want:
REVOKE ALL ON customer FROM PUBLIC
GRANT ALL ON customer TO joe, mary
GRANT SELECT (fname, lname, company, city)
ON customer TO PUBLIC
Related Statement
REVOKE
7-117
IF
IF
Overview
Use the IF statement to execute one or more statements conditionally.
Syntax
IF Boolean-expr
THEN
statement
...
[ ELSE
statement
... ]
END IF
Explanation
IF
is a required keyword.
Boolean-expr
THEN
is a required keyword.
statement
ELSE
is an optional keyword.
END IF
Notes
1. If Boolean-expr is true, the statements following THEN down to an optional
ELSE (if present) or to END IF (if there is no ELSE) are executed.
2. If Boolean-expr is false, the statements following THEN down to an
optional ELSE (if present) or to END IF (if there is no ELSE) are skipped. If
an ELSE is present, the statements following the ELSE are executed.
3. If Bool-expr evaluates as UNKNOWN because the expression contains NULL
values, the IF statement behaves as though it were FALSE.
7-118
IF
Example
IF p_index <= 1 THEN
ERROR "No more stock items in this direction"
ELSE
LET p_index = p_index - 1
DISPLAY dp_stock[p_index].* TO s_stock.*
END IF
Related Statements
CASE, WHENEVER
7-119
INITIALIZE
INITIALIZE
Overview
Use the INITIALIZE statement to initialize a program variable.
Syntax
INITIALIZE variable-list { LIKE column-list | TO NULL }
Explanation
INITIALIZE
is a required keyword.
variable-list
LIKE
is an optional keyword.
column-list
TO NULL
Notes
1. If you include a column-list, it must specify as many columns as there are
variables in variable-list.
2. You must use a table-name prefix in the designation of the column names.
3. In a MODE ANSI database, the name of a table is qualified by the owner of
the table (owner. table-name). You must specify owner when you refer to a
table owned by another user. The use of the prefix owner is optional in a
non-MODE ANSI database. INFORMIX-4GL does check the accuracy of
owner, however, if you include it in a statement. See the section Owner
Naming in Chapter 3 for more information.
4. You can use the upscol utility to create and update the values in
syscolval. (See the discussion of the The upscol Utility in Appendix E.)
5. In a non-MODE ANSI database, there is a single syscolval table for all
users. The INITIALIZE statement assigns to individual variables in
variable-list the DEFAULT values specified in this table.
6. In a MODE ANSI database, each user has his or her own syscolval table.
This means that the values entered into these tables apply only to variables that correspond to columns in tables owned by the specified user. If
7-120
INITIALIZE
no owner name is specified, and the user compiling the program owns
the table, INFORMIX-4GL uses the values in the syscolval table owned by
that user.
7. If any columns corresponding to components of variable-list have not been
assigned DEFAULT values in syscolval, INFORMIX-4GL substitutes NULL
values.
8. Since upscol does not support DATETIME or INTERVAL values, these data
types will default to NULL when you include them in a column-list.
9. You can use the * notation in variable-list and column-list.
10. The TO NULL option requests initialization with the appropriate NULL
value for each variable.
Examples
INITIALIZE var1, var2, var3
LIKE tab1.col1, tab1.col2, tab1.col3
INITIALIZE v_cust.* LIKE customer.*
INITIALIZE v_orders.* TO NULL
INITIALIZE var1, var2, var3
LIKE tab1.var1, eileen.tab2.var2, fred.tab3.var3
Related Statements
LET, VALIDATE
7-121
INPUT
INPUT
Overview
Use the INPUT statement to assign values to program variables from data that
the user enters into fields of a screen form.
Syntax
INPUT { BY NAME variable-list [ WITHOUT DEFAULTS ] |
variable-list [ WITHOUT DEFAULTS ]
FROM { field-list | screen-record [ [ n ] ] .* } [ , . . . ] }
[ ATTRIBUTE ( attribute-list ) ]
[ HELP help-number ]
[ { BEFORE FIELD field-sublist
| AFTER { FIELD field-sublist | INPUT }
| ON KEY ( key-list ) }
statement
...
[ NEXT FIELD field-name ]
...
[ EXIT INPUT ]
...
...
END INPUT ]
Explanation
7-122
INPUT
BY NAME
variable-list
WITHOUT
DEFAULTS
FROM
field-list
screen-record
[n]
INPUT
ATTRIBUTE
(attribute-list)
HELP
help-number
is an integer to identify a help message for this INPUT statement in the help file that was specified in the OPTIONS
statement.
BEFORE FIELD are keywords to transfer control to a 4GL statement when the
is a list of one or more of the fields either explicitly or implicitly referenced in the INPUT statement.
AFTER FIELD
AFTER INPUT
ON KEY
(key-list)
statement
NEXT FIELD
field-name
EXIT INPUT
END INPUT
7-123
INPUT
Notes
1. When you execute the INPUT statement with the WITHOUT DEFAULTS
clause, INFORMIX-4GL displays the current values of variable-list in the
screen fields. This option is appropriate when you are requesting input
prior to updating an existing row of a table.
2. If an INPUT statement omits the WITHOUT DEFAULTS clause, INFORMIX-4GL displays on the form the default values from the form
specification (or from syscolval, if no default valuess were specified by
the DEFAULT attribute in the form specification) and initializes the variables in variable-list accordingly. INFORMIX-4GL assigns NULL values to
all variables for which no default has been set. This option is appropriate
when you are requesting input prior to inserting a new row in a table.
3. The INPUT BY NAME option selects the screen fields based on the identity
of the program variable name and the screen field name. INFORMIX-4GL
uses only the suffix portion of the name of the program variable and the
screen field. You must use the FROM option if the suffixes are not unique
and unambiguous.
4. If you use the FROM option, the number of variables in variable-list must
be the same as the number of field names in field-list or screen-record, and
of the corresponding data type.
5. INPUT is terminated when the user presses ESCAPE (or the key specified
as the Accept key in the OPTIONS statement). For single-item INPUTs (or
after the last item of multiple-item INPUTs), a RETURN is equivalent to
pressing the Accept key.
You can use the AFTER FIELD clause on the last field to override the terminating power of the RETURN by setting NEXT FIELD to the first field.
This option wraps the field-list into a loop. Alternatively, use the INPUT
WRAP option in the OPTIONS statement for the same effect.
6. The user triggers the AFTER INPUT clause (and the set of statements that
follow that clause) by attempting to terminate the INPUT statement. (See
the previous note.) If there is an AFTER INPUT clause, program control
passes to the statements following that clause, rather than to the statements following the END INPUT clause. This feature allows the
programmer to perform data validity checks before allowing the INPUT
statement to terminate.
7. INFORMIX-4GL passes control to the statements following a BEFORE
clause when the cursor enters a field in field-list. It passes control to the
statements following an AFTER clause when the cursor leaves a field in
field-list (after the user has pressed RETURN, indicating that data has been
7-124
INPUT
ESCAPE, if you have specified another key as the Accept key in the
OPTIONS statement.
Other keys that may have special meaning on your system, such as
CTRL-S for XOFF.
13. Use of CTRL-I and CTRL-J in a key-list can conflict with normal data entry.
INFORMIX-4GL Statement Syntax
7-125
INPUT
14. In addition to the RETURN, ESCAPE, Interrupt, and Arrow keys, the user
can employ the following keys for editing during an INPUT statement:
CTRL-A
CTRL-D
CTRL-H
CTRL-L
CTRL-R
CTRL-X
15. Function infield(field) from the function library returns TRUE if the current field is field, and FALSE otherwise. Use it to make field-dependent
responses when the user presses a key specified in the key-list of an ON
KEY clause. If you call infield(field) outside the INPUT statement, it returns
a value corresponding to the field that was current when INPUT was
terminated.
16. Do not execute PROMPT, INPUT, or INPUT ARRAY statements within the
BEFORE, AFTER, or ON KEY clauses of an INPUT statement. You can, however, call a function that executes one of these statements.
17. If you do not use the ATTRIBUTE clause, the display attributes of the input
fields are governed by the INPUT ATTRIBUTE clause of the most recent
OPTIONS statement. (The description of the OPTIONS statement lists the
order of precedence among different sources of 4GL screen attribute
specifications.)
18. In an INPUT statement, any screen attributes specified in attribute-list
apply to all the fields in field-list or screen-record.
19. If you use the ATTRIBUTE clause, no default attributes in syscolatt or
in the form specification file for fields in field-list or screen-record apply
(including any default values from the DEFAULT attribute). The
attribute-list temporarily overrides any attributes specified in an
OPTIONS, DISPLAY FORM, or OPEN WINDOW statement for these fields.
7-126
INPUT
REVERSE
BLINK
UNDERLINE
You can specify zero or one of the keywords in the left-hand columns, and
from zero to three from the right-hand column (but some terminals may
not support some combinations). On color terminals, NORMAL is interpreted as WHITE, BOLD as RED, DIM as BLUE, and INVISIBLE as BLACK.
Do not include the equal ( = ) sign, which in this table shows the effect on
monochrome terminals of keywords that specify color.
These keywords cannot produce the effects suggested by their names
unless the termcap or terminfo files and the physical terminals support
the attribute. (See Appendix I, Modifying termcap and terminfo.)
Note: Some terminal entries in termcap or terminfo include the sg#1 or
xmc#1 capabilities. On these terminals, the first character of variable-list is
replaced by a blank if you use the INPUT statement with any display attribute.
To be safe, make sure that fields in any line of a screen form begin after column 1,
if you specify display attributes.
21. On UNIX systems that use terminfo files rather than termcap, INFORMIX-4GL does not support attributes that specify colors, and the only
valid attribute-list keywords are REVERSE and UNDERLINE.
7-127
INPUT
Example
INPUT p_addr.* FROM sc_addr.*
ATTRIBUTE (REVERSE RED)
HELP 101
BEFORE FIELD fname
MESSAGE "Enter first name of customer"
BEFORE FIELD lname
MESSAGE "Enter last name of customer"
AFTER INPUT
IF check_zip(p_addr.zipcode, p_addr.city)
= FALSE THEN
ERROR "Bad zip code for ", p_addr.city
NEXT FIELD zipcode
END IF
ON KEY (F1)
IF infield(city) THEN
LET p_addr.city = "San Francisco"
DISPLAY p_addr.city TO city
LET p_addr.state = "CA"
DISPLAY p_addr.state TO state
NEXT FIELD zipcode
END IF
END INPUT
Related Statements
DISPLAY, DISPLAY FORM, EXIT, INPUT ARRAY, OPTIONS
7-128
INPUT ARRAY
INPUT ARRAY
Overview
Use the INPUT ARRAY statement to permit the user to enter data onto a screen
array and to store the data in a program record array.
Syntax
INPUT ARRAY record-array [ WITHOUT DEFAULTS ]
FROM screen-array.* [ HELP help-number ]
[ ATTRIBUTE ( attribute-list ) ]
[ { BEFORE { ROW | INSERT | DELETE
| FIELD field-sublist } [ , . . . ]
| AFTER { ROW | INSERT | DELETE |
FIELD field-sublist | INPUT } [ , . . . ]
| ON KEY ( key-list ) }
statement
...
[ NEXT FIELD field-name ]
...
[ EXIT INPUT ]
...
...
END INPUT ]
Explanation
INPUT ARRAY
record-array
WITHOUT
DEFAULTS
FROM
is a required keyword.
screen-array
HELP
is an optional keyword.
help-number
statement.
ATTRIBUTE
(attribute-list)
7-129
INPUT ARRAY
BEFORE
is an optional keyword.
ROW
is an optional keyword.
INSERT
is an optional keyword.
DELETE
is an optional keyword.
FIELD
is an optional keyword.
field-sublist
AFTER
is an optional keyword.
INPUT
is an optional keyword.
ON KEY
key-list
is usually a list of one or more function or CTRL key designations. The list can also include ESCAPE (if you have specified
another key as the Accept key in the OPTIONS statement) or
Interrupt (if you have executed a DEFER INTERRUPT statement).
statement
NEXT FIELD
field-name
EXIT INPUT
END INPUT
Notes
1. When you execute the INPUT ARRAY statement with the WITHOUT
DEFAULTS clause, INFORMIX-4GL displays in screen-array the values in
record-array. You must call set_count() with the number of rows in
program-array before the INPUT ARRAY statement. (See a later note for the
definition of set_count().) This is appropriate when you are requesting
input prior to updating an existing row of a table.
2. When you execute the INPUT ARRAY statement omitting the WITHOUT
DEFAULTS clause, INFORMIX-4GL initializes the first row of screen-array
and record-array with the default values from the form specification (or
from syscolval if no defaults were set in the form). INFORMIX-4GL
assigns NULL values for all variables for which no default has been set.
As the cursor moves into a blank line of screen-array, INFORMIX-4GL ini7-130
INPUT ARRAY
LEFT ARROW
DOWN ARROW
UP ARROW
moves the cursor up one row on the screen. If the cursor was on the first row before the user pressed [ ],
the displayed data moves down one row. If the first
program array row is already on the first screen array
row, [ ] does nothing.
F3
F4
scrolls the display to the previous full page of program array rows. You can reset this key using the
OPTIONS statement.
7-131
INPUT ARRAY
7. The INPUT ARRAY statement is terminated when the user enters ESC or
the key you specified as the Accept key in the OPTIONS statement. If there
is an AFTER INPUT clause, the program control passes to the statements
following that clause, rather than to the statements following the END
INPUT clause. This feature allows the programmer to perform data validity checks before allowing the INPUT ARRAY statement to terminate.
Unlike the INPUT statement, the RETURN does not terminate the
statement.
8. The number of variables in a row of record-array must be the same as the
number of fields in a row of screen-array and of the corresponding data
type.
9. INFORMIX-4GL executes BEFORE, AFTER, and ON KEY clauses in the following order:
BEFORE ROW
BEFORE INSERT, DELETE
BEFORE FIELD
ON KEY
AFTER FIELD
AFTER INSERT, DELETE
AFTER ROW
AFTER INPUT
INPUT ARRAY
7-133
INPUT ARRAY
24. You can include the following keys in a key-list under the stated
conditions:
ESCAPE, if you have specified another key as the Accept key in the
OPTIONS statement.
[ F3 ] if you have specified another key as the Next key in the OPTIONS
statement.
statement.)
You cannot use the following keys in a key-list:
Other keys that may have special meaning on your operating system.
25. Use of CTRL-I and CTRL-J in a key-list can conflict with normal data entry.
26. In addition to the RETURN, ESCAPE, Interrupt, function, and Arrow keys,
the user can employ the following keys for editing during an INPUT
ARRAY statement:
CTRL-A
CTRL-D
CTRL-H
CTRL-L
CTRL-R
CTRL-X
27. The function infield(field) from the function library returns TRUE if the
current field is field and FALSE otherwise. It can be used to make fielddependent responses when the user presses a key in the key-list of an
7-134
INPUT ARRAY
ON KEY clause. If you call infield(field) outside the INPUT ARRAY statement, it returns a value corresponding to the field that was current when
INPUT ARRAY was terminated.
28. Do not execute PROMPT, INPUT, or INPUT ARRAY statements within the
BEFORE, AFTER, or ON KEY clauses of an INPUT ARRAY statement. However, you can call a function that executes one of these statements.
29. Four functions are required to keep track of the relative state of the cursor,
the program array, and the screen array. The functions are defined as
follows:
arr_curr( )
arr_count( )
scr_line( )
set_count( )
30. If you do not use the ATTRIBUTE clause, the display attributes of the input
fields are governed by the INPUT ATTRIBUTE clause of the most recent
OPTIONS statement. (The description of the OPTIONS statement lists the
order of precedence among different sources of 4GL screen attribute
specifications.)
31. In an INPUT ARRAY statement, any screen attributes specified in
attribute-list apply to all the fields in field-list or screen-record.
32. If you use the ATTRIBUTE clause, none of the default attributes listed in
syscolatt or in the form specification file for fields in field-list or
screen-record apply (including any default values from the DEFAULT
attribute). The attribute-list temporarily overrides any attributes specified
in an OPTIONS, DISPLAY FORM, or OPEN WINDOW statement for these
fields.
7-135
INPUT ARRAY
REVERSE
BLINK
UNDERLINE
You can specify zero or one of the keywords in the left-hand columns, and
from zero to three from the right-hand column (but some terminals may
not support some combinations). On color terminals, NORMAL is interpreted as WHITE, BOLD as RED, DIM as BLUE, and INVISIBLE as BLACK.
Do not include the equal ( = ) sign, which in this table shows the effect on
monochrome terminals of keywords that specify color.
These keywords cannot produce the effects suggested by their names
unless the termcap or terminfo files and the physical terminals support
the attribute. (See Appendix I, Modifying termcap and terminfo.)
Note: Some terminal entries in termcap or terminfo include the sg#1 or
xmc#1 capabilities. On these terminals, the first character of variable-list is
replaced by a blank if you use the INPUT statement with any display attribute.
To be safe, make sure that fields in any line of the screen form begin after
column 1, if you specify display attributes.
34. On UNIX systems that use terminfo files rather than termcap, INFORMIX-4GL does not support attributes that specify colors, and the only
valid attribute-list keywords are REVERSE and UNDERLINE.
7-136
INPUT ARRAY
Example
The following program fragment assumes that one column of the screen
array (sc_array) contains the row number (row_num) of the program array
(pa_array) being displayed there. The next column of sc_array is called
first_data. The program recalculates and displays the row number after the
user inserts new rows or deletes old ones.
DEFINE pa_total INTEGER
DEFINE pa_curr
INTEGER
DEFINE sc_curr
INTEGER
#
#
#
#
#
#
#
#
DEFINE k
SMALLINT
INPUT ARRAY pa_array FROM sc_array.*
AFTER INSERT, DELETE
LET pa_curr = arr_curr()
LET pa_total = arr_count()
LET sc_curr = scr_line()
FOR k = pa_curr TO pa_total
LET pa_array[k].row_num = k
IF sc_curr <= sc_total THEN
DISPLAY k TO sc_array[sc_curr].row_num
LET sc_curr = sc_curr + 1
END IF
END FOR
END INPUT
Related Statements
DISPLAY ARRAY, EXIT, INPUT, OPTIONS
7-137
INSERT
INSERT
Overview
Use the INSERT statement to insert one or more new rows into an existing
table.
Syntax
INSERT INTO table-name [ ( column-list ) ]
{ VALUES ( value-list ) | SELECT-statement }
Explanation
INSERT INTO
table-name
column-list
VALUES
is a keyword.
value-list
are the values to insert into the columns that you specified. You can enter one or more program variables or constants, separated by commas.
SELECT-statement
Notes
1. INFORMIX-4GL inserts data into the columns in the specified table in the
order in which you enter column names. It inserts the first value that you
enter into the first listed column, the second value into the second listed
column, and so on.
2. Entering column names is optional. If you omit them, 4GL assumes that
the values are listed in the order in which the columns are listed in the
syscolumns systems catalog. Unless you have subsequently used the
ALTER TABLE statement to change the order, the order is the same as
when the table was created.
3. If you have previously defined a RECORD type program variable LIKE
table-name, you can use the program variable in place of a list of values in
an INSERT statement.
7-138
INSERT
7-139
INSERT
reduce the scope of the INSERT statement or lock the entire table before
executing the statement.
See the section Locking in Chapter 3 for a more detailed description of
table-level and row-level locking in INFORMIX-4GL.
Caution: 4GL makes every possible effort to perform data conversion, including
converting the character string 123 into the integer 123. If the data cannot be converted, however, INSERT stops. Unless you have created the database with
transactions, all changes made to that point remain, but subsequent rows from the
SELECT statement will not be inserted. Data conversion also fails if the target data
type cannot hold the value offered. For example, you cannot insert the integer
123456 into a SMALLINT.
Examples
DEFINE ps_customer RECORD LIKE customer.*
...
INSERT INTO customer VALUES (ps_customer.*)
INSERT INTO customer VALUES (0, f_name, l_name, comp,
addr1, addr2, "Palo Alto", "CA", zip, phone)
Related Statements
DECLARE, DELETE, SELECT
7-140
LABEL
LABEL
Overview
Use the LABEL statement to indicate the position in a 4GL program to which
the GOTO statement transfers control.
Syntax
LABEL label-id:
Explanation
LABEL
is a required keyword.
label-id:
Note
The LABEL statement must be in the same program block (MAIN, FUNCTION,
or REPORT) as the GOTO statement with the same label-id. You cannot use
GOTO to transfer out of a routine.
Example
IF customer_num < 0 THEN
GOTO abort
END IF
statement
...
LABEL abort:
statement
Related Statements
GOTO, WHENEVER
7-141
LET
LET
Overview
Use the LET statement to assign a value to a program variable.
Syntax
LET variable = expr
Explanation
LET
variable
expr
is a required keyword.
is the identifier of a simple program variable.
is an expression.
Notes
1. The variable can be an element of an ARRAY if that element is a simple
variable.
2. As an exception to the .* notation, you may make assignment to a record
variable from another record variable using the statement
LET x.* = y.*
This statement is shorthand for a sequence of LET statements assigning values of elements of y to elements of x.
Examples
LET a = b + c
LET d[index] = "This is a string"
LET newstr = mystr[2,6]
Related Statement
INITIALIZE
7-142
LOAD
LOAD
Overview
Use the LOAD statement to fill an existing table with data taken from an ASCII
file.
Syntax
LOAD FROM "pathname" [ DELIMITER "char" ]
{ INSERT INTO table-name [ ( column-name [ , . . . ] ) ]
| INSERT-stmt }
Explanation
LOAD FROM
pathname
is a character variable or constant that evaluates to the pathname of a file that contains rows of data.
DELIMITER
char
INSERT INTO
table-name
column-name
INSERT-stmt
Notes
1. You must have INSERT permission to use the LOAD statement.
2. You can specify an optional list of one or more column names, enclosed
within parentheses and separated by commas.
3. Fields in the input file must be separated by a delimiter character. If you
do not specify a delimiter in the DELIMITER clause, INFORMIX-4GL
7-143
LOAD
7-144
LOAD
Example
LOAD FROM "/a/data/ord.loadfile" DELIMITER ";"
INSERT INTO orders
LOAD FROM "/tmp/prices" DELIMITER ","
INSERT INTO walter.worktab(price,discount)
Related Statements
UNLOAD, INSERT
Note: INFORMIX-OnLine supports additional data types. Refer to the INFORMIX-OnLine Programmers Manual for more information.
7-145
LOCK TABLE
LOCK TABLE
Overview
Use the LOCK TABLE statement to control access to a table by other users.
Syntax
LOCK TABLE table-name IN { SHARE | EXCLUSIVE } MODE
Explanation
LOCK TABLE
table-name
IN
is a required keyword.
SHARE
EXCLUSIVE
MODE
is a required keyword.
Notes
1. Only one lock can apply to a table at any given time. That is, if a user locks
a table (in either SHARE or EXCLUSIVE mode), no other user can lock that
table in either mode until the first user unlocks it.
2. If your database has transactions and is not MODE ANSI, you must issue
a BEGIN WORK statement before you can issue the LOCK TABLE
statement.
3. You can use the LOCK TABLE statement immediately after beginning a
transaction to override row-level locking during the transaction. Normally, each row of a table affected by a statement within a transaction is
locked for the duration of the transaction. During transactions that affect
a large number of rows, you can exceed the limit that your operating system places on the maximum number of locks.
If you lock the entire table at the beginning of the transaction, however,
INFORMIX-4GL does not lock each row in the table. You may want to use
7-146
LOCK TABLE
Example
LOCK TABLE orders IN EXCLUSIVE MODE
Related Statements
BEGIN WORK, COMMIT WORK, UNLOCK TABLE
7-147
MAIN
MAIN
Overview
Use the MAIN keyword to introduce the MAIN program block.
Syntax
MAIN
statement
...
END MAIN
Explanation
MAIN
is a required keyword.
statement
END MAIN
Note
Every INFORMIX-4GL program must have a MAIN program block and can
have one or more functions and reports.
Related Statements
FUNCTION, REPORT
7-148
MENU
MENU
Overview
Use the MENU statement to create a menu screen, to define user menu
options, to designate help numbers, and to define what statements should be
executed for each option.
Syntax
MENU "menu-name"
COMMAND { KEY ( key-list ) |
[ KEY ( key-list ) ] "menu-option"
[ "helpline" ] [ HELP help-number ] }
statement
...
[ CONTINUE MENU ]
...
[ EXIT MENU ]
...
[ NEXT OPTION "menu-option" ]
...
...
END MENU
Explanation
MENU
is a required keyword.
menu-name
COMMAND
is a required keyword.
KEY
is an optional keyword.
key-list
menu-option
helpline
HELP
is an optional keyword.
7-149
MENU
help-number
is the number of the help message in the help file designated in the OPTIONS statement that corresponds to
menu-option.
statement
CONTINUE MENU
EXIT MENU
NEXT OPTION
END MENU
Notes
1. You must define at least two options (COMMAND clauses) for each menu.
2. The menu screen displays in a ring menu each of the single-word menuoptions in the order of the COMMAND clauses.
3. When INFORMIX-4GL displays a menu, it adds a colon (:) and a space
after the menu name, as well as a space before and after each menu
option. If the width of the menu exceeds the number of characters that the
screen or a window can display on a single line, INFORMIX-4GL displays
the first page of options followed by an ellipsis ( . . . ) indicating that
additional options exist. For example,
menu-name: menu-option1
optional Help line
menu-option2
menu-option3
menu-option4
...
If the user presses the SPACEBAR or [ ] key to move past the rightmost
option (menu-option4 in this case), INFORMIX-4GL displays the next
7-150
MENU
page of menu options. In the following example, the ellipses at each end
indicate that more menu options exist in both directions.
menu-name: ... menu-option5
optional Help line
menu-option6
menu-option7
menu-option8
...
If the user moves the highlight to the right past menu-option8 in this
example, INFORMIX-4GL displays a page of menu options like the
following:
menu-name: ... menu-option9
optional Help line
menu-option10
menu-option11
Since no ellipsis appears to the right of the menu, the user has come to the
last page of the menu options. The user can display the previous page of
menu options again by using the [ ] key to move the highlight past the
leftmost option in the example. The user can display the first page of
menu options by using the [ ] key to move the highlight past the rightmost option in the example.
The [ ] key moves the highlight to the first item on the previous page;
the [ ] key moves the highlight to the first item on the subsequent page.
4. The help-number refers to the number of the help message in the help file
set by the OPTIONS statement.
5. A run-time error occurs if you specify a help-number for an option, and
that number does not occur in the help file, or if the help file does not
exist.
6. You will incur a run-time error if the menu cannot fit on the screen or in
the current window.
INFORMIX-4GL Statement Syntax
7-151
MENU
7. INFORMIX-4GL truncates any helpline that exceeds the width of the screen
or current window.
8. The user chooses an option by typing one of the letters in key-list. If the
KEY clause is not present, the user chooses an option by typing the first
letter of menu-option.
9. After the user chooses an option, INFORMIX-4GL executes the statements
immediately following the COMMAND clause.
10. After INFORMIX-4GL executes all the statements for an option, it redisplays the menu, and the user can choose another option.
11. You can execute a CONTINUE MENU statement anywhere within the
statements following the COMMAND clause. Use of this statement causes
the menu to reappear so that the user can choose another option.
12. The key-list notation to specify function keys is F1 through F36. The notation for CTRL keys is CONTROL-key, where key is any letter except A, D,
H, L, R, or X (Some other keys, such as CTRL-S, CTRL-Q, or CTRL-Z
might also not be allowed, depending on your implementation of the
UNIX operating system.)
The key-list notation for the key is ESC or ESCAPE. The notation for the
Interrupt key (often DEL or CTRL-C) is INTERRUPT.
13. Unless you use the KEY clause, the initial letters of each menu-option
should be different, regardless of case. The values within the key-list must
be unambiguous. Each option must be uniquely defined.
14. INFORMIX-4GL produces a run-time error if a menu option exceeds the
length of the screen or window.
15. You can add a hidden option to your menu by including a KEY key-list
choice in the list of menu COMMANDs. This is demonstrated in the following example.
7-152
MENU
Example
MENU "TOP LEVEL"
COMMAND "Add" "Add a row to the database" HELP 12
...
COMMAND "Find" "Find a row in the database" HELP 13
...
COMMAND "Change" "Update a row in the database" HELP 14
...
COMMAND "Delete" "Delete a row from the database" HELP 15
...
COMMAND key ("!")
CALL bang()
...
COMMAND "Exit" "Return to operating system" HELP 16
EXIT PROGRAM
END MENU
Delete
Exit
Related Command
OPTIONS
7-153
MESSAGE
MESSAGE
Overview
Use the MESSAGE statement to display a character string on the Message line.
Syntax
MESSAGE display-list [ ATTRIBUTE ( attribute-list ) ]
Explanation
MESSAGE
is a required keyword.
display-list
is a list of one or more program variables and/or string constants (enclosed in quotation marks), separated by commas.
ATTRIBUTE
is an optional keyword.
attribute-list
Notes
1. INFORMIX-4GL generates the message by replacing the variables in
display-list with their values and concatenating the resulting strings.
2. The default Message line is the same line used to display the helpline in
menus. See the OPTIONS statement for information about resetting this
line to a different position.
3. The default attribute for the Message line is the NORMAL display. You can
alter the default attribute with the ATTRIBUTE clause.
7-154
MESSAGE
4. The following list shows the screen attributes allowed in the ATTRIBUTE
clause:
WHITE = NORMAL
YELLOW = BOLD
MAGENTA = BOLD
RED = BOLD
CYAN = DIM
GREEN = DIM
BLUE = DIM
BLACK = INVISIBLE
REVERSE
BLINK
UNDERLINE
Example
MESSAGE "Enter the order data."
Related Statements
OPTIONS, PROMPT
7-155
OPEN
OPEN
Overview
Use the OPEN statement to establish search criteria for a SELECT cursor and
initialize the system for subsequent FETCHes, or to set up an INSERT buffer
for an INSERT cursor that references program variables.
Syntax
OPEN cursor-name [ USING variable-list ]
Explanation
OPEN
is a required keyword.
cursor-name
USING
variable-list
is a list of program variables, separated by commas, corresponding to the ? parameters in a query associated with a
SELECT cursor.
Notes
1. If cursor-name is associated with a SELECT statement, the OPEN statement
examines the content of the program variables and, using these values for
the parameters in the SELECT statement, establishes the search criteria for
determining the logical set of rows that satisfies the WHERE clause. This
set of rows is called the active set. It leaves the cursor in an open state and
pointing before the first row of the active set.
2. The active set is a dynamic collection of rows; it is not fixed at the time
when the OPEN statement is executed. Rows meeting the WHERE criteria
and qualified for FETCHing depend on the activity in the table.
3. Once the active set for a SELECT cursor is determined, the program variables are not reexamined until you reopen the cursor.
4. If a SELECT cursor is already open, an OPEN statement closes the cursor
and reopens it, creating a new active set, based on the current values of
the program variables.
7-156
OPEN
5. The FOREACH statement performs an implied OPEN statement. You cannot use the FOREACH statement if the OPEN statement for a SELECT
cursor must have a USING clause to supply values for ? parameters in
a PREPAREd SELECT statement.
6. If cursor-name is associated with an INSERT statement (rather than a
SELECT statement), the OPEN statement cannot include a USING clause.
7. If you reopen an INSERT cursor that is already open, INFORMIX-4GL
flushes the INSERT buffer (that is, INFORMIX-4GL inserts any rows currently in the INSERT buffer into the database table). The global variable
SQLCA. SQLERRD [3] is set to the number of rows successfully inserted
into the database.
8. A cursor declared FOR UPDATE is called an UPDATE cursor. In a database
that uses transactions, you cannot OPEN an UPDATE cursor outside a
transaction unless it also was declared WITH HOLD. You can OPEN a nonUPDATE cursor, or one declared WITH HOLD, at any time.
In a non-MODE ANSI database that has transactions, a transaction begins
with a BEGIN WORK statement and ends with a COMMIT WORK or ROLLBACK WORK statement. In a MODE ANSI database, no BEGIN WORK is
required; all actions take place inside transactions.
9. If you declare a cursor with a DECLARE statement that includes the
SELECT or INSERT keywords, INFORMIX-4GL implicitly PREPAREs the
statement when you OPEN that cursor.
10. The database engine allocates resources to explicitly or implicitly PREPAREd statements. If you release resources with FREE cursor-name, you
cannot use that cursor unless you OPEN it again. If you specify FREE
statement-id, you cannot OPEN a cursor that references statement-id unless
you PREPARE that statement again.
Examples
DECLARE s_curs CURSOR FOR
SELECT * FROM orders
OPEN s_curs
DECLARE q_cursor CURSOR FOR
SELECT o.order_num, SUM(total_price)
FROM orders o, items i
WHERE o.order_date > "06/04/86"
AND o.customer_num = 110
AND o.order_num = i.order_num
GROUP BY o.order_num
OPEN q_cursor
7-157
OPEN
Related Statements
CLOSE, DECLARE, FETCH, FLUSH, FOREACH, FREE, PREPARE, PUT
7-158
OPEN FORM
OPEN FORM
Overview
Use the OPEN FORM statement to associate an INFORMIX-4GL identifier with
a pre-compiled screen form.
Syntax
OPEN FORM form-name FROM "form-file"
Explanation
OPEN FORM
form-name
is an INFORMIX-4GL identifier.
FROM
is a required keyword.
form-file
Notes
1. You must open a form before you can display it.
2. When you execute the OPEN FORM statement, the compiled form is
loaded into and kept in memory until you execute a CLOSE FORM statement for that form. If you have displayed another form and wish to regain
the space used by the first form, you can execute CLOSE FORM on the old
form. The CLOSE FORM statement is a memory-management feature only;
it does not affect the logic of the program.
Example
OPEN FORM order_form FROM "orderform"
Related Statements
CLOSE FORM, DISPLAY FORM
7-159
OPEN WINDOW
OPEN WINDOW
Overview
Use the OPEN WINDOW statement to create and open a window at a specified
origin on the screen. This can optionally display a form.
Syntax
OPEN WINDOW window-name AT row, column
WITH { integer ROWS, integer COLUMNS | FORM "form-file" }
[ ATTRIBUTE ( attribute-list ) ]
Explanation
7-160
OPEN WINDOW
window-name
AT
is a required keyword.
row
is an integer or integer variable between one and the maximum number of lines allowed by your terminal (usually
24), indicating the line on the screen where the top of the
window will appear.
column
is an integer or integer variable between one and the maximum number of columns allowed by your terminal
(usually 80), indicating the column of the screen where
the left margin of the window will appear.
WITH
is a required keyword to specify the vertical and horizontal dimensions of the window, in characters.
integer
ROWS
COLUMNS
FORM
is an optional keyword.
form-file
ATTRIBUTE
is an optional keyword.
(attribute-list)
OPEN WINDOW
Notes
1. When you open a window, INFORMIX-4GL saves any current window
and makes the new window the current window.
2. The window-name is a 4GL identifier whose scope is global to the entire
program. It must begin with a letter. Up to 17 additional characters can
include letters, numbers, and underscores ( _ ).
3. You can use the WITH integer ROWS, integer COLUMNS clause to specify
explicit dimensions for the window.
Alternatively, you can include a WITH FORM clause, so that INFORMIX-4GL automatically opens a window sized to the screen layout of
form-file and displays the form. INFORMIX-4GL determines the width of
the window from the rightmost character of the screen form and calculates the length of the window as this sum:
( FORM LINE (relative to the first line of the window) -1 )
+ form-length
+ 1 (for the COMMENT LINE )
7-161
OPEN WINDOW
Attribute
BORDER
color (see note 13)
REVERSE
PROMPT LINE line-value
MESSAGE LINE line-value
FORM LINE line-value
COMMENT LINE line-value
Default Setting
No border
The default foreground color on your terminal
No reverse video
FIRST ( = 1 )
FIRST + 1 ( = 2 )
FIRST + 2 ( = 3 )
LAST - 1 (for the screen)
LAST (for all other windows)
7-162
OPEN WINDOW
11. When you use the BORDER attribute, INFORMIX-4GL draws a border outside the window area that you specify. For example, if you open the
following window
OPEN WINDOW w1 AT 10,10 WITH 5 ROWS, 30 COLUMNS
ATTRIBUTE (BORDER)
INFORMIX-4GL displays a border with coordinates like those in the fol-
lowing example:
(9,9)
(9,40)
+------------------------------+
|
|
|
|
|
|
|
|
|
|
+------------------------------+
(15,9)
(15,40)
INFORMIX-4GL draws the border with characters defined in the termcap
RED
CYAN
GREEN
BLUE
BLACK
DIM
INVISIBLE
BOLD
NORMAL
14. If you specify a color in the ATTRIBUTE clause of an OPEN WINDOW statement, it becomes the default color for anything displayed in the window
except a menu. You can override the default color for a particular display
by specifying a different color in the ATTRIBUTE clause of a CONSTRUCT,
INFORMIX-4GL Statement Syntax
7-163
OPEN WINDOW
statement.
15. Windows are stacked in the order that they are opened. See the CURRENT WINDOW and CLOSE WINDOW statements for information
about how these statements affect the window stack.
Examples
OPEN WINDOW w1 AT 5, 5
WITH FORM "custform"
OPEN WINDOW w2 AT 10, 12
WITH 5 ROWS, 40 COLUMNS
ATTRIBUTE (BORDER, PROMPT LINE 3)
Related Statements
CLEAR WINDOW, CLOSE FORM, CLOSE WINDOW, CURRENT WINDOW,
OPTIONS
7-164
OPTIONS
OPTIONS
Overview
The OPTIONS statement can modify the reserved line positions and input or
display attributes for screen forms, and can change the keys for screen operations and program aids (like help messages).
Syntax
OPTIONS {MESSAGE LINE line-value |
PROMPT LINE line-value |
COMMENT LINE line-value |
ERROR LINE line-value |
FORM LINE line-value |
INPUT { WRAP | NO WRAP } |
INSERT KEY key-name |
DELETE KEY key-name |
NEXT KEY key-name |
PREVIOUS KEY key-name |
ACCEPT KEY key-name |
HELP FILE "help-file" |
HELP KEY key-name |
INPUT ATTRIBUTE ( attribute-list ) |
DISPLAY ATTRIBUTE ( attribute-list ) } [ , . . . ]
Explanation
OPTIONS
is a required keyword.
line-value
MESSAGE
LINE
PROMPT
LINE
COMMENT
LINE
ERROR LINE
7-165
OPTIONS
FORM LINE
INPUT WRAP
INPUT
NO WRAP
key-name
INSERT KEY
DELETE KEY
NEXT KEY
PREVIOUS KEY are optional keywords to specify the key that scrolls to the
previous page in the INPUT ARRAY or DISPLAY ARRAY statement. The default is [ F4 ].
7-166
ACCEPT KEY
HELP FILE
are optional keywords to specify the file that contains programmer-defined help messages. (Appendix E describes
mkmessage, the help message utility.)
help-file
HELP KEY
INPUT
ATTRIBUTE
attribute-list
is a list of one or more screen display attributes, or the keywords FORM or WINDOW.
OPTIONS
DISPLAY
ATTRIBUTE
Notes
1. You can use the OPTIONS statement to change the defaults listed earlier.
(If you list more than one item in an OPTIONS statement, make sure to
separate the items with commas.)
2. You can issue the OPTIONS statement more than once. The values set in
the last OPTIONS statement encountered at run time prevail.
3. The line-value to position the Form line can be either integer or FIRST
[ + integer]. The line-value of the other reserved lines can have any of the
following formats:
integer
FIRST
LAST
[ + integer ]
[ - integer ]
Here FIRST is the first line of the current window (line 1), and LAST is the
last line of the current window.
4. The line-value for the Error line is relative to the screen, rather than to the
current window. The line-value of any other reserved line is relative to the
first line of the current window (or to the screen, if that is the current
window).
5. The key-name notation to specify function keys is F1 through F36.
The key-name notation for CTRL keys is CTRL-key, where key is any letter
except A, D, H, L, Q, R, S, or X. The key-name notation for is
ESC or ESCAPE.
6. INFORMIX-4GL uses the CTRL keys CTRL-A, CTRL-D, CTRL-H, CTRL-L,
CTRL-R, and CTRL-X for screen-editing functions. You cannot use these
for the Insert key, Delete key, Next key, Previous key, Accept key, or Help
key. In addition, you might not be able to use some other keys, such as
CTRL-C, CTRL-S, CTRL-Q, or CTRL-Z, depending on your implementation
of the UNIX operating system.
7. During a CONSTRUCT, DISPLAY, DISPLAY ARRAY, DISPLAY FORM, INPUT,
or INPUT ARRAY statement, INFORMIX-4GL checks for attributes and
reserved line positions in the following order of precedence (from highest
to lowest):
1. Any ATTRIBUTE clause in the current statement.
2. Any attributes from field descriptions in the current form file. (See the
Attributes Syntax section of Chapter 4.)
INFORMIX-4GL Statement Syntax
7-167
OPTIONS
BLUE
BLACK
DIM
INVISIBLE
BOLD
NORMAL
REVERSE
BLINK
UNDERLINE
FORM
WINDOW
7-168
OPTIONS
Examples
The following statement sets three reserved line positions and specifies the
Next and Previous keys:
OPTIONS MESSAGE LINE 23,
PROMPT LINE LAST-2,
FORM LINE FIRST,
NEXT KEY CONTROL-N,
PREVIOUS KEY CONTROL-P
The following statement causes screen fields to appear as green where values
are input, regardless of the foreground form color or window color:
OPTIONS INPUT ATTRIBUTE (green)
Related Statements
CONSTRUCT, DISPLAY, DISPLAY ARRAY, DISPLAY FORM, ERROR, INPUT,
INPUT ARRAY, MENU, MESSAGE, OPEN FORM, OPEN WINDOW, PROMPT
7-169
OUTPUT TO REPORT
OUTPUT TO REPORT
Overview
Use the OUTPUT TO REPORT statement to pass a single row of data to a report.
Syntax
OUTPUT TO REPORT report-name (expr-list)
Explanation
OUTPUT TO
REPORT
report-name
expr-list
Notes
1. Ordinarily, you will use the OUTPUT TO REPORT statement within a loop
that passes data to a report.
2. The number of expressions in expr-list should agree with the number and
type of arguments in the REPORT routine.
Example
OUTPUT TO REPORT rept1 (v_pers.*)
Related Statements
FINISH REPORT, REPORT, START REPORT
7-170
PREPARE
PREPARE
Overview
Use the PREPARE statement to preprocess an SQL statement for later execution. The SQL statements are listed in Chapter 3.
Syntax
PREPARE statement-id FROM string-spec
Explanation:
PREPARE
is a required keyword.
statement-id
FROM
is a required keyword.
string-spec
Notes
1. The statement(s) described in string-spec cannot contain program variables. Use a question mark ( ? ) as a placeholder for an input value that
will be supplied in an EXECUTE, OPEN, or PUT statement. Do not use a
question mark as a placeholder for an SQL identifier such as a database
name, table name, column name, or user name.
2. If you PREPARE a SELECT statement for use with the DECLARE statement,
string-spec can include a SELECT statement followed by a FOR UPDATE
clause.
3. The string-spec cannot include any of the following statements: CLOSE,
DECLARE, EXECUTE, FETCH, LOAD, OPEN, PREPARE, UNLOAD, and
WHENEVER.
4. Do not PREPARE a SELECT statement with an INTO clause.
5. The scope of statement-id is the module in which you PREPARE it. You can
refer to it by name in functions contained in the same module. It is not,
however, a global identifier that you can reference in another source file.
7-171
PREPARE
Example
LET select_2 = "select * from orders ",
"where customer_num = ? and ", "order_date > ?"
PREPARE query_2 FROM select_2
Related Statements
DECLARE, EXECUTE, FOREACH, FREE, OPEN
7-172
PROMPT
PROMPT
Overview
Use the PROMPT statement to prompt the user for keyboard input, and to
accept a value entered by the user.
Syntax
PROMPT display-list [ ATTRIBUTE ( attribute-list) ]
FOR [ CHAR ] variable
[ HELP help-number ]
[ ATTRIBUTE ( attribute-list) ]
[ ON KEY ( key-list)
statement
...
...
END PROMPT ]
Explanation
PROMPT
is a required keyword.
display-list
ATTRIBUTE
(attribute-list)
FOR
is a required keyword.
CHAR
is an optional keyword.
variable
HELP
is an optional keyword.
help-number
ON KEY
key-list
7-173
PROMPT
statement
is an INFORMIX-4GL statement.
END
PROMPT
Notes
1. INFORMIX-4GL displays the string generated by replacing the variables
in display-list with their current values on the Prompt line if an open form
is displayed. The prompt occurs at the current cursor position if no form
is displayed and
Function keys.
CTRL keys (except as noted later).
ESCAPE (if you have specified another key as the Accept key in the
OPTIONS statement).
Other keys like CTRL-S that may have special meaning on your implementation of UNIX.
6. INFORMIX-4GL terminates PROMPT and passes control to the statements
following an ON KEY clause when the user presses a key specified in key7-174
PROMPT
REVERSE
BLINK
UNDERLINE
You can specify zero or one of the keywords in the left-hand columns, and
from zero to three from the right-hand column (but some terminals may
not support some combinations). On color terminals, NORMAL is interpreted as WHITE, BOLD as RED, DIM as BLUE, and INVISIBLE as BLACK.
Do not include the equal ( = ) sign, which in this table shows the effect on
monochrome terminals of keywords that specify color.
These keywords cannot produce the effects suggested by their names
unless the termcap or terminfo files and the physical terminals support
the attribute. (See Appendix I, Modifying termcap and terminfo.)
7-175
PROMPT
Example
PROMPT "Enter the Customer Number: "
FOR v.cust_no
ON KEY (CONTROL-E)
GOTO stop_now:
END PROMPT
Related Statements
DISPLAY, DISPLAY ARRAY, INPUT, INPUT ARRAY, OPTIONS
7-176
PUT
PUT
Overview
Use the PUT statement to store a row in the INSERT buffer for later insertion
into the database table.
Syntax
PUT cursor-name
[ FROM variable-list ]
Explanation
PUT
is a required keyword.
cursor-name
FROM
is an optional keyword.
variable-list
is a list of program variables, separated by commas, corresponding to the ? parameters in the PREPAREd INSERT
statement associated with cursor-name.
Notes
1. You can execute the PUT statement only if cursor-name has been
DECLAREd for an INSERT statement and is in an open state. Such a cursor
is referred to as an INSERT cursor.
2. The PUT statement puts a row in the buffer created when cursor-name was
OPENed. When you flush the buffer (by executing a series of PUT statements, a CLOSE statement, or a FLUSH statement), INFORMIX-4GL inserts
the buffered rows into the database table as a block.
3. INFORMIX-4GL does not create an INSERT buffer for a cursor associated
with an INSERT statement that contains only constants in the VALUES
clause. If you execute a PUT statement for such a cursor, INFORMIX-4GL
increments a counter that keeps track of the number of rows to be inserted
into the database. The database is updated only when you issue a FLUSH
or CLOSE statement.
4. You close a cursor by issuing a CLOSE statement. Exiting a program without closing an insert cursor leaves the buffer unflushed. Rows inserted
7-177
PUT
into the buffer since the last flush are lost. You cannot rely on the end of
program to close the cursor and flush the buffer.
5. The global variables status (whose value is received from SQLCA.SQLCODE) and SQLCA.SQLERRD[3] indicate the result of each PUT statement.
If INFORMIX-4GL simply puts a row in the INSERT buffer, it sets status
and SQLCA.SQLERRD[3] to zero. If, as the result of a PUT statement,
INFORMIX-4GL successfully inserts a block of rows into the database, it
sets status to zero and sets SQLCA.SQLERRD[3] to the number of rows
inserted. If, as the result of a PUT statement, INFORMIX-4GL is unsuccessful in its attempt to insert an entire block of rows into the database, it sets
status to a negative number (specifically, the number of the error message) and sets SQLCA.SQLERRD[3] to the number of rows successfully
inserted into the database.
6. Whenever the buffer is flushed, SQLCA.SQLERRD[3] is set to the number
of rows successfully inserted into the database. If an error occurs during
the flushing of a buffer, the buffered rows that follow the last successfully
inserted row are discarded.
7. If your database has transactions, you must issue the PUT statement
within a transaction.
8. If cursor-name has been DECLAREd for a PREPAREd INSERT statement that
includes ? parameters, you must use the PUT statement with a FROM
clause. After the FROM keyword, you can list the variable(s) containing
the value(s) that INFORMIX-4GL substitutes for the ? parameters in the
PREPAREd INSERT statement.
Examples
DECLARE icurs CURSOR FOR
INSERT INTO manufact VALUES (m_code, m_name)
OPEN icurs
PUT icurs
PREPARE ins_stmt FROM
"INSERT INTO manufact VALUES (?, ?)"
DECLARE ins_curs CURSOR FOR ins_stmt
OPEN ins_curs
PUT ins_curs FROM m_code, m_name
Related Statements
CLOSE, DECLARE, FLUSH, OPEN, PREPARE
7-178
RECOVER TABLE
RECOVER TABLE
Overview
In the event of a system failure, use the RECOVER TABLE statement to restore
a database table from a backup copy and an audit trail file.
Syntax
RECOVER TABLE table-name
Explanation
RECOVER TABLE
table-name
Notes
1. Once you have recovered the table, use the DROP AUDIT statement to
remove the contents of the audit trail file. Run the CREATE AUDIT statement to start a new audit trail file, then back up the table. See the section
Audit Trails in Chapter 3 for more information.
2. RECOVER TABLE checks that the audit trail and table-name have consistent
record numbers for rows where changes have taken place. If RECOVER
TABLE finds inconsistencies, it stops restoring the table.
3. You must own table-name or have DBA status to use the RECOVER TABLE
statement.
Example
The following SQL statements give a template for the recovery of a table.
They assume that your audit trail began from the last backup.
{restore table from last backup}
RECOVER TABLE customer
DROP AUDIT FOR customer
CREATE AUDIT FOR customer IN "/dev/safe"
{make a backup of the recovered table}
INFORMIX-4GL Statement Syntax
7-179
RECOVER TABLE
Related Statements
CREATE AUDIT, DROP AUDIT
7-180
RENAME COLUMN
RENAME COLUMN
Overview
Use the RENAME COLUMN statement to change the name of a column.
Syntax
RENAME COLUMN table.oldcolumn TO newcolumn
Explanation
RENAME COLUMN are required keywords.
table
oldcolumn
TO
is a required keyword.
newcolumn
Notes
1. You can RENAME a column of a table only when you own the table, have
DBA privilege, or have been granted ALTER permission.
2. The RENAME COLUMN statement cannot be rolled back.
Example
RENAME COLUMN customer.customer_num TO c_num
Related Statements
ALTER TABLE, CREATE TABLE, INSERT, DROP TABLE, RENAME TABLE
7-181
RENAME TABLE
RENAME TABLE
Overview
Use the RENAME TABLE statement to change the name of a table in the
system catalogs.
Syntax
RENAME TABLE oldname TO newname
Explanation
RENAME TABLE
oldname
TO
is a required keyword.
newname
Notes
1. In a non-MODE ANSI database, the newname identifier must be unique
among tables and synonyms. In a MODE ANSI database, it must be unique
among tables and synonyms that you own.
2. You can RENAME a table only when you own the table, have DBA privilege, or have been granted ALTER permission on the table.
3. You can specify owner.oldname in a RENAME TABLE statement, but a compile-time error results if you specify owner.newname.
4. The RENAME TABLE statement cannot be rolled back.
7-182
RENAME TABLE
Example
This example moves the quantity column to the third place:
CREATE TABLE newtab
(item_num
order_num
quantity
stock_num
manu_code
total_price
)
SMALLINT,
INTEGER,
SMALLINT,
SMALLINT,
CHAR(4),
MONEY(8)
Related Statements
ALTER TABLE, CREATE TABLE, INSERT, DROP TABLE, RENAME COLUMN
7-183
REPORT
REPORT
Overview
Use the REPORT routine to provide the format specifications for a report.
Syntax
REPORT report-name ( variable-list )
[ DEFINE-statement ]
...
[ OUTPUT
output-statement
...]
[ ORDER [ EXTERNAL ] BY sort-list ]
FORMAT
format-statement
...
4gl-statement
...
END REPORT
Explanation
REPORT
is a required keyword.
report-name
is an INFORMIX-4GL identifier.
variable-list
is a list of zero or more variables, separated by commas.
DEFINE-statement is a DEFINE statement giving the data type for the variables in variable-list.
OUTPUT
is an optional keyword.
output-statement is an output statement described in Chapter 5.
ORDER BY
are optional keywords.
EXTERNAL
is an optional keyword.
sort-list
is a list of one or more variables from those in variable-list.
FORMAT
is a required keyword.
format-statement is a FORMAT statement described in Chapter 5.
4gl-statement
is an arbitrary INFORMIX-4GL statement.
END REPORT
are required keywords that terminate the REPORT
statement.
7-184
REPORT
Notes
1. If variable-list contains the name of a record, you must DEFINE the record
in DEFINE-statement. Do not append the .* to the name of the record in
variable-list.
2. See Chapter 5 for a discussion of the OUTPUT, ORDER BY, and FORMAT
sections of the REPORT routine.
3. If INFORMIX-4GL statements occur in the control blocks of the FORMAT
section, they are executed during the report-printing phase. If the data is
sorted outside the report, report printing takes place with each OUTPUT
TO REPORT statement. This is called a one-pass report. If the data is sorted
inside the report, report printing takes place with the FINISH REPORT
statement. This is called a two-pass report.
If 4GL statements occur in the OUTPUT TO REPORT loop as well as in the
report, INFORMIX-4GL alternately executes the 4GL statements in the
OUTPUT TO REPORT loop and the 4GL statements in the report during a
one-pass report. In contrast, INFORMIX-4GL repeatedly executes all the
4GL statements in the OUTPUT TO REPORT loop before executing the 4GL
statements in the report during a two-pass report.
Example
The simplest report displays the output of a query:
DECLARE simp_curs CURSOR FOR
SELECT * FROM CUSTOMER
START REPORT simple
FOREACH simp_curs INTO cust.*
OUTPUT TO REPORT simple(cust.*)
END FOREACH
FINISH REPORT simple
...
REPORT simple (x)
DEFINE x RECORD LIKE customer.*
FORMAT
EVERY ROW
END REPORT
Related Statements
FINISH REPORT, OUTPUT TO REPORT, START REPORT
7-185
RETURN
RETURN
Overview
Use the RETURN statement to leave a FUNCTION routine and to return values
to the calling routine.
Syntax
RETURN [expr-list]
Explanation
RETURN
is a required keyword.
expr-list
Notes
1. The RETURN statement can occur only within a FUNCTION routine and
directs INFORMIX-4GL to exit the function and to return to the calling
routine (MAIN, FUNCTION, or REPORT).
2. The expressions in expr-list must match in number and type the argument
list in the RETURNING clause of the CALL statement.
Related Statement
FUNCTION
7-186
REVOKE
REVOKE
Overview
Use the REVOKE statement to remove another users access privileges for a
database or table.
Syntax
REVOKE { tab-privilege ON table-name | db-privilege }
FROM { PUBLIC | user-list}
Explanation
REVOKE
is a required keyword.
tab-privilege
ON
is a required keyword.
table-name
is the name of the table for which you are revoking access
privileges.
db-privilege
FROM
is a required keyword.
INFORMIX-4GL Statement Syntax
7-187
REVOKE
PUBLIC
user-list
Notes
1. You cannot roll back the REVOKE statement.
2. You can revoke database-level access privileges only if you have DBA
status.
3. You can revoke only those table-level access privileges that you have
granted to another user.
4. You cannot revoke privileges from yourself.
5. Although you can grant UPDATE and SELECT privileges for specific columns, you cannot revoke these privileges column by column. If you
revoke UPDATE or SELECT privileges from a user, INFORMIX-4GL automatically revokes all UPDATE and SELECT privileges that you have ever
granted to that user for table-name. You can then re-grant privileges for
specific columns.
6. Only a DBA recipient can revoke the DBA privilege from another recipient. If the database creator grants DBA privileges to another user, that
person can revoke the DBA privilege from the database creator.
7. If you revoke the DBA or RESOURCE privilege from one or more users,
they are left with the CONNECT privilege. To revoke all database privileges from users with DBA or RESOURCE status, you must revoke
CONNECT as well as DBA or RESOURCE.
Examples
REVOKE ALL ON orders FROM PUBLIC
REVOKE DELETE, UPDATE
ON customer FROM jeff, judy
REVOKE CONNECT FROM enid, felix
Related Statement
GRANT
7-188
ROLLBACK WORK
ROLLBACK WORK
Overview
Use the ROLLBACK WORK statement to undo all modifications made to the
database during the current transaction.
Syntax
ROLLBACK WORK
Explanation
ROLLBACK WORK
Note
1. If you use the ROLLBACK WORK statement in a routine that is called by a
WHENEVER statement, be sure to specify WHENEVER ERROR CONTINUE
and WHENEVER WARNING CONTINUE before the ROLLBACK WORK
statement. This will prevent the program from looping if the ROLLBACK
WORK statement fails with an error or warning.
2. See the Transactions section in Chapter 3 for more information about
transactions and the ROLLBACK WORK statement.
3. The ROLLBACK WORK statement releases all row and table locks.
4. The ROLLBACK WORK statement closes all open cursors except those
DECLAREd WITH HOLD, although using it for this purpose is not
recommended.
Related Statements
BEGIN WORK, COMMIT WORK
7-189
ROLLFORWARD DATABASE
ROLLFORWARD DATABASE
Overview
Use the ROLLFORWARD DATABASE statement to cause INFORMIX-4GL to
apply the transactions registered in the transaction log file to a backup copy
of your database, recovering all completed transactions.
Syntax
ROLLFORWARD DATABASE database-name
Explanation
ROLLFORWARD are required keywords.
DATABASE
database-name
Notes
1. Immediately after you roll forward a database, it is in EXCLUSIVE mode,
with no transactions. After the database is closed and reopened, it
becomes accessible to other users, and transactions can resume.
2. See the section Transactions in Chapter 3 for more information.
Related Statements
BEGIN WORK, COMMIT WORK, START DATABASE, ROLLBACK WORK
7-190
RUN
RUN
Overview
Use the RUN statement to execute a system program.
Syntax
RUN command-line [ RETURNING integer-variable
| WITHOUT WAITING ]
Explanation
is a required keyword.
command-line
is an expression that evaluates to a command line for
your operating system. In particular, it may be a character string enclosed in quotation marks.
RETURNING
is an optional keyword.
integer-variable
is an INTEGER-type program variable that will receive
the value returned by the program executed by the
RUN statement.
WITHOUT WAITING are optional keywords.
RUN
Note
RUN spawns a child process described by command-line. The WITHOUT
WAITING option instructs INFORMIX-4GL to continue immediately to the
next 4GL statement, while the RETURNING option instructs INFORMIX-4GL
to await the return value before continuing to the next 4GL statement. If neither optional clause is present, INFORMIX-4GL waits until the child process
is completed (and ignores the return code) before continuing to the next 4GL
statement.
Examples
RUN "date_script" RETURNING error_val
RUN "isql -qr myscript"
RUN charval[i]
7-191
SCROLL
SCROLL
Overview
Use the SCROLL statement to move rows of a screen record through a screen
array.
Syntax
SCROLL { field-list | screen-record. * } [ , . . . ]
{ UP | DOWN } [ BY integer ]
Explanation
SCROLL
is a required keyword.
field-list
screen-record
UP
DOWN
BY
is an optional keyword.
integer
Notes
1. The BY clause determines the number of lines upward or downward that
the data will move. The default is 1.
2. It is the responsibility of the programmer to keep track of what data is left
on the screen.
Example
SCROLL sc_item UP BY 2
Related Statements
DISPLAY ARRAY, INPUT ARRAY
7-192
SELECT
SELECT
Overview
Use the SELECT statement to query the current database.
The SELECT statement can include up to eight clauses. Only the SELECT
clause and the FROM clause are required.
Syntax
SELECT clause [ INTO clause ] FROM clause
[ WHERE clause ]
[ GROUP BY clause ]
[ HAVING clause ]
[ ORDER BY clause ]
[ INTO TEMP clause ]
See The SELECT Statement section later in this chapter for detailed
descriptions of these clauses.
7-193
SET EXPLAIN
SET EXPLAIN
Overview
Use the SET EXPLAIN statement to record how the query processor is accessing the database when executing a query.
Syntax
SET EXPLAIN { ON | OFF }
Explanation
SET EXPLAIN
ON
OFF
Notes
1. When you issue SET EXPLAIN ON, the access procedures of all subsequent
queries are stored in the file sqexplain.out in your current directory. If
sqexplain.out already exists, subsequent output is appended to it. SET
EXPLAIN ON remains in effect until you issue SET EXPLAIN OFF, or the
program ends.
2. SET EXPLAIN estimates the cost in CPU resources (a weighted sum of disk
accesses and total rows processed), indicates the order of table access, and
estimates the number of rows returned. For each table, SET EXPLAIN identifies the type of access and the column(s) that serves as a filter, including
whether the filtering is through an index. The following table-access
types are available:
SEQUENTIAL SCAN
INDEX PATH
AUTOINDEX PATH
3. The name of the owner precedes each table name in the output file.
7-194
SET EXPLAIN
Examples
The following example shows an sqexplain.out output file for a simple query
and for a complex query from one table.
QUERY:
-----select fname, lname, company from customer;
Estimated Cost: 4
Estimated # of Rows Returned: 18
1) joe.customer: SEQUENTIAL SCAN
QUERY:
-----select fname, lname, company from customer
where company matches "Sport*"
and customer_num between 110 and 115
order by lname;
Estimated Cost: 3
Estimated # of Rows Returned: 1
Temporary Files Required For: Order By
1) joe.customer: INDEX PATH
Filters: joe.customer.company MATCHES "Sport*"
(1) Index Keys: customer_num
Lower Index Filter:
joe.customer.customer_num >= 110
Upper Index Filter:
joe.customer.customer_num <= 115
7-195
SET EXPLAIN
Related Statements
ALTER INDEX, CREATE INDEX, SELECT, UPDATE STATISTICS
Note: Additional statistics are available for query processing when you use
INFORMIX-OnLine as the database engine. As a result, estimates for the cost and
the number of rows returned may be more precise under INFORMIX-OnLine.
7-196
Syntax
SET LOCK MODE TO [ NOT ] WAIT
Explanation
SET LOCK MODE
TO
is a required keyword.
NOT
is an optional keyword.
WAIT
is a required keyword.
Notes
1. The TO NOT WAIT option causes INFORMIX-4GL to return an error if a
statement attempts to alter or delete a row (or to SELECT a row FOR
UPDATE) that another process has locked. This is the default situation;
that is, if you have not issued a SET LOCK MODE statement previously.
The NOT option is relevant, therefore, only when you have previously
executed SET LOCK MODE TO WAIT and want to return to the default
state.
2. The TO WAIT option causes INFORMIX-4GL to wait on an attempt to alter
or delete a row (or to SELECT a row FOR UPDATE) that another process has
locked until the locked row becomes unlocked.
3. Use the SET LOCK MODE TO WAIT statement with extreme caution. If the
locking process fails and does not remove the lock, your statement could
wait indefinitely.
4. This feature is available only on systems that have record-level locking
and applies only to row-level locking. Any attempt by another user to
access a row in a table locked IN EXCLUSIVE MODE produces an error.
5. You can use the SET LOCK MODE statement only on systems that support
kernel locking. An error is generated if you use the SET LOCK MODE statement with a system that does not support kernel locking.
INFORMIX-4GL Statement Syntax
7-197
Related Statement
LOCK TABLE
7-198
SLEEP
SLEEP
Overview
Use the SLEEP statement to cause the program to suspend operation for a
period of time.
Syntax
SLEEP integer-expr
Explanation
SLEEP
is a required keyword.
integer-expr
Note
The SLEEP statement causes the program to suspend operation for integerexpr seconds.
Example
SLEEP 4
7-199
START DATABASE
START DATABASE
Overview
Use the START DATABASE statement to start a new transaction log file.
Syntax
START DATABASE database-name WITH LOG IN "pathname" [ MODE ANSI ]
Explanation
START DATABASE are required keywords.
database-name
WITH LOG IN
pathname
MODE ANSI
Notes
1. The START DATABASE statement can perform these tasks:
START DATABASE
5. Singleton transactions do not exist in MODE ANSI. For a singleton statement, you must issue a COMMIT WORK statement to commit a
transaction, or a ROLLBACK WORK statement to roll the database back to
the last COMMIT WORK or ROLLBACK WORK statement.
6. See the section Transactions in Chapter 3 for more information on
START DATABASE. See also the discussion of CREATE DATABASE earlier
in this chapter for more information on MODE ANSI databases.
7. You can determine the type of database that a user selects by checking the
return code from a DATABASE statement in the SQLCA.SQLAWARN character string. See the section SQLCA Record in Chapter 3 for more
information.
8. You cannot remove MODE ANSI from a database. Once started as such, a
database remains MODE ANSI.
Example
START DATABASE stores
WITH LOG IN "/u/myname/stores.log" MODE ANSI
Related Statements
BEGIN WORK, COMMIT WORK, CREATE DATABASE, ROLLBACK WORK,
ROLLFORWARD DATABASE
7-201
START REPORT
START REPORT
Overview
Use the START REPORT statement to begin processing a report.
Syntax
START REPORT report-name
[ TO { filename | PRINTER | PIPE program } ]
Explanation
START REPORT are required keywords.
report-name
TO
is an optional keyword.
filename
PRINTER
is an optional keyword.
PIPE
is an optional keyword.
program
Notes
1. Usually, you will execute the START REPORT statement just before a loop
in which you process the report data using the OUTPUT TO REPORT
statement.
2. If you use the TO clause, INFORMIX-4GL ignores any REPORT TO statement in the OUTPUT section of report-name.
3. If you indicate filename, INFORMIX-4GL puts the report output there.
4. If you use the TO PRINTER option, INFORMIX-4GL sends the report output to your printer. The default printer command is lp or lpr; be sure to
check with your system administrator. You can change the default by setting the DBPRINT environment variable. (See Appendix C.)
5. Use the TO PIPE option to pipe report output to program.
Related Statements
FINISH REPORT, OUTPUT TO REPORT, REPORT
7-202
UNLOAD
UNLOAD
Overview
Use the UNLOAD statement to write the data from a table to an ASCII file.
Syntax
UNLOAD TO "pathname" [ DELIMITER "char" ] SELECT-statement
Explanation
UNLOAD TO
pathname
DELIMITER
char
SELECT-statement
Notes
1. The data from each column in each row are separated from the data in the
next column by the delimiter. INFORMIX-4GL uses as a delimiter the character included in the DELIMITER clause, if one is provided. If no
DELIMITER clause appears in the statement, INFORMIX-4GL checks the
setting in the DBDELIMITER environment variable, if it exists. The default
delimiter is the vertical bar ( | = ASCII 124).
If character data contains a delimiter character, INFORMIX-4GL automatically escapes it with a backslash to prevent interpretation as a special
character. (Backslashes are automatically stripped when the field is
LOADed.)
2. As in a DECLARE statement for a SELECT cursor, the SELECT-statement can
be either an unquoted SELECT statement, or the name of a string variable
that contains a SELECT statement.
3. NULL columns have no characters between delimiters.
INFORMIX-4GL Statement Syntax
7-203
UNLOAD
4. Trailing blanks in CHARACTER data are clipped. Number data types have
no leading blanks.
5. An INTEGER or SMALLINT zero is represented as 0 ; FLOAT, SMALLFLOAT, DECIMAL, and MONEY zeros are represented as 0.00.
6. MONEY values have no leading currency symbol.
7. DATE values are represented as mm/dd/yyyy, where mm is the month
(January = 1, and so on), dd is the day, and yyyy is the year.
8. DATETIME and INTERVAL items are written in character form, showing
only their field digits and delimiters. No type specification or qualifiers
are output. INFORMIX-4GL uses the following pattern: yyyy-mm-dd
hh:mi:ss.fff, omitting fields that are not part of the data.
9. You must have SELECT permission on all columns in the select-list of the
SELECT statement to use the UNLOAD statement.
10. You cannot PREPARE an UNLOAD statement.
11. When you execute an UNLOAD statement, INFORMIX-4GL sets status to
zero to indicate success, or to an error number to indicate failure. If an
error occurs, the SQLCODE and SQLERRD[2] error codes are set, as
described in Chapter 3. In any case, the value of SQLERRD[3] is set to the
number of rows that UNLOAD copied to the file.
Example
UNLOAD TO "cust.out" DELIMITER ";"
SELECT fname, lname, company, city
FROM customer
Related Statements
LOAD, SELECT
Note: INFORMIX-OnLine supports additional data types. Refer to the INFORMIX-OnLine Programmers Manual for more information.
7-204
UNLOCK TABLE
UNLOCK TABLE
Overview
Use the UNLOCK TABLE statement to unlock a table that you previously
locked with the LOCK TABLE statement.
Syntax
UNLOCK TABLE table-name
Explanation
UNLOCK TABLE
table-name
Note
If the database has transactions, the UNLOCK TABLE statement can not be
used and generates an error. All locks placed on the table are released when
the COMMIT WORK or ROLLBACK WORK statement is processed.
Related Statement
LOCK TABLE
7-205
UPDATE
UPDATE
Overview
Use the UPDATE statement to change the values in one or more columns of
one or more rows in a table.
Syntax
UPDATE table-name SET { column-name = expr [ , . . . ] |
{ ( column-list ) | [ table-name. ] * } = { ( expr-list) | record-name.* } }
[ WHERE { condition | CURRENT OF cursor-name } ]
Explanation
7-206
UPDATE
is a required keyword.
table-name
is the name of the table that contains the row(s) that you
want to update.
SET
is a required keyword.
column-name
expr
column-list
expr-list
record-name
WHERE
is an optional keyword.
condition
UPDATE
are keywords.
cursor-name
Notes
1. The expr can be a SELECT statement in parentheses that adheres to standard rules for subqueries. The SELECT statement can return no more than
one value except when included in an expr-list.
2. You cannot use a SELECT statement that retrieves data from table-name.
3. The number of column names included in the column-list must equal the
number of values produced in the expr-list.
4. Although the value returned by expr does not have to be of the same data
type as column-name, it must be compatible. You can put only CHAR data
into CHAR columns, and only numeric or character representations of
numeric data into number columns.
5. If you use the CURRENT OF option in the WHERE clause, INFORMIX-4GL
updates the current row of the active set and leaves the cursor on the
same row.
6. If you do not specify any columns in the FOR UPDATE clause of a
DECLARE statement, you can update any column in a subsequent
UPDATE WHERE CURRENT OF statement. If you do specify one or more
columns in the FOR UPDATE clause, you can update only those columns
in a subsequent UPDATE WHERE CURRENT OF statement. When you
specify the column names in the FOR UPDATE clause, INFORMIX-4GL can
usually perform the updates more quickly.
7. SERIAL columns cannot be updated. If you want to use the [table-name].*
notation and table-name contains a SERIAL column, you can only execute
the following form of the UPDATE statement:
UPDATE table-name
SET [table-name.]* = record-name.*
7-207
UPDATE
7-208
UPDATE
Examples
UPDATE stock
SET unit_price = unit_price * 1.04
WHERE manu_code = "HRO"
UPDATE customer
SET (fname, company, address2) =
("Marie", "Maries Sports",
"P. O. Box 3621")
WHERE customer_num = 103
UPDATE table1
SET (col1, col2, col3) =
((select min (ship_charge),
max (ship_charge) from orders),
"07/01/1986")
WHERE col4 = 1001
Related Statements
SELECT, DELETE, INSERT
7-209
UPDATE STATISTICS
UPDATE STATISTICS
Overview
Use the UPDATE STATISTICS statement to cause the number of rows in a table
to be recorded in the systables catalog.
Syntax
UPDATE STATISTICS [ FOR TABLE table-name ]
Explanation
UPDATE STATISTICS are required keywords.
FOR TABLE
table-name
Notes
1. UPDATE STATISTICS is effective only when there is a current database.
2. INFORMIX-4GL uses the data generated by UPDATE STATISTICS to optimize searching strategy. When you have modified a table extensively, use
UPDATE STATISTICS to improve the efficiency of queries.
3. INFORMIX-4GL does not update the statistics unless you execute the
UPDATE STATISTICS statement.
4. If you omit the FOR TABLE clause, UPDATE STATISTICS updates all the
tables in the current database.
Related Statement
SET EXPLAIN
INFORMIX-OnLine supports additional functionality. Refer to the INFORMIXOnLine Programmers Manual for more information.
7-210
VALIDATE
VALIDATE
Overview
Use the VALIDATE statement to determine whether values in a list of variables conform to the allowed ranges of values in syscolval for a corresponding list of columns.
Syntax
VALIDATE variable-list LIKE column-list
Explanation
VALIDATE
is a required keyword.
variable-list
LIKE
is a required keyword.
column-list
Notes
1. There must be as many entries in column-list as there are variables in
variable-list.
2. You must use a table-name prefix to designate the column names.
3. In a MODE ANSI database, the name of a table is qualified by the owner of
the table (owner. table-name). You must specify owner when you refer to a
table owned by another user.
The use of the prefix owner is optional in a non-MODE ANSI database.
INFORMIX-4GL does check the accuracy of owner, however, if you include
it in a statement. See the section Owner Naming in Chapter 3 for more
information.
4. You can use the upscol utility to create and update the values in
syscolval. (See the discussion of The upscol Utility in Appendix E.)
5. If the current database is not MODE ANSI, the upscol utility creates a single syscolval table that specifies acceptable values or ranges of values for
any or all columns in the database. The VALIDATE statement compares
variable-list with the limitations specified in this table.
7-211
VALIDATE
Examples
VALIDATE var1, var2, var3
LIKE tab1.col1, tab1.col2, tab1.col3
VALIDATE p_customer.* LIKE customer.*
Related Statement
INITIALIZE
7-212
WHENEVER
WHENEVER
Overview
Use the WHENEVER statement to trap errors and other exceptional conditions
that result during the execution of other 4GL statements.
Syntax
WHENEVER { ERROR | WARNING | NOT FOUND }
{GOTO [ : ] label | CALL function-name | CONTINUE | STOP }
Explanation
WHENEVER
is a required keyword.
ERROR
WARNING
NOT FOUND
GOTO
is an optional prefix to label, and conforms to the ANSI standard for SQL syntax.
label
CALL
is an optional keyword.
function-name
CONTINUE
STOP
7-213
WHENEVER
Notes
1. The WHENEVER statement is shorthand for putting an IF statement after
every SQL statement and form-related INFORMIX-4GL statement, and
testing for an error, warning, or NOT FOUND condition.
2. In the default situation, INFORMIX-4GL tests for errors (not warnings)
after every INFORMIX-4GL statement. The 4GL compiler sets the declared
database (that is, the database specified in the DATABASE statement that
precedes the MAIN program block or the first FUNCTION or REPORT routine of the module) as the current database and determines whether it is
MODE ANSI.
If (at compile time) the database is MODE ANSI, the default for WHENEVER ERROR is CONTINUE. Otherwise, the default is STOP. No DATABASE
or START DATABASE statement in a function has any effect on the WHENEVER ERROR default.
3. A program can include several WHENEVER statements. If they refer to the
same exception condition (ERROR, WARNING, or NOT FOUND), the last
one encountered takes precedence.
4. The scope of a WHENEVER statement is the file in which it occurs, and
from its position in the file to the next WHENEVER statement for the same
exception condition in the same file. The scope extends to the end of the
file, if you do not specify more WHENEVER statements for the same
exception condition.
5. INFORMIX-4GL provides useful information (like source-file line numbers where an error has occurred) when it terminates a program because
of an error. You may want to allow errors to occur during program development and insert trapping at a later stage.
6. If the NOT FOUND condition (status=100) is returned, the open cursor is
automatically closed.
7. The label or :label specified after the GOTO or GO TO keywords must be in
the same routine (that is, the same FUNCTION, REPORT, or MAIN program
block) as the WHENEVER statement.
8. Some errors cannot be trapped by the WHENEVER ERROR statement. Certain errors always terminate the program, and others result in action by
INFORMIX-4GL prior to the action specified by WHENEVER. (If you also
have the INFORMIX-4GL Interactive Debugger, however, you can examine the current execution stack and the values of program variables after
any error that is not followed by a system crash.)
9. While both NOT FOUND and NOTFOUND indicate the same condition,
they cannot be used interchangeably. Use NOTFOUND (a single word)
7-214
WHENEVER
with status, and use NOT FOUND (two words) with the WHENEVER
statement.
Examples
The following statement executes a function called error_recovery if an error
condition is detected:
WHENEVER ERROR CALL error_recovery
In the following program fragment, the WHENEVER statement transfers control, after a NOT FOUND condition, to the statement whose label is missing:
in the same routine. (The use of keywords and colons here conforms to the
ANSI standard for SQL syntax.)
MAIN
WHENEVER NOT FOUND GO TO :missing
. . .
LABEL missing:
DISPLAY "No row was retrieved from the database." AT 12,1
. . .
END MAIN
Related Statements
CALL, DEFER, FOREACH, GOTO, IF, LABEL
7-215
WHILE
WHILE
Overview
Use the WHILE statement to execute a group of statements while a condition
is TRUE.
Syntax
WHILE Boolean-expr
statement
...
[ EXIT WHILE ]
...
[ CONTINUE WHILE ]
...
END WHILE
Explanation
WHILE
is a required keyword.
Boolean-expr
statement
EXIT WHILE
is an optional statement.
CONTINUE WHILE
is an optional statement.
END WHILE
Notes
1. The CONTINUE WHILE statement interrupts the sequence and causes the
program control to return to the top of the sequence and to test the Boolean-expr.
2. The EXIT WHILE statement interrupts the sequence and causes the program control to jump to the first statement following the END WHILE
keywords.
3. If Boolean-expr is FALSE on entry to the WHILE statement, program control passes directly to the statement following END WHILE.
7-216
WHILE
Related Statements
CONTINUE, EXIT, FOR
7-217
Syntax
SELECT clause
7-218
Explanation
The following pages explain each of the syntax elements. A few basic concepts are defined here.
1. An expression consists of a column name, a program variable, a constant,
or any combination of these connected by the following arithmetic
operators:
Operator
+
*
/
Operation
addition
subtraction
multiplication
division
the current user. The CURRENT function is described later in this chapter.
The TODAY and USER functions are described in Chapter 3.
An expression can also be one of the aggregate, date, datetime, or length
functions. You cannot include both an aggregate function and a column
7-219
in an expression. The functions that you can use in SQL statements are
defined at the end of this chapter.
A CHAR column can have subscripts so that only a portion of the column
value is involved in the expression. The notation for subscripting a column is column-name[m, n], where you want the mth through the nth characters in the column, for m less than or equal to n. Here the brackets are
literal characters, not conventional symbols to indicate an option.
2. A relational operator is one of the following:
Operator
=
!= or < >
>
>=
<
<=
Operation
equal to
not equal to
greater than
greater than or equal to
less than
less than or equal to
For CHAR expressions, greater than means after in the ASCII collating
order, where lowercase letters are after uppercase letters, and both are
after numerals. See Appendix H for the ASCII codes of all the characters.
For DATE and DATETIME expressions, greater than means later in time.
Notes
1. The clauses of the SELECT statement are explained in detail on the following pages. Briefly, SELECT names a list of columns or expressions to be
retrieved, INTO names the program variables to receive the data, FROM
names a list of tables, WHERE sets conditions on the rows, GROUP BY
groups rows together, HAVING sets conditions on the groups, ORDER BY
sequences the selected rows, and INTO TEMP puts the results into a temporary table.
2. If the SELECT statement returns no rows, INFORMIX-4GL returns a no
rows found code (status = NOTFOUND = 100). See Chapter 3 for a full
explanation.
3. If a SELECT statement returns more than one row or if it is dynamically
defined, you must use a cursor to FETCH one row at a time (see
Chapter 3).
4. It is sometimes helpful to think of the SELECT statement in the following
way:
When you list more than one table in the FROM clause, INFORMIX-4GL
behaves as though it were creating a composite table that is the Cartesian
product of all the tables in the FROM clause. That is, the rows of the new
table are constructed by taking all the possible combinations of rows from
7-220
all the tables listed in the FROM clause. If there is a WHERE clause, INFORMIX-4GL eliminates from this new table all rows that do not meet the conditions of the WHERE clause. This modified table is returned to the
SELECT clause, where all columns not listed are eliminated. The resulting
table is what the SELECT statement returns.
5. The SELECT statement cannot appear in a multi-statement PREPARE.
7-221
SELECT Clause
SELECT Clause
Overview
Use the SELECT clause to specify the data that you want to retrieve from one
or more tables in a database.
Syntax
SELECT [ ALL | DISTINCT | UNIQUE ] select-list
Explanation
SELECT
is a required keyword.
ALL
DISTINCT
is a keyword that causes INFORMIX-4GL to eliminate duplicate rows from the query results.
UNIQUE
select-list
Notes
1. If the SELECT statement does not include a WHERE clause, every row will
be returned.
2. The DISTINCT or UNIQUE keyword can appear once in each level of a
query or subquery.
3. You can use the asterisk (*) in the select-list to select all columns from all
the tables and views in the FROM clause. You could produce the same
result by listing every column name in the select-list.
4. To select all the columns from a single table or view, you can use the notation tablename.*.
5. You can supply a display label for the column name or an expression in the
select-list by following the column name or expression with a legal identifier. If you create a temporary table with the INTO TEMP clause, the
7-222
SELECT Clause
column names of the temporary table are the display labels, if they have
been defined.
6. If you specify an aggregate function and a column in the select-list, the column must be used in the GROUP BY list (see GROUP BY Clause for
further explanation).
Examples
The following examples use INTO, FROM, and WHERE clauses, whose syntax
will be defined later.
This example selects columns customer_num, lname, and city; the FROM
clause indicates that these columns are taken from the customer table. The
values returned are placed in the program variables cnum, lname, and town,
respectively. Since lname is both a program variable name and a column
name, the column identifier is prefixed with the at ( @ ) sign.
SELECT customer_num, @lname, city
INTO cnum, lname, town
FROM customer
The next statement counts the number of rows in orders in which the
customer_num column contains the value 101. In other words, it counts the
number of orders made by the customer whose identifying number is 101.
The number is placed in the variable num.
SELECT COUNT(*)
INTO num
FROM orders
WHERE customer_num = 101
The next statement computes the average of the total_price values in those
rows of items that contain an order_num column equal to 1021.
SELECT AVG(total_price)
FROM items
WHERE order_num = 1021
The next example illustrates the use of display labels. It selects the sum of columns a and b from tablez and gives the sum the label abtotal. Similarly, the
product of columns c and d is labeled cdprod.
SELECT a+b abtotal, c*d cdprod
FROM tablez
INTO TEMP x
7-223
INTO Clause
INTO Clause
Overview
Use the INTO clause to specify the program variables to receive the data
retrieved by the SELECT statement.
Syntax
INTO variable-list
Explanation
INTO
is a required keyword.
variable-list
Notes
1. If the SELECT statement stands alone (not in a DECLARE statement), it
must be a singleton SELECT (returning exactly one row) and must have an
INTO clause.
2. If the SELECT statement returns more than one row, you must use a cursor
to FETCH the rows one at a time. (See Chapter 3.) You can put the INTO
clause in the FETCH statement, rather than in the SELECT statement, but
not in both. You can use the FOREACH statement in place of the FETCH
statement.
3. If you use DECLARE to associate a SELECT statement with a cursor, the
SELECT statement can specify individual elements as a constant but not
as a variable of a program array. (FETCH or FOREACH statements can
specify program array elements as constants or variables in their INTO
clause.)
4. If the number of variables in variable-list differs from the number of items
in the select-list, INFORMIX-4GL returns a warning by setting
SQLCA. SQLAWARN [4] to W. The actual number of variables transferred is
the lesser of the two numbers.
5. If possible, INFORMIX-4GL converts the data type of each selected item to
match that of the receiving variable. If the conversion is not possible, an
error occurs and a negative value is returned in status. In this case, the
7-224
INTO Clause
value in the program variable is unpredictable. See Chapter 2 for a discussion of data conversion.
6. You cannot PREPARE a query that has an INTO clause. (Instead, you can
DECLARE a cursor to perform the query.)
Examples
The following are equivalent program fragments:
DECLARE q_curs CURSOR FOR
SELECT @lname, @company
INTO lname, company
FROM customer
OPEN q_curs
FETCH q_curs
DECLARE q_curs CURSOR FOR
SELECT @lname, @company
FROM customer
OPEN q_curs
FETCH q_curs
INTO lname, company
DECLARE q_curs CURSOR FOR
SELECT @lname, @company
FROM customer
FOREACH q_curs INTO lname, company
. . .
7-225
FROM Clause
FROM Clause
Overview
Use the FROM clause to specify the table(s) or views from which you want to
select data.
Syntax
FROM { table-name [ table-alias ] |
OUTER table-name [ table-alias ] |
OUTER ( table-expr ) } [ , . . . ]
Explanation
FROM
is a required keyword.
OUTER
is an optional keyword.
table-name
table-alias
(table-expr)
Notes
1. Use the optional keyword OUTER to form outer joins. See the Outer
Joins section in Chapter 3 and Appendix G, Outer Joins, for a discussion of this syntax.
2. In a database created as MODE ANSI, the name of a table or view is qualified by the username of the owner (owner.table-name). You must specify
owner when you refer to a table or view owned by another user.
The use of the prefix owner is optional in a database that is not MODE
ANSI. INFORMIX-4GL checks the accuracy of owner, however, if you
include it in a statement. See the section Owner Naming in Chapter 3
of this manual.
3. You can specify an alias for a table name by following the table name with
a space and an SQL identifier. This feature is especially useful when performing self-joins. (See the WHERE Clause section of this chapter.)
7-226
FROM Clause
4. The table-alias that you can specify in a FROM clause is distinct from the
alias for a table that is sometimes required in the TABLES section of a form
specification file. An alias that you define in a form can appear in 4GL
screen interaction statements that reference screen fields but cannot
appear in a SELECT statement. (See Chapter 4.)
Examples
The following example selects customers who have placed orders.
SELECT fname, lname, order_num
FROM customer, orders
WHERE customer.customer_num =
orders.customer_num
The following example selects all customers whether or not they have placed
orders.
SELECT fname, lname, order_num
FROM customer, OUTER orders
WHERE customer.customer_num =
orders.customer_num
7-227
WHERE Clause
WHERE Clause
Overview
Use the WHERE clause to specify search criteria and join conditions on the
data to be selected.
Syntax
WHERE condition
Explanation
WHERE
is a required keyword.
condition
Comparison condition
Join condition
Condition with subquery
Comparison Condition
A comparison condition can have one of the following forms:
a. expr rel-op expr
b. expr [ NOT ] BETWEEN expr AND expr
c. expr [ NOT ] IN ( value-list )
d. column-name [ NOT ] LIKE "string" [ ESCAPE "esc-char" ]
e. column-name [ NOT ] MATCHES "string" [ ESCAPE "esc-char" ]
f. column-name IS [ NOT ] NULL
These forms are explained in the following pages. Any one of these conditions can be preceded by the keyword NOT, in which case the row is selected
only if the condition that NOT qualifies is FALSE.
Syntax
expr rel-op expr
7-228
WHERE Clause
Explanation
expr
is an expression.
rel-op
is a relational operator.
Examples
SELECT fname, lname, company
FROM customer
WHERE city[1,3] = "San"
SELECT order_num, company
FROM orders o, customer c
WHERE o.order_date > "6/12/86"
AND o.customer_num = c.customer_num
If a column value is NULL in a given row, the WHERE clause will not locate
that row if you use relational operators. For example, if paid_date has a NULL
value, you cannot use either statement (a) or (b) to retrieve that row:
--(a)
SELECT customer_num, order_date
FROM orders
WHERE paid_date = ""
--(b)
SELECT customer_num, order_date
FROM orders
WHERE NOT paid_date != ""
Syntax
expr [ NOT ] BETWEEN expr AND expr
Explanation
expr
is an expression.
NOT
BETWEEN
7-229
WHERE Clause
AND
is a required keyword.
Examples
SELECT stock_num, manu_code
FROM stock
WHERE unit_price BETWEEN
loprice AND hiprice
SELECT UNIQUE customer_num, stock_num, manu_code
FROM orders, items
WHERE order_date
BETWEEN "6/1/86" AND "9/7/89"
AND orders.order_num = items.order_num
SELECT fname, lname
FROM customer
WHERE zipcode NOT
BETWEEN "94100" AND "94199"
Syntax
expr [ NOT ] IN ( value-list )
Explanation
expr
is an expression.
NOT
is an optional keyword.
IN
is a required keyword.
(value-list)
Notes
1. The search condition is satisfied when the expression to the left is
included in the list of items. The NOT option produces a search condition
that is satisfied when expr is not in the list of items.
2. The value-list can contain program variables, constants, or the special keyword constants TODAY, CURRENT, and USER.
3. TODAY is evaluated at execution time. CURRENT is evaluated when a cursor is opened, or when the query is executed if it is a singleton select.
7-230
WHERE Clause
Examples
SELECT lname, fname, company
FROM customer
WHERE state IN ("CA", "WA", "OR")
SELECT item_num, total_price
INTO inum, tprice
FROM items
WHERE manu_code IN
("HRO", "HSK")
Syntax
column-name [ NOT ] LIKE "string" [ ESCAPE "escape-character" ]
Explanation
column-name
NOT
is an optional keyword.
LIKE
is a required keyword.
string
ESCAPE
is an optional keyword.
Notes
1. The search condition is successful when the value of the column on the
left matches the pattern specified by string. You can use wildcard characters in place of other characters in the string:
%
2. The NOT option makes the search condition successful when the column
on the left does not match the pattern specified by string.
3. The purpose of the ESCAPE clause is to permit the specification of an
underscore ( _ ) or the percent sign ( % ) in string, and to avoid their interpretation as wildcards. If z is the escape-character, then the characters z_
in a string stand for the character _ (not the wildcard). Similarly, z% in the
string stands for the character % (not the wildcard). Finally, the characters
zz in the string stand for the single character z.
7-231
WHERE Clause
4. You can only use the double quote ( " ) within string to match a literal
quote; you cannot use the ESCAPE keyword. Similarly, you cannot use the
quote character as the ESCAPE character in matching any other pattern.
Examples
SELECT fname, lname
FROM customer
WHERE lname LIKE "%son"
obtains stock number, manufacturers code, and unit price for all stock items
with ball anywhere in their description.
SELECT * FROM customer
WHERE company LIKE "%z_%" ESCAPE "z"
retrieves rows from the customer table where the company column value
includes the underscore character.
Syntax
column-name [ NOT ] MATCHES "string" [ ESCAPE "escape-character" ]
Explanation
column-name
NOT
is an optional keyword.
MATCHES
is a required keyword.
string
ESCAPE
is an optional keyword.
Notes
1. The search condition is successful when the value of the column on the
left matches the pattern specified by string. You can use the following
wildcard characters in place of other characters in the string:
7-232
WHERE Clause
[...]
2. The NOT option makes the search condition successful when the column
on the left does not match the pattern specified by string.
3. The MATCHES comparison is an Informix Software extension to retain
compatibility with earlier versions of Informix products.
4. Values used in a MATCHES search must be character strings.
5. The purpose of the ESCAPE clause is to permit the specification of a question mark ( ? ), an asterisk ( * ), the backslash ( \ ), and left or right bracket
( [ ] ), in string and to avoid their interpretation as wildcards. If z is the
escape character, then the characters z? in a string stand for the character ?
(not the wildcard). Similarly, z* in the string stands for the character *
(not the wildcard). Finally, the characters zz in the string stand for the single character z (same as \z).
6. You can only use the double quote ( " ) within string to match a literal
quote; you cannot use the ESCAPE keyword. Similarly, you cannot use the
quote character as the ESCAPE character in matching any other pattern.
Examples
SELECT fname, lname
FROM customer
WHERE lname MATCHES "Richard*"
selects rows in which the first seven letters of the last name are Richard (thus
matching Richard, Richards, Richardson, and any others).
SELECT customer_num, company
FROM customer
WHERE city MATCHES "[A-J]*"
provides the customer number and company name for all customers in cities
that start with the letters A through J.
SELECT * FROM customer
WHERE company MATCHES "*z?*" ESCAPE "z"
retrieves rows from the customer table, where the value in the company
column includes the question mark.
7-233
WHERE Clause
Syntax
column-name IS [ NOT ] NULL
Explanation
column-name
IS NULL
NOT
is an optional keyword.
Examples
SELECT order_num, customer_num
FROM orders
WHERE paid_date IS NULL
lists those order numbers and customer numbers where the order has not
been paid.
You can link any number of the above-described conditions together using
the logical operators AND or OR. For example:
SELECT order_num, total_price
FROM items
WHERE total_price > loprice AND
manu_code LIKE "H%"
SELECT lname, customer_num
FROM customer
WHERE zipcode BETWEEN
"93500" AND "95700"
OR state NOT IN
("CA", "WA", "OR")
Join Conditions
Overview
You join two tables when you create a relationship in the WHERE clause
between at least one column from one table and at least one column from
another table. The effect of the join is to create a temporary composite table
in which each pair of rows (one from each table) satisfying the join condition
is linked together to form a single row.
7-234
WHERE Clause
Syntax
The critical elements of a SELECT statement with a join between two tables or
views table1 and table2 follow:
SELECT clause FROM table1, table2 WHERE condition
Explanation
SELECT clause is any valid SELECT clause involving columns from table1 or
table2.
FROM
is a required keyword.
table1
table2
WHERE
is a required keyword.
condition
Notes
1. When columns from different tables have the same name, you must distinguish them by prefixing the table identifier and a period, in the format
table.column.
2. In a database created as MODE ANSI, the name of a table is qualified by
the owner of the table (owner. table-name). You must specify owner when
you refer to a table owned by another user.
The use of the prefix owner is optional in a non-MODE ANSI database.
INFORMIX-4GL checks the accuracy of owner, however, if you include it in
a statement. See the section Owner Naming in Chapter 3 of this
manual.
3. A multiple join is a join of more than two tables. Its structure is similar to
that shown previously, except that you have a join condition for more
than one pair of tables in the FROM clause.
4. You can also join a table to itself in a self-join. To do so, you must list the
table name twice in the FROM clause, assigning it two different aliases.
Use the aliases to refer to each of the two tables in the WHERE clause.
5. An outer join occurs when every row from table1 is taken, whether or not
the join condition is met. If the join condition is not met, the columns from
table2 in the select-list are set to NULL values. You indicate an outer join by
inserting the keyword OUTER before table2.
INFORMIX-4GL Statement Syntax
7-235
WHERE Clause
Examples
This example specifies a two-table join:
SELECT order_num, lname, fname
FROM customer, orders
WHERE customer.customer_num
= orders.customer_num
The query results list the order number and first and last names of the customers representative for each order.
This example specifies a multiple-table join:
SELECT UNIQUE company, stock_num, manu_code
FROM customer c, orders o, items i
WHERE c.customer_num = o.customer_num
and o.order_num = i.order_num
This query yields the company name of the customer who ordered an item
identified with the stock number and manufacturer code.
This example specifies a self-join:
SELECT x.stock_num, x.manu_code,
y.stock_num, y.manu_code
FROM stock x, stock y
WHERE x.unit_price > 2.5 * y.unit_price
This query finds pairs of stock items whose unit prices differ by a factor
greater than two and one-half. Here x and y are each aliases for the stock
table.
This example specifies an outer join:
SELECT company, order_num
FROM customer c, OUTER orders o
WHERE c.customer_num = o.customer_num
This query lists all the customers company names and order numbers, if the
customer has placed an order. If not, the company name will still be listed.
See the Outer Joins section in Chapter 3 and Appendix G for information
about outer joins.
7-236
WHERE Clause
Subquery
Overview
The search condition in a SELECT statement can also perform these tasks:
The subquery can depend on whether the current row is being evaluated by
the outer SELECT statement (correlated subqueries).
Syntax
WHERE expr rel-op { ALL | [ ANY | SOME ] } ( SELECT-statement )
WHERE expr [ NOT ] IN ( SELECT-statement )
WHERE [ NOT ] EXISTS ( SELECT-statement )
Explanation
WHERE
is a required keyword.
expr
is an expression.
rel-op
is a relational operator.
ALL
ANY
SOME
7-237
WHERE Clause
IN
EXISTS
is a keyword that asks whether any rows are returned by the following SELECT-statement. The search condition is TRUE if the subquery returns one or more rows.
NOT
Notes
1. You can omit the keywords ANY and ALL in a comparison if you know
that the subquery will return exactly one value. In this case, the search
condition is TRUE if the comparison is TRUE for the expression and the
value returned by the subquery. The status will be set to a negative number if the subquery returns other than a single value.
2. The specification expr IN ( SELECT-statement )
is equivalent to expr = ANY ( SELECT-statement ).
3. The specification expr NOT IN ( SELECT-statement )
is equivalent to expr ! = ALL ( SELECT-statement ).
Examples
SELECT order_num
FROM items
WHERE stock_num = 9 AND quantity =
(SELECT MAX(quantity) FROM items
WHERE stock_num = 9)
7-238
WHERE Clause
This query lists the order numbers of all orders containing an item whose
total price is greater than the total price on all the items in order number 1011.
SELECT UNIQUE customer_num
FROM orders
WHERE order_num NOT IN
(SELECT order_num
FROM items
WHERE stock_num = 1)
This query lists all customer numbers of customers who have placed orders
that do not include baseball gloves (stock_num = 1).
SELECT order_num, stock_num, manu_code, total_price
FROM items x
WHERE total_price >
(SELECT 2 * MIN(total_price)
FROM items
WHERE order_num = x.order_num)
This query (using a correlated subquery) lists all items whose total price is at
least twice the minimum total price for all items on the same order.
7-239
GROUP BY Clause
GROUP BY Clause
Overview
Use the GROUP BY clause to produce a single row of results for each group.
A group is a set of rows having the same values for each column listed.
Syntax
GROUP BY group-list
Explanation
GROUP BY
group-list
Notes
1. Using a GROUP BY clause restricts what you can enter in the SELECT
clause. The select-list can include aggregate functions for any column
and/or the name of any column that you also list in the GROUP BY clause.
You cannot, however, list any column in the select-list that you do not also
list in group-list.
2. The SELECT list can contain expressions involving GROUP BY columns.
3. In the place of column names in group-list, you can enter one or more integers that refer to the position of items in the select-list.
4. NULL values are considered identical when evaluated within a GROUP BY
clause.
5. You can GROUP BY up to eight columns.
Examples
SELECT order_num, COUNT(*), SUM(total_price)
FROM items
GROUP BY order_num
7-240
GROUP BY Clause
obtains the number of items and total price of all items for each order.
SELECT order_num, COUNT(*), SUM(total_price)
FROM items
GROUP BY 1
7-241
HAVING Clause
HAVING Clause
Overview
Use the HAVING clause to apply one or more qualifying conditions to groups.
Syntax
HAVING condition
Explanation
HAVING
is a required keyword.
condition
Notes
1. Each condition compares one column or aggregate property of the group
either with another aggregate property of the group or with a constant.
2. The HAVING clause generally complements a GROUP BY clause. If you
use HAVING without GROUP BY, the HAVING clause applies to all rows
that satisfy the WHERE clause. Without a GROUP BY clause, all rows that
satisfy the WHERE clause make up a single group.
3. You can use the HAVING clause to place conditions on the GROUP BY column values, as well as on aggregate values.
Example
SELECT order_num, AVG(total_price)
FROM items
GROUP BY order_num
HAVING COUNT(*) > 2
This query returns the average total price per item on all orders that have
more than two items.
7-242
ORDER BY Clause
ORDER BY Clause
Overview
Use the ORDER BY clause to sort query results by the values contained in one
or more columns. You can sort only by a column that you specify in the
SELECT clause.
Syntax
ORDER BY column-name [ ASC | DESC ] [ , . . . ]
Explanation
ORDER BY
column-name
ASC
DESC
Notes
1. You can only ORDER BY columns that are named explicitly or implicitly in
the select-list.
2. You can ORDER BY up to eight columns.
3. The total length of the data in the columns included in the ORDER BY
clause cannot be greater than 120 bytes.
4. In the place of column names, you can enter one or more integers that
refer to the position of items in the select-list. In this way, you can ORDER
BY an expression.
5. You cannot use a DECLARE statement with a FOR UPDATE clause to associate a cursor with a SELECT statement that has an ORDER BY clause.
7-243
ORDER BY Clause
Examples
CORRECT:
CORRECT:
SELECT *
FROM orders
ORDER BY order_date
INCORRECT:
performs a nested sort. The first level of sorting is based on the lname column, and the second level is based on the fname column.
7-244
Syntax
INTO TEMP table-name [ WITH NO LOG ]
Explanation
INTO TEMP
table-name
tables.
Notes
1. You will save time if you use a temporary table when the same query
results are required several times.
2. An INTO TEMP clause in a SELECT statement often gives you clearer and
more easily understood statements.
3. The column names of the temporary table are those named in the selectlist. If you list a display label for a column or expression, the column name
in the temporary table is the display label.
4. No indexes are associated with table-name.
5. Do not use an INTO clause with the INTO TEMP clause. If you do, no
results will be returned to the program variables, and status will be set to
a negative value.
6. The temporary table persists until you exit from your 4GL program or
issue the DROP TABLE table-name statement.
7. The keywords WITH NO LOG prevent INFORMIX-4GL from including in
the transaction log operations on temporary tables. You can use this
option to reduce the overhead of transaction logging.
7-245
UNION Operator
UNION Operator
Overview
The UNION operator is a keyword placed between two SELECT statements, to
let you combine the queries into a single query.
Syntax
SELECT-statement UNION [ ALL ] SELECT-statement
[ UNION [ ALL ] SELECT-statement . . . ]
Explanation
UNION
ALL
Notes
1. You can place the UNION operator between each member of a sequence
of more than two queries.
2. It is possible to write single queries that are equivalent to the compound
queries constructed using the UNION operator. The advantage of the
UNION operator is that it makes the process easier.
3. There are restrictions on the queries that you can connect with UNION
operators.
The number of the items in the select-list of each query must be the
same, and corresponding items in each select-list must have identical
data types.
7-246
UNION Operator
You cannot use an INTO statement in a query unless you are sure that
the compound query will return exactly one row and you are not
using a cursor. In this rare case, the INTO clause must be in the first
SELECT statement.
If you use an ORDER BY clause, it must follow the last SELECT statement, and you must refer by integer, not by identifier, to the item to be
ordered. Ordering takes place after the set operation is complete.
4. UNION operators cannot occur inside a subquery and cannot be used in
the definition of a view.
5. The column names (or display labels) of the resulting table are the same
as those from the first SELECT statement.
6. You can put the results of a UNION into a temporary table by putting an
INTO TEMP clause in the final SELECT statement.
Example
The following example selects those items (identified by a stock number and
a manufacturing code) that have a unit price of less than $100.00 or that have
been ordered in quantities greater than three.
SELECT DISTINCT stock_num, manu_code
FROM stock
WHERE unit_price < 100.00
UNION
SELECT stock_num, manu_code,
FROM items
WHERE quantity > 3
ORDER BY 1
7-247
Length
Functions
LENGTH( )
Date
Functions
DATE( )
DAY( )
MDY( )
MONTH( )
WEEKDAY( )
YEAR( )
Datetime
Functions
CURRENT
EXTEND( )
7-248
Aggregate Functions
Aggregate Functions
Overview
The aggregate functions take on values that depend on the set of rows
returned by the WHERE clause of a SELECT statement. In the absence of a
WHERE clause, the aggregate functions take on values that depend on all the
rows formed by the FROM clause.
Syntax
Function
COUNT (*)
COUNT ( DISTINCT x)
returns the number of different values in column x from rows that satisfy the WHERE
clause.
Notes
1. In the functions SUM(x), AVG(x), MAX(x), and MIN(x), x can be an expression instead of a column name. If x is an expression, the function is
evaluated over the values of the expression as computed for each row that
7-249
Aggregate Functions
satisfies the WHERE clause. The expression can not contain another aggregate function.
2. Both the COUNT(x) function and the keyword DISTINCT can only be used
with column names, not with expressions.
3. You can use the keyword DISTINCT only once in each level of a query or
subquery. Use DISTINCT to disregard duplicate query results or to eliminate duplicates from the argument of an aggregate function.
4. Specifying DISTINCT in a MIN or MAX function has no effect on the value
returned by the function.
5. You can use the keyword UNIQUE as a synonym for DISTINCT.
6. Aggregate functions handle NULL values in these ways:
COUNT(DISTINCT x), AVG (x), SUM (x), MAX (x), and MIN (x) ignore
rows with NULL values for x and return the appropriate values based
on the rest of the rows.
COUNT(*) counts all rows, even if the value of every column in the
row is NULL.
Examples
If a query selects seven rows in which the set of values in column x is
{ 2, 2, 2, 3, 3, 4, NULL }
then COUNT (*) returns 7, and COUNT ( DISTINCT x ) returns 3. For these values, MAX (x) returns 4, and MIN (x) returns 2.
7-250
LENGTH( )
LENGTH( )
Overview
The LENGTH function returns the clipped length of a character column or
variable.
Syntax
LENGTH ( string )
Explanation
string
Note
LENGTH allows only one argument. You can, however, combine LENGTH val-
Example
SELECT customer_num, LENGTH(fname) + LENGTH(lname),
LENGTH("How many bytes is this?")
FROM customer WHERE LENGTH(company) > 10
7-251
DATE( )
DATE( )
Overview
The DATE( ) function returns a type DATE value, corresponding to the expression with which you call it.
Syntax
DATE ( expr )
Explanation
DATE
is a required keyword.
expr
Note
The expr is usually of type CHAR, DATETIME, or INTEGER.
Example
The following example uses DATE( ) to convert a string to a date.
WHERE end_date > DATE("12/13/1989")
7-252
DAY( )
DAY( )
Overview
The DAY( ) function returns an integer that represents the day of the month,
when you call it with a type DATE or DATETIME argument.
Syntax
DAY ( time-expr )
Explanation
DAY
is a required keyword.
Example
This example uses the DAY ( ) function with the CURRENT function to compare column values to the current day of the month.
WHERE DAY(ord_date) > DAY(CURRENT)
7-253
MDY( )
MDY( )
Overview
The MDY( ) function returns a type DATE value when you call it with three
expressions that evaluate to integers representing the month, day of the
month, and year.
Syntax
MDY ( expr1, expr2, expr3 )
Explanation
MDY
is a required keyword.
expr1
is an expression that evaluates to an integer representing the number of the month (1-12).
expr2
is an expression that evaluates to an integer representing the number of the day of the month (1-28, 29, 30, or 31, depending on the
month).
expr3
Notes
The value of expr3 cannot be the abbreviation for the year. For example, 89 is
a year in the first century.
7-254
MONTH( )
MONTH( )
Overview
The MONTH( ) function returns an integer corresponding to the month portion of its type DATE or DATETIME argument.
Syntax
MONTH ( time-expr )
Explanation
MONTH
is a required keyword.
Notes
1. This function extracts the month from a DATE value, returning an integer
m in the range 1 m 12.
2. The time-expr cannot be an INTERVAL argument.
Example
SELECT order_num, MONTH (order_date) FROM orders
7-255
WEEKDAY( )
WEEKDAY( )
Overview
The WEEKDAY( ) function returns an integer that represents the day of the
week, when you call it with a type DATE or DATETIME expression.
Syntax
WEEKDAY ( time-expr )
Explanation
WEEKDAY
is a required keyword.
time-expr
Notes
1. WEEKDAY returns an integer in the range 0-6. Zero represents Sunday,
1 represents Monday, and so on.
2. The time-expr cannot be a type INTERVAL argument.
Examples
SELECT order_num, WEEKDAY (order_date) FROM orders
SELECT * FROM orders
WHERE WEEKDAY (paid_date) = WEEKDAY (CURRENT - 31 UNITS DAY)
7-256
YEAR( )
YEAR( )
Overview
The YEAR( ) function returns an integer that represents the year when you call
it with a type DATE or DATETIME expression.
Syntax
YEAR ( time-expr )
Explanation
YEAR
is a required keyword.
Notes
The time-expr cannot be an INTERVAL argument.
Examples
SELECT order_num, YEAR (order_date) FROM orders
SELECT order_num, customer_num FROM orders
WHERE YEAR(ship_date) < YEAR(TODAY)
The second example specifies rows in which the ship_date is earlier than the
beginning of the current year.
7-257
CURRENT
CURRENT
Overview
The CURRENT function returns a DATETIME value with the date and time of
day of the current instant.
Syntax
CURRENT [ first TO last ]
Explanation
CURRENT
is a required keyword.
first
TO
last
Notes
1. The value returned is the date and time (from the system clock) when the
CURRENT function executes.
2. You can use the CURRENT function in any context in which you can use a
DATETIME literal.
3. The first qualifier must specify a field that is more significant than or equal
to the last qualifier.
4. If the function is executed more than once in a statement, identical values
may be returned at each point of the call. You cannot rely on CURRENT to
provide distinct values each time that it executes.
5. INFORMIX-4GL may not execute the CURRENT function in the physical
order in which it appears in a statement. You should not use the function
to mark the start, the end, or any specific point in the execution of the 4GL
statement.
6. If no first TO last qualifiers are specified, the default qualifiers are YEAR
TO FRACTION(3).
7-258
CURRENT
Qualified Data
A number of years.
A number of months.
A number of days.
A number of hours.
A number of minutes.
A number of seconds.
A decimal fraction of a second with n (up to five) digits of precision.
The default precision is three digits (thousandths of a second).
Example
SELECT prog_title FROM tv_programs WHERE
air_date > CURRENT YEAR TO DAY
7-259
EXTEND( )
EXTEND( )
Overview
The EXTEND function adjusts the precision of a DATETIME or DATE value.
Syntax
EXTEND ( value [ , first TO last ] )
Explanation
EXTEND
is a required keyword.
value
first
TO
last
Notes
1. The value can also be a DATETIME literal, or a character string in a valid
DATETIME format. (It cannot be the string representation of a DATE
value.)
2. If no first TO last qualifiers are specified, the default qualifiers are YEAR
TO FRACTION(3).
3. The first qualifier must specify a field that is more significant than or equal
to the last qualifier.
4. If the value contains fields not specified by the qualifiers, the unwanted
fields are discarded.
5. If the first qualifier specifies a field to the left of (that is, more significant
than) what exists in value, the new fields are filled with values returned
by the CURRENT function.
7-260
EXTEND( )
6. If the last qualifier specifies a field to the right of (that is, less significant
than) what exists in value, the new fields are filled in with constant values.
A missing MONTH or DAY is filled in with 1, and the missing fields HOUR
to FRACTION are filled in with 0.
7. The following qualifiers are valid:
Identifier
YEAR
MONTH
DAY
HOUR
MINUTE
SECOND
FRACTION (n)
Qualified Data
A number of years.
A number of months.
A number of days.
A number of hours.
A number of minutes.
A number of seconds.
A decimal fraction of a second with n (up to five) digits
of precision. The default precision is three digits
(thousandths of a second).
Examples
In the following example, the EXTEND function returns the MONTH and DAY
fields from a column that contains YEAR, MONTH, and DAY data. In this
instance the YEAR field is not returned.
SELECT EXTEND(air_date, MONTH TO DAY)
FROM tv_programs
7-261
EXTEND( )
7-262
Appendix
A
Demonstration
Database and
Application
The stores Database
The stores database contains a set of tables that describe an
imaginary business. You can access the data in stores by the
demonstration programs that appear in this book, as well
as by application programs that are listed in the documentation of other Informix products. The stores database is not
MODE ANSI.
This appendix contains five sections:
customer
orders
items
stock
manufact
state
serial(101)
char(15)
char(15)
char(20)
char(20)
char(20)
char(15)
char(2)
char(5)
char(18)
serial(1001)
date
integer
char(40)
char(1)
char(10)
date
decimal(8,2)
money(6)
date
The order_num column is indexed, and must contain unique values. The
customer_num column is indexed, but allows duplicates.
smallint
integer
smallint
char(3)
smallint
money(8)
The order_num column has an index that allows duplicate values. A multiple-column index for the stock_num and manu_code columns also permits
duplicate values.
A-3
smallint
char(3)
char(15)
money(6)
char(4)
char(15)
char(3)
char(15)
char(2)
char(15)
A-4
item_num
order_num
order_num
stock
customer
order_date
stock_num
stock_num
manufact
customer_num
customer_num
manu_code
manu_code
manu_code
fname
ship_instruct
quantity
description
manu_name
lname
backlog
total_price
unit_price
company
po_num
unit
address1
ship_date
unit_descr
address2
ship_weight
state
city
ship_charge
code
state
paid_date
sname
zipcode
Figure A-1
phone
Tables in the stores Database
A-5
Figure A-2
customer_num
101
102
103
104
fname
Ludwig
Carole
Philip
Anthony
order_num
1001
1002
1003
1004
order_date
01/20/1989
06/01/1989
10/12/1989
04/12/1989
lname
Pauli
Sadler
Currie
Higgins
customer_num
104
101
104
106
customer table
(detail)
orders table
(detail)
A-6
order_num
1001
1002
1003
1004
item_num
1
1
2
1
2
3
Figure A-3
order_date
01/20/1989
06/01/1989
10/12/1989
04/12/1989
order_num
1001
1002
1002
1003
1003
1003
customer_num
104
101
104
106
stock_num
1
4
3
9
8
5
manu_code
HRO
HSK
HSK
ANZ
ANZ
ANZ
orders table
(detail)
items table
(detail)
A-7
Figure A-4
item_num
1
1
2
1
2
3
1
order_num
1001
1002
1002
1003
1003
1003
1004
stock_num
1
4
3
9
8
5
1
stock_num
1
1
1
manu_code
HRO
HSK
SMT
description
baseball glove
baseball glove
baseball glove
manu_code
HRO
HSK
HSK
ANZ
ANZ
ANZ
HRO
items table
(detail)
stock table
(detail)
The same stock number and manufacturer code can appear in more than one
row of the items table, if the same item belongs to separate orders. This is
illustrated above in Figure A-4.
Figure A-5
A-8
stock_num
1
1
1
2
manu_code
HRO
HSK
SMT
HRO
manu_code
NRG
HSK
HRO
manu_name
Norge
Husky
Hero
description
baseball glove
baseball glove
baseball glove
baseball
stock table
(detail)
manufact table
(detail)
fname
Ludwig
Carole
Philip
lname
Pauli
Sadler
Currie
...
...
...
...
state
CA
CA
CA
customer table
(detail)
state table
(detail)
sname
Alaska
Alabama
Arkansas
Arizona
California
Joining lets you rearrange your view of a database whenever you want. It
provides flexibility that lets you create new relationships between tables
without redesigning the database. You can easily expand the scope of a database by adding new tables that join the existing tables. As you read through
this manual, you will see programs that set up the join relationships across
tables of the stores database. Refer to these figures whenever you need to
review these relationships.
A-9
A-10
fname
Ludwig
Carole
Philip
Anthony
Raymond
George
Charles
Donald
Jane
Roy
Frances
Margaret
Lana
Frank
Alfred
Jean
Arnold
Dick
customer_num
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
Baxter
Sipes
Parmelee
Grant
Albertson
Beatty
Lawson
Keyes
Jaeger
Miller
Quinn
Ream
Watson
Vector
Higgins
Currie
Sadler
Pauli
lname
Kids Korner
Olympic City
Sporting Place
Sportstown
Sports Center
AA Athletics
Sport Stuff
Quinns Sports
Athletic Supplies
Play Ball!
Phils Sports
Sports Spot
company
5427 College
Mayfair Mart
587 Alvarado
41 Jordan Avenue
654 Poplar
785 Geary St
address1
Redwood City
Palo Alto
Mountain View
Los Altos
Redwood City
Palo Alto
San Francisco
Sunnyvale
city
Oakland
Redwood City
Mountain View
Menlo Park
Redwood City
Menlo Park
Los Altos
Sunnyvale
Redwood City
P. O. Box 3498
address2
customer Table
CA
CA
CA
CA
CA
CA
CA
CA
CA
CA
CA
CA
CA
CA
CA
CA
CA
CA
state
94609
94063
94040
94025
94062
94025
94022
94085
94062
94086
94063
94304
94063
94022
94026
94303
94117
94086
zip code
415-655-0011
415-245-4578
415-534-8822
415-356-1123
415-886-6677
415-356-9982
415-887-7235
408-277-7245
415-743-3611
408-723-8789
415-544-8729
415-356-9876
415-389-8789
415-776-3249
415-368-1100
415-328-4543
415-822-1289
408-789-8075
phone
items Table
item_num
1
1
2
1
2
3
1
2
3
4
1
2
3
4
1
2
3
4
5
1
2
3
4
5
1
2
1
1
2
1
1
2
1
2
3
4
1
2
1
order_num
1001
1002
1002
1003
1003
1003
1004
1004
1004
1004
1005
1005
1005
1005
1006
1006
1006
1006
1006
1007
1007
1007
1007
1007
1008
1008
1009
1010
1010
1011
1012
1012
1013
1013
1013
1013
1014
1014
1015
stock_num
1
4
3
9
8
5
1
2
3
1
5
5
6
6
5
5
5
6
6
1
2
3
4
7
8
9
1
6
6
5
8
9
5
6
6
9
4
4
1
manu_code
HRO
HSK
HSK
ANZ
ANZ
ANZ
HRO
HRO
HSK
HSK
NRG
ANZ
SMT
ANZ
SMT
NRG
ANZ
SMT
ANZ
HRO
HRO
HSK
HRO
HRO
ANZ
ANZ
SMT
SMT
ANZ
ANZ
ANZ
ANZ
ANZ
SMT
ANZ
ANZ
HSK
HRO
SMT
quantity
1
1
1
1
1
5
1
1
1
1
10
10
1
1
5
5
5
1
1
1
1
1
1
1
1
5
1
1
1
5
1
10
1
1
1
2
1
1
1
total_price
250.0
960.0
240.0
20.0
840.0
99.0
960.0
126.0
240.0
800.0
280.0
198.0
36.0
48.0
125.0
190.0
99.0
36.0
48.0
250.0
126.0
240.0
480.0
600.0
840.0
100.0
450.0
36.0
48.0
99.0
840.0
200.0
19.8
36.0
48.0
40.0
960.0
480.0
450.0
A-11
A-12
01/20/89
06/01/89
10/12/89
04/12/89
12/04/89
09/19/89
03/25/89
11/17/89
02/14/89
05/29/89
03/23/89
06/05/89
09/01/89
05/01/89
07/10/89
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
110
106
104
117
104
115
111
110
117
112
116
106
104
101
104
backlog
closed Mon
via ups
ups
closed Monday
after 10 am
via ups
po on box;
deliver back door only
ups
ship_instruct
MA003
8052
B77930
278701
B77897
429Q
4745
LZ230
278693
Q13557
2865
8006
B77890
9270
B77836
po_num
orders Table
08/01/89
05/10/89
09/18/89
06/09/89
04/13/89
06/08/89
03/04/89
12/06/89
04/23/89
12/19/89
04/30/89
10/13/89
06/06/89
02/01/89
ship_date
20.60
40.60
60.80
70.80
10.40
40.60
20.40
45.60
125.90
70.80
80.80
95.80
35.60
50.60
20.40
ship_weight
6.30
12.30
12.20
14.20
5.00
12.30
10.00
13.80
25.20
14.20
16.20
19.20
10.80
15.30
10.00
ship_charge
08/31/89
07/18/89
10/10/89
06/01/89
07/22/89
04/21/89
12/21/89
12/30/89
11/04/89
07/03/89
03/22/89
paid_ date
stock Table
stock_num
manu_code
description
unit_price
unit
unit_descr
HRO
baseball gloves
250.00
case
10 gloves/case
HSK
baseball gloves
800.00
case
10 gloves/case
SMT
baseball gloves
450.00
case
10 gloves/case
HRO
baseball
126.00
case
24/case
HSK
baseball bat
240.00
case
12/case
HSK
football
960.00
case
24/case
HRO
football
480.00
case
24/case
NRG
tennis racquet
28.00
each
each
SMT
tennis racquet
25.00
each
each
ANZ
tennis racquet
19.80
each
each
SMT
tennis ball
36.00
case
24 cans/case
ANZ
tennis ball
48.00
case
24 cans/case
HRO
basketball
600.00
case
24/case
ANZ
volleyball
840.00
case
24/case
ANZ
volleyball net
20.00
each
each
manufact Table
manu_code
manu_name
ANZ
Anza
HSK
Husky
HRO
Hero
NRG
Norge
SMT
Smith
A-13
state Table
A-14
code
sname
code
sname
AK
Alaska
MT
Montana
AL
Alabama
NB
Nebraska
AR
Arkansas
NC
North Carolina
AZ
Arizona
ND
North Dakota
CA
California
NH
New Hampshire
CO
Colorado
NJ
New Jersey
CT
Connecticut
NM
New Mexico
DE
Delaware
NV
Nevada
FL
Florida
NY
New York
GA
Georgia
OH
Ohio
HI
Hawaii
OK
Oklahoma
IA
Iowa
OR
Oregon
ID
Idaho
PA
Pennsylvania
IL
Illinois
RI
Rhode Island
IN
Indiana
SC
South Carolina
KS
Kansas
SD
South Dakota
KY
Kentucky
TN
Tennessee
LA
Louisiana
TX
Texas
MA
Massachusetts
UT
Utah
MD
Maryland
VA
Virginia
ME
Maine
VT
Vermont
MI
Michigan
WA
Washington
MN
Minnesota
WI
Wisconsin
MO
Missouri
WV
West Virginia
MS
Mississippi
WY
Wyoming
Description
Form for displaying customer information
Form for entering an order
Form for displaying a list of states
Form for displaying a list of stock items
Module containing global definitions
Module containing MAIN routine
Module handling the Customer option
Module handling the Orders option
Module handling the Stock option
Module handling the Report option
Module handling hidden sample source code option
Source file for help messages
custform.per
DATABASE stores
SCREEN
{
Customer Form
Number
Owner Name
Company
Address
City
Telephone
:[f000
:[f001
:[f003
:[f004
[f005
:[f006
:[f008
]
][f002
]
]
]
]
] State:[a0] Zipcode:[f007 ]
]
}
TABLES
customer
ATTRIBUTES
f000 = customer.customer_num, NOENTRY;
f001 = customer.fname;
f002 = customer.lname;
f003 = customer.company;
f004 = customer.address1;
f005 = customer.address2;
f006 = customer.city;
a0 = customer.state, UPSHIFT;
f007 = customer.zipcode;
f008 = customer.phone, PICTURE = "###-###-#### XXXXX";
A-15
orderform.per
DATABASE stores
SCREEN
{
-----------------------------------------------------------------------------ORDER FORM
-----------------------------------------------------------------------------Customer Number:[f000
] Contact Name:[f001
][f002
]
Company Name:[f003
]
Address:[f004
][f005
]
City:[f006
] State:[a0] Zip Code:[f007 ]
Telephone:[f008
]
-----------------------------------------------------------------------------Order No:[f009
]
Order Date:[f010
]
PO Number:[f011
]
Shipping Instructions:[f012
]
-----------------------------------------------------------------------------Item No. Stock No. Code
Description
Quantity
Price
Total
[f013 ] [f014 ] [a1 ] [f015
] [f016 ] [f017
] [f018
]
[f013 ] [f014 ] [a1 ] [f015
] [f016 ] [f017
] [f018
]
[f013 ] [f014 ] [a1 ] [f015
] [f016 ] [f017
] [f018
]
[f013 ] [f014 ] [a1 ] [f015
] [f016 ] [f017
] [f018
]
Running Total including Tax and Shipping Charges:[f019
]
==============================================================================
}
TABLES
customer orders items stock
ATTRIBUTES
f000 = customer.customer_num;
f001 = customer.fname;
f002 = customer.lname;
f003 = customer.company;
f004 = customer.address1;
f005 = customer.address2;
f006 = customer.city;
a0 = customer.state, UPSHIFT;
f007 = customer.zipcode;
f008 = customer.phone, PICTURE = "###-###-#### XXXXX";
f009
f010
f011
f012
=
=
=
=
orders.order_num;
orders.order_date, DEFAULT = TODAY;
orders.po_num;
orders.ship_instruct;
f013
f014
a1 =
f015
f016
f017
f018
f019
= items.item_num, NOENTRY;
= items.stock_num;
items.manu_code, UPSHIFT;
= stock.description, NOENTRY;
= items.quantity;
= stock.unit_price, NOENTRY;
= items.total_price, NOENTRY;
= formonly.t_price TYPE MONEY;
INSTRUCTIONS
SCREEN RECORD s_items[4](items.item_num, items.stock_num, items.manu_code,
stock.description, items.quantity, stock.unit_price, items.total_price)
A-16
state_list.per
DATABASE stores
SCREEN
{
State Selection
[a0]
[a0]
[a0]
[a0]
[a0]
[a0]
[a0]
}
[f000
[f000
[f000
[f000
[f000
[f000
[f000
]
]
]
]
]
]
]
TABLES
state
ATTRIBUTES
a0 = state.code;
f000 = state.sname;
INSTRUCTIONS
DELIMITERS " "
SCREEN RECORD s_state[7](state.*)
stock_sel.per
DATABASE stores
SCREEN
{
[f018][f019][f020
[f018][f019][f020
[f018][f019][f020
}
][f021
][f021
][f021
][f022
][f022
][f022
][f023
][f023
][f023
]
]
]
TABLES
stock
ATTRIBUTES
f018 = FORMONLY.stock_num;
f019 = FORMONLY.manu_code;
f020 = FORMONLY.manu_name;
f021 = FORMONLY.description;
f022 = FORMONLY.unit_price;
f023 = FORMONLY.unit_descr;
INSTRUCTIONS
DELIMITERS " "
SCREEN RECORD s_stock[3] (FORMONLY.stock_num THRU FORMONLY.unit_descr)
A-17
d4_globals.4gl
DATABASE stores
GLOBALS
DEFINE
p_customer RECORD LIKE customer.*,
p_orders RECORD
order_num LIKE orders.order_num,
order_date LIKE orders.order_date,
po_num LIKE orders.po_num,
ship_instruct LIKE orders.ship_instruct
END RECORD,
p_items ARRAY[10] OF RECORD
item_num LIKE items.item_num,
stock_num LIKE items.stock_num,
manu_code LIKE items.manu_code,
description LIKE stock.description,
quantity LIKE items.quantity,
unit_price LIKE stock.unit_price,
total_price LIKE items.total_price
END RECORD,
p_stock ARRAY[30] OF RECORD
stock_num LIKE stock.stock_num,
manu_code LIKE manufact.manu_code,
manu_name LIKE manufact.manu_name,
description LIKE stock.description,
unit_price LIKE stock.unit_price,
unit_descr LIKE stock.unit_descr
END RECORD,
p_state ARRAY[50] OF RECORD LIKE state.*,
state_cnt, stock_cnt INTEGER,
print_option CHAR(1)
END GLOBALS
A-18
d4_main.4gl
GLOBALS
"d4_globals.4gl"
MAIN
DEFER INTERRUPT
OPTIONS
HELP FILE "helpdemo"
LET print_option = "s"
CALL get_states()
CALL get_stocks()
CALL ring_menu()
MENU "MAIN"
COMMAND "Customer" "Enter and maintain customer data" HELP 101
CALL customer()
CALL ring_menu()
COMMAND "Orders" "Enter and maintain orders" HELP 102
CALL orders()
CALL ring_menu()
COMMAND "Stock" "Enter and maintain stock list" HELP 103
CALL stock()
CALL ring_menu()
COMMAND "Reports" "Print reports and mailing labels" HELP 104
CALL reports()
CALL ring_menu()
COMMAND key("!")
CALL bang()
CALL ring_menu()
NEXT OPTION "Customer"
COMMAND key("X")
CALL demo()
CALL ring_menu()
NEXT OPTION "Customer"
COMMAND "Exit" "Exit program and return to operating system" HELP 105
CLEAR SCREEN
EXIT PROGRAM
END MENU
END MAIN
FUNCTION bang()
DEFINE cmd CHAR(80),
x CHAR(1)
CALL clear_menu()
LET x = "!"
WHILE x = "!"
PROMPT "!" FOR cmd
RUN cmd
PROMPT "Type RETURN to continue." FOR CHAR x
END WHILE
END FUNCTION
A-19
mrow SMALLINT
DISPLAY " ", str CLIPPED AT mrow,1
SLEEP 3
DISPLAY "" AT mrow,1
END FUNCTION
FUNCTION ring_menu()
DISPLAY "----------------------------------------- ",
"Type Control-W for MENU HELP -------" AT 4,2 ATTRIBUTE(MAGENTA)
END FUNCTION
FUNCTION clear_menu()
DISPLAY "" AT 1,1
DISPLAY "" AT 2,1
END FUNCTION
FUNCTION get_states()
DECLARE c_state CURSOR FOR
SELECT * FROM state
ORDER BY sname
LET state_cnt = 1
FOREACH c_state INTO p_state[state_cnt].*
LET state_cnt = state_cnt + 1
IF state_cnt > 50 THEN
EXIT FOREACH
END IF
END FOREACH
LET state_cnt = state_cnt - 1
END FUNCTION
FUNCTION get_stocks()
DECLARE stock_list CURSOR FOR
SELECT stock_num, manufact.manu_code,
manu_name, description, unit_price, unit_descr
FROM stock, manufact
WHERE stock.manu_code = manufact.manu_code
ORDER BY stock_num
LET stock_cnt = 1
FOREACH stock_list INTO p_stock[stock_cnt].*
LET stock_cnt = stock_cnt + 1
IF stock_cnt > 30 THEN
EXIT FOREACH
END IF
END FOREACH
LET stock_cnt = stock_cnt - 1
END FUNCTION
A-20
d4_cust.4gl
GLOBALS
"d4_globals.4gl"
FUNCTION customer()
OPTIONS
FORM LINE 7
OPEN FORM customer FROM "custform"
DISPLAY FORM customer
ATTRIBUTE(MAGENTA)
CALL ring_menu()
CALL fgl_drawbox(3,30,3,43)
CALL fgl_drawbox(3,61,8,7)
CALL fgl_drawbox(11,61,8,7)
LET p_customer.customer_num = NULL
MENU "CUSTOMER"
COMMAND "One-add" "Add a new customer to the database" HELP 201
CALL add_customer(FALSE)
COMMAND "Many-add" "Add several new customer to database" HELP 202
CALL add_customer(TRUE)
COMMAND "Find-cust" "Look up specific customer" HELP 203
CALL query_customer(23)
IF p_customer.customer_num IS NOT NULL THEN
NEXT OPTION "Update-cust"
END IF
COMMAND "Update-cust" "Modify current customer information" HELP 204
CALL update_customer()
NEXT OPTION "Find-cust"
COMMAND "Delete-cust" "Remove a customer from database" HELP 205
CALL delete_customer()
NEXT OPTION "Find-cust"
COMMAND "Exit" "Return to MAIN Menu" HELP 206
CLEAR SCREEN
EXIT MENU
END MENU
OPTIONS
FORM LINE 3
END FUNCTION
FUNCTION add_customer(repeat)
DEFINE repeat INTEGER
CALL clear_menu()
MESSAGE "Press F1 or CTRL-F for field help; ",
"F2 or CTRL-Z to return to menu"
IF repeat THEN
WHILE input_cust()
ERROR "Customer data entered" ATTRIBUTE (GREEN)
END WHILE
CALL mess("Multiple insert completed - current screen values ignored", 23)
ELSE
IF input_cust() THEN
ERROR "Customer data entered" ATTRIBUTE (GREEN)
ELSE
CLEAR FORM
LET p_customer.customer_num = NULL
ERROR "Customer addition aborted" ATTRIBUTE (RED, REVERSE)
END IF
END IF
END FUNCTION
FUNCTION input_cust()
A-21
FUNCTION query_customer(mrow)
DEFINE where_part CHAR(200),
query_text CHAR(250),
answer CHAR(1),
mrow, chosen, exist SMALLINT
CLEAR FORM
CALL clear_menu()
MESSAGE "Enter criteria for selection"
CONSTRUCT where_part ON customer.* FROM customer.*
MESSAGE ""
IF int_flag THEN
LET int_flag = FALSE
CLEAR FORM
ERROR "Customer query aborted" ATTRIBUTE(RED, REVERSE)
LET p_customer.customer_num = NULL
RETURN (p_customer.customer_num)
END IF
LET query_text = "select * from customer where ", where_part CLIPPED,
" order by lname"
PREPARE statement_1 FROM query_text
DECLARE customer_set SCROLL CURSOR FOR statement_1
A-22
OPEN customer_set
FETCH FIRST customer_set INTO p_customer.*
IF status = NOTFOUND THEN
LET exist = FALSE
ELSE
LET exist = TRUE
DISPLAY BY NAME p_customer.*
MENU "BROWSE"
COMMAND "Next" "View the next customer in the list"
FETCH NEXT customer_set INTO p_customer.*
IF status = NOTFOUND THEN
ERROR "No more customers in this direction"
ATTRIBUTE(RED, REVERSE)
FETCH LAST customer_set INTO p_customer.*
END IF
DISPLAY BY NAME p_customer.* ATTRIBUTE(CYAN)
COMMAND "Previous" "View the previous customer in the list"
FETCH PREVIOUS customer_set INTO p_customer.*
IF status = NOTFOUND THEN
ERROR "No more customers in this direction"
ATTRIBUTE(RED, REVERSE)
FETCH FIRST customer_set INTO p_customer.*
END IF
DISPLAY BY NAME p_customer.* ATTRIBUTE(CYAN)
COMMAND "First" "View the first customer in the list"
FETCH FIRST customer_set INTO p_customer.*
DISPLAY BY NAME p_customer.* ATTRIBUTE(CYAN)
COMMAND "Last" "View the last customer in the list"
FETCH LAST customer_set INTO p_customer.*
DISPLAY BY NAME p_customer.* ATTRIBUTE(CYAN)
COMMAND "Select" "Exit BROWSE selecting the current customer"
LET chosen = TRUE
EXIT MENU
COMMAND "Quit" "Quit BROWSE without selecting a customer"
LET chosen = FALSE
EXIT MENU
END MENU
END IF
CLOSE customer_set
IF NOT exist THEN
CLEAR FORM
CALL mess("No customer satisfies query", mrow)
LET p_customer.customer_num = NULL
RETURN (FALSE)
END IF
IF NOT chosen THEN
CLEAR FORM
LET p_customer.customer_num = NULL
CALL mess("No selection made", mrow)
RETURN (FALSE)
END IF
RETURN (TRUE)
END FUNCTION
A-23
FUNCTION update_customer()
CALL clear_menu()
IF p_customer.customer_num IS NULL THEN
CALL mess("No customer has been selected; use the Find-cust option",23)
RETURN
END IF
MESSAGE "Press F1 or CTRL-F for field-level help"
DISPLAY "Press ESC to update customer data; DEL to abort" AT 1,1
INPUT BY NAME p_customer.* WITHOUT DEFAULTS
AFTER FIELD state
CALL statehelp()
DISPLAY "Press ESC to update customer data; DEL to abort", "" AT 1,1
ON KEY (F1, CONTROL-F)
CALL customer_help()
END INPUT
IF NOT int_flag THEN
UPDATE customer SET customer.* = p_customer.*
WHERE customer_num = p_customer.customer_num
CALL mess("Customer data modified", 23)
ELSE
LET int_flag = FALSE
SELECT * INTO p_customer.* FROM customer
WHERE customer_num = p_customer.customer_num
DISPLAY BY NAME p_customer.*
ERROR "Customer update aborted" ATTRIBUTE (RED, REVERSE)
END IF
END FUNCTION
FUNCTION delete_customer()
DEFINE answer CHAR(1),
num_orders INTEGER
CALL clear_menu()
IF p_customer.customer_num IS NULL THEN
ERROR "No customer has been selected; use the Find-customer option"
ATTRIBUTE (RED, REVERSE)
RETURN
END IF
SELECT COUNT(*) INTO num_orders
FROM orders
WHERE customer_num = p_customer.customer_num
IF num_orders THEN
ERROR "This customer has active orders and can not be removed"
ATTRIBUTE (RED, REVERSE)
RETURN
END IF
PROMPT " Are you sure you want to delete this customer row? "
FOR CHAR answer
IF answer MATCHES "[yY]" THEN
DELETE FROM customer
WHERE customer_num = p_customer.customer_num
CLEAR FORM
CALL mess("Customer entry deleted", 23)
LET p_customer.customer_num = NULL
ELSE
ERROR "Deletion aborted" ATTRIBUTE (RED, REVERSE)
END IF
END FUNCTION
A-24
FUNCTION customer_help()
CASE
WHEN infield(customer_num) CALL showhelp(1001)
WHEN infield(fname) CALL showhelp(1002)
WHEN infield(lname) CALL showhelp(1003)
WHEN infield(company) CALL showhelp(1004)
WHEN infield(address1) CALL showhelp(1005)
WHEN infield(address2) CALL showhelp(1006)
WHEN infield(city) CALL showhelp(1007)
WHEN infield(state) CALL showhelp(1008)
WHEN infield(zipcode) CALL showhelp(1009)
WHEN infield(phone) CALL showhelp(1010)
END CASE
END FUNCTION
FUNCTION statehelp()
DEFINE idx INTEGER
SELECT COUNT(*) INTO idx
FROM state
WHERE code = p_customer.state
IF idx = 1 THEN
RETURN
END IF
DISPLAY "Move cursor using F3, F4, and arrow keys; press ESC to select state"
AT 1,1
OPEN WINDOW w_state AT 8,37
WITH FORM "state_list"
ATTRIBUTE (BORDER, RED, FORM LINE 2)
CALL set_count(state_cnt)
DISPLAY ARRAY p_state TO s_state.*
LET idx = arr_curr()
CLOSE WINDOW w_state
LET p_customer.state = p_state[idx].code
DISPLAY BY NAME p_customer.state ATTRIBUTE (MAGENTA)
RETURN
END FUNCTION
A-25
d4_orders.4gl
GLOBALS
"d4_globals.4gl"
FUNCTION orders()
OPEN FORM order_form FROM "orderform"
DISPLAY FORM order_form
ATTRIBUTE(MAGENTA)
MENU "ORDERS"
COMMAND "Add-order" "Enter new order to database and print invoice"
HELP 301
CALL add_order()
COMMAND "Update-order" "Enter shipping or payment data" HELP 302
CALL update_order()
COMMAND "Find-order" "Look up and display orders" HELP 303
CALL get_order()
COMMAND "Delete-order" "Remove an order from the database" HELP 304
CALL delete_order()
COMMAND "Exit" "Return to MAIN Menu" HELP 305
CLEAR SCREEN
EXIT MENU
END MENU
END FUNCTION
FUNCTION add_order()
DEFINE pa_curr, s_curr, num_stocks INTEGER,
file_name CHAR(20),
query_stat INTEGER
CALL clear_menu()
LET query_stat = query_customer(2)
IF query_stat IS NULL THEN
RETURN
END IF
IF NOT query_stat THEN
OPEN WINDOW cust_w AT 3,5
WITH 19 ROWS, 72 COLUMNS
ATTRIBUTE(BORDER, YELLOW)
OPEN FORM o_cust FROM "custform"
DISPLAY FORM o_cust
ATTRIBUTE(MAGENTA)
CALL fgl_drawbox(3,61,4,7)
CALL fgl_drawbox(11,61,4,7)
CALL add_customer(FALSE)
CLOSE FORM o_cust
CLOSE WINDOW cust_w
IF p_customer.customer_num IS NULL THEN
RETURN
ELSE
DISPLAY by name p_customer.*
END IF
END IF
MESSAGE "Enter the order date, PO number and shipping instructions."
INPUT BY NAME p_orders.order_date, p_orders.po_num, p_orders.ship_instruct
IF int_flag THEN
LET int_flag = FALSE
CLEAR FORM
ERROR "Order input aborted" ATTRIBUTE (RED, REVERSE)
RETURN
END IF
INPUT ARRAY p_items FROM s_items.* HELP 311
A-26
A-27
FUNCTION update_order()
ERROR "This option has not been implemented" ATTRIBUTE (RED)
END FUNCTION
FUNCTION delete_order()
ERROR "This option has not been implemented" ATTRIBUTE (RED)
END FUNCTION
FUNCTION order_total()
DEFINE order_total MONEY(8),
i INTEGER
LET order_total = 0.00
FOR i = 1 TO ARR_COUNT()
IF p_items[i].total_price IS NOT NULL THEN
LET order_total = order_total + p_items[i].total_price
END IF
END FOR
LET order_total = 1.1 * order_total
DISPLAY order_total TO t_price
ATTRIBUTE(GREEN)
END FUNCTION
A-28
FUNCTION item_total()
DEFINE pa_curr, sc_curr INTEGER
LET pa_curr = arr_curr()
LET sc_curr = scr_line()
LET p_items[pa_curr].total_price =
p_items[pa_curr].quantity * p_items[pa_curr].unit_price
DISPLAY p_items[pa_curr].total_price TO s_items[sc_curr].total_price
END FUNCTION
FUNCTION renum_items()
DEFINE pa_curr, pa_total, sc_curr, sc_total, k INTEGER
LET
LET
LET
LET
FOR
pa_curr = arr_curr()
pa_total = arr_count()
sc_curr = scr_line()
sc_total = 4
k = pa_curr TO pa_total
LET p_items[k].item_num = k
IF sc_curr <= sc_total THEN
DISPLAY k TO s_items[sc_curr].item_num
LET sc_curr = sc_curr + 1
END IF
END FOR
END FUNCTION
FUNCTION insert_items()
DEFINE idx INTEGER
FOR idx = 1 TO arr_count()
IF p_items[idx].quantity != 0 THEN
INSERT INTO items
VALUES (p_items[idx].item_num, p_orders.order_num,
p_items[idx].stock_num, p_items[idx].manu_code,
p_items[idx].quantity, p_items[idx].total_price)
IF status < 0 THEN
RETURN (FALSE)
END IF
END IF
END FOR
RETURN (TRUE)
END FUNCTION
FUNCTION get_stock()
DEFINE idx integer
OPEN WINDOW stock_w AT 7, 3
WITH FORM "stock_sel"
ATTRIBUTE(BORDER, YELLOW)
CALL set_count(stock_cnt)
DISPLAY
"Use cursor using F3, F4, and arrow keys; press ESC to select a stock item"
AT 1,1
DISPLAY ARRAY p_stock TO s_stock.*
LET idx = arr_curr()
CLOSE WINDOW stock_w
RETURN p_stock[idx].stock_num, p_stock[idx].manu_code,
p_stock[idx].description, p_stock[idx].unit_price
END FUNCTION
A-29
FUNCTION get_order()
DEFINE idx, exist, chosen INTEGER,
answer CHAR(1)
CALL clear_menu()
CLEAR FORM
IF NOT query_customer(2) THEN
RETURN
END IF
DECLARE order_list CURSOR FOR
SELECT order_num, order_date, po_num, ship_instruct
FROM orders
WHERE customer_num = p_customer.customer_num
LET exist = FALSE
LET chosen = FALSE
FOREACH order_list INTO p_orders.*
LET exist = TRUE
CLEAR orders.*
FOR idx = 1 TO 4
CLEAR s_items[idx].*
END FOR
DISPLAY p_orders.* TO orders.*
DECLARE item_list CURSOR FOR
SELECT item_num, items.stock_num, items.manu_code,
description, quantity, unit_price, total_price
FROM items, stock
WHERE order_num = p_orders.order_num
AND items.stock_num = stock.stock_num
AND items.manu_code = stock.manu_code
ORDER BY item_num
LET idx = 1
FOREACH item_list INTO p_items[idx].*
LET idx = idx + 1
IF idx > 10 THEN
ERROR "More than 10 items; only 10 items displayed"
ATTRIBUTE (RED, REVERSE)
EXIT FOREACH
END IF
END FOREACH
CALL set_count(idx - 1)
CALL order_total()
MESSAGE "Press ESC when you finish viewing the items"
DISPLAY ARRAY p_items TO s_items.*
ATTRIBUTE(CYAN)
MESSAGE ""
IF int_flag THEN
LET int_flag = FALSE
EXIT FOREACH
END IF
PROMPT " Enter y to select this order ",
"or RETURN to view next order: " FOR CHAR answer
IF answer MATCHES "[yY]" THEN
LET chosen = TRUE
EXIT FOREACH
END IF
END FOREACH
IF NOT exist THEN
ERROR "No orders found for this customer" ATTRIBUTE (RED)
ELSE
IF NOT chosen THEN
CLEAR FORM
ERROR "No order selected for this customer" ATTRIBUTE (RED)
END IF
A-30
END IF
END FUNCTION
FUNCTION get_item()
DEFINE pa_curr, sc_curr INTEGER
LET pa_curr = arr_curr()
LET sc_curr = scr_line()
SELECT description, unit_price
INTO p_items[pa_curr].description,
p_items[pa_curr].unit_price
FROM stock
WHERE stock.stock_num = p_items[pa_curr].stock_num
AND stock.manu_code = p_items[pa_curr].manu_code
IF status THEN
LET p_items[pa_curr].description = NULL
LET p_items[pa_curr].unit_price = NULL
END IF
DISPLAY p_items[pa_curr].description, p_items[pa_curr].unit_price
TO s_items[sc_curr].description, s_items[sc_curr].unit_price
IF p_items[pa_curr].quantity IS NOT NULL THEN
CALL item_total()
END IF
END FUNCTION
FUNCTION invoice(file_name)
DEFINE x_invoice RECORD
order_num
order_date
ship_instruct
backlog
po_num
ship_date
ship_weight
ship_charge
item_num
stock_num
manu_code
quantity
total_price
description
unit_price
unit
unit_descr
manu_name
END RECORD,
file_name CHAR(20),
msg CHAR(40)
LIKE
LIKE
LIKE
LIKE
LIKE
LIKE
LIKE
LIKE
LIKE
LIKE
LIKE
LIKE
LIKE
LIKE
LIKE
LIKE
LIKE
LIKE
orders.order_num,
orders.order_date,
orders.ship_instruct,
orders.backlog,
orders.po_num,
orders.ship_date,
orders.ship_weight,
orders.ship_charge,
items.item_num,
items.stock_num,
items.manu_code,
items.quantity,
items.total_price,
stock.description,
stock.unit_price,
stock.unit,
stock.unit_descr,
manufact.manu_name
A-31
CASE (print_option)
WHEN "f"
START REPORT r_invoice TO file_name
CALL clear_menu()
MESSAGE "Writing invoice -- please wait"
WHEN "p"
START REPORT r_invoice TO PRINTER
CALL clear_menu()
MESSAGE "Writing invoice -- please wait"
WHEN "s"
START REPORT r_invoice
END CASE
FOREACH invoice_data INTO x_invoice.*
OUTPUT TO REPORT r_invoice (p_customer.*, x_invoice.*)
END FOREACH
FINISH REPORT r_invoice
IF print_option = "f" THEN
LET msg = "Invoice written to file ", file_name CLIPPED
CALL mess(msg, 23)
END IF
END FUNCTION
A-32
FORMAT
BEFORE GROUP OF x.order_num
SKIP TO TOP OF PAGE
SKIP 1 LINE
PRINT 10 SPACES,
"
W E S T
C O A S T
W H O L E S A L E R S ,
I N C ."
PRINT 30 SPACES," 1400 Hanbonon Drive"
PRINT 30 SPACES,"Menlo Park, CA 94025"
SKIP 1 LINES
PRINT "Bill To:", COLUMN 10,c.fname CLIPPED, " ", c.lname CLIPPED;
PRINT COLUMN 56,"Invoice No.
",x.order_num USING "&&&&&"
PRINT COLUMN 10,c.company
PRINT COLUMN 10,c.address1 CLIPPED;
PRINT COLUMN 56,"Invoice Date: ", x.order_date
PRINT COLUMN 10,c.address2 CLIPPED;
PRINT COLUMN 56,"Customer No.
", c.customer_num USING "####&"
PRINT COLUMN 10,c.city CLIPPED,", ",c.state CLIPPED,"
",
c.zipcode CLIPPED;
PRINT COLUMN 56,"PO No. ",x.po_num
PRINT COLUMN 10,c.phone CLIPPED;
PRINT COLUMN 56,"Backlog Status: ",x.backlog
SKIP 1 LINES
PRINT COLUMN 10,"Shipping Instructions: ", x.ship_instruct
PRINT COLUMN 10,"Ship Date: ",x.ship_date USING "ddd. mmm dd, yyyy";
PRINT "
Weight: ", x.ship_weight USING "#####&.&&"
SKIP 1 LINES
PRINT "----------------------------------------";
PRINT "---------------------------------------"
PRINT "
Stock
Unit
";
PRINT "
Item "
PRINT " # Num Man
Description
Qty
Cost
Unit ";
PRINT " Unit Description
Total"
SKIP 1 LINES
LET calc_total = 0.00
ON EVERY ROW
PRINT x.item_num USING "#&"," ",
x.stock_num USING "&&", " ",x.manu_code;
PRINT " ",x.description," ",x.quantity USING "###&", " ";
PRINT x.unit_price USING "$$$&.&&"," ",x.unit, " ",x.unit_descr,"
PRINT x.total_price USING "$$$$$$$&.&&"
LET calc_total = calc_total + x.total_price
";
A-33
d4_stock.4gl
GLOBALS
"d4_globals.4gl"
FUNCTION stock()
MENU "STOCK"
COMMAND "Add-stock" "Add new stock items to database" HELP 401
CALL add_stock()
COMMAND "Find-stock" "Look up specific stock item" HELP 402
CALL query_stock()
COMMAND "Update-stock" "Modify current stock information" HELP 403
CALL update_stock()
COMMAND "Delete-stock" "Remove a stock item from database" HELP 404
CALL delete_stock()
COMMAND "Exit" "Return to MAIN Menu" HELP 405
CLEAR SCREEN
EXIT MENU
END MENU
END FUNCTION
FUNCTION add_stock()
ERROR "This option has not been implemented" ATTRIBUTE (RED)
END FUNCTION
FUNCTION query_stock()
ERROR "This option has not been implemented" ATTRIBUTE (RED)
END FUNCTION
FUNCTION update_stock()
ERROR "This option has not been implemented" ATTRIBUTE (RED)
END FUNCTION
FUNCTION delete_stock()
ERROR "This option has not been implemented" ATTRIBUTE (RED)
END FUNCTION
A-34
d4_report.4gl
GLOBALS
"d4_globals.4gl"
FUNCTION reports()
CALL ring_menu()
MENU "REPORTS"
COMMAND "Labels" "Print mailing labels from customer list"
HELP 501
CALL print_labels()
CLEAR SCREEN
CALL ring_menu()
COMMAND "Accounts-receivable" "Print current unpaid orders" HELP 502
CALL print_ar()
CLEAR SCREEN
CALL ring_menu()
COMMAND "Backlog" "Print backlogged orders" HELP 503
CALL print_backlog()
CLEAR SCREEN
CALL ring_menu()
COMMAND "Stock-list" "Print stock available" HELP 504
CALL print_stock()
CLEAR SCREEN
CALL ring_menu()
COMMAND "Options" "Change the report output options" HELP 505
CALL update_options()
CALL ring_menu()
COMMAND "Exit" "Return to MAIN Menu" HELP 506
CLEAR SCREEN
EXIT MENU
END MENU
END FUNCTION
FUNCTION print_labels()
DEFINE where_part CHAR(200),
query_text CHAR(250),
msg CHAR(50),
file_name CHAR(20)
OPTIONS
FORM LINE 7
OPEN FORM customer FROM "custform"
DISPLAY FORM customer
ATTRIBUTE(MAGENTA)
CALL fgl_drawbox(3,30,3,43)
CALL fgl_drawbox(3,61,8,7)
CALL fgl_drawbox(11,61,8,7)
CALL clear_menu()
DISPLAY "CUSTOMER LABELS:" AT 1,1
MESSAGE "Use query-by-example to select customer list"
CONSTRUCT BY NAME where_part ON customer.*
IF int_flag THEN
LET int_flag = FALSE
ERROR "Label print request aborted"
RETURN
END IF
MESSAGE ""
LET query_text = "select * from customer where ", where_part CLIPPED,
" order by zipcode"
PREPARE label_st FROM query_text
DECLARE label_list CURSOR FOR label_st
CASE (print_option)
A-35
WHEN "f"
PROMPT " Enter file name for labels >" FOR file_name
IF file_name IS NULL THEN
LET file_name = "labels.out"
END IF
MESSAGE "Printing mailing labels to ", file_name CLIPPED,
" -- Please wait"
START REPORT labels_report TO file_name
WHEN "p"
MESSAGE "Printing mailing labels -- Please wait"
START REPORT labels_report TO PRINTER
WHEN "s"
START REPORT labels_report
CLEAR SCREEN
END CASE
FOREACH label_list INTO p_customer.*
OUTPUT TO REPORT labels_report (p_customer.*)
IF int_flag THEN
LET int_flag = FALSE
EXIT FOREACH
END IF
END FOREACH
FINISH REPORT labels_report
IF int_flag THEN
LET int_flag = FALSE
ERROR "Label printing aborted" ATTRIBUTE (RED, REVERSE)
RETURN
END IF
IF print_option = "f" THEN
LET msg = "Labels printed to ", file_name CLIPPED
CALL mess(msg, 23)
END IF
CLOSE FORM customer
OPTIONS
FORM LINE 3
END FUNCTION
A-36
FUNCTION print_ar()
DEFINE r RECORD
customer_num
fname
lname
company
order_num
order_date
ship_date
paid_date
total_price
END RECORD,
file_name CHAR(20),
msg CHAR(50)
LIKE
LIKE
LIKE
LIKE
LIKE
LIKE
LIKE
LIKE
LIKE
customer.customer_num,
customer.fname,
customer.lname,
customer.company,
orders.order_num,
orders.order_date,
orders.ship_date,
orders.paid_date,
items.total_price
A-37
LIKE
LIKE
LIKE
LIKE
LIKE
LIKE
LIKE
LIKE
LIKE
customer.customer_num,
customer.fname,
customer.lname,
customer.company,
orders.order_num,
orders.order_date,
orders.ship_date,
orders.paid_date,
items.total_price
OUTPUT
PAGE LENGTH 22
LEFT MARGIN 0
FORMAT
PAGE HEADER
PRINT 15 SPACES,"West Coast Wholesalers, Inc."
PRINT 6 SPACES,
"Statement of ACCOUNTS RECEIVABLE - ",
TODAY USING "mmm dd, yyyy"
SKIP 1 LINES
LET name_text = r.fname CLIPPED," ",r.lname CLIPPED,"/",
r.company CLIPPED
PRINT 29 - length(name_text)/2 SPACES, name_text
SKIP 1 LINES
PRINT " Order Date
Order Number
Ship Date
Amount"
PRINT "----------------------------------------------------------"
BEFORE GROUP OF r.customer_num
SKIP TO TOP OF PAGE
AFTER GROUP OF r.order_num
NEED 3 LINES
PRINT " ",r.order_date,7 SPACES,r.order_num USING "###&",8 SPACES,
r.ship_date," ",
GROUP SUM(r.total_price) USING "$$$$,$$$,$$$.&&"
AFTER GROUP OF r.customer_num
PRINT 42 SPACES,"----------------"
PRINT 42 SPACES,GROUP SUM(r.total_price) USING "$$$$,$$$,$$$.&&"
A-38
PAGE TRAILER
IF print_option = "s" THEN
PAUSE "Type RETURN to continue"
END IF
END REPORT
FUNCTION update_options()
DEFINE po CHAR(2)
DISPLAY "Current print option:" AT 8,25
LET po = " ", print_option
DISPLAY po AT 8,46 ATTRIBUTE(CYAN)
MENU "REPORT OPTIONS"
COMMAND "File" "Send all reports to a file"
LET print_option = "f"
EXIT MENU
COMMAND "Printer" "Send all reports to the printer"
LET print_option = "p"
EXIT MENU
COMMAND "Screen" "Send all reports to the terminal screen"
LET print_option = "s"
EXIT MENU
COMMAND "Exit"
EXIT MENU
END MENU
DISPLAY "" AT 8,1
END FUNCTION
FUNCTION print_backlog()
ERROR "This option has not been implemented" ATTRIBUTE (RED)
END FUNCTION
FUNCTION print_stock()
ERROR "This option has not been implemented" ATTRIBUTE (RED)
END FUNCTION
A-39
d4_demo.4gl
FUNCTION demo()
CALL ring_menu()
MENU "DEMO"
COMMAND "Menus" "Source code for MAIN Menu"
CALL showhelp(2001)
COMMAND "Windows" "Source code for STATE CODE Window"
CALL showhelp(2007)
COMMAND "Forms" "Source code for new CUSTOMER data entry"
CALL showhelp(2006)
COMMAND "Detail-Scrolling"
"Source code for scrolling of new ORDER line-items"
CALL showhelp(2003)
COMMAND "Scroll-Cursor" "Source code for customer record BROWSE/SCROLL"
CALL showhelp(2008)
COMMAND "Query_language" "Source code for new order insertion using SQL"
CALL showhelp(2004)
COMMAND "Construct_query"
"Source code for QUERY-BY-EXAMPLE selection and reporting"
CALL showhelp(2002)
COMMAND "Reports" "Source code for MAILING LABEL report"
CALL showhelp(2005)
COMMAND "Exit" "Return to MAIN MENU"
CLEAR SCREEN
EXIT MENU
END MENU
END FUNCTION
A-40
helpdemo.src
.101
The Customer option presents you with a menu that allows you to:
o
o
o
o
.102
The Orders option presents you with a menu that allows you to:
o
o
o
o
.103
The Stock option presents you with a menu that allows you to:
o
o
o
o
.104
The Reports option presents you with a menu that allows you to:
o
o
o
o
o
.105
The Exit option leaves the program and returns you to the operating system.
.201
The One-add option enables you to enter data on new customers to the database.
You may get assistance on what input is appropriate for each field by pressing
the function key F1 when the cursor is in the field.
When you have entered
all the data you want for a given customer, press ESC to enter the data in the
database. If you want to abort a given entry and not write it to the database,
press the INTERRUPT key (usually DEL or CTRL-C).
.202
The Many-add option enables you to enter data on new customers to the
database. You may get assistance on what input is appropriate for each field
by pressing the function key F1 when the cursor is in the field.
When you
have entered all the data you want for a given customer, press ESC to enter
the data in the database. If you want to abort a given entry and not write it
to the database, press the INTERRUPT key (usually DEL or CTRL-C). After each
entry, the cursor will move to the beginning of the form and await the entry
of the next customer. If you have no more customers to add, press CTRL-Z to
return to the CUSTOMER Menu.
A-41
.203
The Find-cust option allows you to select one or more customers and to display
their data on the screen by using query-by-example input. Use the RETURN or
arrow keys to move through the form. Enter the criteria you want the program
to use in searching for customers. Your options include:
o
o
o
o
o
Literal values
A range of values (separated by ":")
A list of values (separated by "|")
Relational operators (for example ">105")
Wildcards like ? and * to match single or any number of characters
.204
The Update-cust option enables you to alter data on old customers in the
database. You must first select a current customer row to deal with by using
the Find-cust option. You may get assistance on what input is appropriate for
each field by pressing the function key F1 when the cursor is in the field.
When you have altered all the data you want for a given customer, press ESC to
enter the data in the database. If you want to abort the changes and not write
them to the database, press the INTERRUPT key (usually DEL or CTRL-C).
.205
The Delete-cust option enables you to remove customers from the database.
You must first select a current customer row to deal with by using the
Find-cust option. For your protection, you will be asked to confirm
that the record should be deleted.
Once deleted, it cannot be
restored. Customers with active orders can not be deleted.
.206
The Exit option of the CUSTOMER Menu takes you back to the MAIN Menu.
.301
The Add-order option enables you to add a new order for an existing customer.
You must first select the desired customer using query-by-example selection
criteria. You will then enter the order date, PO number, and shipping
instructions. The detail line items are then entered into a scrolling display
array. Up to ten items may be entered using the four line screen array. After
the new order is entered, an invoice is automatically generated and displayed
on the screen.
.302
The Update-order option is currently not implemented.
.303
The Find-order option enables you to browse through and select an existing
order. You must first select the desired customer (or customers) whos orders
you wish to scan. For each customer selected, each corresponding order will
be displayed on the screen for examination. You may either select an invoice,
skip to the next invoice, or cancel processing.
.304
The Delete-order option is currently not implemented.
.305
The Exit option of the ORDER Menu returns you to the MAIN Menu.
A-42
.311
You may enter up to ten line items into the scrolling screen array. A number
of standard functions are available for manipulating the cursor in a screen
array.
o
o
o
o
o
o
F1
F2
F3
F4
ESC
CTRL-B
etc...
A-43
.1001
The Number field on the Customer Form contains the serial integer assigned to
the customer row when the data for the customer is first entered into the
database. It is a unique number for each customer. The lowest value of this
field is 101.
.1002
The first section following the Name label should contain the first name of the
contact person at the customers company.
.1003
The second section following the Name label should contain the last name of the
contact person at the customers company.
.1004
This field should contain the name of the customers company.
.1005
The first line of the Address section of the form should contain the mailing
address of the company.
.1006
The second line of the Address section of the form should be used only when
there is not sufficient room in the first line to contain the entire mailing
address.
.1007
The City field should contain the city name portion of the mailing
the customer.
address
of
.1008
Enter the two-character code for the desired state. If no code is entered, or
the entered code is not in the programs list of valid entries, a window will
appear on the screen with a scrolling list of all states and codes. Using the
F3, F4, up and down arrow keys, move the cursor to the line containing the
desired state. After typing ESC, the window will disappear and the selected
state code will appear in the customer entry screen.
.1009
Enter the five digit Zip Code in this field.
.1010
Enter the telephone number of the contact person at the customers company.
Include the Area Code and extension using the format "###-###-#### #####".
.2001
The following is the INFORMIX-4GL source for the main menu. Note that only
the text is specified by the MENU statement; the structure and runtime menu
functions are built-in.
OPTIONS
HELP FILE "helpdemo"
OPEN FORM menu_form FROM "ring_menu"
DISPLAY FORM menu_form
MENU "MAIN"
COMMAND "Customer" "Enter and maintain customer data" HELP 101
CALL customer()
DISPLAY FORM menu_form
COMMAND "Orders" "Enter and maintain orders" HELP 102
CALL orders()
DISPLAY FORM menu_form
COMMAND "Stock" "Enter and maintain stock list" HELP 103
CALL stock()
DISPLAY FORM menu_form
A-44
A-45
.2004
The following is the INFORMIX-4GL source code that uses SQL to insert the
entered order information into the database. Note that the use of
transactions ensures that database integrity is maintained, even if an
intermediate operation fails.
BEGIN WORK
LET p_orders.order_num = 0
INSERT INTO orders VALUES (p_orders.*)
IF status < 0 THEN
ROLLBACK WORK
MESSAGE "Unable to complete update of orders table"
RETURN
END IF
LET p_orders.order_num = SQLCA.SQLERRD[2]
DISPLAY BY NAME p_orders.order_num
FOR i = 1 to arr_count()
INSERT INTO items
VALUES (p_items[counter].item_num, p_orders.order_num,
p_items[counter].stock_num,
p_items[counter].manu_code,
p_items[counter].quantity,
p_items[counter].total_price)
IF status < 0 THEN
ROLLBACK WORK
Message "Unable to insert items"
RETURN FALSE
END IF
END FOR
COMMIT WORK
.2005
The following is the INFORMIX-4GL source code that generates the mailing-label
report. See the source code option CONSTRUCT for the report calling sequence.
REPORT labels_report (rl)
DEFINE rl RECORD LIKE customer.*
OUTPUT
TOP MARGIN 0
PAGE LENGTH 6
FORMAT
ON EVERY ROW
SKIP TO TOP OF PAGE
PRINT rl.fname CLIPPED, 1 SPACE, rl.lname
PRINT rl.company
PRINT rl.address1
IF rl.address2 IS NOT NULL THEN
PRINT rl.address2
END IF
PRINT rl.city CLIPPED, ", ", rl.state, 2 SPACES, rl.zipcode
END REPORT
.2006
The following is the INFORMIX-4GL source code that manages a simple form
for data entry. Note the use of special key definitions during data entry.
OPEN FORM cust_form FROM "customer"
DISPLAY FORM cust_form
MESSAGE "Press F1 or CTRL-F for field help;",
"F2 or CTRL-Z to return to CUSTOMER Menu"
DISPLAY "Press ESC to enter new customer data or DEL to abort entry"
INPUT BY NAME p_customer.*
AFTER FIELD state
CALL statehelp()
ON KEY (F1, CONTROL-F)
A-46
CALL customer_help()
ON KEY (F2, CONTROL-Z)
CLEAR FORM
RETURN
END INPUT
.2007
The following is the INFORMIX-4GL source code that opens a window in the
customer entry screen, displays the list of valid state names and codes, saves
the index into the p_state array for the selected state, closes the window, and
returns the index to the calling routine.
OPEN WINDOW w_state AT 8,40
WITH FORM "state_list"
ATTRIBUTE (BORDER, RED, FORM LINE 2)
CALL set_count(state_cnt)
DISPLAY ARRAY p_state TO s_state.*
LET idx = arr_curr()
CLOSE WINDOW w_state
RETURN (idx)
.2008
The following is the INFORMIX-4GL source code that allows the user to browse
through the rows returned by a "scroll" cursor.
DECLARE customer_set SCROLL CURSOR FOR
SELECT * FROM customer
ORDER BY lname
OPEN customer_set
FETCH FIRST customer_set INTO p_customer.*
IF status = NOTFOUND THEN
LET exist = FALSE
ELSE
LET exist = TRUE
DISPLAY BY NAME p_customer.*
MENU "BROWSE"
COMMAND "Next" "View the next customer in the list"
FETCH NEXT customer_set INTO p_customer.*
IF status = NOTFOUND THEN
ERROR "No more customers in this direction"
FETCH LAST customer_set INTO p_customer.*
END IF
DISPLAY BY NAME p_customer.*
COMMAND "Previous" "View the previous customer in the list"
FETCH PREVIOUS customer_set INTO p_customer.*
IF status = NOTFOUND THEN
ERROR "No more customers in this direction"
FETCH FIRST customer_set INTO p_customer.*
END IF
DISPLAY BY NAME p_customer.*
COMMAND "First" "View the first customer in the list"
FETCH FIRST customer_set INTO p_customer.*
DISPLAY BY NAME p_customer.*
COMMAND "Last" "View the last customer in the list"
A-47
A-48
Appendix
System Catalogs
Information about the database is maintained in the system
catalogs. The system catalogs are as follows:
systables
syscolumns
sysindexes
systabauth
syscolauth
sysdepend
syssynonyms
sysusers
sysviews
sysconstraints
syssyntable
Type
char(18)
char(8)
char(64)
serial
smallint
smallint
smallint
integer
date
integer
char(1)
char(64)
Explanation
name of table
owner of table
directory path for the table file
internal table identifier
row size
number of columns
number of indexes
number of rows
date created
table version number
table type (T = table, V = view, S = synonym)
audit filename (full pathname)
Index
Name
tabname
tabid
Type
unique
unique
Columns
tabname, owner
tabid
B-2
System Catalogs
Column
Name
colname
tabid
colno
coltype
collength
Type
char(18)
integer
smallint
smallint
smallint
Explanation
column name
table identifier
column number
column type
column length (physical)
Index
Name
column
Type
unique
Columns
tabid, colno
Type
char(18)
char(8)
integer
char(1)
char(1)
smallint
smallint
smallint
smallint
smallint
smallint
smallint
smallint
Explanation
index name
owner of index
table identifier
index type (U = unique, D = dupls)
clustering
column number
column number
column number
column number
column number
column number
column number
column number
Index
Name
idxtab
idxname
Type
dupls
unique
Columns
tabid
idxname, tabid
Type
char(8)
char(8)
integer
char(7)
Explanation
grantor of permission
grantee (receiver) of permission
table identifier
authorization type
Index
Name
tabgtor
tabgtee
Type
unique
dupls
Columns
tabid, grantor, grantee
tabid, grantee
Type
char(8)
char(8)
integer
smallint
char(2)
Explanation
grantor of permission
grantee (receiver) of permission
table identifier
column number
authorization type
System Catalogs
B-3
Index
Name
colgtor
colgtee
Type
unique
dupls
Columns
tabid, grantor, grantee, colno
tabid, grantee
Type
integer
char(1)
integer
char(1)
Explanation
tabid of base table or view
base object type (table or view)
tabid of dependent table
dependent object type (only view now)
Index
Name
btabid
dtabid
Type
dupls
dupls
Columns
btabid
dtabid
Type
char(8)
char(18)
date
integer
Explanation
user name of owner
synonym identifier
date synonym created
table identifier
Index
Name
synonym
syntabid
Type
unique
dupls
Columns
owner, synonym
tabid
B-4
System Catalogs
Column
Name
username
usertype
priority
password
Type
char(8)
char(1)
smallint
char(8)
Explanation
user login identifier
D = DBA, R = RESOURCE, C = CONNECT
reserved for future use
reserved for future use
Index
Name
users
Type
unique
Columns
username
Type
integer
smallint
char(64)
Explanation
table identifier
sequence number
portion of SELECT statement
Index
Name
view
Type
unique
Columns
tabid, seqno
Explanation
reserved for future use
constraint identifier
user name of owner
table identifier
reserved for future use
index name
Index
Name
Type
constrname unique
constrtabid dupls
constrid
unique
Columns
constrname, owner
tabid
constrid
Explanation
table identifier
used on INFORMIX-OnLine only
used on INFORMIX-OnLine only
used on INFORMIX-OnLine only
used on INFORMIX-OnLine only
tabid of base table or view
Index
Name
Type
synntabid unique
synnbtabid dupls
Columns
tabid
btabid
System Catalogs
B-5
B-6
System Catalogs
Appendix
Environment
Variables
INFORMIX-4GL makes the following assumptions about
the users environment:
If you are using the C shell, enter the following command to set the ABCD
environment variable to value:
setenv ABCD value
INFORMIX-4GL recognizes the following environment variables:
DBANSIWARN
DBANSIWARN specifies that you want to initiate Informix extension checking. Setting the DBANSIWARN environment variable before you compile a
4GL program is functionally equivalent to compiling with the -ansi flag.
When Informix extensions to ANSI standard syntax are encountered in your
program, warning messages are written to a .err file. At run time, the DBANSIWARN environment variable causes SQLAWARN[6] to be set to W when a
non-ANSI statement is executed.
C shell:
setenv DBANSIWARN
Bourne shell:
DBANSIWARN=
export DBANSIWARN
C-2
Environment Variables
DBDELIMITER
C shell:
unsetenv DBANSIWARN
Bourne shell:
unset DBANSIWARN
DBDELIMITER
DBDELIMITER specifies the field delimiter used by the dbload utility in
unloaded data files. The vertical bar ( | = ASCII 124) is the default.
For example, to make plus ( + ) the field delimiter on a C shell system, enter:
setenv DBDELIMITER +
DBDATE
DBDATE specifies the format you want to use for DATE values. Through
DBDATE, you can specify
where M represents the month, D represents the day, Y4 represents a fourdigit year, and the separator is a (/) slash (mm/dd/yyyy).
Other acceptable values for the separator are a hyphen ( - ), a period ( . ), or a
zero ( 0 ). (You use the zero to indicate no separator.) The slash appears if you
attempt to use a value other than the hyphen, period, or zero to indicate the
separator, or if you do not include a separator character in the DBDATE
definition.
DBEDIT
The separator value must always be specified last. The number of digits specified for the year must always follow the Y. To make the date appear as
mmddyy (with no separator), you would set the DBDATE environment variable for the C shell as follows:
setenv DBDATE MDY20
DBEDIT
DBEDIT names the text editor for creating program files, form specification
files, and command files from within the INFORMIX-4GL Programmers
DBLANG
DBLANG specifies the subdirectory of $INFORMIXDIR that contains
the message (.iem) files used by your program. The default is
$INFORMIXDIR/msg.
C-4
Environment Variables
DBMONEY
If you want to use a message directory other than $INFORMIXDIR/msg, perform the following steps:
1. Use the mkdir command to create the appropriate subdirectory in
$INFORMIXDIR. Set the user and group to informix and the access
permission for this directory to 755.
2. Set the DBLANG environment variable to the new subdirectory. (Specify
only the name of the subdirectory and not the full pathname of the
subdirectory.) If you are using the Bourne shell, enter
DBLANG=dirname
export DBLANG
DBMONEY
DBMONEY applies to MONEY values. It has the format
[ front ] { . | , } [ back ]
where front is the optional symbol that precedes the MONEY value, the
comma or the period is the optional symbol that separates the integral from
the fractional part of the MONEY value, and back is the optional symbol that
follows the MONEY value. The front and back symbols can be up to seven
characters long and can contain any characters except commas or periods.
The default value for DBMONEY is
$.
where the dollar sign precedes the MONEY value, and the period (.) separates
the integral from the fractional part of the MONEY value. (No back symbol
appears.)
Suppose you wanted to represent MONEY values in deutsche marks. For the
C shell, you would set the DBMONEY environment variable as follows:
setenv DBMONEY DM,
DBPATH
where DM is the currency symbol, and the comma separates the integral from
the fractional part of the MONEY value.
If you have specified both symbols and you make a change to either one, you
must respecify the other symbol and the value separator (comma or period).
Similarly, if you change the value separator from a comma to a period, you
must respecify the front symbol as well as the back symbol (if you had previously specified a back symbol).
DBPATH
DBPATH specifies a list of directories (in addition to the current directory) for
INFORMIX-4GL to search for databases and associated files. If you have not
selected a database, INFORMIX-4GL looks to DBPATH as well as the current
DBPRINT
DBPRINT specifies the print program for your computer. For most UNIX systems, the default program is lp.
DBTEMP
DBTEMP specifies the directory into which INFORMIX-4GL should place its
C-6
Environment Variables
INFORMIXDIR
INFORMIXDIR
INFORMIXDIR specifies the directory containing the INFORMIX-4GL files. The
default is the /usr/informix directory.
INFORMIXTERM
INFORMIXTERM specifies whether INFORMIX-4GL should use the termcap or
SQLEXEC
SQLEXEC is needed only if you have both INFORMIX-SE and INFORMIX-OnLine installed on your system, and you want to access INFORMIX-SE.
If you have both engines installed, but you do not specify SQLEXEC, then
INFORMIX-OnLine is the default engine.
SQLEXEC must contain the full pathname of the database engine, which is
located in the lib subdirectory of $INFORMIXDIR.
SQLEXEC
C-8
Environment Variables
Appendix
Reserved Words
This appendix contains a list of Informix reserved words.
Do not use these words as identifiers or as program variable or host variable names. If you use reserved words as
identifiers or variables, your program (or SQL statement)
may fail with an error.
This list contains reserved words from all Informix products, although not all are reserved in each product. Note
that, while their use is not recommended, some reserved
words may not cause errors in every case. For example,
words that are reserved in INFORMIX-4GL will not generate
an error if used with only INFORMIX-SQL. However, if
your INFORMIX-SQL application is later ported to an
INFORMIX-4GL environment, any INFORMIX-4GL
reserved words will cause errors. Additionally, some words
only generate errors if used as host or program variables,
while other words only generate errors if used as identifiers.
In addition to the words on this list, you should not use C,
ADA, or COBOL language keywords in your programs.
abort
absolute
accept
access
add
after
all
allowing
alter
and
ansi
any
array
as
asc
ascending
ascii
at
attribute
attributes
audit
auto
autonext
average
avg
background
before
begin
beginning
bell
between
black
blanks
blink
blue
bold
border
bottom
buffered
by
byte
call
case
D-2
Reserved Words
char
character
check
clear
clipped
close
cluster
col
color
colors
column
columns
command
comment
comments
commit
committed
composites
compress
connect
constant
constraint
construct
continue
convert
count
create
current
cursor
cyan
database
date
datetime
date_type
day
dba
debug
dec
decimal
decimal_type
declare
dec_t
default
defaults
defer
define
delete
delimiter
delimiters
desc
descending
describe
descriptor
dim
dirty
display
displayonly
distinct
do
dominant
double
down
downshift
drop
dtime
dtime_t
eco-*
editadd
editupdate
else
end
end-exec
endif
ending
error
escape
every
exclusive
exec
execute
exists
exit
exitnow
exits
explain
extend
extent
extern
external
false
fetch
field
file
finish
first
fixchar
float
flush
for
foreach
form
format
formonly
found
fraction
free
from
function
globals
go
go to
goto
grant
green
group
having
header
headings
help
hold
hour
identified
if
ifdef
ifndef
immediate
in
include
index
indicator
infield
info
initialize
input
insert
instructions
int
integer
interrupt
intersect
interval
into
intrvl_t
inverse
invisible
is
isam
isolation
join
joining
key
label
last
left
len
length
let
like
line
lineno
lines
load
locator
lock
loc_t
log
long
long_float
long_integer
lookup
loop
magenta
main
margin
master
matches
max
mdy
memory
menu
message
min
minus
minute
mod
mode
modify
module
money
month
name
natural
need
new
next
nextfield
no
nocr
noentry
normal
not
not found
notfound
noupdate
now
null
numeric
of
off
on
open
option
options
or
order
otherwise
out
outer
output
package
page
pageno
param
pause
percent
perform
picture
pipe
positive
precision
prepare
previous
print
printer
prior
privilege
privileges
program
prompt
public
put
query
queryclear
quit
raise
range
read
readonly
real
record
recover
red
register
relative
remove
rename
repair
repeatable
report
required
resource
return
returning
reverse
revoke
right
rollback
rollforward
row
rowid
rows
run
savepoint
screen
scroll
second
section
select
serial
serial_type
set
share
shift
short
short_float
short_integer
sitename
size
skip
sleep
smallfloat
smallint
some
space
spaces
sql
sql*
sqlca
sqlchar_type
sqlda
sqldecimal_type
Appendix D: Reserved Words
sqlerr
sqlerror
sqlfloat_type
sqlint_type
sqlmoney_type
sqlsmfloat_type
sqlsmint_type
sqlwarning
stability
start
startlog
static
statistics
status
stdv
step
stop
string
struct
subtract
D-4
Reserved Words
subtype
sum
synonym
systables
table
temp
text
then
through
thru
time
tiny_integer
to
today
top
total
trailer
trailing
true
type
typedef
undef
underline
union
unique
units
unload
unlock
up
update
upshift
user
using
validate
values
varchar
variable
vc_t
verify
view
wait
waiting
warning
weekday
when
whenever
where
while
white
window
with
without
wordwrap
work
wrap
year
yellow
yes
zerofill
Appendix
INFORMIX-4GL
Utility Programs
This appendix describes nine utility programs that are
included with the INFORMIX-4GL software. You can invoke
these utilities at the system prompt to perform any of the
following tasks:
E-2
In the example on the next page of output from this command line, bcheck
finds no errors.
BCHECK C-ISAM B-tree Checker version 4.00.00
Copyright (C) 1981-1989 Informix Software, Inc.
Software Serial Number INF#R000000
-l
-n
-y
-q
-s
Unless you use the -n or -y option, bcheck is interactive, waiting for you to
respond to each error that it finds.
Use the -y option with caution. Do not run bcheck using the -y option if you
are checking the files for the first time.
E-3
Since bcheck finds errors, you must delete and rebuild the corrupted
indexes.
E-4
E-5
Syntax
dbexport [ -c ] [ -q ] database
[ -o directory-path | -t device -b blksize -s tapesize [ -f pathname ] ]
Explanation
dbexport
-c
-q
database
-b blksize
-s tapesize
-f pathname
Notes
1. You must have DBA privilege or log in as user informix to export a
database.
2. The database is locked in exclusive mode during export. If an exclusive
lock cannot be obtained, the program ends with a diagnostic message.
3. The dbexport program always creates a file of messages called
dbexport.out. This file contains any error messages and warnings, and it
also contains a display of the SQL data definition statements that it is generating. The same material is also written to the standard output unless
you specify the -q option.
E-6
4. You can cancel the program with an Interrupt signal. The dbexport program asks for confirmation before terminating.
5. The dbexport program writes multiple files containing database data,
either to disk or to tape. The -t option specifies that the destination is a
tape drive; otherwise, dbexport writes the files to disk. When you include
the -t option, you must also specify the tape device, the block size, and the
volume capacity.
6. When you include the -t option, the file of data definition statements and
other commands (used by the dbimport utility) are ordinarily also written to the tape. Use the -f option to instruct the program to write these to
the file pathname. This allows you to inspect and modify the statements.
7. When you do not include the -t option, the destination is a disk directory
with the name database.exp. This directory must not exist; the program
will create it. Its group will be informix. If you include the -o directorypath option, the database.exp directory is located in the specified directory.
By default, the database is placed in your current working directory.
8. When output is to disk, the file containing the data definition statements
and other commands to dbimport is written to the file database.sql in the
database.exp directory.
Examples
The following command exports the stores database to tape with a block size
of 16 kilobytes and a tape capacity of 24,000 kilobytes. The file of data definition statements and other directions to dbimport is written to stores.imp in
the /tmp directory.
dbexport -c stores -t /dev/rmt0 -b 16 -s 24000 -f /tmp/stores.imp
E-7
Syntax
dbimport [-c] [-q] database
[-i directory-path |-t device -b blksize -s tapesize [-f pathname] ]
[-d dbspace] [-l [ logpath | buffered] ] [-ansi]
Explanation
-c
-q
database
E-8
-t device
-b blksize
-s tapesize
-f pathname
-d dbspace
-l
logpath
when importing to the standard database engine only, specifies the pathname of the transaction log file.
buffered
when importing to INFORMIX-OnLine only, specifies buffered or unbuffered logging (unbuffered is the default).
-ansi
Notes
1. The program always creates a message file called dbimport.out in the
current directory. This file contains messages and warnings related to the
running of the program. The message are also written to the standard output (normally the terminal screen) unless you include the -q option.
2. You can cancel the program with an interrupt signal. You are prompted
for confirmation before the program terminates.
3. The individual who runs dbimport is granted DBA privilege on the new
database.
4. When importing a database that uses the standard database engine, database files are created in the current directory.
5. Use the -l option to establish transaction logging for the imported database. This option is equivalent to the WITH LOG IN clause of the CREATE
DATABASE statement. A database created as MODE ANSI requires transaction logging. In this situation, you must include the -l option.
6. The dbimport utility reads multiple files containing database data from
either disk or tape. Use the -t option to specify the source as tape; the
default is disk. When you include the -t option, you must also specify the
tape device, blocksize and volume capacity.
7. When you include the -t option, dbimport reads the data definition
statements and other dbimport commands from the tape. Use the
-f pathname option to instruct the program to read the database.sql file in
pathname (instead of the tape) for the data definition statements and other
commands.
To use the -f option you must have also used it when you executed the
dbexport program.
8. If you do not specify the -t option, the source of the database data is a disk
directory with the name database.exp. The dbimport program looks for
this directory in the current working directory, or on the path specified
with the -i option. In either case, the program takes data definition and
other commands from the file database.sql in the directory database.exp.
(This is why the name database must be the same as was given to
dbexport.)
E-9
Example
The following command imports the stores database from a tape with a
blocksize of 16 Kbytes and capacity of 24,000 Kbytes. The file of data definition statements and other import commands was put in stores.imp in the
/tmp directory when dbexport was run.
dbimport -c stores -t /dev/rmt0 -b 16 -s 24000 -f /tmp/stores.imp
The following command imports the stores database from the /usr/informix/
port/stores.exp directory using data definition and commands from the file
stores.sql in that directory. The new database is created as MODE ANSI and
uses logging.
dbimport -c stores -i /usr/informix/port -ansi -l /usr/work/stores.log
INFORMIX-OnLine supports additional functionality. Refer to the INFORMIXOnLine Programmers Manual for more information.
E-10
Data from selected fields of one or more input files can be loaded into
selected columns of one or more database tables.
The user can specify an error limit, and dbload stops when that limit is
reached on the number of records that cannot be entered into the database
because of errors.
If your database supports transactions, you have the option of terminating the loading process without committing any data from the batch of
records that exceeded your error limit.
To use dbload, you must have at least one ASCII input file of data records to
enter, and at least one table to receive the data. You must then create a
command file to specify instructions for reading and loading the data. Finally,
you must invoke dbload by entering an appropriate command line. The following sections provide details about these procedures.
Here yyyy represents year digits, mm the month (January = 1 or 01), dd the day
of the month, hh the hour, mi the minute, ss the second, and fff the fractional part
of a second.
One or more FILE statements, to define data fields within the records of
the input file(s)
One or more INSERT statements, to indicate how to place the new data
into the columns of the database table(s)
INSERT statements in dbload command files resemble INSERT statements in
SQL, except that they cannot incorporate SELECT statements (since the data
are not yet in any table). In effect, the most recent FILE statement replaces
SELECT in defining the list of data values for a dbload INSERT statement to
E-12
The command file can include multiple FILE and INSERT statements. An
explanation of these terms, notes, and an example follow.
Explanation
FILE
is a required keyword.
filename
DELIMITER
nfields
fieldn
start
-end
NULL
null-str
INSERT INTO
tablename
E-13
column-list
VALUES
is an optional keyword to specify a list that can include constants and data field names.
value-list
Notes
1. The dbload utility recognizes valid owner.table references.
2. You need UNIX read permission for filename, and you must also be granted
the INSERT privilege for tablename.
3. Every statement must end with a semicolon ( ; ) symbol.
4. You cannot specify character positions or null-str symbols in a record
defined with the DELIMITER option.
5. Use a colon ( : ) to separate character position or range values in each data
field definition. The list of field definitions must be enclosed in parentheses and separated by commas.
6. The same character position can be repeated in the FILE specification of a
field, or in different fields. (See the command file example that follows
these notes.)
7. The scope of reference of a null-str is the field for which you define it, but
you can define the same null-str for other fields.
8. The DELIMITER option automatically assigns the sequential names f01,
f02, f03, . . . to fields in variable-length records. The value-list of an INSERT
statement can reference field names assigned by the user or by dbload in
the previous FILE statement.
9. If your INSERT statement omits the column-list, then the default columns
are every column in tablename. If you do not specify a value-list, then the
default values are those in every field of the previous FILE statement.
10. An error results if the column-list and the value-list have different numbers
of elements.
11. If the column-list includes fewer columns than tablename, dbload attempts
to insert NULL values in the remaining columns. If a NOT NULL restriction or UNIQUE CONSTRAINT would be violated, the insertion fails, and
an error message appears.
12. Inserted data types correspond to the explicit or default column-list. If the
data field width is different from its corresponding character column,
E-14
inserted values are padded with blanks if the column is wider, or are truncated if the field is wider.
13. Enclose between braces ( { } ) any comments in filename.
14. Use the DELIMITER option to avoid truncation of long character fields. If
the delimiter c (or a backslash) appears as a literal character, you must
prefix it with a backslash ( \ ) in the input file.
15. If you specify DELIMITER, the same delimiter must be used throughout
the input file and must appear in quotes in the FILE statement. You must
remember to place the delimiter immediately before the NEWLINE character that marks the end of each record. (If you omit this delimiter, an
error results whenever the last field of a record is empty.)
Examples
FILE "datafile1" (fld1 1 - 10 : 13 : 5 - 22 NULL = "str1" ,
fld2 10 - 21 : 28 - 32 ,
fld3 8 - 10 : 33 - 50 : 29 - 33 NULL = "str2" ,
. . .
fldN 9 : 16 - 19
NULL = "string") ;
{variable-length fields}
Note: The ellipses (. . .) in this example are typographic conventions that cannot
appear in command files. Unless you use the DELIMITER option, for example, you
must explicitly list every field that a FILE statement defines. Each statement in this
example is described in the pages that follow.
FILE "datafile1" (fld1 1 - 10 : 13 : 5 - 22
NULL = "str1" ,
Here datafile1 is the input file, and fld1, fld2, fld3, through fldN are userassigned field names in its fixed-length data records. In this example, fld1
consists of the characters in positions 1 through 10, 13, and 5 through 22 of
every datafile1 record. (Each record ends with a NEWLINE character.) Notice
that the characters 5 through 10 and 13 appear twice in fld1, and characters
10, 13, and 21 appear in fld1 and fld2.
In field fld1, the NULL symbol is defined as str1. A NULL value is entered
whenever str1 is read in fld1.
INFORMIX-4GL Utility Programs
E-15
The fld2 field consists of positions 10 through 21, and 28 through 32.
The fld3 field is defined as the characters in positions 8 through 10, 33 through
50, and 29 through 33. The NULL symbol for field fld3 is defined as str2.
The field-definition process continues until the last field is reached. Field fldN
contains characters in positions 9, and 16 through 19. The NULL value is
defined as string.
INSERT INTO tab1 (col1, col2, col9, . . . , colN) ;
An INSERT statement follows. Here col1, col2, col9, and so on are the actual
database column names in table tab1. Since no value list is provided, dbload
takes the values in the fields defined in the preceding FILE statement. It
inserts the data from fld1 into col1, from fld2 into col2, from fld3 into col9, and
so forth, until the value from fldN is inserted into colN. (Columns 4 through
8 are skipped, so the new rows will have NULL values there, if the columns
permit NULLs.)
INSERT INTO tab2
VALUES (fld1, fld3, "kevin", . . . , fldN) ;
Since no column list is provided, dbload reads the names of all the columns
in tab2 from the system catalogs. Values to load into each column are specified by field names from the previous FILE statement or as constants. Data in
fld1 go into the first column, data from fld3 into the second, and the constant
kevin into the third. The dbload utility continues until the value in fldN is
inserted into the final column.
INSERT INTO tab3 ;
E-16
The DELIMITER clause tells dbload that file datafile.2 has variable-length
fields, and that the vertical-bar character ( | = ASCII 124) separates each field.
Here 8 is the number of fields in each input record. Fields are automatically
assigned the names f01, f02, f03, and so on.
INSERT INTO tab1
VALUES (f01, f02, "kevin", "234", . . . , f08) ;
Since no column-list or value-list is provided, dbload finds all the names of columns in table tab4 in the system catalogs. The value-list is all the fields
defined in the previous FILE statement. (Notice that this is not the same FILE
statement that was used with table tab3.)
If these values have a one-to-one correspondence with the columns, the value
from field f01 goes into the first column, the value from f02 into the second
column, and so on, until the value in f08 is placed in the last column. An error
results if 8 is not the number of columns in table tab4.
E-17
To use dbload to read and execute a command file, you must enter a command line that includes at least one of its required specifications. The following elements are required in a dbload command line:
dbload { -d database | -c comfile | -l logfile } . . .
dbload
-d database
-c comfile
-l logfile
The following sections describe both the interactive and command modes of
dbload.
Whether you only want dbload to check the syntax of the FILE and
INSERT statements in your command file, without changing the database.
How many bad input records can be encountered before dbload stops
inserting new rows.
How many input file records to read before committing new rows to the
database, if your database supports transactions.
Whether to discard or to commit to the database any rows that were successfully read between the last COMMIT and the first bad record that
exceeds your cumulative error limit.
How many input records to ignore before dbload begins to insert data.
(That is, how many NEWLINE characters to read before actual processing
begins.)
After you enter these specifications or press RETURN to accept the default
values that appear in the prompts, the screen is cleared, and the dbload utility begins execution.
E-18
Syntax
dbload -d database -c comfile -l logfile
[ -e num1 ] [ -n num2 ] [ -i num3 ] [ -p ] [ -r ] [ -s [ > outfile ] ]
Explanation
dbload
is a required keyword.
-d database
-c comfile
-l logfile
-e num1
-n num2
-i num3
-p
-r
instructs dbload not to lock the table(s). (Otherwise, tablelevel locking occurs during loading.)
-s
> outfile
Notes
1. Unless you include at least one of the first three options, dbload displays
a help message and terminates. If you omit one or two of the three
required options, dbload prompts you for additional specifications.
2. You can prefix comfile, logfile, or outfile with a pathname.
E-19
3. You should run dbload with the -s or -s > outfile options before you begin
loading data. These options perform a syntax check on the FILE and
INSERT statements in comfile and ignore any other options except -d database and -c comfile. The screen displays comfile with any errors marked
where they are found.
4. If you do not specify a value for num1, the default is 10 bad records, so the
program stops loading when it reads the 11th bad record. If you set num1
at zero, dbload terminates when it reads the first bad record.
5. If your database supports transactions, dbload reads and inserts a batch
of num2 records between each COMMIT. If you do not specify a value for
num2, the default is 100 records.
6. The -i option instructs dbload to ignore the first num3 lines in the input
file, so processing does not begin until dbload has read num3 NEWLINE
characters. This option is useful, for example, if your most recent dbload
session with the same command file ended after 240 lines of input. You
can resume loading at line 241 by setting num3 equal to 240. It is also useful if header information in the input file precedes the data records.
7. After (num1 + 1) bad records in a database with transactions, the -p
option prompts you to roll back or to commit any rows inserted since the
last transaction. The default is to commit.
8. If you press the Interrupt key, dbload terminates and discards any new
rows that have been inserted but not yet committed to the database (if the
database has transactions).
9. The presence of indexes greatly affects the speed with which the dbload
utility loads data. For best performance, drop any indexes on the tables
receiving the data before you run dbload. You can create new indexes
after dbload has finished.
Examples
The following example shows a dbload command line at the system prompt
that uses all options (except the -s option):
dbload -d stores -c cfyl -l lfyl -e 5 -n 75 -i 20 -p -r
This example specifies the following parameters:
E-20
-d stores
-c cfyl
-l lfyl
-e 5
specifies that dbload will log up to five bad records. The program terminates if a 6th bad record is encountered.
-n 75
-i 20
tells dbload to ignore the first 20 lines of the data file. Processing begins at the 21st line.
-p
-r
Notice that the names of the input file and the table(s) to receive the data do
not appear explicitly in the command line. These names must be specified
within the dbload command file, which is called cfyl in this example.
E-21
E-22
-t tabname
-s sname
specifies the user for whom you want dbschema to output the
CREATE SYNONYM statements. If you specify all for sname,
dbschema outputs all CREATE SYNONYM statements. If you
include the -t option, dbschema produces the CREATE
SYNONYM statements only for the indicated tabname.
-p pname
specifies the user for whom you want dbschema to output permission statements. If you specify all for pname, dbschema
outputs the GRANT statements for all users. If you include the
-t option, dbschema produces the GRANT statements only for
the indicated tabname.
-d database
filename
Notes
1. The following command line produces the SQL statements necessary to
replicate an entire database:
dbschema -d database
This statement tells you that norma issued the GRANT statement.
7. When the GRANT..AS keywords appear in your dbschema output, you
may need to grant certain permissions before running the output as an
SQL script. Consider the following GRANT statement:
GRANT tab-privilege ON user1.tablename TO "user2" AS "user3"
Before this statement can be run to create another schema, the following
must be true:
E-23
Examples
The following statement outputs the SQL statements relating to the customer
table in the stores database to the file c_schema.sql.
dbschema -t customer -s alice -p dinah -d stores c_schema.sql
The CREATE TABLE and CREATE INDEX statements for the customer table
All CREATE SYNONYM statements executed by the user alice on the
customer table
The next dbschema statement outputs the SQL statements for all tables in the
stores database to the file s_schema.sql.
dbschema -t all -s alice -p alice -d stores s_schema.sql
The CREATE TABLE, CREATE VIEW, and CREATE INDEX statements that
replicate all tables, views, and indexes in the stores database
E-24
Using dbupdate
To convert an old database to the new structure, execute the following
command:
dbupdate [ -b | -n ] old-database-name new-database-name
The dbupdate utility creates a new database in the current directory with the
name new-database-name, and copies the data from the old system catalogs to
the new system catalogs, making the appropriate changes.
If you do not use the -b or -n option, dbupdate converts the value of all CHAR
type columns with blank data to NULL and, for each number column, asks
you whether it should convert zero values to NULL values.
The -b option causes dbupdate to leave blank data in CHAR columns as
blanks. The -n option alters the system catalogs to define all columns as NOT
NULL, and does not touch the data files. The -n option includes the -b option.
In addition to these changes, dbupdate corrects a bug in the representation
of negative DECIMAL values.
When dbupdate finishes, you have two database directories (the new and the
old) with two separate system catalogs, but the data and index files are
shared (linked). To complete the update, you should remove the old database
directory.
E-25
No NULL Databases
You may want to avoid dealing with NULL values and their three-valued
logic. You can do this if you carefully adhere to the following rules:
E-26
Syntax
.num
message-text
...
[ ... ]
Explanation
.num
message-text
Notes
1. Each line must end in a RETURN.
2. Each help message should be preceded by a line with nothing on it but a
period (in the first column) and a unique integer num.
INFORMIX-4GL Utility Programs
E-27
3. The message-text starts on the next line, and continues until the next numbered line.
4. You can use the integer num to identify the help message in your INFORMIX-4GL programs. (See the INPUT, INPUT ARRAY, MENU, and
PROMPT statement descriptions in Chapter 7.)
5. All blank lines between two numbered lines are considered part of the
message that belongs to the first of the two numbers.
6. Lines beginning with # are considered comment lines, and are ignored by
mkmessage.
7. If the text of a message occupies more than 20 lines, INFORMIX-4GL automatically breaks the message into pages of 20 lines. You can change
these default page breaks by entering CTRL-L in the first column of a line
in your message file to start a new page.
8. INFORMIX-4GL handles clearing and redisplaying the screen.
Examples
For an example, see the helpdemo.src file from the demonstration application in Appendix A. (See also the section Creating a Help File in Chapter 8
of the INFORMIX-4GL User Guide.)
Syntax
mkmessage helpfile.src helpfile.out
Explanation
E-28
helpfile.src
helpfile.out
Notes
1. You can give the input and output help files any valid names and extensions in place of those shown above.
2. You can specify the output help file name in the OPTIONS statement to
identify it as the current help file.
3. If you want to use help messages from the help file on a field-by-field
basis in an INPUT or INPUT ARRAY statement, you must use the infield()
and showhelp( ) library functions that are supplied with INFORMIX-4GL.
Examples
The example that follows illustrates the use of these functions:
OPTIONS
HELP FILE "stores.hlp",
HELP KEY F1
...
INPUT pr_fname, pr_lname, pr_phone
FROM fname, lname, phone HELP 101
ON KEY (F1)
CASE
WHEN INFIELD(lname)
CALL showhelp(111)
WHEN INFIELD(fname)
CALL showhelp(112)
WHEN INFIELD(phone)
CALL showhelp(113)
OTHERWISE
CALL showhelp(101)
END CASE
END INPUT
E-29
If you choose to modify the contents of the 4glusr.msg message file, you must
specify 4glusr.iem in your mkmessage command line as the object file name:
mkmessage source-file-name 4glusr.iem
The executable file 4glusr.iem is initially installed in the directory $INFORMIX/msg. INFORMIX-4GL looks for message files in one of two directories,
namely /$INFORMIXDIR/$DBLANG or else
/$INFORMIXDIR/msg. If $DBLANG is defined, 4GL looks only in
/$INFORMIXDIR/$DBLANG. If this is not defined, 4GL looks only in
/$INFORMIXDIR/msg. You must place the newly modified file 4glusr.iem
in the appropriate /$INFORMIXDIR/msg or /$INFORMIXDIR/$DBLANG
directory.
E-30
your table and field names are not among the new reserved words. For a list of
reserved words, see Appendix D in this manual.
Make sure all INFORMIX composite fields are indexed. Indexed composite fields will
have composite indexes created for them.
If you have used the LOCATION option to spread an INFORMIX database across a
number of directories, converting the database using sqlconv places all of these files
in the new .dbs directory.
You cannot specify a new starting number for a SERIAL column.
E-31
Conversion Procedures
If There Is No Shortage of Disk Space
You can convert an entire INFORMIX database to an SQL compatible database
for use with INFORMIX-4GL at one time if there is no shortage of disk space.
To convert an entire database at once, you must have available on the disk at
least three times the amount of space required by all the tables in the database
plus additional space for the 4GL system files. The following steps outline the
process of converting an entire database at once:
1. Make certain that INFORMIX and INFORMIX-4GL are included in your
search path.
2. Set the INFORMIXDIR environment variable to point to the INFORMIX-4GL directory.
3. Change your current directory to the directory that contains your INFORMIX database.
4. Create a backup copy of the INFORMIX database.
5. Enter
sqlconv -e databasename
where databasename is the name of the INFORMIX database that you want
to convert. Do not include a filename extension. This command generates
an INFORMER script file (indicated by a .uld extension), an INFORMIX-4GL program (indicated by a .4gl extension), and a dbload command file (indicated by a .cmd extension).
6. Enter
informer databasename databasename.uld
This command unloads the database files (in ASCII format) to unload files
(indicated by a .unl extension) for each table in the database.
E-32
This command compiles the 4GL program created in Step 5, and creates
an executable file with extension .out.
If you have the RDS version of INFORMIX-4GL, enter
fglpc databasename.4gl
This creates a p-code file databasename.4go from the 4GL program that
you created in Step 5.
8. If you have the C Compiler Version of INFORMIX-4GL, enter
databasename.out
This executes the p-code file that you created in Step 6, and re-creates the
database, tables, and indexes in SQL format, but it does not load the data.
9. Enter
dbload -d databasename -c databasename.cmd -l errlog
This command loads the data from the .unl files (generated by informer)
into the appropriate tables, and creates an errlog file, which contains diagnostic information about any rows that were not successfully loaded. For
more information on dbload, see The dbload Utility in this appendix.
10. The final step in the conversion procedure is to remove all the old database files, and the .uld, .4gl, .cmd, .unl, .out or .4go files from your
directory, and any .ec or .c files that may have been created if you have the
C Compiler Version of INFORMIX-4GL. Do not remove your forms and
reports. You can update these later.
E-33
The following steps outline the conversion of the example INFORMIX database, payroll, to an SQL-compatible database for use with 4GL:
1. Make certain that INFORMIX and INFORMIX-4GL are included in your
search path.
2. Set the INFORMIXDIR environment variable to point to the INFORMIX-4GL directory.
3. Change your current directory to the directory that contains your INFORMIX database.
4. Create a backup copy of the INFORMIX database.
5. Enter
sqlconv -e payroll
This command compiles the 4GL program that you created in Step 5, and
creates an .out executable file.
If you have the RDS version of INFORMIX-4GL, enter
fglpc payroll.4gl
This creates a p-code file payroll.4go from the 4GL program that you created in Step 5.
7. If you have the C Compiler Version of INFORMIX-4GL, enter
payroll.out
This executes the p-code file that you created in Step 6, and re-creates the
database, tables, and indexes in SQL format, but it does not load the data.
E-34
8. Enter
cat payroll.uld
The statements in the payroll.uld file outline the first steps of the conversion operation. You must execute each of these statements separately. You
may find it helpful to print a copy of the payroll.uld file for easy reference.
9. Enter
informer payroll
At the INFORMER prompt, enter the first line of the payroll.uld file
exactly as it appears. This creates the unload file for the first table. Exit
from INFORMER.
10. The .cmd file describes the form of the data and contains the INSERT INTO
statements indicating how this data is to be placed in the database files.
The INSERT INTO statements are necessary to load the data into the newly
created database. You must execute each of the statements separately. To
do this, create a copy of the payroll.cmd file for each INSERT INTO statement and make sure you include the .cmd extension to the filename of
each new file. In this instance, we have named the files one.cmd and
two.cmd.
11. Edit the one.cmd file using your system editor, and remove all but the
first INSERT INTO statement from the file. Exit from the file.
12. Execute the first INSERT INTO statement in the one.cmd file by entering
dbload -d payroll -c one.cmd -l errlog
This command loads the data from the .unl file into the appropriate table
and creates an errlog file, which contains diagnostic information about
any rows that were not successfully loaded. A statement appears on the
screen indicating how many rows were loaded into the file. For more
information on dbload, see The dbload Utility in this manual.
13. Before you can perform the same operations on any other database tables,
you must free additional disk space by erasing the INFORMIX versions of
the recently created INFORMIX-4GL files. To erase these files, enter
dbstatus payroll
where filename is the name of the file referred to in the .cmd file created in
Step 11. Exit from dbstatus.
INFORMIX-4GL Utility Programs
E-35
15. Erase the unload file for this same file by entering from the command line
rm filename.unl
16. Continue to unload each table, one at a time, from the INFORMIX database and then load it into the INFORMIX-4GL database. Do this by
repeating Steps 9 through 15. Remember to make a copy of the .cmd file
for each INSERT INTO statement it contains. Each copy must have a
unique name and must end in the .cmd extension. The correct filename
must be included on the command line each time you run the dbload
command.
Repeat these steps until all load statements in the payroll.cmd file have
been executed. This operation loads the actual data into the newly created
database.
17. Check the contents of the data files in the newly created database to make
sure you have successfully converted your INFORMIX database.
18. When all tables in the database have been converted, erase the .uld, .4gl,
.cmd, .out, or .4go files from your directory (and any .ce or .c files that
may have been created if you have the C Compiler Version of INFORMIX-4GL) and drop the INFORMIX database.
Caution: You cannot rerun sqlconv after you have erased a table. The new
scripts generated by the command do not contain the information necessary to convert the table.
E-36
Attributes
Exit
If you select either Validate or Attributes, upscol checks whether the corresponding table exists and, if not, asks whether you want to create it. In the
text that follows, the corresponding table is called syscol. If you choose not to
create it, enter n, and you will return to the UPDATE SYSCOL Menu.
If the data validation table already exists, or if you enter y to create it, upscol
displays the CHOOSE TABLE screen, and prompts you for the name of a table
(tab-name) in db-name. After you select a table, the CHOOSE COLUMN screen
prompts you to select the name of a column (col-name) whose default values
you want to modify in syscol.
E-37
The selected table and column names appear, along with the database name,
on the dividing line beneath the next menu, which is called the ACTION
Menu:
ACTION: Add Update Remove Next Query Table Column Exit
Add an entry to the data validation [or screen display attribute] table.
--------- db-name:tab-name:col-name ------------ Press CTRL-W for Help --------
Now upscol displays the first row of syscol that relates to tab-name and
col-name in the work area beneath this menu. If no such entries exist, a message stating this appears on the Error line.
The options in the ACTION Menu are
E-38
Add
Update
Remove
Next
Query
Restart the display at the first row of syscol for tab-name and
col-name.
Table
Column
Exit
Exit
The options are attribute names and their selection has the following effects:
Autonext
Produces a menu with three options, Yes, No, and Exit. Exit
returns you to the VALIDATE Menu. The default is No.
Comment
Default
Produces a prompt to enter the DEFAULT attribute, formatted as described in Chapter 4. Quotation marks are required
where necessary to avoid ambiguity.
Include
Produces a prompt to enter the INCLUDE attribute, formatted as described in Chapter 4. Quotation marks are required
where necessary to avoid ambiguity.
Picture
Shift
Verify
Produces a menu with three options, Yes, No, and Exit. Exit
returns you to the VALIDATE Menu. The default is No.
Exit
The upscol utility adds or modifies a row of syscolval after you complete
each of these options except Exit.
E-39
The Update option on the ACTION Menu takes you immediately to the
ATTRIBUTE Menu or prompt corresponding to the current attribute for the
current column. You can look at another attribute for the current column by
using the Next option, start through the list again by using the Query option,
remove the current attribute with the Remove option, and select a new column or table with the Column or Table options.
Left
Rev
Under
Where
Discrd_Exit
Exit_Set
If you are adding a new row to syscolatt, a default row is displayed in the
work area below the menu. If you are updating an existing row of syscolatt,
the current row appears. Since no entry is made in syscolatt until you select
Exit_Set, you can alter all the attributes before deciding to modify syscolatt
(Exit_Set) or to abort the changes (Discrd_Exit).
The options of the ATTRIBUTE Menu are screen attribute names, and their
selection has the following effects:
E-40
Blink
Produces a menu with three options, Yes, No, and Exit. The
default is No.
Color
Fmt
Prompts you for the format string to be used when tabname.col-name is displayed.
Left
Produces a menu with three options, Yes, No, and Exit. Yes
causes numeric data to be left justified within the screen
field. The default is No.
Rev
Produces a menu with three options, Yes, No, and Exit. Yes
causes the field to be displayed in reverse video. The default
is No.
Under
Produces a menu with three options, Yes, No, and Exit. Yes
causes the field to be displayed with underlining. The
default is No.
Where
Prompts for the values and value ranges under which these
attributes will apply. See Chapter 4 for allowable syntax.
Discrd_Exit
Exit_Set
After you complete each of these options except Discrd_Exit, upscol adds or
modifies a row of syscolatt.
Note: Whoever runs the upscol utility produces a pair of tables, syscolval and
syscolatt, that provide default values for all the users of a database that is not MODE
ANSI.
If the current database is MODE ANSI, however, the user who runs upscol becomes
the owner of the syscolatt and syscolval tables specified at the upscol menus, but
other users can produce their own user. syscolval and user.syscolatt tables. The
default specifications in an upscol table are applied by INFORMIX-4GL only to columns of database tables that have the same owner as the upscol table. (For details,
see the section The upscol Tables in a MODE ANSI Database in Chapter 4, and
the notes on the INITIALIZE and VALIDATE statements in Chapter 7.)
E-41
E-42
Appendix
DECIMAL
Functions for C
The data type DECIMAL is a machine-independent method
for the representation of numbers of up to thirty-two significant digits, with or without a decimal point, and exponents
in the range -128 to +126. INFORMIX-4GL provides routines
that facilitate the conversion of DECIMAL-type numbers to
and from every data type allowed in the C language.
DECIMAL-type numbers consist of an exponent and a mantissa (or fractional part) in base 100. In normalized form, the
first digit of the mantissa must be greater than zero.
DECIMAL-Type Routines
holds the exponent of the normalized DECIMAL-type number. This exponent represents a power of 100.
dec_pos
dec_ndgts
dec_dgts
DECIMAL-Type Routines
All operations on DECIMAL-type numbers should take place through the
routines provided in the INFORMIX-4GL library and described in the following pages. Any other operations, modifications, or analysis of DECIMAL-type
numbers can produce unpredictable results.
The following C function calls are available in INFORMIX-4GL to treat
DECIMAL-type numbers:
deccvasc( )
dectoasc( )
deccvint( )
dectoint( )
deccvlong( )
dectolong( )
deccvflt( )
dectoflt( )
deccvdbl( )
dectodbl( )
decadd( )
decsub( )
decmul( )
decdiv( )
deccmp( )
deccopy( )
dececvt( )
decfcvt( )
DECCVASC
DECCVASC
Overview
Use deccvasc to convert a value held as a printable character in a C char type
into a DECIMAL-type number.
Syntax
deccvasc(cp, len, np)
char *cp;
int len;
dec_t *np;
Explanation
cp
len
np
Notes
1. The deccvasc function ignores leading spaces in the character string.
2. The character string can have a leading plus (+) or minus (-) sign, a decimal point (.), and numbers to the right of the decimal point.
3. The character string can contain an exponent preceded by either e or E.
The exponent can be preceded by a plus or minus sign.
Return Codes
0
-1200
-1201
-1213
-1216
DECCVASC
Examples
#include <decimal.h>
char input[80];
dec_t number;
.
.
.
/* get input from terminal */
getline(input);
/* convert input into decimal number */
deccvasc(input, 32, &number);
DECTOASC
DECTOASC
Overview
Use dectoasc to convert a DECIMAL-type number to an ASCII string.
Syntax
dectoasc(np, cp, len, right)
dec_t *np;
char *cp;
int len;
int right;
Explanation
np
cp
len
right
Notes
1. If right equals -1, the number of decimal places is determined by the decimal value of *np.
2. If the number does not fit into a character string of length len, dectoasc
converts the number to exponential notation. If the number still does not
fit, dectoasc fills the string with asterisks. If the number is shorter than the
string, it is left-justified and padded on the right with blanks.
3. Because the ASCII string returned by dectoasc is not null-terminated,
your program must add a null character to the string before printing it.
Return Codes
0
-1
DECTOASC
Examples
#include <decimal.h>
char input[80];
char output[16];
dec_t number;
.
.
.
/* get input from terminal */
getline(input);
/* convert input into decimal number */
deccvasc(input, 32, &number);
/* convert number to ASCII string */
dectoasc(&number, output, 15, 1);
/* add null character to end of string prior to printing */
output[15] = \0;
/* print the value just entered */
printf("You just entered %s", output);
DECCVINT
DECCVINT
Overview
Use deccvint to convert a C type int into a DECIMAL-type number.
Syntax
deccvint(integer, np)
int integer;
dec_t *np;
Explanation
integer is the integer you want to convert.
np
Examples
#include <decimal.h>
dec_t decnum;
/* convert the integer value -999
* into a DECIMAL-type number
*/
deccvint(-999, &decnum);
DECTOINT
DECTOINT
Overview
Use dectoint to convert a DECIMAL-type number into a C type int.
Syntax
dectoint(np, ip)
dec_t *np;
int *ip;
Explanation
np
ip
Return Codes
0
-1200
Examples
#include <decimal.h>
dec_t mydecimal;
int myinteger;
/* convert the value in
* mydecimal into an integer
* and place the results in
* the variable myinteger.
*/
dectoint(&mydecimal, &myinteger);
DECCVLONG
DECCVLONG
Overview
Use deccvlong to convert a C type long value into a DECIMAL-type number.
Syntax
deccvlong(lng, np)
long lng;
dec_t *np;
Explanation
lng
np
Examples
#include <decimal.h>
dec_t mydecimal;
long mylong;
/* Set the decimal structure
* mydecimal to 37.
*/
deccvlong(37L, &mydecimal);
mylong = 123456L;
/* Convert the variable mylong into
* a DECIMAL-type number held in
* mydecimal.
*/
deccvlong(mylong, &mydecimal);
DECTOLONG
DECTOLONG
Overview
Use dectolong to convert a DECIMAL-type number into a C type long.
Syntax
dectolong(np, lngp)
dec_t *np;
long *lngp;
Explanation
np
lngp
Return Codes
0
-1200
Examples
#include <decimal.h>
dec_t mydecimal;
long mylong;
/* convert the DECIMAL-type value
* held in the decimal structure
* mydecimal to a long pointed to
* by mylong.
*/
dectolong(&mydecimal, &mylong);
DECCVFLT
DECCVFLT
Overview
Use deccvflt to convert a C type float into a DECIMAL-type number.
Syntax
deccvflt(flt, np)
float flt;
dec_t *np;
Explanation
flt
is a floating-point number.
np
Examples
#include <decimal.h>
dec_t mydecimal;
float myfloat;
/* Set the decimal structure
* myfloat to 3.14159.
*/
deccvflt(3.14159, &mydecimal);
myfloat = 123456.78;
/* Convert the variable myfloat into
* a DECIMAL-type number held in
* mydecimal.
*/
deccvflt(myfloat, &mydecimal);
F-11
DECTOFLT
DECTOFLT
Overview
Use dectoflt to convert a DECIMAL-type number into a C type float.
Syntax
dectoflt(np, fltp)
dec_t *np;
float *fltp;
Explanation
np
fltp
Notes
The resulting floating-point number has eight significant digits.
Examples
#include <decimal.h>
dec_t mydecimal;
float myfloat;
/* convert the DECIMAL-type value
* held in the decimal structure
* mydecimal to a floating point number pointed to
* by myfloat.
*/
dectoflt(&mydecimal, &myfloat);
DECCVDBL
DECCVDBL
Overview
Use deccvdbl to convert a C type double into a DECIMAL-type number.
Syntax
deccvdbl(dbl, np)
double dbl;
dec_t *np;
Explanation
dbl
np
Examples
#include <decimal.h>
dec_t mydecimal;
double mydouble;
/* Set the decimal structure
* mydecimal to 3.14159.
*/
deccvdbl(3.14159, &mydecimal);
mydouble = 123456.78;
/* Convert the variable mydouble into
* a DECIMAL-type number held in
* mydecimal.
*/
deccvdbl(mydouble, &mydecimal);
F-13
DECTODBL
DECTODBL
Overview
Use dectodbl to convert a DECIMAL-type number into a C type double.
Syntax
dectodbl(np, dblp)
dec_t *np;
double *dblp;
Explanation
np
dblp
Notes
The resulting double-precision number receives a total of 16 significant
digits.
Examples
#include <decimal.h>
dec_t mydecimal;
double mydouble;
/* convert the DECIMAL-type value
* held in the decimal structure
* mydecimal to a double pointed to
* by mydouble.
*/
dectodbl(&mydecimal, &mydouble);
Syntax
decadd(n1, n2, result)
dec_t *n1;
dec_t *n2;
dec_t *result;
/* result = n1 + n2 */
/* result = n1 - n2 */
/* result = n1 * n2 */
/* result = n1 / n2 */
Explanation
n1
n2
result
Notes
The result can use the same pointer as either n1 or n2.
F-15
Return Codes
0
-1200
-1201
-1202
DECCMP
DECCMP
Overview
Use deccmp to compare two DECIMAL-type numbers.
Syntax
int deccmp(n1, n2)
dec_t *n1;
dec_t *n2;
Explanation
n1
n2
Return Codes
0
-1
+1
F-17
DECCOPY
DECCOPY
Overview
Use deccopy to copy one dec_t structure to another.
Syntax
deccopy(n1, n2)
dec_t *n1;
dec_t *n2;
Explanation
n1
n2
Syntax
char *dececvt(np, ndigit, decpt, sign)
dec_t *np;
int ndigit;
int *decpt;
int *sign;
char *decfcvt(np, ndigit, decpt, sign)
dec_t *np;
int ndigit;
int *decpt;
int *sign;
Explanation
np
ndigit
is, for dececvt, the length of the ASCII string; for decfcvt, it is the
number of digits to the right of the decimal point.
decpt
sign
is a pointer to the sign of the result. If the sign of the result is negative,
*sign is nonzero; otherwise, the value is zero.
Notes
1. The dececvt function converts the decimal value pointed to by np into a
null-terminated string of ndigit ASCII digits, and returns a pointer to the
string.
2. The low-order digit of the DECIMAL number is rounded.
3. The decfcvt function is identical to dececvt, except that ndigit specifies the
number of digits to the right of the decimal point instead of the total number of digits.
DECIMAL Functions for C
F-19
Examples
In the following example, np points to a dec_t structure containing 12345.67
and *decpt points to an integer containing a 5:
ptr
ptr
ptr
ptr
=
=
=
=
dececvt
dececvt
decfcvt
decfcvt
(np,4,&decpt,&sign);
(np,10,&decpt,&sign);
(np,1,&decpt,&sign);
(np,3,&decpt,&sign);
=
=
=
=
1235
1234567000
123457
12345670
=
=
=
=
dececvt
dececvt
decfcvt
decfcvt
(np,4,&decpt,&sign);
(np,10,&decpt,&sign);
(np,1,&decpt,&sign);
(np,3,&decpt,&sign);
= 1234
= 1234000000
=
= 1
Appendix
Outer Joins
This appendix discusses the difference between a simple
join and an outer join, and describes in detail how outer
joins work. The following SELECT statements illustrate the
basic difference between the two types of join.
SELECT customer.customer_num, lname, order_num
FROM customer, orders
WHERE customer.customer_num = orders.customer_num
Figure G-1
Figure G-2
customer_num
104
101
104
106
116
112
117
110
111
115
104
117
104
106
110
Figure G-3
lname
Higgins
Pauli
Higgins
Watson
Parmelee
Lawson
Sipes
Jaeger
Keyes
Grant
Higgins
Sipes
Higgins
Watson
Jaeger
Query 1 Results
order_num
customer_num
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
101
102
103
104
104
104
104
105
106
106
107
108
109
110
110
111
112
113
114
115
116
117
117
118
lname
order_num
Pauli
Sadler
Currie
Higgins
Higgins
Higgins
Higgins
Vector
Watson
Watson
Ream
Quinn
Miller
Jaeger
Jaeger
Keyes
Lawson
Beatty
Albertson
Grant
Parmelee
Sipes
Sipes
Baxter
1002
1001
1003
1011
1013
1004
1014
1008
1015
1009
1006
1010
1005
1007
1012
Query 2 Results
By using a simple join, Query 1 fetches a list of only those customers who have
items on order, while Query 2 fetches a list of all customers by using an outer
join. Once you understand how similar queries can produce such dissimilar
results, you can begin to use outer joins effectively. The obvious differences
between the two kinds of joins are as follows:
A simple join discards all rows that do not satisfy the join condition.
An outer join preserves rows that would otherwise be discarded.
The following section discusses outer joins in detail.
G-2
Outer Joins
Consider two hypothetical tables, employees and depts, which contain the
following columns and rows (dash indicates a NULL value):
employees
emp_num
2
4
6
5
3
depts
dept_num
105
103
103
102
dept_num
102
103
105
dept_loc
NY
LA
SF
Suppose, for example, that you need a list of employee numbers and department locations for all employees, including those employees whose department locations are unknown (represented by NULL values in the employees
table). The following query fetches the desired results:
SELECT emp_num, dept_loc
FROM employees, OUTER depts
WHERE employees.dept_num = depts.dept_num
dept_num
105
102
103
103
dept_num
105
102
103
103
dept_loc
SF
NY
LA
LA
Note: A filter is a condition expressed in a WHERE clause that applies to columns in a single table. For example,
"dept_loc = SF"
or
Because 4GL applies such filters to the subservient table as it performs the join,
the resulting table may contain NULL values that were not present in the subservient table prior to the join.
Outer Joins G-3
At Step 2, the results include more rows of NULL values than the results of the
original query:
emp_num
2
3
4
5
6
dept_num
105
102
dept_num
105
102
dept_loc
SF
NY
The filter removes rows from the depts table where dept_loc is equal to LA.
2. After performing the join, 4GL applies filters to the dominant table (if they
exist).
3. 4GL applies the SELECT clause to eliminate unneeded columns, and the
query returns the results.
emp_num
2
3
4
5
6
dept_loc
SF
NY
LA
LA
G-4
Outer Joins
customer.customer_num, 4GL combines a row of NULL values with the corresponding row from the customer table. Because the query does not contain
filters, the results preserve every row from the dominant table.
Figure G-4
Figure G-5
order_num ship_date
1002 06/06/1984
1001
1003
1011
1013
06/05/1984
06/07/1984
06/07/1984
06/11/1984
1004
1014 06/09/1984
1008 06/27/1984
1015 06/11/1984
1009 06/15/1984
1006
1010
1005
1007
1012
06/07/1984
06/08/1984
06/08/1984
06/09/1984
Query 3 Results
The preceding example queries two tables in the simplest type of outer join.
You can, in fact, use outer joins to query any number of tables, producing
more types of joins than can be discussed here. The following types are possible when three tables are involved in a query:
Query 4 performs this kind of join. (See the section Examples later in
this chapter.)
Examples
or
SELECT column-list
FROM x, OUTER (y, OUTER z)
WHERE x.a = z.a AND y.b = z.b
Queries 5 and 6 perform this kind of join. (See the following Examples
section.)
You can outer-join two tables individually to a third table, in which case,
join relationships are possible only between the subservient tables and
the dominant table. Query 7 performs this kind of join. (See the following
Examples section.)
SELECT column-list
FROM x, OUTER y, OUTER z
WHERE x.a = y.a AND x.b = z.b
When you outer-join several tables to another table, make sure that your
WHERE clause does not specify impossible join conditions. The following
query attempts a join between two subservient tables:
SELECT column-list
FROM x, OUTER y, OUTER z
WHERE x.a = y.a AND y.b = z.b
Examples
This query outer-joins the result of a simple join to a third table. It produces
a list of all customers with supplemental information (order number, stock
number, manufacturer code, and quantity ordered) for those customers who
have ordered items manufactured by Anza.
Figure G-6
G-6
Outer Joins
Examples
4GL performs the simple join between orders and items first, yielding information on all orders for Anza-manufactured items. The outer join combines
the customer table with the Anza order information. The query results do not
include orders for other items.
customer_num lname
101
102
103
104
104
104
104
104
104
104
105
106
107
108
109
110
110
111
112
112
113
114
115
116
116
117
117
118
Figure G-7
Pauli
Sadler
Currie
Higgins
Higgins
Higgins
Higgins
Higgins
Higgins
Higgins
Vector
Watson
Ream
Quinn
Miller
Jaeger
Jaeger
Keyes
Lawson
Lawson
Beatty
Albertson
Grant
Parmelee
Parmelee
Sipes
Sipes
Baxter
order_num
stock_num
manu_code
quantity
1003
1003
1003
1011
1013
1013
1013
9
8
5
5
5
6
9
ANZ
ANZ
ANZ
ANZ
ANZ
ANZ
ANZ
1
1
5
5
1
1
2
1008
1008
8
9
ANZ
ANZ
1
5
1006
1006
5
6
ANZ
ANZ
5
1
1010
1005
1005
1012
1012
6
5
6
8
9
ANZ
ANZ
ANZ
ANZ
ANZ
1
10
1
1
10
Query 4 Results
Query 5
This query outer-joins the result of an outer join to a third table. When you
use a nested outer join, the query preserves order numbers that Query 4
(using a nested simple join) eliminates. The query results include all orders,
whether or not they contain Anza-manufactured items. For other items, the
condition
where manu_code = "ANZ"
Examples
Figure G-8
Pauli
Sadler
Currie
Higgins
Higgins
Higgins
Higgins
Higgins
Higgins
Higgins
Higgins
Vector
Watson
Watson
Ream
Quinn
Miller
Jaeger
Jaeger
Jaeger
Keyes
Lawson
Lawson
Beatty
Albertson
Grant
Parmelee
Parmelee
Sipes
Sipes
Sipes
Baxter
order_num
stock_num
manu_code
quantity
9
8
5
5
5
6
9
ANZ
ANZ
ANZ
ANZ
ANZ
ANZ
ANZ
1
1
5
5
1
1
2
1008
1008
1015
1009
1006
1006
8
9
ANZ
ANZ
1
5
5
6
ANZ
ANZ
5
1
1010
1005
1005
1007
1012
1012
6
5
6
ANZ
ANZ
ANZ
1
10
1
8
9
ANZ
ANZ
1
10
1002
1001
1003
1003
1003
1011
1013
1013
1013
1004
1014
Query 5 Results
G-8
Outer Joins
notes
sponsors soccer team
customer for 20 years
opening a second store
new customer
Examples
Query 6
This query produces a list of all customers with order numbers and selected
notes.
SELECT customer.customer_num, orders.order_num, notes
FROM customer, OUTER (orders, OUTER custnotes)
WHERE customer.customer_num = orders.customer_num AND
orders.customer_num = custnotes.customer_num
The outer join between custnotes and orders preserves notes only for customers who also have orders.
customer_num
101
102
103
104
104
104
104
105
106
106
107
108
109
110
110
111
112
113
114
115
116
117
117
118
Figure G-9
order_num
notes
1002
1001
1003
1011
1013
sponsors
sponsors
sponsors
sponsors
soccer
soccer
soccer
soccer
team
team
team
team
1004
1014
1008
1015
1009
1006
1010
1005
1007
1012
Query 6 Results
To preserve notes for customers 108 and 118 who do not have orders, you
must outer-join the custnotes table directly with the customer table, as shown
in the next query.
Query 7
This query outer-joins two tables individually to a third table. It outer-joins
both orders and custnotes to customer (the dominant table).
SELECT customer.customer_num, orders.order_num, notes
FROM customer, OUTER orders, OUTER custnotes
WHERE customer.customer_num = orders.customer_num AND
customer.customer_num = custnotes.customer_num
Examples
Figure G-10
customer_num
order_num
101
102
103
104
104
104
104
105
106
106
107
108
109
110
110
111
112
113
114
115
116
117
117
118
1002
1001
1003
1011
1013
notes
sponsors
sponsors
sponsors
sponsors
soccer
soccer
soccer
soccer
team
team
team
team
1004
1014
customer for 20 years
1008
1015
1009
1006
1010
1005
1007
1012
new customer
Query 7 Results
All of the preceding queries fetch information from one table with supplemental information from other tables. When you need similar results, Informix recommends that you use an outer join. When you do not need
supplemental information, as is normally the case, use a simple join instead.
Be aware that your choice of an outer join can influence query optimization
and processing. You can use the SET EXPLAIN ON statement to examine how
the query processor of INFORMIX-4GL performs simple queries, joins, and
outer joins.
G-10
Outer Joins
Appendix
Num
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
Char
^@
^A
^B
^C
^D
^E
^F
^G
^H
^I
^J
^K
^L
^M
^N
^O
^P
^Q
^R
^S
^T
^U
^V
^W
^X
^Y
^Z
esc
^\
^]
^^
^_
!
"
#
$
%
&
(
)
*
^x = CONTROL-X
H-2
Num
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
75
76
77
78
79
80
81
82
83
84
85
Char
+
,
.
/
0
1
2
3
4
5
6
7
8
9
:
;
<
=
>
?
@
A
B
C
D
E
F
G
H
I
J
K
L
M
N
O
P
Q
R
S
T
U
Num
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
Char
V
W
X
Y
Z
[
\
]
^
_
`
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
{
|
}
~
del
Appendix
Modifying termcap
and terminfo
INFORMIX-4GL programs can use function keys and can
display color or intensity attributes in screen displays.
These and other keyboard and screen options are terminal
dependent. To determine terminal-dependent characteristics, INFORMIX-4GL uses the information in the termcap
file or in the terminfo directory. INFORMIX-4GL uses the
INFORMIXTERM environment variable to determine
whether to use termcap or terminfo. For more information
about INFORMIXTERM, read the discussion of environment
variables in the Environment Variables appendix or in
the Preface to the INFORMIX-4GL User Guide .
termcap
termcap
When INFORMIX-4GL is installed on your system, a termcap file is placed in
the etc subdirectory of $INFORMIXDIR. This file is a superset of an operating
system termcap file. The Informix termcap file contains additional capabilities for many terminals. You may want to modify this file further in the following instances:
The entry for your terminal has not been modified to include colorchange and intensity-change capabilities.
Boolean capabilities
Numeric capabilities
String capabilities
All termcap entries have the following format:
I-2
Figure I-1 shows a basic termcap entry for the Wyse 50 terminal:
# Entry for Wyse 50:
Figure I-1
w5|wy50|wyse50:
:if=/usr/lib/tabset/std:\
:al=\EE:am:bs:ce=\Et:cm=\E=%+ %+ :cl=\E*:co#80:\
:dc=\EW:dl=\ER:ho=^^:ei=:kh=^^:im=:ic=\EQ:in:li#24:\
:nd=^L:pt:se=\EG0:so=\EG4:sg#1:ug#1:\
:up=^K:ku=^K:kd=^J:kl=^H:kr=^L:kb=:\
:k0=^A@^M:k1=^AA^M:k2=^AB^M:k3=^AC^M:k4=^AD^M:\
:k5=^AE^M:k6=^AF^M:k7=^AG^M:\
:HI=^|:Po=^R:Pe=^T:
Wyse 50 termcap Entry
Terminal Names
A termcap entry starts with one or more names for the terminal, each separated by a vertical ( | ) bar. For example, the termcap entry for the Wyse 50
terminal starts with the following line:
w5|wy50|wyse50:\
The termcap entry can be accessed using any one of these names.
Boolean Capabilities
A Boolean capability is a two-character code that indicates whether or not a
terminal has a specific feature. If the Boolean capability is present in the termcap entry, the terminal has that particular feature. Figure I-2 shows some of
the Boolean capabilities for the Wyse 50 terminal:
:bs:am:
Figure I-2
#
bs
backspace with CTRL-H
#
am
automatic margins
Boolean Capabilities for the Wyse 50
I-3
Numeric Capabilities
A numeric capability is a two-character code followed by a pound symbol
( # ) and a value. Figure I-3 shows the numeric capabilities for the number of
columns and the number of lines on a Wyse 50 terminal:
:co#80:li#24:
Figure I-3
#
co
number of columns in a line
#
li
number of lines on the screen
Numeric Capabilities for the Wyse 50
String Capabilities
A string capability specifies a sequence that can be used to perform a terminal
operation. A string capability is a two-character code followed by an equal
sign ( = ) and a string ending at the next delimiter ( : ).
Most termcap entries include string capabilities for clearing the screen, cursor movement, Arrow keys, underscore, function keys, and so on. Figure I-4
shows many of the string capabilities for the Wyse 50 terminal:
:ce=\Et:cl=\E*:\
:nd=^L:up=^K:\
:so=\EG4:se=\EG0:\
:ku=^K:kd=^J:kr=^L:kl=^H:\
:k0=^A@^M:k1=^AA^M:k2=^AB^M:k3=^AC^M:
#
#
#
#
#
#
#
#
I-4
ce=\Et
cl=\E*
nd=^L
up=^K
so=\EG4
se=\EG0
start stand-out
end stand-out
Figure I-4
#
ku=^K
up arrow key
#
kd=^J
down arrow key
#
kr=^L
right arrow key
#
kl=^H
left arrow key
#
#
k0=^A@^M
function key F1
#
k1=^AA^M
function key F2
#
k2=^AB^M
function key F3
#
k3=^AC^M
function key F4
String Capabilities for the Wyse 50
Figure I-5
Function Key
termcap Entry
F1
k0=^A@^M
F2
k1=^AA^M
F3
k2=^AB^M
F4
k3=^AC^M
F5
k4=^AD^M
F6
k5=^AE^M
F7
k6=^AF^M
F8
k7=^AG^M
Function Key Entries for the Wyse 50
You can also define keys that correspond to the following capabilities:
If these keys are defined in your termcap file, INFORMIX-4GL uses them.
Otherwise, INFORMIX-4GL uses CTRL-J, CTRL-K, CTRL-M, and CTRL-N,
respectively.
Note: You can also use the OPTIONS statement to name other function keys or
CTRL keys for these operations.
I-5
Figure I-6
Window Border
Graphics
ASCII
Position
Character
Equivalent
upper left corner
2
lower left corner
1
upper right corner
3
lower right corner
5
horizontal
z
vertical
|
6
Wyse 50 ASCII Equivalents for Border Graphics Characters
Again, this information should be located in the manual that comes with
your terminal.
3. Edit the termcap entry for your terminal.
I-6
Note: You may want to make a copy of your termcap file before you edit it. You
can use the TERMCAP environment variable to point to whichever copy of the
termcap file you want to access.
Use the format
termcap-capability=value
to enter values for the following termcap capabilities:
gs
ge
The escape sequence for leaving graphics mode. For example, the
Wyse 50 escape sequence ESC-H CTRL-C is represented as \EH^C.
gb
#
#
#
#
#
#
#
I-7
You should understand these topics before you modify your terminal entry.
I-8
Figure I-7
Number
Color Terminal
0
WHITE
1
YELLOW
2
MAGENTA
3
RED
4
CYAN
5
GREEN
6
BLUE
7
BLACK
Color-Monochrome Correspondence
Monochrome Terminal
NORMAL
BOLD
BOLD
BOLD
DIM
DIM
DIM
INVISIBLE
The background for colors is BLACK in all cases. In the Figure I-7, the signifies that, if the keyword BOLD is indicated as the attribute, the field will be
RED on a color terminal, or if the keyword DIM is indicated as the attribute,
the field will be BLUE on a color terminal.
You can change the color names from the default list by associating different
numbers with different color names in a file named colornames in your current directory or in the /incl subdirectory of $INFORMIXDIR. (See the section
The colornames File later in this appendix.)
In either color or monochrome mode, you can add the REVERSE, BLINK, or
UNDERLINE attributes if your terminal supports them. You can select only
one of these three attributes.
ZA uses the values of these four parameters and a stack machine to determine which characters to send to the terminal. The ZA function is called and
these parameters are evaluated when a color or intensity attribute is encountered in a 4GL program. You can use the information in your terminal manual
to set the ZA parameters to the correct values for your terminal.
To define the ZA string for your terminal, you use stack operators to push and
pop values onto and off the stack. The next section describes several stack
operators. Use these descriptions and the subsequent examples to understand how to define the string for your terminal.
Modifying termcap and terminfo
I-9
Stack Operations
The ZA string uses stack operations to either push values onto the stack or
pop values off the stack. Typically, the instructions in the ZA string push a
parameter onto the stack, compare it to one or more constants, and then send
an appropriate sequence of characters to the terminal. More complex operations are often necessary and, by storing the display attributes in static stack
machine registers (named a through z), you can achieve terminal-specific
optimizations.
A summary follows of the different stack operators you can use to write the
descriptions. For a complete discussion of stack operators, consult your operating system documentation.
%2d
pops a numeric value from the stack and sends a maximum of two
digits to the terminal, padding to two places. For example, if the
value 145 is at the top of the stack, %2d pops the value off the
stack and sends the ASCII representations of 4 and 5 to the terminal. If the value 5 is at the top of the stack, %2d pops the value off
the stack and sends the ASCII representations of 0 and 5 to the
terminal.
%3d
%c
pops a single character from the stack and sends it to the terminal.
the value 45 is on the top of the stack, %Pb pops 45 from the
stack and stores it in the variable Pb.
%g[a-z] gets the value stored in the corresponding variable (P[a-z]) and
pushes it on the stack. For example, if the value 45 is stored in
the variable Pb, %gb gets 45 from Pb and pushes it on the stack.
%c
%{n}
%S[a-z] pops a value from the stack and stores it in the specified static
variable. (Static storage is nonvolatile since the stored value
remains from one attribute evaluation to the next.) The notation
for static variables is Sa, Sb, ... Sz. For example, if the value 45 is
on the top of the stack, %Sb pops 45 from the stack and stores it
in the static variable Sb. This value is accessible for the duration
of the INFORMIX-4GL program.
%G[a-z] gets the value stored in the corresponding static variable (S[a-z])
and pushes it on the stack. For example, if the value 45 is stored
in the variable Sb, %Gb gets 45 from Sb and pushes it on the
stack.
Arithmetic Operators
Each arithmetic operator pops the top two values from the stack, performs an
operation, and pushes the result on the stack.
%+
%-
%*
%/
%m
Bit Operators
The following bit operators pop the top two values from the stack, perform
an operation, and push the result on the stack:
%&
Decimal
12
21
------------------------0
%|
and
=
Decimal
12
21
------------------------1
%^
or
=
29
Decimal
12
21
------------------------1
exclusive or
=
25
The following unary operator pops the top value from the stack, performs an
operation, and pushes the result on the stack:
I-12
%~
Decimal
0
---------------------------1
25
Complement
-26
Logical Operators
The following logical operators pop the top two values from the stack, perform an operation, and push the logical result (either 0 for false or 1 for true)
on the stack:
%=
Equal to. For example, if the parameter p1 has the value 3, the
expression %p1%{2}%= is equivalent to 3=2 and produces a result
of 0 (false).
%>
Greater than. For example, if the parameter p1 has the value 3, the
expression %p1%{0}%> is equivalent to 3>0 and produces a result
of 1 (true).
%<
Less than. For example, if the parameter p1 has the value 3, the
expression %p1%{4}%< is equivalent to 3<4 and produces a result
of 1 (true).
The following unary operator pops the top value from the stack, performs an
operation, and pushes the logical result (either 0 or 1) on the stack.
%!
Conditional Statements
The condition statement IF-THEN-ELSE has the following format:
%? expr %t thenpart %e elsepart %;
The %e elsepart is optional. You can nest conditional statements in the thenpart
or the elsepart.
When INFORMIX-4GL evaluates a conditional statement, it pops the top
value from the stack and evaluates it as either true or false. If the value is
true, INFORMIX-4GL performs the operations after the %t; otherwise it performs the operations after the %e (if any).
Modifying termcap and terminfo
I-13
is equivalent to
if p1 = 3 then print ";31"
%t pops the value from the stack, evaluates 1 as true, and executes the
operations after %t. (Since ;31 is not a stack machine operation, INFORMIX-4GL prints ;31 to the terminal.)
I-14
Summary of Operators
Figure I-8 summarizes the allowed operations:
Figure I-8
Operation
%d
%2d
%3d
%c
Description
write pop() in decimal format
write pop() in 2-place decimal format
write pop() in 3-place decimal format
write pop() as a single character
%p[1-9]
%P[a-z]
%g[a-z]
%c
%{n}
%S[a-z]
%G[a-z]
%+
%%*
%/
%m
%&
%|
%^
%~
%=
%>
%<
%!
%?
I-15
Examples
To illustrate, consider the monochrome Wyse terminal. Figure I-9 shows the
escape sequences for various display characteristics.
Figure I-9
ESC G 0
ESC G 1
ESC G 2
Normal
blank(invisible)
blink
ESC G 4
ESC G 5
ESC G 6
Reverse
Reverse and blank
Reverse and blink
ESC G 8
ESC G 9
ESC G :
Underscore
Underscore and blank
Underscore and blink
ESC G <
ESC G =
ESC G >
Wyse Escape Sequences
The characters after G form an ASCII sequence from the character 0 (zero)
through ?. You can generate the character by starting with 0 and adding 1 for
blank, 2 for blink, 4 for reverse, and 8 for underline.
You can construct the termcap entry in stages, as outlined in the following
display. %pi refers to pushing the ith parameter on the stack. The designation
for ESCAPE is \E. The termcap entry for the Wyse terminal must contain the
following ZA entry in order for INFORMIX-4GL monochrome attributes such
as REVERSE and BOLD to work correctly:
ZA =
EG
%0
%?%p1%{7}%=%t%{1}%|
%e%p1%{3}%>
%p1%{7}%<%&%t%{64}%|
%;%;
%?%p2%t%{4}%|%;
%?%p3%t%{2}%|%;
%?%p4%t%{8}%|%;
%c:
I-16
#print EG
#push 0 (normal) on the stack
#if p1 = 7 (invisible), set
#the 1 bit (blank);
#if p1 > 3 and < 7, set the 64 flag (dim);
#
#
#if p2 is set, set the 4 bit (reverse)
#if p3 is set, set the 2 bit (blink)
#if p4 is set, set the 8 bit (underline)
#print whatever character
#is on top of the stack
You then concatenate these lines as a single string that ends with a colon and
has no embedded NEWLINEs. The actual ZA entry for the Wyse 50 terminal
follows:
ZA = \EG%0%?%p1%{7}%=%t%{1}%|%e%p1%{3}%>%p1%{7}%<%&%t%{64}
%|%;%;%?%p2%t%{4}%|%;%?%p3%t%{2}%|%;%?%p4%t%{8}%|%;%c:
The next example is for the ID Systems Corporation ID231, a color terminal.
On this terminal, to set color and other characteristics you must enclose a
character sequence between a lead-in sequence (ESC [ 0) and a terminating
character (m). The first in the sequence is a two-digit number that determines
whether the assigned color is in the background (30) or in the foreground
(40). The next is another two-digit number that is the other of 30 or 40, incremented by the color number. These characters are followed by 5 if there is
blinking, and by 4 for underlining.
The code in Figure I-10 sets up the entire escape sequence:
ZA =
\E[0;
%?%p1%{0}%=%t%{7}
%e%p1%{1}%=%t%{3}
%e%p1%{2}%=%t%{5}
%e%p1%{3}%=%t%{1}
%e%p1%{4}%=%t%{6}
%e%p1%{5}%=%t%{2}
%e%p1%{6}%=%t%{4}
%e%p1%{7}%=%t%{0}%;
%?%p2%t30;%{40}%+%2d
%e40;%{30}%+%2d%;
%?%p3%t;5%;
%?%p4%t;4%;
m
Figure I-10
#print lead-in
#encode color number (translate
#
from Figure I-7 to the number
#
for the ID231)
#
#
#
#
#
#if p2 is set, print 30 and
# 40 + color number (reverse)
# else print 40 and
# 30 + color number (normal)
#if p3 is set, print 5 (blink)
#if p4 is set, print 4 (underline)
#print m to end character
# sequence
Figure I-11
ZA =\E[0;%?%p1%{0}%=%t%{7}%e%p1%{1}%=%t%{3}%e%p1%{2}%=
%t%{5}%e%p1%{3}%=%t%{1}%e%p1%{4}%=%t%{6}%e%p1%{5}%=%t%
{2}%e%p1%{6}%=%t%{4}%e%p1%{7}%=%t%{0}%;%?%p2%t30;%{40}
%+%2d%e40;%{30}%+%2d%;%?%p3%t;5%;%?%p4%t;4%;m
Concatenated ZA String for ID231
I-17
number
...
Explanation
name
number
is an integer from 0 to 7.
Notes
1. Each color name and number must be on a separate line. They should be
separated by one or more spaces or tabs.
2. name cannot be a reserved word and must be unique in the colornames
file. You cannot assign the same name to more than one number.
3. Unless you redefine them in the colornames file to have a different number, the default color-name keywords that are listed in the Color and
Intensity section of this appendix (and in the next example) retain their
meaning, even when you assign another name to that color number.
Examples
If you created a colornames file to set up the default assignment of names to
color numbers, colornames would look as follows:
WHITE
YELLOW
MAGENTA
RED
CYAN
I-18
0
1
2
3
4
GREEN
BLUE
BLACK
5
6
7
4
2
You could use either CYAN or AQUA in your INFORMIX-4GL program and
get the same color. Similarly, use of MAGENTA or ORANGE produces the
same color.
If you want to change the meaning of the default color names, you can reassign them in colornames:
RED
In this case when you use RED in a program, the color you get is the same
as has been assigned to MAGENTA. If you have not assigned a name to number 3, you are not able to get the color that RED originally represented.
The syscolatt table and the ATTRIBUTE clauses of various 4GL statements can
recognize numeric color codes and non-default names for colors. You can
specify these names or numbers in place of the color keywords that are documented in Chapter 7 and in the description of the upscol utility in
Appendix E.
Note: You cannot, however, specify numeric codes or non-default names from
colornames in the ATTRIBUTES section of a screen form.
I-19
terminfo
terminfo
If you have set the INFORMIXTERM environment variable to terminfo,
INFORMIX-4GL uses the terminfo directory indicated by the TERMINFO
environment variable (or /usr/lib/terminfo if TERMINFO is not set). INFORMIX-4GL uses the information in terminfo to draw window borders, define
function keys, and display certain intensity attributes.
You may want to modify a file in the terminfo directory in the following
instances:
I-20
A terminfo entry contains a list of names for the terminal, followed by a list
of the terminals capabilities. There are three types of capabilities:
Boolean capabilities
Numeric capabilities
String capabilities
All terminfo entries have the following format:
Figure I-12
w5|wy50|wyse50,
am, cols#80, lines#24, cuul=^K, clear=^Z,
home=^^, cuf1=^L, cup=\E=%p1%\s%+%c%p2%\s%+%c,
bw, ul, bel=^G, cr=\r, cud1=\n, cub1=\b, kpb=\b, kcudl=\n,
kdub1=\b, nel=\r\n, ind=\n,
xmc#1, cbt=\EI,
Wyse 50 terminfo Entry
Terminal Names
A terminfo entry starts with one or more names for the terminal (each separated by a vertical bar ( | )). For example, the terminfo entry for the Wyse 50
terminal starts with the following line:
w5|wy50|wyse50,
The terminfo entry can be accessed using any one of these names.
Boolean Capabilities
A Boolean capability is a two- to five-character code that indicates whether
or not a terminal has a specific feature. If the Boolean capability is present in
the terminfo entry, the terminal has that particular feature.
I-21
Figure I-13 shows some of the Boolean capabilities for the Wyse 50:
bw,am,
Figure I-13
.
bw
backward wrap
.
am
automatic margins
Boolean Capabilities for the Wyse 50
Numeric Capabilities
A numeric capability is a two- to five-character code followed by a pound
symbol ( # ) and a value. Figure I-14 shows the numeric capabilities for the
number of columns and the number of lines on a Wyse 50 terminal:
cols#80,lines#24,
Figure I-14
.
cols
number of columns in a line
.
lines
number of lines on the screen
Numeric Capabilities for the Wyse 50
String Capabilities
A string capability specifies a sequence that can be used to perform a terminal
operation. A string capability is a two- to five-character code followed by an
equal sign ( = ) and a string ending at the next delimiter ( , ).
Most terminfo entries include string capabilities for clearing the screen, cursor movement, arrow keys, underscore, function keys, and so on. Figure I-15
shows many of the string capabilities for the Wyse 50 terminal:
el=\ET,clear=E*,
cuf1=^L,cuu1=^K,
smso=\EG4,rmso=\EG0,
kcuu1=^K,kcud1=^J,kcuf1=^L,kcub1=^H,
kf0=^A@^M,kf1=^AA^M,kf2=^AB^M,kf3=^AC^M,
.
.
.
.
.
.
.
.
I-22
el=\Et
clear=\E*
cufl=^L
cuul=^K
smso=\EG4
rmso=\EG0
start stand-out
end stand-out
Figure I-15
.
kcuul=^K
up arrow key
.
kcudl=^J
down arrow key
.
kcufl=^L
right arrow key
.
kcubl=^H
left arrow key
.
.
kf0=^A@^M
function key F1
.
kf1=^AA^M
function key F2
.
kf2=^AB^M
function key F3
.
kf3=^AC^M
function key F4
String Capabilities for the Wyse 50
Figure I-16
Function Key
terminfo Entry
F1
kf0=^A@^M
F2
kf1=^AA^M
F3
kf2=^AB^M
F4
kf3=^AC^M
F5
kf4=^AD^M
F6
kf5=^AE^M
F7
kf6=^AF^M
F8
kf7=^AG^M
Function Key Entries for the Wyse 50
You can also define keys that correspond to the following capabilities:
If these keys are defined in your terminfo file, INFORMIX-4GL uses them.
Otherwise, INFORMIX-4GL uses CTRL-J, CTRL-K, CTRL-M, and CTRL-N,
respectively.
Note: You can also use the OPTIONS statement to name other function keys or
CTRL keys for these operations.
I-23
the hyphen ( - ) for horizontal lines, the vertical bar ( | ) for vertical lines, and
the plus sign ( + ) for corners.
You can look at the terminfo source file (using infocmp) to see if the entry for
your terminal includes these definitions. (Look for the acsc capability,
described later in this section.) If the file for your terminal does not contain
border character definitions, or if you want to specify alternative border characters, you or your system administrator can modify the terminfo source file.
You can refer to your operating system documentation for a complete
description of how to decompile terminfo entries using the infocmp
program.
Perform the following steps to specify border characters in the terminfo
source file for your terminal:
1. Determine the escape sequences for turning graphics mode on and off.
This information is located in the manual that comes with your terminal.
For example, on Wyse 50 terminals, the escape sequence for entering
graphics mode is ESC H^B and the escape sequence for leaving graphics
mode is ESC H^C.
Note: Terminals without a graphics mode do not have this escape sequence. The
procedure for specifying alternative border characters on a non-graphics terminal
is discussed at the end of this section.
2. Identify the ASCII equivalents for the six graphics characters that INFORMIX-4GL requires to draw the border. (The ASCII equivalent of a graphics
character is the key you would press in graphics mode to obtain the indicated character.)
Figure I-17 shows the graphics characters and the ASCII equivalents for a
Wyse 50 terminal.
I-24
Figure I-17
Windown Border
Graphics
ASCII
Position
Character
Equivalent
2
upper left corner
lower left corner
1
upper right corner
3
lower right corner
5
horizontal
z
vertical
|
6
Wyse 50 ASCII Equivalents for Border Graphics Characters
Again, this information should be located in the manual that comes with
your terminal.
3. Edit the terminfo source file for your terminal. (You can decompile it
using infocmp redirected to a file.)
Note: You may want to make a copy of your terminfo directory before you edit
files. You can use the TERMINFO environment variable to point to whichever
copy of the terminfo directory you want to access.
Use the format
terminfo-capability=value
to enter values for the following terminfo capabilities:
smacs The escape sequence for entering graphics mode. In a terminfo
file, ESCAPE is represented as a backslash ( \ ) followed by the letter E; CTRL is represented as a caret ( ^ ). For example, the Wyse
50 escape sequence ESC-H CTRL-B is represented as \EH^B.
rmacs The escape sequence for leaving graphics mode. For example, the
Wyse 50 escape sequence ESC-H CTRL-C is represented as \EH^C.
acsc
I-25
Figure I-18
System Default
Position
Character
upper left corner
l
lower left corner
m
upper right corner
k
lower right corner
j
horizontal lines
q
vertical lines
x
System Default Characters for Border Positions
acsc=l2m1k3j5qzx6
Wyse 50 acsc setting
4. Use tic to recompile the modified terminfo file. See your operating system documentation for a description of the tic program.
The following example shows the full setting for specifying alternative
border characters on the Wyse 50:
smacs=\EH^B,
rmacs=\EH^C,
acsc=l2m1k3j5qzx6,
.
.
.
.
.
.
.
I-26
The following example shows possible values for smacs, rmacs, and acsc in
an entry for a terminal without graphics capabilities. In this example, window borders would be drawn using underscores ( _ ) for horizontal lines, vertical bars ( | ) for vertical lines, periods ( . ) for the top corners, and vertical
bars ( | ) for the lower corners.
smacs=,rmacs=,acsc=l.m|k.j|q_x|,
INFORMIX-4GL uses the graphics characters in the terminfo file when you
specify a window border in an OPEN WINDOW statement.
If you specify these attributes in your INFORMIX-4GL code, they are ignored.
If the terminfo entry for your terminal contains the ul and so attributes, you
can use the UNDERLINE and REVERSE intensity attributes. You can see if your
terminfo entry includes these capabilities by using the infocmp program.
Refer to your operating system documentation for information about infocmp.
If you want to use color and intensity in your INFORMIX-4GL programs, you
must use termcap (by setting the INFORMIXTERM environment variable to
termcap, and by setting the TERMCAP environment variable to $INFORMIXDIR/etc/termcap). For more information, refer to the Environment
Variables appendix and the Preface in the INFORMIX-4GL User Guide.
I-27
I-28
Appendix
J
Working with
DATETIME and
INTERVAL Data
The DATETIME and INTERVAL data types provide a way of
storing moments in time and the spans between moments.
The DATETIME data type holds a value that represents a
single point in time. You choose how precisely a DATETIME
value is stored; its precision can range from years through
fractions of a second. The INTERVAL data type holds a
value that represents a span of time. It can represent either
a span of years and months, or else a span of days, hours,
minutes, seconds, and fractions of a second.
You can specify DATETIME and INTERVAL values in a form
that explicitly identifies not only the value but also the data
type (DATETIME or INTERVAL) and the precision, or you
can enter values as quoted character strings that include
only the values. The explicit form, sometimes called a literal, appears throughout this appendix (except as noted),
but character strings (which omit the data type and field
names) may be required in interactive operations, such as
query by example or data entry through screen forms.
You can manipulate DATETIME and INTERVAL values in a
number of ways. You can enter them as data, you can use
them in relational expressions, and you can manipulate
them arithmetically. This appendix supplies you with
guidelines on how you can use DATETIME and INTERVAL
values. Note, however, that many of the examples presented here are fragmentary. That is, they do not include the
DATETIME Columns
full syntax necessary for an executable statement. (The sectionData Manipulation Statements presents examples of complete SQL statements that use
DATETIME and INTERVAL values.)
DATETIME Columns
Use the DATETIME data type for columns or variables in which you want to
store values that represent a specific point in time. The DATETIME data type
is composed of a contiguous sequence of fields that represent each component of time that you want to record. This is the syntax for defining a
DATETIME column or program variable:
identifier DATETIME first TO last
Here first and last are fields taken from the following list:
Field
Valid Entries
YEAR
MONTH
DAY
HOUR
MINUTE
SECOND
FRACTION
A DATETIME column or variable need not include all fields from YEAR to
FRACTION. It can be a subset of fields, or even a single field (if first and last
are identical). You can define a DATETIME column or variable to include only
the fields that you need. For example, you can specify MONTH TO HOUR to
include only MONTH, DAY, and HOUR. Since the fields are contiguous, they
include all fields from first to last in the sequence listed above. But you cannot
specify HOUR TO YEAR, because first cannot be a smaller unit than last.
Operations involving DATETIME values that do not include precision up to
YEAR use the system date to supply any additional precision required. When
the first field is DAY and the current month has less than 31 days, you can
J-2
Because the column mytime does not include the month or year, the current
month and year are used to evaluate whether the inserted value is within
acceptable bounds. February has only 28 (or 29) days, so no value for DAY
can be larger than 28 (or 29). The INSERT statement in this example would
fail, because the value 31 for DAY is out of range for February. If your application requires that DATETIME inserts span months in this way, always define
DATETIME columns with precision up to at least MONTH.
J-3
Even though the column mytime has a defined precision of YEAR to MINUTE,
you can supply information for only MONTH to HOUR. The entered value is
automatically expanded to fill the column. If the current year is 1989, the
actual inserted value becomes:
DATETIME (1989-8-16 12:00) YEAR TO MINUTE
Notice that the current year, in this example 1989, has been added automatically, along with zeros for the MINUTE field.
The current date is also used to evaluate whether a DATETIME value that
does not include precision up to YEAR is an acceptable date. This can cause
problems when the largest precision of the value is DAY. For example,
assume the current month is September, and you attempt to execute the following statements:
CREATE TABLE mytable (mytime DATETIME DAY TO MINUTE)
INSERT INTO mytable VALUES (DATETIME (31 12) DAY TO HOUR)
Before the row is inserted, the validity of the DATETIME value is checked
against the current date. Because September has only 30 days, the 31 for DAY
is out of range and will produce an error. As a result, you cannot insert this
row during a month that has fewer than 31 days.
Caution: In order to eliminate the risk of processing difficulties during months
with fewer than 31 days, do not create DATETIME columns or variables with a first
precision of DAY, and do not enter DATETIME values with DAY as the field of
largest precision.
When you enter a DATETIME literal, you must include a qualifier that specifies
both the first (largest) and last (smallest) field in the value to be entered.
Including the qualifier is necessary because, as noted earlier, the value that
you are entering can contain fewer fields than defined for that column or
variable. Acceptable keywords for the first and last fields are identical to the
list of valid DATETIME fields displayed previously.
A valid entry contains the DATETIME name, the values to be entered, and the
field qualifier. Use the syntax first-field TO last-field to qualify the DATETIME
value. For example, in the following entry, YEAR TO FRACTION indicates that
values for all possible fields are included in the values listed between the
parentheses. The order of entry and the type of delimiter identify which
value corresponds to each field.
DATETIME (1985-5-2 14:05:00.000) YEAR TO FRACTION
J-4
INTERVAL Columns
The following examples illustrate values that do not include all fields:
DATETIME
DATETIME
DATETIME
DATETIME
DATETIME
When YEAR is given as a two-digit number, as in the first example, it is automatically changed to 19xx (1989 in this case). If you want to specify years
1-99, pad the entry with a preceding zero(s), for example 089 or 0089.
When a value occupies only one field, the first and last qualifiers are the
same. If the first and last qualifiers are both FRACTION, you specify the precision only for the last field.
Values for the fields are written as integers and are separated by delimiters.
All field values are two-digit integers, except for the YEAR (four digits) and
FRACTION (n digits) fields. The following delimiters are used with
DATETIME values:
Delimiter
hyphen ( - )
Between the YEAR and MONTH, and between the MONTH and
DAY portions of the value.
space ( )
colon ( : )
period ( . )
You use the same delimiters when DATETIME values are expressed as character strings.
INTERVAL Columns
Like the DATETIME data type, the INTERVAL data type is composed of a contiguous sequence of fields. Here is the syntax for defining an INTERVAL
column:
identifier INTERVAL first TO last
Here first and last are fields taken from one of the following two lists:
Field
Valid Entries
YEAR
A number of years.
MONTH
A number of months.
OR
Working with DATETIME and INTERVAL Data
J-5
DAY
A number of days.
HOUR
A number of hours.
MINUTE
A number of minutes.
SECOND
A number of seconds.
FRACTION
J-6
Each entry represents a span of time: 5 years and 3 months; 9 months; and 12
hours and 23 minutes, respectively. None of the entries refer to a specific
point in time. For example, the nine-month interval could represent a span
from any single year or across any two years.
When a value contains just one field, the first and last qualifiers are the same.
If the first and last qualifiers are both FRACTION, you can only specify the
precision in the last field.
The first field in an INTERVAL value can be up to nine digits in size (except
for FRACTION, which cannot be more than five digits), but if the value is
greater than the default number of digits allowed for that field, you must
explicitly identify the number of significant digits in the value you are entering. By default, you are allowed up to four digits in a year, three digits in a
fraction, and two digits in all other fields. If you need more digits than the
default, enter the number of required digits (between parentheses) after the
field qualifier.
INTERVAL
INTERVAL
INTERVAL
INTERVAL
The first example illustrates how you can specify a span of 10,000 years by
including the number five (5) after the YEAR. The second example allows a
three-digit MONTH entry. Notice that the number is attached to the first qualifier. You will get a syntax error if you attach the number to the last qualifier.
The third example is a DAY TO MINUTE span of 1 year and 23 minutes. This
illustrates how you can represent values of any length by converting years
and months into their corresponding number of days. Note also how you can
include a zero for the HOUR field in order to enter a value just for MINUTE.
The last example shows how you can specify the precision of both first and
last when FRACTION is the last field.
Non-default precisions are a feature of INTERVAL data. An error results if
you use this notation to specify any DATETIME field except FRACTION.
INTERVAL data follow normal date and time conventions concerning the
range of acceptable values that you can enter. An error results if you exceed
the possible values for a given field. Note the following examples:
INTERVAL (5-13) YEAR TO MONTH
INTERVAL (6-1) YEAR TO MONTH
The first example causes an error because 13 months is more than a year. The
second example correctly expresses the same span of time.
J-7
The values for the fields are written as integers and are separated by delimiters. The following delimiters are used with INTERVAL values:
Delimiter
hyphen ( - )
space ( )
colon ( : )
period ( . )
Values that are specified as character strings are automatically converted into
DATETIME or INTERVAL values. You can use character strings whenever you
specify information for all fields defined for that DATETIME or INTERVAL
column.
When a character string is converted into a DATETIME or INTERVAL value,
the engine assumes that the character string includes information about all
the defined fields. You cannot use character strings to enter DATETIME or
INTERVAL values for a subset of fields, because this produces ambiguous values. If the character string does not contain information for all fields, the
engine returns an error. For example:
INSERT INTO mytable(mytime) VALUES (DATETIME(5-12) MONTH TO DAY)
INSERT INTO mytable(mytime) VALUES ("5-12")
INSERT INTO mytable(myval) VALUES (INTERVAL(11:15) HOUR TO MINUTE)
INSERT INTO mytable(myval) VALUES ("11:15")
J-8
the current year. The character string, however, does not indicate what information is omitted. The engine does not know whether the 5-12 refers to
YEAR and MONTH, or MONTH and DAY, so it returns an error.
The previous INTERVAL example (column myval) enters an HOUR and
MINUTE value into a column defined as DAY TO SECOND. The first INSERT
statement simply pads the value with zeros for YEAR and SECOND. The second INSERT statement produces a conversion error, because the engine does
not know whether the 11:15 refers to HOUR TO MINUTE or MINUTE TO
SECOND.
Operator
+ or +
+ or +
+ or + or + or * or /
Data Type of
Operand 2
Datetime
Interval
Datetime
Interval
CURRENT
Datetime
CURRENT
Interval
UNITS
UNITS
Number
Result
Interval
Datetime
Datetime
Interval
Interval
Interval
Datetime
Datetime
Datetime
Interval
Interval
J-9
You can substitute a DATE value for a DATETIME operand in this table to
obtain a DATETIME or INTERVAL result, except that the difference between
two DATE values is an INTEGER number of days. See the last section of this
appendix for more information on using DATE values in expressions with
DATETIME or INTERVAL values.
No other combinations are allowed. You cannot add DATETIME or DATE values, because this operation does not produce either a point in time or a span
of time. For example, you cannot add December 25 to January 1, though you
can subtract it to find the span between the two dates. Examples of valid
DATETIME expressions are presented in the following sections.
In the first example, no MINUTE field is included for the second value, so the
minutes are automatically set to zero, and the resulting INTERVAL is 60 days,
1 hour, and 30 minutes. In the second example, the year is not included for
the second value. Therefore, the year is automatically set to the current year,
in this case 1989, and the resulting INTERVAL is negative, to show that the
second date is later than the first.
J-10
You cannot directly combine a DATE with an INTERVAL value whose last
qualifier is smaller than DAY. But as the previous example shows, you can use
the EXTEND function to convert the value in a DATE column or variable to a
DATETIME value that includes all the fields of the INTERVAL operand.
values are of similar precision. That is, both must be qualified in the range
YEAR to MONTH, or else both must be in the range DAY to FRACTION. Within
these ranges, the qualifiers need not be identical.
INTERVAL (5-3) YEAR TO MONTH
+ INTERVAL (15) MONTH TO MONTH
result: INTERVAL (6-06) YEAR TO MONTH
INTERVAL (100:30.0005) MINUTE(3) TO FRACTION(4)
- INTERVAL (120.01) SECOND(3) TO FRACTION
result: INTERVAL (98:29.9905) MINUTE TO FRACTION(4)
J-12
The precision of the first value determines the precision of output when
using DATETIME values. In the first example, the precision used for CURRENT matches the first DATETIME value, YEAR TO MINUTE, so the resulting
INTERVAL value has precision DAY TO MINUTE. The precision of the other
three examples is determined by CURRENT, which uses the default precision
of YEAR TO FRACTION.
Similarly, you can specify the TODAY keyword in arithmetic expressions
where a DATE value can appear.
J-13
where number is the amount and field-name is the type of field. The following
examples repeat previous examples, except UNITS replaces one of the
INTERVAL values.
DATETIME (1989-8-1) YEAR TO DAY + 3 UNITS YEAR
result: DATETIME (1992-08-01) YEAR TO DAY
DATETIME (15:45) HOUR TO MINUTE - 720 UNITS MINUTE
result: DATETIME (3:45)HOUR TO MINUTE
INTERVAL (5-3) YEAR TO MONTH + 15 UNITS MONTH
result: INTERVAL (6-06) YEAR TO MONTH
INTERVAL (100:30.0005) MINUTE(3) TO FRACTION(4) - 120 UNITS SECOND
result:
The results of any calculation include the same amount of precision as the
original INTERVAL value. In the first example, the YEAR value is divided by
two leaving one year as a remainder. This remainder is converted into 12
months, added to the 5 existing months, and then divided. One month is left
over, but there is no lower precision, so this remainder is simply discarded in
the final result of 6 years and 8 months.
J-14
The first example updates all rows by a constant INTERVAL value. The second example deletes the rows that are more than a year old. The third example selects all rows for a given one-year period. The final example includes a
derived field in the select-list so that you can compare the existing date with
a later one.
J-15
result is INTERVAL
result is INTERVAL
result is DATETIME
If you need YEAR TO MONTH precision, you can use the EXTEND function on the
first DATE operand, as in the next example:
EXTEND(DATE("5/2/89"), YEAR TO MONTH) - DATE("4/6/54")
result: INTERVAL (35-01) YEAR TO MONTH
While you can interchange DATE and DATETIME values in many situations,
it must be clear whether a value is a DATE or a DATETIME. A DATE value can
come from any of the following sources:
J-16
You can also represent DATE and DATETIME values as quoted character
strings. You can only use strings that are in proper DATE or DATETIME format, however, and only in contexts where the corresponding data type of the
string is known. The following examples illustrate what string format is
required in various contexts:
DATE ("date-string")
WHERE TODAY > "date-string"
WHERE DATE-column < "date-string"
EXTEND ("datetime-string" [, qualifier])
WHERE DATETIME-column > "datetime-string"
When a DATE value is expected, the string must be in DATE format; when a
DATETIME value is expected, the string must be in DATETIME format. For
example, you can use the string "10/30/1989" as a date-string but not as a
datetime-string. Instead, you must use "1989-10-30" or "89-10-30" as the
datetime-string.
J-17
J-18
Error
Messages
Error Messages
This section contains the text of error messages that may
appear when you work with INFORMIX-4GL and suggests
corrective actions.
All errors include an error number. Use the error number to
quickly locate the message in this section. Error messages
with negative numbers appear in order, starting with -100.
The few error messages with positive numbers are placed
at the back of the section.
Note: Unless otherwise noted, the statement containing the
error was not processed.
-100
-101
-102
-103
Description of Error: ISAM error: illegal key descriptor (too many parts or
too long).
Corrective Action: Check that one or more of the elements that make up the
key description is not outside of the range of acceptable values for that element. (There is a maximum of 8 parts and 120 characters to each key
descriptor.)
-104
-105
-106
-107
-108
Error Messages
-109
Description of Error: ISAM error: the key is the files primary key.
Corrective Action: An attempt was made to delete the primary key column.
The primary key cannot be deleted by the isdelindex call.
-110
-111
-112
-113
-114
-116
Error Messages
-118
-119
-120
-121
-122
-123
-124
-125
Error Messages
-126
-127
-128
-129
-130
-131
-132
-133
-134
Error Messages
-135
-136
-137
-138
-139
-141
-142
-143
-144
-145
Description of Error: ISAM error: system does not have disk mirroring
Corrective Action: If you are trying to mirror a dbspace, first reinitialize
INFORMIX-OnLine with a mirror for the root dbspace, then mirror other
dbspaces. (INFORMIX-OnLine)
Error Messages
-146
Description of Error: ISAM error: the other copy of this disk is currently disabled or non-existent.
Corrective Action: Bring up the other chunk of the mirror pair before you
bring down this chunk. (INFORMIX-OnLine)
-147
-148
-149
-200
-201
-202
-203
Error Messages
-204
-205
-206
-207
-208
-209
-210
Error Messages
-211
-212
-213
Error Messages
-214
-215
-216
-217
-218
-219
-220
10
Error Messages
-221
Description of Error: Cannot build temporary file for new table table-name.
Corrective Action: ISAM cannot access the temporary directory (usually,
/tmp) or the disk may be out of space. Check the ISAM error for information
about the source of the problem.
-222
Description of Error: Cannot write to temporary file for new table tablename.
Corrective Action: The disk may be out of space. Check the ISAM error for
information about the source of the problem.
-223
-224
-225
-226
-227
Description of Error: Cannot use ORDER BY clause when selecting into temporary table.
Corrective Action: Remove the ORDER BY clause from your statement. Place
an index on the column you wish to order by after creating the temporary
table.
-228
Error Messages 11
-229
-230
-231
-232
-233
-234
-235
-236
-237
12
Error Messages
-238
-239
-240
-241
-242
-243
-244
-245
-246
Description of Error: Could not do an indexed read to get the next row.
Corrective Action: Check the ISAM error for information about the source of
the problem.
Error Messages
13
-247
-248
-249
-250
-251
-252
-253
-254
-255
14
Error Messages
-256
-257
-258
-260
-261
-262
-263
-264
Error Messages
15
-265
-266
-267
-268
-269
-270
-271
Description of Error: Could not insert new row into the table.
Corrective Action: Check the ISAM error for information about the source of
the problem.
-272
-273
-274
16
Error Messages
-275
-276
-277
Description of Error: UPDATE table table-name is not the same as the cursor
table.
Corrective Action: Either declare a cursor on the table used in the UPDATE
statement, or update the table used in the cursor. Check the spelling of the
table name and cursor name.
-278
-279
-280
-281
-282
-283
17
-284
-285
-286
-287
-288
-289
-290
-291
-292
18
Error Messages
-293
-294
-295
-297
-298
-299
Description of Error: A query may not contain more than one DISTINCT.
Corrective Action: Restructure your query to include only one DISTINCT.
-300
-301
Description of Error: The total size of the GROUP BY columns is too big.
Corrective Action: The total number of characters in all columns listed in the
GROUP BY list exceeds 120 characters. Reduce the column list.
-302
Error Messages
19
-303
-304
-305
-306
-307
-308
Description of Error: Column type must be the same for each UNION
statement.
Corrective Action: Check that each column in the UNION statement is of the
same data type.
-309
-310
-311
20
Error Messages
-312
-313
-314
-315
-316
-317
-318
Description of Error: File with the same name as specified log file already
exists.
Corrective Action: Select a different name for the log file.
-319
-320
-321
Error Messages
21
-322
-323
-324
-325
-326
-327
-328
-329
-330
22
Error Messages
-331
-332
-333
Description of Error: The audit trail file already exists with a different name.
Corrective Action: You must first drop the existing audit trail file (issue a
DROP AUDIT statement) before creating a new audit trail.
-334
-335
-336
-337
-338
Error Messages
23
-339
Description of Error: The audit trail file name must be given in full directory
path.
Corrective Action: Edit your statement to include the full pathname of the
audit trail file.
-340
Description of Error: Cannot open audit trail file. (operating system error).
Corrective Action: Check that you have operating system read permission
to the file. Contact your System Administrator if you need help with this
action.
-341
Description of Error: Could not read a row from audit trail file.
Corrective Action: The request was not completed (possible operating system error). Re-execute your request. If the problem reoccurs, check the ISAM
error message for information about the source of the problem. Contact your
System Administrator if you require assistance with this action. If you again
receive the error, the audit trail file has been corrupted. You may need to drop
and restart the audit trail.
-343
Description of Error: Row from audit trail was added to a different position
than expected.
Corrective Action: Re-execute your request. If the problem reoccurs, check
the ISAM error message for information about the source of the problem.
Contact your System Administrator if you require assistance with this action.
If you again receive the error, the audit trail file has been corrupted. You may
need to drop and restart the audit trail.
-344
Description of Error: Cannot delete rowrow in table does not match row
in audit trail.
Corrective Action: Re-execute your request. If the problem reoccurs, check
the ISAM error message for information about the source of the problem.
Contact your System Administrator if you require assistance with this action.
If you again receive the error, the audit trail file has been corrupted. You may
need to drop and restart the audit trail.
-345
Description of Error: Cannot update rowrow in table does not match row
in audit trail.
Corrective Action: Re-execute your request. If the problem reoccurs, check
the ISAM error message for information about the source of the problem.
Contact your System Administrator if you require assistance with this action.
If you again receive the error, the audit trail file has been corrupted. You may
need to drop and restart the audit trail.
24
Error Messages
-346
-347
-348
-349
-350
-351
-352
-353
-354
Error Messages
25
-355
-356
-357
Description of Error: Dependent table for view view-name has been altered.
Corrective Action: A table upon which the view is constructed has been
modified (for example, a column has been dropped, a data type has been
modified, or a column has been added to the middle of the table). Drop the
view and create a new view.
-358
Description of Error: You must close the current database before you
execute CREATE, START, or ROLLFORWARD.
Corrective Action: You can only use the CREATE DATABASE, START
DATABASE, and ROLLFORWARD DATABASE statements when there is no
current database. Execute a CLOSE DATABASE statement before executing
one of these statements.
-359
-360
-361
-362
-363
26
Error Messages
-364
-365
-366
-367
where n > m
where n > m
where m < 2
-368
-369
-370
-371
Error Messages
27
-372
-373
-374
Description of Error: Can only use column number in ORDER BY clause with
UNION.
Corrective Action: Restructure the query, using ordinal numbers for the
ORDER BY columns.
-375
-376
-377
-378
-379
-380
28
Error Messages
-381
Description of Error: Cannot grant to someone who has granted you the
same privilege before.
Corrective Action: The name of the individual who granted you permission
to use the table must be removed from your user list.
-382
-383
-384
-385
-386
-387
-388
-389
-390
Error Messages
29
-391
-392
-393
-394
-395
-396
Description of Error: Illegal join between a nested outer table and a preserved table.
Corrective Action: Check the syntax of the statement.
-397
-398
-399
-400
-401
30
Error Messages
-402
-403
-404
-405
-406
-407
Description of Error: Error number zero received from the sqlexec process.
Corrective Action: Exit to the operating system command line, re-enter the
program you were using, and resubmit your program.
-408
-409
Description of Error: sqlexec was not found or was not executable by the
current user.
Corrective Action: Check that your INFORMIXDIR environment variable is
properly set. Contact your System Administrator if you need help with this
action.
-410
Error Messages
31
-412
-413
-414
-415
-416
-417
-420
-421
-422
32
Error Messages
-425
-426
-427
-428
-430
-431
-432
-433
-434
-450
33
-451
-452
-453
-454
-455
-456
-461
-462
-463
34
Error Messages
-464
-465
-500
-501
-502
-503
-504
-505
Description of Error: Number of columns in UPDATE does not match number of VALUES.
Corrective Action: The number of columns in the UPDATE statement must
equal the number of values. Rewrite your SQL statement.
-506
-507
Error Messages
35
-508
-509
-510
-511
-512
-513
-514
Description of Error: Only DBA can create, drop, or grant for another user.
Corrective Action: Ask the DBA to perform the operation for you, or to
grant you DBA permission.
-515
-516
36
Error Messages
-517
Description of Error: The size of the index fields is too large or there are too
many parts in the index.
Corrective Action: Reduce the number of fields or the size of the fields in
your index.
-518
-519
-520
-521
-522
-523
-524
-525
-526
-527
Error Messages
37
-528
-529
-531
-532
-533
-534
Description of Error: Could not insert new row into table, table is locked.
Corrective Action: Wait until table is unlocked, and retry the statement.
-535
-536
Description of Error: Cannot have more than one cursor on the same
statement.
Corrective Action: Prepare another identifier on the statement, and declare
a cursor on that identifier.
-538
-539
38
Error Messages
-540
-541
-542
Description of Error: Cannot specify the same column more than once in a
UNIQUE constraint.
Corrective Action: Check your UNIQUE list definition to be sure that no
column is specified more than once in a composite UNIQUE CONSTRAINT.
-543
-544
-545
-546
-549
-550
Error Messages
39
-551
-554
-555
-556
-557
-559
-560
-561
40
Error Messages
-562
-563
-564
-565
-566
-567
Error Messages
41
-568
-569
-570
-571
-572
-573
-574
-575
42
Error Messages
-576
-577
-579
-600
-601
-602
-603
Error Messages
43
-604
-605
-606
-607
-608
-609
-610
-611
-612
Description of Error: Blobs are not allowed in the "group by" clause.
Corrective Action: You cannot include a BLOB column in a GROUP BY clause;
rewrite your select statement.
44
Error Messages
-613
-614
Description of Error: Blobs are not allowed in the "order by" clause.
Corrective Action: You cannot include a BLOB column in an ORDER BY
clause; rewrite your SELECT statement.
-615
-616
-617
Description of Error: A blob data type must be supplied within this context.
Corrective Action: Verify that the source and target are BLOB types.
-618
-620
-621
-622
Error Messages
45
-623
-624
-625
-802
Description of Error: Cannot open file for run (operating system error).
Corrective Action: Check that the file exists. If it is not found in your current
directory you will need to include a full pathname. Check that you have
operating system read permission to access the file. Contact your System
Administrator if you need help with this action.
-804
-809
-816
-817
46
Error Messages
-824
-825
-826
-827
-829
-832
-834
-836
Error Messages
47
-837
-839
-840
-841
Description of Error: Name must start with a letter and contain letters,
digits, or underscores.
Corrective Action: Select a name beginning with a letter and containing only
letters, digits, and underscores.
-842
-843
-844
-846
48
Error Messages
-847
-851
-852
-853
-900
-901
-902
-904
-907
Error Messages
49
-908
-909
-910
-912
-913
Description of Error: Network error - Could not read from remote system.
Corrective Action: Reenter your request. If the problem persists, run your
network diagnostics to determine the source of the problem.
-914
-915
-916
-917
50
Error Messages
-918
-919
-922
-925
-926
-927
-928
Description of Error: The remote server is not licensed for distributed data
access.
Corrective Action: You have tried to access a table on an INFORMIX-OnLine
system that is not licensed for remote access. You can only access other
INFORMIX-STAR systems.
-930
-931
51
-932
-933
-951
-952
Description of Error: Users password is not correct for the remote host.
Corrective Action: Check your /etc/hosts.equiv file to be sure that both the
host machine you are attempting to connect to and the client machine you are
currently logged into have entries in the file. If not, add the missing entry and
reenter your request.
-953
-954
-955
Description of Error: Remote host could not receive data from client.
Corrective Action: Verify that both the host machine and the client machine
are configured properly, and that both machines are aware of each other on
the network. Consult your network user manual for assistance.
-956
52
Error Messages
-999
-1101
-1102
-1107
-1108
-1109
Error Messages
53
-1110
-1111
-1112
-1113
-1114
-1115
-1116
-1117
54
Error Messages
-1119
-1120
-1121
-1122
-1129
-1130
Description of Error: You cannot have multiple BEFORE clauses for the same
field.
Corrective Action: Combine the BEFORE clauses for the same field in INPUT
or INPUT ARRAY statements.
-1131
Description of Error: You cannot have multiple AFTER clauses for the same
field.
Corrective Action: Combine the AFTER clauses for the same field in INPUT
or INPUT ARRAY statements.
Error Messages
55
-1132
-1133
-1134
-1135
-1136
-1137
56
Error Messages
-1138
Description of Error: Border does not fit on screen. Window is too large.
Corrective Action: The dimensions of the bordered window exceed the limits of your screen. Note that the border appears outside the dimensions of the
window. Reduce the size of the window dimensions. If the termcap entry for
your terminal includes an sg#1 setting, or the terminfo entry includes an
xmc#1 setting, INFORMIX-4GL reserves an additional column to the left and
to the right of the window when computing the required window size.
-1139
-1141
-1143
-1144
-1145
Error Messages
57
-1146
-1147
-1148
-1149
-1150
-1200
-1201
58
Error Messages
-1202
-1203
-1204
-1205
-1206
-1208
-1209
Description of Error: Without any delimiters, this date must contain exactly
6 or 8 digits.
Corrective Action: You must enter either 6 or 8 digits when specifying a data
value to represent a DATE.
Error Messages
59
-1210
-1211
-1212
-1213
-1214
-1215
-1216
-1217
-1218
60
Error Messages
-1222
-1223
-1224
-1225
-1226
-1227
-1228
-1229
-1230
-1231
Error Messages
61
-1232
-1250
-1251
-1252
-1254
-1257
Description of Error: Operating system cannot fork process for back end.
Corrective Action: This is an internal error. Follow the suggested actions for
error -1250. After verifying that the error is not the result of a system limit or
problem, please notify the Informix Technical Support Department.
-1258
62
Error Messages
-1260
-1261
-1262
-1263
-1264
Error Messages
63
-1265
-1266
-1267
-1268
-1269
-1270
Description of Error: Interval literal may not have embedded minus sign.
Corrective Action: You can use a minus sign as an arithmetic or unary
operator with INTERVAL literals, but not within any of its fields.
-1271
64
Error Messages
-1301
-1302
Description of Error: The two entries were not the sameplease try again.
Corrective Action: The system issues this warning during an INPUT or
INPUT ARRAY statement when the user does not enter the same value twice
in a display field that has been assigned the VERIFY attribute. The user must
enter the same value twice before the value will be accepted.
-1303
Description of Error: You cannot use this editing feature because a picture
exists.
Corrective Action: The system issues this warning during an INPUT or
INPUT ARRAY statement when the user tries to use CTRL-A, CTRL-D, or
CTRL-X in a display field that has been assigned the PICTURE attribute. The
user should not use the CTRL-A, CTRL-D, or CTRL-X keys when entering data
in a field that has been assigned the PICTURE attribute.
-1304
-1305
-1306
Error Messages
65
-1307
-1308
-1309
Description of Error: There are no more rows in the direction you are going.
Corrective Action: The system issues this warning during an INPUT ARRAY
or DISPLAY ARRAY statement when the user presses the [ ] or Previous Page
key while the cursor is at the beginning of the program array or when the
user presses the [ ] or Next Page key while the cursor is at the end of the
program array. The user should select another scrolling or editing function.
-1312
-1313
-1314
-1315
-1316
66
Error Messages
-1317
-1318
-1319
Description of Error: The 4GL program has run out of runtime data space
memory.
System Action: The program stops and running transactions are rolled back.
Corrective Action: Divide your program into smaller modules. Reduce the
size of arrays and character variables. Make sure that no function returns a
character string longer than 512 characters.
-1320
-1321
-1322
-1323
Error Messages
67
-1324
-1325
-1326
-1327
Description of Error: An insert statement could not be prepared for inserting rows into a temporary table used for a report.
Corrective Action: Check to see that you have CONNECT permission to the
database used by the program. Set all system access permissions to allow you
to write into the database directory.
-1328
-1329
-1330
68
Error Messages
-1331
-1332
-1333
-1334
Description of Error: The 4GL program cannot allocate any more space for
temporary string storage.
Corrective Action: INFORMIX-4GL cannot allocate more than 512 characters
for temporary string storage. This error can occur if the nested functions in a
CALL statement return strings whose total length exceeds 512 characters.
-1335
-1336
-1337
Error Messages
69
-1338
Description of Error: The function function-name has not been defined in any
module in the program.
Corrective Action: This suggests that the function function-name has been
called, but is not in any module in the program. Supply the function in one
of the modules and recompile.
-1339
-1340
-1343
-1345
-1346
-1347
-1348
70
Error Messages
-1349
-1350
-1353
-1355
-1356
-1357
-1358
-1359
71
-1360
-1361
Description of Error: Illegal blob file name. Null names are not permitted.
Corrective Action: You must specify a valid name for the file that contains
this binary large object (BLOB) of data type TEXT or BYTE.
-2013
-2014
-2015
-2016
Description of Error: A comment has been opened, but not closed. The last
comment begun was opened on line lineno, character charposition.
Corrective Action: Comments must be enclosed within a pair of braces
({ and }). Insert a close comment symbol where appropriate. Recompile the
form specification.
-2017
Description of Error: The character data value does not convert correctly to
the field type.
Corrective Action: Check that the values in the character string contain only
ASCII characters, and represent a value of the appropriate data type. See if a
date or time separator is incorrect.
72
Error Messages
-2018
-2019
-2020
Description of Error: The table table-name could not be opened. The operating system was asked to open it for writing.
Corrective Action: Check that you have operating system write permission
to create a file in the designated directory. Contact your System Administrator if you need help with this action. Recompile the form specification.
-2021
-2022
Description of Error: This identifier exceeds the maximum length for identifiers, which is 50.
Corrective Action: Check that all field names, field labels, and identifiers are
less than or equal to 50 characters in length. Recompile the form specification.
-2023
Description of Error: This quoted string exceeds the maximum length for
quoted strings, which is 80.
Corrective Action: Reduce the number of characters in the quoted string to
80 or less. Recompile the form specification.
-2024
Error Messages
73
-2025
Description of Error: The comment close symbol ( } ) has been found on line
lineno, character charposition, even though no comment has been opened.
Corrective Action: Comments must be enclosed within a pair of braces
({ and }). Remove the close comment symbol if it is unnecessary or insert an
open comment symbol where appropriate. Recompile the form specification.
-2026
Description of Error: The FORMONLY field field-name does not have a type
specified. A type must be specified if include lists or default values are
specified.
Corrective Action: Include a type specification after the field-name.
-2027
-2028
-2029
-2030
-2031
74
Error Messages
-2032
Description of Error: The number above could not be successfully converted to either an INTEGER or a DOUBLE or a LONG.
Corrective Action: FORM4GL could not convert the number provided.
Acceptable LONG values are whole numbers between -2,147,483,647 and
2,147,483,647. Check that the number does not exceed these values (if a fixed
point number) or that it does not contain an error (if a decimal number).
Recompile the form specification.
-2033
Description of Error: The field field-name has a default value not within the
range of its include list values.
Corrective Action: If you have an include list and a default, the default must
be within the include list range.
-2035
-2036
-2037
Description of Error: The PROGRAM attribute can only be specified for BYTE
and TEXT fields.
Corrective Action: See if you have specified the wrong field tag or column
name, or the wrong data type of a FORMONLY field.
-2038
-2039
Error Messages
75
-2040
-2041
-2042
Description of Error: The usage of a BLOB field in or around the above statement is incorrect.
Corrective Action: You have specified an attribute that does not support
TEXT or BYTE fields, or else your condition for the COLOR attribute cannot be
applied to a BLOB.
-2043
Description of Error: Screen layout exceeds the specified screen width. This
is a warning only.
System Action: Your form successfully compiled.
Corrective Action: According to your explicit or default column specification, part of your screen layout lies beyond the right-hand limit of the form
or of the physical screen. 4GL programs can use the form, but users may not
be able to see part of it. To avoid this effect, use a narrower page layout.
-2044
Description of Error: At most one color attribute may be specified for each
field with each condition.
Corrective Action: Correct your ATTRIBUTE section, so that no condition
assigns multiple colors to the same field.
-2045
-2100
Description of Error: Field field-tag has validation string error, String = character-string
Corrective Action: Check that the values in the character string contain only
ASCII characters, and represent a value of the appropriate data type.
76
Error Messages
-2800
Description of Error: The first line of the specification must be the keyword
DATABASE followed by the database name, or the FORMONLY keyword (4GL
only). An optional WITHOUT NULL INPUT may also follow.
Corrective Action: Check the spelling of the first line of the form specification file, or check that the keyword DATABASE is followed by the database
name or the FORMONLY keyword. Recompile the form specification.
-2810
-2811
-2812
-2820
-2830
Description of Error: A left square bracket has been found on this line, with
no right bracket to match it.
Corrective Action: A set of brackets [ ] is used to delimit the field size of each
field. Insert a right square bracket ( ] ) where appropriate into the form specification file. Note that a display field cannot be split across lines. For a multiple-line field to which you assign the WORDWRAP attribute, each segment
must be indicated by delimiters, with the same field tag repeated in each segment of the field. Recompile the form specification.
-2831
77
-2832
Description of Error: This form uses "|" to both start and end a field placement. Because of this, the form must specify left and right delimiters, which
are the same character. This is done with a DELIMITERS command in the
INSTRUCTIONS section.
Corrective Action: The DELIMITERS section must specify the same 2
characters for the left and right delimiters.
-2834
-2840
Description of Error: The label label-name was not defined in the form.
Corrective Action: Check that the field tag label-name is included in both the
SCREEN and ATTRIBUTES sections of the form specification file, or delete the
unnecessary label-name. (This error often accompanies errors -2820 and
-2975.) Recompile the form specification.
-2841
Description of Error: The form must include a tables declaration before the
attributes section.
Corrective Action: Include a TABLES section before the ATTRIBUTES section.
-2843
Description of Error: The column column-name does not appear in the form
specification.
Corrective Action: Be sure all fields in the ATTRIBUTES section appear in the
SCREEN section.
-2844
-2845
-2846
78
Error Messages
-2850
-2856
-2859
-2860
-2861
-2862
-2863
Description of Error: The column column-name does not exist among the
specified tables.
Corrective Action: Check the spelling of the column name or check that
column-name does exist in one of the specified tables. Recompile the form
specification.
Error Messages
79
-2864
Description of Error: The table table-name is not among the specified tables.
Corrective Action: Check the spelling of table-name in the ATTRIBUTES section of the file. Check that the table is specified in the TABLES section of your
form. Recompile the form specification.
-2865
Description of Error: The column column-name does not exist in the table
table-name.
Corrective Action: Check the spelling of column-name. Recompile the form
specification.
-2866
-2867
-2870
Description of Error: The subscripted column size does not match the space
allocated in the display field.
Corrective Action: Check that the space provided in the display field is
greater than or equal to the subscripted column size. Recompile the form
specification.
-2880
Description of Error: The word 'screen' or 'end' has been left out.
Corrective Action: Ignore this message. It applies to a feature of PERFORM
forms that 4GL does not support.
-2890
80
Error Messages
-2892
-2893
Description of Error: The display field label field-tag appears more than once
in this form, but the lengths are different.
Corrective Action: A field tag ( = display field label) can appear more than
once in the SCREEN section, but in every instance the display fields must have
identical lengths. Edit the field delimiters so that they are of equal length.
Recompile the form specification.
-2895
Description of Error: Display field length of number does not match the
database column length of number. This is a warning only.
Corrective Action: Check that the display field length (included in the
SCREEN section) is equal to the table column size. (This error occurs only in
character fields and with the -v option to FORM4GL.)
-2901
-2920
-2921
81
-2930
-2931
-2932
Description of Error: Formats can be specified only for DECIMAL, SMALLFLOAT, FLOAT or DATE columns.
Corrective Action: You can only use the FORMAT attribute with a DECIMAL,
SMALLFLOAT, FLOAT, or DATE column to control the format of the display.
Check that you have not specified the format on a CHAR, DATETIME,
INTEGER, INTERVAL, or SMALLINT data type. Recompile the form
specification.
-2933
Description of Error: The format width is larger than the allocated display
width.
Corrective Action: Check that the format of a DECIMAL, SMALLFLOAT,
FLOAT, or DATE column matches the length of the display field in the form.
Recompile the form specification.
-2934
Description of Error: The format width is less than the allocated display
width. This is a warning only.
System Action: The compile was completed.
Corrective Action: Check that the format of a DECIMAL, SMALLFLOAT,
FLOAT, or DATE column matches the length of the display field in the form.
Note: Until this error is corrected, any data displayed in the field might
be truncated.)
-2935
Description of Error: The number of lines specified with the '-l' option or in
the screen section must be a positive integer from 6 to 600.
Corrective Action: Your vertical dimension is out of range. Specify a positive
value between 6 and (lines - 4), for the number of rows that your physical
screen can display.
82
Error Messages
-2936
Description of Error: The number of columns specified with the '-c' option
or in the screen section must be a positive integer from 30 to 600.
Corrective Action: Your horizontal dimension is out of range. Specify a positive value between 30 and the width (in characters) of your physical screen.
-2940
Description of Error: The column column-name appears both with and without subscripts.
Corrective Action: Ignore this message. It applies to a feature of PERFORM
forms that 4GL does not support.
-2943
-2944
Description of Error: You may apply the AFTER ADD, UPDATE, QUERY, or
REMOVE commands to a table onlynot a column.
Corrective Action: Ignore this message. It applies to features of PERFORM
forms that 4GL does not support.
-2945
-2946
Description of Error: You may not calculate an aggregate on the displayonly field field-name.
Corrective Action: Ignore this message. It applies to a feature of PERFORM
forms that 4GL does not support.
-2950
-2951
83
-2952
Description of Error: In order to use a picture, the picture length must be the
same as the display field length.
Corrective Action: Edit the file so that the length of the picture specified
with the PICTURE attribute equals the display field length in the SCREEN section. Recompile the form specification.
-2955
Description of Error: The name field-tag is not a displayed field in this form.
Corrective Action: The display field field-tag has been specified in the
ATTRIBUTES section of the form specification file, but the field-tag is not
included in the SCREEN section of the form. Delete the field-tag from the
ATTRIBUTES section or include it in the SCREEN section. Recompile the form
specification.
-2958
-2959
Description of Error: Two tables may join with a maximum of integer column pairs, including all components of composite columns.
Corrective Action: Ignore this message. It applies to a feature of PERFORM
forms that 4GL does not support.
-2970
Description of Error: The column column-name joins with other columns, but
it is not indexed. It is recommended that columns be indexed for cross-table
queries. Performance will be much improved by creating an index on the
column.
Corrective Action: Ignore this message. It applies to a feature of PERFORM
forms that 4GL does not support.
-2971
-2972
84
Error Messages
-2973
-2975
Description of Error: The display field label field-tag has not been used.
Corrective Action: The field tag ( = display field label) field-tag present in the
SCREEN section of the form specification file does not correspond to any field
name in the ATTRIBUTES section. Delete field-tag from the SCREEN section if
it is unnecessary, or else reference it in the ATTRIBUTES section if you have
neglected to assign it a name. Recompile the form specification.
-2976
Description of Error: The end of the form has been reached prematurely.
Corrective Action: You have a SCREEN section with no following sections.
Edit your form specification file to specify any necessary table names or
aliases, field names, non-default screen arrays, or any other required
information.
-2977
-2978
Description of Error: The column col-name1 and the column col-name2 cannot be joined columns because their types or lengths are different.
Corrective Action: Ignore this message. It applies to a feature of PERFORM
forms that 4GL does not support.
-2984
-2985
Description of Error: The table identifiers name and name represent the same
table.
Corrective Action: Correct the TABLES section, so that each table alias is
associated with a different database table.
-2986
85
-2987
-2988
-2989
-2991
86
Error Messages
-2992
Description of Error: The display label field-tag has already been used.
Corrective Action: Each field tag ( = display label) must be unique. Specify
a different field tag. Recompile the form specification.
-2993
-2994
Description of Error: The form has exceeded the maximum number of joins
between tables.
Corrective Action: Ignore this message. It applies to a feature of PERFORM
forms that 4GL does not support.
-2995
-2996
-2997
-2998
-2999
87
-4300
-4301
Description of Error: The program has too many levels of WHILE, FOR,
MENU, and/or CASE statements.
Corrective Action: A program can contain only 25 levels of WHILE, FOR,
MENU, and/or CASE statements (in any combination). Reduce the number of
nested WHILE, FOR, MENU, and/or CASE statements so that it does not
exceed 25.
-4302
-4304
-4305
-4306
88
Error Messages
-4307
Description of Error: The number of variables and/or constants in the display list does not match the number of form fields in the display destination.
Corrective Action: Check the variable-list and the field-list in your DISPLAY or
DISPLAY ARRAY statement to make sure that they contain the same number
of items.
-4308
Description of Error: The number of input variables does not match the
number of form fields in the screen input list.
Corrective Action: Check the variable-list and the field-list in your INPUT or
INPUT ARRAY statement to make sure that they contain the same number of
items.
-4309
Description of Error: Printing cannot be done within a loop or CASE statement contained in report headers or trailers.
Corrective Action: Do not include PRINT statements within FOR, WHILE, or
CASE statements that appear in FIRST PAGE HEADER, PAGE HEADER, and
PAGE TRAILER control blocks.
-4310
-4311
-4312
-4313
-4314
Description of Error: The program cannot exit a menu at this point because
it is not within a MENU statement.
Corrective Action: Make sure that the EXIT MENU keywords appear only
within a COMMAND clause of the MENU statement.
Error Messages
89
-4315
-4316
-4317
Description of Error: The program cannot exit a FOR statement at this point
because it is not within a FOR statement.
Corrective Action: Make sure that the EXIT FOR keywords appear only
within a FOR statement.
-4318
Description of Error: The program cannot exit a CASE statement at this point
because it is not within a CASE statement.
Corrective Action: Make sure that the EXIT CASE keywords appear only
within a CASE statement.
-4319
Description of Error: The symbol variable-name has been defined more than
once.
Corrective Action: Make sure that each variable is defined only once in your
GLOBALS, MAIN, FUNCTION, or REPORT statement.
-4320
Description of Error: The symbol table-name is not the name of a table in the
specified database.
Corrective Action: Check the spelling of table-name and make sure that it is
a table in the specified database.
-4321
-4322
90
Error Messages
-4323
-4324
-4325
-4326
-4327
-4328
-4329
Error Messages
91
-4330
-4331
-4332
Description of Error: The LET statement must have at least one source
expression.
Corrective Action: Make sure that one or more valid expressions appears to
the right of the equal sign (=) in a LET statement.
-4333
-4334
-4335
-4336
-4338
92
Error Messages
-4339
-4340
-4341
-4342
-4343
Description of Error: Subscripting cannot be applied to the variable variable-name because it is not a character or array variable.
Corrective Action: Check the spelling of the variable name. Define variable-name as a character or array variable or remove the subscript, as appropriate.
-4344
Description of Error: The variable variable-name cannot be used with substrings because it is not a character variable.
Corrective Action: Check the data type of the variable. If variable-name is not
a character variable, remove the subscript(s) or change the type of the variable, as appropriate.
-4345
Error Messages
93
-4346
-4347
-4348
Description of Error: This type of aggregate must be applied to an expression, not *. Only PERCENT and COUNT aggregates use *.
Corrective Action: Use an expression instead of an asterisk (*) with the SUM,
AVG, MIN, and MAX aggregates.
-4349
-4350
Description of Error: The program cannot continue a FOR loop at this time
because it is not within a FOR loop.
Corrective Action: Make sure that the CONTINUE FOR keywords appear
only within a FOR statement.
-4351
-4352
-4356
Description of Error: A page header has already been specified within this
report.
Corrective Action: Change the FORMAT section of your report so that it
contains only one PAGE HEADER control block.
94
Error Messages
-4357
Description of Error: A page trailer has already been specified within this
report.
Corrective Action: Change the FORMAT section of your report so that it
contains only one PAGE TRAILER control block.
-4358
Description of Error: A first page header has already been specified within
this report.
Corrective Action: Change the FORMAT section of your report so that it contains only one FIRST PAGE HEADER control block.
-4359
-4360
-4361
-4362
Description of Error: The report cannot skip to the top of page while in a
header or trailer.
Corrective Action: Remove SKIP TO TOP OF PAGE statements from FIRST
PAGE HEADER, PAGE HEADER, and PAGE TRAILER control blocks.
-4363
Description of Error: The report cannot skip lines while in a loop within a
header or trailer.
Corrective Action: Remove SKIP statements from FOR and WHILE loops that
appear in FIRST PAGE HEADER, PAGE HEADER, and PAGE TRAILER control
blocks.
-4364
95
-4365
-4366
-4367
Description of Error: Interrupt has already been deferred once in the MAIN
program. Each main program may defer interrupt only once.
Corrective Action: Make sure that the DEFER INTERRUPT statement appears
only once, and then only in the MAIN section of your program. (Once
deferred, Interrupt signals cannot be reactivated.)
-4368
Description of Error: Quit has already been deferred once in the MAIN
section of your program. Each main program may defer quit only once.
Corrective Action: Make sure that the DEFER QUIT statement appears only
once, and then only in the MAIN section of your program. (Once deferred,
Quit signals cannot be reactivated.)
-4369
-4370
-4371
96
Error Messages
-4372
Description of Error: The cursor cursor-name has not yet been declared in
this program module. It must be declared before it can be used.
Corrective Action: You must use the DECLARE statement to declare a cursor
in each module before you can use it in statements such as FOREACH, OPEN,
and FETCH.
-4373
Description of Error: A grammatical error has been found on line line-number, character character-number. The construct is not understandable in its context.
Corrective Action: When INFORMIX-4GL encounters a grammatical error, it
inserts a marker in the .err file just past the point where the parser detected
the error. Check the syntax of the marked statement.
-4375
Description of Error: The page length is too short to cover the specified page
header and trailer lengths.
Corrective Action: Make sure that the total number of lines required for the
page header and trailer do not exceed the default page length or the length
specified in the PAGE LENGTH statement. Change the page header and trailer
or the page length as appropriate.
-4376
-4377
-4378
-4379
Error Messages
97
-4380
-4381
Description of Error: The input file filename has an invalid extension. The
filename must have .4gl as the extension.
Corrective Action: Rename the input file so that it has the extension .4gl.
-4382
Description of Error: Record variables that contain array type elements may
not be referenced by the ".*" or THROUGH shorthand, or used as a function
parameter.
Corrective Action: Rewrite your statement so that record variables with
array components do not appear with the THRU, THROUGH, or .* shorthands or as function parameters.
-4383
-4384
Description of Error: The symbol element-name does not represent the element of any record.
Corrective Action: Check the spelling of element-name and make sure that it
belongs to the specified record.
-4385
-4386
Description of Error: There are too many ORDER BY fields in this report. The
maximum number is eight.
Corrective Action: Reduce the number of ORDER BY fields to eight or less.
-4387
Description of Error: The right margin must be greater than the left margin.
Corrective Action: Check that the RIGHT MARGIN value is greater than the
LEFT MARGIN value.
98
Error Messages
-4388
Description of Error: There is one BEFORE GROUP OF clause and one AFTER
GROUP OF clause allowed for each report input parameter.
Corrective Action: You can use only one BEFORE GROUP OF control block
and one AFTER GROUP OF control block for each report parameter. You must
combine multiple BEFORE GROUP OF or AFTER GROUP OF control blocks for
the same parameter into a single control block.
-4389
-4391
-4392
Description of Error: The 4GL compiler has run out of data space memory
to contain the 4GL program symbols. If the program module is very large,
dividing it into separate modules may alleviate the situation.
Corrective Action: Divide your program into smaller programs or reduce
the complexity of your program.
-4393
-4394
Description of Error: The MENU statement has two or more selections using
the key-name key.
Corrective Action: The user selects a menu option by typing one of the letters in a key list (if a KEY clause for the menu option is present) or by typing
the first letter of the menu option (if a KEY clause for the option is not
present). Rewrite the MENU statement so that the letter for selecting each
menu option is unique.
Error Messages
99
-4395
Description of Error: There are too many subscripts specified with a database column name.
Corrective Action: You can use no more than two subscripts with database
columns of type CHAR.
-4396
-4397
-4398
-4399
-4400
-4401
-4402
100
Error Messages
-4403
Description of Error: The number of dimensions for the variable variable-name does not match the number of subscripts.
Corrective Action: Rewrite the statement so that the number of subscripts
after the array name is the same as the number of dimensions in the array
definition.
-4406
-4407
-4408
Description of Error: There is a quoted string that is too long in the above
line.
Corrective Action: A quoted string cannot exceed 80 characters. Reduce the
length of the quoted string or, if appropriate, divide it into shorter strings
separated by commas.
-4409
-4410
-4411
-4412
Description of Error: Values from the RUN command can be returned only
to INTEGER or SMALLINT variables.
Corrective Action: Make sure that the variables that appear in the
RETURNING clause of a RUN statement are defined as INTEGER or SMALLINT.
Error Messages
101
-4413
Description of Error: The label label-name has already been defined within
this MAIN program or function.
Corrective Action: Make sure that each label is defined only once in the
MAIN program or function.
-4414
Description of Error: The label label-name has been used but has never been
defined within the above main program or function.
Corrective Action: Make sure that you define each label with the LABEL
statement before using it in the MAIN program or function.
-4415
-4416
-4417
-4418
Description of Error: The variable used in the INPUT ARRAY statement must
be an array.
Corrective Action: Check the spelling of the variable name and make sure
that it has been defined as an array.
-4419
-4420
Description of Error: The number of lines printed in the IF part of an IFTHEN-ELSE statement of a header or trailer clause must equal the number of
lines printed in the ELSE part.
Corrective Action: Add or remove lines as necessary so that number of lines
printed in the IF part is the same as the number of lines printed in the ELSE
part of the IF-THEN-ELSE statement.
102
Error Messages
-4421
Description of Error: You may not use an INPUT statement within another
INPUT statement or PROMPT statement, even if it is enclosed within a conditional or looping statement.
Corrective Action: Remove any INPUT statements that appear within an
INPUT or PROMPT statement.
-4422
-4423
Description of Error: The CLIPPED and USING options for the DISPLAY
statement may not be used when displaying to a form field.
Corrective Action: Remove all references to CLIPPED and USING from
DISPLAY TO or DISPLAY BY NAME statements. You can substitute for USING
an appropriate format string with the FORMAT attribute, and recompile the
form.
-4424
-4425
Description of Error: The variable variable-name has not been defined LIKE
the table table-name.
Corrective Action: Define the variable with the RECORD LIKE keywords if
you want to use it in an UPDATE statement.
-4426
Description of Error: The PRINT statement may be used only within reports.
If you wish to print without screen positioning, use the DISPLAY statement
without any field or screen destination.
Corrective Action: Replace all PRINT statements that appear outside of
reports with DISPLAY statements. Use the DISPLAY TO or DISPLAY BY NAME
statement to display information in a display field on a screen form, the
DISPLAY AT statement to display information at a specified row and column
on the screen, or the DISPLAY statement to display information without
screen positioning.
Error Messages
103
-4427
Description of Error: The COLUMN feature for the DISPLAY statement may
be used only when displaying without screen or field destination.
Corrective Action: Remove the COLUMN function from the display list of
any DISPLAY AT, DISPLAY TO, or DISPLAY BY NAME statement.
-4428
Description of Error: You may not use a PROMPT statement within an INPUT
or PROMPT statement, even if it is enclosed within a conditional or looping
statement.
Corrective Action: Remove any PROMPT statements that appear within an
INPUT or PROMPT statement.
-4429
-4430
-4432
-4433
-4434
104
Error Messages
-4435
-4437
Description of Error: All table names in the SELECT list must be the same as
the table names in the FROM clause.
Corrective Action: Check that you have not misspelled the name of a table
in the SELECT list.
-4438
-4439
-4440
-4441
Description of Error: The ISAM cursor cursor-name has not yet been declared
in this program module. It must be declared before it can be used.
Corrective Action: Check the spelling of cursor_name and that you have
physically declared the cursor before making reference to it.
-4442
-4443
105
-4444
-4445
-4446
Description of Error: Key value key-value may not be used in this context.
Corrective Action: Choose an acceptable key value and recompile the
program. Acceptable key values are f1 through f36, ESC, ESCAPE, the Interrupt key, or CTRL-k where k is any character except a, d, h, l, r, or x. Some systems also reserve CTRL-S and CTRL-Q for special purposes.
-4447
-4448
Description of Error: Cannot open the file filename for reading or writing.
Corrective Action: Check that the file filename exists and that you have
permission to read or write to it.
-4452
-4453
Description of Error: The size of the global string table has exceeded the
limit of 32767.
Corrective Action: Reduce the number of global variables or reduce the
length of each global variable and recompile the program.
-4454
Description of Error: The size of the local string table has exceeded the limit
of 32767.
Corrective Action: Decrease the length or the number of strings and local
variables. Recompile the program.
-4456
106
Error Messages
-4457
Description of Error: You may have at most 4 keys in the key list.
Corrective Action: Reduce the number of keys to four or less when using the
Key clause in the COMMAND statement of MENU.
-4458
Description of Error: One dimension of this array has exceeded the limit
of 32767.
Corrective Action: Split the array so that the maximum dimension of the
array is less than 32,767. Recompile the form specification.
-4459
-4460
-4461
Description of Error: Line num in the colornames file must have the form
"<color> 0-9".
Corrective Action: The compiler cannot read the colornames file located in
either the current directory or $INFORMIXDIR/incl because a line does not
have the specified format. Check the spelling and syntax for line num in the
colornames file and recompile the program.
-4462
-4463
Description of Error: You may not use NEXT FIELD outside of an INPUT
statement.
Corrective Action: Place NEXT FIELD inside an INPUT statement or INPUT
ARRAY statement and recompile.
-4464
Error Messages
107
-4465
-4466
-4467
-4468
-4469
-4470
-4471
-4472
108
Error Messages
-4473
-4474
-4475
Description of Error: name may not be used as both a function name and a
variable name.
Corrective Action: Rename either the function or the variable, and recompile the program.
-4476
Description of Error: Record members may not be used with database column substring. Possible misspelling or usage of undefined host variables.
Corrective Action: This statement uses an expression of the form
name1.name2[...], where name2 is either a column name, in which case you
cannot specify the substring, or else a variable that has not been defined.
Check the spelling of name1.name2, or remove the brackets, and recompile the
program.
-4477
-4478
Description of Error: The size of the local variables used in this function has
exceeded the 32K per function limit.
Corrective Action: Reduce the size of the functions local variables, and
recompile.
-4479
Error Messages
109
-4480
-4481
-4482
-4483
-4484
-4501
110
Error Messages
-4502
Description of Error: The 4GL program has run out of runtime data space
memory.
System Action: The program stops and running transactions are rolled back.
Corrective Action: Divide your program into smaller modules. Reduce the
size of arrays and character variables. Make sure that no function returns a
character string longer than 512 characters.
-4503
Description of Error: A function has not returned the correct number of values expected by the calling function.
Corrective Action: Make sure that the number of parameters after the
RETURN keyword in the called function is the same as the number of parameters after the RETURNING keyword in the calling statement.
-4504
-4508
-4513
-4517
Description of Error: Strings of length > 512 cannot be returned from function calls.
Corrective Action: Make sure that a character string returned by a function
does not exceed 512 characters.
-4518
Description of Error: The 4GL program cannot allocate any more space for
temporary string storage.
Corrective Action: INFORMIX-4GL cannot allocate more than 512 characters
for temporary string storage. This error can occur if the nested functions in a
CALL statement return strings whose total length exceeds 512 characters.
-4524
-4527
-4529
-4530
Description of Error: Cannot close and free a cursor used to process a report.
Corrective Action: Recompile the program. If the problem reoccurs, call
your Informix Representative.
-4531
Description of Error: The file filename starts with a bad magic number. You
may have tried to run a file that was not created by the 4GL p-code compiler.
Corrective Action: The p-code file has been corrupted. Recompile the
program.
-4534
-4600
-4601
112
Error Messages
-4602
-4603
-4604
-4607
-4608
-4609
-4610
-4611
-4612
Description of Error: Data validation table does not currently exist for this
database.
Corrective Action: If the syscolval table exists, make sure that it resides in
the current directory or in a directory specified by DBPATH. Otherwise, select
the Yes option to create it.
-4613
Description of Error: Screen display attribute table does not currently exist
for this database.
Corrective Action: If the syscolatt table exists, make sure that it resides in
the current directory or in a directory specified by DBPATH. Otherwise, select
the Yes option to create it.
-4614
-4615
-4616
Description of Error: The 4GL program database does not exist. Please
create via PROGRAM section.
Corrective Action: If the syspgm4gl program database does not exist, create
it by using the Program option of the Programmers Environment. If
syspgm4gl does exist, make sure that it resides in the current directory or in
a directory specified by the DBPATH environment variable.
-4617
-4618
114
Error Messages
-4620
-4621
-4622
-4623
-4624
-4625
-4626
-4627
-4628
-4629
-4630
-4631
-4632
-4633
-4634
116
Error Messages
-4635
-4638
-4639
-4640
-4641
-4642
-4643
-4644
Description of Error: The HELP and ATTRIBUTE clauses each can be specified only once.
Corrective Action: Delete all but one clause of each type from the statement,
and recompile.
-4645
-4646
-4647
Description of Error: Cannot open file filename to read a TEXT variable value.
Corrective Action: An I/O error occurred while trying to read the temporary file in which the TEXT or BYTE variable is stored. This can be caused by
insufficient space on the disk, or by file corruption.
-4648
-9143
Description of Error: Character, Text, and Byte data cannot be printed with
"using" formats.
Corrective Action: Be sure you have not attempted to use the USING keyword with Character, Text, and Byte data. You can only use it with date and
number data.
1203
1310
118
Error Messages
1354
2002
2005
2008
Description of Error: The table table-name does not exist in the database.
Corrective Action: The table name included in the TABLE section of the form
specification file is not found in the database specified in the DATABASE section. Check the spelling of the table name.
2009
2010
Description of Error: There is not enough memory to use the default form
option for this particular choice of tables.
Corrective Action: You have exceeded the data space limits of your
machine. Reduce the number of tables included in the form.
2011
2012
2017
Description of Error: The default form has exceeded its label limit.
Corrective Action: A form can use up to 26 one-character fields, 260 twocharacter fields, and 1000 fields of three characters or more. Reduce the number of tables in the default form. Recompile the form specification.
2018
Description of Error: The default form has exceeded its limit of 260 twocharacter labels.
Corrective Action: The total number of two-character fields contained in the
tables used to generate the default form exceeds the 260 limit. You must
delete one or more of the tables containing two-character fields. Recompile
the form specification.
2019
Description of Error: The default form has exceeded its limit of 26 one-character labels.
Corrective Action: The total number of one-character fields contained in the
tables used to generate the default form exceeds the 26 limit. You must delete
one or more of the tables containing one-character fields. Recompile the form
specification.
2020
2028
4150
4152
4153
120
Error Messages
4154
4155
4156
Error Messages
121
122
Error Messages
B C
Index
Index
A
a command-line option 1-62
A symbol in PICTURE format
strings 4-38
ABSOLUTE keyword, FETCH
statement 3-17, 7-98
Accept key 7-166
ACCEPT KEY keywords, OPTIONS
statement 7-79, 7-166
Access privileges 3-41
ALL 7-115, 7-187
ALTER 7-16, 7-115, 7-187
CONNECT 3-41, 7-52, 7-116,
7-187, E-23
database privileges 7-42, 7-116
DBA 3-41, 7-116, 7-187
default 3-41
DELETE 7-115, 7-187
for a synonym 7-47
for database administrator 3-41
FROM PUBLIC 7-188
INDEX 7-115, 7-187
INSERT 7-115, 7-187, E-14
removing 7-187
RESOURCE 3-41, 7-116, 7-187
SELECT 7-115, 7-187, 7-204
table privileges 3-41, 7-115
TO PUBLIC 3-41, 7-116
UNIX permissions 7-42
UPDATE 7-115, 7-187
view privileges 3-60, 7-117
ACTION Menu (upscol
utility) E-38
Active set of a query 2-22, 3-14
ADD keyword, ALTER TABLE
statement 7-14
Index
ATTRIBUTE keyword
CONSTRUCT statement 7-32
DISPLAY ARRAY
statement 4-59, 7-79
DISPLAY FORM statement 7-83
DISPLAY statement 4-59, 7-75
ERROR statement 7-92
INPUT ARRAY statement 7-135
INPUT statement 7-123, 7-129
MESSAGE statement 7-154
OPEN WINDOW
statement 7-160
OPTIONS statement 7-168
PROMPT statement 7-173
Attribute types
AUTONEXT 4-23, 4-57
BLINK 4-26, 4-59, 7-77, I-9, I-27
BOLD 4-59, 7-163, I-27
BORDER 7-163, I-6, I-24
COLOR 4-25, 4-63, E-40
COMMENTS 4-27, 4-57
DEFAULT 4-19, 4-29, 4-57, 7-121,
E-39
DIM 4-59, 7-77, 7-163, I-27
DISPLAY LIKE 4-15, 4-31
DOWNSHIFT 4-32, E-39
FORMAT 4-33, E-41
INCLUDE 4-19, 4-35, 4-57, 7-212,
E-39
INVISIBLE 4-59, 7-77, 7-163, I-27
LEFT 4-26, E-41
NOENTRY 4-37
NORMAL 4-59, 7-154, 7-163
PICTURE 4-38, 4-57
REQUIRED 4-40
REVERSE 4-26, 4-42, 4-59, 7-163,
I-4, I-9, I-27
SHIFT 4-57, E-39
UNDERLINE 4-26, 4-59, I-9, I-27
UPSHIFT 4-43, E-39
VALIDATE LIKE 4-15, 4-45
VERIFY 4-46, 4-57
WORDWRAP 4-21, 4-47
ATTRIBUTES section of form
specification
assigning attributes 4-16
assigning field names 4-16
default values 4-56, 7-168, E-39
definition of 4-16
B
Backup copy of a database 3-45,
3-46
bcheck utility E-2
BEFORE FIELD clause
INPUT ARRAY statement 7-132
BEFORE GROUP OF control block
definition of 5-27
guidelines for using 5-27
BEFORE keyword
ALTER TABLE statement 7-14
INPUT ARRAY statement 7-130
INPUT statement 7-123
REPORT statement 5-27
BEGIN WORK statement
explicit transactions 3-44
syntax and notes 7-18
Bell of a terminal, ringing 2-19,
2-25, 4-38, 7-92
C
C Compiler version of 4GL Intro-3,
1-5, 1-7
C compiler, function 1-32
C functions 1-66, 2-55, 7-19
C language functions in 4GL
programs 1-32, 1-64, 2-55
C shell C-2
c4gl command 1-6, 1-32, 7-7
CALL keyword, WHENEVER
statement 7-213
CALL statement 2-18
passing parameters with 7-111
RETURNING clause 2-56, 7-19
syntax and notes 7-19
with C functions 1-70, 2-58, 7-19
with library functions 6-3
Calling convention for C
functions 2-55
CASE statement 2-19
EXIT CASE 7-96
syntax and notes 7-21
cat utility 1-64, 3-45
cfglgo command 1-66, 1-69
CHAR data type
acceptable values 3-8, 7-50
CHARACTER synonym 2-8, 3-8
subscripts 4-18, 4-19, 7-220
Index 3
Index
Column
adding 7-14
changing column values 3-17,
7-206
changing data type 7-14
constraints 7-16, 7-53
designated as NOT NULL 7-51
determining length 7-52
indexed 3-50, 7-44
joining 7-234, G-1
naming conventions 3-6, 7-51
NULL value in 3-54
removing 7-14
renaming 7-181
virtual 3-59, 7-58
Column data types
CHAR 2-8, 7-50
DATE 2-9, 7-51, C-3
DATETIME 2-9, 7-52, J-1
DECIMAL 2-7, 7-50, F-1
FLOAT 2-8, 7-50
INTEGER 2-7, 7-50
INTERVAL 2-9, 7-52, J-1
MONEY 2-8, 7-50, C-5
SERIAL 7-51, 7-139
SMALLFLOAT 2-8, 7-50
SMALLINT 2-7, 7-50
COLUMN keyword 2-29, 7-181
Columns
in stores database tables A-2
in system catalogs B-1
in upscol tables 4-56, E-37
COLUMNS keyword, OPEN
WINDOW statement 7-160
Comma ( , ) symbol
concatenation operator 2-12,
7-172
in USING format strings 2-44
separator in lists 2-15, I-21
COMMAND clause
MENU statement 7-149
Command file
dbexport E-7
dbload E-12
dbschema E-22
Command line
arguments of a 4GL program 6-5,
6-17
to compile a message file E-28
CONNECT keyword
GRANT statement 7-116
REVOKE statement 7-187
Constant
date-time 2-12, J-1
floating number 2-5
integer 2-5
string 2-5
CONSTRAINT keyword
ALTER TABLE statement 7-14
CREATE TABLE statement 7-49
Constraints 7-139
changing 3-11, 7-16
creating 3-11, 7-53
names 3-7, 7-16, 7-53
owner 3-7, 7-16
CONSTRUCT statement 2-20
NOENTRY fields 4-37
symbols recognized 7-33
syntax and notes 7-32
wildcard characters 7-34
CONTINUE keyword,
WHENEVER statement 2-21,
2-22, 7-213
CONTINUE statement 2-19
FOR 7-105
FOREACH 7-107
MENU 7-152
syntax and notes 7-38
WHILE 7-216
Control blocks 5-23
COUNT aggregate function 3-55,
5-46, 7-249
CPU cost for a query 3-63, 7-194
CREATE AUDIT statement 3-45,
7-39
CREATE DATABASE
statement 3-11
current database 7-41
syntax and notes 7-41
system catalogs 7-41
WITH LOG IN 3-43, 7-42
CREATE INDEX statement 3-12
syntax and notes 7-44
with ASC 7-16, 7-44, 7-53
with DESC 7-44
with UNIQUE and
DISTINCT 7-44
CREATE SYNONYM
statement 3-11, 7-47
CREATE TABLE statement 3-11
assigning data types J-3
guidelines for using 7-49
NOT NULL clause 3-54, 7-51
notes 7-51
owner naming 7-51
syntax 7-49
TEMP keyword 3-58, 7-51
UNIQUE keyword 7-53
WITH NO LOG 7-50
CREATE VIEW statement 3-58
guidelines for using 7-57
owner naming 7-57
syntax and notes 7-57
WITH CHECK OPTION 3-60,
7-58
Currency symbol
default ( = $ ) 2-8, 4-29, C-5
in dbload input files E-12
in format strings 2-47
Current database 3-11
CLOSE DATABASE
statement 7-27
closing 3-11, 7-27
creating 3-11, 7-41
DATABASE statement 7-62
FETCH statement 7-99
selecting 3-11, 7-62
CURRENT function 3-65, 7-258
CURRENT keyword
CURRENT function 2-30, 3-65
DEFAULT attribute 4-30
DELETE statement 3-18, 7-73
FETCH statement 7-98
for a DATETIME value J-13
UPDATE statement 3-19, 7-207
CURRENT OF keywords
DELETE statement 3-18, 7-73
UPDATE statement 3-19, 7-207
Current option of a menu 1-8, 1-37
Current row of a query 3-14, 3-18
Current window 7-23, 7-60, 7-161
CURRENT WINDOW
statement 2-20
syntax and notes 7-60
Cursor 3-13
advancing 3-17, 7-98
closing 3-18, 7-25
declaring 3-14, 7-64
FOR UPDATE 3-17, 7-99, 7-157
non-SCROLLing 3-14
opening 3-17, 7-156
position 3-19, 3-20
scope of reference 2-5, 3-15, 7-67
SCROLL 3-14, 7-65
with CLOSE 3-16, 7-25
with DELETE 3-18
with FETCH 3-16, 7-99
with FOREACH 3-16
with FREE 3-40, 7-109
WITH HOLD 3-14, 3-25, 7-26,
7-65, 7-157
with INSERT 3-25, 7-9, 7-26, 7-65
with OPEN 3-16, 7-156
with SELECT 3-13, 7-64, 7-220
with UPDATE 3-17, 7-99, 7-207
CURSOR keyword
DECLARE statement 3-14
Cursor movement I-22
as determined by FETCH 3-17
as determined by INPUT 7-125
in a menu 7-150
in a screen array 7-80
in a screen form 4-23, 7-35
in a screen record 4-16
Cursor WITH HOLD
BEGIN WORK statement 3-25
COMMIT WORK statement 3-25
DECLARE statement 3-24, 7-65
FETCH statement 3-24
OPEN statement 7-157
customer table in stores
database Intro-11, A-2
Customized runners 1-50, 1-66
CYAN attribute 4-26, 4-59, 7-77,
I-19
D
Data access statements 7-6
GRANT 3-40
LOCK TABLE 3-40
REVOKE 3-40
UNLOCK TABLE 3-40
Index 5
Data conversion
in an INSERT statement 7-140
in an UPDATE statement 7-208
in expressions 2-10, 2-36
Data definition statements 7-6
ALTER INDEX 3-12
ALTER TABLE 3-11
CLOSE DATABASE 3-11
CREATE DATABASE 3-11
CREATE INDEX 3-12
CREATE SYNONYM 3-11
CREATE TABLE 3-11
CREATE VIEW 3-11
DATABASE 3-11
DROP DATABASE 3-11
DROP INDEX 3-12
DROP SYNONYM 3-12
DROP TABLE 3-11
DROP VIEW 3-11
RENAME COLUMN 3-12
RENAME TABLE 3-11
UPDATE STATISTICS 3-12
Data fields E-12
Data integrity statements 3-42, 7-6
Data manipulation statements 7-6
DELETE 3-12, 7-73
INSERT 3-12, 7-138
LOAD 3-12, 7-143
SELECT 3-12, 7-193, 7-218
UNLOAD 3-12, 7-203
UPDATE 3-12, 7-206
Data type
binary large objects
(BLOB) Intro-7
C language 2-55, F-2
changing 7-14
conversion 2-10, 2-36, 7-140
date-time data types J-1
floating decimal point 2-8, 3-9
of columns in a table 3-8, 7-49
of variables 5-7, 7-71, 7-120
of view columns 7-58
storage requirements 7-52
synonyms 2-7
Data types
ARRAY 2-10, 5-8
BYTE Intro-7
CHAR 2-8, 3-8, 4-29, 5-40, 7-50,
E-14
Index
Index 7
Index
E
EBCDIC conversion of ASCII
strings 2-58
Editor blanks (in multiple-line
fields) 4-48
Ellipsis ( . . . ) symbols 7-150
syntax convention Intro-11
ELSE keyword, IF statement 7-118
END keyword
CASE statement 2-19, 7-21
DEFINE statement 7-71
DISPLAY ARRAY statement 7-79
FOR statement 7-104
FOREACH statement 7-106
FORM4GL form specification
file 4-10
FUNCTION statement 7-110
GLOBALS statement 7-112
IF statement 7-118
INPUT ARRAY statement 7-130
MAIN program block 7-148
MENU statement 7-150
PROMPT statement 7-174
REPORT statement 5-20, 7-184
WHILE statement 3-27, 7-216
Environment variable
DBANSIWARN 3-6, 3-64, 7-7, C-2
DBDATE C-3
DBDELIMITER 7-144, 7-203, C-3
F
FALSE (Boolean constant) 2-5, 3-55
FETCH statement
default condition 7-99
examples 3-36
guidelines for using 3-16
NOTFOUND code 3-63, 7-99
syntax and notes 7-98
with SELECT 3-36, 7-224
fgiusr.c file 1-67
fgldb command 1-66
fglgo command 1-6, 1-50, 1-64, 6-4
fglpc command 1-6, 1-61, 7-7
FIELD keyword
INPUT ARRAY statement 7-130
INPUT statement 7-123
Field names in screen forms 4-15,
4-17, 6-14
Field tag 4-9
generated by FORM4GL 4-11
in Boolean expressions 4-25, 4-63
in the ATTRIBUTES section 4-16
in the SCREEN section 4-10, 4-11
naming conventions 4-17
Fields of input records 7-143, E-11
File extensions
.4be 1-36, 1-73
.4bl 1-35, 1-73
.4bo 1-35, 1-73
.4ge 1-10, 1-13, 1-20, 1-35, A-15
.4gi 1-49, 1-54, 1-56, 1-58, 1-64,
1-72
.4gl 1-11, 1-26, 1-32, 1-35, 1-54,
1-55, 1-61, 1-72, A-15
.4go 1-50, 1-54, 1-56, 1-61, 1-62,
1-64, 1-72
.c 1-21, 1-35, 1-69
.dat 3-5, E-2
.dbs 3-5
.ec 1-21, 1-29, 1-32, 1-35, 1-69
Index 9
FLUSH statement
guidelines for using 3-26
status variable and SQLCA
record 3-28
syntax and notes 7-102
FOR keyword
CONTINUE statement 7-38
CREATE AUDIT statement 3-46,
7-39
CREATE SYNONYM
statement 7-47
DECLARE statement 3-25, 7-64
DROP AUDIT statement 7-85
PROMPT statement 7-173
UPDATE STATISTICS
statement 7-210
FOR statement 2-18
EXIT FOR 7-96
syntax and notes 7-104
FOR UPDATE cursor
DECLARE statement 3-17, 7-64
DELETE statement 3-18
FETCH statement 3-19, 7-99
FOREACH statement 3-19
OPEN statement 3-48, 7-157
row-level locking 3-48
FOREACH statement 2-18
CONTINUE FOREACH 7-38
examples 3-16
EXIT FOREACH 7-96
syntax and notes 7-106
Foreground colors 7-168, I-17
FORM Design Menu 1-14, 4-61
FORM keyword
CLEAR statement 7-23
CLOSE FORM statement 7-28
OPEN FORM statement 7-159
OPEN WINDOW
statement 7-160
OPTIONS statement 7-168
FORM LINE keywords
OPEN WINDOW
statement 7-161
OPTIONS statement 7-166
Form specification file, sections of
ATTRIBUTES 4-4, 4-16, 7-167
DATABASE 4-4, 4-7
INSTRUCTIONS 4-51
10
Index
LINENO 5-48
NEED statement 5-38
ON EVERY ROW 5-31
ON LAST ROW 5-33
PAGE HEADER 5-34
PAGE TRAILER 5-36
PAGENO 5-49
PAUSE statement 5-39
PRINT FILE statement 5-42
PRINT statement 5-40
SKIP statement 5-43
SPACE 5-50
TIME 2-41
USING 5-40
WORDWRAP 5-40, 5-51
Format strings
with FORMAT attribute 4-33,
E-41
with PICTURE attribute 4-38
with USING operator 2-44
Formatting a report
automatic page numbering 5-35
default report format 5-21
formatting dates 2-46, C-3
formatting numbers 2-44
grouping data 5-46
page headers and trailers 5-29,
5-34, 5-36
printing column headings 5-35
setting margins 5-12, 5-13, 5-15,
5-16
setting page length 5-17
skipping to top of page 5-43
starting on a new page 5-38
Formatting number
expressions 2-44
Form-only field 4-18, 4-19, 4-22
FORMONLY keyword
ATTRIBUTES section 4-18
DATABASE section 4-7, 4-15
INSTRUCTIONS section 4-54
FRACTION keyword
DATETIME qualifier 3-10, J-2
INTERVAL qualifier 3-10, J-6
FREE statement 3-29, 3-39, 7-109
FROM clause
OUTER keyword 3-62, 7-226, G-3
SELECT statement 3-62, 7-226
table alias 7-235
FROM keyword
CONSTRUCT statement 7-32
DELETE statement 7-73
INPUT ARRAY statement 7-129
INPUT statement 7-122
LOAD statement 7-143
OPEN FORM statement 7-159
PREPARE statement 3-30, 7-171
PUT statement 7-177
REVOKE statement 7-187
SELECT statement 3-62
Function
ASCII 2-25
CLIPPED 2-27
COLUMN 2-29
CURRENT 3-65, 4-30, 7-258, J-13
DATE 2-32
DATE() 2-33, 7-252
DAY() 2-34, 7-253
EXTEND() 2-35, 7-9, 7-260
LENGTH() 2-38, 7-9
MDY() 2-39, 7-254
MONTH() 2-40, 7-9, 7-255
SPACES 5-50
TIME 2-41
TODAY 2-42, 3-65, 4-30, 7-9
USER 3-65
WEEKDAY( ) 2-53, 7-9, 7-256
WORDWRAP 5-51
YEAR( ) 2-54, 7-9, 7-257
Function keys 1-50, I-5, I-23
FUNCTION statement
and variables 2-17
defining a record in 7-111
parameters in 2-17, 7-110
RETURN 7-110, 7-186
syntax and notes 7-110
Functions 2-17
4GL library 2-22, 6-3
aggregate 3-55, 7-249
built-in functions 2-24
C language 1-32, 1-64, 2-55, F-1
calling a function 7-19, 7-111
in an expression 6-3
INFORMIX-ESQL/C 1-32, 1-64
values returned 2-17, 7-111
Index 11
I
i4gl command 1-6, 1-25, 4-61
i4gldemo script Intro-11, 1-6
Identifier
defining 3-28, 4-54, 7-71
distinction between INFORMIX4GL and SQL 3-7
naming conventions 2-4, 4-54
PREPAREd statements 7-67,
7-109
scope of reference 2-4, 7-67, 7-172
IF statement 2-19
relationship to CASE 7-22
syntax and notes 7-118
Implicit transactions 3-6
IN keyword
CREATE AUDIT statement 3-46,
7-39
CREATE DATABASE
statement 3-43
CREATE TABLE statement 7-10,
7-50
LOCK TABLE statement 3-49,
7-146
SELECT statement 7-230
START DATABASE
statement 3-43
INCLUDE attribute 4-57
definition of 4-35
guidelines for using 4-35
specifying values in 7-212
Index
ascending and descending 7-53
auto_indexing 3-52
check and repair index files E-2
clustered 3-52, 7-12, 7-45
creating the index 7-44, E-22
filters 3-52, 7-194
guidelines for using 3-50
multiple-column 7-16, 7-44
NULL value 3-54
removing from a database 7-88
UNIQUE 7-44, 7-53, 7-139
with dbload utility E-20
INDEX keyword
GRANT statement 7-115
REVOKE statement 7-187
12
Index
J
Joins 4-63, 7-234
columns with the same
name 7-235, G-1
in definition of a view 3-59
multiple joins 7-235, G-5
NULL column values 3-56, G-3
outer join 3-61, 7-235, G-1
self-join 7-235
stores database columns A-5
K
Kernel locking 3-50, 7-197
Key
Accept key 7-34, 7-124, 7-166
arrow keys 7-35, 7-125
function keys 7-125, 7-133, 7-167
Help key 7-129, 7-166, E-27
Interrupt 2-23, 7-34, 7-152
Quit 2-23, 7-69
restricted 7-125
scrolling and editing 7-35, 7-166
used in screen arrays 7-131, 7-166
KEY keyword
INPUT ARRAY statement 7-132
INPUT statement 7-123
MENU statement 7-149
OPTIONS statement 7-166
Keywords, notation in syntax
statements Intro-10
L
LABEL statement
GOTO 2-19, 7-114, 7-141, 7-213
syntax and notes 7-141
LAST keyword
FETCH statement 3-23, 7-98
OPEN WINDOW statement
7-161
OPTIONS statement 7-167
REPORT statement 5-33
LEFT attribute 4-26
LEFT MARGIN statement 5-12
LENGTH keyword
LENGTH( ) function 2-38, 6-16,
7-251
PAGE LENGTH statement 5-17
Less ( < ) than symbol
in USING format strings 2-44
relational operator 2-13, 7-33
REVERSE attribute 4-42
LET statement 2-17
CLIPPED 2-27, 3-31
examples 2-38
syntax and notes 7-142
USING 2-46
with string expressions 2-8
Library functions (INFORMIX4GL)
arg_val 6-4
arr_count 6-6
arr_curr 6-7
downshift 6-9
errorlog 6-13
err_get 6-10
err_print 6-11
err_quit 6-12
infield 6-14, 7-126, 7-134
length 6-16, 7-251
num_args 6-17
scr_line 6-18
set_count 6-20
showhelp 6-21
startlog 6-23
upshift 6-25
LIFO (last-in, first-out) queue 2-55
LIKE data type specification 7-138
Index 13
LIKE keyword
DEFINE statement 2-10, 7-71
DISPLAY LIKE attribute 4-31
FORMONLY fields 4-19
GLOBALS statement 7-112
INITIALIZE statement 7-120
RECORD data type 2-9
SELECT statement 2-13, 7-231
VALIDATE LIKE attribute 4-45
VALIDATE statement 2-24, 7-211
WHERE clause 7-231
LINE keyword
OPEN WINDOW
statement 7-161
OPTIONS statement 7-165
SKIP statement 5-43
Line mode of a terminal 7-175
LINENO expression 5-48
LINES keyword
NEED statement 5-38
SKIP statement 5-43
LOAD statement 3-29, 7-143
Local variables 2-4, 5-7
LOCK TABLE statement 3-40, 3-47
syntax and notes 7-146
Locking
guidelines for using 3-47
row-level 3-48, 7-139, 7-146
table-level 3-49, 7-146, E-19
LOG keyword
CREATE DATABASE
statement 3-43
CREATE TABLE statement 7-50
SELECT statement 7-245
START DATABASE
statement 3-43
Logging
error messages 6-23, E-19
of temporary tables 7-50
transactions 3-43
LOOKUP attribute of
PERFORM 4-63
Looping statements 5-4
FOR 2-18, 7-38, 7-104
FOREACH 2-18, 3-16, 7-106
WHILE 2-19, 3-27, 7-216
Lowercase characters
DOWNSHIFT attribute 4-32, E-39
downshift function 6-9
14
Index
M
MAGENTA attribute 4-26, 4-59,
I-19
MAIN statement
description 2-17
in source-code modules 1-33
syntax and notes 7-148
manufact table in stores
database Intro-11, A-4
MARGIN keyword
BOTTOM MARGIN
statement 5-16
LEFT MARGIN statement 5-12
RIGHT MARGIN statement 5-13
TOP MARGIN statement 5-15
WORDWRAP function 5-40
MATCHES keyword, in WHERE
clause 4-58, 7-8, 7-33, 7-232
MAX aggregate function 3-64, 5-46,
7-249
MDY function 2-39, 7-254
Menu options of Programmers
Environment 1-7, 1-30
MENU statement
CONTINUE MENU 7-38
description 2-19
EXIT MENU 7-96
help messages 7-151
syntax and notes 7-149
Menu-building utility 7-149
Menu, programmer-defined
creating 7-149
displaying options 7-38, 7-151
naming menu options 7-150
requesting help from 7-151
selecting options 7-152
Message line 2-19, 7-154
MESSAGE LINE keywords
OPEN WINDOW
statement 7-161
OPTIONS statement 7-154, 7-165
Module 2-18
compiling 1-13, 1-42
option of INFORMIX-4GL
Menu 1-9, 1-38
running multi-module
programs 1-13, 1-42, 1-65
MODULE Menu 1-26, 1-55
Module variables 2-4
MONEY data type
acceptable values 3-9, 7-50
in dbload input files E-12
with database columns 3-9
with display fields 4-29, C-5
with variables 2-8, 7-71
MONTH keyword
DATETIME qualifier 3-10, J-2
INTERVAL qualifier 3-10, J-5
MONTH( ) function 2-40, 7-9,
7-255
Multiple-column fields 4-21, 4-34,
4-42
Multiple-database queries Intro-7
Multiple-line fields 4-20, 4-47
Multiple-module programs,
compiling 1-13, 1-27, 1-41, 1-50,
1-56, 1-64
Multiple-statement prepared
objects 3-38, 7-172
Multiple-table forms 4-56
Multiple-table view 3-60, 7-58
N
Naming conventions
column 3-6, 7-51
constraints 3-7, 7-49
database 3-6, 7-41
display fields 4-17, 4-18, 4-22
field tags 4-11
identifiers 2-4, 3-6
objects in a MODE ANSI
database 3-7
table 3-6, 7-51
NEED statement in REPORT
statement 5-38
New option
FORM Menu 1-17, 1-46
MODULE Menu 1-12, 1-41
NULL values
aggregate functions 3-55, 3-64,
5-46, 7-250
assigning 7-120
definition of 2-5, 3-53
in Boolean expressions 2-14, 3-55,
7-118, 7-229
in columns 3-54, 7-144, 7-234
in display fields 4-19, 4-29, 4-40
in GROUP BY clause 3-56, 7-240
in joined columns 3-56, G-3
in number expressions 3-54
in ORDER BY clause 3-56
in string expressions 3-54, 4-29
in WHERE clause 3-55, 7-228
NOT NULL clause 3-54, 7-51,
7-228
truth tables 3-55
with dbload utility E-12
with INSERT 3-57
with UPDATE 3-57
WITHOUT NULL INPUT 4-7
Number expression 2-11
arithmetic operators in 2-11
formatting 2-44, 4-33
NULL values in 3-54
Number of rows processed 3-63
NUMERIC data type 2-8, 3-9
num_args function 6-17
O
O symbol Intro-11
Object file 1-35, 1-50, 1-72, E-30
Object, naming in MODE ANSI
database 3-7
OF keyword
AFTER GROUP OF control
block 5-25
ARRAY data type 2-10
BEFORE GROUP OF control
block 5-27
DECLARE statement 3-17, 7-64
DELETE statement 3-18, 7-73
UPDATE statement 3-19, 7-207
OFF keyword, SET EXPLAIN 7-194
ON EVERY ROW control
block 5-31
Index 15
ON KEY clause
DISPLAY ARRAY
statement 7-60, 7-79
INPUT ARRAY statement 7-130
INPUT statement 6-22, 7-123
PROMPT statement 7-173
ON keyword
CONSTRUCT statement 7-32
DISPLAY ARRAY statement 7-79
GRANT statement 7-115
PROMPT statement 7-173
REPORT statement 5-8
REVOKE statement 7-187
SET EXPLAIN statement 3-52,
7-194
ON LAST ROW control block 5-33
OnLine database engine Intro-6,
7-7, C-7
OPEN FORM statement 2-20
opening a closed form 7-28
syntax and notes 7-159
OPEN statement
syntax and notes 7-156
USING clause 3-36, 7-157
with a SELECT cursor 3-16
with an INSERT cursor 3-26,
7-157
OPEN WINDOW statement 2-20
ATTRIBUTE clause 7-161
syntax and notes 7-160
Operating system
invoking the Compiler from 1-32,
1-61
invoking the Programmers
Environment from 1-25, 1-30,
1-54, 1-59
Operator
arithmetic 2-11
range 7-34, 7-233
relational 2-13
string 2-12
UNION 7-246
OPTION keyword
CREATE VIEW statement 3-60,
7-57
GRANT statement 7-116
MENU statement 7-150
Options of 4GL menus 7-150
16
Index
START DATABASE
statement 7-200
VALIDATE statement 7-211
Owner of an object in a MODE
ANSI database 4-4, 4-60, 7-16,
7-35
P
PAGE HEADER control block 5-29,
5-34
PAGE keyword
FIRST PAGE HEADER control
block 5-29
PAGE HEADER control
block 5-34
PAGE LENGTH statement 5-17
PAGE TRAILER control
block 5-36
SKIP statement 5-43
PAGE LENGTH statement 5-17
PAGE TRAILER control block 5-36
PAGENO expression 5-49
Pages
of a help file message E-28
of a report 5-9
of a screen form 4-9, 4-63
of menu options 7-150
Parameters of functions 2-56, 7-110
Parentheses
in syntax statements Intro-10
in USING format strings 2-45
Pattern matching
query by example 7-33
with equal ( = ) sign 7-33
with LIKE 2-13, 7-231
with MATCHES 2-13, 7-232
PAUSE statement, REPORT
statement 5-39
P-code compiler, function 1-61
P-code runner 1-61
customized 1-68, 1-69
Interactive Debugger 1-59
specifying name and
location 1-50
P-code version number 1-62, 1-64
PERCENT aggregate function 5-46
PERFORM (INFORMIX-SQL)
screens with INFORMIX4GL 4-3, 4-63
Period ( . ) symbol
delimiter in DATETIME
values 2-6, E-12
delimiter in INTERVAL
values 2-6, E-12
in help message source files E-27
in USING format string 2-45
prefix separator 2-24, 4-14
range operator 7-34
PICTURE attribute 4-38, 4-57
PIPE keyword
REPORT TO statement 5-10
START REPORT statement 7-202
Planned_Compile option,
PROGRAM Menu 1-23, 1-52
Plus ( + ) sign
arithmetic operator 2-11, 7-219
in USING format strings 2-45
in window border 7-163, I-6
unary operator 2-5, 2-6
Popping functions (C
language) 2-55
Pound ( # ) sign
comment indicator 2-3, I-3
in FORMAT format strings 4-33
in PICTURE format strings 4-38
in USING format strings 2-44
PREPARE statement 3-28
executing 3-33, 7-94
guidelines for using 3-28
multiple SQL statements 3-38,
7-172
syntax and notes 7-171
using placeholders for
values 3-30
with a character string 3-30
with a character variable 3-31
Preprocessor, invoking 1-31, 1-32
Previous key 7-166, I-5, I-23
PREVIOUS keyword
FETCH statement 3-23, 7-98
OPTIONS statement 7-166
PRINT FILE statement in
reports 5-42
PRINT statement
CLIPPED 2-27
COLUMN 2-29
REPORT statement 5-40
USING 2-48
PRINTER keyword
REPORT TO statement 5-10
START REPORT statement 7-202
PRIOR keyword, FETCH
statement 3-17, 7-98
PRIVILEGES keyword 7-115
Process isolation Intro-7
Program array
array of records 2-10
arr_count function 6-6
arr_curr function 6-7
defining 2-10, 7-71
displaying rows in 7-79
inserting rows 7-131
set_count function 6-20
table of functions for 7-135
Program examples
that call C functions 1-70, 2-57
Program execution
commencing 1-59, 1-65, 6-4, 6-17
from the command line 1-6, 6-4
programs that call C
functions 1-34, 1-66
terminating 6-12, 7-97
with the Interactive
Debugger 1-65, 1-72
Program features
assignment statements 2-17
calling C functions 1-66, 2-55,
7-19
commenting 2-3
compiler 1-25, 1-32, 1-39
compiling through Programmers
Environment 1-10, 4-60
compiling, at operating system
level 1-61
conditional statements 4-25, 7-21,
7-118
error messages 2-21, 6-10, E-29
executing a non-4GL
process 7-191
expressions 2-11
functions 2-24, 2-55, 6-3, 7-110
help messages 6-21, 7-166, E-27
identifiers 2-4
INFORMIX-4GL language
overview 2-3
lettercase sensitivity 4-11
looping statements 3-24
MAIN program block 2-17, 7-148
menus 7-149
multi-module programs 1-13,
1-41
owner naming 4-15
program arrays 2-10
program flow statements 2-18,
7-5
records 4-54, 7-71, 7-138
reports 2-21, 5-3, 7-184
running, at operating system
level 1-64
screen interaction
statements 2-19, 7-165
statement types 2-16, 3-10, 7-5
transactions 3-42
types of program modules 1-10,
1-21, 1-29, 1-32, 1-50, 1-69
Program flow statements 2-18, 7-5
Program module, definition of 2-18
Program organization
statements 2-17, 7-5
Program records 7-72, 7-138
Program specification
database 1-18, 1-48
Programmers Environment
accessing 1-6, 1-7, 1-37
COMPILE FORM Menu 1-16,
1-45
COMPILE MODULE Menu 1-10,
1-39
COMPILE PROGRAM
Menu 1-22, 1-51
compiling a form 1-27, 1-56, 4-61
compiling a program 1-12, 1-27,
1-41, 1-56
correcting errors in a
program 1-11, 1-40
creating a default form 4-61
Debug option, MODULE
Menu 1-42
Debug option, PROGRAM
Menu 1-53
defining a program 1-26, 1-55
definition of 1-6
Index 17
18
Index
PUBLIC keyword
GRANT statement 3-41, 7-52,
7-116
REVOKE statement 7-52, 7-188
Pushing functions (C
language) 2-55
PUT statement
and the SQLCA record 3-28,
7-178
and the status variable 3-28, 7-178
FROM clause 3-38
guidelines for using 3-26, 7-26
syntax and notes 7-177
Query by example
CONSTRUCT 7-33
PREPARE 3-30
table of operators 7-33
using the alternation
operator 7-33
using the range operator 7-34
using wildcard characters 7-34
Query optimizer 3-52, 7-194
QUERYCLEAR attribute of
PERFORM 4-63
Querying the database
compound queries 7-246
cursors 3-13, 7-64, 7-156
distributed across
databases Intro-7
joins 3-51, 4-63, 7-234, G-1
query by example 7-32
relational operators 7-220
searching for rows with NULL
values 3-56
subqueries 3-56, 7-207, 7-237
through views 3-58
with SELECT 7-218
Question ( ? ) mark
placeholder in PREPAREd
statements 3-30, 7-94, 7-171,
7-178
wildcard 7-34, 7-232
Quick Reference Card Intro-3
Quit key 2-23, 7-69
Reserved lines
Comment line 4-27, 7-165
default settings 7-161
Error line 2-19, 2-23, 6-11, 6-12,
7-162, 7-165
Form line 2-20, 7-162, 7-166
Message line 2-19, 7-165
Prompt line 2-19, 7-165
Reserved words
listing D-1
RESOURCE access privilege 7-116
RESOURCE keyword
GRANT statement 3-41, 7-116
REVOKE statement 7-187
Return key 7-166
RETURN keyword
FUNCTION statement 7-110
RETURN statement 7-186
RETURNING keyword
CALL statement 2-56, 7-19
RUN statement 7-191
REVERSE attribute 4-26, 4-59, I-9
description of 4-42
multiple-column 4-21
REVOKE statement 3-40
DBA 3-41
syntax and notes 7-187
RIGHT attribute of PERFORM 4-63
RIGHT MARGIN statement 5-13
Ring menu 7-150
ROLLBACK WORK statement
restoring previous database 3-42
syntax and notes 7-189
ROLLFORWARD DATABASE
statement
definition of 3-42
recovering a database 3-45
syntax and notes 7-190
Row 3-5
deleting from a table 3-18, 7-73
determining row length E-24
duplicates in a view 3-60
inserting into a table 7-138
locking 3-48, 7-99, 7-139
ROWID 3-62
unlocking 3-48
updating 3-19, E-38
ROW keyword
EVERY ROW statement 5-21
INPUT ARRAY statement 7-130
ON EVERY ROW control
block 5-31
ON LAST ROW control
block 5-33
Row number
in a database table 3-62
in a program array 6-7, 6-20
in a screen array 4-55, 6-18
ROWID value 3-62, 3-64
ROWS keyword, OPEN WINDOW
statement 7-160
Run menu option 1-31, 1-61
Run option
MODULE Menu 1-13, 1-42
PROGRAM Menu 1-24, 1-52
RUN statement 2-19, 7-191
Runner, creating a customized 1-69
Runner, invoking 1-5, 1-50, 1-61
Running a 4GL program
command line 1-6, 1-34
that calls C functions 1-34, 1-72
using Debugger 1-61, 7-7
Run-time errors 2-21, 7-213
S
Schema language 7-10
Schema replication, using
dbschema E-22
Scope of reference of identifiers 2-5
Screen array 7-32, 7-75
definition of 4-55
format of 4-12, 4-56
identifying the current row 6-7,
6-18
keys for scrolling and
editing 7-131
scrolling rows of data 7-192
table of functions for 6-3, 7-135
Screen display characteristics
changing attributes 4-59, 7-36,
7-77, 7-81, 7-83, 7-93, 7-127,
7-136, 7-155, 7-168, 7-175
clearing the screen 7-23, I-4, I-22
Index 19
20
Index
SECOND keyword
DATETIME qualifier 3-10, J-2
INTERVAL qualifier 3-10, J-6
SELECT clause
ALL 7-222
display label 7-8, 7-222
DISTINCT and UNIQUE
keywords 7-222
join conditions 7-234, G-1, G-4
syntax and notes 7-222
SELECT cursor
advancing 3-17
closing 3-17, 7-25
declaring 3-14, 7-64
opening 3-16, 7-156
syntax and notes 3-13, 7-64
SELECT keyword
dbload command file E-12
DECLARE statement 3-14, 7-64
GRANT statement 3-41, 3-60,
7-115, 7-204
REVOKE statement 3-41, 7-187
SELECT statement
aggregate functions in 7-249
arithmetic operators in 7-219
assigning a cursor 3-14, 7-64
constructing with LET 7-172
creating temporary tables 7-8,
7-245
DATETIME or INTERVAL
values J-15
defining a view 3-58, 7-57
definition of 3-12, 7-193
displaying results 5-3
distributed across
databases Intro-7
estimating CPU cost 3-52, 7-194
expression in 7-219
FROM clause 7-226
functions in 2-24, 7-248
GROUP BY clause 7-8, 7-240
HAVING clause 7-242
in a DECLARE statement 7-64
in an INSERT statement 7-138
in an UNLOAD statement 7-203
INTO clause 3-29, 7-99, 7-107,
7-224
INTO TEMP clause 3-58, 7-8,
7-245
Index 21
SQLCA record
definition of 3-63
examined by WHENEVER 2-22
set by CLOSE 3-28
set by FLUSH 3-28
set by PUT 3-28, 7-178
SQLAWARN 3-6, 3-64, 7-213
SQLCODE 3-17, 3-63, 7-145, 7-178
SQLERRD 3-28, 3-63, 7-25, 7-145,
7-157
sqlconv utility E-31
SQLERROR keyword 7-213
SQLEXEC environment
variable C-7
SQLWARNING keyword 7-213
Stack, in calling C functions 2-55
START DATABASE statement 3-42
syntax and notes 7-200
WITH LOG IN 3-43
START REPORT statement 2-21
directing output 5-10
syntax and notes 7-202
startlog function 2-22, 6-23
state table in stores
database Intro-12, A-4
Statement identifier 3-28, 7-94,
7-109
Statement label 7-114, 7-141, 7-213
Statement syntax
ALTER INDEX 7-12
ALTER TABLE 7-14
BEGIN WORK 7-18
CALL 7-19
CASE 7-21
CLEAR 7-23
CLOSE 7-25
CLOSE DATABASE 7-27
CLOSE FORM 7-28
CLOSE WINDOW 7-30
COMMIT WORK 7-31
CONSTRUCT 7-32
CONTINUE 7-38
CREATE AUDIT 7-39
CREATE DATABASE 7-41
CREATE INDEX 7-44
CREATE SYNONYM 7-47
CREATE TABLE 7-49
CREATE VIEW 7-57
CURRENT WINDOW 7-60
22
Index
DATABASE 7-62
DECLARE 7-64
DEFER 7-69
DEFINE 7-71
DELETE 7-73
DISPLAY 7-75
DISPLAY ARRAY 7-79
DISPLAY FORM 7-83
DROP AUDIT 7-85
DROP DATABASE 7-86
DROP INDEX 7-88
DROP SYNONYM 7-89
DROP TABLE 7-90
DROP VIEW 7-91
ERROR 7-92
EXECUTE 7-94
EXIT 7-96
FETCH 7-98
FINISH REPORT 7-101
FLUSH 7-102
FOR 7-104
FOREACH 7-106
FREE 7-109
FUNCTION 7-110
GLOBALS 7-112
GOTO 7-114
GRANT 7-115
IF 7-118
INITIALIZE 7-120
INPUT 7-122
INPUT ARRAY 7-129
INSERT 7-138
LABEL 7-141
LET 7-142
LOAD 7-143
LOCK TABLE 7-146
MAIN 7-148
MESSAGE 7-154
OPEN 7-156
OPEN FORM 7-159
OPEN WINDOW 7-160
OPTIONS 7-165
OUTPUT TO REPORT 7-170
PREPARE 7-171
PROMPT 7-173
PUT 7-177
RECOVER TABLE 7-179
RENAME COLUMN 7-181
RENAME TABLE 7-182
REPORT 7-184
RETURN 7-186
REVOKE 7-187
ROLLBACK WORK 7-189
ROLLFORWARD
DATABASE 7-190
RUN 7-191
SCROLL 7-192
SELECT 7-193, 7-218
SET EXPLAIN 7-194
SET LOCK MODE 7-197
SLEEP 7-199
START DATABASE 7-200
START REPORT 7-202
UNLOAD 7-203
UNLOCK TABLE 7-205
UPDATE 7-206
UPDATE STATISTICS 7-210
VALIDATE 7-211
WHENEVER 7-213
WHILE 7-216
Statement type
assignment 2-17, 7-5
cursor manipulation 3-13, 7-6
data access 3-40, 7-6
data definition 3-11, 7-6
data integrity 3-42, 7-6
data manipulation 3-12, 7-6
data validation 2-23
dynamic management 3-28, 7-6
error and exception
handling 2-21
program flow 2-18, 7-5
program organization 2-17, 7-5
report generation 2-21, 7-5
screen interaction 2-19, 7-5
variable definition 2-17, 7-5
status variable 2-22
definition of 3-63
NOTFOUND code 2-22, 3-17,
3-22, 7-99, 7-213
with cursors 3-28
with err_get function 6-10
with err_print function 6-11
with err_quit function 6-12
with INITIALIZE 7-121
with VALIDATE 7-212
STEP keyword, FOR
statement 7-104
schema 4-57
use by FORM4GL 4-17, 4-56
with DISPLAY LIKE 4-31
syscolval table 2-24, 4-56
as used by INITIALIZE 4-58,
7-121
comparing values of
variables 7-211
creating with upscol 4-60, E-37
data validation 2-23, 4-58, 7-211
schema 4-57
use by FORM4GL 4-17, 4-56
with VALIDATE LIKE
attribute 4-45
syspgm4gl files 1-18, 1-48
System catalogs
creating 3-11, 7-41
described 3-5, B-1
querying when MODE ANSI 3-8
syscolauth B-3
syscolumns 3-58, 7-138, B-2
sysconstraints 7-16, 7-53, B-5
sysdepend B-4
sysindexes B-3
syssynonyms B-4
syssyntable B-5
systabauth B-3
systables 4-15, 7-210, B-2
sysusers B-4
sysviews 3-58, B-5
updating 3-12
T
Table 3-5
access methods 3-52, 7-194
access privileges 3-41, 7-115, E-22
adding a column 7-14
adding a constraint 7-16
adding a row 7-138, 7-143, E-11
alias for table name 4-14, 4-60,
7-35, 7-226
audit trails 3-42, 7-39
changing the data type of a
column 7-14
creating 7-49, E-22
creating a synonym 7-47, E-22
current 4-63
Index 23
24
Index
U
Undefine option, PROGRAM
Menu 1-53
UNDERLINE attribute 4-26, 4-59,
I-9
UNION operator 3-58, 7-58, 7-246
UNIQUE constraint 7-139, E-14
UNIQUE keyword
aggregate functions 7-250
ALTER TABLE statement 7-14
CREATE INDEX statement 7-44
CREATE TABLE statement 7-49
SELECT statement 7-8, 7-222
UNITS keyword 2-43, 4-30, J-13
SELECT statement 7-8
UNIX permissions E-14
UNKNOWN (Boolean
constant) 2-14, 3-55
UNLOAD statement 3-29, 7-203,
E-11
UNLOCK TABLE statement 3-40,
3-47
syntax and notes 7-205
UP keyword
SCROLL statement 7-192
syscolval table 4-57, E-39
UPDATE keyword
DECLARE statement 3-17, 7-64
GRANT statement 3-41, 7-115
REVOKE statement 7-187
UPDATE STATISTICS
statement 7-210
UPDATE statement
data conversion in 7-208
DATETIME or INTERVAL
values J-15
examples 3-18
functions in 7-248
locking rows 3-48
subqueries 7-207
syntax and notes 7-206
updating through a view 3-59
WHERE CURRENT OF
clause 3-19
with NULL values 3-57
UPDATE STATISTICS
statement 3-12, 7-210
UPDATE SYSCOL Menu
(upscol) E-37
Uppercase characters
DOWNSHIFT attribute 4-32, E-39
downshift function 6-9
in 4GL statements 2-3, 4-11
in syntax statements Intro-10
SHIFT attribute 4-57, E-39
UPSHIFT attribute 4-43, E-39
upshift function 6-25
upscol utility 2-24, 4-59, E-37
UPSHIFT attribute 4-43, 7-35, E-39
upshift function 6-25
USER function 3-65, 7-219
User status and privileges 3-41
USING keyword
DISPLAY statement 7-76
EXECUTE statement 3-33, 7-94
OPEN statement 3-36, 7-156
PRINT statement 2-47, 5-40
string operator 2-44
Utility programs
bcheck E-2
dbexport E-6
dbload E-11, E-33
dbschema E-22
dbupdate E-25
mkmessage E-27
sqlconv E-31
upscol 2-24, 4-56, E-37
V
V command-line option 1-33, 1-62
VALIDATE LIKE attribute 4-15,
4-45
VALIDATE Menu (upscol) E-39
VALIDATE statement 2-24, 4-58,
7-211
VALUES keyword
dbload command file E-14
INSERT statement 7-138
VARCHAR data type Intro-7
Variable 2-6
as a parameter 2-17, 7-110
binding to database and
forms 2-14
data types 2-7, 7-71
declaring a 2-4, 5-5, 7-71
global 2-4, 7-112
in REPORT statement 5-5
int_flag 2-23, 7-69
local 2-4, 7-110
module 2-4
naming conventions 2-4
quit_flag 2-23, 7-69
scope of reference 2-4
statements for assigning
values 2-17
statements for defining 2-17
status variable 2-22, 3-63
with the same name 7-111
Variable definition statements 7-5
VERIFY attribute 4-46, 4-57
Version 1 database
conversion to Version 2 E-25
Version numbers of SQL
software 1-33, 1-62
Versions of 4GL Intro-3, 1-5
Vertical ( | ) bar
field separator in files 7-203, E-17
field separator in forms 4-53
graphics character 4-13, I-6, I-25
in termcap specifications I-3
in window border 7-163, I-6
syntax convention Intro-10
with CONSTRUCT 7-33
View
access privileges 3-60, 7-117, E-22
creating 3-58, 7-57, E-22
creating a synonym 7-47, E-22
data constraints 3-60
definition and uses 3-57, 7-57
deleting 3-58, 7-91
guidelines for naming 7-58
limitations 3-58, 7-16, 7-57
modifying the database
through 3-59
querying the database
through 3-58
W
WAIT keyword, SET LOCK MODE
statement 3-50, 7-197
WARNING keyword, WHENEVER
statement 2-22, 3-64, 7-213
Warning messages 1-33, 7-7, 7-213
WEEKDAY function 2-53, 7-256
WHEN keyword, CASE
statement 7-21
WHENEVER statement
ERROR keyword 2-22
guidelines for using 2-22
scope of reference 2-22, 7-214
syntax and notes 7-213
trapping errors 2-22, E-29
trapping warnings and NOT
FOUND 2-22
WARNING keyword 2-22, 7-213
WHERE clause
aggregate functions 5-47, 7-248
ALL 7-237
AND 7-234
ANY 7-237
BETWEEN 3-65, 7-229
comparison condition 7-228
ESCAPE 7-231, 7-233
EXISTS 7-238
IN 7-230, 7-238
IS NULL 7-234
joining columns in 7-234, G-1
LIKE 7-231
MATCHES 7-8, 7-232
NOT 7-218
NULL values 3-55, 7-234
OR 7-234
pattern matching in 7-34, 7-232
ranges in 7-34, 7-229
relational operators in 2-13, 7-229
search conditions 7-34, 7-218,
7-228
sets in 4-58, 7-230
SOME 7-237
syntax and notes 7-228
Index 25
26
Index
X
X symbol in PICTURE format
strings 4-38
xmc1 terminal specification 7-77,
7-127, 7-136, 7-176, I-21
XOFF key 7-125
Y
Y symbol
formatting DATE values 2-46,
C-3
option of bcheck utility E-3
values in syscolatt table 4-58, E-40
YEAR keyword
DATETIME qualifier 2-9, 3-10,
4-20, E-12, J-2, J-5
INTERVAL qualifier 2-9, 3-10
with CURRENT function 2-31,
2-36, 7-259
with EXTEND function 2-36,
7-260
with UNITS keyword 2-43, J-15
YEAR( ) function 2-54, 7-9, 7-257
YELLOW attribute 4-26, 4-59, 7-77,
I-19
YES keyword in syscolval
table 4-57, E-39
Z
ZA function (termcap file) I-9, I-17
Zero
default INTERVAL value 4-7, J-9
default number value 4-19
for Boolean FALSE 2-14
inserting SERIAL values 7-139
value of status variable 2-22,
7-213
zero fill ( & ) character in output
fields 2-46
Zero or more characters, symbol
for 7-34, 7-231, 7-232
ZEROFILL attribute of
PERFORM 4-63