You must use dynamic sql.
Note, that you can't use "SELECT to nowhere" in a compound statement in Db2. That is, the following code is erroneous.
BEGIN
  SELECT * FROM MYTAB;
END@
This is why you need to store the result of SELECT somewhere. You may use Global Temporary Tables for that presuming, that USER TEMPORARY TABLESPASE is available to use for your user.
--#SET TERMINATOR @
BEGIN
  DECLARE V_STMT VARCHAR (500);
  
  SELECT
     'DECLARE GLOBAL TEMPORARY TABLE SESSION.RESULT'
  || ' AS (SELECT * FROM '
  || MAIN
  || ') WITH DATA WITH REPLACE '
  || 'ON COMMIT PRESERVE ROWS NOT LOOGED'
  INTO V_STMT
  FROM XYZ
  -- place your WHERE clause here if needed
  FETCH FIRST 1 ROW ONLY
  ;
  
  EXECUTE IMMEDIATE V_STMT;
END
@
SELECT * FROM SESSION.RESULT
@
dbfiddle link.