View previous topic :: View next topic
|
Author |
Message |
vijaysharma
New User
Joined: 04 Jul 2007 Posts: 3 Location: Bangalore
|
|
|
|
Hi
I want to get the COBOL field size
Lets say I have filed defined in copy book
01 E-Name pic x(40).
move 'Vijay' to E-Name.
If i use the Length function it will always return me the actual length of field i.e, 40.
But i want get the variable size in program , in the above example it should be 5 ('V i j a y ' is 5 letters).
PS let me know is there any function available in COBOL
?
Thanks in Advance
Vijay Sharma |
|
Back to top |
|
|
William Thompson
Global Moderator
Joined: 18 Nov 2006 Posts: 3156 Location: Tucson AZ
|
|
|
|
Sorry, the SIZE is 40 characters....
You want the length of valid data (and who is to say trailing blanks are not valid).
You will have to unstring the data or examine tallying the data with your own rules for defining 'what is valid data and where does it end' to determine the length. |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello,
One way to get what you want is to redefine the field as an array, point to the right-most character, and compare if a space. If it is a space, decrement the pointer and check again. When you come to the first non-blank byte, the value in the pointer is the "length" of the data. This will accomodate embedded spaces which is common in name fields. |
|
Back to top |
|
|
Mickeydusaor
Active User
Joined: 24 May 2006 Posts: 258 Location: Salem, Oregon
|
|
|
|
You could use the cobol REVERSE FUNCTION and process this field
until you come to the first non blank. |
|
Back to top |
|
|
mmwife
Super Moderator
Joined: 30 May 2003 Posts: 1592
|
|
|
|
A variation on Mickey D's solution:
INSPECT FUNCTION REVERSE(TEXT1) TALLYING L FOR LEADING SPACES
COMPUTE L = LENGTH OF TEXT1 - L |
|
Back to top |
|
|
vijaysharma
New User
Joined: 04 Jul 2007 Posts: 3 Location: Bangalore
|
|
|
|
Hi All
Thank You For all Eur quick Response..
regards
Vijay Sharma |
|
Back to top |
|
|
|