I'm sorry..I didn't read your post completely..
If you do not know the length of the string then you can't use the above solution.
But what do you mean by the length is unknown? There would be a maximum length for this string ,right?
So I assume you have a variable that has been defined to hold the largest string (say PIC X(80)).
INSPECT FUNCTION REVERSE(WS-STRING-1) TALLYING WS-TALLY
FOR LEADING SPACES
COMPUTE WS-LEN = LENGTH OF WS-STRING-1 - WS-TALLY
MOVE FUNCTION REVERSE(WS-STRING-1(1: WS-LEN)) TO
DISPLAY 'REVER STRING:' WS-REVER-STRING
The first Reverse function is used to find out the exact length of the string. For finding out the trailing spaces in the string (since the strings can be of variable length,as you mentioned in your initial post), I used reverse with leading spaces.
If your string is having trailing spaces
01 WS-STRING-1 PIC X(10) VALUE 'ABCD'.
After the reverse function the string will be
$$$$$$DCBA.($ - Represents spaces). So we need to remove these spaces from the string before reversing it.
Instead of the above one will the follwoing wil work??
MOVE WS-STRING-1(WS-TALL: WS-LEN)) TO
What is WS-TALL?. I guess its a typo. If you are meaning WS-TALLY
,just wondering how you are going to populate the value for WS-TALLY