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

Need to remove spaces from variable


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
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
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
Reply with quote

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

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

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
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
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
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
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
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
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
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
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: 2501
Location: Atlanta, Georgia, USA

PostPosted: Mon May 24, 2010 4:52 pm
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 -

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 View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts Extracting Variable decimal numbers f... DFSORT/ICETOOL 17
No new posts Sortjoin and Search for a String and ... DFSORT/ICETOOL 1
No new posts Remove leading zeroes SYNCSORT 4
No new posts leading spaces can be removed in trai... DFSORT/ICETOOL 1
No new posts Variable Output file name DFSORT/ICETOOL 8
Search our Forums:

Back to Top