Records and functions
Records can be passed as function parameters, and can be returned from functions.
Passing and returning records as structured values
Records can be passed as a structured value to a function or to a method, when you specify only
the name of the record as parameter (i.e. without the .*
notation).
For better compiler checking, functions should be defined with the fully typed syntax; Note that methods for types can only be defined with a fully typed syntax.
TYPE t_cust RECORD LIKE customer.*
...
FUNCTION display_customer( cust t_cust ) RETURNS ()
...
END FUNCTION
...
DEFINE cust_1 t_cust
CALL display_customer( cust_1 )
This syntax improves code readability and robustness: A compilation error occurs, if the types do not match.
RETURNS
clause, and when only the name of the record variable is used in the
RETURN
instruction:FUNCTION init_customer() RETURNS ( t_cust )
DEFINE c t_cust
LET c.cust_id = 999
RETURN c
END FUNCTION
...
DEFINE cust_1 t_cust
LET cust_1 = init_customer()
Passing records by reference with INOUT
INOUT
keyword:TYPE t_cust RECORD LIKE customer.*
...
FUNCTION init_customer( cust t_cust INOUT ) RETURNS ()
LET cust.cust_id = 101
END FUNCTION
...
DEFINE cust_1 t_cust
CALL init_customer( cust_1 )
DISPLAY cust_1.cust_id -- Shows 101
Passing and returning records with .*
notation
The .*
(dot-star) notation to pass and return records
to/from functions is supported for backward compatibility. Consider to define functions with
parameter and return type definitions, and use only the name of the record variable as parameter or
return value target. See Passing and returning records as structured values
record-name.*
notation, the record is expanded, as if each individual member had been passed by
value:TYPE t_cust RECORD LIKE customer.*
...
FUNCTION display_customer( cust )
DEFINE cust t_cust
...
END FUNCTION
...
DEFINE cust_1 t_cust
CALL display_customer( cust_1.* )