简体   繁体   中英

Displaying variables inside message statement in ABAP

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.

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

What you want can be achieved using a string template (works as of ABAP 7.02) eg |text and { variable }| :

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

Or if you want your message to 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 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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM