Page 1 of 1

Prefill roster columns from external files

Posted: September 30th, 2023, 9:07 am
by blumski
Hello dear users,

Would you please help me ?

I want to prefill two columns of a roster based on values from an external file (from excel to cspro).
For example, if the first province is choosen (PROVINCE=1), prefill school code and school name of the choosen province.

I read this but did not help : viewtopic.php?p=13621&hilit=prefill#p13621
The attached file contains a sample app.

I need your help

Re: Prefill roster columns from external files

Posted: October 2nd, 2023, 7:55 am
by Gregory Martin
First, you need to attach the external dictionary to your application: File -> Add Files, select code.dcf. When you run your program, you will associate CODE_DICT with external.csdb.

Then you can loop over all cases where the province matches:
PROC APP_DICT.PROVINCE

    numeric numSchools;
   
    forcase CODE_DICT where CODE_DICT.PROVINCE = APP_DICT.PROVINCE do
        inc
(numSchools);
        APP_DICT.SCHOOL_CODE(numSchools) = CODE_DICT.SCHOOL_CODE;
        APP_DICT.SCHOOL_NAME(numSchools) = CODE_DICT.SCHOOL_NAME;
    endfor;
Note that the item names are prefixed with the dictionary name. This is because you use the same item name in both APP_DICT and CODE_DICT. Working with CSPro logic will be much easier if you use unique names. I often prefix things in a lookup file with LF_.

The above code doesn't properly account for modifying the province. For example, if you enter 1 and then change it to 2, you will still have some schools from province 1 in the table because there are fewer schools in province 2 than 1. If you wanted to allow changes, you could then clear them like this:
    // clear any schools from other provinces that were previously filled in
   
do numeric ctr = numSchools + 1 while ctr <= maxocc(APP_REC)
        APP_DICT.SCHOOL_CODE(ctr) = notappl;
        APP_DICT.SCHOOL_NAME(ctr) = "";
        NUMBER_OF_STUDENTS(ctr) = notappl;
    enddo;

Re: Prefill roster columns from external files

Posted: October 2nd, 2023, 12:29 pm
by blumski
Thank you very much Gregory 🙏