Dear Users,

While writing code we use to put setrange, before that we put setcurrentkey just to filter the data for that particular keys. I want to know in what situations we will be putting that setcurrentkey.


SETCURRENTKEY is used to select a key for a record, and thereby set the sort order that is used for the table in question. This key becomes the current key and is used by the FIND Function (RECORD), the NEXT Function (RECORD), and other functions until another key is selected. Until this function is called, the table’s primary key is used as the current key.

Use the following guidelines when you use SETCURRENTKEY:

  • Inactive fields are ignored. Only active keys are scanned.

  • When searching for a key, C/SIDE selects the first occurrence of the specified field(s).

This means the following:

  • If you specify only one field as a parameter when you call SETCURRENTKEY, the key that is actually selected may consist of more than one field.

  • If the field that you specify is the first component of several keys, the key that is selected may not be the key that you expect.

  • If no keys can be found that include the field(s) that you specify, a runtime error occurs unless you test the Boolean return value of SETCURRENTKEY in your code.

  • If you do test the return value, you must decide what the program should do if the function returns false, because without a runtime error, the program will continue to run even though no key was found.

Hi Mohana,

Thank you for your kind reply.this will help me a lot.


Please Don’t forget to VERIFY the post(s) that solved your problem.

ya sure.