I have a problem where I am trying to get the length of a variable data string. Basically it is a group of fields but not a copybook and I need to calculate the length with out doing a perform and calculating byte by byte.
Joined: 23 Feb 2006 Posts: 305 Location: Hyderabad,India
hi LlewellynNaicker,
If you are not sure...abt the lenght of the variable withut trailing spaces,
here is a method...you can follow.
1. Reverse the String
2. Search for the non space charecter from the begining of the reversed string. Get the No of trailing Spaces
3. Subtract the number of spaces from the lenght of the variable with spaces.
I have a problem where I am trying to get the length of a variable data string. Basically it is a group of fields but not a copybook and I need to calculate the length with out doing a perform and calculating byte by byte.
Can anyone give me an easier way to do it.
Your help is much appreciated.
Regards
Llewellyn Naicker
hi,
do like this
01 STR1 PIC X(80).
01 LEN PIC 99.
PROCEDURE DIVISION.
PERFORM VARYING I FROM 80 BY -1 UNTIL STR1(I:1) > SPACES
END-PERFORM.