Novel use of MQSCX foritem

When we provide features in our tools and utilities, we don’t always think of all the ways they can be used, and our customers surprise us by finding novel ways to use features. This is the case in the new example script, mqauthlist.mqsx, available in our Example Scripts bundle.

MQSCX has a feature called foritem which works very like foreach but instead of iterating over the responses from a command like DISPLAY QLOCAL, it iterates over the items in a list, for example the NAMES in a namelist, as shown in the example below which is copied out of the MQSCX manual:-

foreach(DISPLAY NAMELIST(*) NAMES)
  foritem(NAMES)
    print _item
  endfor
endfor

foritem loopHowever, foritem will happily iterate over ANY comma-separated list, it doesn’t have to be one that was returned by the queue manager in answer to an MQSC command.

This is demonstrated in the new sample, by hand-crafting the list of queue managers to interrogate, and then using foritem to iterate over each queue manager in the list. Here’s how:-

@qmlist = "PRDQM01,PRDQM02,PRDQM03,PRDQM04,PRDQM05"

** Process each queue manager in the list
foritem(@qmlist)
  if( _item != _qmgr )
    =conn client qm(<_item>) wait(60)
  endif
  ** Issue commands to the queue manager here
endfor

This snippet also demonstrates a new feature added in the most recent refresh of MQSCX, a wait time on the =conn command. When MQSCX connects to a Queue Manager a message is sent to the command server to determine the platform and version of the remote Queue Manager. This parameter allows you to control how long, in seconds, MQSCX is willing to wait for a response before the connection is considered ‘failed’.

I’m sure there are many uses for comma-separated lists that foritem can iterate over.


The best way to understand scripts is of course to have a go with them yourself. There are various examples in the download, so why not try them out yourself. If you are not currently an MQSCX licence holder, you may email support@mqgem.com to request a trial licence.

Advertisements

The team at MQGem would love to hear what you think. Leave your comments here.

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s