The Print Message sample on z/OS

The Print Message sample is a batch application that demonstrates how to remove all the messages from a queue using the MQGET call.

The Print Message sample uses three parameters:
  1. The name of the queue manager
  2. The name of the source queue
  3. An optional parameter for properties

It also prints, for each message, the fields of the message descriptor, followed by the message data. The program prints the data both in hexadecimal and as characters (if they are printable). If a character is not printable, the program replaces it with a period character (.). We can use the program when diagnosing problems with an application that is putting messages on a queue.

Permissible values for the property parameter are:

Value Behavior
0 Default behavior, as it was for Version 6. The properties that get delivered to the application depend on the PropertyControl queue attribute that the message is retrieved from.
1 A message handle is created and used with the MQGET. Properties of the message, except those contained in the message descriptor (or extension) are displayed in a similar fashion to the message descriptor. For example:
****Message properties****
   property name: property value   
Or if no properties are available:
****Message properties****
   None
Numeric values are displayed using printf, string values are surrounding in single quotation marks, and byte strings are surrounded with X and single quotation marks, as for the message descriptor.
2 MQGMO_NO_PROPERTIES is specified, so that only message descriptor properties will be returned.
3 MQGMO_PROPERTIES_FORCE_MQRFH2 is specified, so that all properties are returned in the message data.
4 MQGMO_PROPERTIES_COMPATIBILITY is specified, so that all properties can be returned depending on whether a Version 6 property is included, otherwise the properties are discarded.

We can change the application so that it browses the messages, rather than removing them from the queue. To do this, compile with the option of -DBROWSE, to define the BROWSE macro, as indicated in Design of the Print Message sample on z/OS. Executable code is provided for you in the SCSQLOAD library. Module CSQ4BCG0 is built with -DBROWSE; module CSQ4BCG1 destructively reads the queue.

The application has a single source program, which is written in the C language. Sample run JCL code is also supplied (see Table 3 ). To start the application, edit and run the sample run JCL, as described in Preparing and running sample applications for the batch environment on z/OS. When you run the application (and there are some messages on the queue), the output data set looks like that in Figure 1.
Figure 1. Example of a report from the Print Message sample application
CSQ4BCG1 - starts here
**********************

MQCONN to MQ1E
MQOPEN - 'TEST.QUEUE'
MQCRTMH


MQGET of message number 1
****Message descriptor****
StrucId : 'MD ' Version : 2
Report  : 0 MsgType : 8
Expiry  : -1 Feedback : 0
Encoding : 785 CodedCharSetId : 500
Format : 'MQSTR  '
Priority : 0 Persistence : 0
MsgId : X'C3E2D840D4D8F1C54040404040404040C1EA537F03167D88'
CorrelId : X'C3E2D840D4D8F1C54040404040404040C1EA537F0317A928'
BackoutCount : 0
ReplyToQ    : '                        '
ReplyToQMgr  : ''
** Identity Context
UserIdentifier : 'FRED    '
AccountingToken :
X'0000000000000000000000000000000000000000000000000000000000000000'
ApplIdentityData : '                '
** Origin Context
PutApplType  : '2'
PutApplName  : 'FRED6            '
PutDate : '20080207'  PutTime : '17373745'
ApplOriginData : '  '
GroupId : X'000000000000000000000000000000000000000000000000'
MsgSeqNumber  : '1'
Offset     : '0'
MsgFlags    : '0'
OriginalLength : '-1'

****Message properties****
None

****  Message   ****

length - 30 bytes

00000000: E388 89A2 4089 A240 8140 A289 9497 9385 'This is a simple'
00000010: 40A3 85A2 A340 9485 A2A2 8187 855A   ' test message! '



No more messages
MQDLTMH
MQCLOSE
MQDISC

Parent topic: Use the sample programs for z/OS