Import CSV files

As you have seen the Exporting Complete Table Record into CSV in the last post. Same way here i have written Code for Importing CSV into Table

static void Import_CSV(Args _args)
common TableBuffer;
DictTable dictTable = new DictTable(tableNum(TableName)); // Define Table Name
str TableName =;
DictField dictField;
int i;
CommaIo file;
container line;
str path = 'C:\\Users\\saadullah\\Documents\\'+TableName+'.csv'; // Directory Path
file = new CommaIo(#filename, #io_read);
if (!file || file.status() != IO_Status::Ok)
 throw error("File cannot be opened.");
TableBuffer = dictTable.makeRecord();
while (file.status() == IO_Status::Ok)
 line =; // Selecting File values line by line as assigning to Container
 if (line != conNull())
 // Looping the Table Field
 // we have Defined - 15 from the Counting of Fields 
 // we do not Require 15 System Field such as RecId, RecVersion, Created By, Created Datetime, Modified By, etc...
 for( i =1; i <= dictTable.fieldCnt() -15; i++)
 // Selecting the Fields
 dictField = new DictField(, dictTable.fieldCnt2Id(i));
 // Assigning the Container values to the Selected Table Field
 TableBuffer.( = conpeek(line, i);
 // Inserting Record 

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s