/*********************************
     disconnect erpa80 from a55
*********************************/
update erpa80, a55
set erpa80.p08=0, 
    erpa80.p04= date_sub(a55.p01, interval 1 day), 
    erpa80.p30=concat(erpa80.p30, space(10), a55.p06, ' ', a55.p01), 
    erpa80.remdate = curdate(), 
    erpa80.remtime = curtime(), 
    erpa80.remuser = '@erpt00p01@'
WHERE erpa80.p08=a55.nr01
   && a55.remguc='{p_t00mark}';
/*peg_end*/   



/******************************************
     insert data into erpa80
******************************************/
INSERT INTO erpa80
(nr01, p01, p03, p07, p30,
remfdate, remftime, remfuser, remdate, remtime, remuser) 
SELECT peg_new_nr01('erpa80', 1) as nr01, 
       nr01 as p01, 
       '{odbcdtos(nt_p02)}' as p03, 
       sum(p03) as p07, 
       group_concat(p02) as p30, 
       
       curdate() as remfdate, 
       curtime() as remftime, 
       '@erpt00p01@' as remfuser, 
       curdate() as remdate, 
       curtime() as remtime, 
       '@erpt00p01@' as remuser
FROM ({peg_str}) as erpa80_d03
WHERE p04 in (1, 2)
GROUP BY nr01;
/*peg_end*/