04-10-2007 6:04 AM
Hello Gurus!!!
I have developed coding for transaction fb03 in module pool program using OO concepts.
Now I want to enhance my coding using centralized error handling class.
ie. the errors are not shown immediately but a class captures those errors and then they are sent to the calling class which displays those errors).
Kindly suggest your answers.
Thanks in advance,
Sachin
04-10-2007 6:35 AM
Hello Sachin
I use the interface <b>IF_RECA_MESSAGE_LIST</b> for central message handling. The coding looks like this:
* Define a global attribute in the report or an instance attribute within the model class
DATA:
go_msglist TYPE REF TO if_reca_message_list.
" Create message handler
go_msglist = cf_reca_message_list=>create( ).
* NOTE: the CREATE method contains IMPORTING parameter for
* object/subobject for SAP log (transactions SLG0, SLG1).
" Collect messages/errors -> different methods available:
" (1) Messages from BAPI (structure BAPIRET2)
CALL METHOD go_msglist->add_from_bapi(...)
" (2) SYST-Message available
CALL METHOD go_msglist->add_from_symsg(...)
" (3) Define your own message
CALL METHOD go_msglist->add(...).
If you have a model class (with a message handler) that should collect the messages from subordinates classes you can use method:
go_msglist->add_from_instance( instance->mo_msglist ).
The meaning of the other methods of <b>IF_RECA_MESSAGE_LIST</b> are quite obvious.
Finally, the following coding shows how to display the collected messages in a tree display:
METHOD display_log .
* define local data
DATA:
ld_handle TYPE balloghndl,
lt_log_handles TYPE bal_t_logh,
ls_profile TYPE bal_s_prof.
* Log nicht im Batch-Betrieb anzeigen
CHECK ( syst-batch NE abap_true ).
ld_handle = me->mo_msglist->get_handle( ).
APPEND ld_handle TO lt_log_handles.
* get a display profile which describes how to display messages
CALL FUNCTION 'BAL_DSP_PROFILE_DETLEVEL_GET'
IMPORTING
e_s_display_profile = ls_profile.
*** get standard profile to display one log
** CALL FUNCTION 'BAL_DSP_PROFILE_SINGLE_LOG_GET'
** IMPORTING
** e_s_display_profile = ls_profile.
* set report to allow saving of variants
ls_profile-disvariant-report = sy-repid.
* when you use also other ALV lists in your report,
* please specify a handle to distinguish between the display
* variants of these different lists, e.g:
ls_profile-disvariant-handle = 'LOG'.
CALL FUNCTION 'BAL_DSP_LOG_DISPLAY'
EXPORTING
i_s_display_profile = ls_profile
i_t_log_handle = lt_log_handles
* I_T_MSG_HANDLE =
* I_S_LOG_FILTER =
* I_S_MSG_FILTER =
* I_T_LOG_CONTEXT_FILTER =
* I_T_MSG_CONTEXT_FILTER =
* I_AMODAL = ' '
* IMPORTING
* E_S_EXIT_COMMAND =
EXCEPTIONS
profile_inconsistent = 1
internal_error = 2
no_data_available = 3
no_authority = 4
OTHERS = 5.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
ENDMETHOD.
Regards
Uwe
04-10-2007 8:18 AM
Dear Uwe,
I have implemented validation class which displays all the error messages through message class inside which I displayed error messages.
The code is as follows :-
CLASS z_validation DEFINITION.
PUBLIC SECTION.
METHODS: check_company_code,
check_docnr,
check_fiscal_year.
ENDCLASS. "Z_Validation DEFINITION
----
CLASS Z_Validation IMPLEMENTATION
----
*
----
CLASS z_validation IMPLEMENTATION.
METHOD: check_company_code.
if txt_codco = ' ' and txt_docno = ' ' and txt_fisyr = ' '.
MESSAGE i006.
endif.
IF txt_codco = ' '.
MESSAGE i002.
LEAVE TO SCREEN 0100.
ELSE.
SELECT t001~bukrs INTO CORRESPONDING FIELDS OF TABLE it_doc FROM t001
WHERE t001~bukrs = txt_codco..
IF sy-subrc NE 0.
MESSAGE i000.
LEAVE TO SCREEN 0100.
ENDIF.
ENDIF.
ENDMETHOD. "Check_Company_Code
METHOD: check_docnr.
IF txt_docno = ' '.
MESSAGE i003.
LEAVE TO SCREEN 0100.
ELSE.
SELECT belnr
INTO CORRESPONDING FIELDS OF TABLE it_doc FROM bkpf
WHERE bkpfbukrs = txt_codco AND bkpfbelnr = txt_docno.
IF sy-subrc NE 0.
MESSAGE i005.
LEAVE TO SCREEN 0100.
ENDIF.
ENDIF.
ENDMETHOD . "Check_Docnr
METHOD: check_fiscal_year.
IF txt_fisyr = ' '.
MESSAGE i004.
LEAVE TO SCREEN 0100.
ELSE.
SELECT gjahr
INTO CORRESPONDING FIELDS OF TABLE it_doc FROM bkpf
WHERE bkpfbukrs = txt_codco AND bkpfbelnr = txt_docno AND bkpf~gjahr = txt_fisyr.
IF sy-subrc NE 0.
MESSAGE i001.
LEAVE TO SCREEN 0100.
ENDIF.
ENDIF.
ENDMETHOD. "Check_Fiscal_Year
ENDCLASS. "Z_Validation IMPLEMENTATION
MODULE user_command_0100 INPUT.
DATA: obj1 TYPE REF TO z_validation,
obj2 TYPE REF TO z_data_processing,
obj3 TYPE REF TO z_screen.
CREATE OBJECT: obj1, obj2, obj3.
CASE sy-ucomm.
WHEN 'SEARCH'.
CALL METHOD: obj1->check_company_code.
CALL METHOD: obj1->check_docnr.
CALL METHOD: obj1->check_fiscal_year.
LEAVE TO SCREEN 0200.
ENDCASE.
ENDMODULE. " USER_COMMAND_0100 INPUT
&----
Please suggest your answer.
Thanks in advance,
Sachin
04-10-2007 9:01 AM
Dear Uwe,
What should Ipass in the following method if I want to create my own message :-
CALL METHOD go_msglist->add(...).
Thanks in advance,
Sachin
04-10-2007 10:22 AM
Hello Sachin
Simply fill the parameters with your message identification, e.g.:
CALL METHOD go_msglist->add
EXPORTING
id_msgty = 'E' " error
id_msgid = 'Z_MY_MESSAGES' " name of your message class
id_msgno = '006'
* id_msgv1 = '<value of 1st parameter, if any>'
...
id_detlevel = '1' . " level of the message in the log tree
Regards
Uwe
04-10-2007 12:43 PM
Dear Uwe,
Thanks a lot for the help. I am able to run the code. But I would be glad if you could kindly explain me the logic and functionality of the same.
Also, I would like to know, how to call multiple message nos(000 , 001 ,002 and so on), as I have a message class, which displays all the error messages.
One more thing, I wanted to know, what is id_detlevel. I saw it in the class, it is the number of levels in the log tree. Kindly explain in detail.
Thanks a lot for the valuable advice.
Sachin.
04-10-2007 1:36 PM
Hello Sachin
Of course you will have to log many messages. In this case you have to call the appropriate method for every single message, e.g.:
(1) A function module raises an exception and fills the SYST message parameters -> call method ADD_SYMSG
(2) You want to log your own message -> call method ADD
(3) A BAPI returns several message lines in the RETURN parameter -> map the BAPIRET2 structure to RECAMSG structure and call method ADD for each line
Finally, if your messages have an underlying hierarchy and you want to display this hierarchy as tree you need to set parameter ID_DETLEVEL, e.g.:
(a) Your main objects are sales orders -> set ID_DETLEVEL = '1' with an 'I' message "Process Sales Orders"
(b) You loop over your sales orders -> set ID_DETLEVEL = '2' for each sales order and add an information message to the message handler
(c) You collect messages for each item of the sales order -> set ID_DETLEVEL = '3'
Consequence: the tree display will look like this:
-"Process Sales Orders" [Level=1]
- "Sales Order 1" [Level=2]
- message 1 for item x [Level=3]
- message 2 for item y
- "Sales Order 2"
- message 1 for item x
...
Regards
Uwe
04-10-2007 2:38 PM
Dear Uwe,
With your help, I have implemented the and successfully displayed the error message
(3) Define your own message
CALL METHOD go_msglist->add(...).
But now could you please help me out to display the error message using an instance method i.e.,
go_msglist->add_from_instance( instance->mo_msglist ).
What would be the modifications for the above add_from_instance(method).
Thanks in advance,
Sachin
04-10-2007 5:59 PM
Hello Sachin
You will find plenty of sample reports for displaying logs in package <b>SZAL </b>(for example report <b>SBAL_DEMO_04_DETLEVEL</b>).
How do you use the ADD_FROM_INSTANCE method?
I will give you a simple example. Let's assume you have created a model class holding the business logic of your application. The model class has a message handler (instance attribute MO_MSGLIST of type IF_RECA_MESSAGE_LIST).
The model instance has to create several sales order instances which have their own message handler.
" We are now in the model instance having an instance attribute MO_MSGLIST
LOOP AT mt_list INTO ls_list.
CREATE OBJECT lo_salesdoc
EXPORTING
...
" While creating the instance many checks are executed in the CONSTRUCTOR method and messages are collected in the message handler of the lo_salesdoc instance.
" Next we add these messages to the message handler of the model instance.
" In order to do so we define the message handler of the sales order class as <b>public</b>
" yet <b>read-only</b>.
IF ( lo_salesdoc IS BOUND ).
me->mo_msglist->add_from_instance( lo_salesdoc->mo_msglist ).
" The sales order instance could not be created then add the SYST message
ELSE.
me->mo_msglist->add_symsg( ).
ENDIF.
APPEND lo_salesdoc INTO lt_salesdoc. " itab containing the sales order instances
ENDLOOP.
Regards
Uwe
04-11-2007 6:36 AM
Dear Uwe,
The methods which you have suggested is working fantastic.
But now I want to create my own error table globally with methods get_error( ) and display_error( ).
Whenever the user is getting error , the errors are collected in the error table which I will create with the fields( error description and error type) for time being.
And by using instance ADD_FROM_INSTANCE method , I want to display that particular error accordingly.
Kindly suggest your answer.
Thanks in advance,
Sachin
04-11-2007 10:30 AM
Hello Sachin
The extraction of specific messages has to be done "manually". Using method<b> GET_LIST</b> or <b>GET_LIST_AS_BAPIRET</b> you can retrieve a list of the messages and delete all entries where (e.g.)
msgty NA 'AEX'.
Before doing this you can use method <b>HAS_MESSAGES_OF_MSGTY</b> to check whether a message handler contains any message of type 'E' or worse ('A' or 'X' ).
Regards
Uwe
04-11-2007 10:55 AM
Dear Uwe,
I have implemented the transaction FB03. Used ALV grid for displaying the line items and also displayed the header data by specifying the workarea fields in the following text boxes using module pool program.
Initially, suggested by you, I have implemented the single error method by using add() .
But now , I want to implement it using the add by instance.For that we done the following things :-
1 . Created an error table with fields (error description and error no.).
2. We want to display multiple errors using an instance method so that the coding performance could improve.
3. Also I have created error class using se24.
Kindly suggest me how to implement the same. Waiting for your answer
Thanks in advance,
Sachin