Pages

Thursday, November 17, 2011

Useful PDI steps' commands

Wild card expression
File Names Starts with 100047 and end with  DIS.DAT
${Internal.Job.Filename.Directory}  100047*DIS.DAT <

File names end up with xls extension
${Internal.Transformation.Filename.Directory}\matchdata    .*\.xls


Java scripts
Replace white spaces, concatenate strings and print fields with line breaks 
var Data_file;
var Date_time;
var header_line;
date_time = Date_time1.replace(" ", "-");
Data_file = '82246_data_extraction_' + Date_time1.replace(" ", "-") + '.xls';
header_line = '========================================== \r\n' + 
               'Date & Time  :' + date_time + '\r\n' + 'Output File   :' + Data_file + '\r\n'

If and replace function usage
var max_imported_last_call_new;
if (max_imported_last_call != null) 
       { max_imported_last_call_new=replace(max_imported_last_call, "/", "-"); }
else { max_imported_last_call_new='2000-01-01 00:00:00.0'; }

If and Data Type Conversion
var new_dispo_file_name;
var wave;
if (str2num(filename_date) == str2num(SERVER_DATE)){
new_dispo_file_name = XXXXXX + filename_date + 'CVAR' + num2str(str2num(wave) + 1) + 'DIS';}
else {
new_dispo_file_name = XXXXXX + SERVER_DATE + 'CVAR' + 0 + 'DIS';}

AND and OR conditions 

var IBM_DISPOSITION_CODE;
var fail_number = 0;
IBM_DISPOSITION_CODE = '000';
if (ADDR == null || CITY == null || ZIPCODE == null) {
IBM_DISPOSITION_CODE = '009';
fail_number++;}

if (x_salutation == null && (
(country=='BE' && language=='Dutch') ||
(country=='BE' && language=='French') ||
(country=='FR' && language=='French') ||
(country=='CH' && language=='Italian')  )) {
IBM_DISPOSITION_CODE = '011';
fail_number++;}


Date type (string to date conversion)
eoweek = str2date(date_val,"dd-MMM-yy");
quarter_no = quarter(eoweek);

var SurveyResults_filename = system_date + "_82430SurveyResults";
var SampleDisposition_filename = system_date + "_CumminsDispositionStatus";

var loaddatetime = system_date.substr(0,12) + "00";
var yesterday = dateAdd(today, "d", -1);
var dayb4yesterday = dateAdd(today, "d", -2);


var c_date = date2str(LAST_CALL,"MM/dd/yyyy") + " " + num2str(LAST_TIME/3600, "00") + ":" + (num2str(LAST_TIME%3600/60, "00")) + ":" + (num2str(LAST_TIME%60, "00")) ;

Regular exression
 if ( substr(timetype,0,4) == 'GMT+' || substr(timetype,0,4) == 'GMT-')
{   var re = /([-+])(\d+)(.?)(3?)/.exec(timetype);
    xmins=re[4]
else{mins='00';}
var x = re[2].length;
if ( x == 1) {hr = '0' + re[2]; }
else {hr = re[2]; }
temptime = re[1] + hr + ':' + mins;
}

.*\.add$ - everything ends with ".add"