Skip to Content

Messages Handling

How to implement sy-msgid in our programs?

For example.

REPORT ztest message-id sy-msgid.

TABLES mara.

SELECT SINGLE * FROM mara WHERE matnr = 'X'.

IF sy-subrc <> 0.

message id sy-msgid type sy-msgty number sy-msgno

with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

ENDIF.

Above code returns a dump sayind message type unknown. How to correct it?

And also whether it's possible to use two different message ids in the same program?

Advance thanks.

Regards,

V. Balaji.

Add a comment
10|10000 characters needed characters exceeded

Related questions

3 Answers

  • Best Answer
    Posted on Dec 06, 2004 at 11:27 AM

    Hi Balaji

    That is; to use <b>MESSAGE</b> statement that way, the system variables at the statement (i.e. sy-mXXXX) must be

    filled by some previous statement. And as Sergei stated, <b>SELECT</b> statement does not fill those system variables.

    You must explicitly indicate the message class by;

    MESSAGE ID <message_class> NUMBER <message_number>
    TYPE <message_type> [WITH <var1> <var1> <var1> <var1>] .
    

    <b>MESSAGE</b> statement without <b>ID option</b> will look for a general message class definition for the program which can be set by

    REPORT X MESSAGE-ID <message_class> .

    In your program, since it couldn't find required info, the <b>MESSAGE</b> statement has resulted in a short dump.

    *--Serdar

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Dec 06, 2004 at 08:02 AM

    Hi,

    the sy-... msg-fields are fields that gets populated from SAP during the runtime of programs and contains always the latest used message id, -type and variables.

    Yor program should look like this.

    REPORT ztest. " message-id sy-msgid.

    TABLES mara.

    SELECT SINGLE * FROM mara WHERE matnr = 'X'.

    IF sy-subrc <> 0.

    message id 'ZTEST' type 'E' number '001'

    with var1 var2 var3 var4.

    ENDIF.

    So you can specify a message-id you like, set the message-type to what you like and set the message-number to the desired message. With var1 to var4 you can display up to 4 variables (even texts) in the message. But at least the message should contain '& & & &' which will be replaced by the variables.

    Hope this helps

    regards

    Siggi

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Dec 06, 2004 at 08:07 AM

    SELECT does not assign any value to sy-msgty and other sy-msg* fields. It only updates sy-subrc according to the results of the select. To issue a message you should first define the message class (say ZMYMSG) and then define messages in it. This can be done in SE91. Then the first statement should be as follows:

    <b>REPORT</b> ztest <b>MESSAGE-ID</b> zmymsg.

    After that the message issuing statement can look as follows:

    <b>MESSAGE</b> e001 <b>WITH</b> ....

    Please, see more details in on-line help on MESSAGE statement.

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.