I have to find the length of a string. Lets say the variable is defined as
01 WS-EMP-NAME PIC X(20).
Now this employee name may have a name as small as "DEEPAK"
so if I find the length of this variable using
COMPUTE LENGTH OF WS-EMP-NAME
then I would get the length as 20, while I am looking for the
exact length of item contained in the variable i.e 6 as in this case
Regards
Deepak
"; ; ; ;
Various ways of doing this not sure which would be more efficient, it may depend on the average lenght of the string and the rules around how you want to split it up.
Simplest method:
01 i pic s9(4) comp.
perform varying i from +20 by -1 until Ws-emp-name(i:1) not = space end-perform
or string ws-emp-name delimited by space into ws-work-space pointer ws-emp-name-length end-string
not sure of the exact syntax of the string command please look at the cobol manual. but the ws-emp-name-length will be the string length +1.
use the iuspect statement:
01 ws-emp-name-length pic s9(4) comp.
move 0 to ws-emp-name-length
inspect ws-emp-name tallying ws-emp-name-length before initial ' '