Need suggestions on mapping unique field names only

Receiving a XML file that contains multiple line item segments whereas each one would get segments that look like the following (diff values per line item of course):

1001111111ID45678
2006666668ID45688
3006677898ID45608
4006677898ID45618
5006666668ID45628

Got this converted to an IS document. No problem with that. This is strictly a mapping question that I have.
The mission: Only map the lines above that have a that is unique and if it does happen to appear more than once, only map the line that contains the latest docNumber match, so in the above, I would map line 1 because it contains a unique docNumber 1111111 and I would have to map lines 4 and 5 because even if the number is not unique, I am to grab the latest (last) segment that contains the match. Lines 2 & 3 wouldn’t get mapped at all, because they are not unique and /or considered the latest match.

I cannot figure out the best way to approach this. I tried searching the forum, but don’t think I’m using the right keywords or something, because I can’t find this type of question answered. Thank you for any suggestions!

Hello,

I can think of two ways:-

  1. You can loop over the LIN item by taking the doc number as compare key, do the compare with all existing doc number within document.
    if no other occurance then write, else map with the other occurance. contiue with loop. Store this key in the temp doc list after mapping (in last).
    Before taking the next value check the key value in the temp list if .
    found ignore the further processing for that item.

  2. map Items into document list, convert doclist into stringlist and then write a java service to make the stringlist uniuqe by sorting list on the key (doc number in your case).

  • nD

Solution 1 is the one I’m focusing on, since my company only wants us to write java, as a last resort. The only issue I see with possible solution 1 is my requirement to always get the very last match. I can’t map based on the second occurrence of a match, because one day there may be 2 occurences (matches), but tomorrow there could be 10. My mission is to always grab the last match whether the same doc number appears on multiple line item segments 2 times or 20 times. I didn’t explain this properly in my original email. My apologies. Please help.

With a couple of basic Java services you can write each line to a hashmap using docNumber as the key. This way, the last entry will be the only one kept. The Java services you’d need are simple:

a service to add an entry
– accepts a hashMap object, a key and an object (your IS doc of the line)
– returns a hashMap object (newly created on the first add)

a service to convert the hashMap to a document list
– returns a doc list of all the stored entries

The amount of Java is minimal (and reusable) and will do what you need.

Thank you. I will look into this, as I have never worked with Hash before. I see in PSUtilities that there is createHashtable and containsKey services. Hopefully, that will help me.