2
votes

How do I display a variable inside a message statement, without using a message class?

IF acct_bal < min_bal.
    MESSAGE 'customer balance less than minimum. Balance-->', acct_bal TYPE 'E'.
ENDIF.

My program has a syntax error since the system does not allow acct_bal into the message statement. I don't want to use a message class with placeholders to do this:

Program z_test.
DATA: acct_bal TYPE 'I' value 10,
min_bal TYPE 'I' value 100.
IF acct_bal < min_bal.
    MESSAGE 'customer balance less than minimum. Balance-->', acct_bal type 'E'.
ENDIF.
1

1 Answers

7
votes

There are lots of possibilities. Here are some of them.

What you want can be achieved using a string template:

MESSAGE |customer balance less than minimum. Balance-->{ acct_bal }| TYPE 'E'.

Or if you want your message be translatable via a text symbol:

MESSAGE |{ replace( val = 'customer balance less than minimum. Balance-->&1'(001)
                    sub = '&1' with = acct_bal ) }| TYPE 'E'.

Or if you want your message be translatable via a message class, create a Message ID via transaction code SE91, with the text customer balance less than minimum. Balance-->&1, for instance the ID 001 in the message class ZMSGCLASS:

MESSAGE e001(zmsgclass) TYPE 'E' WITH acct_bal.

Etc.

More information in ABAP Documentation - MESSAGE.