cancel
Showing results for 
Search instead for 
Did you mean: 

How to Ignore records having duplicate field value

Former Member
0 Kudos

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

Accepted Solutions (0)

Answers (4)

Answers (4)

Former Member
0 Kudos

Hi Mukesh,

R u cancating all fields at target side in Mapping?

What is ur target structure??

Thanks,

Maheshwari.

Former Member
0 Kudos

Source:

Record

>MaterialNo

>MaterialID

>AreaCode

>StateCode

Target:

Record

>MaterialNo

>MaterialID

>AreaCode

>StateCode

Both the source and target structure is same. The idea is if "AreaCode" is same for example: "A", we have to map only one record.

Hope this clarifies my requirement.

Thanks

Mukesh

justin_santhanam
Active Contributor
0 Kudos

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.

Former Member
0 Kudos

Thanks Raj,

I have not checked it. I will check it and will let you know.

Thanks

Mukesh

justin_santhanam
Active Contributor
0 Kudos

Sure, If you find it difficult, let me know.

Best Regards,

raj.

Former Member
0 Kudos

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.

justin_santhanam
Active Contributor
0 Kudos

Maheshwari,

We can sort the records, based on the charactet position. Please see the UDF I mentioned above .

Best Regards,

raj.

Former Member
0 Kudos

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

Former Member
0 Kudos

Hi Guys,

Is there any way to do it in mapping.

Regards

Mukesh

Shabarish_Nair
Active Contributor
0 Kudos

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

Former Member
0 Kudos

Hi Mukesh,

U can handle it at Mapping level.

Thanks,

Maheshwari.

Former Member
0 Kudos

Thanks Maheshwari. Can you please throw some light on how to handle it mapping.

I appreciate for your response.

Thanks

Mukesh

justin_santhanam
Active Contributor
0 Kudos

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.

justin_santhanam
Active Contributor
0 Kudos

Mukesh,

Does the mapping logic works. Please provide your feedback.

Best Regards,

raj.