on 03-07-2012 6:45 AM
Hello Gurus,
Could you please help me if v need any UDF for splitting or can i do it with graphical mapping.
Below is the source structure
<header>id123</header>
<item>item123</item>
<data>abd1232011
^^efg4562011
^^hij7892012</data>
Required target structure
<header>id123</header> 1:1
<item>item123</item> 1:1
<content> 1:1
<data> 1:unbounded
<char>abd</char>
<num>123</num>
<date>2011</date>
</data>
my requirement is to break the 1 source field "data" into 3 target fields "char","num","date". Field data is of type string and received as a raw string. The new line is determined by "^^" in the string. fields are separated by "~"
Kindly help
Thanks in advance.
Hi,
I think it can easily be done by graphical mapping. PFB the mapping
Source1 -> substring(1,3) -> CharField
Source1 -> substring(4,7) -> IntegerField
Source1 -> substring(7,11) ->FormatDate -> DateField
Hope this helps.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
For this you don't need UDF. Use copyValue constant type function and map like below.
<data> - CopyValue [0] - <char>
<data> - CopyValue [1] - <num>
<data> - CopyValue [2] - <date>
In CopyValue function double click and give the indexes (0 for fitst one, 1 for second one and 2 for third one).
Regards,
Venkata Ramesh
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
The copyValue function will copy the first value in the field data to the first field, second value in data to second & so on depending on the index in copyValue. For eg
Field1->Val1
Field2->val2
Field2->val3
Field3->val4
here for different values for repeating field Field2 you will use copyvalue & depending on index ie0,1,2 the three values will be populated, but I think in your case all the values are coming under one field right? And the values are separated by ^^..Copyvalue can take values from multiple repetition of a single field into different target fields, but I could not figure out how will it take value from a single field. CopyValue would have been applicable if you had multiple data items and if the values were to be populated from each single instance of field data. Better you go with a UDF.
Edited by: addhingr on Mar 7, 2012 9:55 AM
Edited by: addhingr on Mar 7, 2012 10:09 AM
which version of PI u r working on??
In case ur version is PI7.1 (or greater) then chk this code:
UDF1:
Input will be: var1 of type argument
and add 3 result type with name result1, result2, result3
Execution type: all values of a context
String [] temp = var1[0].split("^^");
for(int i=0;i<temp.length;i++)
{
String [] split1 = temp<i>.split("~");
result1.addValue(split1[0]);
result2.addValue(split1[1]);
result3.addValue(split1[2]);
result1.addContextChange();
result2.addContextChange();
result3.addContextChange();
}
UDF2:
String [] temp = var1[0].split("^^");
for(int i=0;i<temp.length;i++)
result.addValue("");
mapping:
Input----UDF2---data
-----char
Input----UDF1 -------num
-------date
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
>>But i am not returning any value from the below function
this code (UDF2) is used to repeat target "data" node multiple times depending upon the presence of "^^" in the input string....
ur mapping output will be something like this ( correct me if i misunderstood ur req):
<data>
<char>abd</char>
<num>123</num>
<date>2011</date>
</data>
<data>
<char>efg</char>
<num>456</num>
<date>2011</date>
</data>
<data>
<char>hij</char>
<num>789</num>
<date>2012</date>
</data>
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Are you sure that the fields abd-123-2011 will be of 3,3 & 4 digits only.If yes you may not need a UDF and can use substring mapping function & can map as data-> substring(0,2)->char substring(4,6)->num substring(8,11)->date...the field data will be mapped to three substrings with values as above & the substrings will be passed to the respective fields.The position corresponding to ~ has not been included.But you may need a UDF for splitting values by ^^
Edited by: addhingr on Mar 7, 2012 7:57 AM
Edited by: addhingr on Mar 7, 2012 10:10 AM
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
85 | |
10 | |
10 | |
9 | |
7 | |
6 | |
6 | |
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.