The following code is a sample application that you
can run with message queue polling.
data _null_;
length hconn hobj cc reason 8;
length rc hod hgmo hmd hmap msglen 8;
length parms $ 200 options $ 200 action $ 3 msg $ 200;
length desc $ 50;
msglen=0;
hconn=0;
hobj=0;
hod=0;
hgmo=0;
hmd=0;
hmap=0;
/* Get the variables set by the object spawner for this session */
sid = sysget('SASQSID');
qmgr= sysget('SASQMGR');
qname= sysget('SASQUEUE');
put "Spawner job started.";
put "sid = " sid;
put "qmgr = " qmgr;
put "qname = " qname;
call mqconn(qmgr, hconn, cc, reason);
action = "GEN";
parms="OBJECTNAME";
objname=qname;
call mqod(hod, action, rc, parms, objname);
if rc ^= 0 then do;
put 'MQOD: failed with rc= ' rc;
msg = sysmsg();
put msg;
goto exit;
end;
options="INPUT_SHARED";
call mqopen(hconn, hod, options, hobj, cc, reason);
if cc ^= 0 then do;
put 'MQOPEN: failed with reason= ' reason;
goto exit;
end;
parms= "SASQSID";
call mqgmo(hgmo, action, rc, parms, sid);
if rc ^= 0 then do;
put 'MQGMO: failed with rc= ' rc;
msg = sysmsg();
put msg;
goto exit;
end;
desc="CHAR,,100";
call mqmap(hmap, rc, desc);
if rc ^= 0 then do;
put 'MQMAP: failed with rc= ' rc;
msg = sysmsg();
put msg;
goto exit;
end;
reason = 0;
do until (reason = 2033);
action = "GEN";
call mqmd(hmd, action, rc);
if rc ^= 0 then do;
put 'MQMD: failed with rc= ' rc;
msg = sysmsg();
put msg;
end;
call mqget(hconn, hobj, hmd, hgmo, msglen, cc, reason);
if cc ^= 0 then do;
if reason = 2033 then do;
put 'No message available';
end;
else do;
if reason = -2 then do;
/* -2 indicates that a session-specific stop message has */
/* been received from the object spawner queue monitor */
/* application. We should clean up and shutdown */
/* immediately. */
put "MQGET: received stop message from object spawner";
goto exit;
end;
else put 'MQGET: failed with reason= ' reason;
end;
end;
else put 'MQGET: message received: ';
/* Do any application-specific processing of messages here. */
if hmd ^= 0 then do;
call mqfree(hmd);
end;
end; /* end do loop */
exit:
if hobj ^= 0 then do;
options="NONE";
call mqclose(hconn, hobj, options, cc, reason);
if cc ^= 0 then do;
put 'MQCLOSE: failed with reason= ' reason;
end;
end;
if hconn ^= 0 then do;
call mqdisc(hconn, cc, reason);
if cc ^= 0 then do;
put 'MQDISC: failed with reason= ' reason;
end;
end;
if hod ^= 0 then do;
call mqfree(hod);
end;
if hgmo ^= 0 then do;
call mqfree(hgmo);
end;
if hmd ^= 0 then do;
call mqfree(hmd);
end;
if hmap ^= 0 then do;
call mqfree(hmap);
end;
run;