0

I want to show a message of type E for which I have to first create a string. The string has mixed string and integer variables to be joined.

Since only strings can be concatenated, I copy integer variable into string variable, make a whole string and concatenate.

Is there a conversion function such as to_string(integer_variable) that can convert integers to string?

PROGRAM abc.
DATA: im_acc_no TYPE i VALUE 100,
      lv_acc_no TYPE string,
      lv_msg TYPE string.
START-OF-SELECTION.
      lv_acc_no = im_acc_no.
      CONCATENATE 'Acnt# ' lv_acc_no ' does not exist' INTO lv_msg.
      MESSAGE lv_msg TYPE 'E'.
gram77
  • 361
  • 1
  • 12
  • 30
  • 2
    Does this answer your question? [Displaying variables inside message statement in ABAP](https://stackoverflow.com/questions/63958202/displaying-variables-inside-message-statement-in-abap) – Sandra Rossi Sep 30 '20 at 16:03
  • Might also be helpful: [Is there another way to concatenate instead of using the CONCATENATE keyword?](https://stackoverflow.com/questions/18860281/is-there-another-way-to-concatenate-instead-of-using-the-concatenate-keyword) – Eduardo Copat Oct 01 '20 at 19:49

1 Answers1

4

There is the CONV operator (SAP help) which can do something similar to to_string but it is not allowed in the CONCATENATE, so won't help you in your scenario.

You could use the && operator (SAP help) to create the message in-place in the MESSAGE command like:

 MESSAGE |Acnt# | && lv_acc_no && | does not exist| type 'E'.

Side note: do not use this variant of the MESSAGE command, it might be easy to program but it makes it hard to investigate where a message is being generated. For this reason it is better to actually create a message in SE91 and use that. Variable replacements (&) in the message also handle integers just fine.

Gert Beukema
  • 2,510
  • 1
  • 17
  • 18
  • You could also write `|Acnt# { lv_acc_no } does not exist|`. Placing variables inline using `{` and `}` also gives you [a bunch of useful format options](https://help.sap.com/doc/abapdocu_cp_index_htm/CLOUD/en-US/abapcompute_string_format_options.htm). – Philipp Oct 02 '20 at 13:31