How to truncate trailing spaces in a string?



Support for OS/VS COBOL, VS COBOL II, COBOL for OS/390 & VM and Enterprise COBOL for z/OS

How to truncate trailing spaces in a string?

Postby skankatala » Wed Feb 08, 2012 7:02 pm

Is there any function which removes trailing spaces in a String in cobol?

Is there any direct function like TRIM in other languages?
skankatala
 
Posts: 42
Joined: Sun Dec 11, 2011 9:45 am
Location: Hyderabad
Has thanked: 0 time
Been thanked: 0 time

Re: How to truncate trailing spaces in a string?

 

Re: How to truncate trailing spaces in a string?

Postby BillyBoyo » Wed Feb 08, 2012 7:07 pm

What do you want to do with it when you've got rid of the spaces?
BillyBoyo
Global moderator
 
Posts: 3804
Joined: Tue Jan 25, 2011 12:02 am
Has thanked: 22 times
Been thanked: 264 times

Re: How to truncate trailing spaces in a string?

Postby NicC » Wed Feb 08, 2012 7:42 pm

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?
The problem I have is that people can explain things quickly but I can only comprehend slowly.
Regards
Nic
NicC
Global moderator
 
Posts: 2690
Joined: Sun Jul 04, 2010 12:13 am
Location: Pushing up the daisys (almost)
Has thanked: 4 times
Been thanked: 105 times

Re: How to truncate trailing spaces in a string?

Postby Robert Sample » Wed Feb 08, 2012 9:32 pm

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.
Robert Sample
Global moderator
 
Posts: 3367
Joined: Sat Dec 19, 2009 8:32 pm
Location: East Dubuque, Illinois
Has thanked: 1 time
Been thanked: 222 times


Return to IBM Cobol

 


  • Related topics
    Replies
    Views
    Last post