KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Utility method to get all table and field names
PRODUCT: 4D | VERSION: 13.3 | PLATFORM: Mac & Win
Published On: July 25, 2013

This Technical Tip includes a utility method that retrieves all table and field names in the structure. The method populates two arrays, a one-dimensional array with all table names and a two-dimensional array with all field names.

// ----------------------------------------------------
// Method: UTIL_get_table_and_field_names
// Description
//   Method populates two arrays with all Table and Field names in the structure
// Parameters
//   $1 (Pointer) - Pointer to a one-dimensional text array
//                  Array will be populated with all Table names in the structure
//   $2 (Pointer) - Pointer to a two-dimensional text array
//                  Array will be populated with all field names to all tables in the
//                  structure

// ----------------------------------------------------

C_POINTER($1;$2)
C_LONGINT($num_tables_l)
ARRAY TEXT($table_names_at;0)
C_LONGINT($num_fields_l)

$num_tables_l:=Get last table number
ARRAY TEXT($field_names_at;$num_tables_l;0)

For ($i;1;$num_tables_l)
   If (Is table number valid($i))
      APPEND TO ARRAY($table_names_at;Table name($i))
      $num_fields_l:=Get last field number($i)
      For ($j;1;$num_fields_l)
         If (Is field number valid($i;$j))
            APPEND TO ARRAY($field_names_at{$i};Field name($i;$j))
         End if
      End for
   End if
End for

COPY ARRAY($table_names_at;$1->)
COPY ARRAY($field_names_at;$2->)


Here is an example of how the method can be called:

ARRAY TEXT(table_names_at;0)
ARRAY TEXT(field_names_at;0;0)

UTIL_get_table_and_field_names(->table_names_at;->field_names_at)