View previous topic :: View next topic
|
Author |
Message |
vijay_bn79
New User
Joined: 20 Nov 2006 Posts: 48 Location: Hyderabad
|
|
|
|
for example
WS-VARIABLE PIC X(20).
MOVE 'VIJAY' TO WS-VARIABLE
in this example the length is 5
if i move 'VIJAYAKUMAR'
I should get the length as 11 |
|
Back to top |
|
|
Arun Raj
Moderator
Joined: 17 Oct 2006 Posts: 2481 Location: @my desk
|
|
|
|
Hi
Try this code
Code: |
WORKING-STORAGE SECTION.
77 CNT PIC 9(2) VALUE 0.
77 VAR PIC X(20) VALUE 'VIJAYAKUMAR'.
PROCEDURE DIVISION.
INSPECT VAR TALLYING CNT FOR CHARACTERS BEFORE INITIAL ' '
DISPLAY CNT
STOP RUN.
|
Thanks
Arun |
|
Back to top |
|
|
Marso
REXX Moderator
Joined: 13 Mar 2006 Posts: 1353 Location: Israel
|
|
|
|
As this piece of code can be placed in a section which will be executed a number of times, it is safer to write:
Code: |
MOVE 0 TO CNT
INSPECT VAR TALLYING CNT FOR CHARACTERS BEFORE INITIAL ' '
|
Otherwise it will work only on the first time, and on the other times you will receive an erroneous value. |
|
Back to top |
|
|
vijay_bn79
New User
Joined: 20 Nov 2006 Posts: 48 Location: Hyderabad
|
|
|
|
Thanks to all |
|
Back to top |
|
|
vijay_bn79
New User
Joined: 20 Nov 2006 Posts: 48 Location: Hyderabad
|
|
|
|
MOVE 0 TO CNT
INSPECT VAR TALLYING CNT FOR CHARACTERS BEFORE INITIAL ' '
but when we move with space, will this work
MOVE 'VIJAY KUMAR' TO WS-VARIABLE |
|
Back to top |
|
|
William Thompson
Global Moderator
Joined: 18 Nov 2006 Posts: 3156 Location: Tucson AZ
|
|
|
|
The inspect goes after the initial space, your example would have a length of 11. Isn't that what you want? |
|
Back to top |
|
|
William Thompson
Global Moderator
Joined: 18 Nov 2006 Posts: 3156 Location: Tucson AZ
|
|
|
|
Oh my, I bad shooting from the hip....
Code: |
WS-VARIABLE PIC X(20).
move function length-of (ws-variable) to ix.
perform until ix = 0 or ws-variable (ix:1) not = ' '
ix = ix - 1
end-perform.
Length = ix. |
That should be better
(no manual, check systax) |
|
Back to top |
|
|
mmwife
Super Moderator
Joined: 30 May 2003 Posts: 1592
|
|
|
|
You can try something like this:
Code: |
INSPECT FUNCTION REVERSE(TEXT1) TALLYING L FOR LEADING SPACES
COMPUTE L = LENGTH OF TEXT1 - L |
|
|
Back to top |
|
|
|