Sidebar

Can QIE convert a Comma or Pipe separated file to a Fixed Width Value

0 votes
376 views
asked Dec 5, 2013 by brandon-w-8204 (33,270 points)
I have a file that has values separated by commas or pipes.  I need it to be a fixed width file format. Can QIE do this conversion.

1 Answer

0 votes
 
Best answer

Below is the some sample code with comments on how to convert to a Fixed Width format.

 

// sample Pipe Delimeted |12345|First|M|Last|stuff|otherstuff|etc|
 
//Create Message as Fixed Width
message = qie.createFixedWidthMessage(200);
 
//Retrieve Values from Original Message and write fixed width message
 
// Fields     Begin Index Width     Description
// 1          1           10        Not Used
// 2          11          20        ID
// 3          31          20        First Name
// 4          51          20        Middle Name
// 5          71          20        Last Name
// 6          91          20        Stuff
// 7          111         20        Other Stuff
// 8          131         20        etc
// setNode syntax for fixed width - Begin Index, Width [ Row Index ]
 
var count = source.getCount('*');
qie.debug('Row Count: ' + count);
 
// Loop through each row and create the fixed width
for (var j=0 ; j < count ; j++) {
   var row = source.getNode('*[' + (j + 1) + ']');
   
   qie.debug('Row: ' + row);
   
   // verify the row has data
   if (row.length() > 0) {
      
      // Split the row to an Array
      var rowArray = row.split('\\|');
      qie.debug('Row Array Size: ' + rowArray.length);
      
      // Loop through the Array of values and set the new message
      var field = 0;
      message.setNode('1,10[' + j + ']',   rowArray[(field + 1)]);
      message.setNode('11,20[' + j + ']',  rowArray[(field + 2)]);
      message.setNode('31,20[' + j + ']',  rowArray[(field + 3)]);
      message.setNode('51,20[' + j + ']',  rowArray[(field + 4)]);
      message.setNode('71,20[' + j + ']',  rowArray[(field + 5)]);
      message.setNode('91,20[' + j + ']',  rowArray[(field + 6)]);
      message.setNode('111,20[' + j + ']', rowArray[(field + 7)]);
      
   }
}
answered Dec 5, 2013 by brandon-w-8204 (33,270 points)
...