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.

I am not sure how to write in java ,the udf for belwo scenario and wheter it will be value or context or que function.

Scenario is file to idoc

Source

DHP

D1 : Invoice

PLK

P1 : AB

P2 : 123

PLK

P1 : CD

PLK

P1 : DE

P2 : 456

Requirement is : To substring ( first 4 chars) of D1 coming in DHP segment and concatenate with P2 if qualifier is DE in P1 then map this logic to a field in target.

Important point to consider is that if we see that second PLK segment does not have P2 so we cannot do something like we extract a<i> and then take b<i> corresponding since the queue for P2 had 2 values whereas queue for P1 has 3 values.

Can we achieve this ?

Thank you.

Accepted Solutions (0)

Answers (4)

Answers (4)

Former Member
0 Kudos

Hello,

It would not be so tough.

Just keep the context of P2 to its immediate parent node. Use mapWithdefault function and then use remove context function. Now u would be getting exact number of values as in P1.

BR,

Rahul

Former Member
0 Kudos

Hello,

Please try below mentioned UDF, using some standard functions as:

1. SubString function: For providing first 4 character of D1, these should be used as one input parameter to udf.

2. MapwithDefault function: Provide P2 value as input to these function. The output of these function would serve as 2nd input to our udf.

Use the below mention logic:

Input values to this udf are: Input,P1, P2

{start of code}

int i ;

String output;

for(i=0;i<P1.length;i++)

{

if(P1<i>.equals("DE"))

{

output = Input[0] + P2<i>;

result.addValue(output);

}

}{End of code}

BR,

Rahul

Former Member
0 Kudos

Thanks John and Mr. Rahul. I will try it but it is going to be a tough ride.

Former Member
0 Kudos

Hello

I want this whole logic in a java udf as I have some other logi also to be performed ,so with so many boxes it would look very unreadable.

Thank You.

Former Member
0 Kudos

Hello

Or even if in this graphical mapping you can add one more logic

that the whole mapping logic should be executed for P1 = CD

Thank You

Former Member
0 Kudos

Hi Dennis

What i understand is

You need to check D1(substring 4 character of DHP) concatenate P2( or PLK) = DE (in PLK P1) then map to target

with this if the P1 and P2 are not present in equal number you dont want to map it or something else ??

Thanks

Gaurav

Former Member
0 Kudos

Hello

Yes what you understood is correct but with slight modification.

Source

DHP

D1 : Invoice

PLK

P1 : AB

P2 : 123

PLK

P1 : CD

PLK

P1 : DE

P2 : 456

Here when we concatenate first 4 chars of D1 to P2 having qualifier =DE.

I just wanted to bring out the fact that that the second PLK does not have a corresponding P2 and that it is not by mistyping that I have not put in second PLK the corresponding P2 for second segment.

Does it sound bit better?

Thank you

Former Member
0 Kudos

Hi

So from your example i understand is

When source is

Source

DHP
D1 : Invoice

PLK
P1 : AB
P2 : 123

PLK 
P1 : CD

PLK
P1 : DE
P2 : 456

then you wanted to pass

 Invo456 

to target. Right?

Still didnt understand the second requirement. IF you give sample value which you want to pass to target from above source.then it will be more clear

Thanks

Gaurav

Former Member
0 Kudos

Hello Mr Bhargava

You are correct .I want Invo456 as output.

There is no Second req ,just a part of my explanation was : If you notice second PLK , there is no P2 in the second segment. Just wanted to tell this.

Thank You.

Edited by: denny morris on Oct 9, 2008 5:45 AM

Former Member
0 Kudos

Hi Denny

try

public void returnTarget(String[] P1, String[] P2, ResultList result,Container container)
{
    //write your code here
String output="";
 
  for(int i=0;i<P1.length;i++){
			if(P1<i>.equalsIgnoreCase("DE")){
				System.out.println(P1<i>);
				for(int j=0;j<P2.length;j++){
					output=output+P2[j];
				}
				
			}
		}
result.addValue(output);
} 

Another thing you can do is use standard substring function on D1 with 0,4

 D1 ----> Substring ---> Concat --->returnTarget --> Target

Thanks

Gaurav

Former Member
0 Kudos

It is not giving the desired result : Invo456

Former Member
0 Kudos

HI,

try like this..

http://www.flickr.com/photos/23639237@N02/2926085235/

Consider

"Amount" as P1

"Reason" as P2

"ItemCode" as D1

Former Member
0 Kudos

Hi Dennis

public void returnTarget(String[] P1, String[] P2, ResultList result,Container container)
{
    //write your code here
String output="";
 
  for(int i=0;i<P1.length;i++){
			if(P1<i>.equalsIgnoreCase("DE")){
				for(int j=0;j<P2.length;j++){
					output=output+P2[j];
				}
				
			}
		}
result.addValue(output);
} 

Try using the UDF then removeContext and concatenate it to result of D1 substring (0,4) and map to target.

Thanks

Gaurav