Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
I'm working on a job that reads the IMEI number (14 or 15 digits) of a mobile phone and converts it to a 15 digit number in case the input is of 14 digits. Used tJavaRow to implement this algorithm and given below is the code. When run, this job fails with the error; device_imei_conversion being the name of the Talend job. Can someone help with this error?
Detail Message: The method sumOfDigits(int) is undefined for the type device_imei_conversion
// Calculate sum of digits for a number
public static int sumOfDigits(int number)
{
int sum=0;
while(number > 0)
{
sum += number%10;//get the modulus and add it to the running sum
number = number/10;//get the first digit of a number by downcasting; number is int datatype so it removes anything after decimal point
}
return sum;
}
if (input_row.IMEI.length() = 14) {
int sum = 0;
for(int i = 13;i>=0;i=i-1)//loop through all 14 digits in an IMEI
{
String sDigit = input_row.IMEI.substring(i,i+1);//get each digit of IMEI, starting from the right
int digit = Integer.valueOf(sDigit);
if(i%2==0)//way to identify every other second digit from the right
{
sum = sum + digit;
}else
{
sum = sum + sumOfDigits(digit*2);
}
}
sum = sum * 9;// multiply the total sum by 9
String modvalue = String.valueOf(sum%10); // Return check digit
output_row.IMEI = input_row.IMEI+modvalue;
}
else
{
output_row.IMEI = input_row.IMEI;
}
I don't think you can have a function inside of your tjavarow. Put your function:
// Calculate sum of digits for a number
public static int sumOfDigits(int number)
in the metadata/code area. Test it to make sure it's working, and then call that from your tjavarow.
Thanks for your response. Didn't know tJavaRow doesn't support functions. As a workaround, I wrote the same code as part of my "main" instead of a function.