Hi,
it is probably overflow of the Comp_list variable.
Try to declare it longer than 1000 chars.

BTW, for better performance you should avoid testing "IF n=Comp_Counter THEN ... ".
You can add the comma in each loop and after closing the cursor just trim the last one:
Comp_list := rtrim(Comp_list,',');

HTH,
Ales