ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

Inspect for traling spaces

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Inspect for traling spaces

    Hi ,

    is ther any function to get the trailing spaces in the cobol..
    i tried with inspect reverse but the reverse functionality is not supported with my version .. pls let me know is ther any other functionality for this
    thanks ..

  • #2
    Re: Inspect for traling spaces

    Your post is not clear.

    What do you mean by "get" the trailing spaces? Do you want to trim them, count the number of spaces...or what are you trying to accomplish?

    To trim, you can use the FUNCTION TRIM().

    Comment


    • #3
      Re: Inspect for traling spaces

      hi terry ,

      thanks for ur reply ..

      i want to replace the trailing spaces alone with some other character
      frg ws-variable = 'as 213 ' to 'as 213%% '

      ( i want to do it in cobol/400)

      thanks
      vinoth
      Last edited by vinothkumar; May 26, 2009, 07:03 AM.

      Comment


      • #4
        Re: Inspect for traling spaces

        If your restricted to non-ILE Cobol, then the best method is to move your string to an array, then process the array backwards and replace each space with a the new value.

        You just have to remember to terminate your process as soon as you encounter your first non-space character. Here is a simple example:
        Code:
        working-storage section.                                       
        01  ws-variable            pic  x(12)     value 'as 123     '. 
        01  ws-len                 pic s9(03)     value +0.            
        
        move length of ws-variable to ws-len 
                                             
        perform until ws-len < 1               
        or ws-variable (ws-len:1) not = space  
            move '%' to ws-variable (ws-len:1) 
            subtract 1 from ws-len             
        end-perform
        Last edited by Terry Wincheste; May 26, 2009, 09:13 AM.

        Comment

        Working...
        X