on 10-09-2008 2:06 AM
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.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
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
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
HI,
try like this..
http://www.flickr.com/photos/23639237@N02/2926085235/
Consider
"Amount" as P1
"Reason" as P2
"ItemCode" as D1
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
User | Count |
---|---|
85 | |
10 | |
10 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.