Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ABAP Objects - access message class of a class?

Tags:

abap

In the header information of an ABAP Objects class, I can enter a message class to use with the MESSAGE statement. This works like the MESSAGE-ID statement of a report or a function pool. Since I can't find the message class I entered in the header data anywhere in the generated sections, I assume that it's generated into the top-level CLASS-POOL statement somewhere.

For some libraries (for examples, the BAL application logging), it's necessary to specify the message class using a variable or a method parameter. Up to now, I've defined a constant that specified the message class and used that constant. I'm wondering if it's possible to access the message class specified in the header data in some other way so that I can get rid of that redundant variable.

Has anyone found a way to do so?

EDIT: The new way should be easier than the old one - I'm not crazy enough to add a CLASS-CONSTRUCTOR and perform some database access or SEO_* function calls just to get rid of that constant.

like image 296
vwegert Avatar asked Dec 10 '25 15:12

vwegert


2 Answers

I think you need a CLASS-CONSTRUCTOR to set a class attribute with the message class.

The MESSAGE statement with INTO clause has the side effect of setting the SY- system variables. So you could put into your CLASS-CONSTRUCTOR something like:

DATA: lf_dummy TYPE string.
MESSAGE s999 INTO lf_dummy.
af_msgid = sy-msgid.
like image 70
Christian Avatar answered Dec 13 '25 02:12

Christian


You could use the class builder API:

data the_class type ref to cl_oo_class.
create object the_class
  exporting
    clsname = `ZCL_SOMECLASS`.
data message_class type arbgb.
message_class = the_class->class-msg_id.
like image 34
René Avatar answered Dec 13 '25 04:12

René



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!