Karthick,
What do you mean by leangth? If you mean length of a string as the number of characters excluding spaces and NULL, then use the below program.
As such there is NO function in COBOL to find the length of a variable. (As per the above definition).
WORKING-STORAGE SECTION.
77 STRING-1 PIC X(50) VALUE 'arunprasad.k '.
77 INDEX-FOR-LOOP PIC 9(02).
77 LENGTH-OF-STRING-1 PIC 9(02) VALUE ZEROES.
PROCEDURE DIVISION.
MOVE LENGTH OF STRING-1 TO INDEX-FOR-LOOP.
PERFORM UNTIL INDEX-FOR-LOOP = ZEROES
IF NOT (STRING-1(INDEX-FOR-LOOP:1) = SPACES OR LOW-VALUES)
ADD 1 TO LENGTH-OF-STRING-1
END-IF
COMPUTE INDEX-FOR-LOOP = (INDEX-FOR-LOOP - 1) END-COMPUTE
END-PERFORM.
DISPLAY ' Length of STRING-1 : ' LENGTH-OF-STRING-1.
GOBACK.
Let me know if you have any questions.
Arun.