declare cursor xx is select * from inv_grupo;
        cursor fac(part in varchar2) is select * from xx
        where cia='001'
        and sucursal='001'
        and articulo=part;
       cursor inv(part in varchar2) is select * from xy
        where cod_cia='001'
        and sucursal='001'
        and cod_articulo=part;

  vcosto predetlista.costo%type;
  
begin
  for a in xx loop
  begin
     select costo into vcosto from predetlista
     where cod_cia = a.cod_cia
     and   cod_lista_precio='001'
     and   cod_articulo=a.grupo;
  exception
    when no_data_found then
       vcosto:=0;
  end;
  if vcosto>0 then
     for x in inv(a.grupo) loop
        update inv_detmovimiento
        set sub_total=vcosto*can_articulo
        where cod_cia=x.cod_cia
        and   sucursal=x.sucursal
        and   tip_movto=x.tip_movto
        and   cod_movto=x.cod_movto
        and   num_docto=x.num_docto
        and   cod_bodega=x.cod_bodega
        and   cod_Lote=x.cod_lote
        and   cod_articulo=x.cod_articulo
        and   medida=x.medida;
     end loop;   
  end if; 
  end loop;
end;
/


/*  if vcosto>0 then
     for x in fac(a.grupo) loop
        update vendetfactura
        set costo=vcosto
        where cia=x.cia
        and   sucursal=x.sucursal
        and   documento=x.documento
        and   secuencia=x.secuencia;
     end loop;   
  end if; */
