How to use if contion in tranform function?

Discussion on developing CloverETL engine, transformation components etc.

Kunaljd
Posts: 1
Joined: Fri Apr 13, 2012 12:04 pm

How to use if contion in tranform function?

Postby Kunaljd » Fri Apr 13, 2012 1:01 pm

How to use if condition in transform function?

Code: Select all

import org.jetel.component.DataRecordTransform;
import org.jetel.data.*;
 
 
public class ReformatOrdersInline extends DataRecordTransform{
 
   int counter=0;
   int field=0;
 
   public int transform(DataRecord[] source, DataRecord[] target){
   System.out.println("Everthing was OK.");
   
      StringBuffer strBuf=new StringBuffer(80);
      if (source[0]==null){
         System.err.println("NULL source[0]");
      }
      try{
      
      if(GetVal.getString(target[0],"RECORD_TYPE")=="asd")
      {
      System.out.println("Everthing was OK.");
      
      System.out.println(GetVal.getString(source[0],"RECORD_TYPE"));
         SetVal.setString(target[0],"RECORD_TYPE",GetVal.getString(source[0],"RECORD_TYPE"));   
            SetVal.setString(target[0],"BILLING_ACCOUNT_NUMBER",GetVal.getString(source[0],"BILLING_ACCOUNT_NUMBER"));   
            SetVal.setString(target[0],"RECORD_TYPE_PLN_ID",GetVal.getString(source[0],"RECORD_TYPE_PLN_ID")   );
            SetVal.setInt(target[0],"CHARGE_AMOUNT",GetVal.getInt(source[0],"CHARGE_AMOUNT")   );
            
         }      
               
      }catch(Exception ex){
        ex.printStackTrace();
         errorMessage=ex.getMessage()+" ->occured with record :"+counter;
         return SKIP;
      }
      
         return ALL;
   }
}


is this correct??

kubosj
Posts: 372
Joined: Thu Jan 12, 2012 9:10 am

Re: How to use if contion in tranform function?

Postby kubosj » Mon Apr 16, 2012 12:24 pm

Hi Kunaljd,

I don't know what you would like to achieve, but your current code do this:

* check RECORD_TYPE=="asd"
* if equal, set output record data
* if not equal, do nothing
* in both cases send record

This is probably not what you want. If you would like to send record just in case condition is true, use "return OK;" from within block. For rest of cases return SKIP.

See http://doc.cloveretl.com/documentation/ ... alues.html for details.
Jaroslav Kubos
CloverCARE Support
CloverETL | Rapid Data Integration

Visit us online at http://www.cloveretl.com