on 02-27-2008 5:33 PM
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
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
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
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
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.....
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.
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
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");
}
}
}
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
User | Count |
---|---|
84 | |
23 | |
11 | |
9 | |
8 | |
5 | |
5 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.