I tried using RCVMSG but it didn’t work out.
RCVMSG is a correct way to do it in CL. If it didn’t work out, then you need to show us what you did so we can determine what was wrong.
If you are working in a language such as RPG, the correct method would be to use the Receive Program Message (QMHRCVPM) API. The API can also be used in CL, but the RCVMSG command might be easier to use.