Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

REXX Loop

Status
Not open for further replies.

Cweinber21

Technical User
Sep 13, 2018
6
US
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
 
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:
[COLOR=#0000ff]/* create queue of some items */[/color]
[COLOR=#a52a2a][b]queue[/b][/color] [COLOR=#ff00ff]"foo"[/color]
[COLOR=#a52a2a][b]queue[/b][/color] [COLOR=#ff00ff]"bar"[/color]
[COLOR=#a52a2a][b]queue[/b][/color] [COLOR=#ff00ff]"baz"[/color]
[COLOR=#a52a2a][b]queue[/b][/color] [COLOR=#ff00ff]"foo"[/color]
[COLOR=#a52a2a][b]queue[/b][/color] [COLOR=#ff00ff]"bar"[/color]
[COLOR=#a52a2a][b]queue[/b][/color] [COLOR=#ff00ff]"baz"[/color]
[COLOR=#a52a2a][b]queue[/b][/color] [COLOR=#ff00ff]"spam"[/color]
[COLOR=#a52a2a][b]queue[/b][/color] [COLOR=#ff00ff]"eggs"[/color]
[COLOR=#a52a2a][b]queue[/b][/color] [COLOR=#ff00ff]"foo"[/color]
[COLOR=#a52a2a][b]queue[/b][/color] [COLOR=#ff00ff]"foo"[/color]
[COLOR=#a52a2a][b]queue[/b][/color] [COLOR=#ff00ff]"foo"[/color]
[COLOR=#a52a2a][b]queue[/b][/color] [COLOR=#ff00ff]"foo"[/color]
[COLOR=#a52a2a][b]queue[/b][/color] [COLOR=#ff00ff]"spam"[/color]
[COLOR=#a52a2a][b]queue[/b][/color] [COLOR=#ff00ff]"spam"[/color]
[COLOR=#a52a2a][b]queue[/b][/color] [COLOR=#ff00ff]"spam"[/color]
[COLOR=#a52a2a][b]queue[/b][/color] [COLOR=#ff00ff]"spam"[/color]
[COLOR=#a52a2a][b]queue[/b][/color] [COLOR=#ff00ff]"spam"[/color]
[COLOR=#a52a2a][b]queue[/b][/color] [COLOR=#ff00ff]"spam"[/color]
[COLOR=#a52a2a][b]queue[/b][/color] [COLOR=#ff00ff]"spam"[/color]
[COLOR=#a52a2a][b]queue[/b][/color] [COLOR=#ff00ff]"spam"[/color]
[COLOR=#a52a2a][b]queue[/b][/color] [COLOR=#ff00ff]"foo"[/color]
[COLOR=#a52a2a][b]queue[/b][/color] [COLOR=#ff00ff]"bar"[/color]
[COLOR=#a52a2a][b]queue[/b][/color] [COLOR=#ff00ff]"baz"[/color]
[COLOR=#a52a2a][b]queue[/b][/color] [COLOR=#ff00ff]"spam"[/color]
[COLOR=#a52a2a][b]queue[/b][/color] [COLOR=#ff00ff]"eggs"[/color]
[COLOR=#a52a2a][b]queue[/b][/color] [COLOR=#ff00ff]"foobar"[/color]

[COLOR=#0000ff]/* add queued items occurrence into stem */[/color]
occurs. [COLOR=#a52a2a][b]=[/b][/color] 0
[COLOR=#a52a2a][b]do [/b][/color][COLOR=#a52a2a][b]while[/b][/color][COLOR=#a52a2a][b] [/b][/color][COLOR=#008b8b]queued()[/color] [COLOR=#a52a2a][b]<>[/b][/color] 0
  [COLOR=#a52a2a][b]parse pull[/b][/color] item
  [COLOR=#0000ff]--say item[/color]
  [COLOR=#0000ff]/* count item occurrences */[/color]
  occurs.item [COLOR=#a52a2a][b]=[/b][/color] occurs.item + 1
[COLOR=#a52a2a][b]end[/b][/color]

[COLOR=#0000ff]/* show the occurrence of individual items */[/color]
[COLOR=#a52a2a][b]say[/b][/color] [COLOR=#ff00ff]'all queue items occurrence:'[/color]
[COLOR=#a52a2a][b]do item [/b][/color][COLOR=#a52a2a][b]over[/b][/color] occurs.
 [COLOR=#a52a2a][b]say[/b][/color] item [COLOR=#ff00ff]'-->'[/color] occurs.item
[COLOR=#a52a2a][b]end[/b][/color]
[COLOR=#a52a2a][b]say[/b][/color]

[COLOR=#0000ff]/* display only those items which occurs more than 5 times */[/color]
[COLOR=#a52a2a][b]say[/b][/color] [COLOR=#ff00ff]'items that occur more than 5 times:'[/color] 
[COLOR=#a52a2a][b]do item [/b][/color][COLOR=#a52a2a][b]over[/b][/color] occurs.
  [COLOR=#a52a2a][b]if[/b][/color] occurs.item [COLOR=#a52a2a][b]>[/b][/color] 5 [COLOR=#a52a2a][b]then[/b][/color] [COLOR=#a52a2a][b]do[/b][/color]
    [COLOR=#a52a2a][b]say[/b][/color] [COLOR=#ff00ff]"item '"[/color]item[COLOR=#ff00ff]"'"[/color] [COLOR=#ff00ff]'occurs in the queue'[/color] occurs.item [COLOR=#ff00ff]'times.'[/color]
  [COLOR=#a52a2a][b]end[/b][/color]
[COLOR=#a52a2a][b]end[/b][/color]

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.
 
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
 
DO OVER is probably not standard REXX, but only enhancement in Open Object REXX which I'm using.
 
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:
[COLOR=#0000ff]/* create queue of some items */[/color]
[COLOR=#804040][b]queue[/b][/color] [COLOR=#ff00ff]"foo"[/color]
[COLOR=#804040][b]queue[/b][/color] [COLOR=#ff00ff]"bar"[/color]
[COLOR=#804040][b]queue[/b][/color] [COLOR=#ff00ff]"baz"[/color]
[COLOR=#804040][b]queue[/b][/color] [COLOR=#ff00ff]"foo"[/color]
[COLOR=#804040][b]queue[/b][/color] [COLOR=#ff00ff]"bar"[/color]
[COLOR=#804040][b]queue[/b][/color] [COLOR=#ff00ff]"baz"[/color]
[COLOR=#804040][b]queue[/b][/color] [COLOR=#ff00ff]"spam"[/color]
[COLOR=#804040][b]queue[/b][/color] [COLOR=#ff00ff]"eggs"[/color]
[COLOR=#804040][b]queue[/b][/color] [COLOR=#ff00ff]"foo"[/color]
[COLOR=#804040][b]queue[/b][/color] [COLOR=#ff00ff]"foo"[/color]
[COLOR=#804040][b]queue[/b][/color] [COLOR=#ff00ff]"foo"[/color]
[COLOR=#804040][b]queue[/b][/color] [COLOR=#ff00ff]"foo"[/color]
[COLOR=#804040][b]queue[/b][/color] [COLOR=#ff00ff]"spam"[/color]
[COLOR=#804040][b]queue[/b][/color] [COLOR=#ff00ff]"spam"[/color]
[COLOR=#804040][b]queue[/b][/color] [COLOR=#ff00ff]"spam"[/color]
[COLOR=#804040][b]queue[/b][/color] [COLOR=#ff00ff]"spam"[/color]
[COLOR=#804040][b]queue[/b][/color] [COLOR=#ff00ff]"spam"[/color]
[COLOR=#804040][b]queue[/b][/color] [COLOR=#ff00ff]"spam"[/color]
[COLOR=#804040][b]queue[/b][/color] [COLOR=#ff00ff]"spam"[/color]
[COLOR=#804040][b]queue[/b][/color] [COLOR=#ff00ff]"spam"[/color]
[COLOR=#804040][b]queue[/b][/color] [COLOR=#ff00ff]"foo"[/color]
[COLOR=#804040][b]queue[/b][/color] [COLOR=#ff00ff]"bar"[/color]
[COLOR=#804040][b]queue[/b][/color] [COLOR=#ff00ff]"baz"[/color]
[COLOR=#804040][b]queue[/b][/color] [COLOR=#ff00ff]"spam"[/color]
[COLOR=#804040][b]queue[/b][/color] [COLOR=#ff00ff]"eggs"[/color]
[COLOR=#804040][b]queue[/b][/color] [COLOR=#ff00ff]"foobar"[/color]

[COLOR=#0000ff]/* add queued items occurrence into stem */[/color]
occurs. [COLOR=#804040][b]=[/b][/color] 0
items_list [COLOR=#804040][b]=[/b][/color] [COLOR=#ff00ff]''[/color]
[COLOR=#804040][b]do [/b][/color][COLOR=#804040][b]while[/b][/color][COLOR=#804040][b] [/b][/color][COLOR=#008080]queued()[/color] [COLOR=#804040][b]<>[/b][/color] 0
  [COLOR=#804040][b]parse pull[/b][/color] item
  [COLOR=#0000ff]--say item[/color]
  [COLOR=#0000ff]/* add item to items_list if not present */[/color]
  [COLOR=#804040][b]if[/b][/color] [COLOR=#008080]wordpos([/color]item[COLOR=#804040][b],[/b][/color] items_list[COLOR=#008080])[/color] [COLOR=#804040][b]=[/b][/color] 0 [COLOR=#804040][b]then[/b][/color] [COLOR=#804040][b]do[/b][/color]
    items_list [COLOR=#804040][b]=[/b][/color] items_list item
  [COLOR=#804040][b]end[/b][/color]  
  [COLOR=#0000ff]/* count item occurrences */[/color]
  occurs.item [COLOR=#804040][b]=[/b][/color] occurs.item [COLOR=#804040][b]+[/b][/color] 1
[COLOR=#804040][b]end[/b][/color]

[COLOR=#0000ff]/* show the occurrence of individual items */[/color]
[COLOR=#804040][b]say[/b][/color] [COLOR=#ff00ff]'all queue items occurrence:'[/color]
[COLOR=#804040][b]do[/b][/color] j[COLOR=#804040][b]=[/b][/color]1 [COLOR=#804040][b]to[/b][/color] [COLOR=#008080]words([/color]items_list[COLOR=#008080])[/color]
  item [COLOR=#804040][b]=[/b][/color] [COLOR=#008080]word([/color]items_list[COLOR=#804040][b],[/b][/color] j[COLOR=#008080])[/color]
  [COLOR=#804040][b]say[/b][/color] item [COLOR=#ff00ff]'-->'[/color] occurs.item
[COLOR=#804040][b]end[/b][/color]
[COLOR=#804040][b]say[/b][/color]

[COLOR=#0000ff]/* display only those items which occurs more than 5 times */[/color]
[COLOR=#804040][b]say[/b][/color] [COLOR=#ff00ff]'items that occur more than 5 times:'[/color] 
[COLOR=#804040][b]do[/b][/color] j[COLOR=#804040][b]=[/b][/color]1 [COLOR=#804040][b]to[/b][/color] [COLOR=#008080]words([/color]items_list[COLOR=#008080])[/color]
  item [COLOR=#804040][b]=[/b][/color] [COLOR=#008080]word([/color]items_list[COLOR=#804040][b],[/b][/color] j[COLOR=#008080])[/color]
  [COLOR=#804040][b]if[/b][/color] occurs.item [COLOR=#804040][b]>[/b][/color] 5 [COLOR=#804040][b]then[/b][/color] [COLOR=#804040][b]do[/b][/color]
    [COLOR=#804040][b]say[/b][/color] [COLOR=#ff00ff]"item '"[/color]item[COLOR=#ff00ff]"'"[/color] [COLOR=#ff00ff]'occurs in the queue'[/color] occurs.item [COLOR=#ff00ff]'times.'[/color]
  [COLOR=#804040][b]end[/b][/color]
[COLOR=#804040][b]end[/b][/color]

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.
 
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:
[COLOR=#0000ff]/* create queue of some items */[/color]
[COLOR=#804040][b]queue[/b][/color] [COLOR=#ff00ff]"foo"[/color]
[COLOR=#804040][b]queue[/b][/color] [COLOR=#ff00ff]"bar"[/color]
[COLOR=#804040][b]queue[/b][/color] [COLOR=#ff00ff]"baz"[/color]
[COLOR=#804040][b]queue[/b][/color] [COLOR=#ff00ff]"foo"[/color]
[COLOR=#804040][b]queue[/b][/color] [COLOR=#ff00ff]"bar"[/color]
[COLOR=#804040][b]queue[/b][/color] [COLOR=#ff00ff]"baz"[/color]
[COLOR=#804040][b]queue[/b][/color] [COLOR=#ff00ff]"spam"[/color]
[COLOR=#804040][b]queue[/b][/color] [COLOR=#ff00ff]"eggs"[/color]
[COLOR=#804040][b]queue[/b][/color] [COLOR=#ff00ff]"foo"[/color]
[COLOR=#804040][b]queue[/b][/color] [COLOR=#ff00ff]"foo"[/color]
[COLOR=#804040][b]queue[/b][/color] [COLOR=#ff00ff]"foo"[/color]
[COLOR=#804040][b]queue[/b][/color] [COLOR=#ff00ff]"foo"[/color]
[COLOR=#804040][b]queue[/b][/color] [COLOR=#ff00ff]"spam"[/color]
[COLOR=#804040][b]queue[/b][/color] [COLOR=#ff00ff]"spam"[/color]
[COLOR=#804040][b]queue[/b][/color] [COLOR=#ff00ff]"spam"[/color]
[COLOR=#804040][b]queue[/b][/color] [COLOR=#ff00ff]"spam"[/color]
[COLOR=#804040][b]queue[/b][/color] [COLOR=#ff00ff]"spam"[/color]
[COLOR=#804040][b]queue[/b][/color] [COLOR=#ff00ff]"spam"[/color]
[COLOR=#804040][b]queue[/b][/color] [COLOR=#ff00ff]"spam"[/color]
[COLOR=#804040][b]queue[/b][/color] [COLOR=#ff00ff]"spam"[/color]
[COLOR=#804040][b]queue[/b][/color] [COLOR=#ff00ff]"foo"[/color]
[COLOR=#804040][b]queue[/b][/color] [COLOR=#ff00ff]"bar"[/color]
[COLOR=#804040][b]queue[/b][/color] [COLOR=#ff00ff]"baz"[/color]
[COLOR=#804040][b]queue[/b][/color] [COLOR=#ff00ff]"spam"[/color]
[COLOR=#804040][b]queue[/b][/color] [COLOR=#ff00ff]"eggs"[/color]
[COLOR=#804040][b]queue[/b][/color] [COLOR=#ff00ff]"foobar"[/color]

[COLOR=#0000ff]/* add queued items occurrence into stem */[/color]
occurs. [COLOR=#804040][b]=[/b][/color] 0
nr_items [COLOR=#804040][b]=[/b][/color] 0
items_list. [COLOR=#804040][b]=[/b][/color] [COLOR=#ff00ff]''[/color]
[COLOR=#804040][b]do [/b][/color][COLOR=#804040][b]while[/b][/color][COLOR=#804040][b] [/b][/color][COLOR=#008080]queued()[/color] [COLOR=#804040][b]<>[/b][/color] 0
  [COLOR=#804040][b]parse pull[/b][/color] item
  [COLOR=#0000ff]--say item[/color]
  [COLOR=#0000ff]/* add item to items_list if not present */[/color]
  [COLOR=#804040][b]if[/b][/color] occurs.item [COLOR=#804040][b]=[/b][/color] 0 [COLOR=#804040][b]then[/b][/color] [COLOR=#804040][b]do[/b][/color]
    nr_items [COLOR=#804040][b]=[/b][/color] nr_items [COLOR=#804040][b]+[/b][/color] 1
    items_list.nr_items [COLOR=#804040][b]=[/b][/color] item
  [COLOR=#804040][b]end[/b][/color]  
  [COLOR=#0000ff]/* count item occurrences */[/color]
  occurs.item [COLOR=#804040][b]=[/b][/color] occurs.item [COLOR=#804040][b]+[/b][/color] 1
[COLOR=#804040][b]end[/b][/color]

[COLOR=#0000ff]/* show the occurrence of individual items */[/color]
[COLOR=#804040][b]say[/b][/color] [COLOR=#ff00ff]'all queue items occurrence:'[/color]
[COLOR=#804040][b]do[/b][/color] j[COLOR=#804040][b]=[/b][/color]1 [COLOR=#804040][b]to[/b][/color] nr_items
  item [COLOR=#804040][b]=[/b][/color] items_list.j
  [COLOR=#804040][b]say[/b][/color] item [COLOR=#ff00ff]'-->'[/color] occurs.item
[COLOR=#804040][b]end[/b][/color]
[COLOR=#804040][b]say[/b][/color]

[COLOR=#0000ff]/* display only those items which occurs more than 5 times */[/color]
[COLOR=#804040][b]say[/b][/color] [COLOR=#ff00ff]'items that occur more than 5 times:'[/color] 
[COLOR=#804040][b]do[/b][/color] j[COLOR=#804040][b]=[/b][/color]1 [COLOR=#804040][b]to[/b][/color] nr_items
  item [COLOR=#804040][b]=[/b][/color] items_list.j
  [COLOR=#804040][b]if[/b][/color] occurs.item [COLOR=#804040][b]>[/b][/color] 5 [COLOR=#804040][b]then[/b][/color] [COLOR=#804040][b]do[/b][/color]
    [COLOR=#804040][b]say[/b][/color] [COLOR=#ff00ff]"item '"[/color]item[COLOR=#ff00ff]"'"[/color] [COLOR=#ff00ff]'occurs in the queue'[/color] occurs.item [COLOR=#ff00ff]'times.'[/color]
  [COLOR=#804040][b]end[/b][/color]
[COLOR=#804040][b]end[/b][/color]
 
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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top