Page 1 of 1

How to detect duplicates cases ?

Posted: May 4th, 2017, 5:13 am
by thierryt
Hi all,
please, i want to know if there is a function whom can indicates that i have a duplicate case when i fill the last question of id-items.
i know that when it is a duplicate case there is a message system 'Case Ids 0001001 duplicate an existing case..', but i want to program it before receive this message.
Thanks !

Re: How to detect duplicates cases ?

Posted: May 4th, 2017, 7:36 am
by josh
You should be able to use the keylist function for this. Get the list of keys from your dictionary and then loop through it to check the ids entered against the list of other ids in the file.See the example for keylist in the help.

Re: How to detect duplicates cases ?

Posted: May 4th, 2017, 7:51 am
by Gregory Martin
If using 7.0 (which you have to for keylist), you can also use the find function on the input dictionary. Construct the potential key as a string, and then do something like this:
if find(INPUT_DICT,=,keyString) then
    errmsg("You've already entered a case with these IDs");
endif;

Re: How to detect duplicates cases ?

Posted: May 4th, 2017, 3:21 pm
by thierryt
Hi Josh, for now i use cspro 6.3, thanks !

Re: How to detect duplicates cases ?

Posted: May 4th, 2017, 3:23 pm
by thierryt
Hi Martin thanks a lot for that solution,
i executed it on killfocus and it is very nice !!!
When i read the help of find function , i was thinking that it is always for external dict, but now i know that i can use it for input dict.
Thanks a lot !

Re: How to detect duplicates cases ?

Posted: May 4th, 2017, 5:54 pm
by Gregory Martin
You were right that in the past it was only for external dictionaries. In fact, just this week I updated the help for the find function, so when 7.0 comes out you'll be able to learn about these new features.

Re: How to detect duplicates cases ?

Posted: June 2nd, 2017, 1:01 pm
by Merlino
Hi!
As josh said, I tried with keylist but it worked only once and nothing again. It is always the same message of the system ((duplicated case ID...) although I did the same as the following example from CSPro's help

Example 2
PROC GLOBAL

list string enteredKeys;

PROC HOUSEHOLD_NUMBER

keylist(CENSUS_DICT,enteredKeys);

do numeric keyCtr = 1 while keyCtr <= length(enteredKeys)

if HOUSEHOLD_NUMBER = tonumber(enteredKeys(keyCtr)[9:2]) then
errmsg("The household number %d has already been entered.",HOUSEHOLD_NUMBER);
reenter;
endif;

enddo;

Re: How to detect duplicates cases ?

Posted: June 3rd, 2017, 3:13 am
by josh
Yes, I just tested this and I see the same problem. It seems that the duplicate ID error message runs before the postproc so there is no way to avoid it.

Re: How to detect duplicates cases ?

Posted: June 3rd, 2017, 11:18 am
by Merlino
Ok josh!
is it possible in a next revision to change some thing about?

Re: How to detect duplicates cases ?

Posted: June 5th, 2017, 5:24 am
by josh
We will look into it.