2010 Mar 08 12:52 PM
Hello,
we are trying to use application logging feature provided with ABAP by way of function modules BAL_LOG_ADD/SAVE etc. the results of these are visible in trasnaction SLG1.
In our scenario, we want to keep track of different abnormal situations which a background Job of a user with dialogue operation faces. So these situations could be part of a successful or un-successful transactions i.e. there could be and overall COMMIT or ROLLBACK for each transactions for which the log operations have been carried out.
Now the problem is that , the Logs are not getting saved for unsuccessful transactions i.e. where there is no COMMIT.
I need your help to get over this situation so that I able to save the Logs (in standard Log objects which are visiible in SLG1) even if the business transaction is not committed.
regards
Sushil
Hello,
we are trying to use application logging feature provided with ABAP by way of function modules BAL_LOG_ADD/SAVE etc. the results of these are visible in trasnaction SLG1.
In our scenario, we want to keep track of different abnormal situations which a background Job of a user with dialogue operation faces. So these situations could be part of a successful or un-successful transactions i.e. there could be and overall COMMIT or ROLLBACK for each transactions for which the log operations have been carried out.
Now the problem is that , the Logs are not getting saved for unsuccessful transactions i.e. where there is no COMMIT.
I need your help to get over this situation so that I able to save the Logs (in standard Log objects which are visiible in SLG1) even if the business transaction is not committed.
regards
Sushil
2010 Mar 08 3:26 PM
2010 Mar 08 10:08 PM
As the logs are first stored in memory, you may either use ROLLBACK on the main data then write the log to database and COMMIT, or if the transaction is successful do a unique COMMIT after data + log database updates
2010 Mar 09 6:57 AM
This trick could easily work if it is a custom transaction/program.
I would like to log msgs from the user exists (implemented by us) of the standard transactions where the commit is controlled by the stanrdard code and it might not be a good approach to do COMMIT in the user exist/Badis of the standard transaction.
let me know if I am missing sme thread here and may be there is some alternate trick by which it works in a cleaner way.
thanks for your time,
Sushil
2010 Mar 09 10:40 AM
There's one thing I don't understand, the standard probably works well. So, why don't you look at the way it works? (debug I mean)
Could you tell us more about the transaction you use, maybe some people already implemented it.
2010 Mar 09 5:59 PM
Hi Sushil, I have used this a few times. I just cut and paste some of the important parts of the code I used for the logging. I hope this helps you, or at least points you in a good direction. Good Luck!:
DATA: it_log_message TYPE zzlog_message OCCURS 0.
DATA: wa_log_message TYPE zzlog_message.
DATA: BEGIN OF gt_inv_rawdata_holder OCCURS 0,
rec(200) TYPE c,
END OF gt_inv_rawdata_holder.
DATA: gt_inv_rawdata_error LIKE STANDARD TABLE OF z3isp_inv_raw_tb.
*
*
*
*
IF sy-subrc <> 0.
MOVE-CORRESPONDING z3isp_inv_raw_tb TO wa_inv_rawdata_error.
MOVE 'E' TO wa_log_message-msgty.
CONCATENATE wa_inv_rawdata_error-z3ispmatnr
wa_inv_rawdata_error-z3isplocn84
INTO wa_log_message-msg_text_1
SEPARATED BY space.
CONCATENATE wa_inv_rawdata_error-z3ispstockroomcd
wa_inv_rawdata_error-z3ispmvdt
INTO wa_log_message-msg_text_2
SEPARATED BY space.
MOVE wa_inv_rawdata_error-z3ispmvtm TO
wa_log_message-msg_text_3.
MOVE 'Duplicate record' TO wa_log_message-msg_text_4.
APPEND wa_log_message TO it_log_message.
Endif.
*
*
*
*
*send the already collected error messages in it_log_message
*to App Log SLG1 Object Name ZISPINVRAW
CALL FUNCTION 'ZIU_MESSAGE_LOGGING'
EXPORTING
i_log_object = c_obj_zxiproxy
i_extnumber = l_ext_number
TABLES
t_log_message = it_log_message
EXCEPTIONS
log_header_inconsistent = 1
logging_error = 2
OTHERS = 3.
IF sy-subrc <> 0.
MOVE 'X' TO flg_applog_issue.
ENDIF.
commit work.
2010 Mar 09 6:02 PM
How come code always looke like this? I cut and pasted it right in my replay. Highlighted it, and selected "code"?
Oh well, here is the FM I call I tried several times to get it to display properly.
FUNCTION ziu_message_logging.
*"----------------------------------------------------------------------
*"*"Local interface:
*" IMPORTING
*" REFERENCE(I_LOG_OBJECT) TYPE BALOBJ_D
*" REFERENCE(I_EXTNUMBER) TYPE STRING
*" TABLES
*" T_LOG_MESSAGE STRUCTURE ZZLOG_MESSAGE
*" EXCEPTIONS
*" LOG_HEADER_INCONSISTENT
*" LOGGING_ERROR
*"----------------------------------------------------------------------
CONSTANTS: c_message TYPE syst-msgid VALUE 'ZMESSAGE',
c_999 TYPE syst-msgno VALUE '999'.
DATA:
l_log_handle TYPE balloghndl,
l_s_log TYPE bal_s_log,
l_dummy TYPE string,
l_ext_no TYPE bal_s_log-extnumber,
l_s_mdef TYPE bal_s_mdef.
* IF t_log_message[] IS NOT INITIAL.
l_s_log-object = i_log_object.
l_ext_no = i_extnumber.
l_s_log-extnumber = l_ext_no.
* Create the log with header data
CALL FUNCTION 'BAL_LOG_CREATE'
EXPORTING
i_s_log = l_s_log
IMPORTING
e_log_handle = l_log_handle
EXCEPTIONS
log_header_inconsistent = 1
OTHERS = 2.
IF sy-subrc <> 0.
CASE sy-subrc.
WHEN 1.
RAISE log_header_inconsistent.
WHEN OTHERS.
RAISE logging_error.
ENDCASE.
ENDIF.
l_s_mdef-log_handle = l_log_handle.
* Set the default value
CALL FUNCTION 'BAL_GLB_MSG_DEFAULTS_SET'
EXPORTING
i_s_msg_defaults = l_s_mdef
EXCEPTIONS
others = 0.
* Loop the message table and write the messages into the log
LOOP AT t_log_message.
* Use the message type ZMESSAGE and msg no 999
* Issue the message in a dummy variable
MESSAGE ID c_message TYPE t_log_message-msgty NUMBER c_999
WITH t_log_message-msg_text_1 t_log_message-msg_text_2
t_log_message-msg_text_3 t_log_message-msg_text_4
INTO l_dummy.
* The parameters set by message statement will be used
* Add the message in the log
PERFORM msg_add.
ENDLOOP.
* save logs in the database
CALL FUNCTION 'BAL_DB_SAVE'
EXPORTING
i_save_all = 'X'
EXCEPTIONS
log_not_found = 1
save_not_allowed = 2
numbering_error = 3
OTHERS = 4.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
* ENDIF.
endfunction.
*--------------------------------------------------------------------
* FORM MSG_ADD
*--------------------------------------------------------------------
* Add the message to the log
*-------------------------------------------------------------------*
FORM msg_add.
DATA:
l_s_msg TYPE bal_s_msg.
* define data of message for Application Log
l_s_msg-msgty = sy-msgty.
l_s_msg-msgid = sy-msgid.
l_s_msg-msgno = sy-msgno.
l_s_msg-msgv1 = sy-msgv1.
l_s_msg-msgv2 = sy-msgv2.
l_s_msg-msgv3 = sy-msgv3.
l_s_msg-msgv4 = sy-msgv4.
* add this message to log file
* (I_LOG_HANDLE is not specified, we want to add to the default log.
* If it does not exist we do not care =>EXCEPTIONS log_not_found = 0)
CALL FUNCTION 'BAL_LOG_MSG_ADD'
EXPORTING
* I_LOG_HANDLE =
i_s_msg = l_s_msg
EXCEPTIONS
log_not_found = 0
OTHERS = 1.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
ENDFORM.Edited by: Tom Matys on Mar 9, 2010 1:15 PM
2015 Nov 05 1:23 PM
| User | Count |
|---|---|
| 3 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |