KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Method to Get Count and Names of All or Non-Invisble Tables
PRODUCT: 4D | VERSION: 19 | PLATFORM: Mac & Win
Published On: December 30, 2021

The methods below can be used to get a collection containing the names of all the tables in the database. The .length property of the returned collection can be used to find the table count. The methods do not include deleted or trashed tables.

Depending on whether you want to get all or only the non-invisible tables, the first method returns all table names in the structure and the second method utilizes GET TABLE TITLES which returns all non-invisible tables in the structure.

Get names of all tables.

//================================
//Method: GetTableNames
//Description: Get all table names in the structure. Does not include deleted tables.
//Parameters:
// $0 (Collection) = Collection of table names
//================================
C_COLLECTION($0;$tableNames_c)
C_LONGINT($lastTable_l;$i)
C_TEXT($text_t)

$tableNames_c:=New collection
$lastTable_l:=Get last table number
For ($i;1;$lastTable_l)
  If (Is table number valid($i))
    $tableNames_c.push(Table name($i))
  End if
End for
$0:=$tableNames_c


Get names of non-invisible tables.
//================================
//Method: GetTableNames
//Description: Get all non-invisible table names in the structure. Does not include deleted tables.
//Parameters:
// $0 (Collection) = Collection of table names
//================================
ARRAY TEXT($tableTitle_a;0)
ARRAY LONGINT($tableNum_a;0)
C_COLLECTION($0;$tableNames_c)

GET TABLE TITLES($tableTitle_a;$tableNum_a)
ARRAY TO COLLECTION($tableNames_c;$tableTitle_a)
$0:=$tableNames_c

Commented by Jody Bevan on January 12, 2022 at 6:30 AM
Though you have written what Get Table Title correctly (technically) it was written in a way that made me have to read it a few times to understand what you were actually saying. I suggest that it be changed from 'non-invisible tables', to all visible tables. OK, I am nitpicking, but as a native english speaker it is much easier to understand.