cancel
Showing results for 
Search instead for 
Did you mean: 

java udf

Former Member
0 Kudos

Hello sdners

I need help with a java udf

context udf : array of texts will be passed to udf

text1 : This is a purchase order number 111111....# and date is 10/02

text2: purchase order number 222..# and date is 10/03

text n...

In all these texts being passed to the udf,we need to extract the string : purchase order 11111...

so basically the substring needs to be extracted "purchase order 11111... " . Anything between purchase order... and #: the substring needs to be extracted.

The substring extracted is dynamic in length : purchase order ..... : can be of any length.

regards

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi,

input text is : The purchase order number is 123456#

output : purchase order number is 123456

if the above is ur requirement then check with the below udf..it works!!

use cache parameter as value

public String find(String a,Container container)
{
   //write your code here
 String start_pos = "purchase order";
String end_pos = "#";
int s1 = a.indexOf(start_pos);
int s2 = a.indexOf(end_pos);
String output = a.substring(s1,s2);
return output;
}

srctext-->find->tgt

Former Member
0 Kudos

Hi Malini/Sridhar

Thanks to both of you.

Malini has understood the requirement correctly as her understanding of the question is correct although i have not tried her udf.

But Malini ,the field is repeating : I mean there can be many texts coming as the segment under which it comes is a repeating segment. You gave cache parameter as value ,but I guess since the field is repeating we need to give cache parameter as Context. Can you modify your functions as a context function instead of value ?

Regards

Former Member
0 Kudos

Hi Denny

Try this


public void returnPurchaseOrder(String[] input,ResultList result,Container container)
{
    //write your code here
String output="";

  for(int i=0;i<input.length;i++){
      int start = input.indexOf('Purchase order');
      int end = input.indexOf('#');
      output = text1.substring(start,end);
  }
result.addValue(output);
} 

Thanks

Gaurav

Former Member
0 Kudos

A general question : When in java we say index of ( purchase order) what is the value returned : postion of p or purchase order?

Regards

Former Member
0 Kudos

HI Denny

Thanks for asking this i made a mistake in the code above. Corrected one is



public void returnPurchaseOrder(String[] input,ResultList result,Container container)
{
    //write your code here
String output="";
 
  for(int i=0;i<input.length;i++){
      int start = input.indexOf("Purchase order");
      int end = input.indexOf('#');
      output = text1.substring(start,end);
  }
result.addValue(output);
} 

In Java when we say index of - it return position(integer) of a character or string.

indexOf( ' character' )

indexOf ( "String" )

In case source come as PURCHASE ORDER and sometime purchase Order we can use compareToIgnoreCase("Purchase order") that should solve the problem

Thanks

Gaurav

Former Member
0 Kudos

So in this string : " This is a purchase order number 11111 #" what is the postion of this string : " purchase order "

Secondly how to incorporate the logic for ignoring the case of " purchase order" . It is free form text and it can come as PURCHASE ORDER.

Thank You

Former Member
0 Kudos

Hi Denny

This is a purchase order number 11111 #

in this "purchase order" is 11 but for your requirement to get only 1111 out of the above string you need to keep "purchase order number" into the code i provided above instead of "purchase order"

Secondly for your requirement of the above string you can incorporate

 int start = input.toLowerCase().indexOf("purchase order"); 

Thanks

Gaurav

Former Member
0 Kudos

Dear Mr Bhargav

Thank you .

There is an old saying : "That it ends where it starts". You had initally started answering this query

But Malini and Sridhar's inputs were also very significant.

Will award the points now.

Regards

Answers (3)

Answers (3)

Former Member
0 Kudos

Hi,

I have modified my udf.

Hope it works 4r repeating segments.

Use cache parameter as context


public void find(String[] a,ResultList result,Container container)
{
 //write your code here
 String start_pos = "purchase order";
String end_pos = "#";
for(int i=0 ; i != a.length ; i++)
{
int s1 = a<i>.indexOf(start_pos);
int s2 = a<i>.indexOf(end_pos);
String output = a<i>.substring(s1,s2);
result.addValue(output);
}
}

Former Member
0 Kudos

Thank You Mr Balasuamania.

Former Member
0 Kudos

Hi Denny

thanks for the clarification

you can try this

String out="";

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

int x = text1<i>.indexOf('#');

out = text1<i>.substring(0,x);

}

result.addValue(out);

Thanks

Gaurav

Former Member
0 Kudos

Dear Mr Bhargava

In your substring function you have given as (0,x )as parameters ,although "purchase" can come anywhere in the text and not at position 0 only.

Could you clarify ?

Regards

Former Member
0 Kudos

Hi

Ohh can you give me the some sample data so that we can think of dynamic value for this.

How can we identify the start of purchase order number. like you have specified end as #

Thanks

Gaurav

Former Member
0 Kudos

Hi

I am not sure but cant we identify in a text : a substring starting with purchase and ending with #

Purchase(wild card *) ends with #

Text1 : This is a purchase order number 111111#

Text2: Purchase order number 2222#

Text3 : This is an invoice but its purchase order number is 33333# and its invoice number is 44.

If we have texts like these passed to your udf ,then can we identify this substring ( Purchase order number ..) based on the logic : starts with purchase and everything before #?

I am not sure though.

Regards

Former Member
0 Kudos

Hi

Without the info of identifying we need to consider every case out here.

The above UDF code can be enhanced using any other string operation

http://java.sun.com/j2se/1.5.0/docs/api/java/lang/String.html

Thanks

Gaurav

Former Member
0 Kudos

Does someone have any solution for this unique issue?

Regards

Edited by: denny morris on Oct 4, 2008 3:47 PM

Former Member
0 Kudos

Hi Denny,

Based on my understanding the output should be Purchase order should return the UDF .

If my understanding is right then the following udf return the Puchase order number.

import java.util.*;

String s="";

StringTokenizer parser = new StringTokenizer(a);

while (parser.hasMoreTokens()) {

String s1=parser.nextToken();

if(s1.endsWith("#")){

s = s1;

}

}

int k = s.length()-1;

return s.substring(0,k);

This will return the Puchase order number in a given any String ends with #.

for the above texts it will give the output as 111111

Regards

Sridhar Goli

Former Member
0 Kudos

Sridhar:

In your understanding of requirement :

Input : This is a purchase order number 11111 and invoice is 222

Outut : purchase order number 11111

Since this is a free form text ,it needs to be returned in target as : purchase order number 11111

and it needs to be a context function as it can repeat many time with different values as it comes under a repeating segment.

Regards

Former Member
0 Kudos

Hi Denny

can you provide more info on your requirement

In case you don't have context type UDF this is pretty easy to do

text1 = "11111#222"

for this x = text1.IndexOf('#');

String out ="";

out = text1.substring(0,x);

return out;

Thanks

Gaurav

.

Former Member
0 Kudos

Dear Mr Bhargava

In source the text field repeats. So i heard ,we need a contxt or queue udf for this since we need to pass a list of values.

Could you specify what else is not clear in the requirement? so that i could explain more.

Regards

Former Member
0 Kudos

We will have list of texts which i have mentioned and we need to extract only the substring which tells the purchase order number and to specify the end of this substring there is a # coming ,so we need to extract the sub string : purchase order number......

Everything after purchase and before # needs to be extracted.