Referencing records and fields via RecordRef and FieldRef
The NAV datatype Record
provides an interface to tables in the database. A certain limitation of the Record type is that a declaration of a Record
variable is fixed in design time. Each variable must be linked to a table in the object design, and the link cannot be changed dynamically.
An alternative to static linking is the RecordRef
datatype. A variable of RecordRef
type is assigned to a specific table at runtime, but dynamics linking leads to higher complexity of code.
How to do it...
The RecordRef
and FieldRef
datatypes will be used to write a function comparing two records from the same table.
Create a codeunit in the object designer and declare a local function
CompareRecords
in the codeunit. This is the function that will do the comparison. Set the function's return type toBoolean
.Access the C/AL Locals in the function
CompareRecords
, declare a parameterRecRef
of typeRecordRef
. After that, open the parameter properties and set...