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
 

 

String length Calculation

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

New User


Joined: 17 Sep 2008
Posts: 41
Location: Chennai

PostPosted: Tue Apr 12, 2011 12:03 pm    Post subject: String length Calculation
Reply with quote

Hi,

I need to calculate the length of a string coming in a 60byte field. The string varies every time its input to the system. So it could be like below,
Code:

----+----1----+----2----+----3----+----4----+----5----+----6
123456789012345678901234567890123456789012345678901234567890
Sales Information
AAAA                                                     123
$xyz                         vvv


I need to calculate eliminiating any trailing spaces. In the above example the 1st line should return 17 as its length and 2nd one should return 60 and 3rd should return 32 as its length.
Hope i am clear on the above.
Can anyone guide me please.

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

enrico-sorichetti

Global Moderator


Joined: 14 Mar 2007
Posts: 10202
Location: italy

PostPosted: Tue Apr 12, 2011 12:09 pm    Post subject: Reply to: String length Calculation
Reply with quote

please learn to post properly using the code tags,
it will make possible to understand Your issues and will save the moderators the time spent editing Your posts to make them readable/understandable

- the way the records were posted originally made just impossible to understand the real payload lengths
Back to top
View user's profile Send private message
Bill Woodger

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7232

PostPosted: Tue Apr 12, 2011 12:11 pm    Post subject:
Reply with quote

Redefine your 60 bytes as an OCCURS PIC X, then with your subscript/index at 60, start checking for a blank. If blank, go down one with your subscript/index etc. If non-blank you have the last one. Watch out for the entire field being space, the no-trailing-spaces example you already have.
Back to top
View user's profile Send private message
Bill O'Boyle

CICS Moderator


Joined: 14 Jan 2008
Posts: 2502
Location: Atlanta, Georgia, USA

PostPosted: Tue Apr 12, 2011 12:15 pm    Post subject: Reply to: String length Calculation
Reply with quote

Review the following and modify accordingly -

http://www.ibmmainframes.com/viewtopic.php?p=143786&highlight=#143786

Bill
Back to top
View user's profile Send private message
Bill Woodger

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7232

PostPosted: Tue Apr 12, 2011 12:17 pm    Post subject:
Reply with quote

I should have "previewed". When I said "OCCURS PIC X" I wasn't intending to provide the exact code for you. I meant "with an OCCURS" with the PICTURE of a single X (ie one byte).
Back to top
View user's profile Send private message
Anuj Dhawan

Senior Member


Joined: 22 Apr 2006
Posts: 6258
Location: Mumbai, India

PostPosted: Tue Apr 12, 2011 12:23 pm    Post subject:
Reply with quote

Quote:
length of a string coming in a 60byte field
"string" - COBOL does not have strings. COBOL has variables that can be numeric, alphanumeric, national, DBCS etc. but never string.

Again, COBOL does not have the concept of strings such as C (that is, where the length of the variable changes at run time). COBOL variables have fixed sizes and that size is fixed at compile time. So when you say "60-byte" -- it's "60-bytes"; no less, no more!

So what is the COBOL defintion of the variable you read-into your input?
Are you talikng about single input-file or multiple inputs with different lengths?
Back to top
View user's profile Send private message
Bill Woodger

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7232

PostPosted: Tue Apr 12, 2011 1:10 pm    Post subject: Re: Reply to: String length Calculation
Reply with quote

Bill O'Boyle wrote:
Review the following and modify accordingly -

http://www.ibmmainframes.com/viewtopic.php?p=143786&highlight=#143786

Bill


Slightly "over-the-top" for the request? Just needs the legnth excluding trailing blanks.

Another Bill
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


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

PostPosted: Tue Apr 12, 2011 2:39 pm    Post subject:
Reply with quote

Bill Woodger wrote:
Slightly "over-the-top" for the request? Just needs the legnth (sic) excluding trailing blanks


actually not.
when we are not berating posters for failing to search,
we tend to give them (what newbees may consider) 'too much info'.

the TS (topic starter) has made 27 posts,
has no profile, no ability to send a PM to him,
and asks a question that
  • should have been posted in the rookies/students forum
  • obviously has not bothered to search

deserved to have some reasonably sophisticated code thrown at him
that he should parse and use what he needs.
at the same time he (as well as other members/guests - who do search) can learn something.

The answer to the TS's problem can also be satisfied with an
INSPECT REVERSE(element-name) TALLYING FOR LEADING SPACES,
which essentially is much easier code to understand at first glance
and is compact,
and depending on the box and COBOL release can be very efficient.

all three solutions (Bill's, yours, and the INSPECT) can be found easily by searching.

I also consider your comment to be something that should have been handled with a PM to Bill.
Mine also,
but you did not,
so I did not.

Welcome to the forum, by the way.
Back to top
View user's profile Send private message
Bill Woodger

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7232

PostPosted: Tue Apr 12, 2011 3:08 pm    Post subject:
Reply with quote

dbzTHEdinosauer wrote:

Welcome to the forum, by the way.


Thank you. I appreciate it.

I'm very sorry, the other Bill, I intended no criticism in any way. When I looked at all the code, I just thought... Wow.

I am pretty new to posting in forums, and am unaware of the etiquette here or anywhere else. Still am. I'll have to search around.

What I might deduce so far is that if the question is simplistic or idiotic there are no-holds-barred, if you have a brain and lots of posts and I don't have lots of posts (state of brain unknown to others) I PM, otherwise those with brains and posts can comment publicly like I did in error this time? :-)

OK, I'm good with that, although if I ever get to lots of posts I think I'll just PM (it does seem more polite and I wouldn't want to presume at what stage others might think I'm worthy!).
Back to top
View user's profile Send private message
Vidya Bhama

New User


Joined: 17 Sep 2008
Posts: 41
Location: Chennai

PostPosted: Tue Apr 12, 2011 3:10 pm    Post subject:
Reply with quote

Thanks for the quick response.

@Enrico & Anuj I will take care in future to check that i have posted the code properly. Thanks for this time and info provided.

@Bill & Bill : Thanks for the solution. The single byte check worked as expected.

Regards,
Vidya
Back to top
View user's profile Send private message
Phrzby Phil

Active Member


Joined: 31 Oct 2006
Posts: 961
Location: Richmond, Virginia

PostPosted: Tue Apr 12, 2011 5:36 pm    Post subject:
Reply with quote

Bill -

Stay tuned for a while and you'll see that the etiquette here varies most interestingly.
Back to top
View user's profile Send private message
Bill Woodger

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7232

PostPosted: Tue Apr 12, 2011 9:58 pm    Post subject:
Reply with quote

Phrzby Phil wrote:
Bill -

Stay tuned for a while and you'll see that the etiquette here varies most interestingly.


Thanks. I'll try. :-)
Back to top
View user's profile Send private message
Balaji Krishnamurthy

New User


Joined: 26 Feb 2008
Posts: 20
Location: chennai

PostPosted: Thu Apr 21, 2011 2:22 pm    Post subject: String length Calculation
Reply with quote

http://ibmmainframes.com/about4550.html
Back to top
View user's profile Send private message
PeterHolland

Global Moderator


Joined: 27 Oct 2009
Posts: 2422
Location: Netherlands, Amstelveen

PostPosted: Thu Apr 21, 2011 2:32 pm    Post subject:
Reply with quote

Intrinsic function LENGTH could do the job.
Back to top
View user's profile Send private message
Bill Woodger

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7232

PostPosted: Thu Apr 21, 2011 3:48 pm    Post subject: Re: String length Calculation
Reply with quote

Balaji Krishnamurthy wrote:
http://ibmmainframes.com/about4550.html


Is this a new question?
Back to top
View user's profile Send private message
Anuj Dhawan

Senior Member


Joined: 22 Apr 2006
Posts: 6258
Location: Mumbai, India

PostPosted: Mon Apr 25, 2011 4:04 pm    Post subject: Re: String length Calculation
Reply with quote

Bill Woodger wrote:
Balaji Krishnamurthy wrote:
http://ibmmainframes.com/about4550.html


Is this a new question?
No - he is referring to another, similar, discussion.
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 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
This topic is locked: you cannot edit posts or make replies. Checking wether a string starts from ... sundaram.naveen CLIST & REXX 9 Thu Oct 06, 2016 11:56 am
No new posts Format to pipe delimited with variabl... pshongal SYNCSORT 6 Wed Sep 14, 2016 2:48 pm
No new posts Random Password (in string format) ge... ezhavendhan COBOL Programming 10 Mon Aug 29, 2016 3:18 pm


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