CloverETL Transformation Language examples

Code examples

Code Output
int i=10;
int j=9;
date date1=2006-01-01;print_err(date1);
date date2=2006-02-01;print_err(date2);
boolean result;
boolean compareDates=date1<=date2;
print_err(compareDates);
if (date1<=date2) {
        print_err('before if (i<j)');
	if (i<j) print_err('date1<today and i<j') 
        else print_err('date1<date2 only')
	result=true;
}
result=false;
if (i<j) result=true;
else if (not result) result=true;
else print_err('last else');
print_err(result);


Sun Jan 01 00:00:00 CET 2006
Wed Feb 01 00:00:00 CET 2006


true

before if (i<j)

date1<date2 only




true


date born=$Born;print_err(born);
int n=date2num(born,month);print_err(n);
string mont;
decimal april=4d;
switch (n) {
	case 0.0:mont='january';
	case 1.0:mont='february';
	case 2.0:mont='march';
	case 3:mont='april';
	case april:mont='may';
	case 5.0:mont='june';
	case 6.0:mont='july';
	case 7.0:mont='august';
	case 3:print_err('4th month')
	case 8.0:mont='september';
	case 9.0:mont='october';
	case 10.0:mont='november';
	case 11.0:mont='december';
	default: mont='unknown';
};
print_err('month:'+mont);
boolean ok=(n. ge .0)and(n. lt .12);
switch (ok) {
	case true:print_err('OK')
	case false:print_err('WRONG')
};
switch (born) {
	case 2006-01-01:
              {mont='January';print_err('january');}
	case 1973-04-23:
              {mont='April';print_err('april');}
	default:print_err('other')
};
print_err(mont);
Mon Apr 23 00:00:00 CET 1973
3











4th month






month:april


OK






april


April
date born=$Born;print_err(born);
date now=today();
int yer=0;
for (born;born<now;born=dateadd(born,1,year)) ++yer;
print_err('years on the end:'+yer);
boolean b;
for (born;!b;++yer) 
	if (yer==100) b=true;
print_err(born);
print_err('years on the end:'+yer);
Mon Apr 23 00:00:00 CET 1973



years on the end:34



Mon Apr 23 00:00:00 CEST 2007
years on the end:101
ddiff=datediff(born,otherdate,year);
string dts=date2str(ndate,'yy.MM.dd');
string s='hello world';
number lenght=5.5;
string subs=substring(s,1,lenght);
print_err('original string:'+s );
print_err('substring:'+subs );
string upper=uppercase(subs);
print_err('to upper case:'+upper );
string lower=lowercase(subs+'hI   ');
print_err('to lower case:'+lower );
string c=concat(lower,upper,2,',today is ',today());
print_err('concatenation "'+lower+'"+"'+upper+'"+2+",today is "+today():'+c );
date born=nvl($Born,today());
date datum=dateadd(born,100,millisec);
print_err(datum);
long ddiff;date otherdate=today();
print_err('date diffrence:'+ddiff );
string rep=replace(c,'[lL]','t');
print_err(rep);
decimal(10,5) stn=str2num('2.5125e-1',decimal);
print_err(stn);
string nts=num2str(10,4);
print_err(nts);
date newdate=2001-12-20 16:30:04;
decimal dtn=date2num(newdate,month);
print_err('month from newdate:'+dtn );
date ndate=2002-12-24;
print_err('date to string:'+dts);
print_err(str2date(dts,'yy.MM.dd'));





original string:hello world
substring:ello 

to upper case:ELLO 

to lower case:ello hi   


concatenation "ello hi   "+"ELLO "+2+",today is "+today()
:ello hi   ELLO 2,today is Fri Sep 01 10:44:22 CEST 2006
Thu Jul 28 10:44:22 CEST 2005

date diffrence:-1

etto hi   EttO 2,today is Fri Sep 01 10:44:22 CEST 2006
0.25125

22


month from newdate:11.00


date to string:02.12.24
Tue Dec 24 00:00:00 CET 2002
string original=${G1};
int num=str2num(original); 
print_err(original);
print_err(num);


10
10
int counter = 1;
int mult = 2;
list keyList = [1,4,6,14,16];
int i;
string value = '';
string tmp;
string errmes;
 
// Generates output record.
function generate() {
	foreach (i : keyList) {
		tmp = lookup(LookupTable0,i).value;
		value = concat(value, tmp);
		tmp = lookup_next(LookupTable0).value;
		while (!isnull(tmp)) {
			value = concat(value, tmp);
			tmp = lookup_next(LookupTable0).value;
		} 
		value = concat(value, ';');
	}
	do {
		counter = mult * counter++ ;
	} while (counter < ${MAX});
	try {
		i = "some string";
	} catch (errmes) { 
		print_log(error, errmes);
	}
	$counter := counter--;
	$lookup := value;
}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
class org.jetel.interpreter.TransformLangExecutorRuntimeException#Interpreter
 runtime exception on line 27 column 13 : 
invalid assignment of "some string" [STRING] to variable "i" [INTEGER] "
 - incompatible data types

Example from Join Component

  //#TL
 
  function price_per_unit(unit_price,quantity,discount){
    return (unit_price*quantity - discount)/quantity
  }
 
  function ship_time(ordered,shipped){
    if (shipped .lt. ordered) return
    else return datediff(shipped,ordered,day);
  }
 
  function transform(){
    int shiptime;
    string datum = $ORDERS_DBF.SHIPPEDDAT;
 
    if (datum .ne. "        ") {
      shiptime=ship_time($ORDERS_DBF.ORDERDATE,str2date(datum,"yyyyMMdd"));
    } else {
      shiptime=-1;
    }
 
    $ORDERS_Info.ORDERID:=$ORDERS_DBF.ORDERID;
    $ORDERS_Info.CUSTOMERID:=$ORDERS_DBF.CUSTOMERID;
    $ORDERS_Info.PRODUCTID:=$Bigodata_dbf.PRODUCTID;
    $ORDERS_Info.UNITPRICE:=$Bigodata_dbf.UNITPRICE;
    $ORDERS_Info.PRICE_PER_UNIT:=
 
    price_per_unit($Bigodata_dbf.UNITPRICE,
 
    $Bigodata_dbf.QUANTITY,$Bigodata_dbf.DISCOUNT);
    $ORDERS_Info.QUANTITY:=$Bigodata_dbf.QUANTITY;
    $ORDERS_Info.DISCOUNT:=$Bigodata_dbf.DISCOUNT;
    $ORDERS_Info.SHIPTIME:=shiptime;
  }

transf_lang_examples.txt · Last modified: 2010/03/22 14:21 by avackova
Back to top
chimeric.de = chi`s home Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0