Page 1 of 1

How to truncate trailing spaces in a string?

PostPosted: Wed Feb 08, 2012 7:02 pm
by skankatala
Is there any function which removes trailing spaces in a String in cobol?

Is there any direct function like TRIM in other languages?

Re: How to truncate trailing spaces in a string?

PostPosted: Wed Feb 08, 2012 7:07 pm
by BillyBoyo
What do you want to do with it when you've got rid of the spaces?

Re: How to truncate trailing spaces in a string?

PostPosted: Wed Feb 08, 2012 7:42 pm
by NicC
Look at it like this - say your variable is X(10) and the contents are 3 bytes long if you strip the trailing 7 spaces your variable is still 10 bytes long. So the question is - what character do you want to replace those 7 spaces with?

Re: How to truncate trailing spaces in a string?

PostPosted: Wed Feb 08, 2012 9:32 pm
by Robert Sample
Technically, COBOL does not have strings in the sense of other languages, where the length can vary at run time. In COBOL, every variable in WORKING-STORAGE has its length set at compile time, and that length does not change during the program execution. Even variables defined with OCCURS DEPENDING ON have the maximum length allocated in WORKING-STORAGE at compile time, so there's something in every one of those memory locations even if the length is less than the maximum.