Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

Need to remove spaces from variable

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
View previous topic :: :: View next topic  
Author Message
rupesh gullu

New User


Joined: 12 Dec 2008
Posts: 96
Location: Gurgaon

PostPosted: Mon May 24, 2010 10:47 am    Post subject: Need to remove spaces from variable
Reply with quote

Hi,

I have a string say 'bAbBbCbbDbE .....' and so on of 30 bytes. Here small b denotes space. There can be more than one space between two characters. I need to remove all the spaces and wirte it into single varaible. So my o/p should be ABCDE.... Can I do it using String function.

regards,
rupesh gupta
Back to top
View user's profile Send private message

Escapa

Senior Member


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

PostPosted: Mon May 24, 2010 11:32 am    Post subject:
Reply with quote

Hi, Sometime back I posted solution for similar requirement...

You are lucky... I was able to find it... Check if below

http://www.ibmmainframes.com/viewtopic.php?t=34326&highlight=strippara
Back to top
View user's profile Send private message
ajithj

New User


Joined: 13 Jun 2005
Posts: 5

PostPosted: Mon May 24, 2010 11:41 am    Post subject: Reply to: Need to remove spaces from variable
Reply with quote

01 WS-INPUT PIC X(30) VALUE ' A B C D E '
01 WS-ARRAY.
05 WS-CHARS PIC X(1) OCCURS 30 TIMES
01 WS-OUTPUT PIC X(30)
01 WS-POSITION-1 PIC 99
01 WS-POSITION-2 PIC 99
.
.
.
.
.
.
MOVE WS-INPUT TO WS-ARRAY
MOVE 1 TO WS-POSITION-2

PERFORM VARYING WS-POSITION-1 FROM 1 BY 1 UNTIL WS-POSITION-1 > 30
IF WS-CHAR (WS-POSITION-1) > SPACES
MOVE WS-CHAR (WS-POSITION-1) TO WS-CHAR (WS-POSITION-2)
MOVE SPACE TO WS-CHAR (WS-POSITION-1)
ADD +1 TO WS-POSITION-2
END-IF
END-PERFORM

MOVE WS-ARRAY TO WS-OUTPUT
Back to top
View user's profile Send private message
rupesh gullu

New User


Joined: 12 Dec 2008
Posts: 96
Location: Gurgaon

PostPosted: Mon May 24, 2010 11:43 am    Post subject: Reply to: Need to remove spaces from variable
Reply with quote

Thanks all for the response its working fine.

regards,
rupesh gupta
Back to top
View user's profile Send private message
Escapa

Senior Member


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

PostPosted: Mon May 24, 2010 1:32 pm    Post subject: Re: Reply to: Need to remove spaces from variable
Reply with quote

ajithj wrote:

Code:
    IF WS-CHAR (WS-POSITION-1) > SPACES


Hi Ajith, I am not sure why you are using > here??

Where as OP wants only SPACES TO remove....

What if WS-CHAR (WS-POSITION-1) is X'00'?
Back to top
View user's profile Send private message
Escapa

Senior Member


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

PostPosted: Mon May 24, 2010 1:34 pm    Post subject: Re: Reply to: Need to remove spaces from variable
Reply with quote

rupesh gullu wrote:
Thanks all for the response its working fine.

regards,
rupesh gupta

Which solution you have used?
Back to top
View user's profile Send private message
Pravesh

New User


Joined: 30 Jul 2009
Posts: 32
Location: Gurgaon

PostPosted: Mon May 24, 2010 2:50 pm    Post subject: Reply to: Need to remove spaces from variable
Reply with quote

You can try out this also(If do not want to use array)

VAR-A PIC X(30) VALUE 'A B C D E'
VAR-B PIC X(30) VALUE SPACES
N= 0
PERFOME VARYING X FROM 1 BY 1 UNTIL X > 30
IF VAR-A(X :1) = ' '
N = N + 1
ELSE
M= X-N
MOVE VAR-A(X :1) TO VAR-B(M: 1)
END-IF
END-PERFORM
Back to top
View user's profile Send private message
Escapa

Senior Member


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

PostPosted: Mon May 24, 2010 3:06 pm    Post subject: Re: Reply to: Need to remove spaces from variable
Reply with quote

Pravesh wrote:
You can try out this also(If do not want to use array)

VAR-A PIC X(30) VALUE 'A B C D E'
VAR-B PIC X(30) VALUE SPACES
N= 0
PERFOME VARYING X FROM 1 BY 1 UNTIL X > 30
IF VAR-A(X :1) = ' '
N = N + 1
ELSE
M= X-N
MOVE VAR-A(X :1) TO VAR-B(M: 1)
END-IF
END-PERFORM

Do not post untested code.... Use code tags....
Back to top
View user's profile Send private message
Pravesh

New User


Joined: 30 Jul 2009
Posts: 32
Location: Gurgaon

PostPosted: Mon May 24, 2010 3:30 pm    Post subject: Reply to: Need to remove spaces from variable
Reply with quote

Hi Sambhaji,
Can you please let me know what logical error my code has?


Regards,
Pravesh
Back to top
View user's profile Send private message
Escapa

Senior Member


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

PostPosted: Mon May 24, 2010 3:53 pm    Post subject: Re: Reply to: Need to remove spaces from variable
Reply with quote

Pravesh wrote:
Hi Sambhaji,
Can you please let me know what logical error my code has?


Regards,
Pravesh


IT IS MIXTURE OF COBOL + PSEUDO CODE
Back to top
View user's profile Send private message
Bill O'Boyle

CICS Moderator


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

PostPosted: Mon May 24, 2010 4:52 pm    Post subject: Reply to: Need to remove spaces from variable
Reply with quote

Although the following post removes all specified unwanted characters from a given string, it may be helpful for future reference, perhaps some of the code is adaptable to your request -

http://ibmmainframes.com/viewtopic.php?p=143786&highlight=#143786

Bill
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts To trim spaces in a pipe delimited da... Nish84 COBOL Programming 16 Mon Oct 10, 2016 1:54 pm
No new posts Format to pipe delimited with variabl... pshongal SYNCSORT 6 Wed Sep 14, 2016 2:48 pm
No new posts Removing Extra Spaces in a comma sepa... Puspojit DFSORT/ICETOOL 3 Tue Sep 13, 2016 7:46 am
No new posts Variable for cursor names ravikumar15 DB2 5 Sun Jul 17, 2016 7:08 am
No new posts Remove Special Characters from Mainfr... Rodger Zhang All Other Mainframe Topics 6 Wed Jul 06, 2016 1:12 am


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us