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 spaces in between
Goto page 1, 2  Next
 
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Application Programming
View previous topic :: View next topic  
Author Message
Rahull
Beginner


Joined: 29 Jan 2004
Posts: 62
Topics: 19

PostPosted: Thu Aug 11, 2005 10:25 am    Post subject: Remove spaces in between Reply with quote

Hi,

Can you please tell me how to remove trailing, leaving and in between spaces using inspect or string or unstring command.

Initial input text : " This is a test text ".

Final Output text : "thisisatesttext".

Thanks in advance.
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


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

PostPosted: Thu Aug 11, 2005 10:43 am    Post subject: Reply with quote

Rahull,

Try this


Code:

01 WS-INPUT        PIC X(50) VALUE 'THIS IS A TEST TEXT'.   
01 WS-LENGTH       PIC S9(04) COMP.                         
01 W-TALLY         PIC S9(04) COMP.                         
01 WS-OUTPUT       PIC X(50) VALUE SPACES.                 
01 WS-I-SUB        PIC S9(04) COMP.                         
01 WS-O-SUB        PIC S9(04) COMP VALUE 1.                 
                                                           
PROCEDURE DIVISION.       
                                 
     INSPECT FUNCTION REVERSE(WS-INPUT) TALLYING W-TALLY   
         FOR LEADING SPACES                                 
                                                           
     COMPUTE WS-LENGTH = LENGTH OF WS-INPUT - W-TALLY       
                                                           
     PERFORM VARYING WS-I-SUB FROM 1 BY 1                   
       UNTIL WS-I-SUB > WS-LENGTH                           
                                                           
       IF WS-INPUT ( WS-I-SUB: 1 ) NOT = SPACE             
          MOVE WS-INPUT  ( WS-I-SUB: 1 ) TO                 
               WS-OUTPUT ( WS-O-SUB: 1 )                   
          ADD +1 TO WS-O-SUB                               
       END-IF                                               
     END-PERFORM                                           
                                                           
     DISPLAY WS-OUTPUT                                     

_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Itanium
Beginner


Joined: 14 Aug 2005
Posts: 6
Topics: 1

PostPosted: Sun Aug 14, 2005 1:17 pm    Post subject: Reply with quote

Hi Kolusu,

This was my code i wrote for the same requirement some months ago. Your one was awesome.

Code:
01  WS-WORKING-STORAGE.                                         
    05  WS-WORD-CNT             PIC 9(2) VALUE 0.               
    05  WS-OP-WORD-CNT          PIC 9(2) VALUE 0.               
                                                                 
    05  WS-TABLE.                                               
        10 WS-VAR               PIC X(80).                       
        10 WS-OUTPUT-VAR        PIC X(80).                       
                                                                 
    05  WS-SPACE                PIC X(01) VALUE 'N'.             
        88 WS-SPACE-YES         VALUE 'Y'.                       
        88 WS-SPACE-NO          VALUE 'N'.                       

PROCEDURE DIVISION.                                             
                                                                 
0000-BEGIN.                                                     
                                                                 
    MOVE 'ASDA   SKADJ L  KDJF ASD  DF ASDF AS   SADF  SDF   SDF'
                                       TO WS-VAR.               
                                                                 
    PERFORM 1000-LOOP UNTIL WS-WORD-CNT = 80 .                   
                                                                 
    DISPLAY WS-VAR                                               
    DISPLAY WS-OUTPUT-VAR.                                       
                                                                 
    STOP RUN.                                                   
1000-LOOP.                                               
                                                         
     IF WS-VAR(WS-WORD-CNT:1) = ' ' THEN                 
        SET WS-SPACE-YES TO TRUE                         
     ELSE                                               
        IF WS-SPACE-YES                                 
           MOVE ' '   TO WS-OUTPUT-VAR(WS-OP-WORD-CNT:1)
           ADD  1     TO WS-OP-WORD-CNT                 
           MOVE WS-VAR(WS-WORD-CNT:1) TO                 
                      WS-OUTPUT-VAR(WS-OP-WORD-CNT:1)   
           ADD  1     TO WS-OP-WORD-CNT                 
           SET WS-SPACE-NO  TO TRUE                     
        ELSE                                             
           MOVE WS-VAR(WS-WORD-CNT:1) TO                 
                      WS-OUTPUT-VAR(WS-OP-WORD-CNT:1)   
           ADD  1     TO WS-OP-WORD-CNT                 
        END-IF                                           
     END-IF                                             
     ADD  1     TO WS-WORD-CNT.                         


Thanks,
Smile
Back to top
View user's profile Send private message
ranga_subham
Intermediate


Joined: 31 Jan 2006
Posts: 255
Topics: 72

PostPosted: Fri Mar 24, 2006 1:31 am    Post subject: No utility can achieve it. Reply with quote

Kolusu,

This is very interesting stuff. I believe you can't achieve the same by using a utilities like SORT or FIle-Aid.

Quote:

INSPECT FUNCTION REVERSE(WS-INPUT) TALLYING W-TALLY
FOR LEADING SPACES


Why you had to use REVERSE function on the WS-INPUT?

Earlier
Quote:

'THIS IS A TEST TEXT'


Later
Quote:

'TEXT TEST A IS THIS'


What would be the significance? I haven't understood it really.

Thanks.
_________________
Ranga
*****
None of us is as smart as all of us - Ken Blanchard
Back to top
View user's profile Send private message
Phantom
Data Mgmt Moderator
Data Mgmt Moderator


Joined: 07 Jan 2003
Posts: 1056
Topics: 91
Location: The Blue Planet

PostPosted: Fri Mar 24, 2006 4:37 am    Post subject: Reply with quote

Ranga,

Quote:

What would be the significance? I haven't understood it really.


On an average, in an alphanumeric variable - the number of trailing spaces can be expected to be more than leading spaces - since people normally enter alphanumeric values starting from byte 1.

When the text is smaller compared to the Picture clause length, you would be wasting cpu cycles doing the perform till end of line. And, INSPECT has no way to identify the number of trailing spaces / characters. So, use REVERSE function along with INSPECT to find out the number of trailing spaces and save the number of iterations in perform.

Hope this helps,

Thanks,
Phantom
Back to top
View user's profile Send private message
ranga_subham
Intermediate


Joined: 31 Jan 2006
Posts: 255
Topics: 72

PostPosted: Fri Mar 24, 2006 7:57 am    Post subject: Reply with quote

Well.....Well..........

It is really lots of thought behind the solution. It is a great feeling to be a MEMBER of this forum.

Thanks a zillion.
_________________
Ranga
*****
None of us is as smart as all of us - Ken Blanchard
Back to top
View user's profile Send private message
psmadhusudhan
Beginner


Joined: 28 Nov 2006
Posts: 143
Topics: 48

PostPosted: Tue Mar 31, 2009 8:39 am    Post subject: Reply with quote

Hi,

I had tried the code given by kolusu on following text
"MAKE A DIFFERENCE "

but I am getting output as
"MAKEADIFFERENCE0000010"

numeric values are getting appending at the end of string. The code is exact as shown by kolusu. Can somebody help me getting it correct.
_________________
Thanks
Madhu Sudhan
Back to top
View user's profile Send private message
dbzTHEdinosauer
Supermod


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

PostPosted: Tue Mar 31, 2009 9:17 am    Post subject: Reply with quote

Quote:
The code is exact as shown by kolusu.


Madhu,

suggest you recheck your code.
_________________
Dick Brenholtz
American living in Varel, Germany
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


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

PostPosted: Tue Mar 31, 2009 10:55 am    Post subject: Reply with quote

psmadhusudhan,

I would bet that you have line numbers in pos 72 thru 80 which are also included as part of your input string.

To get rid of them

1. Type NUM OFF on the command prompt and press ENTER
2. Type [code:1:a54964a299]C P'
Back to top
View user's profile Send private message Send e-mail Visit poster's website
psmadhusudhan
Beginner


Joined: 28 Nov 2006
Posts: 143
Topics: 48

PostPosted: Wed Apr 01, 2009 3:52 am    Post subject: Reply with quote

You are right kolusu. Thank you very much. Smile
_________________
Thanks
Madhu Sudhan
Back to top
View user's profile Send private message
arvibala
Beginner


Joined: 12 Feb 2008
Posts: 142
Topics: 67

PostPosted: Tue Apr 21, 2009 1:23 pm    Post subject: Reply with quote

Like Ranga said abt Reverse Function

Quote:

Earlier
Quote:

'THIS IS A TEST TEXT'



Later
Quote:

'TEXT TEST A IS THIS'


Is the output after Reverse True???? It should be like this Correct?

"TXET TSET A SI SIHT"

Cheers,
_________________
Arvind
"You can make a difference with your smile. Have that with you always"
Back to top
View user's profile Send private message Yahoo Messenger
kolusu
Site Admin
Site Admin


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

PostPosted: Tue Apr 21, 2009 1:31 pm    Post subject: Reply with quote

arvibala,

Are u really thinking that the code reverses the text? bonk It Does NOT. Inspect reverse does the scanning from the end of the text to the beginning of the text looking for the non space value. once it finds the non space value it stops.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
arvibala
Beginner


Joined: 12 Feb 2008
Posts: 142
Topics: 67

PostPosted: Tue Apr 21, 2009 2:12 pm    Post subject: Reply with quote

Quote:

Like Ranga said abt Reverse Function


Hi Kolusu,

I was quoting the REVERSE Function, not the Logic of ur code. The Output Ranga gave for the Reverse function was wrong. He gave word by word Reverse of the sentence. I was questioning that.

And the REVERSE FUNCTION reverses the Text and gives as input to the INSPECT, then only it will be able to eliminate the leading spaces.

Thanks,
_________________
Arvind
"You can make a difference with your smile. Have that with you always"
Back to top
View user's profile Send private message Yahoo Messenger
kolusu
Site Admin
Site Admin


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

PostPosted: Tue Apr 21, 2009 2:15 pm    Post subject: Reply with quote

arvibala wrote:
And the REVERSE FUNCTION reverses the Text and gives as input to the INSPECT, then only it will be able to eliminate the leading spaces.

Thanks,


bonk unbelievable
Back to top
View user's profile Send private message Send e-mail Visit poster's website
arvibala
Beginner


Joined: 12 Feb 2008
Posts: 142
Topics: 67

PostPosted: Tue Apr 21, 2009 2:25 pm    Post subject: Reply with quote

Code:

WORKING-STORAGE SECTION.                       
01 NAME                PIC X(50).               

PROCEDURE DIVISION.                             
MAIN-STREET.                                   
    MOVE 'THIS IS ARVIND' TO NAME.             
    DISPLAY 'REVERSE:', FUNCTION REVERSE(NAME).
    STOP RUN.                                   


the output was

Code:

REVERSE:                                    DNIVRA SI SIHT

_________________
Arvind
"You can make a difference with your smile. Have that with you always"
Back to top
View user's profile Send private message Yahoo Messenger
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
Goto page 1, 2  Next
Page 1 of 2

 
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