Thursday, May 21, 2009

Use of Application Log FMs to display Message List/Log




 
REPORT zpwtest .
 
*&---------------------------------------------------------------------*
*& Types and Data
*&---------------------------------------------------------------------*
DATA: l_log_handle TYPE balloghndl,
l_s_log TYPE bal_s_log ,
l_s_msg TYPE bal_s_msg ,
l_msgno TYPE symsgno ,
l_s_display_profile TYPE bal_s_prof.
 
DATA : i_t100 TYPE TABLE OF t100 ,
ls_t100 TYPE t100 .
 
*&---------------------------------------------------------------------*
*& Selection Screen
*&---------------------------------------------------------------------*

PARAMETERS : p_arbgb TYPE t100-arbgb OBLIGATORY DEFAULT 'SD' .
 
*&---------------------------------------------------------------------*
*& Start of Selection
*&---------------------------------------------------------------------*

START-OF-SELECTION .
 
SELECT *
INTO TABLE i_t100
FROM t100
WHERE sprsl = sy-langu
AND arbgb = p_arbgb .
 
*&---------------------------------------------------------------------*
*& End of Selection
*&---------------------------------------------------------------------*

END-OF-SELECTION .
 
* Create an initial log file ------------------------------------------*

l_s_log-extnumber = 'Messages'.
CALL FUNCTION 'BAL_LOG_CREATE'
EXPORTING
i_s_log = l_s_log
IMPORTING
e_log_handle = l_log_handle
EXCEPTIONS
OTHERS = 1.
IF sy-subrc <> 0.
ENDIF.
 
DATA lv_int TYPE sy-tabix .
 
* Fill up corresponding error messages to log --------------------------*

LOOP AT i_t100 INTO ls_t100.
CLEAR l_s_msg .
lv_int = sy-tabix MOD 3 .
IF lv_int = 0 .
l_s_msg-msgty = 'S' .
ELSEIF lv_int = 1 .
l_s_msg-msgty = 'E' .
ELSE.
l_s_msg-msgty = 'W' .
ENDIF.
 
l_s_msg-msgid = ls_t100-arbgb .
l_s_msg-msgno = ls_t100-msgnr .
l_s_msg-msgv1 = '&' .
l_s_msg-msgv2 = '&' .
l_s_msg-msgv3 = '&' .
l_s_msg-msgv4 = '&' .
 
CALL FUNCTION 'BAL_LOG_MSG_ADD'
EXPORTING
i_log_handle = l_log_handle
i_s_msg = l_s_msg
EXCEPTIONS
OTHERS = 1.

IF sy-subrc <> 0 .
ENDIF .
ENDLOOP.
 
* Prepare to display the error log -------------------------------------*

CALL FUNCTION 'BAL_DSP_PROFILE_NO_TREE_GET'
IMPORTING
e_s_display_profile = l_s_display_profile.
 
* l_s_display_profile-use_grid = 'X' .

l_s_display_profile-disvariant-report = sy-repid.
l_s_display_profile-disvariant-handle = 'LOG'.
 
* Display error messages in grid ---------------------------------------*

CALL FUNCTION 'BAL_DSP_LOG_DISPLAY'
EXPORTING
i_s_display_profile = l_s_display_profile
EXCEPTIONS
OTHERS = 1.
IF sy-subrc <> 0.
ENDIF.
 
* Delete the messages inserted to application log ----------------------*

CALL FUNCTION 'BAL_LOG_MSG_DELETE_ALL'
EXPORTING
i_log_handle = l_log_handle
EXCEPTIONS
log_not_found = 1
OTHERS = 2.
 
IF sy-subrc <> 0.
ENDIF.

0 comments: