Make a generic function for 2 diff. tables ?

Hi I want to write a generic function that can evaluate a table. I want to use it for two tables that have the same layout, only a different name. Like this: result1 := EvaluateFunction(Table1,param1,param2); result2 := EvaluateFunction(Table2,param1,param2); I can’t manage to make the function generic so I can pass both tables to it… What is the best way to do this ? Make two functions that are the same except for the tablename ? Thanks Gazz

Look up RecordRefs and FieldRefs in C/SIDE help. These data types were created exactly for this purpose - to allow dynamic assignment of tables so that a single function can be built that accepts/manipulates data from different tables. For an actual example, take a look at how the change log works. In codeunit 1, the OnGlobalModify trigger receives a RecordRef reference to a record (can be any record in any table) and then passes it in to the respective function in codeunit 423.

Is there anyone who can give me an example of how to implement recordref/fieldref ? The c/side-help is incomplete and not helping in any way. I can’t manage to pass a record to a function by means of a recordref :frowning: I looked at the cu mentioned above but it doesn’t make it all that clear to me. Newbie, you see :wink:

quote:

Hi I want to write a generic function that can evaluate a table. I want to use it for two tables that have the same layout, only a different name. Like this: result1 := EvaluateFunction(Table1,param1,param2); result2 := EvaluateFunction(Table2,param1,param2); I can’t manage to make the function generic so I can pass both tables to it… What is the best way to do this ? Make two functions that are the same except for the tablename ? Thanks Gazz
Originally posted by gazpacho - 2005 May 02 : 14:24:59

You may make a sole function working on Table1 then, when you need to run it on Table2 you may do the following: Define a variable TableVar, Type: Record, subtype: Table1 Then write some code like this: TableVar.TRANSFERFIELDS(Table2); result2 := EvaluateFunction(TableVar,param1,param2); Table2.TRANSFERFIELDS(TableVar); The last line is only needed if the table variable is changed by the function. Hope this will help Anna

If you nevertheless want to look into RecordRef’s, you could probably make good use of this demo: http://www.mibuso.com/dlinfo.asp?FileID=276