select All Records Dynamically in axapta

This is sample code to select All Records Dynamically in axapta

static void selectAllRecordsRuntimeArgs _args)
{
firstTable firstTable;
DictField dictField;
DictTable dictTable;
int field;
int fieldId;
int records;
str header, line;
;
// Create a new object of type DictTable based on the firstTable
dictTable = new DictTable(tablenum(firstTable));
// Loop through the fields on the table.
// For each field, store the field-label in the header variable.
for (field=1; field <= dictTable.fieldCnt(); field++)
{ fieldId = dictTable.fieldCnt2Id(field);
dictField = new DictField(tablenum(firstTable), fieldId);
header += strfmt("%1, ", dictField.label()); }
info(strupr(header)); // strupr changes the string to UPPERCASE // Loop through all the records in the firstTable while select firstTable
{ line = "";
// For each record in the firstTable, loop through all the //fields // and store the value of the field for this record in the //line variable.
for (field=1; field <= dictTable.fieldCnt(); field++)
{ fieldId = dictTable.fieldCnt2Id(field); dictField = new DictField(firstTable.TableId, fieldId);
// Instead of referencing to the fieldname, I reference to
//field ID // to get the fields value.
line += strfmt("%1, ", firstTable.(fieldId));
} info(line);
records++;
}
info(strfmt("%1 records were selected", records));
}