/*
indsæt iddocreg og programmet tæller op hvor mange dubletter der findes
i hele ib-basen, og gemmer iddocstrucf i tabellen tab_count_double
*/ 

IS
   iddocstruct_gl NUMBER(10) :=0;
   iddocstrucf_gl NUMBER(10) :=0;
   idhid_gl NUMBER(10) :=0;
   dato_gl DATE;

BEGIN
   DELETE FROM tab_count_double;

DECLARE
   CURSOR check_for_double IS
      SELECT iddocstruct, iddocstrucf, idhid, dateto FROM docstrucrel order by iddocstruct, iddocstrucf;
   BEGIN 
      FOR counter IN check_for_double
      LOOP
         IF iddocstruct_gl = counter.iddocstruct THEN
            IF idhid_gl = counter.idhid THEN
               IF dato_gl > sysdate THEN
                  IF counter.dateto > sysdate THEN
                     IF iddocstruct_gl != iddocstrucf_gl THEN
                        insert into tab_count_double (nummer)VALUES
                           (counter.iddocstruct);
                     END IF; 
                  END IF; 
            END IF; 
         END IF;
      END IF; 
      iddocstruct_gl := counter.iddocstruct;
         iddocstrucf_gl := counter.iddocstrucf;
         idhid_gl := counter.idhid;
         dato_gl := counter.dateto; 
      END LOOP;
   END; 
END;