If flag = *off;
run full SQL;
run SQL with Where clause;
You could after loading subfile have user place cursor on field you want to filter by and press a Fkey.
Get data at cursor location and pass data to where statement.
Google "cursor location site:iprodeveloper.com"