View previous topic :: View next topic
|
Author |
Message |
dipanshu
New User
Joined: 16 Jan 2006 Posts: 53 Location: pune
|
|
|
|
Hi,
Suppose
x1 pic x(9) value is 'abc'
x2 pic x(9)
move x1 to x2
now x2 should display only 'abc' with no trailing spaces
pls suggest with code too.
thanks,
Dipanshu |
|
Back to top |
|
|
bhardwajparitosh
New User
Joined: 30 Jul 2005 Posts: 4 Location: india
|
|
|
|
use refrence modification
move x1(1:3) to x2.
or at the time of display u can use
display x1(1:3).
this will most probably remove trailing space
another way to solve the proble to have x2 pic x(3) so everything will be automatically done if u move the variable |
|
Back to top |
|
|
dipanshu
New User
Joined: 16 Jan 2006 Posts: 53 Location: pune
|
|
|
|
Hi,
You r right
but i want some generalised logic, The above I given is just the example, value may be vary from 1 chracter to 9 chracter and the logic u given is only meant for 3 chracter.
Pls reply with some flexible logic ?
Thanks,
Dipanshu |
|
Back to top |
|
|
sudheer_kumar
New User
Joined: 27 Dec 2005 Posts: 16
|
|
|
|
01 WS-STR PIC X(15).
01 WS-STR1 PIC X(15).
01 I PIC 9 VALUE 1.
01 J PIC 9 VALUE 1.
01 WS-LEN-2 PIC S9(04) COMP.
MOVE ' NAVEEN ' TO WS-STR
MOVE LENGTH OF WS-STR TO WS-LEN-2
PERFORM VARYING I FROM 1 BY 1 UNTIL I > WS-LEN-2
IF WS-STR(I:1) NOT EQUAL SPACE
MOVE WS-STR(I:1) TO WS-STR1(J:1)
ADD 01 TO J
END-IF
END-PERFORM
The WS-STR1 contains 'NAVEEN'.
If I am wrong let me know.
Regards,
Sudheer |
|
Back to top |
|
|
DavidatK
Active Member
Joined: 22 Nov 2005 Posts: 700 Location: Troy, Michigan USA
|
|
|
|
dipanshu,
Question.
The title to your subject is:
Quote: |
How to remove leading & trailing space. |
Does this imply that your data might be " DAVE " with leading and trailing spaces? and you want the variable to display "DAVE" with no leading or trailing spaces?
The post by sudheer_kumar will not work as you might think.
If variable WS-STR1 initially contained "1234567890ABCDE" and you execute his moves, the result in WS-STR1 will be "NAVEEN7890ABCDE"
Then post by bhardwajparitosh
Quote: |
use refrence modification
move x1(1:3) to x2.
or at the time of display u can use
display x1(1:3).
this will most probably remove trailing space
another way to solve the proble to have x2 pic x(3) so everything will be automatically done if u move the variable |
is pretty close. If you move x1(1:3) to x2, x2 will contain "ABC " ("ABC trailed by 12 spaces)
The display x1(1:3) will work 'display x1(beg_loc:len)' is better, the problem is knowing where the starting char is and the length of the string you want to display.
The last suggestion I really like, the problem is knowing how long the PIC needs to be.
Making the assumption that you have taken care of the leading spaces so the text is left justified, the code below may be of interest to you.
Code: |
01 PGM-VARIABLES.
05 CHAR-CNT PIC 9(5) VALUE 15.
05 X1 PIC X(15) VALUE 'ABC'.
05 X2.
10 X2-X OCCURS 1 TO 15 TIMES
DEPENDING ON CHAR-CNT PIC X.
PROCEDURE DIVISION.
MOVE 'ABC' TO X1.
PERFORM P1000-GET-CHAR-CNT THRU P1000-EXIT.
MOVE X1 TO X2.
DISPLAY '>' X2 '<'.
MOVE 'DIPANSHU' TO X1.
PERFORM P1000-GET-CHAR-CNT THRU P1000-EXIT.
MOVE X1 TO X2.
DISPLAY '>' X2 '<'.
MOVE SPACES TO X1.
PERFORM P1000-GET-CHAR-CNT THRU P1000-EXIT.
MOVE X1 TO X2.
DISPLAY '>' X2 '<'.
MOVE 'HELLO DIPANSHU!' TO X1.
PERFORM P1000-GET-CHAR-CNT THRU P1000-EXIT.
MOVE X1 TO X2.
DISPLAY '>' X2 '<'.
GOBACK.
P1000-GET-CHAR-CNT.
PERFORM
VARYING CHAR-CNT FROM LENGTH OF X1 BY -1
UNTIL X1(CHAR-CNT:1) NOT = ' '
OR CHAR-CNT < 1
END-PERFORM.
P1000-EXIT.
EXIT.
|
The above code produces the following output.
Code: |
.SARPAGE 40
.
.>ABC<
.>DIPANSHU<
.><
.>HELLO DIPANSHU!<
|
|
|
Back to top |
|
|
|