Description
Data Dictionaries use Smart Table Locking to determine which tables need to be updated and which can be left as read-only. Tables that are part of the DDO structure of a component (e.g. dbView), for example, parent tables of the view's Server DDO, are automatically locked as needed (during save, delete, update operations).
Tables that require write access during such operations but are not part of the view's DDO structure can be given such access by adding them to the main table DDO's list of 'External Tables' using Add_System_File.
Set Add_System_File to OrdSys.File_Number DD_Lock_On_New_Save_Delete
Each record in a Table should contain a field or set of fields that provides the record a unique ID. This will usually be your Primary key. In some cases, the value of the primary key must be manually provided by the operator (e.g. entering a unique string ID as part of data input). In some cases, the back-end database will provide the primary key automatically when the record is saved. In other cases, the Data Dictionary must to provide the unique ID when the record is first saved.
The auto-increment feature of the Data Dictionary provides this facility by automatically assigning unique sequential numbers for each new record.
In order for the Data Dictionary to know what next increment value will be for a new record, it must store the last assigned number in some other external table. To create an auto-increment field, you will need to define the table and field of the external table as well as the ID field in your Data Dictionary. The field property Field_Auto_Increment is provided to do this:
Set Field_Auto_Increment Field Customer.cust_number to File_Field OrdSys.Last_Cust_Num
In this example, the field last _cust_num in the system table ordsys is designated to increment and provide a value to the field cust_number in the Table Customer.
Auto incrementing will only work correctly if the external table is a (one record) system table or is a related parent table.
You will use a system table if the unique ID is single segment as is shown in the above example with cust_number. If you are using a field from a system table, you need to register this table as an external table so that it will be correctly locked during save operations. For example:
Set Field_Auto_Increment Field to Customer.cust_number to File_Field OrdSys.Last_Cust_Num
Set Add_System_File to OrdSys.File_Number DD_Lock_On_New_Save_Delete
You may use a related parent table if your unique ID is multi-segment. For example, an order-detail ID may consist of an Order Number (OrderDtl.Order_number) and a system assigned detail number (OrderDtl.Detail_Number). If the last detail number was stored in each Order within the Order header table (OrderHea.Last_Detail_Num) the auto increment field would be defined as:
Set Field_Auto_Increment Field OrderDtl.Detail_Number to File_Field OrderHea.Last_Detail_Num
Note that this "Set Add_System_File" version of this message is preferred over the now obsolete "Send Add_System_File" message. The Set is used by the Visual DataDictionary Modeler.
See Also
Add_Client_File | Add_Server_File | System_File_Count | System_File_Number | System_File_Lock_Mode | Defining Data Dictionary Field Attributes
System and External Tables