on 05-30-2007 3:27 PM
Hi,
I have a fixed length flat file having multiple records.
Ex:
1000423421A8090
1000802421A8091
1000454421B8092
1000412421C8093
The first 2 record has A. So I have to take only one out of first two record and ignore the second one. I mean if there is any duplicate field at 11th position then I have to select only one record.
Can you please let me know how to handle this.
Thanks
Mukesh
Hi Mukesh,
R u cancating all fields at target side in Mapping?
What is ur target structure??
Thanks,
Maheshwari.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Mukesh,
Have you tried the mapping logic I gave above. This gives the same o/p as u needed.
Sample I/P
1000423421A8090
1000802421A8091
1000454421B8092
1000412421C8093
1000802421A9091
1000412421C7093
The logic first sorts all the records based on the 10th character and give the first record for each values based on 10th character.
Sorting
1000423421A8090
1000802421A8091
1000802421A9091
1000454421B8092
1000412421C7093
1000412421C8093
Sample O/P
1000423421A8090
1000454421B8092
1000412421C7093
Best Regards,
raj.
Hi Mukesh,
Try this solution....but this will work fine if 2 records with duplicate value, come in order....bcoz its difficult to sort records according to 11th value.
Sorce---substring(Starting position 10,Number of characters 1)\UDF--Target
Source----
/
use RemoveContext and SplitByValue if required.
UDF :
String str = a[0];
for(int i = 1 ; i < a.length ; i++)
{
if(str == a<b>[</b>i<b>]</b>)
result.addValue(b[i-1]);
else
result.addValue(b<b>[</b>i<b>]</b>);
str = a<b>[</b>i<b>]</b>;
}
It will be better if u provide ur source n Target structure.
Thanks,
Maheshwari.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks Guys.
My source structure is;
Record length
>MaterialNo 4
>MaterialID 6
>AreaCode 1
>StateCode 4
So if the source file has records having same area code, i have to read only one record.
For example:
The below file has 2 records having same area code "A". So I have to map only first record to the target.
1000423421A8090
1000802421A8091
1000454421B8092
1000412421C8093
Please let me know how to handle this.
Thanks
Mukesh
handle it in the mapping stage, using a combination of sort and splitbyvalue functions !!
in case of splitbyvalue use the option on value change.
More @ http://help.sap.com/saphelp_nw04/helpdata/en/21/3bb8c495125e4eb5969f0377885fe0/content.htm
Also ref: http://help.sap.com/saphelp_nw04/helpdata/en/43/c4cdfc334824478090739c04c4a249/content.htm
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Mukesh,
U can handle it at Mapping level.
Thanks,
Maheshwari.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Mukesh,
Use the following UDF to achieve the same.
<u><b><i>getchar</i></b></u>
char ret = Values.charAt(10);
return ""ret"";
<u><b><i>Maptarget</i></b></u>
//write your code here
int len = Values.length;
String char_at="";
String pos="";
for(int j=0;j<len;j++)
{
if(j==0){
result.addValue(Values[j]);
}
else
{
char_at= ""+ Values[j-1].charAt(10);
pos=""+Values[j].charAt(10);
if(!char_at.equals(pos))
{
result.addValue(Values[j]);
}
}
}
<b><i><u>Mapping Logic</u></i></b>
1. Use sort by key function
in the first parameter map - Source -UDF(getchar)
in the second parameter map -Source
2.Map the output of sortbykey to UDF(Maptarget)
3.Finally Map the o/p of UDF to target.
I checked it, its working as per your reqmt.
If you have any doubts reply me I'll help you out.
Note: In UDF(MapTarget) use Queue
Best Regards,
Raj.
User | Count |
---|---|
88 | |
23 | |
11 | |
9 | |
8 | |
5 | |
5 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.