Hello Cspro users.
I have a case where I will number concessions and households.
The concession number will depend on the number of households in it. And the households are sequential within a concession. Is there a cspro function which can do that?
Cascading sequential numbering
-
mussabahire
- Posts: 57
- Joined: September 5th, 2016, 4:55 am
Cascading sequential numbering
You do not have the required permissions to view the files attached to this post.
-
htuser
- Posts: 687
- Joined: December 19th, 2011, 6:26 pm
- Location: Silver Spring Area, MD, USA
Re: Cascading sequential numbering
Hello,
One the the approach (I implemented in the attached example) is to use SQLQuery.
Try to adapt this posted example on what you want to do and if you have some issues, please let me know by posting a small apps on this forum.
Best,
One the the approach (I implemented in the attached example) is to use SQLQuery.
Try to adapt this posted example on what you want to do and if you have some issues, please let me know by posting a small apps on this forum.
Best,
You do not have the required permissions to view the files attached to this post.
G.VOLNY, a CSProuser from Haiti, since 2004
-
mussabahire
- Posts: 57
- Joined: September 5th, 2016, 4:55 am
Re: Cascading sequential numbering
Here is the application.
You can have a look and help me with sequential numbering.
Thank you.
You can have a look and help me with sequential numbering.
Thank you.
You do not have the required permissions to view the files attached to this post.
-
htuser
- Posts: 687
- Joined: December 19th, 2011, 6:26 pm
- Location: Silver Spring Area, MD, USA
Re: Cascading sequential numbering
I did some changes and I preferred using pure CSPro logic, because requires less coding than the SQL approach. I also did a basic change in the dictionary because it ensure more data integrity:
a) concession roster is record limited to the number of concessions defined in CONC.
b) household roster record is limited to HHINCONCESSION defined in the Concession roster.
Please test it and let me know if it is correct.
To the CSPro Developer Team, I discovered that list and array defined at the Roster Proc level are not recognized in any items relative of this roster... This behavior should be a bug.
Best
a) concession roster is record limited to the number of concessions defined in CONC.
b) household roster record is limited to HHINCONCESSION defined in the Concession roster.
Please test it and let me know if it is correct.
To the CSPro Developer Team, I discovered that list and array defined at the Roster Proc level are not recognized in any items relative of this roster... This behavior should be a bug.
Best
You do not have the required permissions to view the files attached to this post.
Last edited by htuser on May 10th, 2025, 9:44 pm, edited 1 time in total.
G.VOLNY, a CSProuser from Haiti, since 2004
-
htuser
- Posts: 687
- Joined: December 19th, 2011, 6:26 pm
- Location: Silver Spring Area, MD, USA
Re: Cascading sequential numbering
I did minor improvements to the logic to :
a) End the roster when all the individuals of each household are recorded in the HOUSEHOLD_RECORD000 roster;
b) Give a direct way to fill HOW_MANY_INDIVIDUAL because other fields are automatically populated;
c) Correct the comment about list, array defined in the Preproc of the Roster Proc are not recognized by Roster's items.
Best
a) End the roster when all the individuals of each household are recorded in the HOUSEHOLD_RECORD000 roster;
b) Give a direct way to fill HOW_MANY_INDIVIDUAL because other fields are automatically populated;
c) Correct the comment about list, array defined in the Preproc of the Roster Proc are not recognized by Roster's items.
/* Application 'SEQUENTIAL' logic file generated by CSPro */
PROC GLOBAL
PROC SEQUENTIAL_FF
PROC CONCESSION_ID
Preproc
if curocc()>CONC then
errmsg ("No more concession!!!");
endgroup;
endif;
do numeric i = 1 while i <= CONC
if curocc()=1 then
$=curocc();
else $= $(curocc()-1) + 1;
endif;
enddo;
PROC HOUSEHOLD_RECORD000
Preproc
advance to HOW_MANY_INDIVIDUAL(1);
PROC CONCESSION_ID_1
Preproc
//Why list and array declared HOUSEHOLD_RECORD000 are not recognized by roster's items?
list numeric concessionNumber;
array numeric householdByConcession(30,2);
householdByConcession.clear();
do numeric i =1 while i<=CONC
if HHINCONCESSION(i)>0 then
householdByConcession(i,1)=CONCESSION_ID(i);
householdByConcession(i,2)=HHINCONCESSION(i);
endif;
enddo;
numeric nRow=tblrow (householdByConcession);
concessionNumber.clear();
do numeric i=1 while i<= nRow
do numeric j=1 while j<= householdByConcession(i,2)
concessionNumber.add(householdByConcession(i,1));
enddo;
enddo;
do numeric i = 1 while i <= concessionNumber.length()
CONCESSION_ID_1(i)= concessionNumber(i);
enddo;
//Onfocus
if curocc()>concessionNumber.length() then
errmsg ("No more Household!!!");
endgroup;
endif;
Postproc
advance to HOW_MANY_INDIVIDUAL;
PROC HOUSEHOLD_ID
Preproc
numeric i=curocc();
if i=1 then
$=1
elseif i>1 and CONCESSION_ID_1(i-1)<>CONCESSION_ID_1(i)
then
$=1
else
$ = $(i-1) + 1;
endif;
PROC HOW_MANY_INDIVIDUAL
Postproc
advance to HOW_MANY_INDIVIDUAL(curocc()+1);
You can copy and paste this logic in the demo app.PROC GLOBAL
PROC SEQUENTIAL_FF
PROC CONCESSION_ID
Preproc
if curocc()>CONC then
errmsg ("No more concession!!!");
endgroup;
endif;
do numeric i = 1 while i <= CONC
if curocc()=1 then
$=curocc();
else $= $(curocc()-1) + 1;
endif;
enddo;
PROC HOUSEHOLD_RECORD000
Preproc
advance to HOW_MANY_INDIVIDUAL(1);
PROC CONCESSION_ID_1
Preproc
//Why list and array declared HOUSEHOLD_RECORD000 are not recognized by roster's items?
list numeric concessionNumber;
array numeric householdByConcession(30,2);
householdByConcession.clear();
do numeric i =1 while i<=CONC
if HHINCONCESSION(i)>0 then
householdByConcession(i,1)=CONCESSION_ID(i);
householdByConcession(i,2)=HHINCONCESSION(i);
endif;
enddo;
numeric nRow=tblrow (householdByConcession);
concessionNumber.clear();
do numeric i=1 while i<= nRow
do numeric j=1 while j<= householdByConcession(i,2)
concessionNumber.add(householdByConcession(i,1));
enddo;
enddo;
do numeric i = 1 while i <= concessionNumber.length()
CONCESSION_ID_1(i)= concessionNumber(i);
enddo;
//Onfocus
if curocc()>concessionNumber.length() then
errmsg ("No more Household!!!");
endgroup;
endif;
Postproc
advance to HOW_MANY_INDIVIDUAL;
PROC HOUSEHOLD_ID
Preproc
numeric i=curocc();
if i=1 then
$=1
elseif i>1 and CONCESSION_ID_1(i-1)<>CONCESSION_ID_1(i)
then
$=1
else
$ = $(i-1) + 1;
endif;
PROC HOW_MANY_INDIVIDUAL
Postproc
advance to HOW_MANY_INDIVIDUAL(curocc()+1);
Best
G.VOLNY, a CSProuser from Haiti, since 2004
-
mussabahire
- Posts: 57
- Joined: September 5th, 2016, 4:55 am
Re: Cascading sequential numbering
Thanks, This is what I wanted.
Only if it can be in one roster.
Only if it can be in one roster.