Merging of 2 CSDBE Files

Other discussions about CSPro
Forum rules
New release: CSPro 8.0
Post Reply
YFT_CBSD
Posts: 47
Joined: January 3rd, 2023, 12:36 am

Merging of 2 CSDBE Files

Post by YFT_CBSD »

Hello i'd like to ask if this screnario is possible:

A and B contatins the same CASE ID
A_CSDBE contains the data from section A-E
B_CSDBE contains the data section F

i want to merge the both files. is it possible?
Outcome will contain the data from Section A-F.
if yes. How?
Gregory Martin
Posts: 1777
Joined: December 5th, 2011, 11:27 pm
Location: Washington, DC

Re: Merging of 2 CSDBE Files

Post by Gregory Martin »

This is traditionally done using a record sort: https://www.csprousers.org/help/CSSort/ ... _sort.html

However, record sorts only work on text files, so you could:

1) Convert both files to text.
2) Perform the record sort.
3) Convert the output data back to Encrypted CSPro DB (if necessary).

However, you will lose information that is not stored in a text file, like the sync history, so this may not necessarily be a viable option.

Anther option would be to:

1) Load B_CSDBE.
2) Store the Section F data in temporary variables.
3) Load A_CSDBE.
4) Copy the data from the temporary variables back to Section F.
YFT_CBSD
Posts: 47
Joined: January 3rd, 2023, 12:36 am

Re: Merging of 2 CSDBE Files

Post by YFT_CBSD »

Anther option would be to:

1) Load B_CSDBE.
2) Store the Section F data in temporary variables.
3) Load A_CSDBE.
4) Copy the data from the temporary variables back to Section F.

What tool will i use in this case?
Gregory Martin
Posts: 1777
Joined: December 5th, 2011, 11:27 pm
Location: Washington, DC

Re: Merging of 2 CSDBE Files

Post by Gregory Martin »

You would do this in a data entry or batch application. If this is all post-data collection processing, you could create a batch application:

1) The input dictionary to your program would be a dummy dictionary, meaning that you won't actually use it. You can create a new dictionary for this.

2) You will attach your actual dictionary to the program as an external dictionary.

Then your code would look something like this:
// load the case in B
setfile(MY_DICT, "b.csdbe");
loadcase(MY_DICT, "my_id");

// assign section F variables from B to temporary variables
numeric temp_f01 = F01;
numeric temp_f02 = F02;
// ...

// load the case in A
setfile(MY_DICT, "a.csdbe");
loadcase(MY_DICT, "my_id");

// assign temporary variables to A's section F
F01 = temp_f01;
F02 = temp_f02;

// save the case, either to A, or to a different file; this shows to a different file
setfile(MY_DICT, "new-file.csdbe|password=1234", append);
writecase(MY_DICT);
YFT_CBSD
Posts: 47
Joined: January 3rd, 2023, 12:36 am

Re: Merging of 2 CSDBE Files

Post by YFT_CBSD »

Hi, what function should i use in the

loadcase(HPQF2_DICT, "my_id");

to call all the caseid in my csdbe?
Thanks
Gregory Martin
Posts: 1777
Joined: December 5th, 2011, 11:27 pm
Location: Washington, DC

Re: Merging of 2 CSDBE Files

Post by Gregory Martin »

Can you clarify your question? Are you trying to look at all cases in your file? If so, you can iterate over every case using the forcase statement:

https://www.csprousers.org/help/CSPro/f ... ement.html
YFT_CBSD
Posts: 47
Joined: January 3rd, 2023, 12:36 am

Re: Merging of 2 CSDBE Files

Post by YFT_CBSD »

Yes. for example I have 10cases in A.csdbe and 10 cases also in B.csdbe.
How can i set it at the loadcase function all at once(not manually typing all the case id of 10 cases).

Can u show how to insert the forcase function in the code below? Thanks
// load the case in B
setfile(MY_DICT, "b.csdbe");
loadcase(MY_DICT, "my_id");

// assign section F variables from B to temporary variables
numeric temp_f01 = F01;
numeric temp_f02 = F02;
// ...

// load the case in A
setfile(MY_DICT, "a.csdbe");
loadcase(MY_DICT, "my_id");

// assign temporary variables to A's section F
F01 = temp_f01;
F02 = temp_f02;

// save the case, either to A, or to a different file; this shows to a different file
setfile(MY_DICT, "new-file.csdbe|password=1234", append);
writecase(MY_DICT);
Gregory Martin
Posts: 1777
Joined: December 5th, 2011, 11:27 pm
Location: Washington, DC

Re: Merging of 2 CSDBE Files

Post by Gregory Martin »

What I would do is put all the keys into a string list and then loop over them. For example, this will get all of A's IDs (assuming A is open at the beginning of this code), and then loop over each case:
    List string case_keys_in_a;
    keylist(MY_DICT, case_keys_in_a);
   
    do numeric ctr = 1 while ctr <= case_keys_in_a.length()
        setfile(MY_DICT, "a.csdbe");
        loadcase(MY_DICT, case_keys_in_a(ctr));
       
        //....
   
enddo;
Post Reply