Hi Gita,
You can store the value of SY-SUBRC in a FLAG variable and then display the message at the END-OF-SELECTION event as the SY-SUBRC stores the state of last executed statement and the END-OF-SELECTION statement would always trigger it to 0.
for e.g.
AT SELECTION-SCREEN.
SELECT COUNT(*) FROM dd02l INTO v_cnt WHERE TABNAME = p_tabnam.
FLAG = SY-SUBRC.
END-OF-SELECTION.
IF FLAG EQ 0.
MESSAGE 'Valid Table Name ' TYPE 'S'.
ELSE.
MESSAGE 'Invalid Table Name' TYPE 'S' DISPLAY LIKE 'E'.
ENDIF.