Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

How to check the length of the variable

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
View previous topic :: :: View next topic  
Author Message
vijay_bn79

New User


Joined: 20 Nov 2006
Posts: 48
Location: Hyderabad

PostPosted: Tue Nov 21, 2006 6:09 pm    Post subject: How to check the length of the variable
Reply with quote

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

Arun Raj

Moderator


Joined: 17 Oct 2006
Posts: 2180
Location: @my desk

PostPosted: Tue Nov 21, 2006 6:22 pm    Post subject: Re: How to check the length of the variable
Reply with quote

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

REXX Moderator


Joined: 13 Mar 2006
Posts: 1224
Location: Israel

PostPosted: Tue Nov 21, 2006 7:02 pm    Post subject:
Reply with quote

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

New User


Joined: 20 Nov 2006
Posts: 48
Location: Hyderabad

PostPosted: Wed Nov 22, 2006 1:42 pm    Post subject:
Reply with quote

Thanks to all
Back to top
View user's profile Send private message
vijay_bn79

New User


Joined: 20 Nov 2006
Posts: 48
Location: Hyderabad

PostPosted: Fri Nov 24, 2006 5:19 pm    Post subject: Re: How to check the length of the variable
Reply with quote

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

Global Moderator


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

PostPosted: Fri Nov 24, 2006 5:23 pm    Post subject:
Reply with quote

The inspect goes after the initial space, your example would have a length of 11. Isn't that what you want?
Back to top
View user's profile Send private message
William Thompson

Global Moderator


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

PostPosted: Fri Nov 24, 2006 8:34 pm    Post subject:
Reply with quote

Oh my, I bad icon_redface.gif 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
View user's profile Send private message
mmwife

Super Moderator


Joined: 30 May 2003
Posts: 1592

PostPosted: Sat Nov 25, 2006 5:00 am    Post subject:
Reply with quote

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
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts What is the command to check MODE of ... rohanthengal CLIST & REXX 7 Fri Nov 18, 2016 1:48 pm
No new posts Check System time(Minute) Using TIME1... balaji81_k DFSORT/ICETOOL 5 Fri Nov 11, 2016 10:53 am
No new posts SQZ pipe delimited file with 1 column... Rick Silvers DFSORT/ICETOOL 2 Sun Nov 06, 2016 8:11 pm
No new posts Joinkeys operation when key1 and key2... Susanta DFSORT/ICETOOL 5 Wed Nov 02, 2016 5:35 pm
No new posts Format to pipe delimited with variabl... pshongal SYNCSORT 6 Wed Sep 14, 2016 2:48 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us