×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

REXX Loop

REXX Loop

REXX Loop

(OP)
Hello all,
I'm having some difficulty looping through a queued() list and retrieving only information that's displayed more than 5 times. I have working JCL which uses PGM=ISRSUPC and scans through the syslog gathering information. I then use REXX coding to iterate through that information and only show the information needed. I would like to use REXX to loop through this information and only display entries that occur more than 5 times. Basically I'd like to grab the first entry then loop through the dataset seeing if it occurs more than 5 times, if so, then queue that information and move onto the next entry and perform the same task. Any information would be greatly appreciated. Thanks

RE: REXX Loop

Hi Cweinber21,

First iterate over the queue with DO WHILE QUEUED() and extract all queue items with PARSE PULL and count their occurrence into a stem.
Than you can iterate over your stem and select only those items which occurrence is more than 5.

Here is an little example: cweinber21.rex

CODE

/* create queue of some items */
queue "foo"
queue "bar"
queue "baz"
queue "foo"
queue "bar"
queue "baz"
queue "spam"
queue "eggs"
queue "foo"
queue "foo"
queue "foo"
queue "foo"
queue "spam"
queue "spam"
queue "spam"
queue "spam"
queue "spam"
queue "spam"
queue "spam"
queue "spam"
queue "foo"
queue "bar"
queue "baz"
queue "spam"
queue "eggs"
queue "foobar"

/* add queued items occurrence into stem */
occurs. = 0
do while queued() <> 0
  parse pull item
  --say item
  /* count item occurrences */
  occurs.item = occurs.item + 1
end

/* show the occurrence of individual items */
say 'all queue items occurrence:'
do item over occurs.
 say item '-->' occurs.item
end
say

/* display only those items which occurs more than 5 times */
say 'items that occur more than 5 times:' 
do item over occurs.
  if occurs.item > 5 then do
    say "item '"item"'" 'occurs in the queue' occurs.item 'times.'
  end
end 

Output:

CODE

$ rexx cweinber21.rex
all queue items occurrence:
baz --> 3
bar --> 3
eggs --> 2
foobar --> 1
spam --> 10
foo --> 7

items that occur more than 5 times:
item 'spam' occurs in the queue 10 times.
item 'foo' occurs in the queue 7 times. 

RE: REXX Loop

(OP)
Thanks for the quick reply Mikrom. I haven't used the Do -- Over coding before. Unfortunately when running this I'm receiving an error "Invalid whole number". I've been testing my code and even created a member and tried your code and I'm receiving the same error. Have you seen this error before? I'll continue messing around. Thanks again for the information

RE: REXX Loop

DO OVER is probably not standard REXX, but only enhancement in Open Object REXX which I'm using.

RE: REXX Loop

So, I try it now differently using standard REXX functionality only, but here I additionally need a list of unique items.

Now try this:

CODE

/* create queue of some items */
queue "foo"
queue "bar"
queue "baz"
queue "foo"
queue "bar"
queue "baz"
queue "spam"
queue "eggs"
queue "foo"
queue "foo"
queue "foo"
queue "foo"
queue "spam"
queue "spam"
queue "spam"
queue "spam"
queue "spam"
queue "spam"
queue "spam"
queue "spam"
queue "foo"
queue "bar"
queue "baz"
queue "spam"
queue "eggs"
queue "foobar"

/* add queued items occurrence into stem */
occurs. = 0
items_list = ''
do while queued() <> 0
  parse pull item
  --say item
  /* add item to items_list if not present */
  if wordpos(item, items_list) = 0 then do
    items_list = items_list item
  end  
  /* count item occurrences */
  occurs.item = occurs.item + 1
end

/* show the occurrence of individual items */
say 'all queue items occurrence:'
do j=1 to words(items_list)
  item = word(items_list, j)
  say item '-->' occurs.item
end
say

/* display only those items which occurs more than 5 times */
say 'items that occur more than 5 times:' 
do j=1 to words(items_list)
  item = word(items_list, j)
  if occurs.item > 5 then do
    say "item '"item"'" 'occurs in the queue' occurs.item 'times.'
  end
end 

Output:

CODE

$ rexx cweinber21.rex
all queue items occurrence:
foo --> 7
bar --> 3
baz --> 3
spam --> 10
eggs --> 2
foobar --> 1

items that occur more than 5 times:
item 'foo' occurs in the queue 7 times.
item 'spam' occurs in the queue 10 times. 

Hopefully this will work for you.

RE: REXX Loop

And here is a little modification where items_list is not a big string delimited by spaces, but other stem.
It should work for you too.

CODE

/* create queue of some items */
queue "foo"
queue "bar"
queue "baz"
queue "foo"
queue "bar"
queue "baz"
queue "spam"
queue "eggs"
queue "foo"
queue "foo"
queue "foo"
queue "foo"
queue "spam"
queue "spam"
queue "spam"
queue "spam"
queue "spam"
queue "spam"
queue "spam"
queue "spam"
queue "foo"
queue "bar"
queue "baz"
queue "spam"
queue "eggs"
queue "foobar"

/* add queued items occurrence into stem */
occurs. = 0
nr_items = 0
items_list. = ''
do while queued() <> 0
  parse pull item
  --say item
  /* add item to items_list if not present */
  if occurs.item = 0 then do
    nr_items = nr_items + 1
    items_list.nr_items = item
  end  
  /* count item occurrences */
  occurs.item = occurs.item + 1
end

/* show the occurrence of individual items */
say 'all queue items occurrence:'
do j=1 to nr_items
  item = items_list.j
  say item '-->' occurs.item
end
say

/* display only those items which occurs more than 5 times */
say 'items that occur more than 5 times:' 
do j=1 to nr_items
  item = items_list.j
  if occurs.item > 5 then do
    say "item '"item"'" 'occurs in the queue' occurs.item 'times.'
  end
end 

RE: REXX Loop

(OP)
Thanks Mikrom. Yea DO OVER isn't support here :( I was modifying the original coding and it looks like I was on the right track since I had sorta the same information you just provided. With what I have and your information, I should be good. I appreciate the help

RE: REXX Loop

Ok, I wish you good luck

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close