CREATE OR REPLACE TRIGGER USR_ATU_PRAZOPGTAF_SAP
BEFORE INSERT
   ON PRAZOPGTAF FOR EACH ROW
DECLARE
  V_NRINSJURFORN VARCHAR2(20);
BEGIN
   BEGIN
      SELECT MAX(NRINSJURFORN)
        INTO V_NRINSJURFORN
        FROM FORNECEDOR, AUTOFORNE
       WHERE AUTOFORNE.CDFILDEST   = :NEW.CDFILDEST
         AND AUTOFORNE.CDFILLANC   = :NEW.CDFILLANC
         AND AUTOFORNE.NRAUTOFORN  = :NEW.NRAUTOFORN
         AND FORNECEDOR.CDFORNECED = AUTOFORNE.CDFORNECED
         AND NVL(FORNECEDOR.USR_INTEGRAMESAP, 'N') = 'S';
   EXCEPTION
      WHEN NO_DATA_FOUND THEN
         V_NRINSJURFORN := NULL;
   END;
   IF V_NRINSJURFORN IS NOT NULL THEN
      :NEW.USR_IDINTEGRAMESAP  := 'S';
   END IF;
END;
/

-- VERSAO --
BEGIN ATUVEROBJ('USR_ATU_PRAZOPGTAF_SAP','6.02.XXX'); END;
/