Get example

 ******************************************************* 
* amqsget: Get messages from a queue\
*******************************************************
include MQSeries,mqsbp, include
prompt '' 
equ SLEEPYTIME to 5000

* Values from the configuration file 
* ----------------------------------
execute 'MQSeries-setup display manager.name' capturing QMName

HConn = -1
HObj = -1

* Parse the sentence
* ------------------
gosub sen.get
QName = field(sen,' ',tok); tok += 1
if QName = '' then
   print 'Required parameter missing - queue name'
   stop
end

* Build the connection
* --------------------
QMName = '' ;* Queue manager name (use the default)
call MQCONN( QMName, HConn, CompCode, Reason )
gosub iserror

* Open the queue
* --------------
od=''
od<MQOD.ObjectName> = QName
Options = MQOO_INPUT_AS_Q_DEF + MQOO_OUTPUT +
  MQOO_INQUIRE + MQOO_SET
call MQOPEN( HConn, od, Options, HObj, CompCode, Reason )
gosub iserror
print 'Sample AMQSGET start'
print 'Queue Name : "':QName:'"'

* Get from queue
* ------------------------
loop
  md=''; gmo=''
  buff=space(65536)
  buff.len=len(buff)
  md<MQMD.Format> = MQFMT_STRING
  md<MQMD.MsgId> = MQMI_NONE
  md<MQMD.CorrelId> = MQCI_NONE
  gmo<MQGMO.Options> = MQGMO_WAIT
  gmo<MQGMO.WaitInterval> = SLEEPYTIME
call
  MQGET(HConn,HObj,md,gmo,buff.len,buff,
  rtn.len,CompCode,Reason )

while Reason<>MQRC_NO_MSG_AVAILABLE do
  gosub iserror
  buff=buff[1,rtn.len]
  if rtn.len>60 then
  print 'message <':buff[1,60]:'...>'
  end else
  print 'message <':buff:'>'
 end
repeat

* Close queue, then connection
* -----------------------------------
call MQCLOSE(HConn, HObj, Options, CompCode, Reason)
call MQDISC( HConn, CompCode, Reason )

print 'Sample AMQSGET end'
stop

sen.get:
**********************************************
* Get the sentence
**********************************************
tclread sen
sen = trim(sen)
opt = field(sen,'(',2)
sen = field(sen,'(',1)
tok = 1
verb = field(sen,' ',tok); tok += 1
vflg = index(opt,'v',1)
return
iserror:
**********************************************
* if it's an error then stop
**********************************************

if Reason = MQRC_NONE then return
if Reason>2000 then
  print Reason:' (':MQRC_DESC<Reason-2000>:')'
end else
  print Reason
end
if HObj > 0 then call MQCLOSE(HConn, HObj, Options, CompCode, Reason)
if HConn > 0 then call MQDISC(HConn, CompCode, Reason) stop
stop