View previous topic :: View next topic
|
Author |
Message |
rupesh gullu
New User
Joined: 12 Dec 2008 Posts: 96 Location: Gurgaon
|
|
|
|
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 |
|
|
Escapa
Senior Member
Joined: 16 Feb 2007 Posts: 1399 Location: IL, USA
|
|
Back to top |
|
|
ajithj
New User
Joined: 13 Jun 2005 Posts: 5
|
|
|
|
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 |
|
|
rupesh gullu
New User
Joined: 12 Dec 2008 Posts: 96 Location: Gurgaon
|
|
|
|
Thanks all for the response its working fine.
regards,
rupesh gupta |
|
Back to top |
|
|
Escapa
Senior Member
Joined: 16 Feb 2007 Posts: 1399 Location: IL, USA
|
|
|
|
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 |
|
|
Escapa
Senior Member
Joined: 16 Feb 2007 Posts: 1399 Location: IL, USA
|
|
|
|
rupesh gullu wrote: |
Thanks all for the response its working fine.
regards,
rupesh gupta |
Which solution you have used? |
|
Back to top |
|
|
Pravesh
New User
Joined: 30 Jul 2009 Posts: 32 Location: Gurgaon
|
|
|
|
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 |
|
|
Escapa
Senior Member
Joined: 16 Feb 2007 Posts: 1399 Location: IL, USA
|
|
|
|
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 |
|
|
Pravesh
New User
Joined: 30 Jul 2009 Posts: 32 Location: Gurgaon
|
|
|
|
Hi Sambhaji,
Can you please let me know what logical error my code has?
Regards,
Pravesh |
|
Back to top |
|
|
Escapa
Senior Member
Joined: 16 Feb 2007 Posts: 1399 Location: IL, USA
|
|
|
|
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 |
|
|
Bill O'Boyle
CICS Moderator
Joined: 14 Jan 2008 Posts: 2501 Location: Atlanta, Georgia, USA
|
|
Back to top |
|
|
|