CREATE OR REPLACE PROCEDURE SPED_CONTABIL_CENTROCUSTO (
   P_NRSEQARQMAG  IN ARQMAGNETICO.NRSEQARQMAG%TYPE,
   P_DTFINAL IN DATE,
   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_I100 IN (
   SELECT '|I100|'||
          TO_CHAR(P_DTFINAL,'DDMMYYYY')||'|'||
          C.CDCENTCUST||'|'||
          RETIRA_CARACTER_ESPECIAL(C.NMCENTCUST,'S')||'|' AS DSLINHA
   FROM CENTCUST C
   ORDER BY C.CDCENTCUST) LOOP

      V_NRORDREGARQ := V_NRORDREGARQ + 1;
      INSERT INTO ARQMAGNETICO
        (NRORDREGARQ, DSREGARQMAG, NRSEQARQMAG)
      VALUES
        (LPAD(TO_CHAR(V_NRORDREGARQ),10,'0'), C_I100.DSLINHA, P_NRSEQARQMAG);
   END LOOP;

   P_NRORDREGARQ := V_NRORDREGARQ;
END;
/