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

How to check the length of the variable


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
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
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: 2481
Location: @my desk

PostPosted: Tue Nov 21, 2006 6:22 pm
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: 1353
Location: Israel

PostPosted: Tue Nov 21, 2006 7:02 pm
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
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
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: 3156
Location: Tucson AZ

PostPosted: Fri Nov 24, 2006 5:23 pm
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: 3156
Location: Tucson AZ

PostPosted: Fri Nov 24, 2006 8:34 pm
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
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 View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts Store the data for fixed length COBOL Programming 1
No new posts How to split large record length file... DFSORT/ICETOOL 10
No new posts PARSE Syntax for not fix length word ... JCL & VSAM 7
No new posts Extracting Variable decimal numbers f... DFSORT/ICETOOL 17
No new posts VB to VB copy - Full length reached SYNCSORT 8
Search our Forums:

Back to Top