Adding same fields in different cases
-
- Posts: 63
- Joined: May 15th, 2018, 1:18 am
Adding same fields in different cases
Dear CSPRO Team,
How can I add same numeric field from different cases into another dictionary field.
How can I add same numeric field from different cases into another dictionary field.
-
- Posts: 1803
- Joined: December 5th, 2011, 11:27 pm
- Location: Washington, DC
Re: Adding same fields in different cases
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.
-
- Posts: 63
- Joined: May 15th, 2018, 1:18 am
Re: Adding same fields in different cases
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.
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.
- Attachments
-
- ABC.7z
- (3.89 KiB) Downloaded 243 times
-
- Posts: 1803
- Joined: December 5th, 2011, 11:27 pm
- Location: Washington, DC
Re: Adding same fields in different cases
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;
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;
-
- Posts: 63
- Joined: May 15th, 2018, 1:18 am
-
- Posts: 63
- Joined: May 15th, 2018, 1:18 am
Re: Adding same fields in different cases
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.
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.
-
- Posts: 1803
- Joined: December 5th, 2011, 11:27 pm
- Location: Washington, DC
Re: Adding same fields in different cases
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).
-
- Posts: 63
- Joined: May 15th, 2018, 1:18 am
Re: Adding same fields in different cases
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
Please check.
ERROR: Ambiguous symbol 'DISTRICT_REC' (2 synonyms found) - please provide qualifiers enough to avoid ambiguity near line
- Attachments
-
- ABC.7z
- (4.27 KiB) Downloaded 205 times
-
- Posts: 1803
- Joined: December 5th, 2011, 11:27 pm
- Location: Washington, DC
Re: Adding same fields in different cases
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;
do numeric ctr = 1 while ctr <= count(DISTRICT_REC)
inc(total_men, NO_OF_MENS(ctr));
enddo;
endfor;
-
- Posts: 63
- Joined: May 15th, 2018, 1:18 am
Re: Adding same fields in different cases
Thanks
It works
It works