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 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: 2504
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 Moving values to a variable of copybo... Vignesh Sid COBOL Programming 6 Wed Sep 06, 2017 1:04 pm
No new posts Remove leading spaces from numeric field rexx77 SYNCSORT 6 Wed Sep 06, 2017 2:15 am
No new posts Updating the Trailer count in variabl... satheshbabur DFSORT/ICETOOL 6 Wed Aug 30, 2017 9:49 pm
No new posts Move from Comp3 variable to Edited Va... sreekusr COBOL Programming 8 Thu Aug 10, 2017 4:20 pm
No new posts Can I traverse a STEM variable? chong.zhou CLIST & REXX 5 Wed May 31, 2017 3:54 pm

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