View previous topic :: View next topic
|
Author |
Message |
Vidya Bhama
New User
Joined: 17 Sep 2008 Posts: 41 Location: Chennai
|
|
|
|
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 |
|
|
enrico-sorichetti
Superior Member
Joined: 14 Mar 2007 Posts: 10873 Location: italy
|
|
|
|
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 |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
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 |
|
|
Bill O'Boyle
CICS Moderator
Joined: 14 Jan 2008 Posts: 2501 Location: Atlanta, Georgia, USA
|
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
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 |
|
|
Anuj Dhawan
Superior Member
Joined: 22 Apr 2006 Posts: 6250 Location: Mumbai, India
|
|
|
|
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 |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
Slightly "over-the-top" for the request? Just needs the legnth excluding trailing blanks.
Another Bill |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
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 |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
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 |
|
|
Vidya Bhama
New User
Joined: 17 Sep 2008 Posts: 41 Location: Chennai
|
|
|
|
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 |
|
|
Phrzby Phil
Senior Member
Joined: 31 Oct 2006 Posts: 1042 Location: Richmond, Virginia
|
|
|
|
Bill -
Stay tuned for a while and you'll see that the etiquette here varies most interestingly. |
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
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 |
|
|
Balaji Krishnamurthy
New User
Joined: 26 Feb 2008 Posts: 20 Location: chennai
|
|
Back to top |
|
|
PeterHolland
Global Moderator
Joined: 27 Oct 2009 Posts: 2481 Location: Netherlands, Amstelveen
|
|
|
|
Intrinsic function LENGTH could do the job. |
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
Balaji Krishnamurthy wrote: |
http://ibmmainframes.com/about4550.html |
Is this a new question? |
|
Back to top |
|
|
Anuj Dhawan
Superior Member
Joined: 22 Apr 2006 Posts: 6250 Location: Mumbai, India
|
|
|
|
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 |
|
|
|