on 03-10-2011 1:01 PM
Hi,
I need some advice/input for a mapping.
MT_Source Occurence
ROW 1
Customer 1
Article 1
MT_Target
ROW 1:n
Customer 1
field1 1
field2 1
field3 1
Article field from source is a string of N-times 5 characters
Requirements for mapping are:
The target structure must have N rows
Then the string must be substringed to N-strings
Each field1,2,3 is substring of one substring.
Example
MT_Source looks like:
<row>
customer is X
article is string "12345ABCDE"
</row>
MT_Target must be like:
<row>
customer X
field1 12
field2 34
field3 5
</row>
<row>
customer X
field1 AB
field2 CD
field3 E
</row>
Can it be done with graphical mapping and udf?
Or is it better to do it all in one XSLT or JAVA or ABAP mapping?
Any coding examples u can give are much appreciated.
Kr
Robert
Try this to solve your problem!
Step1. Create UDF with cache as Queue.
while(a[0].length() >= 5)
{
String res = a[0].substring(0,5);
a[0] = a[0].substring(5,a[0].length());
result.addValue(res);
}
Step2. Mapping of fields should be done like this..
Customer --->CopyValue(0) --->Customer
Article ->UDF->ROW
Article ->UDF->SubString(0,2)->SplitByValue(each)->Field1
Article ->UDF->SubString(2,2)->SplitByValue(each)->Field2
Article ->UDF->SubString(4,1)->SplitByValue(each)->Field3
Test it and let me know.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Sarvesh,
Thx for posting.
Your solution is similar to my variant on Anand's solution in that i have more UDF's, one for each field.
And i need 3 UDF's in stead of your 1 UDF, but than i dont have to put the extra Substring function in there either, nor hte context change.
So i believe i have most pieces now and i will solve my puzzle.
kr
Robert
Hello,
This only one udf will slove ur problem
input to this udf is article and UDF will have 4 outputs.
first output map to customer
second output to field1
third output to field2
fourth to field3
udf details
Execution type="all values of a context"
Add 4 resultlist like result1,result2,result3,result4
public void myComplexMapping(String[] var1, ResultList result1, ResultList result2, ResultList result3, ResultList result4, Container container) throws StreamTransformationException{
int test=var1[0].length();
test=test/5;
for(int i=0;i<test;i++)
result1.addValue("");
String str="";
for(int j=0;j<test;j++)
{
str=var1[0].substring(j*5,(j*5)+5);
result2.addValue(str.substring(0,2));
result3.addValue(str.substring(2,4));
result4.addValue(str.substring(4,5));
result2.addContextChange();
result3.addContextChange();
result4.addContextChange();
}
}
Enjoy exploring PI
Anand
Hi Anand,
One modification needs to be made:
I have said above that customer is given only one time and it needs to be replicated inside the row structure.
So it must be outside the UDF.
I probably need the UseOnetoMany, though i'm not sure, as all inputs in teh source are mandatory but only appear once. So not sure where to get the "many" from.
Anyway, thx for continous feedback.
kr
Robert
> I have said above that customer is given only one time and it needs to be replicated inside the row structure.
>
> So it must be outside the UDF.
> I probably need the UseOnetoMany, though i'm not sure, as all inputs in teh source are mandatory but only appear once. So not sure where to get the "many" from.
I guess you missed to read this in my first reply.. e.g.
Customer --->CopyValue(0) --->Customer
You can also use the function "UseOneAs Many" but CopyValue will just work fine in this case..
Hi Anand, Sarvesh,
First of all: thx a lot for all your valuable inputs.
The only issue left for me was the customer. Just Copyvalue never worked because in source structure there is one and only one value, and it never became two.
I've solved this also inside my UDF now. I've added one input (var2) and one output (result5) it and looks like this now:
public void allinONE(String[] var1, String[] var2, ResultList result1, ResultList result2, ResultList result3, ResultList result4, ResultList result5, Container container) throws StreamTransformationException{
int test=var1[0].length();
test=test/5;
for(int i=0;i<test;i++){
result1.addValue("");
result5.addValue(var2[0]);
result5.addContextChange();
}
String str="";
for(int j=0;j<test;j++)
{
str=var1[0].substring(j*5,(j*5)+5);
result2.addValue(str.substring(0,2));
result3.addValue(str.substring(2,4));
result4.addValue(str.substring(4,5));
result2.addContextChange();
result3.addContextChange();
result4.addContextChange();
}
This gets me exactly the output i need.
Again thx for the input
I'll keep exploring
kr
Robert
Hi Robert,
I think you need to write a UDF for your requirement
firstly, input of udf is article and the output of udf is mapped to Customer node(this will make the occurance of customer according to article length)
public void DynamicOccurance(String article[], ResultList result,Container container) throws StreamTransformationException
{
int len=article[0].length()/5;
for(int i=0;i<len;i++)
result.addValue("");
}
Secondly for field1,field2,field3 i think you can use simple substring in graphical mapping for each accordingly from article.(you can write another simple udf in java for it also )
Hope it helps,
Anand
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Anand,
Yes that certainly helps.
Now i get at least N occurences of my ROW node.
Second challenge though is to fill the fields1 ,2, and 3.
I think its not possible to do only graphical mapping as i do not know how many times the substring will be in string ARTICLE.
So i thought that the way forward is
1) create substrings of the string article, i.e. split into
ABCDE
12345
etc
etc
2) then create the sub-substring for the fields out of these substrings.
AB
CD
E
12
34
5
etc
etc
Any assistance is valuable
kr
Robert
Hi,
Second requiremnt i think the solution is tricky...solution i found was if instead of having 3 fields as field1,field2,field3...make only one field with min and max occurances as 3 and then use this udf
input to udf is article and map the output of this udf to field in target
Execution type="all values of a context"
public void threefields(String article[], ResultList result,Container container) throws StreamTransformationException
{
int len=article[0].length()/5;
String str="";
for(int j=0;j<len;j++)
{
str=article[0].substring(j*5,(j*5)+5);
result.addValue(str.substring(0,2));
result.addValue(str.substring(2,4));
result.addValue(str.substring(4,5));
result.addContextChange();
}
}
and i have not test this udf kindly modify as required.
Note:If this solution is not possible..then ask experts help or go for alternate solutions like java mapping etc
Thanks,
Anand
Hi Anand,
Slowly getting there
I couldn't get your code to work properly, but i've implemented it slightly differently.
I just created three UDF's one for substring 12, one for substring 34, one for substring 5.
This way the output it is easier to manipulate into my field1, field 2 and field 3.
It maybe your solution is still better/quicker but at least i have a workable solution.
I'll see and let you know when my solution is complete.
Thx
Robert
User | Count |
---|---|
84 | |
25 | |
12 | |
9 | |
6 | |
6 | |
5 | |
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.