### START REPORT Syntax Example
Source: https://github.com/m121752332/fjs-fgl-2.32-manual/blob/master/doc/User/Reports.md
Demonstrates the basic syntax for starting a report, directing output to a file, and setting page length.
```FGL
01 DEFINE file_name VARCHAR(200), page_size INTEGER
02 ...
03 START REPORT myrep
04 TO FILE file_name
05 WITH PAGE LENGTH = page_size
```
--------------------------------
### Full MessageServer Example
Source: https://github.com/m121752332/fjs-fgl-2.32-manual/blob/master/doc/User/ClassMessageServer.md
Demonstrates connecting to the MessageServer, sending an 'f1' key event, and handling the received event. This example requires a network setup and uses UDP, so message delivery is not guaranteed.
```script
01 MAIN
02 CALL base.MessageServer.connect()
03 MENU "test"
04 COMMAND "send F1" CALL base.MessageServer.send("f1")
05 ON KEY (F1) DISPLAY "Key F1 received..."
06 COMMAND "quit" EXIT MENU
07 END MENU
08 END MAIN
```
--------------------------------
### Example: Open window and change its title
Source: https://github.com/m121752332/fjs-fgl-2.32-manual/blob/master/doc/User/TutChap12.md
A complete example demonstrating how to open a window, get a reference to it, and change its title text. This illustrates the basic workflow for manipulating window objects.
```4gl
01 MAIN
DEFINE mywin ui.Window
OPEN WINDOW w1 WITH FORM "testform"
LET mywin = ui.Window.getCurrent()
CALL mywin.setText("test")
MENU
ON ACTION quit
EXIT MENU
END MENU
END MAIN
```
--------------------------------
### Example: Get Window by Name and Change Title
Source: https://github.com/m121752332/fjs-fgl-2.32-manual/blob/master/doc/User/ClassWindow.md
Demonstrates opening a window, retrieving it by name, changing its title, and then closing it.
```4gl
MAIN
DEFINE w ui.Window
OPEN WINDOW w1 WITH FORM "customer" ATTRIBUTE(TEXT="Unknown")
LET w = ui.Window.forName("w1")
IF w IS NULL THEN EXIT PROGRAM 1 END IF
CALL w.setText("Customer")
MENU "Test"
COMMAND "exit" EXIT MENU
END MENU
CLOSE WINDOW w1
END MAIN
```
--------------------------------
### Example: Get the type and version of the front end
Source: https://github.com/m121752332/fjs-fgl-2.32-manual/blob/master/doc/User/ClassInterface.md
Demonstrates how to retrieve and display the front-end type and version using ui.Interface methods.
```APIDOC
## Example 1: Get the type and version of the front end
```
MAIN
MENU "Test"
COMMAND "Get"
DISPLAY "Name = " || ui.Interface.getFrontEndName()
DISPLAY "Version = " || ui.Interface.getFrontEndVersion()
COMMAND "Exit"
EXIT MENU
END MENU
END MAIN
```
```
--------------------------------
### Example: Link modules and libraries into a program
Source: https://github.com/m121752332/fjs-fgl-2.32-manual/blob/master/doc/User/Tools.html
This example demonstrates linking multiple modules and a library to create a program named 'myprog.42x'.
```bash
fgllink -o myprog.42x module1.42m module2.42m lib1.42x
```
--------------------------------
### CONSTRUCT with SQL Query Example
Source: https://github.com/m121752332/fjs-fgl-2.32-manual/blob/master/doc/User/Construct.html
This example shows a CONSTRUCT instruction followed by an SQL query.
```4gl
MAIN
DEFINE rec_1 RECORD
fld_1 INT,
fld_2 STRING(10)
END
CONSTRUCT rec_1
IF SQLCODE = 0 THEN
DISPLAY rec_1.fld_1
END IF
END MAIN
```
--------------------------------
### Simple CONSTRUCT Example
Source: https://github.com/m121752332/fjs-fgl-2.32-manual/blob/master/doc/User/Construct.html
This example demonstrates a basic CONSTRUCT instruction within a program.
```4gl
MAIN
DEFINE rec_1 RECORD
fld_1 INT,
fld_2 STRING(10)
END
CONSTRUCT rec_1
END MAIN
```
--------------------------------
### 4GL Built-in Functions Example
Source: https://context7.com/m121752332/fjs-fgl-2.32-manual/llms.txt
Demonstrates various built-in 4GL functions for string manipulation, command-line arguments, error handling, environment access, logging, and runtime information. Ensure proper error handling setup with WHENEVER ERROR.
```4gl
MAIN
DEFINE s STRING
DEFINE n INTEGER
DEFINE errtext STRING
DEFINE pid INTEGER
-- String functions
LET s = " Hello World "
DISPLAY UPSHIFT(s) -- " HELLO WORLD "
DISPLAY DOWNSHIFT(s) -- " hello world "
DISPLAY LENGTH(s) -- 15 (ignores trailing spaces, not leading)
-- Command-line arguments
DISPLAY "Program name: " || ARG_VAL(0)
DISPLAY "Num args: " || NUM_ARGS()
IF NUM_ARGS() >= 1 THEN
DISPLAY "First arg: " || ARG_VAL(1)
END IF
-- Error handling helpers
WHENEVER ERROR CONTINUE
LET n = 1/0
IF STATUS <> 0 THEN
LET errtext = err_get(STATUS)
ERR_PRINT(STATUS) -- prints error text to the error line
DISPLAY "Error " || STATUS || ": " || errtext
END IF
WHENEVER ERROR STOP
-- Environment and system
LET s = fgl_getenv("FGLDIR")
CALL fgl_setenv("MY_VAR", "myvalue")
LET pid = fgl_getpid()
DISPLAY "FGLDIR=" || s || " PID=" || pid
-- Logging
CALL startlog("/tmp/myapp.log")
CALL errorlog("Application started, PID=" || pid)
-- Window title and size (GUI mode)
CALL fgl_settitle("My Application v1.0")
CALL fgl_setsize(800, 600)
-- Runtime version
DISPLAY "Runtime: " || fgl_getversion()
END MAIN
```
--------------------------------
### WCI Parent Program Setup
Source: https://github.com/m121752332/fjs-fgl-2.32-manual/blob/master/doc/User/ClassInterface.md
Configures the main window container (WCI parent) by setting its name, text, type, size, and loading a start menu. It also includes logic to prevent exiting if child programs are still running.
```FGL
MAIN
CALL ui.Interface.setName("main1")
CALL ui.Interface.setText("This is the MDI container")
CALL ui.Interface.setType("container")
CALL ui.Interface.setSize("600px","600px")
CALL ui.Interface.loadStartMenu("appmenu")
MENU "Main"
COMMAND "Help" CALL help()
COMMAND "About" CALL aboutbox()
COMMAND "Exit"
IF ui.Interface.getChildCount()>0 THEN
ERROR "You must first exit the child programs."
ELSE
EXIT MENU
END IF
END MENU
END MAIN
```
--------------------------------
### Source String File Example (common.str)
Source: https://github.com/m121752332/fjs-fgl-2.32-manual/blob/master/doc/User/LocalizedStrings.html
Example of a source string file used to define localizable strings. A compiled version must be created.
```text
01
```
--------------------------------
### Build Information Output Example
Source: https://github.com/m121752332/fjs-fgl-2.32-manual/blob/master/doc/User/CompilingPrograms.md
Example output from `fglrun -b mymodule.42m`, showing the product version and build number, the source file path, and the pcode version.
```text
2.11.01-1161.12 /home/devel/stores/mymodule.4gl 15
```
--------------------------------
### BEFORE DIALOG Block Example
Source: https://github.com/m121752332/fjs-fgl-2.32-manual/blob/master/doc/User/MultipleDialogs.html
The BEFORE DIALOG block executes once at the start of a DIALOG instruction, before user interaction. It's used for setup and setting initial focus.
```4gl
MAIN
DEFINE rec_employee RECORD LIKE employee.*
DEFINE DIALOG d_employee ()
BEFORE DIALOG
CALL set_initial_focus(d_employee.emp_id)
AFTER DIALOG
MESSAGE "Dialog finished."
...
END DIALOG
CALL d_employee()
END MAIN
```
--------------------------------
### Example: Compile and link modules and libraries into a program
Source: https://github.com/m121752332/fjs-fgl-2.32-manual/blob/master/doc/User/Tools.html
This example demonstrates compiling .4gl files and linking .42m modules and .42x libraries to create a program named 'myprog.42x'.
```bash
fgl2p -o myprog.42x module1.4gl module2.42m lib1.42x
```
--------------------------------
### Example: Get Current Form and Hide Groupbox
Source: https://github.com/m121752332/fjs-fgl-2.32-manual/blob/master/doc/User/ClassWindow.md
Shows how to get the current window and its form, then hide a specific groupbox element via a menu command.
```4gl
MAIN
DEFINE w ui.Window
DEFINE f ui.Form
OPEN WINDOW w1 WITH FORM "customer"
LET w = ui.Window.getCurrent()
IF w IS NULL THEN EXIT PROGRAM 1 END IF
LET f = w.getForm()
MENU "Test"
COMMAND "hide" CALL f.setElementHidden("gb1",1)
COMMAND "exit" EXIT MENU
END MENU
CLOSE WINDOW w1
END MAIN
```
--------------------------------
### Example: Fill ComboBox Item List
Source: https://github.com/m121752332/fjs-fgl-2.32-manual/blob/master/doc/User/ClassComboBox.html
This example demonstrates how to get a ComboBox form field view and populate its item list using program code.
```text
01
```
```text
01
```
--------------------------------
### Open and Display Form Example
Source: https://github.com/m121752332/fjs-fgl-2.32-manual/blob/master/doc/User/FAQList.md
Shows how to open and display a form in the default SCREEN window. This avoids the extra empty window issue.
```Genero BDL
01 MAIN
03 OPEN FORM f FORM "form1"
03 DISPLAY FORM f
04 MENU "Example"
05 COMMAND "Exit"
06 EXIT MENU
07 END MENU
08 END MAIN
```
--------------------------------
### Get FGLDIR
Source: https://github.com/m121752332/fjs-fgl-2.32-manual/blob/master/doc/User/ClassApplication.html
Retrieves the system-dependent path of the runtime system's installation directory.
```APIDOC
## getFglDir
### Description
Returns the system-dependent path of the installation directory of the runtime system (FGLDIR environment variable).
### Method
`base.Application.getFglDir()`
### Returns
- STRING: The path to the FGLDIR installation directory.
```
--------------------------------
### Simple StartMenu in XML Format
Source: https://github.com/m121752332/fjs-fgl-2.32-manual/blob/master/doc/User/StartMenus.html
An example of a simple StartMenu defined using XML format.
```xml
```
--------------------------------
### Open and Display Form Example
Source: https://github.com/m121752332/fjs-fgl-2.32-manual/blob/master/doc/User/WindowsAndForms.md
Demonstrates the typical usage of `OPEN FORM` and `DISPLAY FORM` at the beginning of a program to show the main form. It also shows how to call input routines and close forms.
```42f
01 OPEN FORM f FROM "customer"
02 DISPLAY FORM f
```
```42f
01 MAIN
02 OPEN FORM f1 FROM "customer"
03 DISPLAY FORM f1
04 CALL input_customer()
05 CLOSE FORM f1
06 OPEN FORM f2 FROM "custlist"
07 DISPLAY FORM f2
08 CALL input_custlist()
09 CLOSE FORM f2
10 END MAIN
```
--------------------------------
### Get Specific Argument - 4GL
Source: https://github.com/m121752332/fjs-fgl-2.32-manual/blob/master/doc/User/ClassApplication.html
Retrieves a specific command-line argument by its position. Argument positions start from 1.
```4GL
LET arg_value = base.Application.getArgument(1)
```
--------------------------------
### Application Using Message File for Help
Source: https://github.com/m121752332/fjs-fgl-2.32-manual/blob/master/doc/User/MessageFiles.md
Demonstrates how to set up a message file and use message IDs within menu commands and dialogs to trigger help messages via SHOWHELP() or the HELP keyword.
```4gl
01 MAIN
02 OPTIONS
03 HELP FILE "help.iem"
04 OPEN WINDOW w1 AT 5,5 WITH FORM "const"
05 MENU "My Menu"
06 COMMAND "Option 1" HELP 101
07 DISPLAY "Option 1 chosen"
08 COMMAND "Help"
09 CALL SHOWHELP(103)
10 END MENU
11 CLOSE WINDOW w1
12 END MAIN
```
--------------------------------
### Get FGLDIR Path - 4GL
Source: https://github.com/m121752332/fjs-fgl-2.32-manual/blob/master/doc/User/ClassApplication.html
Retrieves the system-dependent path of the installation directory for the runtime system, as defined by the FGLDIR environment variable.
```4GL
LET fgl_dir = base.Application.getFglDir()
```
--------------------------------
### Open and Close Window Example
Source: https://github.com/m121752332/fjs-fgl-2.32-manual/blob/master/doc/User/FAQList.md
Demonstrates opening and closing a window. Use CLOSE WINDOW SCREEN at the beginning to avoid an extra empty window.
```Genero BDL
01 MAIN
02 OPEN WINDOW w1 AT 1,1 WITH FORM "form1"
03 MENU "Example"
04 COMMAND "Exit"
05 EXIT MENU
06 END MENU
07 CLOSE WINDOW w1
08 END MAIN
```
--------------------------------
### Report Driver Example with Interrupt Handling
Source: https://github.com/m121752332/fjs-fgl-2.32-manual/blob/master/doc/User/Reports.md
This example demonstrates how to use the report driver to process records and handle user interruption by checking the INT_FLAG variable. It shows the correct sequence of START REPORT, OUTPUT TO REPORT, and FINISH REPORT or TERMINATE REPORT.
```4gl
01 DATABASE stores7
02 MAIN
03 DEFINE rcust RECORD LIKE customer.*
04 DECLARE cu1 CURSOR FOR SELECT * FROM customer
05 LET int_flag = FALSE
06 START REPORT myrep
07 FOREACH cu1 INTO rcust.*
08 IF int_flag THEN EXIT FOREACH END IF
09 OUTPUT TO REPORT myrep(rcust.*)
10 END FOREACH
11 IF int_flag THEN
12 TERMINATE REPORT myrep
13 ELSE
14 FINISH REPORT myrep
15 END IF
16 END MAIN
```
--------------------------------
### Form Item Width Adjustment for Special Items
Source: https://github.com/m121752332/fjs-fgl-2.32-manual/blob/master/doc/User/FormSpecFiles.md
This example demonstrates how the width of special form items like BUTTONEDIT is automatically adjusted. The 'f1' EDIT item gets a width of 7, while the 'f2' BUTTONEDIT gets a width of 5 (7-2) to accommodate its button.
```formspec
01 GRID
02 {
03 1234567
04 [f1 ] -- this EDIT gets a width of 7
05 [f2 ] -- this BUTTONEDIT gets a width of 5 (7-2)
06 }
07 END
```
--------------------------------
### Creating a Help Action
Source: https://github.com/m121752332/fjs-fgl-2.32-manual/blob/master/doc/User/NewFeatures.md
Example of how the 'help' predefined action is created for HELP clauses in dialog instructions.
```4GL
INPUT BY NAME .... HELP 12423 -- Creates action 'help'
```
--------------------------------
### Get ComboBox Item Name by Index
Source: https://github.com/m121752332/fjs-fgl-2.32-manual/blob/master/doc/User/ClassComboBox.html
The `getItemName` method retrieves the name of an item at a specified position (index) in the combobox. Indexing starts at 1.
```javascript
local name as string
name = cb.getItemName( 1 )
```
--------------------------------
### Get ComboBox Item Text by Index
Source: https://github.com/m121752332/fjs-fgl-2.32-manual/blob/master/doc/User/ClassComboBox.html
The `getItemText` method retrieves the display text of an item at a specified position (index) in the combobox. Indexing starts at 1.
```javascript
local text as string
text = cb.getItemText( 1 )
```
--------------------------------
### ui.Interface.loadStartMenu
Source: https://github.com/m121752332/fjs-fgl-2.32-manual/blob/master/doc/User/ClassInterface.html
Loads the start menu defined in an XML file into the AUI tree.
```APIDOC
## ui.Interface.loadStartMenu
### Description
Loads the start menu defined in an XML file into the [AUI tree](DynamicUI.html). See [StartMenus](StartMenus.html) for more details.
### Method
POST
### Endpoint
ui.Interface.loadStartMenu( file STRING )
### Parameters
#### Path Parameters
- **file** (STRING) - Required - The path to the XML file defining the start menu.
### Response
#### Success Response (200)
- **return value** (void) - Indicates successful loading.
```
--------------------------------
### Usage Example: Getting Target Row
Source: https://github.com/m121752332/fjs-fgl-2.32-manual/blob/master/doc/User/ClassDragDrop.html
Illustrates how to use the `getLocationRow` method within `ON DROP` or `ON DRAG_OVER` blocks to determine the target row for a drag-and-drop operation.
```APIDOC
## Usage Example: Getting Target Row
### Description
Demonstrates the use of the `getLocationRow()` method, typically within `ON DROP` or `ON DRAG_OVER` event handlers, to identify the specific row in a target list that the dragged object is hovering over or dropped onto.
### Code
```
// Typically used within ON DROP or ON DRAG_OVER blocks
// For example, to get the target row index:
LET targetRowIndex = dnd.getLocationRow()
// This index can then be used to modify or replace the data in that row.
```
```
--------------------------------
### Open, Menu, and Close Window
Source: https://github.com/m121752332/fjs-fgl-2.32-manual/blob/master/doc/User/WindowsAndForms.md
Demonstrates opening a window with a form, setting up a menu with an exit command, and then closing the window.
```FGL
01 MAIN
02 OPEN WINDOW w1 WITH FORM "customer"
03 MENU "Test"
04 COMMAND KEY(INTERRUPT) "exit" EXIT MENU
05 END MENU
06 CLOSE WINDOW w1
07 END MAIN
```
--------------------------------
### Define Command to Start Front-End
Source: https://github.com/m121752332/fjs-fgl-2.32-manual/blob/master/doc/User/DynamicUI.html
Use the 'cmd' entry to specify the command executed to launch the front-end. The '%d' placeholder is replaced by the TCP port.
```ini
gui.server.autostart.cmd = "/opt/app/gdc-2.30/bin/gdc -p %d -q -M"
```
--------------------------------
### Start Genero DB SQL Command Interpreter
Source: https://github.com/m121752332/fjs-fgl-2.32-manual/blob/master/doc/User/odiagads.html
Use this command to verify your ODBC environment setup. Replace _dns-name_, _appadmin_, and _password_ with your actual credentials.
```bash
$ antscmd -d _dns-name_ -u _appadmin_ -p _password_
```
--------------------------------
### Invalid HBox Layout in GRID
Source: https://github.com/m121752332/fjs-fgl-2.32-manual/blob/master/doc/User/Mig0004.md
This example demonstrates an invalid GRID layout definition where HBox layout tags are used within lists, which is denied by the fglform compiler starting from version 2.20.05.
```4gl
01 SCHEMA FORMONLY
02 LAYOUT
03 GRID
04 {
05 [f01 : |f02 ] -- HBox layout tags in lists are denied
06 [f01 |f02 ]
07 [f01 |f02 ]
08 [f01 |f02 ]
09 }
10 END
11 END
```
--------------------------------
### Function Call and Return Example
Source: https://github.com/m121752332/fjs-fgl-2.32-manual/blob/master/doc/User/FlowControl.md
Demonstrates calling a function 'foo' with different inputs and handling its return values. The function returns NULLs for a NULL input and record members for a non-NULL input.
```fgl
MAIN
02 DEFINE forname, surname CHAR(10)
03 CALL foo(NULL) RETURNING forname, surname
04 DISPLAY forname CLIPPED, " ", upshift(surname) CLIPPED
05 CALL foo(1) RETURNING forname, surname
06 DISPLAY forname CLIPPED, " ", upshift(surname) CLIPPED
07 END MAIN
08
09 FUNCTION foo(code)
10 DEFINE code INTEGER
11 DEFINE person RECORD
12 name1 CHAR(10),
13 name2 CHAR(20)
14 END RECORD
15 IF code IS NULL THEN
16 RETURN NULL, NULL
17 ELSE
18 LET person.name1 = "John"
19 LET person.name2 = "Smith"
20 RETURN person.*
21 END IF
22 END FUNCTION
```
--------------------------------
### Grid Dependencies Example
Source: https://github.com/m121752332/fjs-fgl-2.32-manual/blob/master/doc/User/Layout.md
Demonstrates how grid cell sizes are influenced by the widgets they contain, ensuring text-mode alignment. This rule ensures that elements 'a' and 'b' share the same starting position and size.
```GRID
GRID
{
[a ]
[b ]
}
END
```
--------------------------------
### Import os Package Library
Source: https://github.com/m121752332/fjs-fgl-2.32-manual/blob/master/doc/User/BuiltInClasses.html
Example of importing the 'os' package library to use the Path class.
```4GL
IMPORT os
```
--------------------------------
### Initialize Dialog and Set Focus with BEFORE DIALOG
Source: https://github.com/m121752332/fjs-fgl-2.32-manual/blob/master/doc/User/MultipleDialogs.md
Use the BEFORE DIALOG block for initial dialog setup, variable initialization, and setting focus to a specific field. This block executes once at the start of a dialog.
```FGL
BEFORE DIALOG
CALL DIALOG.setActionActive("save",FALSE)
CALL DIALOG.setFieldActive("cust_status", is_admin())
IF cust_is_new() THEN
NEXT FIELD cust_name
END IF
```
--------------------------------
### Example: Using Static and Dynamic Arrays
Source: https://github.com/m121752332/fjs-fgl-2.32-manual/blob/master/doc/User/Arrays.html
Illustrates the declaration and basic usage of both static and dynamic arrays.
```Informix 4GL
DEFINE static_array STATIC ARRAY[5] OF INT
DEFINE dynamic_array DYNAMIC ARRAY OF INT
LET static_array[1] = 10
LET static_array[5] = 50
LET dynamic_array[1] = 100
LET dynamic_array[3] = 300
DISPLAY "Static array element 1: ", static_array[1]
DISPLAY "Dynamic array element 3: ", dynamic_array[3]
```
--------------------------------
### CONSTRUCT with SQL Query Example
Source: https://github.com/m121752332/fjs-fgl-2.32-manual/blob/master/doc/User/Construct.md
Shows how to use CONSTRUCT to build a WHERE clause for an SQL query, then execute the query and display results.
```4gl
01 MAIN
02
03 DEFINE condition STRING
04 DEFINE statement STRING
05 DEFINE cust RECORD
06 first_name CHAR(30),
07 last_name CHAR(30)
08 END RECORD
09
10 DATABASE stores
11
12 OPEN FORM f1 FROM "const"
13 DISPLAY FORM f1
14
15 CONSTRUCT BY NAME condition ON first_name, last_name
16 BEFORE CONSTRUCT
17 DISPLAY "A*" TO first_name
18 DISPLAY "B*" TO last_name
19 END CONSTRUCT
20
21 LET statement =
22 "SELECT first_name, last_name FROM customer WHERE " || condition
23 DISPLAY "SQL : " || statement
24
25 PREPARE s1 FROM statement
26 DECLARE c1 CURSOR FOR s1
27 FOREACH c1 INTO cust.*
28 DISPLAY cust.*
29 END FOREACH
30
31 END MAIN
```
```4gl
01 DATABASE stores
02
03 LAYOUT
04 GRID
05 {
06 FirstName [f001 ]
07 LastName [f002 ]
08 }
09 END
10 END
11
12 TABLES
13 customer
14 END
15
16 ATTRIBUTES
17 f001 = customer.first_name;
18 f002 = customer.last_name;
19 END
```
--------------------------------
### Define Form Item Position and Length
Source: https://github.com/m121752332/fjs-fgl-2.32-manual/blob/master/doc/User/FormSpecFiles.md
This example illustrates how to define the position and length of a form item. The 'f1' item starts at position 3 and has a length of 2 characters, as indicated by its placement and delimiters.
```formspec
01 GRID
02 {
03 1234567890
04 [f1]
05 }
06 END
```
--------------------------------
### Misaligned Field Tags (Vertical) in GRID
Source: https://github.com/m121752332/fjs-fgl-2.32-manual/blob/master/doc/User/Mig0004.md
This example shows a GRID layout with misaligned field tags vertically, which will cause a compilation error with fglform starting from version 2.20.05 due to stricter layout checking.
```4gl
01 SCHEMA FORMONLY
02 LAYOUT
03 GRID
04 {
05 [f01 ] [f02 ]
06 [f01 ] [f02 ] -- Misaligned field tags (vertical)
07 [f01 ] [f02 ]
08 [f01 ] [f02 ]
09 }
10 END
11 END
```
--------------------------------
### ON ACTION Block Example
Source: https://github.com/m121752332/fjs-fgl-2.32-manual/blob/master/doc/User/InputArray.md
Execute instructions when the user performs a specific abstract action. This is preferred over ON KEY for better abstraction.
```FGL
ON ACTION zoom
CALL zoom_customers() RETURNING st, cust_id, cust_name
...
```
--------------------------------
### Create and Execute Stored Procedure with Output Parameters
Source: https://github.com/m121752332/fjs-fgl-2.32-manual/blob/master/doc/User/SqlProgramming.md
Demonstrates creating a stored procedure with output parameters and then executing it using the EXECUTE IMMEDIATE and PREPARE statements. Ensure parameter types and IN/OUT/INOUT options match the procedure definition.
```SQL
01 MAIN
02 DEFINE n INTEGER
03 DEFINE d DECIMAL(6,2)
04 DEFINE c VARCHAR(200)
05 DATABASE test1
06 EXECUTE IMMEDIATE "create procedure proc1 @v1 integer, @v2 decimal(6,2) output, @v3 varchar(20) output"
07 || " as begin"
08 || " set @v2 = @v1 + 0.23"
09 || " set @v3 = 'Value = ' || cast(@v1 as varchar)
10 || "end"
11 PREPARE stmt FROM "{ call proc1(?,?,?) }"
12 LET n = 111
13 EXECUTE stmt USING n IN, d OUT, c OUT
14 DISPLAY d
15 DISPLAY c
16 END MAIN
```
--------------------------------
### Populate ComboBox Programmatically
Source: https://github.com/m121752332/fjs-fgl-2.32-manual/blob/master/doc/User/ClassComboBox.md
This example demonstrates how to get a ComboBox form field, clear its existing items, and add new items with both keys and values. It also shows how to check if an item exists before adding it.
```Program File
01 MAIN
02 DEFINE cb ui.ComboBox
03 DEFINE airport CHAR(3)
04
05 OPEN FORM f1 FROM "combobox"
06 DISPLAY FORM f1
07 LET cb = ui.ComboBox.forName("formonly.airport")
08 IF cb IS NULL THEN
09 ERROR "Form field not found in current form"
10 EXIT PROGRAM
11 END IF
12 CALL cb.clear()
13 CALL cb.addItem("CDG", "Paris-Charles de Gaulle, France")
14 CALL cb.addItem("LCY", "London-City Airport, UK")
15 CALL cb.addItem("LHR", "London-Heathrow, UK")
16 CALL cb.addItem("FRA", "Frankfurt Airport, Germany")
17 IF cb.getIndexOf("SFO") == 0 THEN
18 CALL cb.addItem("SFO", "San Francisco International Airport, CA" )
19 END IF
20
21 INPUT BY NAME airport
22
23 END MAIN
```
--------------------------------
### MAIN Program Block Initialization and Menu Handling
Source: https://github.com/m121752332/fjs-fgl-2.32-manual/blob/master/doc/User/TutChap11.md
Initializes the MAIN program block by connecting to the database, closing the screen, opening a form window, and setting up the menu actions for 'new', 'find', and 'next'. This code handles the core user interaction flow for order management.
```4gl
35 MAIN
36 DEFINE has_order, query_ok SMALLINT
37 DEFER INTERRUPT
38
39 CONNECT TO "custdemo"
40 CLOSE WINDOW SCREEN
41
42 OPEN WINDOW w1 WITH FORM "orderform"
43
44 MENU
45 BEFORE MENU
46 CALL setup_actions(DIALOG,FALSE,FALSE)
47 ON ACTION new
48 CLEAR FORM
49 LET query_ok = FALSE
50 CALL close_order()
51 LET has_order = order_new()
52 IF has_order THEN
53 CALL arr_items.clear()
54 CALL items_inpupd()
55 END IF
56 CALL setup_actions(DIALOG,has_order,query_ok)
57 ON ACTION find
58 CLEAR FORM
59 LET query_ok = order_query()
60 LET has_order = query_ok
61 CALL setup_actions(DIALOG,has_order,query_ok)
62 ON ACTION next
```
--------------------------------
### Combobox with HBox for Layout Control
Source: https://github.com/m121752332/fjs-fgl-2.32-manual/blob/master/doc/User/Mig0001.html
This example shows how to use an HBox to prevent a field like 'edit2' from growing excessively due to a preceding combobox. It suggests using HBoxes for fields that start alongside a combobox and are of similar or larger size.
```4gl
[edit1] [combo :] [edit2 :] ...
```
--------------------------------
### Create StartMenu Dynamically with DomNode
Source: https://github.com/m121752332/fjs-fgl-2.32-manual/blob/master/doc/User/StartMenus.html
Demonstrates the steps to dynamically create a StartMenu using the DomNode class. This involves getting the AUI root node, creating the StartMenu node, adding a group node, and then adding command and separator nodes.
```javascript
var root = AUI.getRoot();
var startMenu = root.createNode({"tag":"StartMenu"});
var group = startMenu.createNode({"tag":"StartMenuGroup"});
group.createNode({"tag":"StartMenuCommand", "text":"Program 1", "action":"program1();"});
group.createNode({"tag":"StartMenuCommand", "text":"Program 2", "action":"program2();"});
group.createNode({"tag":"StartMenuSeparator"});
group.createNode({"tag":"StartMenuCommand", "text":"Program 3", "action":"program3();"});
```
--------------------------------
### Create XLS File with Apache POI Framework
Source: https://github.com/m121752332/fjs-fgl-2.32-manual/blob/master/doc/User/JavaBridge.html
This example demonstrates creating an XLS file using the Apache POI framework. Ensure the Apache POI JAR is downloaded, installed, and its path is set in the CLASSPATH environment variable.
```BDL
01
// Example code using Apache POI framework would go here
```
--------------------------------
### Example: Fetching Rows into a Dynamic Array
Source: https://github.com/m121752332/fjs-fgl-2.32-manual/blob/master/doc/User/Arrays.html
Demonstrates the recommended method for populating a dynamic array with data, likely from a database query.
```Informix 4GL
MAIN
DEFINE data_array DYNAMIC ARRAY OF RECORD
id INT,
name STRING(50)
END RECORD
-- Assume 'cursor' is a valid database cursor
WHILE NOT cursor.isEnd()
LET data_array[cursor.currentRow()] = cursor.currentRowData()
CALL cursor.nextRow()
END WHILE
DISPLAY "Fetched ", data_array.getLength(), " rows."
END MAIN
```
--------------------------------
### Dynamically Create Toolbar with DOM
Source: https://github.com/m121752332/fjs-fgl-2.32-manual/blob/master/doc/User/Toolbars.md
This example demonstrates creating a toolbar dynamically using the `DomNode` class. It involves setting a default initializer, getting the form's DOM node, and then creating `ToolBar`, `ToolBarItem`, and `ToolBarSeparator` nodes with their respective attributes.
```4gl
01 CALL ui.Form.setDefaultInitializer("myinit")
02 OPEN FORM f1 FROM "form1"
03 DISPLAY FORM f1
04 ...
05 FUNCTION myinit(form)
06 DEFINE form ui.Form
06 DEFINE f om.DomNode
08 LET f = form.getNode()
09 ...
10 END FUNCTION
```
```4gl
01 DEFINE tb om.DomNode
02 LET tb = f.createChild("ToolBar")
```
```4gl
01 DEFINE tbi om.DomNode
02 LET tbi = tb.createChild("ToolBarItem")
03 CALL tbi.setAttribute("name","update")
04 CALL tbi.setAttribute("text","Modify")
05 CALL tbi.setAttribute("comment","Modify the current record")
06 CALL tbi.setAttribute("image","change")
```
```4gl
01 DEFINE tbs om.DomNode
02 LET tbs = tb.createChild("ToolBarSeparator")
```
--------------------------------
### Import util Package Library
Source: https://github.com/m121752332/fjs-fgl-2.32-manual/blob/master/doc/User/BuiltInClasses.html
Example of importing the 'util' package library to use the Math class.
```4GL
IMPORT util
```
--------------------------------
### Prepare, Execute, and Free SQL Statement
Source: https://github.com/m121752332/fjs-fgl-2.32-manual/blob/master/doc/User/DynamicSql.md
This example demonstrates preparing an SQL DELETE statement, executing it with a parameter, and then freeing the statement resources.
```4gl
01 FUNCTION deleteOrder(n)
02 DEFINE n INTEGER
03 PREPARE s1 FROM "DELETE FROM order WHERE key=?"
04 EXECUTE s1 USING n
05 FREE s1
06 END FUNCTION
```
--------------------------------
### Create XLS File with Apache POI Framework
Source: https://github.com/m121752332/fjs-fgl-2.32-manual/blob/master/doc/User/JavaBridge.md
This example shows how to create an XLS file using the Apache POI framework. Ensure the Apache POI JAR file is downloaded, installed, and its path is set in the CLASSPATH environment variable.
```Genero BDL
IMPORT JAVA java.io.FileOutputStream
IMPORT JAVA org.apache.poi.hssf.usermodel.HSSFWorkbook
IMPORT JAVA org.apache.poi.hssf.usermodel.HSSFSheet
IMPORT JAVA org.apache.poi.hssf.usermodel.HSSFRow
IMPORT JAVA org.apache.poi.hssf.usermodel.HSSFCell
IMPORT JAVA org.apache.poi.hssf.usermodel.HSSFCellStyle
IMPORT JAVA org.apache.poi.hssf.usermodel.HSSFFont
IMPORT JAVA org.apache.poi.ss.usermodel.IndexedColors
MAIN
DEFINE fo FileOutputStream
DEFINE workbook HSSFWorkbook
DEFINE sheet HSSFSheet
DEFINE row HSSFRow
DEFINE cell HSSFCell
DEFINE style HSSFCellStyle
DEFINE headerFont HSSFFont
DEFINE i, id INTEGER, s STRING
LET workbook = HSSFWorkbook.create()
LET style = workbook.createCellStyle()
CALL style.setAlignment(HSSFCellStyle.ALIGN_CENTER)
CALL style.setFillForegroundColor(IndexedColors.LIGHT_CORNFLOWER_BLUE.getIndex());
CALL style.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
LET headerFont = workbook.createFont()
CALL headerFont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD)
CALL style.setFont(headerFont);
LET sheet = workbook.createSheet()
LET row = sheet.createRow(0)
LET cell = row.createCell(0)
CALL cell.setCellValue("Item Id")
CALL cell.setCellStyle(style)
LET cell = row.createCell(1)
CALL cell.setCellValue("Name")
CALL cell.setCellStyle(style)
FOR i=1 TO 10
LET row = sheet.createRow(i)
LET cell = row.createCell(0)
CALL cell.setCellType(HSSFCell.CELL_TYPE_NUMERIC)
LET id = 100 + i
CALL cell.setCellValue(id)
LET cell = row.createCell(1)
LET s = SFMT("Item #%1",i)
CALL cell.setCellValue(s)
END FOR
LET fo = FileOutputStream.create("itemlist.xls");
CALL workbook.write(fo);
CALL fo.close();
END MAIN
```
--------------------------------
### Write HTML Page with XmlWriter
Source: https://github.com/m121752332/fjs-fgl-2.32-manual/blob/master/doc/User/ClassXmlWriter.md
This example demonstrates how to use the XmlWriter class to create an HTML file. It covers starting and ending the document, creating nested elements like HTML, HEAD, TITLE, STYLE, and BODY, and adding text content and attributes.
```MAIN
01 MAIN
02 DEFINE w om.SaxDocumentHandler
03 DEFINE a,n om.SaxAttributes
04
05 LET w = om.XmlWriter.createFileWriter("sample.html")
06 LET a = om.SaxAttributes.create()
07 LET n = om.SaxAttributes.create()
08
09 CALL n.clear()
10
11 CALL w.startDocument()
12
13 CALL w.startElement("HTML",n)
14
15 CALL w.startElement("HEAD",n)
16
17 CALL w.startElement("TITLE",n)
18 CALL w.characters("HTML page generated with XmlWriter")
19 CALL w.endElement("TITLE")
20
21 CALL a.clear()
22 CALL a.addAttribute("type","text/css")
23 CALL w.startElement("STYLE",a)
24 CALL w.characters("\nBODY { background-color:#c0c0c0; }\n")
25 CALL w.endElement("STYLE")
26
27 CALL w.endElement("HEAD")
28
29 CALL w.startElement("BODY",n)
30
31 CALL addHLine(w)
32 CALL addTitle(w,"What is XML?",1,"55ff55")
33 CALL addParagraph(w,"XML = eXtensible Markup Language ...")
34
35 CALL addHLine(w)
36 CALL addTitle(w,"What is SAX?",1,"55ff55")
37 CALL addParagraph(w,"SAX = Simple Api for XML ...")
38
39 CALL w.endElement("BODY")
40
41 CALL w.endElement("HTML")
42
43 CALL w.endDocument()
44
45 END MAIN
```
```FUNCTION
47 FUNCTION addHLine(w)
48 DEFINE w om.SaxDocumentHandler
49 DEFINE a om.SaxAttributes
50 LET a = om.SaxAttributes.create()
51 CALL a.clear()
52 CALL a.addAttribute("width","100%")
53 CALL w.startElement("HR",a)
54 CALL w.endElement("HR")
55 END FUNCTION
```
```FUNCTION
57 FUNCTION addTitle(w,t,x,c)
58 DEFINE w om.SaxDocumentHandler
59 DEFINE t VARCHAR(100)
60 DEFINE x INTEGER
61 DEFINE c VARCHAR(20)
62 DEFINE a om.SaxAttributes
63 DEFINE n varchar(10)
64 LET a = om.SaxAttributes.create()
65 LET n = "h" || x
66 CALL a.clear()
67 CALL w.startElement(n,a)
68 IF c IS NOT NULL THEN
69 CALL a.addAttribute("color",c)
70 END IF
71 CALL w.startElement("FONT",a)
72 CALL w.characters(t)
73 CALL w.endElement("FONT")
74 CALL w.endElement(n)
75 END FUNCTION
```
```FUNCTION
77 FUNCTION addParagraph(w,t)
78 DEFINE w om.SaxDocumentHandler
79 DEFINE t VARCHAR(2000)
80 DEFINE a om.SaxAttributes
81 LET a = om.SaxAttributes.create()
82 CALL a.clear()
83 CALL w.startElement("P",a)
84 CALL w.characters("Text is:")
84 CALL w.skippedEntity("nbsp") # Add a non breaking space :
84 CALL w.characters("is")
84 CALL w.characters(t)
85 CALL w.endElement("P")
86 END FUNCTION
```
--------------------------------
### Simple INPUT Statement Example
Source: https://github.com/m121752332/fjs-fgl-2.32-manual/blob/master/doc/User/RecordInput.md
Demonstrates a basic INPUT statement using a screen record specification. Ensure the form definition file (FormFile.per) and program source code are correctly set up.
```4gl
01 DATABASE stores
02
03 LAYOUT
04 GRID
05 {
06 Customer : [f001 ]
07 Name : [f002 ]
08 Last Name: [f003 ]
09 }
10 END
11 END
12
13 TABLES
14 customer
15 END
16
17 ATTRIBUTES
18 f001 = customer.customer_num ;
19 f002 = customer.fname, default = "", upshift ;
20 f003 = customer.lname ;
21 END
22
23 INSTRUCTIONS
24 SCREEN RECORD sr_cust(
25 customer.customer_num,
26 customer.fname,
27 customer.lname);
28 END
```
```4gl
01 MAIN
02
03 DEFINE custrec RECORD
04 id INTEGER,
05 first_name CHAR(30),
06 last_name CHAR(30)
07 END RECORD
09
10 OPTIONS INPUT WRAP
11
12 OPEN FORM f FROM "FormFile"
13 DISPLAY FORM f
14
15 LET INT_FLAG = FALSE
16 INPUT custrec.* FROM sr_cust.*
17
18 IF INT_FLAG = FALSE THEN
19 DISPLAY custrec.*
20 LET INT_FLAG = FALSE
21 END IF
22
23 END MAIN
```
--------------------------------
### Basic ON ACTION Example
Source: https://github.com/m121752332/fjs-fgl-2.32-manual/blob/master/doc/User/RecordInput.md
Executes a sequence of instructions when the user raises a specific abstract action. This is preferred over ON KEY for controlling user interaction.
```FGL
...
ON ACTION zoom
CALL zoom_customers() RETURNING st, cust_id, cust_name
...
```
--------------------------------
### Default Drag Start Operation in Genero BDL
Source: https://github.com/m121752332/fjs-fgl-2.32-manual/blob/master/doc/User/DragAndDrop.md
This example shows the default behavior for the ON DRAG_START event when Drag and Drop is enabled in a DISPLAY ARRAY. It sets the operation to 'copy', specifies 'text/plain' as the MIME type, and populates the buffer with the selected rows as a tab-separated string.
```BDL
01 DEFINE dnd ui.DragDrop
02 ...
03 DISPLAY ARRAY arr TO sr.*
04 ...
05 ON DRAG_START(dnd)
06 CALL dnd.setOperation("copy")
07 CALL dnd.setMimeType("text/plain")
08 CALL dnd.setBuffer(DIALOG.selectionToString("sr"))
09 ...
10 END DISPLAY
```
--------------------------------
### Install License Key with fglWrt
Source: https://github.com/m121752332/fjs-fgl-2.32-manual/blob/master/doc/User/FglErrors.md
Use this command to install a temporary license using the provided installation key.
```bash
fglWrt -k
```
--------------------------------
### Load StartMenu from XML
Source: https://github.com/m121752332/fjs-fgl-2.32-manual/blob/master/doc/User/StartMenus.md
Use the ui.Interface.loadStartMenu method to load a StartMenu definition from an XML file. The file extension can be omitted, and the system will search for it in specified environment paths.
```4gl
CALL ui.Interface.loadStartMenu("standard")
```
--------------------------------
### Program Creating Toolbar Dynamically
Source: https://github.com/m121752332/fjs-fgl-2.32-manual/blob/master/doc/User/Toolbars.html
Example demonstrating the dynamic creation of a toolbar using programming logic.
```4gl
LOCAL form_node, toolbar_node, button_node
form_node = Interface.GetFormNode()
toolbar_node = DomNode.Create("ToolBar")
form_node.AddChild(toolbar_node)
button_node = DomNode.Create("ToolBarItem")
button_node.SetAttribute("text", "New")
button_node.SetAttribute("icon", "new.ico")
button_node.SetAttribute("action", "new_file")
toolbar_node.AddChild(button_node)
button_node = DomNode.Create("ToolBarItem")
button_node.SetAttribute("text", "Close")
button_node.SetAttribute("icon", "close.ico")
button_node.SetAttribute("action", "close_file")
toolbar_node.AddChild(button_node)
```