Is this a case of just having to provide my own LE-enabled HLASM
implementation, or could I pull something quick-and-dirty like using the
C-library version of the index function?
Business need: Scan an input string value for "contains" a given
argument string anywhere inside the input string. Invariant: Length of
argument string always <= length of input string.
In REXX, I would say:
IF (POS(needle,haystack) > 0) ; THEN (Found it, do whatever is needed)
ELSE (Not there, do whatever business logic requires when absent)
where "needle" is the argument string and "haystack" is the input
string.
I've dl'd the latest CBT and COV indexes to see if this particular wheel
has already been invented and contributed, but it doesn't look like it
on first glance. Still looking though, I'll post back if I find
anything.
TIA for any info/url/RTFM you can provide.
Peter
This message and any attachments are intended only for the use of the addressee and
may contain information that is privileged and confidential. If the reader of the
message is not the intended recipient or an authorized representative of the
intended recipient, you are hereby notified that any dissemination of this
communication is strictly prohibited. If you have received this communication in
error, please notify us immediately by e-mail and delete the message and any
attachments from your system.
----------------------------------------------------------------------
For IBM-MAIN subscribe / signoff / archive access instructions,
send email to list...@bama.ua.edu with the message: GET IBM-MAIN INFO
Search the archives at http://bama.ua.edu/archives/ibm-main.html
Where did you get that idea?
How about:
inspect trans-image tallying sel-ptr for characters
before 'SELECT '
inspect trans-image tallying spa-ptr for all ' '
before 'SELECT '
inspect trans-image tallying art-ptr for characters
before 'ARTIST='
inspect trans-image tallying tme-ptr for characters
before 'TIME='
That is, if you are looking for a string, inspect and
count the characters before the string; if the value is
0, the string is at the front. if the value equals the
size of your haystack, the string is not there.
More generally, perhaps:
inspect haystack tallying loc-ctr for characters before needle
You could also do:
inspect haystack tallying occ-ctr for all needle
to count the number of occurrences, which may be closer
to what you're after.
<ad>
String handling, and a whole lot more, are discussed
in our three-day class "Advanced Topics in COBOL".
Details at:
http://www.trainersfriend.com/COBOL_Courses/D725descrpt.htm
</ad>
>
> Is this a case of just having to provide my own LE-enabled HLASM
> implementation, or could I pull something quick-and-dirty like using the
> C-library version of the index function?
>
> Business need: Scan an input string value for "contains" a given
> argument string anywhere inside the input string. Invariant: Length of
> argument string always <= length of input string.
>
> In REXX, I would say:
>
> IF (POS(needle,haystack) > 0) ; THEN (Found it, do whatever is needed)
> ELSE (Not there, do whatever business logic requires when absent)
>
> where "needle" is the argument string and "haystack" is the input
> string.
>
> I've dl'd the latest CBT and COV indexes to see if this particular wheel
> has already been invented and contributed, but it doesn't look like it
> on first glance. Still looking though, I'll post back if I find
> anything.
>
> TIA for any info/url/RTFM you can provide.
>
Kind regards,
-Steve Comstock
The Trainer's Friend, Inc.
303-393-8716
http://www.trainersfriend.com
z/OS Application development made easier
* Our classes include
+ How things work
+ Programming examples with realistic applications
+ Starter / skeleton code
+ Complete working programs
+ Useful utilities and subroutines
+ Tips and techniques
==> call or email to receive a free sample student handout <==
INSPECT WS-HAYSTACK
TALLYING WS-CHAR-TOTAL
FOR CHARACTERS
BEFORE INITIAL
WS-NEEDLE
IF WS-CHAR-TOTAL < LENGTH OF WS-HAYSTACK
....then you have a hit
ELSE
..... no hit.
END-IF
WS-NEEDLE can be any size. Often, it is expressed as:
WS-NEEDLE(1:ws-last-nonblank-char)
....where ws-last-nonblank-char is, as the name implies, the position
of the last nonblank character in WS-NEEDLE.
inspect haystack tallying loc-ctr for characters before needle
inspect haystack tallying loc-ctr for characters before needle
<Unsnip>
Well, it really is true you learn something new every day. I did not
realize that the BEFORE/AFTER could be more than one character.
Thank you very much!
Peter
P.S. -- I truly do wish I could take your classes. Unfortunately I'm
not in charge of budgets.
This message and any attachments are intended only for the use of the addressee and
may contain information that is privileged and confidential. If the reader of the
message is not the intended recipient or an authorized representative of the
intended recipient, you are hereby notified that any dissemination of this
communication is strictly prohibited. If you have received this communication in
error, please notify us immediately by e-mail and delete the message and any
attachments from your system.
----------------------------------------------------------------------
Actually, INSPECT is not limited to single characters.
<Snipped>
Which I did not know and Steve also pointed out. Thank you also for
helping to cure my ignorance.
I've always resorted to an inline perform loop with reference
modification compares...
<Snipped>
Yes, that obviously would work, but I was looking for a less brute-force
solution. Hmm-m-m. I wonder which would be more efficient, for a range
of sizes of "needles"? INSPECT or inline performs?
Maybe I'll work that out if I can find any of those pesky round tuits
anywhere.
Thanks.
Peter
This message and any attachments are intended only for the use of the addressee and
may contain information that is privileged and confidential. If the reader of the
message is not the intended recipient or an authorized representative of the
intended recipient, you are hereby notified that any dissemination of this
communication is strictly prohibited. If you have received this communication in
error, please notify us immediately by e-mail and delete the message and any
attachments from your system.
----------------------------------------------------------------------
>I have been looking around, but there doesn't seem to be an Enterprise
>COBOL equivalent of the INDEX() or POS() string function anywhere
>
>TIA for any info/url/RTFM you can provide.
>
Boyer-Moore?
Linkname: Boyer-Moore string search algorithm - Wikipedia, the free encyclopedia
URL: http://en.wikipedia.org/wiki/Boyer%E2%80%93Moore_string_search_algorithm
... or is that too PFCSK for a COBOL programmer?
-- gil
Besides, for all I know the INSPECT verb may use Boyer-Moore under the covers.
Sophisticated, efficient -- I love it. Thanks for the reference, that
one goes into my keep list.
But as Don said, that's *way* too much work when INSPECT provides what I
need, as do the index() or pos() function in other languages.
Yes, I do understand and solve problems in more then one (computer)
language. Programmers who are fluent in COBOL are not limited to that
language skill, they are only limited by what business will pay them to
support.
Thanks again for the interesting reference.
Peter
This message and any attachments are intended only for the use of the addressee and
may contain information that is privileged and confidential. If the reader of the
message is not the intended recipient or an authorized representative of the
intended recipient, you are hereby notified that any dissemination of this
communication is strictly prohibited. If you have received this communication in
error, please notify us immediately by e-mail and delete the message and any
attachments from your system.
----------------------------------------------------------------------
Exactly. In many shops, a COBOL programmer who coded a Boyer-Moore
algorithm would be in serious trouble with his project lead. :-)