

CREATE COMPUTE MODULE SET_FAULT_EXTRACT_FAILURE
	CREATE FUNCTION Main() RETURNS BOOLEAN
	BEGIN
		-- CALL CopyMessageHeaders();
		CALL CopyEntireMessage();

		DECLARE i INTEGER 1;
		label1 : BEGIN
			FOR error AS InputRoot.XMLNSC.*[] DO
				IF FIELDNAME(error) <> 'XmlDeclaration' THEN
					SET OutputRoot.XMLNSC.*[i].error = 'Invalid operation';
					SET OutputRoot.XMLNSC.*[i].errorDetail = 'Invalid operation';
					LEAVE label1;
				END IF;

				SET i = i + 1;
			END FOR;
		END;

		RETURN TRUE;
	END;

	CREATE PROCEDURE CopyMessageHeaders() BEGIN
		DECLARE I INTEGER 1;
		DECLARE J INTEGER;
		SET J = CARDINALITY(InputRoot.*[]);
		WHILE I < J DO
			SET OutputRoot.*[I] = InputRoot.*[I];
			SET I = I + 1;
		END WHILE;
	END;

	CREATE PROCEDURE CopyEntireMessage() BEGIN
		SET OutputRoot = InputRoot;
	END;
END MODULE;


CREATE COMPUTE MODULE SET_FAULT_INVALID_MESSAGE
	CREATE FUNCTION Main() RETURNS BOOLEAN
	BEGIN
		-- CALL CopyMessageHeaders();
		CALL CopyEntireMessage();

		DECLARE i INTEGER 1;
		label1 : BEGIN
			FOR error AS InputRoot.XMLNSC.*[] DO
				IF FIELDNAME(error) <> 'XmlDeclaration' THEN
					SET OutputRoot.XMLNSC.*[i].error = 'Invalid message';
					SET OutputRoot.XMLNSC.*[i].errorDetail = 'Invalid message';
					LEAVE label1;
				END IF;

				SET i = i + 1;
			END FOR;
		END;

		RETURN TRUE;
	END;

	CREATE PROCEDURE CopyMessageHeaders() BEGIN
		DECLARE I INTEGER 1;
		DECLARE J INTEGER;
		SET J = CARDINALITY(InputRoot.*[]);
		WHILE I < J DO
			SET OutputRoot.*[I] = InputRoot.*[I];
			SET I = I + 1;
		END WHILE;
	END;

	CREATE PROCEDURE CopyEntireMessage() BEGIN
		SET OutputRoot = InputRoot;
	END;
END MODULE;


CREATE COMPUTE MODULE SET_FAULT_RPG_MSGERR
	CREATE FUNCTION Main() RETURNS BOOLEAN
	BEGIN
		-- CALL CopyMessageHeaders();
		CALL CopyEntireMessage();

		DECLARE i INTEGER 1;
		label1 : BEGIN
			FOR error AS InputRoot.XMLNSC.*[] DO
				IF FIELDTYPE(error.msgerr) IS NOT NULL THEN
					SET OutputRoot.XMLNSC.*[i].error = 'Message Error From RPG Call';
					SET OutputRoot.XMLNSC.*[i].errorDetail = 'msgerr [' || InputRoot.XMLNSC.*[i].msgerr || ']';
					LEAVE label1;
				END IF;

				SET i = i + 1;
			END FOR;
		END;

		RETURN TRUE;
	END;

	CREATE PROCEDURE CopyMessageHeaders() BEGIN
		DECLARE I INTEGER 1;
		DECLARE J INTEGER;
		SET J = CARDINALITY(InputRoot.*[]);
		WHILE I < J DO
			SET OutputRoot.*[I] = InputRoot.*[I];
			SET I = I + 1;
		END WHILE;
	END;

	CREATE PROCEDURE CopyEntireMessage() BEGIN
		SET OutputRoot = InputRoot;
	END;
END MODULE;


CREATE COMPUTE MODULE SET_FAULT_RPG_MSG_ERR
	CREATE FUNCTION Main() RETURNS BOOLEAN
	BEGIN
		-- CALL CopyMessageHeaders();
		CALL CopyEntireMessage();

		DECLARE i INTEGER 1;
		label1 : BEGIN
			FOR error AS InputRoot.XMLNSC.*[] DO
				IF FIELDTYPE(error.msgErr) IS NOT NULL THEN
					SET OutputRoot.XMLNSC.*[i].error = 'Message Error From RPG Call';
					SET OutputRoot.XMLNSC.*[i].errorDetail = 'Message Error [' || InputRoot.XMLNSC.*[i].msgErr || ']';
					LEAVE label1;
				END IF;

				SET i = i + 1;
			END FOR;
		END;

		RETURN TRUE;
	END;

	CREATE PROCEDURE CopyMessageHeaders() BEGIN
		DECLARE I INTEGER 1;
		DECLARE J INTEGER;
		SET J = CARDINALITY(InputRoot.*[]);
		WHILE I < J DO
			SET OutputRoot.*[I] = InputRoot.*[I];
			SET I = I + 1;
		END WHILE;
	END;

	CREATE PROCEDURE CopyEntireMessage() BEGIN
		SET OutputRoot = InputRoot;
	END;
END MODULE;


CREATE COMPUTE MODULE SET_FAULT_RPG_MSG_ERR_01_DATA_NOT_FOUND
	CREATE FUNCTION Main() RETURNS BOOLEAN
	BEGIN
		-- CALL CopyMessageHeaders();
		CALL CopyEntireMessage();

		DECLARE i INTEGER 1;
		label1 : BEGIN
			FOR error AS InputRoot.XMLNSC.*[] DO
				IF FIELDTYPE(error.msgErr) IS NOT NULL THEN
					IF (error.msgErr = '01') THEN
						SET OutputRoot.XMLNSC.*[i].error = 'Data not found';
						SET OutputRoot.XMLNSC.*[i].errorDetail = 'Message Error [' || error.msgErr || ']';
					ELSE
						SET OutputRoot.XMLNSC.*[i].error = 'Message Error';
						SET OutputRoot.XMLNSC.*[i].errorDetail = 'Message Error [' || error.msgErr || ']';
					END IF;
					LEAVE label1;
				END IF;

				SET i = i + 1;
			END FOR;
		END;

		RETURN TRUE;
	END;

	CREATE PROCEDURE CopyMessageHeaders() BEGIN
		DECLARE I INTEGER 1;
		DECLARE J INTEGER;
		SET J = CARDINALITY(InputRoot.*[]);
		WHILE I < J DO
			SET OutputRoot.*[I] = InputRoot.*[I];
			SET I = I + 1;
		END WHILE;
	END;

	CREATE PROCEDURE CopyEntireMessage() BEGIN
		SET OutputRoot = InputRoot;
	END;
END MODULE;


CREATE COMPUTE MODULE SET_FAULT_MESSAGE_EOD
	CREATE FUNCTION Main() RETURNS BOOLEAN
	BEGIN
		-- CALL CopyMessageHeaders();
		CALL CopyEntireMessage();

		DECLARE i INTEGER 1;
		label1 : BEGIN
			FOR error AS InputRoot.XMLNSC.*[] DO
				IF FIELDNAME(error) <> 'XmlDeclaration' THEN
					SET OutputRoot.XMLNSC.*[i].error = 'EOD';
					SET OutputRoot.XMLNSC.*[i].errorCode = '9999';
					SET OutputRoot.XMLNSC.*[i].errorDetail = 'EOD is running right now';
					LEAVE label1;
				END IF;

				SET i = i + 1;
			END FOR;
		END;

		RETURN TRUE;
	END;

	CREATE PROCEDURE CopyMessageHeaders() BEGIN
		DECLARE I INTEGER 1;
		DECLARE J INTEGER;
		SET J = CARDINALITY(InputRoot.*[]);
		WHILE I < J DO
			SET OutputRoot.*[I] = InputRoot.*[I];
			SET I = I + 1;
		END WHILE;
	END;

	CREATE PROCEDURE CopyEntireMessage() BEGIN
		SET OutputRoot = InputRoot;
	END;
END MODULE;