cancel
Showing results for 
Search instead for 
Did you mean: 

Problem in UDF

Former Member
0 Kudos

Hi Friend

I need your help in writing a UDF

please help there is some small mistake in java syntax while writing this UDF

Below is the code for the same:

As an argument i am passing Diff_Price,Price_Override,Promo_no,MMID,Bill_Disc

String con1 = "ZKA6";

String con2 = "ZKA7";

String con3 = "ZKA8";

if (Diff_Price != "0" && Price_Override == "1")

{

result.addValue("ZKA8");

}

if (Diff_Price != "0" && Price_Override == "0" && (Promo_no == "02" || Promo_no == "03") )

{

result.addValue("ZKA6");

}

if (Diff_Price != "0" && Price_Override == "0" && (Promo_no == "04" || Promo_no == "05") )

{

result.addValue("ZKA7");

}

if (Diff_Price != "0" && Price_Override == "0" && Promo_no == "0" )

{

if (MMID == "0")

{

result.addValue("Bill_Disc");

}

if (MMID >= 1 && MMID <= 125 ) // when MMID is between 1-125

{

result.addValue("ZKA6");

}

if (MMID >= 126 && MMID <= 255 ) // when MMID is between 126-255

{

result.addValue("ZKA7");

}

}

if ( Diff_price == 0)

{

result.addValue("0");

}

Write now i am getting this Error while activating :

incomparable types: java.lang.String[] and java.lang.String

if (Diff_Price != "0" && Price_Override == "1")

This is because the arguments which are coming in this UDF are of String array type and we are trying to compare them with string.

Please guide how to solve this error.

What should i add in this code to run it fine

Thanks

Accepted Solutions (1)

Accepted Solutions (1)

justin_santhanam
Active Contributor
0 Kudos

Sharma,

I believe you are using Queue

hence change the code


Diff_Price != "0" && Price_Override == "1"

to 

Diff_Price[0] != "0" && Price_Override[0] == "1"

Change it as above If your Diff_Price and Price_Override are constant's

raj.

Former Member
0 Kudos

Hi Raj

yes i am using queue.

But one thing which i think is as we are passing this Diff_price and as String [] and when we will check that with "0" (which is a string) so will it not give the error again.

Diff_Price[0] != "0" && Price_Override[0] == "1"

these arguments are coming from a file which is a source and what do u means by constant i dint get it ?

Thanks

justin_santhanam
Active Contributor
0 Kudos

Sharma,

Chnage it as


( !Diff_Price[0].equals("0") &&  Price_Override[0].equals("1"))

raj.

Former Member
0 Kudos

Here if you are using queue then for multiple occurance of the input fields you need to use the loop

as

for(int i = 0; i< Diff_price.length; i++)

{

/// Add your code as it is just use i instead of 0

// Diff_Price<i> != "0" && Price_Override<i> == "1"

}

Useing 0 will always indicate to 1st value of the whole queue. if there are multiple values of Diff_Price, Price_Override etc are available then you need to use the loop

Thanks

Swarup

justin_santhanam
Active Contributor
0 Kudos

Sharma,

Can u send your test data across. Coz based on your data you need to decide whether to go for Queue or Value .

raj.

Former Member
0 Kudos

What about this condition:

where i have to check the range

if (MMID<i>>=1) && (MMID<i><=125)

will this code run or give me the error.

Thanks

nisarkhan_n
Active Contributor
0 Kudos

Use double quotes for the constans as pointed by Raj.

Former Member
0 Kudos

Friends with this piece of code i am having problem :

if (MMID<i> >= "1" && MMID<i> <= "125" )

{

result.addValue("ZKA6");

}

This is the error message i am getting while activating :

operator <= cannot be applied to java.lang.String,java.lang.String if (MMID<i> >= "126" && MMID<i> <= "255" ) // when MMID is between 126-255 ^

Please help

Thanks

Edited by: aquarian sharma on Feb 28, 2008 7:43 AM

Edited by: aquarian sharma on Feb 28, 2008 7:44 AM

nisarkhan_n
Active Contributor
0 Kudos

if (MMID >= 1 && MMID <= 125 )

{

result.addValue("ZKA6");

}

I am sorry since you were using the double quotes for Number value (Constant) it was treating it as string and for string we cannot use >=.

Former Member
0 Kudos

What should be used while checking String and string array

let us say we converted string array into a string than we jave to check this greater than equal to

wat should be used ?

Thanks

nisarkhan_n
Active Contributor
0 Kudos

Convert that string array to integer, then put ito inetger aray and check with the conditino "<=" operator.

get the values in a loop and convert each value into integer and put into integer array

String s[]

Int a[]

convert S[] to in a[] in a loop using String to int converion method and use it in IF stament <=

for( int i=0;i<s.length;i++)

{

int a<i> = integer.ParseInt(S<i>)

if (a<i> >= a[i+1])

and so on.....

Former Member
0 Kudos

Hi,

Please find the code:

public class Test_01 {

public static void main(String[] args) {

String Diff_Price = "10";

String Price_Override = "0";

String Promo_no = "0";

String MMID = "185";

int M = Integer.parseInt(MMID);

String Bill_Disc = "Bill_Disc";

String con1 = "ZKA6";

String con2 = "ZKA7";

String con3 = "ZKA8";

if (Diff_Price != "0" && Price_Override == "1")

{

System.out.println(con3);

}

if (Diff_Price != "0" && Price_Override == "0" && (Promo_no == "02" || Promo_no == "03") )

{

System.out.println(con1);

}

if (Diff_Price != "0" && Price_Override == "0" && (Promo_no == "04" || Promo_no == "05") )

{

System.out.println(con2);

}

if (Diff_Price != "0" && Price_Override == "0" && Promo_no == "0" )

{

if (M == 0)

{

System.out.println(Bill_Disc);

}

if (M >= 1 && M <= 125 ) // when MMID is between 1-125

{

System.out.println(con1);

}

if (M >= 126 && M <= 255 ) // when MMID is between 126-255

{

System.out.println(con2);

}

}

if ( Diff_Price.equals("0"))

{

System.out.println("0");

}

}

}

I tested with sample values, it is working fine. Please test with your test data.

I hope this will help you out.

Thanks,

Kishore.

rodrigoalejandro_pertierr
Active Contributor
0 Kudos

hi,

all parameters you import to an UDF is an STRING.

in this case, you have to validate if value of MMID is between a range, so you have to do this

int i_MMID = Integer.parseInt(MMID[j])

and then do the validation

if (MMID >= 1 && MMID <= 125 )

like you are ussing queue is why i put before the [j]. i explaned it in my previous post

hope it helps,

Edited by: Rodrigo Pertierra on Feb 28, 2008 7:39 AM

Former Member
0 Kudos

Will this UDF work if the diff_Price has negative value also.

Like at the runtime let us say the file is passing -6 as the value of Diff_Price than will it work fine or will create any probs

for(int i=0;i<Diff_Price.length;i++)

{

if (!Diff_Price<i>.equals( "0") && Price_Override<i>.equals("1"))

{

result.addValue("ZKA8");

}

if (!Diff_Price<i>.equals( "0") && Price_Override<i>.equals("0") && (Promo_no<i>.equals( "02") || Promo_no<i>.equals( "03") ))

{

result.addValue("ZKA6");

}

if (!Diff_Price<i>.equals( "0") && Price_Override<i>.equals("0") && (Promo_no<i>.equals( "04") || Promo_no<i>.equals( "05") ))

{

result.addValue("ZKA7");

}

if (!Diff_Price<i>.equals( "0") && Price_Override<i>.equals("0") && Promo_no<i>.equals( "0"))

{

if (MMID<i>.equals( "0"))

{

result.addValue("ZKA7");

}

if (Integer.parseInt(MMID<i>) >= 1 && Integer.parseInt(MMID<i>) <= 125 ) // when MMID is between 1-125

{

result.addValue("ZKA6");

}

if (Integer.parseInt(MMID<i>) >= 126 && Integer.parseInt(MMID<i>) <= 255 ) // when MMID is between 126-255

{

result.addValue("ZKA7");

}

}

}

Answers (1)

Answers (1)

Former Member
0 Kudos

HI,

As Raj have mentioned here you have used the Cache Parameter as Queue or Context for that use below "[0]"

if (Diff_Price[0] != "0" && Price_Override[0] == "1")

Or else change the Cache parameter to Value in initial creation of UDF.

At left top side of UDF editor you will get icon to change these paramters.

Check if the occurance of the input parameters is more than 1 then Cache paramtere is Queue or Context

else it should be Value.

If you have used the Cache parameter as Value your code will work perfectly.

Thanks

Swarup

rodrigoalejandro_pertierr
Active Contributor
0 Kudos

ifhi

if your function use only Diff_price as queue replace your code as follow

as

for(int j = 0; j< Diff_price.length; j++)

{

Diff_Price[j] != "0" && Price_Override[0] == "1"

}

else if Diff_price is a queue too replace de [0] by [j], same with all parameters you are ussing.

Diff_price[j]

Price_OverrideI[j]

Promo_no[j]

MMID[j]

Bill_Disc[j]

but if any of this parameters is a constant use [0] because the parameter has only one value.

hope it helps

Edited by: Rodrigo Pertierra on Feb 27, 2008 4:39 PM