How to use DELCASE function to delete many cases in the csdb file ?

Discussions about CSEntry
Forum rules
New release: CSPro 8.0
mosbi
Posts: 23
Joined: April 8th, 2021, 4:13 am

How to use DELCASE function to delete many cases in the csdb file ?

Post by mosbi »

Hello TML,
I'm having trouble with the DELCASE function.
I try to delete several questionnaires from a FORCASE loop, but unfortunately the questionnaires are not deleted. I really don't know where the problem is?
Here is an excerpt from my script:

Code: Select all

forcase DICT_NAME WHERE C24=codeLogin do
delcase(DICT_NAME, key(DICT_NAME));
endfor;
I don't really know where the problem is, maybe there is a CSPRO principle about deleting questionnaires that I don't understand.
Can someone guide me?
Gregory Martin
Posts: 1777
Joined: December 5th, 2011, 11:27 pm
Location: Washington, DC

Re: How to use DELCASE function to delete many cases in the csdb file ?

Post by Gregory Martin »

Try that loop without the key function. Delcase will delete the currently loaded case, so it's not necessary. I believe that will work for you...if not, let us know.
forcase DICT_NAME WHERE C24 = codeLogin do
    delcase
(DICT_NAME);
endfor;
mosbi
Posts: 23
Joined: April 8th, 2021, 4:13 am

Re: How to use DELCASE function to delete many cases in the csdb file ?

Post by mosbi »

Unfortunately this solution does not work.
Here is my code,

Code: Select all

forcase CAISSE_VILLAGEOISE WHERE C24=codeLogin do
					numeric rep;
					rep = delcase(CAISSE_VILLAGEOISE);
					errmsg("%v",rep);
				endfor;
				
I even tried to see if the forcase loop executes well, and I see that it executes well because the ERRMSG function that I placed inside executes well, but the execution of the DELCASE function returns 0, which means that the DELCASE function in turn did not execute.
I really don't know why?
thank's
sherrell
Posts: 397
Joined: April 2nd, 2014, 9:16 pm
Location: Washington, DC

Re: How to use DELCASE function to delete many cases in the csdb file ?

Post by sherrell »

Hi Mosbi,

Could you post your app here w/a few cases so we can test it out?

Or, if you'd prefer not to make your files public, could you send them to us at cspro@lists.census.gov? Be sure you zip all the applicable files (use the pack app from the tools to be sure), and attach a csdb file.

Thanks,
Sherrell
mosbi
Posts: 23
Joined: April 8th, 2021, 4:13 am

Re: How to use DELCASE function to delete many cases in the csdb file ?

Post by mosbi »

Wow, this is getting complicated.
Because my application is very complex with connections to servers, syncdata etc...
Even if I send you this, the configuration that must follow even can take time.
I can not understand, what can block the operation of a simple DELCASE.
My function is however very simple as I showed it to you!!!
all the parameters that the function requires are respected, I don't know now.
If I have to reduce my application to simple and be able to send it to you, it may also take me time and it may not reflect reality.
Anyway !!!!
Maybe someone else can give me some other tips?
sherrell
Posts: 397
Joined: April 2nd, 2014, 9:16 pm
Location: Washington, DC

Re: How to use DELCASE function to delete many cases in the csdb file ?

Post by sherrell »

Hi Mosbi,

Unless there's something seriously wrong in the engine (which we doubt), you of course shouldn't have this problem. My suggestion to you is:

1) Strip down your application to just the delete logic; does that work? If not, then zip the application and any needed data files, and send it to us at cspro@lists.census.gov. We'll take a look at it (I will be sending you a direct message, please look for that). Otherwise, continue to step 2.

2) Build your application back up incrementally to the complete application. If your app is large, then start from the full application and drop file I/O (such as syncing, loadcases, writecases, etc). Anything that looks like it might interfere with what you're doing. If that doesn't work, remove as much as possible until you can get the delcase to work. When you get it to work, zip up the application and save this second iteration.

3) Now, undo the last change you made, and confirm that delcase is failing. If delcase works, then zip up this version and send it to us with the zip file from Step 2. Be sure to include any data files we would need to test this. If however delcase is working, then you need to overwrite the zip file from step 2 and keep adding code back in until delcase fails.

We essentially want the most complete version of your program when delcase works, and then the next step larger/complete application when delcase fails. Hopefully I've explained this clearly, please let me know if not.

Sherrell
mosbi
Posts: 23
Joined: April 8th, 2021, 4:13 am

Re: How to use DELCASE function to delete many cases in the csdb file ?

Post by mosbi »

Hello,
Finally I was able to simplify my application to explain my problem to you.
After decompressing my attached file, in the application folder, here are some descriptions of the different files:
- CaisseVillageoise.dcf: representing the external dictionary of the data that I want to delete with the delcase
- CaisseVillageoise.csdb: representing the data that I want to delete with the delcase
- SendDataServer.ent.apc: representing an external function for the deletion action with the delcase.
Functioning:
When you launch my application:
- at the first question enter any number to pass
- The second question asks if you want to delete the data?
Choose the first option.
As soon as you choose the first option, normally the data in the CaisseVillageoise.csdb file must be deleted, unfortunately this is not the case.
I hope that with this application that reflects my reality, someone could offer me a solution.
In the meantime....
Thank you.
Attachments
AppTest.zip
(12.84 KiB) Downloaded 112 times
sherrell
Posts: 397
Joined: April 2nd, 2014, 9:16 pm
Location: Washington, DC

Re: How to use DELCASE function to delete many cases in the csdb file ?

Post by sherrell »

Hi Mosbi,

It looks like all the files didn't make it; specifically, the data file CaisseVillageoise.csdb

Could you try again?

Thanks
Sherrell
mosbi
Posts: 23
Joined: April 8th, 2021, 4:13 am

Re: How to use DELCASE function to delete many cases in the csdb file ?

Post by mosbi »

Oh sorry, I didn't notice that.
However I zipped the application through the Pack Application option in the Tools menu of CSPRO.
I just added the missing file and redo the manual compression.

Thank you.
Attachments
AppTest_updated.zip
(25.02 KiB) Downloaded 102 times
sherrell
Posts: 397
Joined: April 2nd, 2014, 9:16 pm
Location: Washington, DC

Re: How to use DELCASE function to delete many cases in the csdb file ?

Post by sherrell »

Hi Mosbi,

Thanks for your data file.

Problem #1: We have a bug (and will have to fix it), but you're not getting the warning message about your delcase call. While the syntax for the function shows:

Code: Select all

b = delcase(dictionary_nameʃ, id1, ..., idNʅ);
the id1 to idN just means that the function takes as many identifier arguments as needed that have been defined in your dictionary. So, if you move your function into the main application and do a compile, you'll get a warning on this call, as you're only providing the first ID, when you need to provide them all. The sentence in the help page that mentions this is:

The combined length of the variables in the list must equal the length of the case IDs defined for the external dictionary.

Here's the help page: https://www.csprousers.org/help/CSPro/d ... ction.html

Problem #2: You don't need any arguments for your delcase! Since your forcase loop restricts the cases to CDC0014, those are the only cases that are being processed within the loop, so those are the only ones that can get deleted.

Problem #3: It still wasn't working (it should be at this point), so I opened CaisseVillageoise.csdb in DataViewer and noticed the IDs in the tree didn't match what was showing up in the right view. Were you per chance manually editing this file in another app? Specifically C67 wasn't matching for two of the cases. Once I saved out the datafile as a .dat file and read it back in as a csdb, everything worked fine.

Comment: A minor issue, but you're restricting ID1 to CDC0014; yet in your dictionary you did not define this as one of the possible IDs. This doesn't impact the program, but since you defined quite a few other values for ID1, I thought I'd mention that this isn't one of them.

Hopefully this should do it.
Sherrell
Post Reply