1

I am using the MESSAGE function and I want to know how I can find out if the message id exists or not.
For example:

  1. I defined a message with the id "001" in my message class "test_message".
  2. Then I call it like this: MESSAGE e001(test_messages) WITH 'Test'.
  3. I retrieve it in another function from sy

When I do MESSAGE e000(test_messages) WITH 'Test'. the values in sy are the same (except for the id of course). But in that case I want to change my process because I never created a message with the id 000.
I don't know where else to check if the id actually exists or not.

Cold_Class
  • 3,214
  • 4
  • 39
  • 82

2 Answers2

2

You can do a SELECT versus the table T100. If you can find your message, it exists :P

Something like

SELECT "just anything that fits your needs, with or without SINGLE
  "UP TO 1 ROWS if you will not use the table's PK
  FROM T100
  INTO "field or fieldlist that fits your needs
  WHERE ARBGB = "your ID
    AND MSGNR = "your number.
"ENDSELECT. if you use UP TO 1 ROWS
IF sy-subrc = 0. "it exists
VXLozano
  • 317
  • 1
  • 7
  • 1
    SQL "improved" as per @s-grosjean suggestion. I usually do NOT provide the exact piece of code needed by OPs (nor here nor in my original birthplace SAPFans). I'm used to leave to the OPs the work to fulfill their own requests from my "hints". – VXLozano Feb 26 '18 at 08:17
  • thx for pointing me to my own question here, I completely forgot about it xD – Cold_Class Mar 28 '18 at 15:39
2

VXLozano's answer is appropriate but could be improved in performance by providing also the language field and retrieving only the TEXT field. Doing so allows you to add the "SINGLE" option and speed-up your message look-up.

SELECT SINGLE TEXT
  FROM T100
  INTO dummyfield
 WHERE SPRSL = SY-LANGU
   AND ARBGB = "Your ID"
   AND MSGNR = "your Number".
IF sy-subrc = 0.
  "the requested message in the message class exists for your current language
ENDIF.
S.Grosjean
  • 21
  • 2