‎2007 Apr 12 6:14 AM
Hello,
I would like to know how can we handle errors in ABAP OO by the add_from_instance method.
Kindly suggest your answers.
Regards,
Prerna.
‎2007 Apr 12 8:05 AM
Hello Perna
I assume that you mean the instance method from interface <b>IF_RECA_MESSAGE_LIST</b>.
The logic is quite simple. Let's assume a scenario where you have a <b>model instance</b> (containing the business logic -> <b>MVC </b>model). This model instance creates instance of others classes (e.g. for sales orders, etc.). Thus, we have a <b>composition </b>of classes.
Both the model instance and the others instances (which are customer classes) have a message handler (of TYPE REF TO if_reca_message_list). The message handler is defines as <b>public </b>and <b>read-only</b> instance attribute.
Following is some sample coding which demonstates the logic:
" We are here in a method of the model instance. We access the message handler
" using me->msg_msglist.
" The model instance has a list of object instance (e.g. me->mt_orders).
" Before processing these orders the model instance has already added
" several messages (e.g. for validation) to its message handler.
" Now the model instance processes the order instances:
LOOP AT me->mt_orders INTO ls_order.
" While creating the order instance they have done themselves some validation
" an added the message to their own message handler,
" e.g. ls_order-instance->mo_msglist.
" Now we add the messages from the order instances to the message handler
" of the model instance.
CALL METHOD me->mo_msglist->add_from_instance( ls_order-instance->mo_msglist).
" NOTE: this method has an IMPORTING parameter which allows to add
" the messages as subnode
ENDLOOP.Regards
Uwe
‎2007 Apr 12 8:19 AM
Hello,
I have a validation class which validates the data.
In the asmple logic, you have said that we have to collect these messages.
Kindly guide me as to how do I collect them.
Thanks,
Prerna
‎2007 Apr 12 9:00 AM
Hello Prerna
Assuming that the methods of your validation class return the message by raising an exception you can collect the messages as following:
" 1st validation
CALL METHOD mo_myclass->validate_input1
EXPORTING
...
EXCEPTIONS
error = 1
others = 2.
IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
" Here we collect the message that is returned in SYST
me->mo_msglist->add_from_symsg( ).
ENDIF.
" 2nd validation
CALL METHOD mo_myclass->validate_input2
EXPORTING
...
EXCEPTIONS
error = 1
others = 2.
IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
" Here we collect the message that is returned in SYST
me->mo_msglist->add_from_symsg( ).
ENDIF.
Regards
Uwe