cancel
Showing results for 
Search instead for 
Did you mean: 

Help needed on UDF

Former Member
0 Kudos

Hi all,

Am writing a UDF to split the source field into 4 target fields.

Input1 = FR76102780434000620096870417

Input2 = 15,25|4,12|26,27|1,27

Need to split the input1 values according to input2 indexes,

ex;-

Output1 = parse the input1 from 15 to 25 ( 620096870).

Output2 = parse the input1 from 4 to 12 ( 10278043).

Output3 = parse the input1 from 26 to 27 ( 1).

Output4 = parse the input1 from 1 to 27 ( FR76102780434000620096870417).

Has anybody worked on similar things..........pls share....

Accepted Solutions (0)

Answers (3)

Answers (3)

anupam_ghosh2
Active Contributor
0 Kudos

Hi,

Try this UDF of type context



public void inputsplit(String[] a,String[] b,ResultList result,Container container){
{
           //write your code here
 try
		{
			String c[];
			int d[];
			c=b[0].split("[,|]");
			int i,j,m,t,g;
			d=new int[c.length];
		
			for(i=0;i<c.length;++i)
			{

				  d<i>=new Integer(c<i>).intValue();
			}
			if(d.length%2==0)
			{
				
				for(i=0,j=0;i<d.length/2;++i,j+=2)
				{
				                m=d[j];
                                                                                t=j + 1;
                                                                                g=d[t];                                                                                
result.addValue(a[0].substring(m,g));
				}
			}
			else
			{
				result.addValue("error:odd number split");;
			}
			
		}
		catch(Exception e)
		{
			e.printStackTrace();
		}
}

String a[]={"FR76102780434000620096870417"};

String b[]={"15,25|4,12|26,27|1,27"};

I got following ouput considering the first character of String a[] (which is 'F') begins at index 0 (zero).


0620096870
10278043
1
R7610278043400062009687041

In case you are considering the first character of input string a[] at index 1 then pls decrease the value of d[j] and d[j+1] by 1 unit within inner for loop before adding to output result list.

N.B- in my code some lines are not being printed in forum post. The code within second for loop is shown below. I have added extra variables m and t to avoid printing errors.

for(i=0,j=0;i<d.length/2;+i,j=2)

{

m=d[j];

t=j + 1;

g=d[t];

result.addValue(a[0].substring(m,g));

}

Regards

Anupam

Edited by: anupamsap on Mar 4, 2012 4:15 AM

markangelo_dihiansan
Active Contributor
0 Kudos

Hello,

Am writing a UDF to split the source field into 4 target fields.

Input1 = FR76102780434000620096870417

Input2 = 15,25|4,12|26,27|1,27

Need to split the input1 values according to input2 indexes,

You only need 1 UDF for this but may need to repeat the mapping if you are using PI 7.0 and below.

UDF type is Context

Arguments: inp1

inp2


String temp[] = inp2[0].split("\\|");
for(int a=0;a<temp.length;a++){
   String temp2[] = temp[a].split(",");
   String out = inp1[0].substring(Integer.parseInt(temp2[0]),Integer.parseInt(temp2[1]));
   result.addValue(out);
}

Here is the mapping (PI 7.0 and below)


Input1 -> UDF -> copyValue[0] -> Target1
Input2 -> /

Input1 -> UDF -> copyValue[1] -> Target2
Input2 -> /

Input1 -> UDF -> copyValue[2] -> Target3
Input2 -> /

Input1 -> UDF -> copyValue[3] -> Target4
Input2 -> /

Hope this helps,

Mark

Former Member
0 Kudos

Hi Santhosh,

Is it not possible for you to split it with subString function in graphical mapping?

How you would like to assign the values?

Thanks

Ray..