Getting a message using the wait option
This example demonstrates how to use the MQGET call with the wait option and accepting truncated messages.
This extract is taken from the Credit Check sample application (program CSQ4CVB5) supplied with IBM MQ for z/OS . For the names and locations of the sample applications on other platforms, see Sample procedural programs (platforms except z/OS ).⋮ * -------------------------------------------------------* WORKING-STORAGE SECTION. * -------------------------------------------------------* * * W00 - General work fields * 01 W00-WAIT-INTERVAL PIC S9(09) BINARY VALUE 30000. * * W03 - MQM API fields * 01 W03-HCONN PIC S9(9) BINARY VALUE ZERO. 01 W03-OPTIONS PIC S9(9) BINARY. 01 W03-HOBJ-CHECKQ PIC S9(9) BINARY. 01 W03-COMPCODE PIC S9(9) BINARY. 01 W03-REASON PIC S9(9) BINARY. 01 W03-DATALEN PIC S9(9) BINARY. 01 W03-BUFFLEN PIC S9(9) BINARY. * 01 W03-MSG-BUFFER. 05 W03-CSQ4BCAQ. COPY CSQ4VB3. * * API control blocks * 01 MQM-MESSAGE-DESCRIPTOR. COPY CMQMDV. 01 MQM-GET-MESSAGE-OPTIONS. COPY CMQGMOV. * * CMQV contains constants (for filling in the * control blocks) and return codes (for testing * the result of a call). * 01 MQM-MQV. COPY CMQV SUPPRESS. * -------------------------------------------------------* PROCEDURE DIVISION. * -------------------------------------------------------* ⋮ * Open input queue. ⋮
* * Get and process messages. * COMPUTE MQGMO-OPTIONS = MQGMO-WAIT + MQGMO-ACCEPT-TRUNCATED-MSG + MQGMO-SYNCPOINT. MOVE LENGTH OF W03-MSG-BUFFER TO W03-BUFFLEN. MOVE W00-WAIT-INTERVAL TO MQGMO-WAITINTERVAL. MOVE MQMI-NONE TO MQMD-MSGID. MOVE MQCI-NONE TO MQMD-CORRELID. * * Make the first MQGET call outside the loop. * CALL 'MQGET' USING W03-HCONN W03-HOBJ-CHECKQ MQMD MQGMO W03-BUFFLEN W03-MSG-BUFFER W03-DATALEN W03-COMPCODE W03-REASON. * * Test the output of the MQGET call using the * PERFORM loop that follows. * * Perform whilst no failure occurs * - process this message * - reset the call parameters * - get another message * End-perform * * * Test the output of the MQGET call. If the call * fails, send an error message showing the * completion code and reason code, unless the * completion code is NO-MSG-AVAILABLE. * IF (W03-COMPCODE NOT = MQCC-FAILED) OR (W03-REASON NOT = MQRC-NO-MSG-AVAILABLE) MOVE 'MQGET ' TO M02-OPERATION MOVE MQOD-OBJECTNAME TO M02-OBJECTNAME PERFORM RECORD-CALL-ERROR END-IF. ⋮Parent topic: COBOL examples