Monday 10 June 2013

How do I fetch data if my table/view name comes as a parameter in a string?

Well, that's where I got stuck once.
But after much investigation, I discovered the solution.

You can make use of SysDictTable class here, pass the name as a string and store the data in buffer of type Common so that no error is raised.


SysDictTable dictTable = SysDictTable::newName('myTableName');
Common common = dictTable.makeRecord();

Now if you want to read a particular field "Description" from table myTableName, if you try doing that by writing Common.Description  you would get an error.

Instead, you should follow this method:

while select common
{
info (common.(dictTable.fieldName2Id('Description')));
}