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

Find the length of data


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
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
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
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

Active User


Joined: 29 Jun 2005
Posts: 155

PostPosted: Wed Oct 29, 2008 10:46 am
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: 6966
Location: porcelain throne

PostPosted: Wed Oct 29, 2008 12:29 pm
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
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
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
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: 1353
Location: Israel

PostPosted: Wed Oct 29, 2008 7:07 pm
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: 8697
Location: Dubuque, Iowa, USA

PostPosted: Wed Oct 29, 2008 7:28 pm
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
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 View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts How to save SYSLOG as text data via P... All Other Mainframe Topics 2
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 Data set Rec-Cnt and Byte-Cnt Testing & Performance 2
Search our Forums:

Back to Top