Skip to main content
insightsoftware Documentation insightsoftware Documentation
{%article.title%}
Published:
Was this article helpful?
0 out of 0 found this helpful

Insert DataTableRow

Once you have created an in-memory DataTable object, you can add a row to it dynamically using this command.

This command can be useful when you want to move existing data from a hierarchical DataArea to a flat DataTable.

You can use the CreateList function with the Populated data option to retrieve data from the DataArea and store it in a variable. You can then use the Insert DataTableRow command to insert the contents of the list variable into a row in a table.

Note: If you’re using lists to extend the contents of the column name variable, including adding columns with the userlist data type, you must use the ListAppend function.

If you want to move existing data from a DataTable object back to a hierarchical DataArea, use the Fetch command.

Syntax:

Insert DataTableRow Into DataTableName using VariableName

where:

  • DataTableName is the name of a DataTable object in which to insert the row.
  • VariableName is the name of a string variable. The STRING list variable contains a value for each column in the DataTable. Each value in the STRING list variable can be translated to a correct data type according to the column in the DataTable (for example, string or number).

Note: The column order is determined by the ColumnID, in the LV_APPTABLE_COLUMNS table, in ascending order for the particular DataTable.

Syntax example:

// Populates DataTable dtSalary with data from dataArea daSalary

// Create and download the dataArea that we want to use as our source

Create DATAAREA daSalary using "Salary.lvdsp"

Create LOCK USER USING "Salary.lvdsp"

Download daSalary StandardAll

 

// Create the DataTable

Create DATATABLE dtSalary using "Salary.lvdtd"

 

// Variables to store fields of each record to insert into the DataTable

Create VARIABLE sField AS STRING

Create VARIABLE ID AS NUM

Create VARIABLE EmpNames[] AS STRING

Create VARIABLE Positions[] AS STRING

Create VARIABLE Salaries[] AS NUM

Create VARIABLE Entity AS STRING

Create VARIABLE Categories[] AS STRING

  Set VARIABLE ID = 0 set Variable Entity = E11211  

// Extract the data out of the dataArea into lists  

// List of employee names from dataArea

Set VARIABLE sField = "Employee_Name"

Set VARIABLE EmpNames = CreateList("POPULATEDDATA", "daSalary", "STRING", "VALUES", "SalaryFields.lvdsp")

//ExportVariable EmpNames "DataTable2.out" APPEND  

// List of employee positions from dataArea

Set VARIABLE sField = "Employee_Position"

Set VARIABLE Positions = CreateList("POPULATEDDATA", "daSalary", "STRING", "VALUES", "SalaryFields.lvdsp")

//ExportVariable Positions "DataTable2.out" APPEND  

// List of salaries from dataArea

Set VARIABLE sField = "AnnualBase"

Set VARIABLE Salaries = CreateList("POPULATEDDATA", "daSalary", "NUM", "VALUES", "SalaryFields.lvdsp")

//ExportVariable Salaries "DataTable2.out" APPEND  

// List of categories from dataArea

Set VARIABLE sField = "Employee_Category"

Set VARIABLE Categories = CreateList("POPULATEDDATA", "daSalary", "STRING", "VALUES", "SalaryFields.lvdsp")

//ExportVariable Categories "DataTable2.out" APPEND  

// Variable to store row information to insert Create VARIABLE MyTableRow[] AS STRING  

// loop through each list and populate MyTableRow

  For EACH sItem in EmpNames  

// Clear MyTableRow

Set VARIABLE MyTableRow = ""

Set Variable ID = $ID$ + 1  

Set VARIABLE MyTableRow = NumToStr("$ID$")

Set VARIABLE MyTableRow = ListAppend(MyTableRow, "$EmpNames[$ID$]$" )

Set VARIABLE MyTableRow = ListAppend(MyTableRow, "$Positions[$ID$]$" )

Set VARIABLE MyTableRow = ListAppend(MyTableRow, "$Categories[$ID$]$" )

Set VARIABLE MyTableRow = ListAppend(MyTableRow, "$Salaries[$ID$]$" )

Set VARIABLE MyTableRow = ListAppend(MyTableRow, "$Entity$" )  

// Insert the row into the table Insert DataTableRow Into dtSalary using MyTableRow  

Next  

Show DATATABLE dtSalary using TABLE "Salary.lvtvw"

See also

Published:

Insert DataTableRow

Once you have created an in-memory DataTable object, you can add a row to it dynamically using this command.

This command can be useful when you want to move existing data from a hierarchical DataArea to a flat DataTable.

You can use the CreateList function with the Populated data option to retrieve data from the DataArea and store it in a variable. You can then use the Insert DataTableRow command to insert the contents of the list variable into a row in a table.

Note: If you’re using lists to extend the contents of the column name variable, including adding columns with the userlist data type, you must use the ListAppend function.

If you want to move existing data from a DataTable object back to a hierarchical DataArea, use the Fetch command.

Syntax:

Insert DataTableRow Into DataTableName using VariableName

where:

  • DataTableName is the name of a DataTable object in which to insert the row.
  • VariableName is the name of a string variable. The STRING list variable contains a value for each column in the DataTable. Each value in the STRING list variable can be translated to a correct data type according to the column in the DataTable (for example, string or number).

Note: The column order is determined by the ColumnID, in the LV_APPTABLE_COLUMNS table, in ascending order for the particular DataTable.

Syntax example:

// Populates DataTable dtSalary with data from dataArea daSalary

// Create and download the dataArea that we want to use as our source

Create DATAAREA daSalary using "Salary.lvdsp"

Create LOCK USER USING "Salary.lvdsp"

Download daSalary StandardAll

 

// Create the DataTable

Create DATATABLE dtSalary using "Salary.lvdtd"

 

// Variables to store fields of each record to insert into the DataTable

Create VARIABLE sField AS STRING

Create VARIABLE ID AS NUM

Create VARIABLE EmpNames[] AS STRING

Create VARIABLE Positions[] AS STRING

Create VARIABLE Salaries[] AS NUM

Create VARIABLE Entity AS STRING

Create VARIABLE Categories[] AS STRING

  Set VARIABLE ID = 0 set Variable Entity = E11211  

// Extract the data out of the dataArea into lists  

// List of employee names from dataArea

Set VARIABLE sField = "Employee_Name"

Set VARIABLE EmpNames = CreateList("POPULATEDDATA", "daSalary", "STRING", "VALUES", "SalaryFields.lvdsp")

//ExportVariable EmpNames "DataTable2.out" APPEND  

// List of employee positions from dataArea

Set VARIABLE sField = "Employee_Position"

Set VARIABLE Positions = CreateList("POPULATEDDATA", "daSalary", "STRING", "VALUES", "SalaryFields.lvdsp")

//ExportVariable Positions "DataTable2.out" APPEND  

// List of salaries from dataArea

Set VARIABLE sField = "AnnualBase"

Set VARIABLE Salaries = CreateList("POPULATEDDATA", "daSalary", "NUM", "VALUES", "SalaryFields.lvdsp")

//ExportVariable Salaries "DataTable2.out" APPEND  

// List of categories from dataArea

Set VARIABLE sField = "Employee_Category"

Set VARIABLE Categories = CreateList("POPULATEDDATA", "daSalary", "STRING", "VALUES", "SalaryFields.lvdsp")

//ExportVariable Categories "DataTable2.out" APPEND  

// Variable to store row information to insert Create VARIABLE MyTableRow[] AS STRING  

// loop through each list and populate MyTableRow

  For EACH sItem in EmpNames  

// Clear MyTableRow

Set VARIABLE MyTableRow = ""

Set Variable ID = $ID$ + 1  

Set VARIABLE MyTableRow = NumToStr("$ID$")

Set VARIABLE MyTableRow = ListAppend(MyTableRow, "$EmpNames[$ID$]$" )

Set VARIABLE MyTableRow = ListAppend(MyTableRow, "$Positions[$ID$]$" )

Set VARIABLE MyTableRow = ListAppend(MyTableRow, "$Categories[$ID$]$" )

Set VARIABLE MyTableRow = ListAppend(MyTableRow, "$Salaries[$ID$]$" )

Set VARIABLE MyTableRow = ListAppend(MyTableRow, "$Entity$" )  

// Insert the row into the table Insert DataTableRow Into dtSalary using MyTableRow  

Next  

Show DATATABLE dtSalary using TABLE "Salary.lvtvw"

See also

For an optimal Community experience, Please view on Desktop