Portal | IBM Manuals | Downloads | Products | Refer | Info | Programs | JCLs | Forum Rules*| Site Map | Mainframe CD 
IBMMAINFRAMES.com - IBM Mainframe Support Forums Index
 
Register
 
IBMMAINFRAMES.com - IBM Mainframe Support Forums Index FAQ Search Memberlist Usergroups Profile Log in to check your private messages Log in
 
how to determine the length of a variable in COBOL?

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> Mainframe COBOL
Author Message
iknow

Senior Member


Joined: 22 Aug 2005
Posts: 582
Location: Colarado, US

PostPosted: Wed Sep 14, 2005 10:30 pm    Post subject: how to determine the length of a variable in COBOL?
Reply with quote

For eg: like if a variable is defined as 01 N1 PIC X(20). and a value is moved into it, MOVE 'ASDAS' TO N1. then how to retrieve the length of the N1 variable which is 5? the LENGTH OF gives a result of 20.
Back to top
View user's profile Send private message
References
sridevi2005

New User


Joined: 15 Sep 2005
Posts: 45

PostPosted: Thu Sep 15, 2005 12:35 pm    Post subject: Re: how to determine the length of a variable in COBOL?
Reply with quote

Hi,

I think the following code will help u

MOVE FUCNTION LENGTH(str1) TO WS-I
PERFORM UNTIL VARYING WS-J FROM 1 BY 1 UNTIL STR1(1: ) = SPACES
OR WS-I = WS-J
DISPLAY WSJ
END-PERFORM

Thanks,
Sridevi
Back to top
View user's profile Send private message
michaelraj

New User


Joined: 01 Sep 2005
Posts: 44
Location: Bangalore

PostPosted: Thu Sep 15, 2005 1:07 pm    Post subject:
Reply with quote

Hi ,

Try this,

String "ASDAS" Delimited by ' ' into N1 with Pointer ws-count

We may count the number of characters actually moved to the N1 if it is initialized at zero.

Regards,
Mike.
Back to top
View user's profile Send private message
mmwife

Super Moderator


Joined: 30 May 2003
Posts: 1526

PostPosted: Sun Oct 16, 2005 11:05 pm    Post subject:
Reply with quote

*************************************************************
Finding the length of a string using the REVERSE function of LE Cobol
*************************************************************
INSPECT FUNCTION REVERSE(TEXT1) TALLYING L FOR LEADING SPACES
COMPUTE L = LENGTH OF TEXT1 - L

where: L is actual length of text in TEXT1. Note!!! TEXT1 remains unchanged after the operation (i.e. it isn't reversed).
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> Mainframe COBOL All times are GMT + 6 Hours
Page 1 of 1