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
 

 

Find the length of data

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

New User


Joined: 05 Jun 2008
Posts: 17
Location: chennai

PostPosted: Wed Oct 29, 2008 10:33 am    Post subject: Find the length of data
Reply with quote

Hi
Our scenario goes like this
we have one variable name WS-NAME PIC X(12), its length is 12 bytes.
now, if a data of length 4 bytes, say BALA got entered in WS-NAME, we would like to know how to compute the exact length of the data entered in WS-NAME?
Back to top
View user's profile Send private message

Aji

New User


Joined: 03 Feb 2006
Posts: 53
Location: Mumbai

PostPosted: Wed Oct 29, 2008 10:44 am    Post subject: Reply to: Find the length of data
Reply with quote

Hi,

Inspect text1 tallying leng for trailing spaces.

act_len = len(text1) - leng.



Thanks

Aji
Back to top
View user's profile Send private message
balaji81_k

New User


Joined: 29 Jun 2005
Posts: 89

PostPosted: Wed Oct 29, 2008 10:46 am    Post subject: Re: Find the length of data
Reply with quote

Hi Friend,

I believe u need to declare the WS-NAME as VARCHAR like in DB2
(i,e)

01 WS.
02 WS-NAME PIC X(12).
02 WS-LENGTH PIC S9(4) COMP.

01 WS-CAL-LENGTH PIC 9(12).

IF WE MOVE BALA:

MOVE 'BALA' TO WS-NAME.
MOVE FUNCTION LENGTH(WS-NAME) TO WS-CAL-LENGTH.
DISPLAY WS-CAL-LENGTH.
the variable WS-CAL-LENGTH will have length of what the text u entered in WS-NAME.

Thanks
Balaji K
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6968
Location: porcelain throne

PostPosted: Wed Oct 29, 2008 12:29 pm    Post subject:
Reply with quote

Balaji K,

obviously you have neither tested your code nor read the documentation.

Aji,

When AFTER is specified, counting and/or replacing of the inspected item
(identifier-1) begins with the first character position to the right of the
delimiter and continues toward the rightmost character position in the
inspected item. If no delimiter is present in the inspected item, no counting or
replacement takes place.


possibly:

Code:

Inspect function reverse (ws-name) tallying lding-spaces-count for leading spaces

compute actual-length
      = function length (ws-name) - lding-spaces-count
end-compute


I say possibly, because I,
like both of you,
have not tested the code.
Back to top
View user's profile Send private message
Escapa

Senior Member


Joined: 16 Feb 2007
Posts: 1399
Location: IL, USA

PostPosted: Wed Oct 29, 2008 1:41 pm    Post subject:
Reply with quote

Dick Brenholtz wrote:

I say possibly, because I,
like both of you,
have not tested the code.

No worries icon_smile.gif
It works well icon_biggrin.gif
Back to top
View user's profile Send private message
mmwife

Super Moderator


Joined: 30 May 2003
Posts: 1592

PostPosted: Wed Oct 29, 2008 6:18 pm    Post subject:
Reply with quote

Hi Sambhaji,

If you can guarantee that there will be no interspersed spaces in the field (e.g. "B A L A")', you s/b OK.
Back to top
View user's profile Send private message
Escapa

Senior Member


Joined: 16 Feb 2007
Posts: 1399
Location: IL, USA

PostPosted: Wed Oct 29, 2008 6:45 pm    Post subject:
Reply with quote

Jack wrote:

Hi Sambhaji,

If you can guarantee that there will be no interspersed spaces in the field (e.g. "B A L A")', you s/b OK.

In case of interspersed spaces e.g. "B A L A"
in above example lding-spaces-count will be 5
and so actual-length will be 12 - 5 = 7, Which is correct.
Back to top
View user's profile Send private message
Marso

REXX Moderator


Joined: 13 Mar 2006
Posts: 1232
Location: Israel

PostPosted: Wed Oct 29, 2008 7:07 pm    Post subject:
Reply with quote

Why don't you try your own code by yourself ??? None of the following is working:

Aji wrote:
Inspect text1 tallying leng for trailing spaces.
TRAILING spaces ???

balaji81_k wrote:
01 WS-CAL-LENGTH PIC 9(12).

MOVE 'BALA' TO WS-NAME.
MOVE FUNCTION LENGTH(WS-NAME) TO WS-CAL-LENGTH.
DISPLAY WS-CAL-LENGTH.
the variable WS-CAL-LENGTH will have length of what the text u entered in WS-NAME.
PIC 9(12) because the computer is counting on its 12 fingers ???
All the rest is just plain wrong.
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8118
Location: East Dubuque, Illinois, USA

PostPosted: Wed Oct 29, 2008 7:28 pm    Post subject:
Reply with quote

Dick's code works as presented. I tested it using
Code:
           MOVE 'BALA'                 TO  WS-NAME.
           MOVE ZERO                   TO  LDING-SPACES-COUNT.
           INSPECT FUNCTION REVERSE (WS-NAME)
               TALLYING LDING-SPACES-COUNT
               FOR LEADING SPACES.
           COMPUTE ACTUAL-LENGTH
                 = FUNCTION LENGTH (WS-NAME) - LDING-SPACES-COUNT
           END-COMPUTE.
           DISPLAY WS-NAME ' ' LDING-SPACES-COUNT ' ' ACTUAL-LENGTH.
           MOVE 'B A L A'              TO  WS-NAME.
           MOVE ZERO                   TO  LDING-SPACES-COUNT.
           INSPECT FUNCTION REVERSE (WS-NAME)
               TALLYING LDING-SPACES-COUNT
               FOR LEADING SPACES.
           COMPUTE ACTUAL-LENGTH
                 = FUNCTION LENGTH (WS-NAME) - LDING-SPACES-COUNT
           END-COMPUTE.
           DISPLAY WS-NAME ' ' LDING-SPACES-COUNT ' ' ACTUAL-LENGTH.
and received as output:
Code:
 BALA         08 04
 B A L A      05 07
Back to top
View user's profile Send private message
Terry Heinze

JCL Moderator


Joined: 14 Jul 2008
Posts: 1249
Location: Richfield, MN, USA

PostPosted: Thu Oct 30, 2008 12:11 am    Post subject:
Reply with quote

Also, LENGTH OF WS-NAME can be substituted for FUNCTION LENGTH (WS-NAME).
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 copying data without knowing location arunsoods DFSORT/ICETOOL 6 Thu Jul 20, 2017 1:03 pm
This topic is locked: you cannot edit posts or make replies. Fetching data from BAI File arunsoods JCL & VSAM 1 Wed Jul 19, 2017 4:28 pm
No new posts Loading data to table gives wrong for... Raghu navaikulam DB2 19 Thu Jul 13, 2017 2:11 pm
No new posts SQL - select data available in index Nileshkul DB2 3 Mon Jun 26, 2017 1:30 am
No new posts NDM syntax checking without actually ... GAPX1 All Other Mainframe Topics 0 Wed Jun 07, 2017 2:36 am


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