Records as function parameters
Records can be passed to function by value or by reference.
Records can be passed as function parameters, and can be returned from functions.
When passing records to functions with the
record-name.*
notation, the record is expanded, as if each individual member had been passed by
value:TYPE t_cust RECORD
id INTEGER,
name VARCHAR(50)
END RECORD
MAIN
DEFINE r t_cust
LET r.id = 999
LET r.name = "Mike Torme"
CALL func1(r.*) -- Local variable r is not changed
DISPLAY "1: ", r.id, " ", r.name
CALL func2() RETURNING r.* -- Local variable r is changed
DISPLAY "2: ", r.id, " ", r.name
END MAIN
FUNCTION func1(x t_cust)
LET x.name = "Scott Finley"
END FUNCTION
FUNCTION func2()
DEFINE x t_cust
LET x.id = 998
LET x.name = "Scott Finley"
RETURN x.*
END FUNCTION
Output:
1: 999 Mike Torme
2: 998 Scott Finley
Records can be passed to functions by reference, if the function is defined with the
INOUT
keyword:TYPE t_cust RECORD
id INTEGER,
name VARCHAR(50)
END RECORD
MAIN
DEFINE r t_cust
LET r.id = 999
LET r.name = "Mike Torme"
CALL func1(r) -- Local variable r is changed
DISPLAY "1: ", r.id, " ", r.name
END MAIN
FUNCTION func1(x t_cust INOUT)
LET x.name = "Scott Finley"
END FUNCTION
Records can be passed by value to a method, when you specify only the name of the
record:
TYPE t_class RECORD
id INTEGER
END RECORD
TYPE t_cust RECORD
id INTEGER,
name VARCHAR(50)
END RECORD
MAIN
DEFINE o t_class
DEFINE r t_cust
LET r.id = 999
LET r.name = "Mike Torme"
CALL o.meth1(r) -- Local variable r is not changed
DISPLAY "1: ", r.id, " ", r.name
END MAIN
FUNCTION (this t_class) meth1(x t_cust)
LET this.id = x.id
LET x.name = "Scott Finley"
END FUNCTION
Output:
1: 999 Mike Torme
For more details, see Passing a record as parameter.