View previous topic :: View next topic
|
Author |
Message |
ba.appaiah
New User
Joined: 18 Sep 2008 Posts: 3 Location: BANGALORE
|
|
|
|
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 |
|
|
Cary
New User
Joined: 23 Sep 2008 Posts: 3 Location: China
|
|
|
|
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 |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
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 |
|
|
ba.appaiah
New User
Joined: 18 Sep 2008 Posts: 3 Location: BANGALORE
|
|
|
|
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 |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8697 Location: Dubuque, Iowa, USA
|
|
|
|
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 |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
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. . .
Going further, if you had a "shortened value" with the spaces "removed" what would you do with it? |
|
Back to top |
|
|
roopannamdhari Warnings : 1 New User
Joined: 14 Sep 2006 Posts: 71 Location: Bangalore
|
|
|
|
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 |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
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 |
|
|
|