When i declare a cursor as follows along with 'with clause' ---

EXEC SQL DECLARE PUBS CURSOR FOR
WITH tmp AS (SELECT distinct pub.PUB_IDT IDT,edt.pub_mth
FROM PRMSELINCPUBT pub,prmeditiot edt
WHERE pub.PRM_IDT = 1306 and
pub.CHP_NUM = 1 and pub.pub_idt=edt.pub_idt
and edt.pub_mth is not null
order by edt.pub_mth asc)
SELECT distinct tmp.idt FROM tmp;

it results in error like

PCC-S-02201, Encountered the symbol "tmp" when expecting one of the following:
;

The same query when i run from DB side,it fetches the result.Please tell me how to resolve this.