IF EXISTS(SELECT * FROM sysobjects O, sysusers U
          WHERE
            o.name = 'ARQDIGITAL_BLOCO8' and
            type = 'P'                   and
            u.uid = o.uid                and
            u.name = USER)
DROP PROCEDURE ARQDIGITAL_BLOCO8
GO

CREATE PROCEDURE ARQDIGITAL_BLOCO8
   @P_CDEMPRESA   VARCHAR(4000),
   @P_NRSEQARQMAG VARCHAR(4000), 
   @P_RETURN      NUMERIC OUTPUT 
AS
BEGIN
DECLARE   @V_REGTOT8 NUMERIC;

   /* ABERTURA DO BLOCO 8 */
   INSERT INTO ARQMAGNETICO
        (NRORDREGARQ, DSREGARQMAG, NRSEQARQMAG)
      VALUES
      ('47'+ RIGHT(REPLICATE('0', 8) + '1', 8), '|8001'+'|'+ '1' +'|'+'DF'+'|', @P_NRSEQARQMAG);
   SET @V_REGTOT8 = ISNULL(@V_REGTOT8,0) + 1;

   /* ENCERRAMENTO DO BLOCO 8 */
   SET @V_REGTOT8 = ISNULL(@V_REGTOT8,0) + 1;

   INSERT INTO ARQMAGNETICO
        (NRORDREGARQ, DSREGARQMAG, NRSEQARQMAG)
   VALUES
     ('48'+ RIGHT(REPLICATE('0', 8) + '1', 8), '|8990'+'|'+'2'+'|', @P_NRSEQARQMAG);	

   SET @P_RETURN = @V_REGTOT8; 
END
GO

-- VERSAO --
EXEC ATUVEROBJ 'ARQDIGITAL_BLOCO8','5.05.008';
GO

