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

String length Calculation


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

Superior Member


Joined: 14 Mar 2007
Posts: 10873
Location: italy

PostPosted: Tue Apr 12, 2011 12:09 pm
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

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Tue Apr 12, 2011 12:11 pm
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: 2501
Location: Atlanta, Georgia, USA

PostPosted: Tue Apr 12, 2011 12:15 pm
Reply with quote

Review the following and modify accordingly -

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

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

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Tue Apr 12, 2011 12:17 pm
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

Superior Member


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

PostPosted: Tue Apr 12, 2011 12:23 pm
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

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Tue Apr 12, 2011 1:10 pm
Reply with quote

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

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
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

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Tue Apr 12, 2011 3:08 pm
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
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

Senior Member


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

PostPosted: Tue Apr 12, 2011 5:36 pm
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

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Tue Apr 12, 2011 9:58 pm
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
Reply with quote

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

Global Moderator


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

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

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

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Thu Apr 21, 2011 3:48 pm
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

Superior Member


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

PostPosted: Mon Apr 25, 2011 4:04 pm
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 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 Replace each space in cobol string wi... COBOL Programming 3
No new posts PARSE Syntax for not fix length word ... JCL & VSAM 7
No new posts Sortjoin and Search for a String and ... DFSORT/ICETOOL 1
Search our Forums:

Back to Top