Adds a new column to a table.
Type: Function
Parameters: Handle hTable, String sColumnName, Integer iDataType, Integer iLength, Integer iPrecision
Parameter |
Description |
hTable |
A file handle to the table name. Same as the Filelist.cfg slot number. Note: If instead need to pass the table name as a string you can use the SQLColumnAddByTableName function. |
sColumnName |
The new column name to be added |
iDataType |
Any of the framework replacement data type constants or SQL data types. Note: Do NOT use any of the standard DataFlex data types, such as DF_ASCII, DF_BCD, DF_DATE etc. See Mapping of SQL Data Types. |
iLength |
Optional. The length of the column. Only applicable for some field types like e.g. SQL_VarChar. |
iDecimals |
Optional. The precision of the column, aka number of decimals. Only applicable for some field types like e.g. SQL_Numeric or SQL_Decimal. |
bInitVal |
Optional. Pass True if the new column should be populated with a sColumnValue for each existing row. |
sColumnValue |
Optional. The value to insert in each table row for the new column. Only needed if bInitVal = True |
Syntax
Function ApiColumnAdd Handle hTable String sNewColumnName Integer iDataType Integer iLength
Call: |
Get ApiColumnAdd 0 MyTableName.File_Number "NewColumn" DF_ASCII_DUF 30 0 True "InitValue" to bOK |
Description
Use it to create or add a new column to a table. The iDataType can be any of the data types defined in DataFlex. The iLength and iDecimals parameter are optional, unless a data type that are not "fixed" in length is passed.
Note: Internally it uses the ApiColumnUpdateValue function if the bInitVal = True. If you want to add a field/column to an SQL table, use the SQLColumnAdd function instead.
Example
Procedure OnUpdate
Boolean bOK
Get ApiColumnAdd Invoice.File_Number "PrintedFlag" DF_BCD_DUF 2 0 True "1" to bOK
End_Procedure