Page 1 of 1

Adding same fields in different cases

Posted: November 19th, 2019, 6:08 am
by Bhupender11
Dear CSPRO Team,

How can I add same numeric field from different cases into another dictionary field.

Re: Adding same fields in different cases

Posted: November 19th, 2019, 6:37 am
by Gregory Martin
Can you give more detail about what you're trying to do? Are you during this during entry or during editing? You can only have one case in memory at a given time, so you may have to be clever with an approach for accessing data from multiple cases.

Re: Adding same fields in different cases

Posted: November 20th, 2019, 12:07 am
by Bhupender11
Dear Gregory Martin,
Thanks for reply.

I have attached a dummy application. Please look into that.
Here are two dictionary file. One is District_Dict and other is Combined_Dict.
I have entered 4 cases in District application where population of men is given.

I want to add total population of men in combined dictionary application.

Re: Adding same fields in different cases

Posted: November 20th, 2019, 7:05 am
by Gregory Martin
You can iterate through each case to total the men:
PROC NO_OF_MENS_COMBINED

preproc

    numeric
total_men = 0;

   
forcase DISTRICT_DICT where STATE_CODE = STATE do
        inc
(total_men, NO_OF_MENS);
   
endfor;

    NO_OF_MENS_COMBINED = total_men;

Re: Adding same fields in different cases

Posted: November 21st, 2019, 1:19 am
by Bhupender11
Thanks

Re: Adding same fields in different cases

Posted: November 22nd, 2019, 5:05 am
by Bhupender11
Dear Gregory Martin,

I again stuck there. It shows an error while doing

forcase DISTRICT_DICT where STATE_CODE = STATE do

do numeric ctr = 1 while ctr <= totocc(DISTRICT_REC000)

total_men = (total_men + NO_OF_MENS);
enddo;

total=total+total+men;

endfor;


ERROR: 'DISTRICT_REC000' is not a declared variable or is a misspelled dictionary entry
ERROR: Record, group or multiple item name expected near line 6 in NO_OF_MENS_COMBINED procedure


If the field is multiple than how can I add population of men.


Thanks in advance.

Re: Adding same fields in different cases

Posted: November 22nd, 2019, 7:07 am
by Gregory Martin
DISTRICT_REC000 likely refers to a roster (form element), which you won't have when using this as an external dictionary. Instead, you'll use the record name, DISTRICT_REC. Also, when you refer to NO_OF_MENS in the loop, you'll want to use NO_OF_MENS(ctr).

Re: Adding same fields in different cases

Posted: November 24th, 2019, 11:39 pm
by Bhupender11
I have tried this but it shows Ambiguity error.

Please check.


ERROR: Ambiguous symbol 'DISTRICT_REC' (2 synonyms found) - please provide qualifiers enough to avoid ambiguity near line

Re: Adding same fields in different cases

Posted: November 25th, 2019, 6:28 am
by Gregory Martin
Sometimes you get that error with the totocc function. I like to use the count function instead. This will work:
    forcase DISTRICT_DICT where STATE_CODE = STATE do

        do numeric
ctr = 1 while ctr <= count(DISTRICT_REC)
           
inc(total_men, NO_OF_MENS(ctr));
       
enddo;

   
endfor;

Re: Adding same fields in different cases

Posted: November 25th, 2019, 6:46 am
by Bhupender11
Thanks

It works