Page 1 of 1

Cascading sequential numbering

Posted: May 5th, 2025, 8:50 am
by mussabahire
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?

Re: Cascading sequential numbering

Posted: May 6th, 2025, 11:18 am
by htuser
Hello,
One the the approach (I implemented in the attached example
TEST_Incrementation.zip
) 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,

Re: Cascading sequential numbering

Posted: May 7th, 2025, 12:22 am
by mussabahire
Here is the application.
You can have a look and help me with sequential numbering.
Thank you.

Re: Cascading sequential numbering

Posted: May 7th, 2025, 2:12 pm
by htuser
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
SEQ_Modified_GV.zip
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

Re: Cascading sequential numbering

Posted: May 8th, 2025, 8:43 am
by htuser
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.
/* 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.
Best

Re: Cascading sequential numbering

Posted: May 10th, 2025, 7:40 am
by mussabahire
Thanks, This is what I wanted.
Only if it can be in one roster.