To show error message with traffic light indicator in custom screen or for any custom object we can use this function module C14Z_MESSAGES_SHOW_AS_POPUP.
Error message is maintained in SE91 transaction. This is the message format
Once you execute this FM below is the output
If your using this function module and your getting error message then we need to stop the program flow manually using STOP or EXIT or LEAVE TO LIST-PROCESSING (depend on the object).