ALTER PROCEDURE OP_GrabarValesProc  
(@CORRNBR          int,  
 @DOCTYPEID        UD_DOCTYPEID,  
 @NBRDOCUMENT      UD_CORRELATIVOS,  
 @DATEPROCESALES   UD_FECHA)  
as  
BEGIN  
   -- Declaración de Variables       
  
   DECLARE @custidss  UD_CODCLIENT   
   DECLARE @SITEID    UD_IDSITE   
   DECLARE @NBRBONUS  NUMERIC(10)     
   DECLARE @ERROR     Integer       
   DECLARE @MONTOBONUS NUMERIC(9,4)  
   -- Declaración del Cursor   
   DECLARE OPBONUS CURSOR FOR  
           SELECT custidss,SITEID,NBRBONUS,MONTOBONUS FROM TMP_OP_BONUS WHERE CORRNBR=@CORRNBR   
      OPEN OPBONUS  
      FETCH NEXT FROM OPBONUS INTO @custidss,@SITEID,@NBRBONUS,@MONTOBONUS                 
  
      WHILE @@FETCH_STATUS = 0  
           BEGIN            
              INSERT INTO OP_BONUS (DOCTYPEID,NBRDOCUMENT,custidss,SITEID,NBRBONUS,DATEPROCESALES,MONTOBONUS)   
                          VALUES(@DOCTYPEID,@NBRDOCUMENT,@custidss,@SITEID,@NBRBONUS,@DATEPROCESALES,@MONTOBONUS)  
  
              SET @ERROR=@@error  
       
                IF (@ERROR!=0)  
                  BEGIN         
                    CLOSE OPBONUS  
                    DEALLOCATE OPBONUS  
                    RETURN(1)    
                  END   
               
              FETCH NEXT FROM OPBONUS INTO @custidss,@SITEID,@NBRBONUS,@MONTOBONUS                                  
           END  
    
      CLOSE OPBONUS  
      DEALLOCATE OPBONUS  
      RETURN (0)           
END  
