insert into q31
(nr01, p01, p03, p05, 
remfdate, remftime, remfuser, remdate, remtime, remuser)
select peg_new_nr01('q31', 1) as nr01,
       tbl01.*
from
(       
    select z_q31_mydata.p01 as p01, 
           z_q31_mydata.p03 as p03, 
           z_q31_mydata.p05 as p05, 
           curdate() as remfdate, 
           curtime() as remftime, 
           '{user_pswd}@std_tables' as remfuser,
           curdate() as remdate, 
           curtime() as remtime, 
           '{user_pswd}@std_tables' as remuser
    from z_q31_mydata
    left join q31 on q31.p01=z_q31_mydata.p01
                  && q31.p03=z_q31_mydata.p03
                  && q31.p05=z_q31_mydata.p05
    left join q30 on q30.nr01=z_q31_mydata.p01
    where q31.nr01 is null
       && q30.p01='{my_tbl}'
) as tbl01;
/*peg_end*/