Ver Mensaje Individual
  #1 (permalink)  
Antiguo 11/05/2014, 16:59
Emerson_Palacios
 
Fecha de Ingreso: junio-2008
Mensajes: 13
Antigüedad: 15 años, 10 meses
Puntos: 0
Uso de Signal para devolver mensaje de Error.

Buenas Tardes Amigos del foro. quería ver si me pueden ayudar en un Problema que tengo con el uso del Signal. Tengo un store procedure al cual le paso como parámetro los datos de un documento este procedure levanta un cursor con el detalle de dicho documento y va actualizando los stocks de los productos pero en el caso que alguno de los productos del documento no tenga stock estoy utilizando el signal para cortar el proceso y que me devuelva un mensaje de error indicándome cual es el producto que no tiene saldo. El Procedure funciona es decir que cuando no encuentra saldo se corta el proceso pero no me devuelve el mensaje de Error. les muestro parte del código para que me den una mano.

Código MySQL:
Ver original
  1. DECLARE alm CHAR(4);
  2. DECLARE cod varchar(20);
  3. DECLARE cant int;
  4. DECLARE specialty CONDITION FOR SQLSTATE '45000';
  5. DECLARE items cursor for select id_alm,id_articulo,sum(cantidad) from ActStock where id_cia=cia and tipo=tip and serie=seri and numero=num GROUP BY ID_ARTICULO;
  6. DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET done = 1;
  7. SET @d=concat('insert into ActStock select ''',cia,''',id_almacen,tipo,serie,numero,id_Articulo,cantidad from ',TAB,' where tipo=''',TIP,''' and serie=''',SERI,''' and numero=''',NUM,'''');
  8. PREPARE stmt2 FROM @d;
  9. EXECUTE stmt2;
  10. DROP PREPARE stmt2;
  11. OPEN items;
  12.     FETCH items INTO alm,cod,cant;
  13.     IF NOT done THEN
  14.   IF OPE='-' then  
  15.             SET @d=CONCAT('SELECT @s:=STOCK FROM TB_STOCK',CIA,' WHERE ID_AGENCIA=''',AGE,''' AND ID_ALMACEN=''',ALM,''' AND ID_PRODUCTO=''',COD,'''');
  16.             PREPARE stmt2 FROM @d;
  17.             EXECUTE stmt2;
  18.             DROP PREPARE stmt2;
  19.             IF @s < CANT then
  20.                 DELETE FROM ActStock where id_cia=cia and tipo=tip and serie=seri and numero=num;
  21.                 SIGNAL specialty SET MESSAGE_TEXT = 'Producto sin stock';
  22.             END IF;
  23.         END IF;  
  24.     SET @d=CONCAT('INSERT INTO TB_STOCK',CIA,' values(''',AGE,''',''',alm,''',''',cod,''',''',if(OPE='+',cant,cant * -1),''',''0'') on duplicate key update stock=stock ',OPE,' ',cant);
  25.             PREPARE stmt2 FROM @d;
  26.       EXECUTE stmt2;
  27.        DROP PREPARE stmt2;
  28.     END IF;
  29. UNTIL done END REPEAT;
  30. CLOSE items;
  31. DELETE FROM ActStock where id_cia=cia and tipo=tip and serie=seri and numero=num;
De antemano muchas gracias. cualquier ayuda me servira.