When answering this question I offered a suggestion that you could total the number of connections coming over a set of SVRCONN channels by using the following single line in MQSCX.
@total=0;foreach(DISPLAY CHSTATUS(*) CURSHCNV);@total=@total+CURSHCNV;endfor;print @total
This totaled all the CURSHCNV values for all the channels whose status was displayed.
It occurred to me that there are many other examples of commands where you might want to total up some integer attribute from a set of objects or status records.
- DISPLAY QLOCAL(SYSTEM.ADMIN.*.EVENT) CURDEPTH
How many event messages you have
- DISPLAY CHSTATUS(*) WHERE(RQMNAME EQ MQG2) MSGS
How many messages have been sent to queue manager MQG2
- DISPLAY TPSTATUS(‘#’) TYPE(SUB) NUMMSGS
How many messages have been sent to susbcribers
- DISPLAY QLOCAL(*) OPPROCS
How many putting applications are around
Instead of repeating the single line each time with changes to reflect the different command, it might be handy to have a little function that you could just throw a command at and it would do the totaling up for you. For example, you could do something like this:-
func totals(Command,Attribute) @total = 0 foreach(@Command + ' ' + @Attribute) @total = @total + eval(@Attribute) endfor print 'Total of',@Attribute,'for all',@Command,'is',@total endfunc
And then call it and get the result like so:-
totals("DISPLAY QLOCAL(Q*)","CURDEPTH") Total of CURDEPTH for all DISPLAY QLOCAL(Q*) is 8
MQSCX functions are just so handy!