Вы находитесь на странице: 1из 28

Module

3
Informix 4GL The Programmer’s
Environment
Objectives
At the end of this module, you will be able to:
„ Navigate through the Informix 4GL Programmer’s Environment menu
„ Choose the appropriate menu option for a given task
„ Use the alternative command-line options to create programs

The Programmer’s Environment 1214 07-99 3-1


 2000 Informix Software, Inc.
Accessing the Programmer's Environment

i4gl

r4gl

The Programmer’s Environment 1214 07-99 2

There are two ways to enter the Programmer's Environment. The method you use
depends on which type of Informix 4GL you have: 4GL Rapid Development
System or the C Compiler Version.
Informix 4GL C Compiler Version
To access the menu system for the Informix 4GL C Compiler Version, enter the
following at the system prompt:
i4gl
This will take you into the main menu, as shown on the next page.
Informix 4GL Rapid Development System
To access the menu system for the Informix 4GL Rapid Development System, enter
the following at the system prompt:
r4gl
This will also take you into the main menu.
Differences in the Menus
The following pages describe the menu environment of Informix 4GL. There are a
few differences between the Informix 4GL Rapid Development System and the
Informix 4GL C Compiler Version. These differences will be pointed out as you go
through this module.

Informix 4GL The Programmer’s Environment 3-2


Informix 4GL Menu

Informix-4GL: Module Form Program Query-language Exit


Create, modify, or run individual 4GL program modules.
-------------------------------Press CTRL-W for Help-----------

The Programmer’s Environment 1214 07-99 3

At the top menu level of Informix 4GL, there are five options:
Module Takes you to the Module menu of an Informix 4GL
program module.
Form Takes you to the Form menu for a screen form.
Program Allows you to specify the components of a multi-module
program.
Query-language Allows you to use SQL interactively.
Exit Returns you to the operating system.

Note You must have purchased the Informix-SQL product in order for the
Query-language option to work.

Informix 4GL The Programmer’s Environment 3-3


The MODULE Menu

Informix 4GL RDS


MODULE: Modify New Compile Program_Compile Run Debug Exit
Change an existing 4GL program module.
-----------------------------Press CTRL-W for Help-------------

Informix 4GL Compiled


MODULE: Modify New Compile Program_Compile Run Exit
Change an existing 4GL program module.
-------------------------------Press CTRL-W for Help-----------

The Programmer’s Environment 1214 07-99 4

The MODULE menu is used to create all the modules that will be needed for your
program. The options available are:
Modify Allows you to make changes to an existing module. If you
select this option, you will be asked to choose a module
from a given list and will then be placed into an editor.
When you are finished editing the module, you will go
through the compilation menus.
New Asks you to assign a name for a module, and then places
you in your editor. When you have finished writing your
new module, you will go through the compilation menus.
Compile Asks you to choose a file and then takes you through the
compilation menus.
Program_Compile Is the same as the Compile option of the PROGRAM
menu. It permits you to compile and link modules, as
described in the program specification database.
Run Presents a list of executable programs.
Debug allows you to choose a runable module to execute through
the Informix 4GL Interactive Debugger.

Informix 4GL The Programmer’s Environment 3-4


The Debug option is only available in the Informix 4GL RDS version of the product.
The Debug option will only work if the Interactive Debugger has been purchased
and installed.

Informix 4GL The Programmer’s Environment 3-5


The FORM Menu

FORM: Modify Generate New Compile Exit


Change an existing form specification.
-------------------------------Press CTRL-W for Help-----------

The Programmer’s Environment 1214 07-99 6

The FORM menu is used to create forms that can be displayed to the user. The
options available are described below:
Modify Allows you to change the look and functionality of a
form.
Generate Creates a default form.
New Takes you into an empty file where you can create a form.
Compile Translates an English-like form specification into
something the computer can use.
Exit Returns to the Informix 4GL Menu.

Informix 4GL The Programmer’s Environment 3-6


The Compilation Menus
Menu Sequence:
Errors in Code
MODIFY MODULE: Compile Save-and-exit Discard-and-exit
First Compile the 4GL module specification.
COMPILE MODULE: Object Runable Exit
Second Create an object file (.4go suffix)

COMPILE MODULE: Correct Exit


Third Correct errors in the 4GL module.

Menu Sequence:
No Errors in Code
MODIFY MODULE: Compile Save-and-exit Discard-and-exit
First Compile the 4GL module specification.
COMPILE MODULE: Object Runable Exit
Second Create an object file (.4go suffix)
MODIFY MODULE: Compile Save-and-exit Discard-and-exit
Third Save the 4GL module and return to MODULE Menu.

The Programmer’s Environment 1214 07-99 7

Once you have created or changed a module, you will be taken through the
compilation menus. The compilation menus are used to compile your Informix
4GL code into either an executable program or a linkable module.
The First Menu
The first menu consists of three choices:
Compile Takes you to the second menu, as shown above.
Save-and-exit Saves the changes made during the last editing session,
but does not try to compile them.
Discard-and-exit Discards the changes made during the last editing session.
(This option does not delete your file, providing you have
saved it at least one time.)
The Second Menu
The second menu consists of three choices:
Object Should be selected when the module is part of a multiple
module program.
Runable Should be selected when the module is a self contained
program. (It must have at least a MAIN function.)
Exit returns you to the first menu.
Informix 4GL The Programmer’s Environment 3-7
The Third Menu
The third menu consists of two choices:
Correct Returns you to the editor and points out errors in your
code. Once you have made corrections, you are returned
to the first menu.
Exit Returns you to the first menu.

Informix 4GL The Programmer’s Environment 3-8


The PROGRAM Menu

Informix 4GL RDS


PROGRAM: Modify New Compile Planned_Compile Run Debug Undefine Exit
Change the compilation definition of a 4GL application program.
---------------------------------Press CTRL-W for Help------------------

Informix 4GL Compiled


PROGRAM: Modify New Compile Planned_Compile Run Drop Exit
Change the compilation definition of a 4GL application program.
---------------------------------Press CTRL-W for Help-------------

The Programmer’s Environment 1214 07-99 9

The PROGRAM menu is used to link all the modules together into one program.
The options available are described below:
Modify Allows you to modify the data in your program
specification. You are prompted for the name of the
program you wish to modify. The Programmer's
Environment then displays a screen and menu which is
used to update the information about the program.
New Allows you to create a new program specification which
contains the modules and libraries that make up the
desired application program.
Compile Performs the compilation and linking described by the
program specification, taking into account the time when
the files were last updated. (This is the same as
Program_Compile in the MODULE menu.)
Planned_Compile Taking into account the time of last change for the various
modules that make up your program, this option presents
a summary of the steps that will be executed if you select
Compile.

Informix 4GL The Programmer’s Environment 3-9


Run Presents a list of compiled programs which may be
executed.
Drop Removes the name for a program. Does not remove the
actual modules.
Debug Lets you choose a runable module to execute through the
Interactive Debugger, if you have purchased and installed
that product.
Undefine Behaves like the Drop option.

Informix 4GL The Programmer’s Environment 3-10


Creating a Program

PROGRAM: Modify New Compile Planned_Compile Run


Add the compilation definition of a 4GL application program.

CREATE DATABASE (Y or N) >>


Create Informix 4GL program sources database.

NEW PROGRAM>>
Enter the name you want to assign to the program, and press RETURN.

The Programmer’s Environment 1214 07-99 11

A program is created by linking a series of modules together. The PROGRAM


menu is a means for keeping track of the modules that make up a program.
The Program Database
When you choose the New option for the first time, you will be asked if you want to
create an Informix 4GL source database. This database is used to keep track of the
modules that make up a program. You should answer Y to this prompt. This will
create a program sources database to track the modules that make up the program.
Naming Your Program
If the source database already exists, the Programmer's Environment takes you
directly to the NEW PROGRAM prompt, where you are asked to name your new
program. The name you choose becomes the name used to refer to all of the modules
that make up your program. The program name:
„ Must begin with a letter.
„ Can contain letters, numbers, and underscores (_).
„ May be a maximum of 10 characters long in UNIX.

Informix 4GL The Programmer’s Environment 3-11


Informix 4GL RDS

NEW PROGRAM: 4GL Globals Other Program_Runner Rename Exit


Edit the 4GL sources list.
------------------------------------ Press CTRL-W for Help--------
Program [ ]
Runner [fglgo ] Runner Path [ ]
Debugger [fgldb ] Debugger Path [ ]

4gl Source 4gl Source Path


[ ] [ ]
[ ] [ ]
[ ] [ ]

Global SoInformixurce Other Source Path


[ ] [ ]
[ ] [ ]
[ ] [ ]

Other .4go Other .4go Path


[ ] [ ]
[ ] [ ]

The Programmer’s Environment 1214 07-99 12

The illustration above shows the program screen for Informix 4GL RDS. This is
the screen that appears if you choose the New or Modify option from the
PROGRAM menu. The options available here are described below:
4GL Takes you into the 4gl Source list. This is where you enter
the names of the modules that make up your program and
their paths.
Globals Allows you to update the Global Source array. If changes
are made to this module, then all modules will be
recompiled since changes to globals can affect all other
modules.
Other Allows you to update the Other .4go and Other .4go Path.
This is where you specify the names and locations of
other Informix 4GL object files.
Program_Runner Allows you to specify the file name and path of the p-code
runner that you want to run your program. A custom
p-code runner is needed if you are going to call a C code
function from within your Informix 4GL application.

Informix 4GL The Programmer’s Environment 3-12


Rename Allows you to change the name of your program. This
affects what the executable file is called.
Exit Returns you to the PROGRAM menu.

Informix 4GL The Programmer’s Environment 3-13


Informix 4GL C Compiler Version

NEW PROGRAM: 4GL Other Libraries Compile_Options Rename Exit


Edit the 4GL sources list.
----------------------------------Press CTRL-W for Help---------
Program [ ]

4gl Source 4gl Source Path


[ ] [ ]
[ ] [ ]
[ ] [ ]
[ ] [ ]
[ ] [ ]

Other Source Ext Other Source Path


[ ] [ ] [ ]
[ ] [ ] [ ]
[ ] [ ] [ ]

Libraries [ ] Compile Options [ ]


[ ] [ ]

The Programmer’s Environment 1214 07-99 14

The illustration above shows the program screen for the Informix 4GL C Compiler
Version. This is the screen that appears if you choose the New or Modify option
from the PROGRAM menu. The options available here are described below:
4GL Takes you into the 4gl Source list. This is where you enter
the names of the modules that make up your program and
the path for those modules.
Other Allows you to update the three-column screen array with
headings Other Source, Ext, and Other Source Path. This
is where you place the file name and location of C, Cobol,
or other source or object code.
Libraries Permits you to add the names of up to 10 libraries that you
want linked with your program.
Compile_Options Lets you supply up to 10 command line options for the C
compiler, if desired.
Rename Allows you to change the name of your program. This
affects what your executable file will be called.
Exit Returns you to the PROGRAM menu.

Informix 4GL The Programmer’s Environment 3-14


Listing the Modules

NEW PROGRAM: 4GL Globals Other Program_Runner Rename


Do not Exit
include the
Edit the 4GL sources list.
- - - - - - - - - - - - - - - - - - - Press CTRL-W .4gl
for extension.
Help - - - - -
Program [prog_all]
Runner [fglgo ] Runner Path [ ]
Debugger [fgldb ] Debugger Path [ ]

4gl Source 4gl Source Path


[main_mod ] [ ]
[input_mod ] [
There is no separate
]
location
[update_mod ] [ for the globals module
] in the
Global Source Other Source Path Compiled version of the
[globs ] [ product. The file ]containing the
[ ] [ ]
GLOBALS function is listed
Other .4go Other .4go Path
[ ] [
with the other modules
]
under
[ ] [ the 4gl Source.
]

The Programmer’s Environment 1214 07-99 15

The 4GL option is used to enter a list of modules that make up your program. The
4gl Source column of this form is actually an array of values (that is, more than
just the five that are visible). Enter all of the modules that make up your program.
As your program grows, you can come back to this screen and enter additional
modules.
Global Source with Rapid Development System
The Global Source field is only available with the Rapid Development System. You
can enter the name of a module that contains your GLOBALS function. If you make
a change to the file listed in the Global Source field, all other modules will be
automatically recompiled. This is due to the fact that changes to this module could
affect the other modules in your program.
If you are using the Compiled Version, list the module that contains the GLOBALS
function in the 4gl Source array.

Informix 4GL The Programmer’s Environment 3-15


An Alternative

Working at
the Command Compiled Version: RDS:
Line c4gl fglpc
Using a
.SUFFIXES: .4gl .o .per .frm .c
Makefile .4gl.o :
/usr/informix/bin/c4gl -c $*.0 $<
.per.frm :
form4gl $*
.c.o :

The Programmer’s Environment 1214 07-99 16

As you have seen, the Programmer's Environment lets you list the files that are
part of an application. The advantage of this is that you can have the database keep
track of what to compile. However, there are limitations:
„ The Programmer's Environment puts all compiled files in the current directory
(that is, the directory from which you invoked the Programmer's
Environment). You may want to keep different source files and compiled files
in different directories.
„ The Programmer's Environment only sees form files in the current directory.
You may want to put form files in a separate directory.
„ You cannot customize the commands that the Programmer's Environment uses
to compile. So if you want to use a special option or change file names, you
have to use the compile command directly. This is true for forms and for code.
These limitations can become more problematic in large applications. They can all
be resolved, however, if you work from the command line and use the make utility.

Informix 4GL The Programmer’s Environment 3-16


c4gl from the Command Line
„ Creating a program from a single module
c4gl filename.4gl -o myprog.4ge

„ Creating a program from multiple modules


Š To compile a single module to object code
c4gl filename.4gl -o filename.o
Š To create an executable from multiple modules
c4gl file1.4gl file2.o file3.o -o myprog.4ge

„ Executing the program


myprog.4ge

The Programmer’s Environment 1214 07-99 17

As an alternative to the Programmers Environment, you may compile your


program to produce a C executable from the command line, using Informix 4GL
C Compiler Version.
A single module program
1. Create a 4GL source code module using vi, or another text editor. Name the file
filename.4gl.
2. Compile the program to a C executable by entering the following at the command
line:
c4gl filename.4gl -o appl.4ge

The -o option allows you to specify the name of the output file. If you omit this
-o option, the default output file is named a.out.
The c4gl command performs the necessary processing steps to invoke the
preprocessors, link the object files, and produce an executable 4GL program.
When the compilation completes successfully, c4gl automatically removes the
intermediate files with extensions .c, .ec, and .4ec, which are generated during
the phases of compilation.
3. If errors occur, an error file will be created, filename.err. Correct any errors in
the source module using the text editor, and re-compile.

Informix 4GL The Programmer’s Environment 3-17


The resulting .4ge program file is an executable file that can be run by entering its
name at the command line:
appl.4ge

A program with multiple modules


You can compile the individual 4GL source modules separately. If there is no MAIN
program block in the source file, your code is compiled to object code:
c4gl file1.4gl -o file1.o
Compilation errors will be reported in an error file, file1.err.

The separate object files can be linked with the module that contains the MAIN
program block at a later time, to produce an executable C program:
c4gl file1.4gl file2.o file3.o -o appl.4ge

There are additional options that can be specified for the c4gl command to customize
the processing. For a complete description of these options see the Informix 4GL
Reference Manual.

Informix 4GL The Programmer’s Environment 3-18


RDS from the Command Line
„ Creating a program from a single module
fglpc filename.4gl

„ Creating a program from multiple modules


Š Compile each module to p-code
fglpc file1.4gl file2.4gl
Š Concatenate p-code files together
cat file1.4go file2.4go > myprog.4gi

„ Executing the program


fglgo filename.4go
or
fglgo myprog.4gi
The Programmer’s Environment 1214 07-99 19

Informix 4GL Rapid Development System can also be used from the command
line to create programs. The p-code that is created by the compiler can be executed
using the p-code runner.
A single module program
1. Create a 4GL source code module using vi, or another text editor. Name the file
filename.4gl.
2. Compile the program to p-code by entering the following at the command line:
fglpc filename.4gl
The fglpc command compiles your source code and produces a file containing
tables of information and blocks of p-code, with the file name filename.4go.
3. If errors occur, an error file will be created, filename.err. Correct any errors in
the source module using the text editor, and re-compile.
In order to execute the resulting .4go p-code file, the p-code runner must be used to
interpret the code:
fglgo filename.4go

Informix 4GL The Programmer’s Environment 3-19


A program with multiple modules
If a program has several modules, they must each be compiled to p-code. Several
modules can be compiled at once:
fglpc file1.4gl file2.4gl
This command will generate two p-code files, file1.4go and file2.4go.
Compilation errors will be reported in the error files, file1.err and file2.err.

Before the program can be run the p-code modules must be combined into a single
file:
cat file1.4go file2.4go > myprog.4gi

Then the p-code runner (or the Debugger, if available) can be used to execute the p-
code:
fglgo myprog.4gi

If you do not specify the file extension, fglgo looks first for the filename with a .4gi
extension, and then for the filename with a .4go extension.
See the Informix 4GL Reference Manual for additional options to the fglpc and fglgo
commands.

Informix 4GL The Programmer’s Environment 3-20


Using make and makefiles
„ make - a system utility to generate and execute commands
„ makefile - customized command file used by make to
track and re-compile source modules when necessary

Examples:

make

make target

The Programmer’s Environment 1214 07-99 21

The make utility is a system utility which generates and executes commands. Many
development shops use the make utility to keep track of source files that have
changed, and to re-compile when necessary.
The make utility uses a description file (command file), known as the makefile or
Makefile, and some general templates to determine the dependencies between the
files. Before linking the object files, make checks to see if each of the prerequisites
are up to date. In addition to the description file, make derives necessary
information from the last-modified time of files as recorded in the file system.
To invoke make, you can issue one of the following commands:
„ make
„ make target
In the first option, the utility will make the first target it finds in the makefile. In the
second option, you specify the target to make after the make command. More than
one target can be specified on the command line.

Informix 4GL The Programmer’s Environment 3-21


Following are suggested custom targets to support Informix 4GL development:
make PCODE The target PCODE will compile the Informix 4GL Rapid
Development System version of the application.
make CCODE The target CCODE will compile the Informix 4GL C
Compiler version of the application.
make FORM The target FORM will compile the forms.
The sample makefile on the next page uses these custom targets.
If you wish to use make to manage your files, you will need to edit the makefile as
you develop applications to define the name of your 4GL source files, forms and final
executable. Your instructor can provide a copy of the makefile for your use.

For additional information on makefiles, visit the Informix Developer Network


(IDN) on the Web at the following URL:
http://www.informix.com/idn

Informix 4GL The Programmer’s Environment 3-22


Sample makefile
.SUFFIXES: .o .ec .c .4gl .4ge .4go .4gi .4ga .per .frm .msg .iem

4GL = filename.4gl filename2.4gl

FORM = formname.per
Enter your
filenames here. PROG_NAME = application.4ge

COBJS = $(4GL:.4gl=.o)
POBJS = $(4GL:.4gl=.4go)
CFORM = $(FORM:.per=.frm)
RDS_NAME= $(PROG_NAME:.4ge=.4gi)

CCODE: $(COBJS)
c4gl -o $(PROG_NAME) $(COBJS)
@- echo "Finished compiling ccode..."

PCODE: $(POBJS)
cat $(POBJS) > $(RDS_NAME)
@- echo "Finished compiling pcode..."

FORM: $(CFORM)
@- echo "Finished compiling forms..."

.4gl.4go:
fglpc $*.4gl

.4gl.o:
c4gl -c $*.4gl

.per.frm:
form4gl -s $*.per

Note The indented lines of makefiles must have tab characters. Using blank spaces will
prevent the makefile from working.

Informix 4GL The Programmer’s Environment 3-23


Exercise in Creating a Program

Create a program for the demonstration database using the


modules listed below. These modules were created for you
when you ran the r4gldemo or i4gldemo program.
„ d4_cust
„ d4_demo
„ d4_stock
„ d4_main
„ d4_orders
„ d4_report
„ d4_globals

The Programmer’s Environment 1214 07-99 24

Use the PROGRAM menu to link the modules that make up the demonstration
application.
Create the Program Database
Choose New from the PROGRAM menu. You may need to answer Yes when asked
to create a program database (syspgm4gl).
Name your program cust# where # represents your student login number (e.g.,
cust1).
List the Modules
You will now be placed in the PROGRAM screen. Enter the names of the modules
that make up the program cust#. These modules are listed in the slide above (all of
the modules).
„ Rapid Development System: List all modules, except d4_globals, in the 4gl
Source field. The d4_globals module should be placed in the Global Source
field.
„ C Compiler Version: List all modules, including d4_globals, in the 4gl Source
field.
Leave the Program Screen
When you have entered all of the modules, press the ESC key, and then choose Exit.

Informix 4GL The Programmer’s Environment 3-24


Compile Your Program
Choose Compile from the PROGRAM menu. Highlight cust# and press RETURN.
The compile sequence can take several minutes.
Run the Program
Once your program has compiled, choose Run from the PROGRAM menu to
execute your program.

Informix 4GL The Programmer’s Environment 3-25


Common Module Menu Sequence
Informix 4GL: Module Form Program Query-language Exit

MODULE: Modify New Compile Program_Compile Run Debug Exit

MODIFY MODULE>>

USE-EDITOR>>vi

MODIFY MODULE: Compile Save-and-exit Discard-and-exit

COMPILE MODULE: Object Runable Exit

COMPILE MODULE: Correct Exit

Common Form Generate Menu Sequence


Informix 4GL: Module Form Program Query-language Exit

FORM: Modify Generate New Compile Exit

CHOOSE DATABASE>>

NEW FORM>>

CHOOSE TABLE>>

NEW FORM: Table-selection-complete Select-more-tables Exit

Common Form Modify Menu Sequence


Informix 4GL: Module Form Program Query-language Exit

FORM: Modify Generate New Compile Exit

MODIFY FORM>>

USE-EDITOR>>vi

MODIFY FORM: Compile Save-and-exit Discard-and-exit

COMPILE FORM: Correct Exit

Informix 4GL The Programmer’s Environment 3-26


File Extensions

Extension Description
.4gl Informix 4GL Source module
.4ge C Compiled Version executable
.o C Compiled Version object
.4go RDS Version object
.4gi RDS Version program
.per Form File Source
.frm Form File Compiled
.msg Message file source
.ex or .iem Message File Compiled

The Programmer’s Environment 1214 07-99 27

File Extensions
.4gl Informix 4GL Source module
.4ge C Compiled Version executable
.o C Compiled Version object
.4go RDS Version object
.4gi RDS Version program
.per Form File Source
.frm Form File Compiled
.msg Message File Source
.ex or .iem Message File Compiled

The extensions .4gl, .4ge, .4go, .4gi, are Informix naming conventions which are
enforced only when you are using the Programmer’s Environment. The extensions
.msg, .ex, and .iem are simply naming conventions also. Your company may have
different naming standards.

Informix 4GL The Programmer’s Environment 3-27

Вам также может понравиться