MQSCX feature – write to a file

MQSCX File AccessWhen writing an MQSCX script you can print out details to the screen, or open a file and write your output to the file instead. This can be very useful for generating a report about something, as is shown in a new example script, mqauthlist.mqsx, available in our Example Scripts bundle. This script writes a report to file. Here’s how:-

** Open file and write header
@filename = "mqauthlist_" + date(_time, "_y_mm_d") + ".txt"

@hf = fopen(@filename, "w")
if( @hf = -1 )
   print "Error opening file", @filename, "ErrorNo=", _errno

fprint @hf,"MQ Report for", @env, "on", date(_time, "mmm dd, y"), _nl
fprint @hf, "**-------------------------------------------------**"
fprint @hf, "** Queue Manager", :10:_qmgr, "                       **"
fprint @hf, "**-------------------------------------------------**"

** Close the file
print "Created file <@filename>"

There are a few system variables also demonstrated in the above snippet that are useful in this, and other situations.

When opening a file, and any other interactions with the system, the errno is always useful to be able to get hold of. In MQSCX you can do so through the _errno system variable. You might also find it useful to use the _errnostr system variable which will provide a string interpretation of the errno. So you might print your error opening the file out like this:-

@hf = fopen(@filename,"w")
if ( @hf = -1 )
    print "Can not open file '<@filename>' errno:<_errno> <_errnostr>"

Another system variable shown is _nl which simply writes a new line to the screen or file (depending on whether you use print or fprint).

Also demonstrated is the system variable _qmgr which is an easy way to access the name of the queue manager the script is currently connected to. Similar to _cmdlevel and _platform (which were covered in MQSCX feature – CommandLevel and Platform) they give you quick access to attributes you could also get through issuing a command.

Writing reports based on interrogations of your queue manager by issuing commands in an MQSCX script opens up a world of possibilities for what you are able to do.

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 to request a trial licence.


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: Logo

You are commenting using your 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