The Browse sample programs
The Browse sample programs browse messages on a queue using the MQGET call.
See the following topics for the name of this program on different platforms:
- Features shown in the C and COBOL MQI samples for AIX® and Linux®
- Features shown in the C and COBOL MQI samples for Windows
- Features shown in the Visual Basic MQI samples for Windows
- Features shown in the C, COBOL and RPG MQI samples for IBM® i
Design of the Browse sample program
The program opens the target queue using the MQOPEN call with the MQOO_BROWSE option. If it cannot open the queue, the program outputs an error message containing the reason code returned by the MQOPEN call.
- MQGMO_BROWSE_NEXT
- After the MQOPEN call, the browse cursor is positioned logically before the first message in the queue, so this option causes the first message to be returned when the call is first made.
- MQGMO_NO_WAIT
- The program does not wait if there are no messages on the queue.
- MQGMO_ACCEPT_TRUNCATED_MSG
- The MQGET call specifies a buffer of fixed size. If a message is longer than this buffer, the program displays the truncated message, together with a warning that the message has been truncated.
The program demonstrates how you must clear the MsgId
and CorrelId
fields of the MQMD structure after each MQGET call, because the call sets these fields to the values contained in the message it retrieves. Clearing these fields means that successive MQGET calls retrieve messages in the order in which the messages are held in the queue.
The program continues to the end of the queue; the MQGET call returns the MQRC_NO_MSG_AVAILABLE reason code and the program displays a warning message. If the MQGET call fails, the program displays an error message that contains the reason code.
The program then closes the queue using the MQCLOSE call.