View previous topic :: View next topic
|
Author |
Message |
Pons
New User
Joined: 25 May 2007 Posts: 61 Location: Coimbatore
|
|
|
|
Hi,
How can i get the last two character of my variable using inspect or anything else.
Ex: My variable is
01 WS-ADDRESS PIC X(30).
Assume the valuse is like 'NEW YORK NY '.
There is no need only one spaces between two variables.
It may like 'NEW YORK NY '.
So i just want only last two characer NY alone...
How is it possible |
|
Back to top |
|
|
Craq Giegerich
Senior Member
Joined: 19 May 2007 Posts: 1512 Location: Virginia, USA
|
|
|
|
Code: |
01 ws-state pic xx.
01 x1 pic s9(4) comp.
01 WS-ADDRESS PIC X(30).
PERFORM VARYING X1 FROM 29 BY -1 UNTIL X1 <= 0
IF WS-ADDRESS (X1 : 1) > ' ' AND WS-ADDRESS (X1 + 1 : 1) > ' '
MOVE WS-ADDRESS (X1 : 2) TO WS-STATE
MOVE 0 TO X1
END-IF
END-PERFORM.
|
|
|
Back to top |
|
|
Gnanas N
Active Member
Joined: 06 Sep 2007 Posts: 792 Location: Chennai, India
|
|
|
|
Code: |
.
.
.
01 WS-STATE PIC XX.
01 X1 PIC S9(4) COMP.
01 WS-ADDRESS PIC X(30) VALUE 'NEW YORK NY'.
.
.
.
INSPECT FUNCTION REVERSE(WS-ADDRESS)
TALLYING X1 FOR LEADING SPACE.
COMPUTE X1 = 30 - 1 - X1.
MOVE WS-ADDRESS(X1:2) TO WS-STATE.
.
.
. |
Is this okay? |
|
Back to top |
|
|
Pons
New User
Joined: 25 May 2007 Posts: 61 Location: Coimbatore
|
|
|
|
Thanks Giegerich and gnanas,
I have the same logic which you had Giegerich. But it looks like some what hard to me. Thats what i try to find some other logic. I try with Gnanas logic. Thanks again... |
|
Back to top |
|
|
Craq Giegerich
Senior Member
Joined: 19 May 2007 Posts: 1512 Location: Virginia, USA
|
|
|
|
There are no leading spaces in 'NEW YORK NY '! |
|
Back to top |
|
|
Gnanas N
Active Member
Joined: 06 Sep 2007 Posts: 792 Location: Chennai, India
|
|
|
|
Code: |
INSPECT FUNCTION REVERSE(WS-ADDRESS)
TALLYING X1 FOR LEADING SPACE. |
I have reversed it!!! |
|
Back to top |
|
|
mmwife
Super Moderator
Joined: 30 May 2003 Posts: 1592
|
|
|
|
Hi Gnanas,
You might want to save yourself some future maint by coding:
Code: |
COMPUTE X1 = LENGTH OF WS-STATE - (X1 + 1) |
|
|
Back to top |
|
|
Gnanas N
Active Member
Joined: 06 Sep 2007 Posts: 792 Location: Chennai, India
|
|
|
|
Thanks, Jack. |
|
Back to top |
|
|
ranga_subham
New User
Joined: 01 Jul 2005 Posts: 51
|
|
|
|
Hi,
Why can't we try the following?
Code: |
WORKING-STORAGE SECTION.
01 WS-VAR PIC X(20) VALUE 'NEW YORK NY'.
01 WS-VA1 PIC X(20) JUST RIGHT.
PROCEDURE DIVISION.
MAIN-PARA.
DISPLAY '*** PROGRAM STARTS ***'.
DISPLAY WS-VAR.
MOVE SPACES TO WS-VA1.
MOVE WS-VAR TO WS-VA1.
DISPLAY WS-VA1.
DISPLAY WS-VA1(18:2).
DISPLAY '*** PROGRAM ENDS ***'.
STOP RUN.
|
Please suggest.
Thanks. |
|
Back to top |
|
|
Marso
REXX Moderator
Joined: 13 Mar 2006 Posts: 1353 Location: Israel
|
|
|
|
Ranga,
because the "JUST RIGHT" works only if you MOVE fields with different length (or if you're using UNSTRING):
Code: |
WORKING-STORAGE SECTION.
01 WS-VAR PIC X(20) VALUE 'NEW YORK NY'.
01 WS-VA1 PIC X(50) JUST RIGHT.
PROCEDURE DIVISION.
MAIN-PARA.
DISPLAY '*** PROGRAM STARTS ***'.
DISPLAY WS-VAR.
MOVE SPACES TO WS-VA1.
MOVE WS-VAR TO WS-VA1.
DISPLAY WS-VA1.
DISPLAY WS-VA1(18:2).
DISPLAY '*** PROGRAM ENDS ***'.
STOP RUN. |
I have changed the length of WS-VA1 in your example. In this case, the 20 chars of WS-VAR will be moved to the 20 rightmost characters of WS-VA1 and it will be padded with 30 spaces on the left.
But within the 20 characters, nothing will be shifted. Which means you will now have spaces to the left AND to the right of your string... |
|
Back to top |
|
|
ranga_subham
New User
Joined: 01 Jul 2005 Posts: 51
|
|
|
|
Thanks Marso.........Now, I got my basics right........... |
|
Back to top |
|
|
|