Hi Jepoy,
You can refer the below piece of code for your requirement: You can set the flag at Start of Selection.
Then Import the same in the AT SELECTION SCREEN Output event. Make sure to free the memory ID after the Import. This will not clear the Parameter when you press enter.
AT SELECTION-SCREEN OUTPUT.
IMPORT lv_flg FROM MEMORY ID 'CLEAR'.
FREE MEMORY ID 'CLEAR'.
IF sy-subrc eq 0.
CLEAR p_matnr.
ENDIF.
START-OF-SELECTION.
lv_matnr = p_matnr.
EXPORT lv_flg = 'X' to MEMORY ID 'CLEAR'.
Hope this works.
Thanks,
Abhi