countcases statement problem

Discussions about CSEntry
Forum rules
New release: CSPro 8.0
Post Reply
tbernardo
Posts: 11
Joined: May 27th, 2016, 2:02 am

countcases statement problem

Post by tbernardo »

Hi Folks,

can anyone help me with the countcases statement? when I use it without any criteria it gives me a number (e.g 4 even if there are much more cases) but when I add a criteria it gives me 1 no matter what criteria I use. I have an external file which I use to determine the products of stores. I'd like to determine the number of products of a specific store and use that number for the roster's occurrence control field name.

Regards,
Tomas
aaronw
Posts: 561
Joined: June 9th, 2016, 9:38 am
Location: Washington, DC

Re: countcases statement problem

Post by aaronw »

I ran countcases in a project that I am working on without issue. I tried with and without a condition.
numeric i = countcases(PSC_GEOCODES_DICT);
errmsg("Cases: %d", i);
i = countcases(PSC_GEOCODES_DICT where GEOCODES_PROVINCE = 01 and GEOCODES_DISTRICT = 02);
errmsg("Cases: %d", i);
tbernardo
Posts: 11
Joined: May 27th, 2016, 2:02 am

Re: countcases statement problem

Post by tbernardo »

Hi Aaron,

I still cannot get the countcases statement working. Could you please have a look at the attached test file?

Regards,

Tomas
Attachments
Test.zip
(3.58 KiB) Downloaded 256 times
aaronw
Posts: 561
Joined: June 9th, 2016, 9:38 am
Location: Washington, DC

Re: countcases statement problem

Post by aaronw »

PRODUTOSPORESTABELECE_DICT does not describe the collected data. This dictionary has one id item of length 3. However, your data looks like "1071001008Farinha de trigo." It looks to me like you are using a new version of the dictionary to collect the data, but used the old version as the external dictionary in your attached project.

Based on your current dictionary and data you only have two case ids (031 and 071) and a bunch of duplicates.

1031001001Arroz gr�o
1031001011Milho em gr�o branco
1031001012Mapira em gr�o
1071001001Farinha de milho
1071001002Farinha de trigo
1071001003Farinha de trigo
1071001004Farinha de trigo
1071001005Farinha de trigo
1071001006Farinha de trigo
1071001007Farinha de trigo
1071001008Farinha de trigo

Your countcases return 2 and 1 which is what I would expect.
i = countcases(PRODUTOSPORESTABELECE_DICT); // = 2 (031 & 071)
i = countcases(PRODUTOSPORESTABELECE_DICT where PRODUTOSPORESTABELECE_ID = 071); // 1 (071)
tbernardo
Posts: 11
Joined: May 27th, 2016, 2:02 am

Re: countcases statement problem

Post by tbernardo »

Hi Aaron,
In fact PRODUTOSPORESTABELECE_DICT doesn't describe the collected data. It is an external dictionary with province codes (3), store code (3), product codes (3) and product name (30). The current dictionary (TEST_DICT) data has no duplicates. I made small changes in it adding month and year. I would expect 11 cases without criteria and 3 cases if I add 031 as condition and 8 if the condition is 071. The idea is to determine the number of cases meeting a criteria and restrict the roster based on that number. What am I doing wrong?
Regards,
Tomas
Attachments
Test.zip
(4.93 KiB) Downloaded 263 times
aaronw
Posts: 561
Joined: June 9th, 2016, 9:38 am
Location: Washington, DC

Re: countcases statement problem

Post by aaronw »

The external dictionary you're describing is different from the one originally attached. It now looks complete.

Countcases is being called on PRODUTOSPORESTABELECE_DICT. This dictionary is associated with ProdutosPorEstabelece.dat. However, there are only two unique case ids specified, 031001 and 1071001.

Now, I am going to update ProdutosPorEstabelece.dat and make all 11 case ids unique. Here is what the data now looks like:

1031001001Arroz
1031002011Milho branco
1031003012Mapira
1071001001Cadeira de plastico
1071002002Ferro de engomar
1071003003Computador
1071004004Impressora
1071005005Disquete
1071006006Garrafa
1071007007Tijolo
1071008008Celular

With this data your countcases will return 11 and 3 which is what you are expecting.

Remember the first value identifies the record. The next 6 values define your province and store code. These are your case ids. The additional data is not part of your case id. The case id allows you to uniquely identify this data.
tbernardo
Posts: 11
Joined: May 27th, 2016, 2:02 am

Re: countcases statement problem

Post by tbernardo »

Thanks Aaron. Now I got the idea of the statement. Since a store can have many products in order to have unique IDs I have to add the product code as well. I made the necessary changes to the dictionary and got what I expected.
Regards,
Tomas
Post Reply