select ename,eno,esal,edept from emp where edept='d001'
There is a LENGTH function in COBOL, but it will not be helpful in solving your problem. All LENGTH will do is return the maximum size of a character string -- and you should already know that.
The problem boils down to one of parsing and counting based on your particular parameters. For example, in the SQL your provided above, the answer I'm expecting you want to receive is 55, because that is the total number of characters starting with the "s" in select and ending with the closing single quotation. So you could write your own counting routine that just counts the characters until two spaces are found in succession. Of course, that might not work for you because you can write your SQL statement many different ways, including with many embedded spaces. For example:
select ename, eno, esal, edept from emp where edept='d001'
I put a space after each comma, but also an extra space after "edept" but before the "from" clause. I am guessing that you would want the function to return 59 in this case, but if you just counted until reaching two spaces you'd get 30 -- definitely the wrong answer.
I suppose you could code a routine to count backward through the text string and stop as soon as you get a non-space. Then you'd add one (for the non-space) and subtract the number from the maximum length.
Otherwise, unless you can put some rules around the SQL you are formulating, I don't know of a reasonable way to go about this task.