Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Profile Log in to check your private messages Log in
 
How to remove trailing spaces in a variable

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
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    Post subject: How to remove trailing spaces in a variable
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    Post subject:
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

Site Director


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

PostPosted: Thu Sep 25, 2008 10:25 am    Post subject:
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    Post subject:
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: 8165
Location: East Dubuque, Illinois, USA

PostPosted: Mon Oct 06, 2008 7:07 pm    Post subject:
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

Site Director


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

PostPosted: Tue Oct 07, 2008 12:18 am    Post subject:
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    Post subject: Reply to: How to remove trailing spaces in a variable
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

Site Director


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

PostPosted: Tue Oct 07, 2008 7:51 pm    Post subject:
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    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 Moving values to a variable of copybo... Vignesh Sid COBOL Programming 6 Wed Sep 06, 2017 1:04 pm
No new posts Remove leading spaces from numeric field rexx77 SYNCSORT 6 Wed Sep 06, 2017 2:15 am
No new posts Updating the Trailer count in variabl... satheshbabur DFSORT/ICETOOL 6 Wed Aug 30, 2017 9:49 pm
No new posts Move from Comp3 variable to Edited Va... sreekusr COBOL Programming 8 Thu Aug 10, 2017 4:20 pm
No new posts Can I traverse a STEM variable? chong.zhou CLIST & REXX 5 Wed May 31, 2017 3:54 pm

Facebook
Back to Top
 
Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us