| View previous topic :: View next topic | 
	
	
		| Author | Message | 
	
		| Rahull Beginner
 
  
 Joined: 29 Jan 2004
 Posts: 62
 Topics: 19
 
 
 | 
			
				|  Posted: Thu Aug 11, 2005 10:25 am    Post subject: Remove spaces in between |   |  
				| 
 |  
				| 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 |  | 
	
		|  | 
	
		| kolusu Site Admin
 
  
 
 Joined: 26 Nov 2002
 Posts: 12394
 Topics: 75
 Location: San Jose
 
 | 
			
				|  Posted: Thu Aug 11, 2005 10:43 am    Post subject: |   |  
				| 
 |  
				| 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 |  | 
	
		|  | 
	
		| Itanium Beginner
 
  
 Joined: 14 Aug 2005
 Posts: 6
 Topics: 1
 
 
 | 
			
				|  Posted: Sun Aug 14, 2005 1:17 pm    Post subject: |   |  
				| 
 |  
				| 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,
 
  |  | 
	
		| Back to top |  | 
	
		|  | 
	
		| ranga_subham Intermediate
 
  
 Joined: 31 Jan 2006
 Posts: 255
 Topics: 72
 
 
 | 
			
				|  Posted: Fri Mar 24, 2006 1:31 am    Post subject: No utility can achieve it. |   |  
				| 
 |  
				| 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 |  | 
	
		|  | 
	
		| Phantom Data Mgmt Moderator
 
  
 
 Joined: 07 Jan 2003
 Posts: 1056
 Topics: 91
 Location: The Blue Planet
 
 | 
			
				|  Posted: Fri Mar 24, 2006 4:37 am    Post subject: |   |  
				| 
 |  
				| 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 |  | 
	
		|  | 
	
		| ranga_subham Intermediate
 
  
 Joined: 31 Jan 2006
 Posts: 255
 Topics: 72
 
 
 | 
			
				|  Posted: Fri Mar 24, 2006 7:57 am    Post subject: |   |  
				| 
 |  
				| 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 |  | 
	
		|  | 
	
		| psmadhusudhan Beginner
 
  
 Joined: 28 Nov 2006
 Posts: 143
 Topics: 48
 
 
 | 
			
				|  Posted: Tue Mar 31, 2009 8:39 am    Post subject: |   |  
				| 
 |  
				| 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 |  | 
	
		|  | 
	
		| dbzTHEdinosauer Supermod
 
 
 Joined: 20 Oct 2006
 Posts: 1411
 Topics: 26
 Location: germany
 
 | 
			
				|  Posted: Tue Mar 31, 2009 9:17 am    Post subject: |   |  
				| 
 |  
				|  	  | 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 |  | 
	
		|  | 
	
		| kolusu Site Admin
 
  
 
 Joined: 26 Nov 2002
 Posts: 12394
 Topics: 75
 Location: San Jose
 
 | 
			
				|  Posted: Tue Mar 31, 2009 10:55 am    Post subject: |   |  
				| 
 |  
				| 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 |  | 
	
		|  | 
	
		| psmadhusudhan Beginner
 
  
 Joined: 28 Nov 2006
 Posts: 143
 Topics: 48
 
 
 | 
			
				|  Posted: Wed Apr 01, 2009 3:52 am    Post subject: |   |  
				| 
 |  
				| You are right kolusu. Thank you very much.  _________________
 Thanks
 Madhu Sudhan
 |  | 
	
		| Back to top |  | 
	
		|  | 
	
		| arvibala Beginner
 
  
 Joined: 12 Feb 2008
 Posts: 142
 Topics: 67
 
 
 | 
			
				|  Posted: Tue Apr 21, 2009 1:23 pm    Post subject: |   |  
				| 
 |  
				| 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 |  | 
	
		|  | 
	
		| kolusu Site Admin
 
  
 
 Joined: 26 Nov 2002
 Posts: 12394
 Topics: 75
 Location: San Jose
 
 | 
			
				|  Posted: Tue Apr 21, 2009 1:31 pm    Post subject: |   |  
				| 
 |  
				| arvibala, 
 Are u really thinking that the code reverses the text?
  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 |  | 
	
		|  | 
	
		| arvibala Beginner
 
  
 Joined: 12 Feb 2008
 Posts: 142
 Topics: 67
 
 
 | 
			
				|  Posted: Tue Apr 21, 2009 2:12 pm    Post subject: |   |  
				| 
 |  
				|  	  | 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 |  | 
	
		|  | 
	
		| kolusu Site Admin
 
  
 
 Joined: 26 Nov 2002
 Posts: 12394
 Topics: 75
 Location: San Jose
 
 | 
			
				|  Posted: Tue Apr 21, 2009 2:15 pm    Post subject: |   |  
				| 
 |  
				|  	  | 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,
 | 
 
 
  unbelievable |  | 
	
		| Back to top |  | 
	
		|  | 
	
		| arvibala Beginner
 
  
 Joined: 12 Feb 2008
 Posts: 142
 Topics: 67
 
 
 | 
			
				|  Posted: Tue Apr 21, 2009 2:25 pm    Post subject: |   |  
				| 
 |  
				|  	  | 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 |  | 
	
		|  | 
	
		|  | 
	
		|  |