Академический Документы
Профессиональный Документы
Культура Документы
2
Basic Components of Informix 4GL
Objectives
At the end of this module, you will be able to:
Define the terms:
PROGRAM
MODULE
FUNCTION
FORM
Understand how these components make up an Informix 4GL program
If you take a look at any program, there are basic things it will need to do. In the
case of a program to keep track of a sporting goods distributor, it will need to keep
track of customers, inventory, and orders. In Informix 4GL, this could be three
separate programs or one program that handles all three aspects. For the purposes
of this module, let us say you need to keep track of customers, and that this will be
a program by itself.
There are basic operations involved in keeping track of customers. These may
include adding new customers, deleting old ones, or changing the addresses of
existing ones. With these operations in mind, let us look at the Informix 4GL
components that would be required for a program to track customers.
Program
Program
cust_edit.4gl
cust_add.4gl
.4gl
FUNCTION add_cust() FUNCTION delete_cust()
4GL code 4GL code
4GL code 4GL code
END FUNCTION END FUNCTION
Program
cust_main.4gl cust_add.4gl cust_edit.4gl
FUNCTION delete_cust()
GLOBALS FUNCTION add_cust() 4GL code
4GL code 4GL code 4GL code
END GLOBALS END FUNCTION END FUNCTION
FUNCTION update_cust()
MAIN REPORT cust_list()
4GL code
4GL code 4GL code
4GL code
END MAIN END REPORT
END FUNCTION
In Informix 4GL executable statements are organized into larger units called
program blocks. Each block begins with a keyword, which tells Informix 4GL
what kind of program block to expect.
4GL modules can contain three types of program blocks:
MAIN
The MAIN statement defines the MAIN program block. Informix 4GL always starts
executing the MAIN program block first. It is the MAIN program block that drives
the rest of the program; therefore, every program requires exactly one MAIN
statement (otherwise Informix 4GL would not know where to start).
FUNCTION
The FUNCTION statement defines a FUNCTION program block. The function is
the basic unit for Informix 4GL code. It is the general purpose program block, unlike
MAIN or REPORT. You define what each function's purpose is going to be.
A function can be invoked from any module of your program.
Program
FUNCTION delete_cust()
GLOBALS FUNCTION add_cust() 4GL code
4GL code 4GL code 4GL code
END GLOBALS END FUNCTION END FUNCTION
FUNCTION update_cust()
MAIN REPORT cust_list()
4GL code
4GL code 4GL code
4GL code
END MAIN END REPORT
END FUNCTION
The GLOBALS statement allows you to extend the visibility of program variables
beyond the source module in which they are defined.
Defining global variables
The definition of a global variable must be contained in a globals file, a source
module that contains the GLOBALS statement. For any given global variable
there should be only one file which defines the variable.
The definition statement takes the form:
GLOBALS
DEFINE variable1 INTEGER,
variable2 CHAR(5),
...
END GLOBALS
The GLOBALS statement must appear before the first MAIN, FUNCTION or
REPORT program block.
Note
All versions of 4GL have allowed disjoint sections of an application to use disjoint
globals files as long as all the global object files were linked into the application.
cust_add.4gl
FUNCTION add_cust()
OPEN FORM customer
4GL code
Cust # [ ] END FUNCTION
Name [ ]
Add. [ ]
City [ ] FUNCTION insert_cust()
State [ ] 4GL code
Zip [ ] 4GL code
END FUNCTION
--customer.per
SCREEN
{
Cust # [ ]
The form is a separate file that is used to specify what the appearance of the visual
screen display will look like during data entry and manipulation. There is quite a
bit of flexibility in how a form can look, depending on your needs.
Separate Entity
Forms are a separate entity from the rest of your program. They do not fit into the
categories of program, module, program block or function. Instead they become
their own category. Forms are compiled separately and are used by your program.
Forms can be used to display information from a database as well as to update,
delete, and insert information.
Program
cust_add.4gl
cust_main.4gl cust_edit.4gl
FUNCTION add_cust()
4GL code
4GL code
END FUNCTION
FUNCTION insert_cust()
4GL code
4GL code
END FUNCTION
Case Study
1
Basic Components of Informix 4GL 1213 07-99 17