IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

How to remove trailing spaces in a variable


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
ba.appaiah

New User


Joined: 18 Sep 2008
Posts: 3
Location: BANGALORE

PostPosted: Wed Sep 24, 2008 1:59 pm
Reply with quote

Hi,

I Have a variable of X(40) . When a pass a value to this variable it is not necessary that i have to pass a variable of length 40. So there will be trailing spaces. How do i remove these space?
Back to top
View user's profile Send private message
Cary

New User


Joined: 23 Sep 2008
Posts: 3
Location: China

PostPosted: Thu Sep 25, 2008 10:04 am
Reply with quote

May be not need move a value 0f 40 length.Check your data attribuate.

or cut the value to your need.

xx pic x(40)
yy pic x(10)
yy = xx(1:10)
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


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

PostPosted: Thu Sep 25, 2008 10:25 am
Reply with quote

Hello,

Quote:
How do i remove these space?
You don't. If you have a pic x(40) variable, it will take 40 bytes. If 10 bytes are "data" and the other 30 are spaces, there is no "removal".

If you explain what you really want to do (removing spaces is not the goal, only a means to it), someone may be able to offer suggestions.
Back to top
View user's profile Send private message
ba.appaiah

New User


Joined: 18 Sep 2008
Posts: 3
Location: BANGALORE

PostPosted: Mon Oct 06, 2008 7:00 pm
Reply with quote

Hi,
Quote:
How do i remove these space?

The value that will be populated in to the X(40) variable is unknown. So i have to determine where the value ends.

The value could just be "HI" or "HI HOW ARE YOU".

The aim is to remove the spaces that follows at the end of the value.
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8697
Location: Dubuque, Iowa, USA

PostPosted: Mon Oct 06, 2008 7:07 pm
Reply with quote

A COBOL variable is fixed length. If the value is HI it is followed by 38 spaces; if it is HI HOW ARE YOU then it is followed by 26 spaces. If you want to know where the last non-space character is, start at the end of the variable and look for a non-space character one by one. You can replace the trailing spaces by some other character, but you're always, always, always going to have 40 characters in the variable. COBOL is not like C where variables can have different lengths.
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


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

PostPosted: Tue Oct 07, 2008 12:18 am
Reply with quote

Hello,

To repeat. . . .
Quote:
If you explain what you really want to do (removing spaces is not the goal, only a means to it), someone may be able to offer suggestions.
If you cannot or will not explain what you are trying to do, no one can help you. . . icon_sad.gif

Going further, if you had a "shortened value" with the spaces "removed" what would you do with it?
Back to top
View user's profile Send private message
roopannamdhari
Warnings : 1

New User


Joined: 14 Sep 2006
Posts: 71
Location: Bangalore

PostPosted: Tue Oct 07, 2008 10:46 am
Reply with quote

Hi,
The method Robert has suggested will work fine to find out actual length of data in a variable. Here is the logic

Perform varying I from 40 by -1 until I = 0 or var1 (I: 1) not equal spaces
End-perform

If var1 is having value "HI" I will returns 2
If var1 is having value "HI how are you" I will returns 14

here you get actual length of data in variable var1

Thanks,
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


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

PostPosted: Tue Oct 07, 2008 7:51 pm
Reply with quote

Hello,

How does that remove the "unwanted" spaces?

When posting a reply, it is best to make sure the answer relates to the posted question.

We are still waiting for clarification from ba.appaiah.

You may have guessed at something that will help ba.appaiah. More important is that people learn how to ask their question so the forum can help them. The people who ask their questions well tend to receive more usable answers and they receive them more quickly.
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts Extracting Variable decimal numbers f... DFSORT/ICETOOL 17
No new posts Sortjoin and Search for a String and ... DFSORT/ICETOOL 1
No new posts Remove leading zeroes SYNCSORT 4
No new posts leading spaces can be removed in trai... DFSORT/ICETOOL 1
No new posts Variable Output file name DFSORT/ICETOOL 8
Search our Forums:

Back to Top