Hi Gita,
Below example code will work for you. I tried and it does work and it sets the cursor in field where there is an error:
PARAMETERS : p_matnr TYPE mara-matnr,
p_mtart TYPE mara-mtart,
p_werks TYPE marc-werks.
DATA : lv_mtart TYPE mara-mtart,
lv_matnr TYPE mara-matnr,
lv_werks TYPE t001w-werks.
AT SELECTION-SCREEN OUTPUT.
IF NOT p_mtart IS INITIAL.
SELECT SINGLE mtart FROM t134 INTO lv_mtart WHERE mtart = p_mtart.
IF NOT sy-subrc IS INITIAL.
SET CURSOR FIELD 'P_MTART'.
MESSAGE 'Material type invalid' TYPE 'S' DISPLAY LIKE 'E'.
ENDIF.
ENDIF.
IF NOT p_matnr IS INITIAL.
SELECT SINGLE matnr FROM mara INTO lv_matnr WHERE matnr = p_matnr.
IF NOT sy-subrc IS INITIAL.
SET CURSOR FIELD 'P_MATNR'.
MESSAGE 'Material invalid' TYPE 'S' DISPLAY LIKE 'E'.
ENDIF.
ENDIF.
IF NOT p_werks IS INITIAL.
SELECT SINGLE werks FROM t001w INTO lv_werks WHERE werks = p_werks.
IF NOT sy-subrc IS INITIAL.
SET CURSOR FIELD 'P_WERKS'.
MESSAGE 'Plant invalid' TYPE 'S' DISPLAY LIKE 'E'.
ENDIF.
ENDIF.
You can modify the above code as required for you and it should work.
Thanks,
Naveen