CREATE OR REPLACE PROCEDURE SPED_CONTABIL_HISTORICO (
   P_NRSEQARQMAG  IN ARQMAGNETICO.NRSEQARQMAG%TYPE,
   P_NRINIORDENA  IN INTEGER,
   P_IDSPED       IN VARCHAR2, /* PARAMETRO QUE DEFINE SE SERA GERADO SPED OU FCONT */   
   P_NRORDREGARQ  OUT INTEGER)
IS
   V_NRORDREGARQ INTEGER;
   V_AUXILIAR    VARCHAR2(200);
BEGIN
   V_NRORDREGARQ := P_NRINIORDENA;
   /*NAO HOUVERAM ALTERACOES PARA A VERSAO 7.00*/
   FOR C_I075 IN (
   SELECT '|I075|'||
          H.CDHISTPADR||'|'||
          RETIRA_CARACTER_ESPECIAL(H.DSHISTPADR,'S')||'|' AS DSLINHA
   FROM HISTPADR H
   ORDER BY H.CDHISTPADR) LOOP
      V_NRORDREGARQ := V_NRORDREGARQ + 1;
      INSERT INTO ARQMAGNETICO
        (NRORDREGARQ, DSREGARQMAG, NRSEQARQMAG)
      VALUES
        (LPAD(TO_CHAR(V_NRORDREGARQ),10,'0'), C_I075.DSLINHA, P_NRSEQARQMAG);
   END LOOP;
   P_NRORDREGARQ := V_NRORDREGARQ;
END;