Skip to content

How do I get number of fields/columns read from a data file

This example demonstrates fetching the number of columns in a dataset after reading the data from a data file.

In the solution shown below, a dataset is created with the specified data definition that holds the attributes of the data file using "ddCreateDataSet" command. The data from the data file is read into this dataset using "ddCreateDatasetFromADatafile" command. The total number of columns is fetched from a dataset using "ddGetColumnCount" command and stored into a variable

Solution:
# Command Target Value
Creating the dataset and specifying the data definition name of the data file
1ddCreateDataSet InsuranceDetails Insurance Details(W)
Reading the data from the data file into the dataset
2ddCreateDatasetFromADatafile Insurance Details(W) InsuranceDetails
Getting the number of columns from the dataset
3ddGetColumnCount InsuranceDetails Column_Count

Tips, Tricks, Gotchas & Best Practices: 

  • You should use the same dataset name which is created by using "ddCreateDataSet" command in "ddCreateDatasetFromADatafile" and "ddGetColumnCount" commands.
  • You can optionally pass the status of the Data Definition and Data file along with their names in "ddCreateDataSet" and "ddCreateDatasetFromADatafile" commands respectively. Allowed values for status are 'W'(WIP) and 'A'(Active). If the status value is not passed, the status is assumed to be 'W'(WIP).
  • As a best practice, it is always advisable to define the variable names without any spaces and if you want to differentiate the words, use underscores.


Feedback and Knowledge Base