Tech Tip: Getting a list of field names from a table name
PRODUCT: 4D | VERSION: 14.x | PLATFORM: Mac & Win
Published On: June 17, 2015
SQL system tables can be used to determine the field names of a certain table. Below is an utility method using SQL's system tables to obtain a list of a table's fields given the table name.
//Method name: GetFieldsFromTable //Determines if character specified in string is a vowel //$1 - Table name //$2 - Array to contain resulting field names C_TEXT($1;$tablename) C_POINTER($2;$arrFields) If(Count parameters>=2) $tablename:=$1 $arrFields:=$2 Begin SQL SELECT COLUMN_NAME FROM _USER_COLUMNS WHERE TABLE_NAME=:$tablename INTO :$arrFields; End SQL End if |
Example:
Given the following table:

Run the utility method above:
ARRAY TEXT($arrFields;0) GetFieldsFromTable("Table_1";->$arrFields) |
The resulting array of fields are listed:
