>Fred got as close as you're going to get. With the new session object, there is no way to tell how many datasessions are open without testing all numbers within reason. If you are sure that you have not used the session object, you can spin through _SCREEN.Forms testing for private datasessions.
I haven't tried it, but why not something like:
pnDS = MAXDS
for x = 1 to MAXDS
set datasession to &x
if set('datasession') <> x
pnDS = pnDS - 1
endif
endfor
?pnDS