I have a requirement where in I have 2 transactions, namely TRN1 and TRN2. TRN1 will put a message onto Queue1. When a message in put onto Queue1, TRN2 is triggered in the background. It does a get from Queue1 and processes the message and put the response onto Queue2. In my first program, after putting a message onto queue1, I am trying to get the response message from queue2 after 20 seconds delay. Here inorder to identify the message I have used MQPMO-NEW-CORREL-ID in MQPMO options in first program and I have saved MQPMO-NEW-CORREL-ID in working storage variable to use it while getting the message. Here my question is how can we get the correlid of a message in queue1 in second program so that same can be used while putting a message onto queue2?
The way you describe is not the standard way to achieve what you want.
Standard practice is for TRN1 to issue MQPUT(1) to put a message on Queue1. This returns a MsgId in the Message Descriptor (MQMD) to TRN1 application. This is then put into the MQMD.CorrelId for the MQGET of the reply message which TRN1 issues.
The message that was MQPUT(1) carries the MsgId in its Message Descriptor and this is presented to TRN2 along with the name of the ReplytoQ. TRN2 then moves this MsgId to the CorrelId field of the reply which it will MQPUT(1) to Queue2 (the ReplytoQ) and a new MsgId is generated for the reply.
In this way, TRN1 always issues an MQGET for the message with a CorrelId that matches the MsgId from the MQPUT(1).