Sunteți pe pagina 1din 3

Domains:

Can use normal variables of type long, double, or string, but this can cause problems if the length or type
of the table field has been changed in the data dictionary.
It is preferable to use domain declarations for storing the value of a database table field.
When you use a domain declaration, the type and length for the declared variable are read from the data
dictionary.
Variables of type enumerate or set must always be declared with a domain declaration.
It is also possible to declare an array by using a domain.
Arrays:
An array can have up to four dimensions
There are three types of arrays: long, double, and string.
LONG lng_array(2,4)----The first number after the array name indicates the number of dimensions in
the array. The second number indicates the number of longs that can be stored in each dimension
(1,1) = 3
(2,1) = 100
(2,2) = 98 (1,3) = 56 (2,3) = 55 (2,4) = 77
STRING str_arr(10,5)
| 5 strings of length 10
First dimension indicates the start position in the string.
It is possible to specify a length for the string to be retrieved by using a semicolon [;] followed by the
required length. If you omit the length, the total length of the string is taken.
str_arr(2,1;1) = "b" This references the first string starting at position 2 with length 1.
str_arr(3,2) = "CDEF" This references the second string beginning at position 3.
strg(2;3) = "Hello" The letters "Hel" (3 characters) are stored from position 2 onwards
There are two lengths associated with a string: the maximum and the current length.
If a string is declared as STRING strg(100), the maximum length of strg is 100. If strg is filled as strg =
"hello", the current length is 5. If strg is filled as strg(1) = "hello", the current length is also is 100, as the
remaining positions are filled with spaces. When you specify a start position, the string is always filled
out with spaces.
The keyword FIXED is applicable to one-dimensional strings only. Multi-dimensional string arrays are
always fixed and do not need to be declared with the keyword FIXED.
Based variables:
The BASED mechanism is applicable to strings or arrays of all possible types.
It determines that a variable will be based on another variable.
For based variables, no memory space is reserved when they are declared. At runtime they use the same
memory space as the variable on which they are based. So by using this mechanism, the same section of
memory can be accessed via different names.
You use the following construction to base one variable on another: BASE var_1 AT var_2
STRING a(10) FIXED
STRING b(5) BASED
BASE b AT a(3) | This indicates that the space occupied by b is the same as the space for a(3;5)
Common variables:
Only string variables can be declared as COMMON.

Common variables are automatically based on a common memory part that can be used by several
programs. For this reason they must be declared as BASED. The fact that they are common must be
indicated with the reserved word COMMON.

Iterations:
WHILE statement.
WHILE expression
statement(s)
ENDWHILE
FOR num_var = num_expr_1 TO num_expr_2 [STEP num_expr_3]
statement(s)
ENDFOR
REPEAT
statement(s)
UNTIL expression
Variables:
The value of a static variable is saved at the end of the function and is used again the next time the
function is called.
A static variable is automatically initialized at the start of the program.
Normal local variables are undefined at each function call, and are not initialized at first call.
Variables declared outside any function block are global variables. You can use them in all functions
that occur after the variable declaration.
An external variable is declared outside the function blocks. You can use them in all functions that occur
after the variable declaration, and also in other programs (for example, forms, reports, and runtime
expressions).
4GL Event Sections
PROGRAM SECTIONS:
Main sections
declaration:
Use this section to declare tables and global variables, also use this section to define macros and
function prototypes.
before.program:
Use this section to program actions that must be executed when the session starts. For example, you can
use this section to initialize or import variables or to read a special record.
after.form.read:
Use this section to change form data at run time after it has been read in memory. Typical functionality is
the removal of fields, groups or commands.
on.error:
Use this section to program actions that must be executed at the end of the session, before the
after.program section. If the session is canceled, the actions in this section are not executed. If an error is
detected, you can check the predefined variable e for the error code.
after.program:
Use this section to program actions that must be executed at the end of the session, after the on.error
section.
after.update.db.commit:
Use this section to program actions that must be executed immediately after a after.commit.transaction()
call, if the database is updated.

before.display.object:
Use this section to program actions that must be executed each time the entire record is displayed.
before.new.object:
Use this section to program actions that must be executed once before the input of the first field of the
new created record. It is used for setting the default values of the record fields.
on.display.total.line:
Use this section to calculate and display the total line fields. The function display.total.fields() must be
called from this section to display the actual total fields values. This section will be called when the variable
fattr.total.line is set in the before.program section. By default the 4GL-Engine will call this section after a (new)
set of records is read from the database. In addition an application can trigger this section to be called by calling
the function: refresh.total.line().
functions:
Use this section to define the functions used in the other sections. This must be the last section in the
script.

S-ar putea să vă placă și