by Robert Sample » Fri Aug 06, 2010 11:27 pm
First, be aware that COBOL -- unlike C or similar languages -- does not have the concept of "string". A COBOL variable defined in WORKING-STORAGE as PIC X(10) will always contain 10 bytes -- never more, never less.
Second, you did not mention which COBOL compiler you are using -- VS COBOL II, for example, does not have some of the functionality of Enterprise COBOL for MVS & VM and the solution varies slightly by compiler.
Assuming you're using a reasonably recent COBOL compiler (always a dangerous assumption), you can either (1) use reference modification from byte 10 to 1 looking for the first non-blank character, or (2) use FUNCTION REVERSE on the variable and INSPECT tallying leading spaces, then subtract the tally count from 10.
A method that would work for all versions of COBOL would be to redefine the variable as a 10-byte array and look at each byte from 10 to 1 to find the first non-blank character.