Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

Remove trailing spaces.

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
View previous topic :: :: View next topic  
Author Message
passion_sujesh

New User


Joined: 14 Mar 2008
Posts: 74
Location: India,Chennai

PostPosted: Fri Sep 05, 2008 5:35 pm    Post subject: Remove trailing spaces.
Reply with quote

Hi All,
I have a requirement in which i have to remove all the trailing spaces from an variable. Can any one provide me a solution on how this can be acheived.
Example:
Consider the value to be 'abcd efgh ' the output should be 'abcd efgh'. All the spaces in the trailer should be removed.
Back to top
View user's profile Send private message

Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 7993
Location: Bellevue, IA

PostPosted: Fri Sep 05, 2008 6:20 pm    Post subject:
Reply with quote

Uh ... you do know that COBOL variables are fixed length, right? Just exactly what do you want to replace the space with? You've got to replace it with another character -- LOW-VALUES, HIGH-VALUES, printable character, non-printing character.
Back to top
View user's profile Send private message
ssk1711

New User


Joined: 16 Jun 2008
Posts: 40
Location: bangalore

PostPosted: Fri Sep 05, 2008 6:25 pm    Post subject:
Reply with quote

Hi

I think you can use VARCHAR.

Please specify exact requirement, with an example.
Back to top
View user's profile Send private message
Craq Giegerich

Senior Member


Joined: 19 May 2007
Posts: 1512
Location: Virginia, USA

PostPosted: Fri Sep 05, 2008 6:35 pm    Post subject:
Reply with quote

ssk1711 wrote:
Hi

I think you can use VARCHAR.

Please specify exact requirement, with an example.


VARCHAR in COBOL?
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 7993
Location: Bellevue, IA

PostPosted: Fri Sep 05, 2008 6:36 pm    Post subject:
Reply with quote

Look in the COBOL Language Reference and you will not find any mention of VARCHAR, which is a database field type. VARCHAR fields in DB2 become fixed-length COBOL variables when the data is moved.
Back to top
View user's profile Send private message
Bill O'Boyle

CICS Moderator


Joined: 14 Jan 2008
Posts: 2502
Location: Atlanta, Georgia, USA

PostPosted: Fri Sep 05, 2008 7:41 pm    Post subject:
Reply with quote

Proceed backwards until you find the first position which is greater than space -

Code:

           03  WS-STRING           PIC  X(256).                           
           03  WS-SUB              PIC S9(008)     BINARY.               
      *                                                                   
           MOVE 'ABCD EFH'             TO WS-STRING.                     
           MOVE LENGTH OF WS-STRING    TO TALLY.                         
           MOVE ZERO                   TO WS-SUB.                         
      *                                                                   
           PERFORM UNTIL TALLY < 1                                       
               IF  WS-STRING (TALLY:1) > SPACE                           
                   MOVE TALLY          TO WS-SUB                         
                   MOVE ZERO           TO TALLY                           
               ELSE                                                       
                   SUBTRACT 1          FROM TALLY                         
               END-IF                                                     
           END-PERFORM.                                                   

After falling thru from the PERFORM, if WS-SUB is non-zero (in this case, 08), then this is the length of the string, before the start of trailing spaces.

Optionally, INSPECT FUNCTION REVERSE can also be used, but that's up to you and requires at a minimum, COBOL/370.

Bill
Back to top
View user's profile Send private message
ashimer

Active Member


Joined: 13 Feb 2004
Posts: 551
Location: Bangalore

PostPosted: Fri Sep 05, 2008 9:05 pm    Post subject:
Reply with quote

You will extract the data and again will put in a variable of length 256 only right ? so what abt the places after the data ? it will again be spaces ..

As Robert asked the trailing spaces needs to be replaced by what ?
Back to top
View user's profile Send private message
Bill O'Boyle

CICS Moderator


Joined: 14 Jan 2008
Posts: 2502
Location: Atlanta, Georgia, USA

PostPosted: Fri Sep 05, 2008 9:11 pm    Post subject: Re: Remove trailing spaces
Reply with quote

Review this recent post -

http://ibmmainframes.com/viewtopic.php?t=32610

Bill
Back to top
View user's profile Send private message
ashimer

Active Member


Joined: 13 Feb 2004
Posts: 551
Location: Bangalore

PostPosted: Fri Sep 05, 2008 10:07 pm    Post subject:
Reply with quote

I guess the referred post serves another purpose.

You have a variable X(5) with value 'BILL '. You strip BILL and will have to put that into another variable X(5). Now the value is again 'BILL ' i.e. BILL followed by one space. You cannot just have only 'BILL' as there is no concept of varying char in COBOL so as to fit the data correctly depending on the lenght ...

If the OP wants the trailing spaces to be removed for some kind of checking or whtever the spaces needs to be removed by something else ...

As mentioned you can use PERFORM of REVERSE function to find the trailing spaces and then use MOVE or reference modification to convert the spaces to something else ...
Back to top
View user's profile Send private message
dick scherrer

Site Director


Joined: 23 Nov 2006
Posts: 19270
Location: Inside the Matrix

PostPosted: Sat Sep 06, 2008 5:08 am    Post subject:
Reply with quote

Hello,

Quote:
I have a requirement in which i have to remove all the trailing spaces from an variable.
Where did this requirement originate?

How will the "field" (after the spaces are removed) be used? Is this data to be downloaded?

Might the requirement also include creating a delimited file for download? If the goal is a delimited file, the spaces can be removed and the next delimiter can be placed immediately after the last meaningful byte in the trailing-spaces-removed field(s).
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts Count Trailing Spaces in variable str... Virendra Shambharkar SYNCSORT 10 Thu Feb 02, 2017 12:23 pm
No new posts Remove junk values in a file and rite... KP1125 DFSORT/ICETOOL 2 Wed Jan 25, 2017 9:58 pm
No new posts Sort Card to Remove Duplicate records... raj4neo SYNCSORT 2 Wed Jan 25, 2017 4:44 am
No new posts To trim spaces in a pipe delimited da... Nish84 COBOL Programming 16 Mon Oct 10, 2016 1:54 pm
No new posts Removing Extra Spaces in a comma sepa... Puspojit DFSORT/ICETOOL 3 Tue Sep 13, 2016 7:46 am


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us