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: 2276
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: 1228
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 Converting Variable block file to Fix... bhavana yalavarthi DFSORT/ICETOOL 10 Tue May 16, 2017 2:20 pm
No new posts Check if any Detail records and extra... V S Amarendra Reddy SYNCSORT 19 Mon May 08, 2017 8:54 pm
No new posts Getting error while opening a variabl... apandey1 COBOL Programming 5 Fri May 05, 2017 12:22 pm
No new posts Length of Tape file Mohan Kothakota JCL & VSAM 9 Thu Apr 20, 2017 10:24 pm
No new posts Sort Large record length cmsmoon DFSORT/ICETOOL 14 Tue Apr 11, 2017 5:49 pm


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