Ah! That CL example explains better what you're trying to do. Here, try it this way:
pgm ( &MISC# ) dcl &MISC# *dec ( 4 0 ) dcl &MISC *char 4 chgvar &MISC &MISC# strqmqry qmqry( AXMTESTLIB/SANQMCON1 ) output( * ) + setvar( ( MISC &MISC ) ) monmsg ( QWM2701 ) exec( RETURN ) END: return endpgm
I reformatted for readability and made a couple simple changes.
Your &MISC# variable is being passed as a numeric parm, and that's fine as long as it was generated in the calling program as *DEC (4 0) or a compatible data type in a different language. But when it is used by the STRQMQRY command, it needs to be a series of character digits.
We do that by creating a *CHAR variable that is 4 bytes long and letting the CHGVAR command do a straight conversion. Bear in mind that the CL variable named &MISC has no relationship at all with your QM replacement variable of the same name. It's probably not a good idea to use the same name for both, but it will work. It just brings potential confusion when errors come up.
I also got rid of the ALWQRYDFN() parameter. Since you're creating a QM query, you don't want some *QRYDFN object of the same name getting into this. I'd make other changes, but they aren't actually required for this question.
And your QM query statement becomes something like:
SELECT bcbgcd COLHDG("MISC" "CODE"), somecolumn LEN(4,0) COLHDG("SHARED CONTAINER" "CODE") NAME(MISC) FROM lmbcrela WHERE bcbgcd=&MISC
I replaced the "&MISC" for the second column with a column name of "somecolumn", though I think I can see why you had it there. If you really wanted a column from a table, then use the name of that column. You might even put &MISC back and have it work. It doesn't make much sense, though, for this SELECT statement since the same value is going to show up in the bcbgcd column anyway. Your WHERE clause guarantees that both columns will be nothing but repeats of the value in &MISC -- if 1000 rows match, then that value will display 2000 times and nothing else will show up.
I assume that you will develop the SELECT statement over time to make it more meaningful. This should get you closer.