on 04-18-2009 1:08 AM
Hi
I have to write the UDF to check the value exists or not ,, if exists then i need to take the values before ,
Ex : TEST,DEMO
then the out put is TEST
if the value does not exists then pass the empty value
S V
String s = ",",c=null;
int len;
int i = var1.indexOf(s);
len = var1.length();
if (len == 0)
{
c = " ";
return c;
}
else if(i>-1)
c = var1.substring(0, i);
return c;
Now u dont get the Exception
because u earlier did not check the condition before getting the substring whether it found the ", "or not if it does not find it then u will get the i value as -1 and if u try to get the substring u get that exception
Initialize the value in the variable c (the value u want to return)if it does not find comma
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
your logic should be as follows;
THEN ---------> input field --------> TARGET
input fields -------------> EXISITS (node function) -> IF
ELSE ------> substring of inputfield (0,indexOf(,))
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
HI
I wrote following UDF :
String s = ",";
int len;
int i = var1.indexOf(s);
i++;
len = var1.length();
if (len == 0)
{
String c = " ";
};
String c = var1.substring(0, i-1);
return c;
still its giving me error while testing the mapping
Runtime exception when processing target-field mapping /ZPAT/IODCZE1I/CITY; root message: Exception:[java.lang.StringIndexOutOfBoundsException: String index out of range: -1] in class
Hi
My requirement is ..
On source side i have one field ctyst and which has a value Atlanta, GA
i have to map Atlanta to one field and GA to another fiels on target.. basically i have to separate the values before and after comma..
i able to achieve that .. my problem is when there is no value in Ctyst field .. its giving error in Mapping .. how i will handle that ..
my UDF code:
String s = ",";
int len;
int i = var1.indexOf(s);
i++;
len = var1.length();
if (len == 0)
{
String c = " ";
};
String c = var1.substring(0, i-1);
return c;
SV,
Can you try the below code?
UDF
The UDF must have two inputs. catyst , const1
String return_field1=" ";
String return_field2 =" ";
StringTokenizer st = new StringTokenizer(catyst,",");
while(st.hasMoreTokens())
{
return_field1 = st.nextToken();
return_field2 = st.nextToken();
}
if(const1.equals("field1"))
return return_field1;
else
return return_field2;
The above code can be used for both of your target fields. If the source is blank then blank values will be returned to the target fields.
The mapping logic must be
catyst &CONSTANT("field1") ---> UDF --->Target field 1
catyst & CONSTANT("field2") ---> UDF ---> Target field2
Thanks,
raj.
hello,
did you tried with try catch block. as suggested in previous block..you can handle tat exception using try catch..
String s = ",";
int len;
int i = var1.indexOf(s);
i++;
len = var1.length();
try {
if (len == 0)
{
String c = " ";
};
String c = var1.substring(0, i-1);
return c;
}catch(StringIndexOutOfBoundsException e) {};
Hi
If that is the case u can use MapWithDefault Node Function , it will send if any value present , set default value in it as "Space", and this gets triggers if source has no value.
rgds
srini
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
SV,
if for example you have Test1, Demo1, Demo2 .. then still you have to return Test1?
Thanks,
raj.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
86 | |
10 | |
10 | |
9 | |
7 | |
7 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.