Summary:
See also: Variables, Records, Data Types, Constants.
A user type is a data type based on built-in types, records or arrays.
TYPE identifier definition
You can define a user type as a synonym for an existing data type, or as a shortcut for records and array structures.
After declaring a user type, it can be used as a normal data type to define variables.
The scope of a user type is the same as for variables and constants. Types can be global, local to a module, or local to a function.
01
TYPE customer RECORD02
cust_num INTEGER,03
cust_name VARCHAR(50),04
cust_addr VARCHAR(200)05
END RECORD06
DEFINE c customer
The following example defines the user type in a globals file and then uses the type in a report program:
01
-- typeglobals.4gl02
03
GLOBALS04
TYPE rpt_order RECORD05
order_num INTEGER,06
store_num INTEGER,07
order_date DATE,08
fac_code CHAR(3)09
END RECORD10
END GLOBALS
01
-- report1.4gl02
03
GLOBALS "typeglobals.4gl"04
05
MAIN06
DEFINE o rpt_order07
CONNECT TO "custdemo"08
DECLARE order_c CURSOR FOR09
SELECT order_num,10
store_num,11
order_date,12
fac_code13
FROM orders14
START REPORT order_list15
FOREACH order_c INTO o.*16
OUTPUT TO REPORT order_list(o.*)17
END FOREACH18
FINISH REPORT order_list19
DISCONNECT CURRENT20
END MAIN21
22
REPORT order_list(ro)23
DEFINE ro rpt_order24
25
FORMAT26
ON EVERY ROW27
PRINT ro.order_num,...