Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

How to move message text from message class using variable

manoj_goyal2
Participant

Hi,

I have message number in internal table. I want to display message txt on report.

Can somebody tell me how I can move the message text to a variable, using message number stored in variable.

Variables details is as follows.

DATA: lv_msg_id type sy-msgno.

DATA: lv_msg_text(60) type c.

lv_msg_id = '010'.

I want to store msg text in lv_msg_text.

Thanks.

9 REPLIES 9

romanweise
Active Contributor

The message statement has an INTO option allowing you to store the message in a field insteat of showing it on the screen directly.

MESSAGE E010(MESSAGE_CLASS) WITH VAR1 VAR2 VAR3 VAR4

INTO lv_msg_txt.

If you need to assign message class, number and type dynamically use the following version:

MESSAGE ID my_mid TYPE my_mtype NUMBER my_num WITH my_var1 my_var2 my_var3 my_var4 INTO lv_msg_txt.

Rgds.

Roman

0 Kudos

Hi,

You can also use the Function Module BAPI_MESSAGE_GET_DETAIL to get the message passing the Message Id, No, variables etc.

Reward if useful

Regards,

Abhishek

0 Kudos

Hi Roman,

Thanks for your reply.

I used your statment but I am getting this result.

Data: gc_msgid type sy-msgid value 'zmy_msg_class'.

data: lv_errid type sy-msgno.

lv_errid = '010'.

MESSAGE ID gc_msgid TYPE 'I' NUMBER gi_error_list-errid

INTO lv_err_txt.

Result: I:zmy_msg_class:010

Can you please see what is wrong in this.

0 Kudos

Hi,

Can you try

MESSAGE gi_error_list-errid(gc_msgid) INTO lv_err_txt.

Regards,

Atish

0 Kudos

Hi Atish,

I used your statement and it is giving me following error.

Three-digit error number XXX required in the "MESSAGE EXXX.. Statement.

0 Kudos

Hi,

I think you can use your earlier statement only

MESSAGE ID gc_msgid TYPE 'I' NUMBER gi_error_list-errid

INTO lv_err_txt.

What is the error you getting in this.

Regards,

Atish

0 Kudos

> I:zmy_msg_class:010

This ist the standard message which is shown if the specified message is not existing or does not have a translation to your logon language.

check if the name of the message class and the number are really correct. Perhaps writing the message class in capital letters might help.

0 Kudos

You can use function module: FORMAT_MESSAGE

But remmeber about language translation. If it doesn't exist you don't get value in variable.

Here it's example code:

 DATA: text TYPE string.


  CALL FUNCTION 'FORMAT_MESSAGE'
    EXPORTING
      id        = 'AUTH_WIZ'    " Application Area
      lang      = sy-langu
      no        = '003'
      v1        = 'TEST VALUE'   " 1st parameter
      v2        = sy-msgv2    " 2nd parameter
      v3        = sy-msgv3    " 3rd parameter
      v4        = sy-msgv4    " 4th Parameter
    IMPORTING
      msg       = text
    EXCEPTIONS
      not_found = 1.
  IF sy-subrc <> 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
               WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ELSE.
    WRITE:/ text.
  ENDIF.

This simple FM check only table T100 as select single, so sometimes better is use select on T100 and get all message to global table/class attribute and after use read table on it. It's much better when u have many messages to handle in your class/ program.

  DATA: messages TYPE HASHED TABLE OF t100 WITH UNIQUE KEY msgnr.


  SELECT *
    FROM t100
    INTO TABLE @messages[]
   WHERE sprsl = @sy-langu
     AND arbgb = 'AUTH_WIZ'.
  IF sy-subrc EQ 0.
    READ TABLE messages INTO DATA(message) WITH KEY msgnr = '003'.
    IF sy-subrc EQ 0.
      REPLACE '&' IN message-text WITH 'TEST VALUE'.
      WRITE:/ message-text.
    ENDIF.
  ENDIF.

roberto_forti
Contributor
0 Kudos

Hi Dear, you can code in different ways. see one sample on below ABAP Code, please!

Best Regards!

data: lv_text type string.
   
"BAPI Message text
message id lw_bapiret2-id
      type lw_bapiret2-type
    number lw_bapiret2-number
      with lw_bapiret2-message_v1
           lw_bapiret2-message_v2
           lw_bapiret2-message_v3
           lw_bapiret2-message_v4
      into lv_text.

message s223(z1) with (lv_text) display like 'I'.