IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

To get theSize of Cobol Field


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
vijaysharma

New User


Joined: 04 Jul 2007
Posts: 3
Location: Bangalore

PostPosted: Mon Jul 09, 2007 7:51 pm
Reply with quote

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
View user's profile Send private message
William Thompson

Global Moderator


Joined: 18 Nov 2006
Posts: 3156
Location: Tucson AZ

PostPosted: Mon Jul 09, 2007 9:19 pm
Reply with quote

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
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Mon Jul 09, 2007 9:49 pm
Reply with quote

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
View user's profile Send private message
Mickeydusaor

Active User


Joined: 24 May 2006
Posts: 258
Location: Salem, Oregon

PostPosted: Mon Jul 09, 2007 11:02 pm
Reply with quote

You could use the cobol REVERSE FUNCTION and process this field
until you come to the first non blank.
Back to top
View user's profile Send private message
mmwife

Super Moderator


Joined: 30 May 2003
Posts: 1592

PostPosted: Tue Jul 10, 2007 12:43 am
Reply with quote

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
View user's profile Send private message
vijaysharma

New User


Joined: 04 Jul 2007
Posts: 3
Location: Bangalore

PostPosted: Tue Jul 10, 2007 1:56 pm
Reply with quote

Hi All

Thank You For all Eur quick Response..


regards

Vijay Sharma
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts Replace each space in cobol string wi... COBOL Programming 3
No new posts COBOL -Linkage Section-Case Sensitive COBOL Programming 1
No new posts COBOL ZOS Web Enablement Toolkit HTTP... COBOL Programming 0
No new posts Replace Multiple Field values to Othe... DFSORT/ICETOOL 12
No new posts Calling DFSORT from Cobol, using OUTF... DFSORT/ICETOOL 5
Search our Forums:

Back to Top