View previous topic :: View next topic |
Author |
Message |
jagan Beginner
Joined: 27 Jan 2003 Posts: 5 Topics: 4
|
Posted: Thu Mar 06, 2003 10:30 am Post subject: how to the length of a string |
|
|
hi friends,
i want to know the actual length of a value in a variable.
suppose i have a variable xcob with 40 size.
xcob pic x(40)
after i moved some value to that xcob.
is there any length verb in cobol?
length(xocb)
thanks
jagan |
|
Back to top |
|
|
hari_uss Beginner
Joined: 19 Dec 2002 Posts: 78 Topics: 6 Location: Trivandrum, India
|
Posted: Thu Mar 06, 2003 10:47 am Post subject: |
|
|
MOVE FUNCTION REVERSE(XCOB) TO XCOB-REV.
INSPECT XCOB-REV TALLYING WS-COUNT
FOR LEADING SPACES.
COMPUTE WS-LENGTH = LENGTH OF XCOB - WS-COUNT.
DISPLAY 'LENGTH = ' WS-LENGTH.
Note: Untested code. |
|
Back to top |
|
|
Grant Beginner
Joined: 02 Dec 2002 Posts: 45 Topics: 1 Location: Sydney, NSW, Australia
|
Posted: Thu Mar 06, 2003 5:23 pm Post subject: |
|
|
Jagan,
The solution provided by hari_uss will work, but it will require a subroutine call to be generated for MOVE FUNCTION REVERSE(XCOB) TO XCOB-REV.
I think you will find that the following code will be pretty efficient
Code: |
WORKING-STORAGE SECTION.
01 X-COB Pic X(100) value 'abcde'.
01 I Pic s9(4) binary.
PROCEDURE DIVISION.
Perform varying I from length of X-COB by -1
Until X-COB(I:1) not = spaces
End-perform
Display "The value of I is " I
GOBACK.
|
The value of I is 0005 |
|
Back to top |
|
|
ipog_jkm Beginner
Joined: 28 Apr 2003 Posts: 2 Topics: 0
|
Posted: Tue Apr 29, 2003 6:01 am Post subject: |
|
|
Hi Jagan ,
You can use the following code
INSPECT WS-STRING TALLYING WS-COUNTER
FOR CHARACTERS BEFORE INITIAL SPACE
WS-STRING - STRING USED
WS-COUNTER - NO CHARACTERS. |
|
Back to top |
|
|
misfit Beginner
Joined: 01 May 2003 Posts: 26 Topics: 9 Location: India
|
Posted: Thu May 01, 2003 12:52 am Post subject: |
|
|
hi ipog_jkm,
will this solution work for string having leading or embedded spaces? _________________ <i><b> Don't wish it were easier. Wish you were better. </b></i> |
|
Back to top |
|
|
Dibakar Advanced
Joined: 02 Dec 2002 Posts: 700 Topics: 63 Location: USA
|
Posted: Thu May 01, 2003 2:17 am Post subject: |
|
|
No,
You will have to get count for both leading and trailing spaces seperately and then compute the length.
Diba. |
|
Back to top |
|
|
slade Intermediate
Joined: 07 Feb 2003 Posts: 266 Topics: 1 Location: Edison, NJ USA
|
Posted: Fri May 02, 2003 12:14 pm Post subject: |
|
|
This should work:
INSPECT WS-STRING TALLYING WS-L-SPACES
FOR CHARACTERS BEFORE INITIAL SPACE
INSPECT FUNCTION REVERSE (WS-STRING) TALLYING WS-T-SPACES
FOR CHARACTERS BEFORE INITIAL SPACE
COMPUTE WS-STRING-LEN
= LENGTH OF WS-STRING - WS-L-SPACES - WS-T-SPACES |
|
Back to top |
|
|
|
|