Hello Gita,
I know it has been a long time since your request but for next time you might face the same issue, please try the following:
IF sy-batch EQ abap_true.
MESSAGE 'Error' TYPE 'E'.
ELSE.
MESSAGE 'Error' TYPE 'S' DISPLAY LIKE 'E'.
RETURN.
ENDIF.
It covers both dialog and batch job uses.
Hope it will help you in future.
Eloi