MVSFORUMS.com Forum Index MVSFORUMS.com
A Community of and for MVS Professionals
 
 FAQFAQ   SearchSearch   Quick Manuals   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

remove padded spaces at end in a cobol string

 
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Application Programming
View previous topic :: View next topic  
Author Message
nk.nithya
Beginner


Joined: 28 Dec 2007
Posts: 4
Topics: 2
Location: India

PostPosted: Mon Apr 18, 2011 5:06 am    Post subject: remove padded spaces at end in a cobol string Reply with quote

Input;
Code:
'abc def ghijk lmnopqur                    '

Output
Code:
' abc def ghijk lmnopqur'
Back to top
View user's profile Send private message Send e-mail
dbzTHEdinosauer
Supermod


Joined: 20 Oct 2006
Posts: 1411
Topics: 26
Location: germany

PostPosted: Mon Apr 18, 2011 8:57 am    Post subject: Reply with quote

cobol does not have varibale length strings........RTFM

Depending upon your destination field, you can move with reference-modification,
truncate with STRING Delimited by - though here you have to have a unique delimiter:
  • replace the last space with something unique for string delimited by
  • if you know that you will always have 2 spaces only at the end, you can use delimited by ' '.


INSPECT (REVERS(your-field)) TALLYING SPACE-CTR FOR LEADING SPACES will tell you how many trailing spaces you have.
the LENGTH(your-field) - SPACES-CTR = number of characters to move.
_________________
Dick Brenholtz
American living in Varel, Germany
Back to top
View user's profile Send private message
misi01
Advanced


Joined: 02 Dec 2002
Posts: 629
Topics: 176
Location: Stockholm, Sweden

PostPosted: Tue Apr 26, 2011 1:11 am    Post subject: More to the point (?) Reply with quote

why do you need to remove trailing spaces ???

If your input string is defined as x(30) with 12 trailing spaces, moving it to a field defined as x(18 ) will remove all trailing spaces, so again, why do you need to remove them ????
Back to top
View user's profile Send private message Send e-mail
computer
Beginner


Joined: 12 Jun 2007
Posts: 64
Topics: 17
Location: Hyderabad

PostPosted: Tue Jun 28, 2011 11:58 am    Post subject: Reply with quote

Hi nk.nithya,

A simple perform will do. Need to decalre a table variable with picture clause one. And start reading from reverse and capture data from first non-space character till you reach to the starting position.

Hope this helps....
Back to top
View user's profile Send private message
papadi
Supermod


Joined: 20 Oct 2009
Posts: 594
Topics: 1

PostPosted: Tue Jun 28, 2011 1:02 pm    Post subject: Reply with quote

There is no need for a perform. . .

There is actually no reason to do anything. The original post makes no sense. . .

The data is the data and is stored as it is stored. . . It is not a string with trailing blanks. It is not a string at all. . . COBOL has no way to "shorten" the value.
_________________
All the best,

di
Back to top
View user's profile Send private message
Anuj Dhawan
Intermediate


Joined: 19 Jul 2007
Posts: 298
Topics: 7
Location: Mumbai,India

PostPosted: Mon Jul 04, 2011 10:28 am    Post subject: Reply with quote

What exactly the question is here?
_________________
Regards,
Anuj
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12375
Topics: 75
Location: San Jose

PostPosted: Mon Jul 04, 2011 10:32 am    Post subject: Reply with quote

Folks please look at the date on which the topic is opened.

thanks

Kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
papadi
Supermod


Joined: 20 Oct 2009
Posts: 594
Topics: 1

PostPosted: Mon Jul 04, 2011 1:50 pm    Post subject: Reply with quote

Hi Kolusu,

My reply was to the post from "computer" - not the topic in general. Would you prefer we did not reply to such "clutter posts" pointing out that they provide no value and may even more confuse the less experienced?

di
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12375
Topics: 75
Location: San Jose

PostPosted: Mon Jul 04, 2011 3:53 pm    Post subject: Reply with quote

Papadi,

I did not mean your posts. Clutter posts should be avoided.


Kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
nk.nithya
Beginner


Joined: 28 Dec 2007
Posts: 4
Topics: 2
Location: India

PostPosted: Wed Jul 27, 2011 6:43 am    Post subject: Reply with quote

Hi All,

Please tell me whether it coud be possible or not......
Do not comment on the Post..
Code:

MOVE 0                        TO WS-A     
INSPECT FUNCTION REVERSE(WS-NAME) TALLYING
        WS-A FOR LEADING SPACES.           
DISPLAY 'NAME2:' WS-NAME WS-NAM.           
DISPLAY 'A :' WS-A.                       
PERFORM VARYING WS-A FROM 10 BY -1         
  UNTIL WS-NAME(WS-A:1) NOT = SPACE       
END-PERFORM.                               
MOVE WS-NAME(1:WS-A) TO WS-NAM1(1:WS-A).   

Declared the variable WS-NAME as X(10).
This is mainly for the purpose, when you export it into excel, blank spaces looks like Junk characters. In order to avoid that we need to remove all the padded blanks at the end.


Thanks,
Nk.Nithya Smile
Back to top
View user's profile Send private message Send e-mail
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12375
Topics: 75
Location: San Jose

PostPosted: Wed Jul 27, 2011 10:17 am    Post subject: Reply with quote

nk.nithya wrote:
Hi All,

Please tell me whether it coud be possible or not......
Do not comment on the Post..


nk.nithya,

You are not going too far with this attitude. You need to understand that there is nothing to create a dynamic variable string in COBOL. Since you are always creating a 10 byte field what happens if you have the following input?
Code:


----+----1----+----2----+----3----+----4-
AAAAAAAAAA    - 10 CHARACTERS NO SPACES 
AAAAAAAAA     - 09 CHARACTERS 01 SPACES 
AAAAAAAA      - 08 CHARACTERS 02 SPACES 
AAAAAAA       - 07 CHARACTERS 03 SPACES 
AAAAAA        - 06 CHARACTERS 04 SPACES 
AAAAA         - 05 CHARACTERS 05 SPACES 
AAAA          - 04 CHARACTERS 06 SPACES 
AAA           - 03 CHARACTERS 07 SPACES 
AA            - 02 CHARACTERS 08 SPACES 
A             - 01 CHARACTERS 09 SPACES 


So you need to understand that no matter what you do you will still have spaces at the end for character data.

If your primary aim is to create an excel file then create the file with delimited (tab, ; ...) and then you will have truly variable data.
_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
papadi
Supermod


Joined: 20 Oct 2009
Posts: 594
Topics: 1

PostPosted: Wed Jul 27, 2011 11:41 am    Post subject: Reply with quote

Quote:

This is mainly for the purpose, when you export it into excel, blank spaces looks like Junk characters.
Not on any of the thousands of downloaded files we've used. . .

It you have found a way to corrupt spaces to "junk" it is (nearly guaranteed) an error with the process.

If you really believe this has happened automagically, post some of of the mainframe data (in hex) and the data received (again in hex) on the target system).
_________________
All the best,

di
Back to top
View user's profile Send private message
seagull
Beginner


Joined: 13 Sep 2006
Posts: 5
Topics: 0

PostPosted: Wed Aug 10, 2011 5:05 am    Post subject: Reply with quote

Are you sure it's spaces being transalated to junk? Spaces don't normally present any problems with export to excel. Could it be low-values?
_________________
"Programming today is a race between software engineers striving to build bigger and better idiot- proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning."
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Application Programming All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


MVSFORUMS
Powered by phpBB © 2001, 2005 phpBB Group