Export CSV file

Hi Guys,.

Today i’m going to share one of the easiest way to Export and Import the Data without Microsoft Office Excel.
Its Comma Separated Value (CSV). The main Objective of CSV is storing the table record in the CSV file. even though i have found it from CookBook. But i have modified that coding for General Purpose in any table we can easily Export and Import.
Here i have written my Job for Exporting Complete data of any defined Table into CSV..

static void ExportCSV(Args _args)
 common TableBuffer;
 DictTable dictTable = new DictTable(tableNum(TableName)); // Define Table Name
 str TableName = dictTable.name();
 DictField dictField;
 int i;
 CommaIo file;
 container line;
 str path = 'C:\\Users\\saadullah\\Documents\\'+TableName+'.csv'; // Directory Path
file = new CommaIo(#filename, #io_write);
if (!file || file.status() != IO_Status::Ok)
 throw error("File cannot be opened.");
TableBuffer = dictTable.makeRecord();
// Select the Entire Table
 while select TableBuffer
 // 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.id(), dictTable.fieldCnt2Id(i));
// Adding the Selected Field values in Container
 line += [ TableBuffer.(dictField.id()) ];
 // Wrting the Selected Container Expression in File
// we have to store the Next Records , so we are making Container to Null
 line = ConNull();
info(strfmt("File Successfully Created in %1", #filename));

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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