iSeries: Check if table exists + return message in embedded statement

Date: 2018-03-20
BEGIN ATOMIC
 DECLARE @ROWCOUNT INT NOT NULL DEFAULT 0;
 SELECT COUNT(*) INTO @ROWCOUNT FROM QSYS2.SYSTABLES WHERE TABLE_NAME = 'View1' and TABLE_SCHEMA = CURRENT_SCHEMA;
 IF(NOT @ROWCOUNT > 0) THEN
 CREATE OR REPLACE VIEW View1 AS SELECT * FROM Users;
 SIGNAL SQLSTATE VALUE '99998' SET MESSAGE_TEXT = 'VIEW View1 CREATED';
 ELSE
 SIGNAL SQLSTATE VALUE '99999' SET MESSAGE_TEXT = 'VIEW View1 EXISTS'; 
 END IF;
END
7530cookie-checkiSeries: Check if table exists + return message in embedded statement