Quick Reference¶
A condensed lookup for the things you reach for constantly. For explanations, follow the links back to the relevant chapter.
Data types¶
| Type | For | Max / note |
|---|---|---|
CHAR(n) |
Fixed-length text | up to 32,767 |
VARCHAR(n) |
Variable-length text | up to 32,767 |
STRING |
Variable-length text | up to 32,767 |
TEXT |
Long / unlimited text | blob |
INTEGER |
Whole number | 32-bit |
SMALLINT |
Whole number | 16-bit |
DECIMAL(p,s) |
Exact decimal (money!) | p digits, s decimals |
MONEY(p,s) |
Currency amount | |
FLOAT |
Approximate decimal | avoid for money |
DATE |
Calendar date | shown per DBDATE |
DATETIME |
Date + time |
Operators¶
arithmetic + - * / MOD
compare = != < <= > >=
logic AND OR NOT
null IS NULL IS NOT NULL
text match MATCHES "J*" LIKE "John%"
concatenate a CLIPPED, " ", b CLIPPED a || b
Control flow¶
IF cond THEN ... ELSE ... END IF
CASE value
WHEN x ...
OTHERWISE ...
END CASE
WHILE cond ... END WHILE
FOR i = 1 TO n [STEP s] ... END FOR
FOREACH cursor INTO vars ... END FOREACH
EXIT FOR | EXIT WHILE | CONTINUE FOR
Functions¶
FUNCTION name(a, b)
DEFINE a INTEGER
DEFINE b INTEGER
RETURN a + b
END FUNCTION
CALL name(2, 3) RETURNING result
CALL do_something() -- returns nothing
Built-in functions¶
Text
| Call | Result |
|---|---|
LENGTH(s) |
Length of s |
UPSHIFT(s) |
Uppercase |
DOWNSHIFT(s) |
Lowercase |
instr(s, sub) |
Position of sub in s (0 if none) |
s[a,b] |
Substring from a to b |
s CLIPPED |
s with trailing spaces removed |
ASCII n / CHR(n) |
Character ↔ code |
Numbers
| Call | Result |
|---|---|
ABS(x) |
Absolute value |
ROUND(x, n) |
Round to n decimals |
TRUNC(x, n) |
Truncate |
x MOD y |
Remainder |
Dates
| Call | Result |
|---|---|
TODAY |
Today's date |
CURRENT |
Current date and time |
YEAR(d) / MONTH(d) / DAY(d) |
Parts of a date |
WEEKDAY(d) |
Day of week (0 = Sunday) |
MDY(m, d, y) |
Build a date |
d + 30 |
30 days later |
end - start |
Days between |
Formatting
LET text = amount USING "###,##&.&&" -- number with separators
LET text = order_date USING "yyyy-mm-dd" -- date as text
Program / system
| Call | Result |
|---|---|
NUM_ARGS() |
Number of command-line args |
ARG_VAL(i) |
The i-th argument |
fgl_getenv("VAR") |
An environment variable |
Screens and lists¶
OPEN WINDOW w WITH FORM "name" CLOSE WINDOW w
DISPLAY BY NAME var, var2 DISPLAY value TO field
INPUT BY NAME var, var2 [WITHOUT DEFAULTS]
MENU "title" COMMAND "X" ... EXIT MENU END MENU
CALL SET_COUNT(n)
DISPLAY ARRAY a TO sr.* ... END DISPLAY
INPUT ARRAY a FROM sr.* ... END INPUT
ARR_CURR() -- current row number
Status flags:
| Flag | Meaning |
|---|---|
INT_FLAG |
True if the user cancelled |
SQLCA.SQLCODE |
0 ok, 100 not found, <0 error |
STATUS |
Result of the last non-SQL operation |
SQL¶
DATABASE db
SELECT cols INTO vars FROM t WHERE ...
DECLARE c CURSOR FOR SELECT ... FOREACH c INTO vars ... END FOREACH
INSERT INTO t (...) VALUES (...)
UPDATE t SET col = val WHERE ...
DELETE FROM t WHERE ...
PREPARE p FROM "... ?" EXECUTE p USING v INTO out
BEGIN WORK COMMIT WORK ROLLBACK WORK
WHENEVER ERROR STOP|CONTINUE WHENEVER NOT FOUND CONTINUE
VDC client calls¶
CALL ui.Interface.setText("Title")
CALL ui.Interface.loadStyles("default")
DEFINE w ui.Window DEFINE f ui.Form
LET w = ui.Window.getCurrent() LET f = w.getForm()
CALL f.setFieldHidden("field", 1) -- 1 hide, 0 show
DEFINE cb ui.ComboBox
LET cb = ui.ComboBox.forName("field") CALL cb.clear()
CALL cb.addItem("value", "Label")
CALL ui.vdc.toast("Saved", 0, 3000) -- type 0=ok 1=error 2=warn 3=info
Build commands¶
4glpc -o prog.4ae prog.4gl # single file
4glpc -o app.4ae a.4gl b.4gl c.4gl # multi-file (globals first)
4glc -o mod.ao mod.4gl # one module to an object
4glpc -o app.4ae *.ao # link objects
fcompile -xml form.per # a form
4glc --as-dll -o lib.so a.4gl b.4gl # a shared library
./prog.4ae # run
Environment variables¶
export AUBITDIR=/opt/aubit4gl
export PATH=$AUBITDIR/bin:$PATH
export LD_LIBRARY_PATH=$AUBITDIR/lib:$LD_LIBRARY_PATH
export A4GL_UI=XML # speak the VDC protocol
export AFGLSERVER=127.0.0.1 # where the client listens
export AFGLPORT=3490 # the client's port
export DBPATH=.:/path/to/forms # where forms are found
export DBDATE=DMY4/ # date display, e.g. 31/12/2026
export DB_LOCALE=en_US.UTF-8
export CLIENT_LOCALE=en_US.UTF-8
The gotchas, in one place¶
DEFINEstatements go at the top of a function, before any code.- Test empty text with
LENGTH(x CLIPPED) > 0, notx != "". STRINGhas no methods — useinstr,x[a,b],UPSHIFT,DOWNSHIFT,CLIPPED.- You cannot pass an array as a parameter — use
COPYOF(read-only) or a global array. - There is no
TRY/CATCHand noELSE IF(two words) — check status, and useCASE.
That is the everyday toolkit. For the exhaustive lists, see the Language Reference (every statement and built-in) and the Command-line Tools page. The fastest way to learn, though, is to type the examples in, compile them, and change them until they break — then fix them.