Skip to main content

[archive] Inspect Tallying!!!

  • December 7, 2009
  • 7 replies
  • 0 views

[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

7 replies

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

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

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

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

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

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

[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
Thanks for the fast response.
Both solutions are working excellent.
Thanks again.....