Write/Create Files into folder during Batch jobs

A sample code to write data into specified directory. I have used TEXTIO  here because my requirment is to run that from batch and i have used sys Operational framework  .

 

 

TextIo textIOWrite;
str fileLine, headerFileLine, fileName, filePath;
//Creating the header of my file

headerFileLine = strFmt(“%1|%2|%3|%4|%5|%6|%7|%8|%9|%10|%11|%12|%13|%14|%15|%16|%17|%18|%19|%20|%21|%22|%23|%24”,
‘client’, ‘company’, ‘keycode’, ‘order_number’, ‘order_date’, ‘po_number’, ‘po_date’, ‘international’, ‘ship_method’, ‘first_name’, ‘last_name’ ,’addr1′,
‘addr2′ ,’addr3′ ,’city’ ,’state’ ,’zip’ ,’country’ ,’ship_date’ ,’comments’ ,’item’, ‘description’ ,’size’ , ‘qty’);

//Insert logic here for data manupilation

// Inserting data into my FileLine
fileLine = strFmt(“%1|%2|%3|%4|%5|%6|%7|%8|%9|%10|%11|%12|%13|%14|%15|%16|%17|%18|%19|%20|%21|%22|%23|%24″,
’56’, countryName , ‘DEFAULT’, salesTable.SalesId, salesLine.ShippingDateRequested, SalesTable.CustomerRef, SalesLine.ReceiptDateRequested,
Country, SalesLine.DlvMode,’ ‘, SalesLine.DeliveryName, addr1, addr2, addr3, city , state , zip, logisticsPostalAddress.CountryRegionId,
SalesLine.ShippingDateRequested, notes, salesLine.ItemId, SalesLine.itemName(), Size::findbyRecId(InventTable::find(salesLine.ItemId).Size).Name,SalesLine.SalesQty);

//After creating the header and data line i am creating my file now
fileName = ‘MyFile’ + ‘.csv’; // I am creating CSV files here

filePath = SysFileStoreParameters::find().OutgoingDirectory; // I have created a parameter to save my folder location in system parameters and reading data from that custom parameter

if (filePath == ”)
{
throw error(‘File path no setup.’);
}

if (subStr(filePath, strLen(filePath)-1, 1) != @”\”)
{
filePath = filePath +@”\”;
}

filePath = filePath+fileName;

languageId = SystemParameters::find().SystemLanguageId;

FileIOPermission = new FileIOPermission(filePath, “RW”);
FileIOPermission.assert();

textIOWrite = new TextIo(filePath , “W”, 20127);

textIOWrite.write(headerFileLine);
textIOWrite.write(fileLine);

Advertisements

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s