Trigger Oralce

Trigger Oralce

-- **************************************************************************
-- gcommovh_upd
-- DEISTER WebStudio XSQL-TRIGGER Mon Oct 10 18:58:30 CEST 2011 Engine: oracle
-- **************************************************************************

-- **************************************************************************
-- PACKAGE FOR MUTATING TABLES USING METHOD ASSOCIATIVE ARRAYS gcommovh_pkg
-- **************************************************************************
CREATE OR REPLACE  PACKAGE gcommovh_pkg
  AS  
    type ridArray is table of gcommovh%ROWTYPE index by binary_integer; 
    type rowidArray is table of rowid index by binary_integer;

    nxtRows ridArray;
    prvRows ridArray;
    empty ridArray;
    rowids rowidArray;
    empty_rd rowidArray;
END;
.
run


-- **************************************************************************
-- TRIGGER: gcommovh_upd_b (BEFORE-update)
-- **************************************************************************
CREATE OR REPLACE TRIGGER gcommovh_upd_b
BEFORE UPDATE ON gcommovh
DECLARE
BEGIN

 gcommovh_pkg.nxtRows := gcommovh_pkg.empty;
 gcommovh_pkg.prvRows := gcommovh_pkg.empty;
gcommovh_pkg.rowids :=  gcommovh_pkg.empty_rd;
   -- Instruccion nula por si el body del trigger esta vacio.
   null;

END gcommovh_upd_b;
.
run



-- **************************************************************************
-- TRIGGER: gcommovh_upd_pre (BEFORE-update-FOR EACH ROW)
-- Functions and Procedures[out].
-- **************************************************************************
CREATE OR REPLACE TRIGGER gcommovh_upd_pre
BEFORE UPDATE ON gcommovh
REFERENCING NEW AS nxt OLD AS prv
FOR EACH ROW
DECLARE
BEGIN

   -- Instruccion nula por si el body del trigger esta vacio.
   null;

    IF (:prv.movest  = 1                 AND
                :prv.movest  = :nxt.movest AND
                :prv.movhis  = :nxt.movhis AND
                :nxt.movhis != -1
            ) THEN
     :nxt.movest := sdm_set_value('0');

    END IF;

    IF (:prv.movhis = 1                 AND
                :prv.movhis = :nxt.movhis AND
               (:prv.movest = :nxt.movest OR :prv.movest = 1 AND :nxt.movest = 0)
            ) THEN
     :nxt.movhis := sdm_set_value('0');

    END IF;

END gcommovh_upd_pre;
.
run



-- **************************************************************************
-- TRIGGER: gcommovh_upd (AFTER-update-FOR EACH ROW)
-- **************************************************************************
CREATE OR REPLACE TRIGGER gcommovh_upd
AFTER UPDATE ON gcommovh
REFERENCING NEW AS nxt OLD AS prv
FOR EACH ROW
DECLARE
    N65620 integer;
    N65696 integer;
    N65705 integer;
    N65736 integer;
    N65745 integer;
    N66048 integer;
    N66090 integer;
    N66220 integer;
    N66253 integer;
    N66399 integer;
BEGIN

 
    -- Colocamos en el array de rowids en nxt, ya lo que utilizaremos en procedures OUT
    gcommovh_pkg.rowids(gcommovh_pkg.rowids.count+1) := :nxt.rowid;
    -- Para cada tag prv y nxt seteamos el valor en el vector correspondiente del package
    -- Block nxtRows. First line increments count (index of row).
    gcommovh_pkg.nxtRows(gcommovh_pkg.nxtRows.count+1).tipdoc := :nxt.tipdoc;
    gcommovh_pkg.nxtRows(gcommovh_pkg.nxtRows.count).movhis := :nxt.movhis;
    gcommovh_pkg.nxtRows(gcommovh_pkg.nxtRows.count).almori := :nxt.almori;
    gcommovh_pkg.nxtRows(gcommovh_pkg.nxtRows.count).almdes := :nxt.almdes;
    gcommovh_pkg.nxtRows(gcommovh_pkg.nxtRows.count).almdes := :nxt.almdes;
    gcommovh_pkg.nxtRows(gcommovh_pkg.nxtRows.count).almdes := :nxt.almdes;
    gcommovh_pkg.nxtRows(gcommovh_pkg.nxtRows.count).docori := :nxt.docori;
    gcommovh_pkg.nxtRows(gcommovh_pkg.nxtRows.count).movhis := :nxt.movhis;
    gcommovh_pkg.nxtRows(gcommovh_pkg.nxtRows.count).cabid := :nxt.cabid;
    gcommovh_pkg.nxtRows(gcommovh_pkg.nxtRows.count).docori := :nxt.docori;
    gcommovh_pkg.nxtRows(gcommovh_pkg.nxtRows.count).delega := :nxt.delega;
    gcommovh_pkg.nxtRows(gcommovh_pkg.nxtRows.count).tercer := :nxt.tercer;
    gcommovh_pkg.nxtRows(gcommovh_pkg.nxtRows.count).movhis := :nxt.movhis;
    gcommovh_pkg.nxtRows(gcommovh_pkg.nxtRows.count).delega := :nxt.delega;
    gcommovh_pkg.nxtRows(gcommovh_pkg.nxtRows.count).tercer := :nxt.tercer;
    gcommovh_pkg.nxtRows(gcommovh_pkg.nxtRows.count).terenv := :nxt.terenv;
    gcommovh_pkg.nxtRows(gcommovh_pkg.nxtRows.count).divisa := :nxt.divisa;
    gcommovh_pkg.nxtRows(gcommovh_pkg.nxtRows.count).movhis := :nxt.movhis;
    gcommovh_pkg.nxtRows(gcommovh_pkg.nxtRows.count).tipdoc := :nxt.tipdoc;
    gcommovh_pkg.nxtRows(gcommovh_pkg.nxtRows.count).cabid := :nxt.cabid;
    gcommovh_pkg.nxtRows(gcommovh_pkg.nxtRows.count).fecmov := :nxt.fecmov;
    gcommovh_pkg.nxtRows(gcommovh_pkg.nxtRows.count).movhis := :nxt.movhis;
    gcommovh_pkg.nxtRows(gcommovh_pkg.nxtRows.count).tipdoc := :nxt.tipdoc;
    gcommovh_pkg.nxtRows(gcommovh_pkg.nxtRows.count).almori := :nxt.almori;
    gcommovh_pkg.nxtRows(gcommovh_pkg.nxtRows.count).almdes := :nxt.almdes;
    gcommovh_pkg.nxtRows(gcommovh_pkg.nxtRows.count).fecmov := :nxt.fecmov;
    gcommovh_pkg.nxtRows(gcommovh_pkg.nxtRows.count).impnxt := :nxt.impnxt;
    gcommovh_pkg.nxtRows(gcommovh_pkg.nxtRows.count).conten := :nxt.conten;
    gcommovh_pkg.nxtRows(gcommovh_pkg.nxtRows.count).dosier := :nxt.dosier;
    gcommovh_pkg.nxtRows(gcommovh_pkg.nxtRows.count).destra := :nxt.destra;
    gcommovh_pkg.nxtRows(gcommovh_pkg.nxtRows.count).desadu := :nxt.desadu;
    gcommovh_pkg.nxtRows(gcommovh_pkg.nxtRows.count).docser := :nxt.docser;
    gcommovh_pkg.nxtRows(gcommovh_pkg.nxtRows.count).movest := :nxt.movest;
    gcommovh_pkg.nxtRows(gcommovh_pkg.nxtRows.count).movhis := :nxt.movhis;
    gcommovh_pkg.nxtRows(gcommovh_pkg.nxtRows.count).movhis := :nxt.movhis;
    gcommovh_pkg.nxtRows(gcommovh_pkg.nxtRows.count).movhis := :nxt.movhis;
    gcommovh_pkg.nxtRows(gcommovh_pkg.nxtRows.count).movest := :nxt.movest;
    gcommovh_pkg.nxtRows(gcommovh_pkg.nxtRows.count).movest := :nxt.movest;
    gcommovh_pkg.nxtRows(gcommovh_pkg.nxtRows.count).movest := :nxt.movest;
    gcommovh_pkg.nxtRows(gcommovh_pkg.nxtRows.count).movest := :nxt.movest;
    gcommovh_pkg.nxtRows(gcommovh_pkg.nxtRows.count).movhis := :nxt.movhis;
    gcommovh_pkg.nxtRows(gcommovh_pkg.nxtRows.count).cabid := :nxt.cabid;
    gcommovh_pkg.nxtRows(gcommovh_pkg.nxtRows.count).movhis := :nxt.movhis;
    gcommovh_pkg.nxtRows(gcommovh_pkg.nxtRows.count).movhis := :nxt.movhis;
    gcommovh_pkg.nxtRows(gcommovh_pkg.nxtRows.count).cabid := :nxt.cabid;
    gcommovh_pkg.nxtRows(gcommovh_pkg.nxtRows.count).movest := :nxt.movest;
    gcommovh_pkg.nxtRows(gcommovh_pkg.nxtRows.count).movest := :nxt.movest;
    gcommovh_pkg.nxtRows(gcommovh_pkg.nxtRows.count).movhis := :nxt.movhis;
    gcommovh_pkg.nxtRows(gcommovh_pkg.nxtRows.count).cabid := :nxt.cabid;
    gcommovh_pkg.nxtRows(gcommovh_pkg.nxtRows.count).movhis := :nxt.movhis;
    gcommovh_pkg.nxtRows(gcommovh_pkg.nxtRows.count).movhis := :nxt.movhis;
    gcommovh_pkg.nxtRows(gcommovh_pkg.nxtRows.count).cabid := :nxt.cabid;
    gcommovh_pkg.nxtRows(gcommovh_pkg.nxtRows.count).estcab := :nxt.estcab;
    gcommovh_pkg.nxtRows(gcommovh_pkg.nxtRows.count).estcab := :nxt.estcab;
    gcommovh_pkg.nxtRows(gcommovh_pkg.nxtRows.count).fecrec := :nxt.fecrec;
    gcommovh_pkg.nxtRows(gcommovh_pkg.nxtRows.count).movhis := :nxt.movhis;
    gcommovh_pkg.nxtRows(gcommovh_pkg.nxtRows.count).estcab := :nxt.estcab;
    gcommovh_pkg.nxtRows(gcommovh_pkg.nxtRows.count).fecrec := :nxt.fecrec;
    gcommovh_pkg.nxtRows(gcommovh_pkg.nxtRows.count).fecrec := :nxt.fecrec;
    gcommovh_pkg.nxtRows(gcommovh_pkg.nxtRows.count).movhis := :nxt.movhis;
    gcommovh_pkg.nxtRows(gcommovh_pkg.nxtRows.count).docser := :nxt.docser;
    gcommovh_pkg.nxtRows(gcommovh_pkg.nxtRows.count).fecrec := :nxt.fecrec;
    gcommovh_pkg.nxtRows(gcommovh_pkg.nxtRows.count).fecmov := :nxt.fecmov;
    gcommovh_pkg.nxtRows(gcommovh_pkg.nxtRows.count).movhis := :nxt.movhis;
    gcommovh_pkg.nxtRows(gcommovh_pkg.nxtRows.count).cabid := :nxt.cabid;
    gcommovh_pkg.nxtRows(gcommovh_pkg.nxtRows.count).tercer := :nxt.tercer;
    gcommovh_pkg.nxtRows(gcommovh_pkg.nxtRows.count).delega := :nxt.delega;
    gcommovh_pkg.nxtRows(gcommovh_pkg.nxtRows.count).terenv := :nxt.terenv;
    gcommovh_pkg.nxtRows(gcommovh_pkg.nxtRows.count).divisa := :nxt.divisa;
    gcommovh_pkg.nxtRows(gcommovh_pkg.nxtRows.count).movhis := :nxt.movhis;
    gcommovh_pkg.nxtRows(gcommovh_pkg.nxtRows.count).cabid := :nxt.cabid;
    gcommovh_pkg.nxtRows(gcommovh_pkg.nxtRows.count).cabid := :nxt.cabid;
    gcommovh_pkg.nxtRows(gcommovh_pkg.nxtRows.count).cabid := :nxt.cabid;
    gcommovh_pkg.nxtRows(gcommovh_pkg.nxtRows.count).fconta := :nxt.fconta;
    gcommovh_pkg.nxtRows(gcommovh_pkg.nxtRows.count).movhis := :nxt.movhis;
    gcommovh_pkg.nxtRows(gcommovh_pkg.nxtRows.count).estcab := :nxt.estcab;
    gcommovh_pkg.nxtRows(gcommovh_pkg.nxtRows.count).movhis := :nxt.movhis;
    gcommovh_pkg.nxtRows(gcommovh_pkg.nxtRows.count).estcab := :nxt.estcab;
    gcommovh_pkg.nxtRows(gcommovh_pkg.nxtRows.count).estcab := :nxt.estcab;
    gcommovh_pkg.nxtRows(gcommovh_pkg.nxtRows.count).estcab := :nxt.estcab;
    gcommovh_pkg.nxtRows(gcommovh_pkg.nxtRows.count).estcab := :nxt.estcab;
    gcommovh_pkg.nxtRows(gcommovh_pkg.nxtRows.count).movhis := :nxt.movhis;
    gcommovh_pkg.nxtRows(gcommovh_pkg.nxtRows.count).dtogen := :nxt.dtogen;
    gcommovh_pkg.nxtRows(gcommovh_pkg.nxtRows.count).docori := :nxt.docori;
    gcommovh_pkg.nxtRows(gcommovh_pkg.nxtRows.count).movhis := :nxt.movhis;
    gcommovh_pkg.nxtRows(gcommovh_pkg.nxtRows.count).tipdoc := :nxt.tipdoc;
    gcommovh_pkg.nxtRows(gcommovh_pkg.nxtRows.count).dtogen := :nxt.dtogen;
    gcommovh_pkg.nxtRows(gcommovh_pkg.nxtRows.count).cabid := :nxt.cabid;
    gcommovh_pkg.nxtRows(gcommovh_pkg.nxtRows.count).docori := :nxt.docori;
    gcommovh_pkg.nxtRows(gcommovh_pkg.nxtRows.count).dtogen := :nxt.dtogen;
    gcommovh_pkg.nxtRows(gcommovh_pkg.nxtRows.count).fecmov := :nxt.fecmov;
    gcommovh_pkg.nxtRows(gcommovh_pkg.nxtRows.count).dtopp := :nxt.dtopp;
    gcommovh_pkg.nxtRows(gcommovh_pkg.nxtRows.count).movhis := :nxt.movhis;
    gcommovh_pkg.nxtRows(gcommovh_pkg.nxtRows.count).tipdoc := :nxt.tipdoc;
    gcommovh_pkg.nxtRows(gcommovh_pkg.nxtRows.count).dtogen := :nxt.dtogen;
    gcommovh_pkg.nxtRows(gcommovh_pkg.nxtRows.count).dtopp := :nxt.dtopp;
    gcommovh_pkg.nxtRows(gcommovh_pkg.nxtRows.count).fecmov := :nxt.fecmov;
    gcommovh_pkg.nxtRows(gcommovh_pkg.nxtRows.count).fecmov := :nxt.fecmov;
    gcommovh_pkg.nxtRows(gcommovh_pkg.nxtRows.count).cabid := :nxt.cabid;
    gcommovh_pkg.nxtRows(gcommovh_pkg.nxtRows.count).tipdoc := :nxt.tipdoc;
    gcommovh_pkg.nxtRows(gcommovh_pkg.nxtRows.count).movhis := :nxt.movhis;
    gcommovh_pkg.nxtRows(gcommovh_pkg.nxtRows.count).cabid := :nxt.cabid;
    gcommovh_pkg.nxtRows(gcommovh_pkg.nxtRows.count).delega := :nxt.delega;
    gcommovh_pkg.nxtRows(gcommovh_pkg.nxtRows.count).movhis := :nxt.movhis;
    gcommovh_pkg.nxtRows(gcommovh_pkg.nxtRows.count).cabid := :nxt.cabid;
    gcommovh_pkg.nxtRows(gcommovh_pkg.nxtRows.count).depart := :nxt.depart;
    gcommovh_pkg.nxtRows(gcommovh_pkg.nxtRows.count).movhis := :nxt.movhis;
    gcommovh_pkg.nxtRows(gcommovh_pkg.nxtRows.count).cabid := :nxt.cabid;
    gcommovh_pkg.nxtRows(gcommovh_pkg.nxtRows.count).almori := :nxt.almori;
    gcommovh_pkg.nxtRows(gcommovh_pkg.nxtRows.count).movhis := :nxt.movhis;
    gcommovh_pkg.nxtRows(gcommovh_pkg.nxtRows.count).cabid := :nxt.cabid;
    gcommovh_pkg.nxtRows(gcommovh_pkg.nxtRows.count).almdes := :nxt.almdes;
    gcommovh_pkg.nxtRows(gcommovh_pkg.nxtRows.count).movhis := :nxt.movhis;
    gcommovh_pkg.nxtRows(gcommovh_pkg.nxtRows.count).cabid := :nxt.cabid;
    gcommovh_pkg.nxtRows(gcommovh_pkg.nxtRows.count).refter := :nxt.refter;
    gcommovh_pkg.nxtRows(gcommovh_pkg.nxtRows.count).movhis := :nxt.movhis;
    gcommovh_pkg.nxtRows(gcommovh_pkg.nxtRows.count).cabid := :nxt.cabid;
    gcommovh_pkg.nxtRows(gcommovh_pkg.nxtRows.count).tipefe := :nxt.tipefe;
    gcommovh_pkg.nxtRows(gcommovh_pkg.nxtRows.count).movhis := :nxt.movhis;
    gcommovh_pkg.nxtRows(gcommovh_pkg.nxtRows.count).cabid := :nxt.cabid;
    gcommovh_pkg.nxtRows(gcommovh_pkg.nxtRows.count).frmpag := :nxt.frmpag;
    gcommovh_pkg.nxtRows(gcommovh_pkg.nxtRows.count).movhis := :nxt.movhis;
    gcommovh_pkg.nxtRows(gcommovh_pkg.nxtRows.count).cabid := :nxt.cabid;
    gcommovh_pkg.nxtRows(gcommovh_pkg.nxtRows.count).imptot := :nxt.imptot;
    gcommovh_pkg.nxtRows(gcommovh_pkg.nxtRows.count).movhis := :nxt.movhis;
    gcommovh_pkg.nxtRows(gcommovh_pkg.nxtRows.count).cabid := :nxt.cabid;
    gcommovh_pkg.nxtRows(gcommovh_pkg.nxtRows.count).tercer := :nxt.tercer;
    gcommovh_pkg.nxtRows(gcommovh_pkg.nxtRows.count).movhis := :nxt.movhis;
    gcommovh_pkg.nxtRows(gcommovh_pkg.nxtRows.count).cabid := :nxt.cabid;
    gcommovh_pkg.nxtRows(gcommovh_pkg.nxtRows.count).tipdir := :nxt.tipdir;
    gcommovh_pkg.nxtRows(gcommovh_pkg.nxtRows.count).movhis := :nxt.movhis;
    gcommovh_pkg.nxtRows(gcommovh_pkg.nxtRows.count).cabid := :nxt.cabid;
    gcommovh_pkg.nxtRows(gcommovh_pkg.nxtRows.count).terfac := :nxt.terfac;
    gcommovh_pkg.nxtRows(gcommovh_pkg.nxtRows.count).movhis := :nxt.movhis;
    gcommovh_pkg.nxtRows(gcommovh_pkg.nxtRows.count).cabid := :nxt.cabid;
    gcommovh_pkg.nxtRows(gcommovh_pkg.nxtRows.count).dirfac := :nxt.dirfac;
    gcommovh_pkg.nxtRows(gcommovh_pkg.nxtRows.count).movhis := :nxt.movhis;
    gcommovh_pkg.nxtRows(gcommovh_pkg.nxtRows.count).cabid := :nxt.cabid;
    gcommovh_pkg.nxtRows(gcommovh_pkg.nxtRows.count).divisa := :nxt.divisa;
    gcommovh_pkg.nxtRows(gcommovh_pkg.nxtRows.count).movhis := :nxt.movhis;
    gcommovh_pkg.nxtRows(gcommovh_pkg.nxtRows.count).cabid := :nxt.cabid;
    gcommovh_pkg.nxtRows(gcommovh_pkg.nxtRows.count).dtogen := :nxt.dtogen;
    gcommovh_pkg.nxtRows(gcommovh_pkg.nxtRows.count).movhis := :nxt.movhis;
    gcommovh_pkg.nxtRows(gcommovh_pkg.nxtRows.count).cabid := :nxt.cabid;
    gcommovh_pkg.nxtRows(gcommovh_pkg.nxtRows.count).dtopp := :nxt.dtopp;
    gcommovh_pkg.nxtRows(gcommovh_pkg.nxtRows.count).movhis := :nxt.movhis;
    gcommovh_pkg.nxtRows(gcommovh_pkg.nxtRows.count).cabid := :nxt.cabid;
    gcommovh_pkg.nxtRows(gcommovh_pkg.nxtRows.count).conten := :nxt.conten;
    gcommovh_pkg.nxtRows(gcommovh_pkg.nxtRows.count).movhis := :nxt.movhis;
    gcommovh_pkg.nxtRows(gcommovh_pkg.nxtRows.count).cabid := :nxt.cabid;
    gcommovh_pkg.nxtRows(gcommovh_pkg.nxtRows.count).impres := :nxt.impres;
    gcommovh_pkg.nxtRows(gcommovh_pkg.nxtRows.count).movhis := :nxt.movhis;
    gcommovh_pkg.nxtRows(gcommovh_pkg.nxtRows.count).cabid := :nxt.cabid;
    gcommovh_pkg.nxtRows(gcommovh_pkg.nxtRows.count).movhis := :nxt.movhis;
    gcommovh_pkg.nxtRows(gcommovh_pkg.nxtRows.count).tipdoc := :nxt.tipdoc;
    gcommovh_pkg.nxtRows(gcommovh_pkg.nxtRows.count).docser := :nxt.docser;
    gcommovh_pkg.nxtRows(gcommovh_pkg.nxtRows.count).impres := :nxt.impres;
    gcommovh_pkg.nxtRows(gcommovh_pkg.nxtRows.count).impres := :nxt.impres;
    gcommovh_pkg.nxtRows(gcommovh_pkg.nxtRows.count).movhis := :nxt.movhis;
    gcommovh_pkg.nxtRows(gcommovh_pkg.nxtRows.count).docser := :nxt.docser;
    gcommovh_pkg.nxtRows(gcommovh_pkg.nxtRows.count).tipdoc := :nxt.tipdoc;
    gcommovh_pkg.nxtRows(gcommovh_pkg.nxtRows.count).tipdoc := :nxt.tipdoc;
    -- Block prvRows. First line increments count (index of row).
    gcommovh_pkg.prvRows(gcommovh_pkg.prvRows.count+1).tipdoc := :prv.tipdoc;
    gcommovh_pkg.prvRows(gcommovh_pkg.prvRows.count).almori := :prv.almori;
    gcommovh_pkg.prvRows(gcommovh_pkg.prvRows.count).almdes := :prv.almdes;
    gcommovh_pkg.prvRows(gcommovh_pkg.prvRows.count).almdes := :prv.almdes;
    gcommovh_pkg.prvRows(gcommovh_pkg.prvRows.count).almdes := :prv.almdes;
    gcommovh_pkg.prvRows(gcommovh_pkg.prvRows.count).docori := :prv.docori;
    gcommovh_pkg.prvRows(gcommovh_pkg.prvRows.count).delega := :prv.delega;
    gcommovh_pkg.prvRows(gcommovh_pkg.prvRows.count).tercer := :prv.tercer;
    gcommovh_pkg.prvRows(gcommovh_pkg.prvRows.count).delega := :prv.delega;
    gcommovh_pkg.prvRows(gcommovh_pkg.prvRows.count).tercer := :prv.tercer;
    gcommovh_pkg.prvRows(gcommovh_pkg.prvRows.count).terenv := :prv.terenv;
    gcommovh_pkg.prvRows(gcommovh_pkg.prvRows.count).divisa := :prv.divisa;
    gcommovh_pkg.prvRows(gcommovh_pkg.prvRows.count).fecmov := :prv.fecmov;
    gcommovh_pkg.prvRows(gcommovh_pkg.prvRows.count).fecmov := :prv.fecmov;
    gcommovh_pkg.prvRows(gcommovh_pkg.prvRows.count).conten := :prv.conten;
    gcommovh_pkg.prvRows(gcommovh_pkg.prvRows.count).dosier := :prv.dosier;
    gcommovh_pkg.prvRows(gcommovh_pkg.prvRows.count).destra := :prv.destra;
    gcommovh_pkg.prvRows(gcommovh_pkg.prvRows.count).desadu := :prv.desadu;
    gcommovh_pkg.prvRows(gcommovh_pkg.prvRows.count).movest := :prv.movest;
    gcommovh_pkg.prvRows(gcommovh_pkg.prvRows.count).movest := :prv.movest;
    gcommovh_pkg.prvRows(gcommovh_pkg.prvRows.count).movhis := :prv.movhis;
    gcommovh_pkg.prvRows(gcommovh_pkg.prvRows.count).movhis := :prv.movhis;
    gcommovh_pkg.prvRows(gcommovh_pkg.prvRows.count).movhis := :prv.movhis;
    gcommovh_pkg.prvRows(gcommovh_pkg.prvRows.count).movest := :prv.movest;
    gcommovh_pkg.prvRows(gcommovh_pkg.prvRows.count).movest := :prv.movest;
    gcommovh_pkg.prvRows(gcommovh_pkg.prvRows.count).movest := :prv.movest;
    gcommovh_pkg.prvRows(gcommovh_pkg.prvRows.count).movhis := :prv.movhis;
    gcommovh_pkg.prvRows(gcommovh_pkg.prvRows.count).movhis := :prv.movhis;
    gcommovh_pkg.prvRows(gcommovh_pkg.prvRows.count).movest := :prv.movest;
    gcommovh_pkg.prvRows(gcommovh_pkg.prvRows.count).movhis := :prv.movhis;
    gcommovh_pkg.prvRows(gcommovh_pkg.prvRows.count).movhis := :prv.movhis;
    gcommovh_pkg.prvRows(gcommovh_pkg.prvRows.count).estcab := :prv.estcab;
    gcommovh_pkg.prvRows(gcommovh_pkg.prvRows.count).estcab := :prv.estcab;
    gcommovh_pkg.prvRows(gcommovh_pkg.prvRows.count).fecrec := :prv.fecrec;
    gcommovh_pkg.prvRows(gcommovh_pkg.prvRows.count).tipdoc := :prv.tipdoc;
    gcommovh_pkg.prvRows(gcommovh_pkg.prvRows.count).docser := :prv.docser;
    gcommovh_pkg.prvRows(gcommovh_pkg.prvRows.count).fecrec := :prv.fecrec;
    gcommovh_pkg.prvRows(gcommovh_pkg.prvRows.count).tipdoc := :prv.tipdoc;
    gcommovh_pkg.prvRows(gcommovh_pkg.prvRows.count).fecmov := :prv.fecmov;
    gcommovh_pkg.prvRows(gcommovh_pkg.prvRows.count).tercer := :prv.tercer;
    gcommovh_pkg.prvRows(gcommovh_pkg.prvRows.count).delega := :prv.delega;
    gcommovh_pkg.prvRows(gcommovh_pkg.prvRows.count).terenv := :prv.terenv;
    gcommovh_pkg.prvRows(gcommovh_pkg.prvRows.count).divisa := :prv.divisa;
    gcommovh_pkg.prvRows(gcommovh_pkg.prvRows.count).fconta := :prv.fconta;
    gcommovh_pkg.prvRows(gcommovh_pkg.prvRows.count).tipdoc := :prv.tipdoc;
    gcommovh_pkg.prvRows(gcommovh_pkg.prvRows.count).docser := :prv.docser;
    gcommovh_pkg.prvRows(gcommovh_pkg.prvRows.count).estcab := :prv.estcab;
    gcommovh_pkg.prvRows(gcommovh_pkg.prvRows.count).tipdoc := :prv.tipdoc;
    gcommovh_pkg.prvRows(gcommovh_pkg.prvRows.count).docser := :prv.docser;
    gcommovh_pkg.prvRows(gcommovh_pkg.prvRows.count).estcab := :prv.estcab;
    gcommovh_pkg.prvRows(gcommovh_pkg.prvRows.count).estcab := :prv.estcab;
    gcommovh_pkg.prvRows(gcommovh_pkg.prvRows.count).estcab := :prv.estcab;
    gcommovh_pkg.prvRows(gcommovh_pkg.prvRows.count).estcab := :prv.estcab;
    gcommovh_pkg.prvRows(gcommovh_pkg.prvRows.count).dtogen := :prv.dtogen;
    gcommovh_pkg.prvRows(gcommovh_pkg.prvRows.count).dtogen := :prv.dtogen;
    gcommovh_pkg.prvRows(gcommovh_pkg.prvRows.count).dtogen := :prv.dtogen;
    gcommovh_pkg.prvRows(gcommovh_pkg.prvRows.count).fecmov := :prv.fecmov;
    gcommovh_pkg.prvRows(gcommovh_pkg.prvRows.count).dtopp := :prv.dtopp;
    gcommovh_pkg.prvRows(gcommovh_pkg.prvRows.count).tipdoc := :prv.tipdoc;
    gcommovh_pkg.prvRows(gcommovh_pkg.prvRows.count).delega := :prv.delega;
    gcommovh_pkg.prvRows(gcommovh_pkg.prvRows.count).depart := :prv.depart;
    gcommovh_pkg.prvRows(gcommovh_pkg.prvRows.count).almori := :prv.almori;
    gcommovh_pkg.prvRows(gcommovh_pkg.prvRows.count).almdes := :prv.almdes;
    gcommovh_pkg.prvRows(gcommovh_pkg.prvRows.count).refter := :prv.refter;
    gcommovh_pkg.prvRows(gcommovh_pkg.prvRows.count).tipefe := :prv.tipefe;
    gcommovh_pkg.prvRows(gcommovh_pkg.prvRows.count).frmpag := :prv.frmpag;
    gcommovh_pkg.prvRows(gcommovh_pkg.prvRows.count).imptot := :prv.imptot;
    gcommovh_pkg.prvRows(gcommovh_pkg.prvRows.count).tercer := :prv.tercer;
    gcommovh_pkg.prvRows(gcommovh_pkg.prvRows.count).tipdir := :prv.tipdir;
    gcommovh_pkg.prvRows(gcommovh_pkg.prvRows.count).terfac := :prv.terfac;
    gcommovh_pkg.prvRows(gcommovh_pkg.prvRows.count).dirfac := :prv.dirfac;
    gcommovh_pkg.prvRows(gcommovh_pkg.prvRows.count).divisa := :prv.divisa;
    gcommovh_pkg.prvRows(gcommovh_pkg.prvRows.count).dtogen := :prv.dtogen;
    gcommovh_pkg.prvRows(gcommovh_pkg.prvRows.count).dtopp := :prv.dtopp;
    gcommovh_pkg.prvRows(gcommovh_pkg.prvRows.count).conten := :prv.conten;
    gcommovh_pkg.prvRows(gcommovh_pkg.prvRows.count).impres := :prv.impres;
    gcommovh_pkg.prvRows(gcommovh_pkg.prvRows.count).impres := :prv.impres;

   -- Instruccion nula por si el body del trigger esta vacio.
   null;

   -- Include [before] for trigger [gcommovh_upd] must be resolved at runtime

    IF (:prv.tipdoc != :nxt.tipdoc AND
                :nxt.movhis != -1
           ) THEN
     sdm_raise_msg(0, 'No se puede modificar ciertos datos claves del movimiento');

    END IF;

    IF (
               (:prv.almori != :nxt.almori                       OR
                :prv.almdes != :nxt.almdes                       OR
               (:prv.almdes IS NULL AND :nxt.almdes IS NOT NULL) OR
               (:prv.almdes IS NOT NULL AND :nxt.almdes IS NULL) OR
                NVL(:prv.docori, ' ') != NVL(:nxt.docori, ' ')) AND
                :nxt.movhis != -1
            ) THEN

-- Variable ID: N65620
     
                    SELECT COUNT(*)
                     INTO N65620
                      FROM gcommovl
                     WHERE cabid = :nxt.cabid;
    IF (N65620 > 0
            ) THEN
     sdm_raise_msg(0, 'No se puede modificar ciertos datos si hay líneas');

    END IF;

    END IF;

    IF (LENGTH(TRIM(:nxt.docori)) > 0 AND
               (:prv.delega != :nxt.delega OR :prv.tercer != :nxt.tercer) AND
                :nxt.movhis != -1
           ) THEN
     sdm_raise_msg(0, 'Mov. con documento origen, ciertos datos no se pueden modificar');

    END IF;

    IF (
               (:prv.delega != :nxt.delega  OR
                :prv.tercer != :nxt.tercer  OR
                :prv.terenv != :nxt.terenv  OR
                :prv.divisa != :nxt.divisa) AND
                :nxt.movhis != -1
           ) THEN

-- Variable ID: N65696
     
                  SELECT COUNT(*)
                   INTO N65696
                    FROM gcommovd
                   WHERE codigo = :nxt.tipdoc
                     AND tabdes = 'FC'
               ;
     
                   SELECT COUNT(*)
                    INTO N65705
                     FROM gcommovl
                    WHERE cabid = :nxt.cabid
                      AND estlin NOT IN ('E', 'V')
               ;
    IF (N65696 = 0 AND
               N65705 > 0
           ) THEN
     sdm_raise_msg(0, 'Mov. con lineas procesadas, ciertos datos no se pueden modificar');

    END IF;

    END IF;

-- Variable ID: N65736
     
                    SELECT COUNT(*)
                     INTO N65736
                      FROM gcommovd, galmctas a, galmctas b
                     WHERE gcommovd.codigo = :nxt.tipdoc
                       AND gcommovd.ctaori = a.codigo
                       AND gcommovd.ctades = b.codigo
                       AND (a.indsal != 'N' OR b.indsal != 'N')
                ;
     
                    SELECT COUNT(*)
                     INTO N65745
                      FROM galmacen
                     WHERE (codigo = :nxt.almori OR  codigo = :nxt.almdes)
                       AND fecval IS NOT NULL
                       AND (fecval >= :nxt.fecmov
                        OR  fecval >= :prv.fecmov)
                ;
    IF (:nxt.fecmov != :prv.fecmov AND
                :nxt.movhis != -1 AND
                N65736 > 0 AND
                N65745 > 0
            ) THEN
     sdm_raise_msg(0, 'Fecha movimiento anterior a la del ultimo cierre del almacen orig/dest');

    END IF;

    IF (:nxt.impnxt = 1 AND
                (NVL(:prv.conten,' ') != NVL(:nxt.conten,' ') OR
                 NVL(:prv.dosier,' ') != NVL(:nxt.dosier,' ') OR
                 NVL(:prv.destra,' ') != NVL(:nxt.destra,' ') OR
                 NVL(:prv.desadu,' ') != NVL(:nxt.desadu,' '))
            ) THEN
     sdm_raise_msg(0, 'Movimiento [' || TRIM(:nxt.docser) || '] evolucionado. No se puede cambiar datos de importaciones');

    END IF;

    IF (:prv.movest != :nxt.movest AND
                :nxt.movest  = 0 AND
                :nxt.movhis != -1
            ) THEN
     INSERT INTO gdoc_traspaso (tabname, colname, colval, tipope, tippro)
       VALUES ('gcommovh', 'cabid', :nxt.cabid, 1, 0);


    END IF;

    IF (:prv.movhis != :nxt.movhis AND
                :nxt.movhis  = 0 AND
                :prv.movhis != -1
            ) THEN
     INSERT INTO gdoc_traspaso (tabname, colname, colval, tipope, tippro)
       VALUES ('gcommovh', 'cabid', :nxt.cabid, 1, 1);


    END IF;

    IF (:prv.movest != :nxt.movest AND
                :nxt.movest  = 1 AND
                :nxt.movhis != -1
            ) THEN
     DELETE FROM gdoc_traspaso WHERE 
                        tabname = 'gcommovh'       AND
                        colname = 'cabid'          AND
                        colval  = :nxt.cabid AND
                        tippro  = 0
                     ;


    END IF;

    IF (:prv.movhis != :nxt.movhis AND
                :nxt.movhis  = 1 AND
                :prv.movhis != -1
            ) THEN
     DELETE FROM gdoc_traspaso WHERE 
                        tabname = 'gcommovh'        AND
                        colname = 'cabid'           AND
                        colval  = :nxt.cabid  AND
                        tippro  = 1
                     ;


    END IF;

-- Variable ID: N66048
     
                    SELECT COUNT(*)
                     INTO N66048
                      FROM gcommovd
                     WHERE codigo = :prv.tipdoc
                       AND stkpla IN (1, 2, 3, 4)
                 ;
    IF (
               ((:prv.estcab  = 'E' AND :nxt.estcab != 'E') OR
                (:prv.estcab != 'E' AND :nxt.estcab  = 'E') OR
                 :prv.fecrec != :nxt.fecrec) AND
                 :nxt.movhis != -1 AND
                 N66048 > 0
            ) THEN
     UPDATE gpro_stkplanm
        SET estado=CASE WHEN :nxt.estcab = 'E' THEN 'E' ELSE 'V' END,
            fecmov=:nxt.fecrec
      WHERE 
                        tabmov = 'gcommovh' AND
                        docser = :prv.docser;


    END IF;

-- Variable ID: N66090
     
                    SELECT COUNT(*)
                     INTO N66090
                      FROM gcommovd
                     WHERE codigo = :prv.tipdoc
                       AND stkpla IN (1, 2, 3, 4)
                 ;
    IF (:prv.fecrec < :nxt.fecrec AND
                 :nxt.movhis != -1 AND
                 N66090 > 0
            ) THEN
     UPDATE greserva
        SET estlin='A'
      WHERE 
                        tabres    = 'gvenpedh'        AND
                        tabapr    = 'gcommovh'        AND
                        docapr    = :nxt.docser AND
                        fecent < :nxt.fecrec AND
                        estlin   != 'A'               AND
                        canpro   != 0
                    ;


    END IF;

    IF (:nxt.fecmov != :prv.fecmov AND
                :nxt.movhis != -1
            ) THEN
     UPDATE gcommovl
        SET cosmed=0
      WHERE 
                        cabid   = :nxt.cabid AND
                        cosmed != 0
                    ;


    END IF;
   IF gcommovl_pkg.nxtRows.count = 0 THEN 

    IF (
               (:prv.tercer != :nxt.tercer OR
                :prv.delega != :nxt.delega OR
                :prv.terenv != :nxt.terenv OR
                :prv.divisa != :nxt.divisa) AND
                :nxt.movhis != -1
            ) THEN
     DELETE FROM gcommovh_dtcl WHERE cabid = :nxt.cabid;

     DELETE FROM gcommovl_dtlh WHERE cabid = :nxt.cabid;

     UPDATE gcommovl
        SET precio=0,
            dtolin=0,
            pretar=NULL,
            dtotar=NULL
      WHERE cabid  = :nxt.cabid;


    END IF;
   END IF; 

-- Variable ID: N66220
     
                   SELECT COUNT(*)
                    INTO N66220
                     FROM gcommovd
                    WHERE codigo  = :prv.tipdoc
                      AND cominv != 'N'
                      AND aplcon != 0
               ;
    IF (:prv.fconta IS NULL     AND
               :nxt.fconta IS NOT NULL AND
               :nxt.movhis != -1 AND
               N66220 > 0
           ) THEN
     DELETE FROM cpar_premovi WHERE 
                      tabori = 'gcomalbh'        AND
                      docser = :prv.docser AND
                      estado = 'C'
                  ;


    END IF;

-- Variable ID: N66253
     
                    SELECT COUNT(*)
                     INTO N66253
                      FROM gcommovd
                     WHERE codigo = :prv.tipdoc
                       AND cominv = 'S'
                ;
    IF (:prv.estcab  = 'V' AND
                :nxt.estcab  = 'E' AND
                :nxt.movhis != -1  AND
                N66253 > 0
            ) THEN
     DELETE FROM cpar_premovi WHERE 
                        tabori = 'gcomalbh' AND
                        docser = :prv.docser;


    END IF;

    IF (:prv.estcab != :nxt.estcab                 AND
               (:prv.estcab  = 'P' AND :nxt.estcab != 'V') AND
               (:prv.estcab != 'E' AND :prv.estcab != 'V') AND
               (:nxt.estcab  = 'E'  OR :nxt.estcab  = 'V') AND
                :nxt.movhis != -1
            ) THEN
     sdm_raise_msg(0, 'Cabecera de transaccion cursada. No se puede alterar');

    END IF;

-- Variable ID: N66399
     
                    SELECT COUNT(*)
                     INTO N66399
                      FROM gcommovd
                     WHERE codigo = :nxt.tipdoc
                       AND tabdes = 'FC'
                 ;
    IF (
                (:prv.dtogen != :nxt.dtogen OR
                 :prv.fecmov != :nxt.fecmov OR
                 :prv.dtopp  != :nxt.dtopp) AND
                 :nxt.movhis != -1 AND
                 N66399 > 0
            ) THEN
     UPDATE gcomfach
        SET dtogen=:nxt.dtogen,
            dtopp=:nxt.dtopp,
            fecha=:nxt.fecmov,
            valor=:nxt.fecmov,
            user_updated=USER,
            date_updated=CURRENT_TIMESTAMP
      WHERE 
                        cabori = :nxt.cabid;


    END IF;

    IF (:prv.tipdoc != :nxt.tipdoc AND
                :nxt.movhis != -1
            ) THEN
     cerrauth_anular('gcommovh', 'tipdoc', :nxt.cabid, 0);

    END IF;

    IF (:prv.delega != :nxt.delega AND
                :nxt.movhis != -1
            ) THEN
     cerrauth_anular('gcommovh', 'delega', :nxt.cabid, 0);

    END IF;

    IF (:prv.depart != :nxt.depart AND
                :nxt.movhis != -1
            ) THEN
     cerrauth_anular('gcommovh', 'depart', :nxt.cabid, 0);

    END IF;

    IF (:prv.almori != :nxt.almori AND
                :nxt.movhis != -1
            ) THEN
     cerrauth_anular('gcommovh', 'almori', :nxt.cabid, 0);

    END IF;

    IF (:prv.almdes != :nxt.almdes AND
                :nxt.movhis != -1
            ) THEN
     cerrauth_anular('gcommovh', 'almdes', :nxt.cabid, 0);

    END IF;

    IF (:prv.refter != :nxt.refter AND
                :nxt.movhis != -1
            ) THEN
     cerrauth_anular('gcommovh', 'refter', :nxt.cabid, 0);

    END IF;

    IF (:prv.tipefe != :nxt.tipefe AND
                :nxt.movhis != -1
            ) THEN
     cerrauth_anular('gcommovh', 'tipefe', :nxt.cabid, 0);

    END IF;

    IF (:prv.frmpag != :nxt.frmpag AND
                :nxt.movhis != -1
            ) THEN
     cerrauth_anular('gcommovh', 'frmpag', :nxt.cabid, 0);

    END IF;

    IF (:prv.imptot != :nxt.imptot AND
                :nxt.movhis != -1
            ) THEN
     cerrauth_anular('gcommovh', 'imptot', :nxt.cabid, 0);

    END IF;

    IF (:prv.tercer != :nxt.tercer AND
                :nxt.movhis != -1
            ) THEN
     cerrauth_anular('gcommovh', 'tercer', :nxt.cabid, 0);

    END IF;

    IF (:prv.tipdir != :nxt.tipdir AND
                :nxt.movhis != -1
            ) THEN
     cerrauth_anular('gcommovh', 'tipdir', :nxt.cabid, 0);

    END IF;

    IF (:prv.terfac != :nxt.terfac AND
                :nxt.movhis != -1
            ) THEN
     cerrauth_anular('gcommovh', 'terfac', :nxt.cabid, 0);

    END IF;

    IF (:prv.dirfac != :nxt.dirfac AND
                :nxt.movhis != -1
            ) THEN
     cerrauth_anular('gcommovh', 'dirfac', :nxt.cabid, 0);

    END IF;

    IF (:prv.divisa != :nxt.divisa AND
                :nxt.movhis != -1
            ) THEN
     cerrauth_anular('gcommovh', 'divisa', :nxt.cabid, 0);

    END IF;

    IF (:prv.dtogen != :nxt.dtogen AND
                :nxt.movhis != -1
            ) THEN
     cerrauth_anular('gcommovh', 'dtogen', :nxt.cabid, 0);

    END IF;

    IF (:prv.dtopp  != :nxt.dtopp AND
                :nxt.movhis != -1
            ) THEN
     cerrauth_anular('gcommovh', 'dtopp', :nxt.cabid, 0);

    END IF;

    IF (NVL(:prv.conten, ' ') != NVL(:nxt.conten, ' ') AND
                :nxt.movhis != -1
            ) THEN
     cerrauth_anular('gcommovh', 'conten', :nxt.cabid, 0);

    END IF;

    IF (:prv.impres != :nxt.impres AND
                :nxt.movhis != -1
            ) THEN
     cerrauth_anular('gcommovh', 'impres', :nxt.cabid, 0);

    END IF;

    IF (:nxt.movhis != -1) THEN
     csyn_document_inserta('gcommovh', :nxt.tipdoc, :nxt.docser);

    END IF;

    IF (:prv.impres != :nxt.impres AND
                :nxt.impres  = 'S' AND
                :nxt.movhis != -1
            ) THEN
     INSERT INTO csyn_document (tabid, docser, accion, progname, proces) 
           SELECT 
                            tabid, :nxt.docser, 2, progname, 0
                        
        FROM csyn_tablas
       WHERE 
                            tabid = 'gcommovh' AND
                            NVL(tipdoc, :nxt.tipdoc) = :nxt.tipdoc AND
                            indnot = 2
                        
;


    END IF;

   -- Include [after] for trigger [gcommovh_upd] must be resolved at runtime

END gcommovh_upd;
.
run



-- **************************************************************************
-- TRIGGER: gcommovh_upd_a (AFTER-update)
-- **************************************************************************
CREATE OR REPLACE TRIGGER gcommovh_upd_a
AFTER UPDATE ON gcommovh
DECLARE
    N66333 integer;
BEGIN

   -- Instruccion nula por si el body del trigger esta vacio.
   null;
   IF gcommovl_pkg.nxtRows.count != 0 THEN 

   FOR i IN 1 .. gcommovh_pkg.nxtRows.count LOOP

    IF (
               (gcommovh_pkg.prvRows(i).tercer != gcommovh_pkg.nxtRows(i).tercer OR
                gcommovh_pkg.prvRows(i).delega != gcommovh_pkg.nxtRows(i).delega OR
                gcommovh_pkg.prvRows(i).terenv != gcommovh_pkg.nxtRows(i).terenv OR
                gcommovh_pkg.prvRows(i).divisa != gcommovh_pkg.nxtRows(i).divisa) AND
                gcommovh_pkg.nxtRows(i).movhis != -1
            ) THEN
     DELETE FROM gcommovh_dtcl WHERE cabid = gcommovh_pkg.nxtRows(i).cabid;

     DELETE FROM gcommovl_dtlh WHERE cabid = gcommovh_pkg.nxtRows(i).cabid;

     UPDATE gcommovl
        SET precio=0,
            dtolin=0,
            pretar=NULL,
            dtotar=NULL
      WHERE cabid  = gcommovh_pkg.nxtRows(i).cabid;


    END IF;
   END LOOP;
   END IF;


   FOR i IN 1 .. gcommovh_pkg.nxtRows.count LOOP

-- Variable ID: N66333
     
                    SELECT COUNT(*)
                     INTO N66333
                      FROM gcommovd
                     WHERE codigo = gcommovh_pkg.nxtRows(i).tipdoc
                       AND tabori = 'MC'
                       AND actori = 'S'
                ;
    IF (gcommovh_pkg.prvRows(i).dtogen != gcommovh_pkg.nxtRows(i).dtogen AND
                gcommovh_pkg.nxtRows(i).docori IS NOT NULL          AND
                gcommovh_pkg.nxtRows(i).movhis != -1 AND
                N66333 > 0
            ) THEN
     UPDATE gcomacuh
        SET imptot= imptot +
                         (SELECT NVL(SUM(impnet), 0) * (gcommovh_pkg.nxtRows(i).dtogen - gcommovh_pkg.prvRows(i).dtogen) / 100
                            FROM gcommovl
                           WHERE cabid = gcommovh_pkg.nxtRows(i).cabid),
            user_updated=USER,
            date_updated=CURRENT_TIMESTAMP
      WHERE 
                        docser = gcommovh_pkg.nxtRows(i).docori;


    END IF;
   END LOOP;
 gcommovh_pkg.nxtRows := gcommovh_pkg.empty;
 gcommovh_pkg.prvRows := gcommovh_pkg.empty;

END gcommovh_upd_a;
.
run