IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Removing Spaces in the output


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
simha_it

New User


Joined: 05 May 2005
Posts: 30

PostPosted: Tue Sep 16, 2008 7:04 pm
Reply with quote

Hi,
I want to remove the spaces in the output.

For ex: Output:ABCD_123_IUTOER_545_JLLDF_____1_____
'_' indicates SPACE

Now my output should looks like: ABCD123IUTOER545JLLDF1

Simha.
Back to top
View user's profile Send private message
expat

Global Moderator


Joined: 14 Mar 2007
Posts: 8797
Location: Welsh Wales

PostPosted: Tue Sep 16, 2008 7:07 pm
Reply with quote

Had you have used tags to show your example the spaces would appear as spaces

Click HERE to see how to use tags.
Back to top
View user's profile Send private message
Escapa

Senior Member


Joined: 16 Feb 2007
Posts: 1399
Location: IL, USA

PostPosted: Tue Sep 16, 2008 7:43 pm
Reply with quote

Quote:

(we can remove the spaces by using INSPECT verb. Give me the Pseudo code)

I think NO. when you use replacing you need to give same size character string which you want to replace.

You need to use perform loop using combination string and unstring using pointers
Back to top
View user's profile Send private message
Escapa

Senior Member


Joined: 16 Feb 2007
Posts: 1399
Location: IL, USA

PostPosted: Tue Sep 16, 2008 7:58 pm
Reply with quote

Hope you have digged out something by now..
here is solution
Code:

*WS
01 VIN PIC X(40) VALUE 'ABCD 12  IUTOER 545 JLLDF    1   '.
01 VOUT PIC X(40).                                         
01 VTEMP PIC X(40).                                         
01 PTR1 PIC 99.                                             
01 PTR2 PIC 99.                                             

*PD
    MOVE 1 TO PTR1 PTR2.               
    MOVE SPACES TO VOUT VTEMP.         
    PERFORM UNTIL PTR1 > 40             
    UNSTRING VIN DELIMITED BY ALL SPACES
      INTO VTEMP  POINTER PTR1         
    STRING VTEMP DELIMITED BY SPACES   
      INTO VOUT POINTER PTR2           
    END-PERFORM.                       
    DISPLAY "INPUT :" VIN.             
    DISPLAY "OUTPUT:" VOUT.             

Output is
Code:

INPUT :ABCD 12  IUTOER 545 JLLDF    1     
OUTPUT:ABCD12IUTOER545JLLDF1             
Back to top
View user's profile Send private message
simha_it

New User


Joined: 05 May 2005
Posts: 30

PostPosted: Wed Sep 17, 2008 1:39 pm
Reply with quote

Thanks for the quick response and thanks again for your time.....
Back to top
View user's profile Send private message
simha_it

New User


Joined: 05 May 2005
Posts: 30

PostPosted: Wed Sep 17, 2008 1:44 pm
Reply with quote

Is there any other way of achieving the same without declating VOUT and VTEMP? Bcoz my output field is having huge length. So I can't declare another variable with the same length.
Back to top
View user's profile Send private message
ksk

Active User


Joined: 08 Jun 2006
Posts: 355
Location: New York

PostPosted: Wed Sep 17, 2008 5:54 pm
Reply with quote

otherway is follow reference modification and move the required values into the same input variable.

e.g., for your example ABCD_123_IUTOER
Code:

             move Input(1:4) to Input(1:4).
             move Input(6:3) to Input(5:3).
             move Input(10:6) to Input(8:6). and so on.


As this involves lot of coding may not be feasible if your input is very big.
Back to top
View user's profile Send private message
Bill O'Boyle

CICS Moderator


Joined: 14 Jan 2008
Posts: 2501
Location: Atlanta, Georgia, USA

PostPosted: Wed Sep 17, 2008 8:49 pm
Reply with quote

Review the below link -

ibmmainframes.com/viewtopic.php?t=32610

Bill
Back to top
View user's profile Send private message
ashimer

Active Member


Joined: 13 Feb 2004
Posts: 551
Location: Bangalore

PostPosted: Wed Sep 17, 2008 9:13 pm
Reply with quote

Quote:

Is there any other way of achieving the same without declating VOUT and VTEMP?


You will require atleast one temp variable ...

Use perform checking for each character for spaces .. and if not space then move it to the temp variable using ref modification ...
Back to top
View user's profile Send private message
Escapa

Senior Member


Joined: 16 Feb 2007
Posts: 1399
Location: IL, USA

PostPosted: Thu Sep 18, 2008 5:59 pm
Reply with quote

Quote:

Is there any other way of achieving the same without declating VOUT and VTEMP? Bcoz my output field is having huge length. So I can't declare another variable with the same length.


Yes ther is a way. You can achieve it using redefines clause.
Check out below code
Code:

*WS
01 VINTEMP.                                                   
   02 VIN PIC X(40) VALUE 'ABCD 12  IUTOER 545 JLLDF    1   '.
   02 VIN1 REDEFINES VIN PIC X OCCURS 40 TIMES.               
*PD
MOVE 1 TO IDX1.                                     
PERFORM STRIP-PARA VARYING IDX FROM 1 BY 1 UNTIL   
        IDX = 40.                                   
DISPLAY "IDX1:" IDX1.                               
PERFORM MOVE-SPACES VARYING IDX FROM IDX1 BY 1 UNTIL
        IDX = 40.                                   
DISPLAY "WITHOUT USING TEMP VARIABLE: " VIN.       
.
.
.
STRIP-PARA.                           
    IF VIN1(IDX) NOT = ' '  THEN       
       IF IDX NOT = IDX1 THEN         
          MOVE VIN1(IDX) TO  VIN1(IDX1)
       END-IF                         
    COMPUTE IDX1 = IDX1 + 1.           
MOVE-SPACES.                           
    MOVE ' ' TO VIN1(IDX).             
'
'
*Output
WITHOUT USING TEMP VARIABLE: ABCD12IUTOER545JLLDF1

Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts Sortjoin and Search for a String and ... DFSORT/ICETOOL 1
No new posts Joinkeys - 5 output files DFSORT/ICETOOL 7
No new posts leading spaces can be removed in trai... DFSORT/ICETOOL 1
No new posts Build a record in output file and rep... DFSORT/ICETOOL 11
No new posts XDC SDSF output to temp dataset CLIST & REXX 4
Search our Forums:

Back to Top