-- Costeo de toma fisica en el momento que desee ---
declare cursor xx is select b.cod_bodega,a.cod_articulo 
from inv_dettomafis a,inv_tomafis b
where b.cod_cia='001'
and   a.secuencia=529
and   b.secuencia=529;
  vcosto inv_artic_bodega.cos_promedio%type;
begin
  for a in xx loop
    begin
      select cos_promedio into vcosto
      from inv_artic_bodega
      where cod_cia='001'
      and   cod_bodega='001'
      and   cod_articulo=a.cod_articulo;
    exception
      when no_data_found then
         vcosto:=0;
    end;
    update inv_dettomafis
    set costo=vcosto
    where secuencia=529
    and   cod_articulo=a.cod_articulo;
  end loop;
   commit;
end;   
/
-- Rebaja las existencias fisicas de la bodega 004 en la bodega 001
declare cursor xx is select * from inv_dettomafis
where secuencia=529;
begin
  for a in xx loop
    update inv_dettomafis
    set can_existe=can_existe-a.can_fisico
    where secuencia=528
    and   cod_articulo=a.cod_articulo;
  end loop;
  commit;
end;
/