Highlighted
Absent Member.
Absent Member.
954 views

[archive] Inspect Tallying!!!

[Migrated content. Thread originally posted on 07 December 2009]

Hi,

Using INSPECT statement to search a record for exact text works like:

77 my-field pic x(100).
INSPECT my-field TALLYING mycounter FOR all 'test'

if the word 'test' exists in my-field, the mycounter will be incremented by 1.
this works fine.

But mycounter is never incremented by 1 when using the statement like:

77 my-field pic x(100).
77 my-search-field pic x(10).

inspect my-field TALLYING mycounter FOR all my-search-field
where my-seach-field is a data-field in the WS contains what the user types.

I've tried to replaces all the trailing spaces in my-search-field by Nulls but it didn't work also.:mad:

Any tips?
Thanks
0 Likes
4 Replies
Highlighted
Absent Member.
Absent Member.

RE: [archive] Inspect Tallying!!!

I use same logic in some of my programs, and you probably need to do something like the following.

MOVE ZEROS TO mycounter, space-ctr.
IF my-search-field NOT = SPACES
   INSPECT my-search-field TALLYING space-ctr FOR TRAILING " "
   COMPUTE space-ctr  =
        FUNCTION LENGTH(my-search-field) - space-ctr
   END-COMPUTE
   INSPECT my-field TALLYING mycounter FOR ALL my-search-field(1:space-ctr)
END-IF.
0 Likes
Highlighted
Absent Member.
Absent Member.

RE: [archive] Inspect Tallying!!!

my solution:


       test-search section.
[COLOR="Red"]*** my fields from WS ***[/COLOR]
      * 77  my-field                pic x(100)    value "AbA test AbA".
      * 77  my-search               pic x(10)     value "test".
      * 77  counter                 pic 9(3)      value zeroes.
      * 77  h-count                 pic 9(3)      value zeroes.
      * 77  h-range                 pic 9(3)      value zeroes.

           move    zeroes to counter.
           inspect my-field tallying counter for all "test".
           display message box counter.
[COLOR="Red"]*** Result - 1 ***[/COLOR]

           move    zeroes to counter.
           inspect my-field tallying counter for all my-search.
           display message box counter.
[COLOR="Red"]*** Result - 0 = your problem ***[/COLOR]

           move    zeroes to counter.
           move    zeroes to h-count.
           inspect my-search tallying h-count for trailing spaces.
           compute h-range = 10 - h-count.
           inspect my-field tallying counter
                   for all my-search(1:h-range).
           display message box counter.
[COLOR="Red"]*** Result - 1 = my solution ***[/COLOR]

       test-search-ende.
           exit.
       test-search-e.
0 Likes
Highlighted
Absent Member.
Absent Member.

RE: [archive] Inspect Tallying!!!

Yes - you will need to inspect a certain length of field.
here's exactly what we do.
You can see we even convert both strings to the same case for comparisons

INSPECT WS-STA-CUST-ORD-NO CONVERTING "abcdefghijklmnopqrstuvwxyz"
                           TO         "ABCDEFGHIJKLMNOPQRSTUVWXYZ"

INSPECT WS-STA-CUST-ORD-NO TALLYING WS-COUNT
                              FOR ALL S-RANGE-SEARCH (1:WS-LEN)
0 Likes
Highlighted
Absent Member.
Absent Member.

RE: [archive] Inspect Tallying!!!

Thanks for the fast response.
Both solutions are working excellent.
Thanks again.....
0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.