Removing Blanks with COBOL

benidrar -  
blux Posted messages 5044 Registration date   Status Moderator Last intervention   -
Hello

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

Thank you.

7 answers

  1. blux Posted messages 5044 Registration date   Status Moderator Last intervention   3 455
     
    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
  2. 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
  3. blux Posted messages 5044 Registration date   Status Moderator Last intervention   3 455
     
    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
  4. 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
    1. blux Posted messages 5044 Registration date   Status Moderator Last intervention   3 455
       
      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
  5. KAIDI
     
    do you need to remove all spaces or not?
    'DE SEVRES" should it become "DESEVRES"?
    0
    1. blux Posted messages 5044 Registration date   Status Moderator Last intervention   3 455
       
      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
  6. 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
  7. benidrar
     
    Hello,

    thank you all for your very precious help!
    0
    1. claudius51 Posted messages 1 Status Member
       
      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
      1. blux Posted messages 5044 Registration date   Status Moderator Last intervention   3 455 > claudius51 Posted messages 1 Status Member
         
        It's been 3 years since the problem was solved...

        --

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