cancel
Showing results for 
Search instead for 
Did you mean: 

Messages Handling

balaji_viswanath
Participant
0 Kudos

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.

Accepted Solutions (1)

Accepted Solutions (1)

ssimsekler
Active Contributor
0 Kudos

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

Answers (2)

Answers (2)

sergey_korolev
Active Contributor
0 Kudos

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.

Former Member
0 Kudos

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