Summary:
See also: Built-in Functions.
A utility function is a function provided in a separate 4GL library; it is not built in the runtime system. You must link with the utility library to use one of the utility functions.
The library of utility function is named libfgl4js. The 42x file, 42m modules and 42f forms are provided in $FGLDIR/lib. The sources of the utility functions and form files are provided in the FGLDIR/src directory.
Function | Description |
Common dialog functions | |
FGL_WINBUTTON() | In a separate window, displays an interactive message box with multiple choices |
FGL_WINMESSAGE() | In a separate window, Displays an interactive message box with some text |
FGL_WINPROMPT() | Displays a dialog box with a field that accepts a value |
FGL_WINQUESTION() | In a separate window, displays an interactive message box with Yes, No, Cancel buttons |
FGL_WINWAIT() | Displays a dialog box and waits for the user to press a key |
Database utility functions | |
DB_GET_DATABASE_TYPE() | Returns the type of the current database |
DB_GET_SEQUENCE() | Returns a new serial value from a predefined table (SERIALREG) |
DB_START_TRANSACTION() | Starts a new transaction if none is started (for nested transaction handling) |
DB_FINISH_TRANSACTION() | Ends a nested transaction |
DB_IS_TRANSACTION_STARTED() | Returns TRUE if a nested transaction is started |
Front End Functions (Use ui.Interface.frontCall() instead) | |
WINOPENDIR() | Shows a dialog window to select a directory in the front
end workstation file system; use ui.Interface.frontCall("standard","opendir",...) instead. |
WINOPENFILE() | Shows a dialog window to select a file in the front end
workstation file system; use ui.Interface.frontCall("standard","openfile",...) instead. |
WINSAVEFILE() | Shows a dialog window to save a file in the front end
workstation file system; use ui.Interface.frontCall("standard","savefile",...) instead. |
Microsoft Windows Client Specific Functions (Use ui.Interface.frontCall() instead) | |
WINEXEC() | Starts a program on a Microsoft Windows front end without
waiting; use ui.Interface.frontCall("standard","execute",...) instead. |
WINEXECWAIT() | Starts a program on a Microsoft Windows front end and
waits; use ui.Interface.frontCall("standard","execute",...) instead. |
WINSHELLEXEC() | Opens a document on a Microsoft Windows front end with
the corresponding program; use ui.Interface.frontCall("standard","shellexec",...) instead. |
Function | Description |
DATE1() | Converts a DATETIME to a DATE. |
TIME1( ) | Extracts the time part (hour, minute, second) from DATETIME. |
FGL_FGLGUI() | Returns TRUE if the application runs in GUI mode. |
FGL_GETUITYPE() | Returns the type of the front end. |
FGL_MSG_NONL() | Returns an error message without trailing blanks. |
FGL_INIT4JS( ) | Initializes the built-in function library. |
FGL_MSG_NONL( ) | Returns an error message without the CR at the end. |
FGL_WTKCLIENT( ) | Returns TRUE if the current front end is the WTK. |
FGL_RESOURCE( ) | Selects a specific FGLPROFILE file. |
FGL_UIRETRIEVE( ) | Returns the value of a variable from the WTK front end. |
FGL_UISENDCOMMAND( ) | Sends a TCL command to the WTK front end. |
FGL_WTKCLIENT( ) | Returns TRUE if the current front end is the WTK. |
FGL_CHARBOOL_TO_INTBOOL() | Converts a character representation of a Boolean value to an INTEGER. |
FGL_INTBOOL_TO_CHARBOOL( ) | Converts an INTEGER to a character representation of the Boolean value. |
This function returns the database type for the current connection.
CALL DB_GET_DATABASE_TYPE()
RETURNING result STRING
After connecting to the database, you can get the type of the database server with this function.
The following table shows the codes returned by this function, for the supported database types:
Code | Description |
ADS | ANTs / Genero DB |
ASA | Sybase ASA |
DB2 | IBM DB2 |
IFX | Informix |
MYS | MySQL |
MSV | Microsoft SQL Server |
ORA | Oracle |
PGS | PostgreSQL |
This function generates a new sequence for a given identifier.
CALL DB_GET_SEQUENCE( id STRING )
RETURNING
result INTEGER
This function generates a new sequence from a register table created in the current database.
The table must be created as follows:
CREATE TABLE SERIALREG
( TABLE_NAME VARCHAR(50) NOT NULL PRIMARY KEY,
LAST_SERIAL INTEGER NOT NULL )
Each time you call this function, the sequence is incremented in the database table and returned by the function.
It is mandatory to use this function inside a transaction block, in order to generate unique sequences.
01
MAIN02
DEFINE ns, s INTEGER03
DATABASE mydb04
LET s = DB_START_TRANSACTION()05
LET ns = DB_GET_SEQUENCE("mytable")06
INSERT INTO mytable VALUES ( ns, 'a new sequence' )07
LET s = DB_FINISH_TRANSACTION(TRUE)08
END MAIN
This function encapsulates the BEGIN WORK instruction to start a transaction.
CALL DB_START_TRANSACTION()
RETURNING result
INTEGER
You can use the transaction management functions to handle nested transactions.
On most database engines, you can only have a unique transaction, that you start with BEGIN WORK and you end with COMMIT WORK or ROLLBACK WORK. But in a complex program, you may have nested function calls doing several SQL transactions.
The transaction management functions execute a real transaction instruction only if the number of subsequent start/end calls of these functions matches.
01
DEFINE s INTEGER02
03
MAIN04
DATABASE mydb05
LET s = DB_START_TRANSACTION() -- real BEGIN WORK06
CALL do_update()07
LET s = DB_FINISH_TRANSACTION(TRUE) -- real COMMIT WORK08
END MAIN09
10
FUNCTION do_update()11
LET s = DB_START_TRANSACTION()12
UPDATE customer SET cust_status = 'X'13
LET s = DB_FINISH_TRANSACTION(TRUE)14
END FUNCTION
This function encapsulates the COMMIT WORK or ROLLBACK WORK instructions to end a transaction.
CALL DB_FINISH_TRANSACTION( commit INTEGER )
RETURNING result INTEGER
When the number of calls to DB_START_TRANSACTION() matches, this function executes a COMMIT WORK if the passed parameter is TRUE; if the passed parameter is not TRUE, it executes a ROLLBACK WORK.
If the number of calls does not match, the function does nothing.
See also: DB_START_TRANSACTION().
This function indicates whether a transaction is started with the transaction management functions.
CALL DB_IS_TRANSACTION_STARTED()
RETURNING result
INTEGER
The function returns TRUE if a transaction was started with DB_START_TRANSACTION().
This function displays an interactive message box containing multiple choices, in a separate window.
CALL FGL_WINBUTTON(
title STRING, text STRING, default STRING,
buttons STRING, icon STRING, danger SMALLINT )
RETURNING result STRING
FGL_WINBUTTON()
function to open a message box and let the
end user select an option in a set of buttons. The function returns the label of the button which has been selected by the user.
You can define up to 7 buttons that each have 10 characters.
You can also use a form or a menu with "popup" style instead.
If two buttons start with the same letter, the user will not be able to select one of them on the ASCII client.The "&" before a letter for a button is either displayed (ASCII client), or it underlines the letter.
01
MAIN02
DEFINE answer STRING03
LET answer = FGL_WINBUTTON( "Media selection", "What is your favorite media?",04
"Lynx", "Floppy Disk|CD-ROM|DVD-ROM|Other", "question", 0)05
DISPLAY "Selected media is: " || answer06
END MAIN
This function displays an interactive message box containing text, in a separate window.
CALL FGL_WINMESSAGE( title STRING, text
STRING, icon STRING )
FGL_WINMESSAGE()
function displays a message box to the end
user.
You can also use a form or a menu with "popup" style instead.
icon is ignored by the ASCII client.01
MAIN02
CALL FGL_WINMESSAGE( "Title", "This is a critical message.", "stop")03
END MAIN
This function displays a dialog box containing a field that accepts a value.
CALL FGL_WINPROMPT (
x INTEGER, y INTEGER, text
STRING,
default STRING, length INTEGER, type INTEGER )
RETURNING value STRING
FGL_WINPROMPT()
function allows the end user to enter a value.
You can also use your own form instead.
Avoid passing NULL values.
01
MAIN02
DEFINE answer DATE04
LET answer = FGL_WINPROMPT( 10, 10, "Today", DATE, 10, 7 )05
DISPLAY "Today is " || answer06
END MAIN
This function displays an interactive message box containing Yes, No, and Cancel buttons, in a separate window
CALL FGL_WINQUESTION(
title STRING, text
STRING, default STRING,
buttons STRING, icon STRING, danger
SMALLINT )
RETURNING value STRING
FGL_WINQUESTION()
function shows a questiopn to the end user
and waits for an answer.
You can also use a form or a menu with "popup" style instead.
Setting buttons to another value may result in unpredictable behavior at runtime.Avoid passing NULL values
01
MAIN02
DEFINE answer STRING04
LET answer = "yes"05
WHILE answer = "yes"06
LET answer = FGL_WINQUESTION(07
"Procedure", "Would you like to continue ? ",08
"cancel", "yes|no|cancel", "question", 0)09
END WHILE10
IF answer = "cancel" THEN11
DISPLAY "Canceled."12
END IF13
END MAIN
This function displays an interactive message box.
CALL FGL_WINWAIT( text
STRING )
You can also use a form or a menu with "popup" style instead.
This function executes a program on the machine where the Windows Front End runs and returns immediately.
CALL WINEXEC( command STRING )
RETURNING result
INTEGER
See also: WINEXECWAIT(), DDE Support.
This function executes a program on the machine where the Windows Front End runs and waits for termination.
CALL WINEXECWAIT( command STRING )
RETURNING result INTEGER
See also: WINEXEC(), DDE Support.
This function opens a document with the corresponding program, based on the file extension.
CALL WINSHELLEXEC( filename STRING )
RETURNING result
INTEGER
See also: WINEXEC(), DDE Support.
This function shows a dialog window to let the user select a directory path on the front end workstation file system.
CALL WINOPENDIR( dirname STRING, caption STRING )
RETURNING
result STRING
This function shows a dialog window to let the user select a file path on the front end workstation file system, for displaying.
CALL WINOPENFILE( dirname STRING, typename STRING,
extlist STRING, caption STRING )
RETURNING result
STRING
This function shows a dialog window to let the user select a file path on the front end workstation file system, for saving.
CALL WINSAVEFILE( dirname STRING, typename STRING,
extlist STRING, caption STRING )
RETURNING result
STRING