-- Version:		2025.7.31  14:52:27
Drop Table T_LOV_REASON@

Create Table T_LOV_REASON(
Type		VARCHAR(60)		NOT NULL,
Code		VARCHAR(12)		NOT NULL,
DESC		VARCHAR(254)		NOT NULL,
toc		TIMESTAMP,
tom		TIMESTAMP,
mop		VARCHAR(120),
mou		VARCHAR(30),
CONSTRAINT pk_T_LOV_REASON PRIMARY KEY (Type, Code)
)
IN TB8KUSREMS INDEX IN TB8KIDXEMS@

COMMENT ON Table T_LOV_REASON IS '原因代码表'@

COMMENT ON T_LOV_REASON (Type IS 'name of reason type')@
COMMENT ON T_LOV_REASON (Code IS 'reason code')@
COMMENT ON T_LOV_REASON (DESC IS 'description')@

/****************************************************************************
						INSERT TRIGGER FOR TABLE
							  T_LOV_REASON
*****************************************************************************/
DROP TRIGGER ins_b_T_LOV_REASON@

CREATE OR REPLACE TRIGGER ins_b_T_LOV_REASON
BEFORE INSERT ON T_LOV_REASON REFERENCING NEW AS NEWROW FOR EACH ROW
MODE DB2SQL
BEGIN ATOMIC
	DECLARE	programm	VARCHAR(120);
	DECLARE	auth	VARCHAR(30);

	set (programm,auth) = (SELECT APPL_NAME,AUTHID FROM SYSIBMADM.APPLICATIONS WHERE APPL_ID = (SELECT APPLICATION_ID() FROM dual));

	set NEWROW.toc = (values sysdate);
	set NEWROW.tom = (values sysdate);
	set NEWROW.mop = programm;
	set NEWROW.mou = auth;
END
@
/****************************************************************************
						UPDATE TRIGGER FOR TABLE
							  T_LOV_REASON
*****************************************************************************/
DROP TRIGGER upd_b_T_LOV_REASON@

CREATE OR REPLACE TRIGGER upd_b_T_LOV_REASON
BEFORE UPDATE ON T_LOV_REASON REFERENCING NEW AS NEWROW FOR EACH ROW
MODE DB2SQL
BEGIN ATOMIC
	DECLARE	programm	VARCHAR(120);
	DECLARE	auth	VARCHAR(30);

	set (programm,auth) = (SELECT APPL_NAME,AUTHID FROM SYSIBMADM.APPLICATIONS WHERE APPL_ID = (SELECT APPLICATION_ID() FROM dual));

	set NEWROW.tom = (values sysdate);
	set NEWROW.mop = programm;
	set NEWROW.mou = auth;
END
@
