CREATE OR REPLACE 
TRIGGER ATUALIZA_SUBPRODUTO
BEFORE INSERT OR UPDATE OF CDSISTEMA ON SOLISERV FOR EACH ROW
BEGIN
   IF (:NEW.CDSISTEMA IS NOT NULL) THEN
      IF SUBSTR(:NEW.CDSISTEMA, 1, 3) IN ('WIN', 'WEB', 'PLM', 'WWW') THEN
         IF SUBSTR(:NEW.CDSISTEMA, 5 , 3) = 'ADM' THEN
            :NEW.CDPRODCOMP := '0000000080';
         ELSIF SUBSTR(:NEW.CDSISTEMA, 5 , 3) = 'AGE' THEN
            :NEW.CDPRODCOMP := '0000000481';
         ELSIF SUBSTR(:NEW.CDSISTEMA, 5 , 3) = 'AEV' THEN
            :NEW.CDPRODCOMP := '0000000382';
         ELSIF SUBSTR(:NEW.CDSISTEMA, 5 , 3) = 'AMB' THEN
            :NEW.CDPRODCOMP := '0000000376';
         ELSIF SUBSTR(:NEW.CDSISTEMA, 5 , 3) = 'ATE' THEN
            :NEW.CDPRODCOMP := '0000000082';
         ELSIF SUBSTR(:NEW.CDSISTEMA, 5 , 3) = 'ATH' THEN
            :NEW.CDPRODCOMP := '0000000083';
         ELSIF SUBSTR(:NEW.CDSISTEMA, 5 , 3) = 'BCO' THEN
            :NEW.CDPRODCOMP := '0000000097';
         ELSIF SUBSTR(:NEW.CDSISTEMA, 5 , 3) = 'BSG' THEN
            :NEW.CDPRODCOMP := '0000000085';
         ELSIF SUBSTR(:NEW.CDSISTEMA, 5 , 3) = 'CAD' THEN
            :NEW.CDPRODCOMP := '0000000110';
         ELSIF SUBSTR(:NEW.CDSISTEMA, 5 , 3) = 'CDG' THEN
            :NEW.CDPRODCOMP := '0000000088';
         ELSIF SUBSTR(:NEW.CDSISTEMA, 5 , 3) = 'CME' THEN
            :NEW.CDPRODCOMP := '0000000089';
         ELSIF SUBSTR(:NEW.CDSISTEMA, 5 , 3) = 'COC' THEN
            :NEW.CDPRODCOMP := '0000000091';
         ELSIF SUBSTR(:NEW.CDSISTEMA, 5 , 3) = 'CMP' THEN
            :NEW.CDPRODCOMP := '0000000092';
         ELSIF SUBSTR(:NEW.CDSISTEMA, 5 , 3) = 'CSA' THEN
            :NEW.CDPRODCOMP := '0000000379';
         ELSIF SUBSTR(:NEW.CDSISTEMA, 5 , 3) = 'CUS' THEN
            :NEW.CDPRODCOMP := '0000000112';
         ELSIF SUBSTR(:NEW.CDSISTEMA, 5 , 3) = 'CTB' THEN
            :NEW.CDPRODCOMP := '0000000094';
         ELSIF SUBSTR(:NEW.CDSISTEMA, 5 , 3) = 'DFE' THEN
            :NEW.CDPRODCOMP := '0000000113';
         ELSIF SUBSTR(:NEW.CDSISTEMA, 5 , 3) = 'DFS' THEN
            :NEW.CDPRODCOMP := '0000000114';
         ELSIF SUBSTR(:NEW.CDSISTEMA, 5 , 3) = 'DIC' THEN
            :NEW.CDPRODCOMP := '0000000107';
         ELSIF SUBSTR(:NEW.CDSISTEMA, 5 , 3) = 'DIH' THEN
            :NEW.CDPRODCOMP := '0000000106';
         ELSIF SUBSTR(:NEW.CDSISTEMA, 5 , 3) = 'EMP' THEN
            :NEW.CDPRODCOMP := '0000000115';
         ELSIF SUBSTR(:NEW.CDSISTEMA, 5 , 3) = 'ESP' THEN
            :NEW.CDPRODCOMP := '0000000117';
         ELSIF SUBSTR(:NEW.CDSISTEMA, 5 , 3) = 'EST' THEN
            :NEW.CDPRODCOMP := '0000000116';
         ELSIF SUBSTR(:NEW.CDSISTEMA, 5 , 3) = 'ETH' THEN
            :NEW.CDPRODCOMP := '0000000138';
         ELSIF SUBSTR(:NEW.CDSISTEMA, 5 , 3) = 'FAI' THEN
            :NEW.CDPRODCOMP := '0000000119';
         ELSIF SUBSTR(:NEW.CDSISTEMA, 5 , 3) = 'FAC' THEN
            :NEW.CDPRODCOMP := '0000000118';
         ELSIF SUBSTR(:NEW.CDSISTEMA, 5 , 3) = 'FAH' THEN
            :NEW.CDPRODCOMP := '0000000139';
         ELSIF SUBSTR(:NEW.CDSISTEMA, 5 , 3) = 'FAS' THEN
            :NEW.CDPRODCOMP := '0000000120';
         ELSIF SUBSTR(:NEW.CDSISTEMA, 5 , 3) = 'FAV' THEN
            :NEW.CDPRODCOMP := '0000000140';
         ELSIF SUBSTR(:NEW.CDSISTEMA, 5 , 3) = 'FIS' THEN
            :NEW.CDPRODCOMP := '0000000121';
         ELSIF SUBSTR(:NEW.CDSISTEMA, 5 , 3) = 'FPG' THEN
            :NEW.CDPRODCOMP := '0000000141';
         ELSIF SUBSTR(:NEW.CDSISTEMA, 5 , 3) = 'GEP' THEN
            :NEW.CDPRODCOMP := '0000000142';
         ELSIF SUBSTR(:NEW.CDSISTEMA, 5 , 3) = 'GER' THEN
            :NEW.CDPRODCOMP := '0000000122';
         ELSIF SUBSTR(:NEW.CDSISTEMA, 5 , 3) = 'GQL' THEN
            :NEW.CDPRODCOMP := '0000000143';
         ELSIF SUBSTR(:NEW.CDSISTEMA, 5 , 3) = 'GSQ' THEN
            :NEW.CDPRODCOMP := '0000000123';
         ELSIF SUBSTR(:NEW.CDSISTEMA, 5 , 3) = 'IMO' THEN
            :NEW.CDPRODCOMP := '0000000084';
         ELSIF SUBSTR(:NEW.CDSISTEMA, 5 , 3) = 'LIB' THEN
            :NEW.CDPRODCOMP := '0000000086';
         ELSIF SUBSTR(:NEW.CDSISTEMA, 5 , 3) = 'LOJ' THEN
            :NEW.CDPRODCOMP := '0000000124';
         ELSIF SUBSTR(:NEW.CDSISTEMA, 5 , 3) = 'MAN' THEN
            :NEW.CDPRODCOMP := '0000000125';
         ELSIF SUBSTR(:NEW.CDSISTEMA, 5 , 3) = 'MEQ' THEN
            :NEW.CDPRODCOMP := '0000000144';
         ELSIF SUBSTR(:NEW.CDSISTEMA, 5 , 3) = 'ORP' THEN
            :NEW.CDPRODCOMP := '0000000108';
         ELSIF SUBSTR(:NEW.CDSISTEMA, 5 , 3) = 'PAG' THEN
            :NEW.CDPRODCOMP := '0000000095';
         ELSIF SUBSTR(:NEW.CDSISTEMA, 5 , 3) = 'PED' THEN
            :NEW.CDPRODCOMP := '0000000129';
         ELSIF SUBSTR(:NEW.CDSISTEMA, 5 , 3) = 'PES' THEN
            :NEW.CDPRODCOMP := '0000000145';
         ELSIF SUBSTR(:NEW.CDSISTEMA, 5 , 3) = 'PAH' THEN
            :NEW.CDPRODCOMP := '0000000126';
         ELSIF SUBSTR(:NEW.CDSISTEMA, 5 , 3) = 'PLA' THEN
            :NEW.CDPRODCOMP := '0000000130';
         ELSIF SUBSTR(:NEW.CDSISTEMA, 5 , 3) = 'PCP' THEN
            :NEW.CDPRODCOMP := '0000000127';
         ELSIF SUBSTR(:NEW.CDSISTEMA, 5 , 3) = 'PDV' THEN
            :NEW.CDPRODCOMP := '0000000128';
         ELSIF SUBSTR(:NEW.CDSISTEMA, 5 , 3) = 'QFO' THEN
            :NEW.CDPRODCOMP := '0000000131';
         ELSIF SUBSTR(:NEW.CDSISTEMA, 5 , 3) = 'QPR' THEN
            :NEW.CDPRODCOMP := '0000000109';
         ELSIF SUBSTR(:NEW.CDSISTEMA, 5 , 3) = 'REC' THEN
            :NEW.CDPRODCOMP := '0000000096';
         ELSIF SUBSTR(:NEW.CDSISTEMA, 5 , 3) = 'RES' THEN
            :NEW.CDPRODCOMP := '0000000476';
         ELSIF SUBSTR(:NEW.CDSISTEMA, 5 , 3) = 'RHM' THEN
            :NEW.CDPRODCOMP := '0000000132';
         ELSIF SUBSTR(:NEW.CDSISTEMA, 5 , 3) = 'SAC' THEN
            :NEW.CDPRODCOMP := '0000000398';
         ELSIF SUBSTR(:NEW.CDSISTEMA, 5 , 3) = 'SRV' THEN
            :NEW.CDPRODCOMP := '0000000133';
         ELSIF SUBSTR(:NEW.CDSISTEMA, 5 , 3) = 'SUP' THEN
            :NEW.CDPRODCOMP := '0000000134';
         ELSIF SUBSTR(:NEW.CDSISTEMA, 5 , 3) = 'TRD' THEN
            :NEW.CDPRODCOMP := '0000000135';
         ELSIF SUBSTR(:NEW.CDSISTEMA, 5 , 3) = 'VMN' THEN
            :NEW.CDPRODCOMP := '0000000136';
         ELSIF SUBSTR(:NEW.CDSISTEMA, 5 , 3) = 'VRF' THEN
            :NEW.CDPRODCOMP := '0000000137';
         END IF;
         :NEW.CDPRODGRUP := '0000000078';
      ELSE
         IF SUBSTR(:NEW.CDSISTEMA, 5 , 3) = 'ACG' THEN
            :NEW.CDPRODCOMP := '0000000155';
         ELSIF SUBSTR(:NEW.CDSISTEMA, 5 , 3) = 'ADM' THEN
            :NEW.CDPRODCOMP := '0000000156';
         ELSIF SUBSTR(:NEW.CDSISTEMA, 5 , 3) = 'ATC' THEN
            :NEW.CDPRODCOMP := '0000000157';
         ELSIF SUBSTR(:NEW.CDSISTEMA, 5 , 3) = 'BCO' THEN
            :NEW.CDPRODCOMP := '0000000158';
         ELSIF SUBSTR(:NEW.CDSISTEMA, 5 , 3) = 'CMP' THEN
            :NEW.CDPRODCOMP := '0000000159';
         ELSIF SUBSTR(:NEW.CDSISTEMA, 5 , 3) = 'COM' THEN
            :NEW.CDPRODCOMP := '0000000160';
         ELSIF SUBSTR(:NEW.CDSISTEMA, 5 , 3) = 'CTB' THEN
            :NEW.CDPRODCOMP := '0000000161';
         ELSIF SUBSTR(:NEW.CDSISTEMA, 5 , 3) = 'CUS' THEN
            :NEW.CDPRODCOMP := '0000000162';
         ELSIF SUBSTR(:NEW.CDSISTEMA, 5 , 3) = 'ESC' THEN
            :NEW.CDPRODCOMP := '0000000501';
         ELSIF SUBSTR(:NEW.CDSISTEMA, 5 , 3) = 'ESP' THEN
            :NEW.CDPRODCOMP := '0000000502';
         ELSIF SUBSTR(:NEW.CDSISTEMA, 5 , 3) = 'EST' THEN
            :NEW.CDPRODCOMP := '0000000163';
         ELSIF SUBSTR(:NEW.CDSISTEMA, 5 , 3) = 'FAT' THEN
            :NEW.CDPRODCOMP := '0000000164';
         ELSIF SUBSTR(:NEW.CDSISTEMA, 5 , 3) = 'FIS' THEN
            :NEW.CDPRODCOMP := '0000000165';
         ELSIF SUBSTR(:NEW.CDSISTEMA, 5 , 3) = 'GER' THEN
            :NEW.CDPRODCOMP := '0000000166';
         ELSIF SUBSTR(:NEW.CDSISTEMA, 5 , 3) = 'GES' THEN
            :NEW.CDPRODCOMP := '0000000500';
         ELSIF SUBSTR(:NEW.CDSISTEMA, 5 , 3) = 'INT' THEN
            :NEW.CDPRODCOMP := '0000000498';
         ELSIF SUBSTR(:NEW.CDSISTEMA, 5 , 3) = 'ORC' THEN
            :NEW.CDPRODCOMP := '0000000167';
         ELSIF SUBSTR(:NEW.CDSISTEMA, 5 , 3) = 'PAG' THEN
            :NEW.CDPRODCOMP := '0000000168';
         ELSIF SUBSTR(:NEW.CDSISTEMA, 5 , 3) = 'PLA' THEN
            :NEW.CDPRODCOMP := '0000000169';
         ELSIF SUBSTR(:NEW.CDSISTEMA, 5 , 3) = 'QTT' THEN
            :NEW.CDPRODCOMP := '0000000170';
         ELSIF SUBSTR(:NEW.CDSISTEMA, 5 , 3) = 'REC' THEN
            :NEW.CDPRODCOMP := '0000000171';
         ELSIF SUBSTR(:NEW.CDSISTEMA, 5 , 3) = 'REL' THEN
            :NEW.CDPRODCOMP := '0000000172';
         ELSIF SUBSTR(:NEW.CDSISTEMA, 5 , 3) = 'SUP' THEN
            :NEW.CDPRODCOMP := '0000000173';
         ELSIF SUBSTR(:NEW.CDSISTEMA, 5 , 3) = 'TFS' THEN
            :NEW.CDPRODCOMP := '0000000174';
         ELSIF SUBSTR(:NEW.CDSISTEMA, 5 , 3) = 'TRH' THEN
            :NEW.CDPRODCOMP := '0000000175';
         END IF;
         :NEW.CDPRODGRUP := '0000000102';
      END IF;
   END IF;   
END;
/