create or replace FUNCTION ARQDIGITAL_BLOCOD( 
   P_CDIMPOSTO    IN IMPOSTO.CDIMPOSTO%TYPE, 
   P_CDEMPRESA    IN EMPRESA.CDEMPRESA%TYPE, 
   P_CDINSCESTA   IN EMPRESA.CDINSCESTA%TYPE, 
   P_DTINICIAL    IN NOTAFISCAL.DTENTRSAID%TYPE, 
   P_DTFINAL      IN NOTAFISCAL.DTENTRSAID%TYPE,  
   P_NRSEQARQMAG  IN ARQMAGNETICO.NRSEQARQMAG%TYPE) RETURN NUMBER  
AS  
   V_CONTREGD        NUMBER;  
   V_MOVIMENT        NUMBER;  
   V_IDENCARGODOS    VARCHAR2(04);  
BEGIN  
   IF V_CONTREGD <> 0 THEN  
      V_MOVIMENT := 0;  
   ELSE  
      V_MOVIMENT := 1;  
   END IF;  
   V_CONTREGD := NVL(V_CONTREGD,0) + 1;  
   INSERT INTO ARQMAGNETICO  
     (NRORDREGARQ, DSREGARQMAG, NRSEQARQMAG)  
   VALUES  
     ('24'||LPAD(RTRIM(V_CONTREGD), 8, '0'), '|D001'|| '|' ||'1'|| '|' , P_NRSEQARQMAG);  
   V_CONTREGD := NVL(V_CONTREGD,0) + 1; 
   INSERT INTO ARQMAGNETICO 
     (NRORDREGARQ, DSREGARQMAG, NRSEQARQMAG) 
   VALUES 
     ('28'||LPAD(RTRIM(V_CONTREGD), 8, '0'), '|D990'|| '|' ||V_CONTREGD|| '|', P_NRSEQARQMAG); 
   RETURN(V_CONTREGD); 
END; 
/

-- VERSAO --
BEGIN ATUVEROBJ('ARQDIGITAL_BLOCOD','5.30.030'); END;
/

