Application Log in SLG0 & SLG1
Application Log
These are 3 important transaction code used for Application Log:
- SLG0– Create a new Log Object and Sub-object
- SLG1– Display Application Log
- SLG2– Delete the Application Log
Step-1: Create Object using SLG0:
Step-1.2: Select Object and click on Sub-Objects:
Step-2: Implement logic for Object & Sub Object with dummy code:
REPORT ZDEMO_TESTING.
***===>Standard Internal Table & Structure
DATA:lt_msg TYPE bal_tt_msg,
ls_msg TYPE bal_s_msg.
***===>Data Declaraction
DATA: lv_handle TYPE balloghndl.
***===>Append Message to Internal Table
MOVE 'S' TO ls_msg-msgty.
MOVE 'ZCRM' TO ls_msg-msgid.
MOVE '000' TO ls_msg-msgno.
MOVE 'SLG Log' TO ls_msg-msgv1.
APPEND ls_msg TO lt_msg.
***===>Call Generic Function Module to create application log
CALL FUNCTION 'ZCRM_APPLICATION_LOG'
EXPORTING
i_object = 'ZCRM_LOG'
i_subobject = 'ZCRM_SOBJ'
i_prog = sy-cprog
i_user = sy-uname
i_transaction = sy-tcode
i_date = sy-datum
i_time = sy-uzeit
i_batch = sy-batch
IMPORTING
e_log_handle = lv_handle
TABLES
t_message = lt_msg
EXCEPTIONS
log_header_inconsistent = 1
OTHERS = 2.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.
***===>Standard Internal Table & Structure
DATA:lt_msg TYPE bal_tt_msg,
ls_msg TYPE bal_s_msg.
***===>Data Declaraction
DATA: lv_handle TYPE balloghndl.
***===>Append Message to Internal Table
MOVE 'S' TO ls_msg-msgty.
MOVE 'ZCRM' TO ls_msg-msgid.
MOVE '000' TO ls_msg-msgno.
MOVE 'SLG Log' TO ls_msg-msgv1.
APPEND ls_msg TO lt_msg.
***===>Call Generic Function Module to create application log
CALL FUNCTION 'ZCRM_APPLICATION_LOG'
EXPORTING
i_object = 'ZCRM_LOG'
i_subobject = 'ZCRM_SOBJ'
i_prog = sy-cprog
i_user = sy-uname
i_transaction = sy-tcode
i_date = sy-datum
i_time = sy-uzeit
i_batch = sy-batch
IMPORTING
e_log_handle = lv_handle
TABLES
t_message = lt_msg
EXCEPTIONS
log_header_inconsistent = 1
OTHERS = 2.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.
Step-3: Run above Report Program and check log in SLG1.
**********************************************************************************
FUNCTION ZCRM_APPLICATION_LOG.
*"--------------------------------------------------------------------
*"*"Local Interface:
*" IMPORTING
*" VALUE(I_OBJECT) TYPE BALOBJ_D
*" VALUE(I_SUBOBJECT) TYPE BALSUBOBJ
*" VALUE(I_EXTNUMBER) TYPE BALNREXT OPTIONAL
*" VALUE(I_EXC) TYPE BAL_S_EXC OPTIONAL
*" VALUE(I_PROG) TYPE SYST_CPROG DEFAULT SY-CPROG
*" VALUE(I_USER) TYPE SYST_UNAME DEFAULT SY-UNAME
*" VALUE(I_TRANSACTION) TYPE SYST_TCODE DEFAULT SY-TCODE
*" VALUE(I_DATE) TYPE SYST_DATUM DEFAULT SY-DATUM
*" VALUE(I_TIME) TYPE SYST_UZEIT DEFAULT SY-UZEIT
*" VALUE(I_BATCH) TYPE SYST_BATCH DEFAULT SY-BATCH
*" EXPORTING
*" VALUE(E_LOG_HANDLE) TYPE BALLOGHNDL
*" TABLES
*" T_MESSAGE TYPE BAL_TT_MSG
*" EXCEPTIONS
*" LOG_HEADER_INCONSISTENT
*"--------------------------------------------------------------------
DATA: lv_s_log TYPE bal_s_log,
lv_handle TYPE balloghndl.
DATA: lwa_message TYPE bal_s_msg,
lwa_handle TYPE balloghndl,
lt_handle TYPE bal_t_logh.
lv_s_log-object = i_object.
lv_s_log-subobject = i_subobject.
lv_s_log-extnumber = i_extnumber.
lv_s_log-aldate = i_date.
lv_s_log-altime = i_time.
lv_s_log-aluser = i_user.
lv_s_log-altcode = i_transaction.
lv_s_log-alprog = i_prog.
lv_s_log-almode = i_batch.
CALL FUNCTION 'BAL_LOG_CREATE'
EXPORTING
i_s_log = lv_s_log
IMPORTING
e_log_handle = lv_handle
EXCEPTIONS
log_header_inconsistent = 1
OTHERS = 2
.
IF sy-subrc <> 0.
* Implement suitable error handling here
ELSE.
LOOP AT t_message INTO lwa_message.
CALL FUNCTION 'BAL_LOG_MSG_ADD'
EXPORTING
i_log_handle = lv_handle
i_s_msg = lwa_message
EXCEPTIONS
log_not_found = 1
msg_inconsistent = 2
log_is_full = 3
OTHERS = 4
.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.
ENDLOOP.
ENDIF.
lwa_handle = lv_handle.
APPEND lwa_handle TO lt_handle.
CALL FUNCTION 'BAL_DB_SAVE'
EXPORTING
i_save_all = 'X'
i_t_log_handle = lt_handle
EXCEPTIONS
log_not_found = 1
save_not_allowed = 2
numbering_error = 3
OTHERS = 4
.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.
e_log_handle = lv_handle.
ENDFUNCTION.
Comments
Post a Comment