Isolate Multiple Occurance of Same Records - BSFN

FrankCLT

Well Known Member
Hello,

I need to read through an array in a C++ BSFN and either write to another array or file the multiple occurances,.....below is an example of the data.....

Thank you for any help....

Array1: What I need in Array 2:
1111111 1111111
1111111 1111111
1111111 1111111

2222222 4444444
3333333 4444444
4444444 5555555
4444444 5555555
5555555
5555555
6666666
7777777
8888888
9999999
 
Last edited:
Easiest way would be to use jdeCache since you can create a unique index on the field(s) in the struct that will help you find the duplicates.
 
Below is actual sample data.......the end goal is to take data from array aBoxTrkA and populate aBoxTrkD with only the multiple occurrences. The red highlight in aBoxTrkA is the only record that would NOT be written to aBoxTrkD because it occurs just once. I will add the code shortly....and a Visual Studio Debug....


Thanks again,
FrankCLT




aBoxTrkA
0 085085000303985330 1Z8R9A510346043690
1 085085000303985330 1Z8R9A510347631301
2 085085000303985330 1Z8R9A510347814159
3 085085000303985330 1Z8R9A510347957540
4 085085000303985507 1Z8R9A510346913571
5 085085000303985507 1Z8R9A510347894671
6 085085000303985521 1Z8R9A510346303480
7 085085000303985521 1Z8R9A510347934163
8 085085000303985620 1Z8R9A510346043690

9 085085000303985637 1Z8R9A510346408331
10 085085000303985637 1Z8R9A510348212726
11 085085000303985729 1Z8R9A510347053436
12 085085000303985729 1Z8R9A510347622311




aBoxTrkD
0 085085000303985330 1Z8R9A510346043690
1 085085000303985330 1Z8R9A510347631301
2 085085000303985330 1Z8R9A510347814159
3 085085000303985330 1Z8R9A510347957540
4 085085000303985507 1Z8R9A510346913571
5 085085000303985507 1Z8R9A510347894671
6 085085000303985521 1Z8R9A510346303480
7 085085000303985521 1Z8R9A510347934163
8 085085000303985637 1Z8R9A510346408331
9 085085000303985637 1Z8R9A510348212726
10 085085000303985729 1Z8R9A510347053436
11 085085000303985729 1Z8R9A510347622311
 

Attachments

  • Code.JPG
    Code.JPG
    36.9 KB · Views: 6
Last edited:
Here is the snippet of code:

Code.JPG
















Results from above loop
DebugStep.JPG




















This is what the above debug should look like......index from 0 - 11, no missing entries.

aBoxTrkD
0 085085000303985330 1Z8R9A510346043690
1 085085000303985330 1Z8R9A510347631301
2 085085000303985330 1Z8R9A510347814159
3 085085000303985330 1Z8R9A510347957540
4 085085000303985507 1Z8R9A510346913571
5 085085000303985507 1Z8R9A510347894671
6 085085000303985521 1Z8R9A510346303480
7 085085000303985521 1Z8R9A510347934163
8 085085000303985637 1Z8R9A510346408331
9 085085000303985637 1Z8R9A510348212726
10 085085000303985729 1Z8R9A510347053436
11 085085000303985729 1Z8R9A510347622311

















 
Last edited:
Maybe I'm complicating things.....how would i find distinct items in the array....the red would be the distinct record.


aBoxTrkA
0 085085000303985330
1 085085000303985330
2 085085000303985330
3 085085000303985330
4 085085000303985507
5 085085000303985507
6 085085000303985521
7 085085000303985521
8 085085000303985620
9 085085000303985637
10 085085000303985637
11 085085000303985729
12 085085000303985729
 
To avoid the "missing" indexes, use a separate counter variable that only increments when you get inside your 'if' statement. use that variable instead of j when you are assigning to your D array: aBoxTrkD[newvar].
 
You can do this in two loops. Create a struct that has a key and a counter. The key will contain the first part of the string. In the first loop, you create an array of this struct that should look like this:

[0] => {key: "085085000303985330", count: 4 }
[1] => {key: "085085000303985507 ", count: 2 }
..
..

Then, you loop through this array to pick the ones from the original array. You skip the ones that have count < 2.


I know this is not relevant to your question, but you can do this in one line in C#:

List<string> list = new List<string>() {
"085085000303985330 1Z8R9A510346043690",
"085085000303985330 1Z8R9A510347631301",
"085085000303985330 1Z8R9A510347814159",
"085085000303985330 1Z8R9A510347957540",
"085085000303985507 1Z8R9A510346913571",
"085085000303985507 1Z8R9A510347894671",
"085085000303985521 1Z8R9A510346303480",
"085085000303985521 1Z8R9A510347934163",
"085085000303985620 1Z8R9A510346043690",
"085085000303985637 1Z8R9A510346408331",
"085085000303985637 1Z8R9A510348212726",
"085085000303985729 1Z8R9A510347053436",
"085085000303985729 1Z8R9A510347622311"
};

var result = list.GroupBy(x => x.Substring(0, x.IndexOf(" "))).Where(y => y.Count() > 1).SelectMany(x => x).ToList();

That's it. :)
 
If there was such a thing as a C++ BSFN I'd use a std::map templated container.

But sadly we are stuck plain old C language for BSFNs so as another poster said, a generic jdeCache based BSFN approach would work. Plenty of examples sitting around in the standard JDE C business functions.
 
Back
Top