View previous topic :: View next topic |
Author |
Message |
nk.nithya Beginner
Joined: 28 Dec 2007 Posts: 4 Topics: 2 Location: India
|
Posted: Mon Apr 18, 2011 5:06 am Post subject: remove padded spaces at end in a cobol string |
|
|
Input; Code: | 'abc def ghijk lmnopqur ' |
Output Code: | ' abc def ghijk lmnopqur' |
|
|
Back to top |
|
|
dbzTHEdinosauer Supermod
Joined: 20 Oct 2006 Posts: 1411 Topics: 26 Location: germany
|
Posted: Mon Apr 18, 2011 8:57 am Post subject: |
|
|
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 |
|
|
misi01 Advanced
Joined: 02 Dec 2002 Posts: 629 Topics: 176 Location: Stockholm, Sweden
|
Posted: Tue Apr 26, 2011 1:11 am Post subject: More to the point (?) |
|
|
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 |
|
|
computer Beginner
Joined: 12 Jun 2007 Posts: 64 Topics: 17 Location: Hyderabad
|
Posted: Tue Jun 28, 2011 11:58 am Post subject: |
|
|
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 |
|
|
papadi Supermod
Joined: 20 Oct 2009 Posts: 594 Topics: 1
|
Posted: Tue Jun 28, 2011 1:02 pm Post subject: |
|
|
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 |
|
|
Anuj Dhawan Intermediate
Joined: 19 Jul 2007 Posts: 298 Topics: 7 Location: Mumbai,India
|
Posted: Mon Jul 04, 2011 10:28 am Post subject: |
|
|
What exactly the question is here? _________________ Regards,
Anuj |
|
Back to top |
|
|
kolusu Site Admin
Joined: 26 Nov 2002 Posts: 12375 Topics: 75 Location: San Jose
|
Posted: Mon Jul 04, 2011 10:32 am Post subject: |
|
|
Folks please look at the date on which the topic is opened.
thanks
Kolusu |
|
Back to top |
|
|
papadi Supermod
Joined: 20 Oct 2009 Posts: 594 Topics: 1
|
Posted: Mon Jul 04, 2011 1:50 pm Post subject: |
|
|
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 |
|
|
kolusu Site Admin
Joined: 26 Nov 2002 Posts: 12375 Topics: 75 Location: San Jose
|
Posted: Mon Jul 04, 2011 3:53 pm Post subject: |
|
|
Papadi,
I did not mean your posts. Clutter posts should be avoided.
Kolusu |
|
Back to top |
|
|
nk.nithya Beginner
Joined: 28 Dec 2007 Posts: 4 Topics: 2 Location: India
|
Posted: Wed Jul 27, 2011 6:43 am Post subject: |
|
|
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 |
|
Back to top |
|
|
kolusu Site Admin
Joined: 26 Nov 2002 Posts: 12375 Topics: 75 Location: San Jose
|
Posted: Wed Jul 27, 2011 10:17 am Post subject: |
|
|
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 |
|
|
papadi Supermod
Joined: 20 Oct 2009 Posts: 594 Topics: 1
|
Posted: Wed Jul 27, 2011 11:41 am Post subject: |
|
|
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 |
|
|
seagull Beginner
Joined: 13 Sep 2006 Posts: 5 Topics: 0
|
Posted: Wed Aug 10, 2011 5:05 am Post subject: |
|
|
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 |
|
|
|
|