Design of the Print Message sample on z/OS

The Print Message sample application uses a single program written in the C language.

The flow through the program logic is:
  1. Check that the names of the queue manager and queue have been passed from the run JCL. If they have not, print an error message and stop processing.
  2. Connect to the queue manager using the MQCONN call. If this call is not successful, print the completion and reason codes and stop processing; otherwise print the name of the queue manager.
  3. Open the queue using the MQOPEN call with the MQOO_INPUT_SHARED option. Note: If we want the application to browse the messages rather than remove them from the queue, compile the sample with -DBROWSE, or, add #define BROWSE at the beginning of the source. When you do this, the macro preprocessor adds the line in the program that selects the MQOO_BROWSE option in the compilation.

    On input to this call, the program uses the connection handle returned in step 2. For the object descriptor structure (MQOD), it uses the default values for all the fields except the queue name (which was passed in step 1 ). If this call is not successful, print the completion and reason codes and stop processing; otherwise, print the name of the queue.

  4. If we use a message handle to obtain the message properties use MQCRTMH to create such a handle for use with subsequent MQGET calls. If this call is not successful, print the completion and reason codes and stop processing.
  5. Set the get message options to reflect the request action for any message properties.
  6. Perform the following loop until the MQGET call fails:
    1. Initialize the buffer to blanks so that the message data does not get corrupted by any data already in the buffer.
    2. Set the MsgId and CorrelId fields of the MQMD structure to nulls so that the MQGET call selects the first message from the queue.
    3. Get a message from the queue, using the MQGET call. On input to this call, the program specifies:

      • The connection and object handles from steps 2 and 3.
      • An MQMD structure with all fields set to their initial values. (MsgId and CorrelId are reset to nulls for each MQGET call.)
      • The option MQGMO_NO_WAIT. Note: If we want the application to browse the messages rather than remove them from the queue, compile the sample with -DBROWSE, or, add #define BROWSE at the beginning of the source. When you do this, the macro preprocessor adds the line in the program that selects the MQGMO_BROWSE_NEXT option to the compilation. When this option is used on a call against a queue for which no browse cursor has previously been used with the current object handle, the browse cursor is positioned logically before the first message.
      • A buffer of size 64KB to hold the data copied from the message.

    4. Call the printMD subroutine. This prints the name of each field in the message descriptor, followed by its contents.
    5. If you created a message handle in step 4 call the printProperties subroutine to display any message properties.
    6. Print the length of the message, followed by the message data. Each line of message data is in this format:

      • Relative position (in hexadecimal) of this part of the data
      • 16 bytes of hexadecimal data
      • The same 16 bytes of data in character format, if it is printable (nonprintable characters are replaced by periods)

  7. If the MQGET call fails, test the reason code to see if the call failed because there are no more messages on the queue. In this case, print the message: No more messages; otherwise, print the completion and reason codes. In both cases, go to step 9. Note: The MQGET call fails if it finds a message that has more than 64KB of data. To change the program to handle larger messages, you could do one of the following:

    • Add the MQGMO_ACCEPT_TRUNCATED_MSG option to the MQGET call, so that the call gets the first 64KB of data and discards the remainder
    • Make the program leave the message on the queue when it finds one with this amount of data
    • Increase the size of the buffer

  8. If you created a message handle in step 4 call MQDLTMH to delete it.
  9. Close the queue using the MQCLOSE call with the object handle returned in step 3.
  10. Disconnect from the queue manager using the MQDISC call with the connection handle returned in step 2.

Parent topic: The Print Message sample on z/OS