Summary:
See also: Compiling Programs, Flow Control, The Application class, Database Schema Files, Preprocessor.
You can control the behavior of the runtime system with some FGLPROFILE configuration parameters.
Dialog.fieldOrder = {true|false}
When TRUE, intermediate triggers are executed. As the user goes to a new field with a mouse click, the runtime system executes the BEFORE FIELD / AFTER FIELD triggers of the input fields between the source and the destination field. When FALSE, intermediate triggers are not executed..
The default setting for the runtime system is FALSE; while the default
setting in FGLPROFILE for Dialog.fieldOrder
is TRUE. As a result, the
overall setting after installation is TRUE. To modify the behavior of
intermediate field trigger execution, change the setting of Dialog.fieldOrder
in FGLPROFILE.
The MAIN block is the starting point of the application. When the runtime system executes a program, after some initialization, it gives the control to this program block.
MAIN
[ define-statement | constant-statement ]
{ [defer-statement] | fgl-statement | sql-statement }
[...]
END MAIN
The DEFER instruction allows you to control the behavior of the program when an interruption or quit signal has been received.
DEFER { INTERRUPT | QUIT }
When an interrupt signal is caught by the runtime system and DEFER INTERRUPT is used, the int_flag global variable is automatically set to TRUE by the runtime system.
Interrupt signals are raised on terminal consoles when the user hits a key like CTRL-C (depends on the stty configuration). When using a front end, no terminal console is used for the BDL program; therefore users cannot send interrupt signals with the CTRL-C key. To send an interruption request from the front end, you must define an 'interrupt' action view. For more detail, refer to Interruption Handling in the Dynamic User Interface .
DEFER QUIT indicates that the program must continue when receiving a quit signal. By default, the program stops.
When a quit signal is caught by the runtime system and DEFER QUIT is used, the quit_flag global variable is automatically set to TRUE by the runtime system.
STATUS is a predefined variable that holds the execution status of the last instruction.
STATUS
DEFINE STATUS INTEGER
01
MAIN02
DEFINE n INTEGER03
WHENEVER ANY ERROR CONTINUE04
LET n = 10/005
DISPLAY STATUS06
END MAIN
INT_FLAG is a predefined variable that is automatically set to TRUE when the user presses the interruption key.
INT_FLAG
DEFINE INT_FLAG INTEGER
01
MAIN02
DEFINE n INTEGER03
DEFER INTERRUPT04
LET INT_FLAG = FALSE05
FOR n = 1 TO 100006
IF INT_FLAG THEN EXIT FOR END IF07
...08
END FOR09
END MAIN
QUIT_FLAG is a predefined variable that is automatically set to TRUE when a 'quit event' arrives.
QUIT_FLAG
DEFINE QUIT_FLAG INTEGER
01
MAIN02
DEFER QUIT03
LET QUIT_FLAG = FALSE04
INPUT BY NAME ...05
IF QUIT_FLAG THEN06
...07
END IF08
END MAIN
The OPTIONS instruction allows you to change default program options.
OPTIONS
{ INPUT [NO] WRAP
| HELP FILE help-filename
| INPUT ATTRIBUTE ( {FORM|WINDOW|input-attributes}
)
| DISPLAY ATTRIBUTE ( {FORM|WINDOW|display-attributes} )
| SQL INTERRUPT {ON|OFF}
| ON TERMINATE SIGNAL CALL term-function
| FIELD ORDER {CONSTRAINED|UNCONSTRAINED|FORM}
| ON CLOSE APPLICATION {STOP|CALL close-function}
| RUN IN {FORM|LINE} MODE
| MESSAGE LINE line-value
Console Only!
| COMMENT LINE {OFF|line-value}
Console Only!
| PROMPT LINE line-value
Console Only!
| ERROR LINE line-value
Console Only!
| FORM LINE line-value
Console Only!
| INSERT KEY key-name
Console Only!
| DELETE KEY key-name
Console Only!
| NEXT KEY key-name
Console Only!
| PREVIOUS KEY key-name
Console Only!
| ACCEPT KEY key-name
Console Only!
| HELP KEY key-name
Console Only!
} [,...]
A program can include several OPTIONS statements. If these statements conflict in their specifications, the OPTIONS statement most recently encountered at runtime prevails. OPTIONS can specify the following features of other statements (such as CONSTRUCT, DISPLAY, DISPLAY ARRAY, DISPLAY FORM, ERROR, INPUT, INPUT ARRAY, MESSAGE, OPEN FORM, OPEN WINDOW, PROMPT and RUN ):
The following options define positions of reserved lines in the console (character terminals). When using the standard graphical mode, is not recommended that you use these options, as most will have no effect on the display.
You can specify any of the following positions for each reserved line:
Expression | Description |
FIRST | The first line of the screen or window. |
FIRST + integer | A relative line position from the first line. |
integer | An absolute line position in the screen or window. |
LAST - integer | A relative line position from the last line. |
LAST | The last line of the screen or window. |
An ATTRIBUTE clause of an OPEN WINDOW, CONSTRUCT, INPUT, DISPLAY, INPUT ARRAY or DISPLAY ARRAY statement only temporarily redefines the attributes. After the window closes (in the case of an OPEN WINDOW statement) or after the statement terminates (in the case of an INPUT, DISPLAY, INPUT ARRAY or DISPLAY ARRAY statement), the runtime system restores the attributes from the most recent OPTIONS statement.
Any attribute defined by the OPTIONS statement remains in effect until the runtime system encounters an ATTRIBUTES clause that redefines the same attribute in one of the following statements:
The FORM keyword in INPUT ATTRIBUTE, or DISPLAY ATTRIBUTE clauses instructs the runtime system to use the input or display attributes of the current form. Similarly, you can use the WINDOW keyword of the same options to instruct the program to use the input or display attributes of the current window. You cannot combine the FORM or WINDOW attributes with any other attributes.
The following table shows the allowed input-attributes and display-attributes
Attribute | Description |
BLACK, BLUE, CYAN, GREEN, MAGENTA, RED, WHITE, YELLOW | The color of the displayed text. |
BOLD, DIM, INVISIBLE, NORMAL | The font attribute of the displayed text. |
REVERSE, BLINK, UNDERLINE | The video attribute of the displayed text. |
The tab order in which the screen cursor visits fields of a form is that of the field list of currently executing CONSTRUCT, INPUT, and INPUT ARRAY statements, unless the tab order has been modified by a NEXT FIELD clause. By default, the interactive statement terminates if the user presses RETURN in the last field (or if entered data fills the last field, if that field has the AUTONEXT attribute).
The INPUT WRAP keywords change this behavior, causing the cursor to move from the last field to the first, repeating the sequence of fields until the user presses the Accept key. The INPUT NO WRAP option restores the default input loop behavior.
The RUN IN {FORM|LINE} MODE option can be used to set the default screen mode of the RUN instruction.
The OPTIONS ON TERMINATE SIGNAL CALL funcname defines the function that must be called when the application receives the SIGTERM signal. With this option you can control program termination - for example, by using ROLLBACK WORK to cancel all pending SQL operations. If this statement is not called, the program is stopped with an exit value of SIGTERM (15).
On Microsoft Windows platforms, the function will be called in the following cases:
The OPTIONS ON CLOSE APPLICATION CALL function can be used to execute specific code when the front-end stops. For example, when the client program is stopped, when the user session is ended, or when the workstation is shut down.
Before stopping, the front-end sends a internal event that is trapped by the runtime system. When a callback function is specified with the above program option command, the application code that was executing is canceled, and the callback function as executed before the program stops.
You typically do a ROLLBACK WORK, close all files, and release all resources in that function.
You can configure this option in two ways:
The HELP FILE clause specifies an expression that returns the filename of a help file. This filename can also include a pathname. Messages in this file can be referenced by number in form-related statements, and are displayed at runtime when the user presses the Help key.
See also Message Files.
In an INPUT, INPUT ARRAY, or CONSTRUCT, by default, the tabbing order is defined by the list of fields used by the program instruction. This corresponds to FIELD ORDER CONSTRAINED.
When using FIELD ORDER UNCONSTRAINED, the UP ARROW and DOWN ARROW keys will move the cursor to the field above or below, respectively. Use the FIELD ORDER CONSTRAINED option to restore the default behavior of the UP ARROW and DOWN ARROW keys (moving the cursor to the previous or next field, respectively).
When you specify FIELD ORDER FORM, the tabbing order is defined by the TABINDEX attributes of the current form fields. This allows you to define a tabbing order specific to the layout of the form, that is independent from the program instruction:
Form file:
01
LAYOUT02
GRID03
{04
First name: [f001 ]05
Last name: [f002 ]06
}07
END08
END09
ATTRIBUTES10
EDIT f001 = FORMONLY.fname, TABINDEX = 1;11
EDIT f002 = FORMONLY.fname, TABINDEX = 2;12
END
Program file:
01
MAIN02
DEFINE fname, lname CHAR(20)03
OPTIONS FIELD ORDER UNCONSTRAINED04
OPEN FORM f1 FROM "f1"05
DISPLAY FORM f106
INPUT BY NAME fname, lname07
END MAIN
The OPTIONS instruction can specify physical keys to support logical key functions in the interactive instructions.
Here is the description of keys:
You can specify the following keywords for the physical key names:
Key Name | Description |
ESC or ESCAPE | The ESC key (not recommended, use ACCEPT instead). |
INTERRUPT | The interruption key (on UNIX, interruption signal). |
TAB | The TAB key (not recommended). |
CONTROL-char | A control key where char can be any character except A, D, H, I, J, K, L, M, R, or X |
F1 through F255 | A function key. |
LEFT | The left arrow key. |
RETURN or ENTER | The return key. |
RIGHT | The right arrow key. |
DOWN | The down arrow key. |
UP | The up arrow key. |
PREVIOUS or PREVPAGE | The previous page key. |
NEXT or NEXTPAGE | The next page key. |
You might not be able to use other keys that have special meaning to your version of the operating system. For example, CONTROL-C, CONTROL-Q, and CONTROL-S specify the Interrupt, XON, and XOFF signals on many UNIX systems.
When using character terminals, BDL recognizes two screen display modes: line mode (IN LINE MODE) and formatted mode (IN FORM MODE). The OPTIONS and RUN statements can explicitly specify a screen mode. The OPTIONS statement can set separate defaults for these statements.
After IN LINE MODE is specified, the terminal is in the same state (in terms of stty options) as when the program began. This usually means that the terminal input is in cooked mode, with interruption enabled, and input not available until after a newline character has been typed.
The IN FORM MODE keywords specify raw mode, in which each character of input becomes available to the program as it is typed or read.
By default, a program operates in line mode, but so many statements take it into formatted mode (including OPTIONS statements that set keys, DISPLAY, OPEN WINDOW, DISPLAY FORM, and other screen interaction statements), that typical programs are actually in formatted mode most of the time.
When the OPTIONS statement specifies RUN IN FORM MODE, the program remains in formatted mode if it currently is in formatted mode, but it does not enter formatted mode if it is currently in line mode.
When the OPTIONS statement specifies RUN IN LINE MODE, the program remains in line mode if it is currently in line mode, and it switches to line mode if it is currently in formatted mode.
The RUN instruction creates a new process and executes the command passed as argument.
RUN command
[ IN {FORM|LINE} MODE ]
[ RETURNING variable | WITHOUT WAITING ]
The RUN instruction executes an operating system command line; you can even run a second application as a secondary process. When the command terminates, the runtime system resumes execution.
Waiting for the sub-process
By default, the runtime system waits for the end of the execution of the command.
Unless you specify WITHOUT WAITING, the RUN instruction also does the following:
If you specify WITHOUT WAITING, the specified command line is executed as a background process, and generally does not affect the visual display. This clause is useful if you know that the command will take some time to execute, and your program does not need the result to continue.
Catching the execution status
The RETURNING clause saves the termination status code of the command that RUN executes in a program variable of type INTEGER. You can then examine this variable in your program to determine the next action to take. A status code of zero usually indicates that the command has terminated normally. Non-zero exit status codes usually indicate that an error or a signal caused execution to terminate.
The execution status provided by the RETURNING clause is platform dependant. On Unix systems, the value is composed by two bytes having different meanings. On Windows platforms, the execution status is usually zero for success, not zero if an error occurred.
The LINE and FORM mode
According to the type of command to be executed, you may need to use the line or form mode, which defines how the terminal or the graphical front-end behaves when running the child process.
By default, programs operate in line mode, but so many statements take it into form mode (including OPTIONS statements that set keys, DISPLAY, OPEN WINDOW, DISPLAY FORM, and other screen interaction statements) that typical programs are actually in form mode most of the time.
If no screen mode is specified in the RUN command, the current value from the OPTIONS statement is used. This is by default, IN LINE MODE. This mode is the opposite of the default screen mode for PIPE specifications.
When the RUN statement specifies IN FORM MODE, the program remains in form mode if it is currently in form mode, but it does not enter form mode if it is currently in line mode. When the prevailing RUN option specifies IN LINE MODE, the program remains in line mode if it is currently in line mode, and it switches to line mode if it is currently in form mode. The same comments apply to the PIPE option.
Remark: Besides RUN, the OPTIONS, START REPORT, and REPORT statements can explicitly specify a screen mode.
The EXIT PROGRAM instruction terminates the execution of the program.
EXIT PROGRAM [ exit-code ]
01
MAIN02
DISPLAY "Emergency exit."03
EXIT PROGRAM (-1)04
DISPLAY "This will never be displayed !"05
END MAIN
Database Schema Specification identifies the database schema files to be used for compilation.
SCHEMA dbname
[DESCRIBE] DATABASE dbname
01
SCHEMA dbdevelopment -- Compilation database schema02
DEFINE rec RECORD LIKE customer.*03
MAIN04
DATABASE dbproduction -- Runtime database specification05
SELECT * INTO rec.* FROM customer WHERE custno=106
END MAIN
The NULL constant is provided as "nil" value.
NULL
01
MAIN02
DEFINE s CHAR(5)03
LET s = NULL04
DISPLAY "s IS NULL evaluates to:"05
IF s IS NULL THEN06
DISPLAY "TRUE"07
ELSE08
DISPLAY "FALSE"09
END IF10
END MAIN
The TRUE constant is a predefined boolean value that evaluates to 1.
TRUE
01
MAIN02
IF FALSE = TRUE THEN03
DISPLAY "Something wrong here"04
END IF05
END MAIN
The FALSE constant is a predefined boolean value that evaluates to 0.
FALSE
01
FUNCTION isodd( value )02
DEFINE value INTEGER03
IF value MOD 2 = 1 THEN04
RETURN TRUE05
ELSE06
RETURN FALSE07
END IF08
END FUNCTION
The NOTFOUND constant is a predefined integer value that evaluates to 100.
NOTFOUND
01
MAIN02
DATABASE stores03
SELECT tabid FROM systables WHERE tabid = 104
IF SQLCA.SQLCODE = NOTFOUND THEN05
DISPLAY "No row was found"06
END IF07
END MAIN
The BREAKPOINT instruction sets a program breakpoint when running in debug mode.
BREAKPOINT
When you start fglrun in debug mode, if the program flow encounters a BREAKPOINT instruction, the program execution stops and the debug prompt is displayed, to let you enter a debugger command.
The BREAKPOINT instruction is ignored when not running in debug mode.
01
MAIN02
DEFINE i INTEGER03
LET i=12304
BREAKPOINT05
DISPLAY i06
END MAIN
The DISPLAY instruction displays text in line mode to the standard output channel.
DISPLAY expression [,...]
You can use this instruction to display information to the standard output channel.
01
MAIN02
DISPLAY "Today's date is: ", TODAY03
END MAIN
The ERROR instruction displays an error message to the user.
ERROR text [,...] [ ATTRIBUTE ( display-attributes ) ]
The following table shows the display-attributes supported by the ERROR statement:
Attribute | Description |
BLACK, BLUE, CYAN, GREEN, MAGENTA, RED, WHITE, YELLOW | The color of the displayed text. |
BOLD, DIM, INVISIBLE, NORMAL | The font attribute of the displayed text. |
REVERSE, BLINK (Console Only!), UNDERLINE | The video attribute of the displayed text. |
01
MAIN02
WHENEVER ERROR CONTINUE03
DATABASE stock04
WHENEVER ERROR STOP05
IF sqlca.sqlcode THEN06
ERROR "Connection failed (" || sqlca.sqlcode || ")"07
END IF08
END MAIN
The MESSAGE instruction displays a message to the user.
MESSAGE text [,...] [ ATTRIBUTE ( display-attributes ) ]
The following table shows the display-attributes supported by the MESSAGE statement:
Attribute | Description |
BLACK, BLUE, CYAN, GREEN, MAGENTA, RED, WHITE, YELLOW | The color of the displayed text. |
BOLD, DIM, INVISIBLE, NORMAL | The font attribute of the displayed text. |
REVERSE, BLINK (Console Only!), UNDERLINE | The video attribute of the displayed text. |
01
MAIN02
WHENEVER ERROR CONTINUE03
DATABASE stock04
WHENEVER ERROR STOP05
IF sqlca.sqlcode THEN06
ERROR "Connection failed (" || sqlca.sqlcode || ")"07
ELSE08
MESSAGE "Connected to database."09
END IF10
END MAIN
This feature allows you to define the labels of keys, to show a specific text in the default action button created for the key.
key.key-name.text = "label"
CALL FGL_SETKEYLABEL( "key-name", "label"
)
KEYS
key-name = "label"
[...]
[END]
CALL FGL_DIALOG_SETKEYLABEL( "key-name", "label"
)
KEY key-name = "label"
Traditional 4GL applications use a lot of function keys and/or control keys to manage user actions. For example, in the following interactive dialog, the function key F10 is used to show a detail window:
01
INPUT BY NAME myrecord.*02
ON KEY (F10)03
CALL ShowDetail()04
END INPUT
For backward compatibility, the language allows you to specify a label to be displayed in a default action button created specifically for the key.
By default, if you do not specify a label, no action button is displayed for a function key or control key.
The following table shows the key names recognized by the runtime system:
Key Name | Description |
f1 to f255 | Function keys. |
control-a to control-z | Control keys. |
accept | Validation key. |
interrupt | Cancellation key. |
insert | The insert key when in an INPUT ARRAY. |
delete | The delete key when in an INPUT ARRAY. |
help | The help key. |
You can define key labels at different levels, from the default settings to a specific field, to show a specific label for the key when the focus is in that field. The order of precedence for key label definition is the following:
You can query the label defined at the program level with the FGL_GETKEYLABEL function and, for the current interactive instruction, with the FGL_DIALOG_GETKEYLABEL function.