KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Acquiring Pointers to Converted Subtables and Subtable Fields
PRODUCT: 4D | VERSION: 11 | PLATFORM: Mac & Win
Published On: June 18, 2009

When working with 4D v11 SQL and converted databases that had subtables in previous versions, some thought and planning needs to be focused on the converted tables. One aspect that could be a challenge is getting a pointer to the converted table and its fields.

This can be overcome fairly easily. Thanks to the naming convention that was adapted, you can programmatically acquire a pointer to a converted table. Given a subtable named "[MyTable]MySubtable", by convention 4D names the converted table "[MyTable_MySubtable]".

The code snippet below shows how to take the subtable addressing convention from previous versions of 4D and acquire a pointer to the table and field in the converted table. 4D v11 SQL converts subtables and uses this naming convention to access converted subrecords; but only as long as the relation to the converted table is unmodified.

C_LONGINT($Pos)
C_TEXT($TableName_T;Subtable_T;Field_T)
C_POINTER($Subtable_P;$Field_P)

$TableName_T:="[OneTable]Subjects'Subject"

$Pos:=Position("'";$TableName_T)
Field_T:=Substring($TableName_T;$Pos+1)
$TableName_T:=Substring($TableName_T;1;$Pos-1)

Subtable_T:=Replace String($TableName_T;"]";"_")+"]"

EXECUTE FORMULA("$Subtable_P:=(->"+Subtable_T+")")
EXECUTE FORMULA("$Field_P:=(->"+Subtable_T+Field_T+")")