检查消息id是否存在

Check if message id exists

我正在使用 MESSAGE 函数,我想知道如何确定消息 ID 是否存在。
例如:

  1. 我在我的消息中定义了一个 ID 为“001”的消息 class "test_message".
  2. 然后我这样称呼它:MESSAGE e001(test_messages) WITH 'Test'.
  3. 我在 sy
  4. 的另一个函数中检索它

当我做的时候MESSAGE e000(test_messages) WITH 'Test'. sy 中的值是相同的(当然除了 id)。但在那种情况下,我想更改我的流程,因为我从未创建过 ID 为 000 的消息。
我不知道还有什么地方可以检查该 ID 是否确实存在。

您可以 SELECT 对比 table T100。如果你能找到你的消息,它就存在 :P

类似

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 的回答是恰当的,但可以通过提供语言字段并仅检索 TEXT 字段来提高性能。这样做允许您添加 "SINGLE" 选项和 speed-up 您的消息 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.