Removing Blanks with COBOL

benidrar -  
blux Posted messages 2017 Registration date   Status Modérateur Last intervention   -
Hello

How to remove trailing spaces in a string with COBOL
for example 'abcd ' would become 'abcd'

Thank you.

7 réponses

blux Posted messages 2017 Registration date   Status Modérateur Last intervention   3 452
 
Hi,

UNSTRING ... DELIMITED BY ALL SPACES INTO ...

That should work...

See you, Blux
 "The idiots dare everything. It's even how we recognize them." 
1
benidrar
 
Thank you, I tried
but apparently it doesn't work!
There are still whitespaces
that I want to only eliminate the whitespaces on the right
for example:
'DE SEVRES '
do not delete the space between 'de' and 'sevres'
See you later
0
blux Posted messages 2017 Registration date   Status Modérateur Last intervention   3 452
 
Ok, so in this case, the only solution is to redefine your input area as a table:

05 toto occurs 200.
10 str pic x.

move tavariable to toto.

And then you make a loop that decrements i from 200 to 1 and you test x(i) until x(i) is different from space. As soon as your condition is true, you copy the rest into another variable (with 'string').

--
See you Blux
 "The fools, they dare to do anything. It's even how you recognize them"
0
KAIDI
 
Hello
If at first, you don't know where to put the spaces, it seems difficult!
'DE SEVRES " How can you know that you need to leave a space between DE and
SEVRES???
Once this issue is determined, the rest is solved...
KAIDI
0
blux Posted messages 2017 Registration date   Status Modérateur Last intervention   3 452
 
Euh well yes, he said 'remove the whites on the right'... ;-)

--
See you Blux
 "Stupid people, they dare everything. That's even how you recognize them"
0
KAIDI
 
do you need to remove all spaces or not?
'DE SEVRES" should it become "DESEVRES"?
0
blux Posted messages 2017 Registration date   Status Modérateur Last intervention   3 452
 
No, he only wants to remove the spaces on the right...

--
A+ Blux
 "Stupid people dare to do anything. It's precisely how we recognize them"
0
KAIDI
 
He can only do it if he knows in advance the words (or the lengths) from which he has to remove the spaces!!
0
benidrar
 
Hello,

thank you all for your very precious help!
0
claudius51 Posted messages 1 Status Membre
 
hello

I think we need to use an occurs and test the value character by character

but do not perform the delete if val (I) = spaces and val (i + 1) not = spaces

best regards
0
blux Posted messages 2017 Registration date   Status Modérateur Last intervention   3 452 > claudius51 Posted messages 1 Status Membre
 
It's been 3 years since the problem was solved...

--

See you, Blux
 "Fools dare everything. It's even how we recognize them"
0