Pages

Thursday, December 24, 2009

Display Error/Success/Warning messages at end of ALV report display in POP-UP Window

Use this Fm to display error messages. We can type in the Error type and it will give appropriate icons.

DATA: lwa_display_profile TYPE bal_s_prof,
lwa_log TYPE bal_s_log,
lwa_msg TYPE bal_s_msg.
DATA: lv_mess1 TYPE char50,
lv_mess2 TYPE string,
lv_prog TYPE sy-repid,
lv_title TYPE string.

* Define Grid Title
lv_prog = sy-repid.
lv_title = 'Overtime Equalization Report - Error Log'(044).

IF gv_err_flag IS INITIAL."Control should get inside this IF only
"for the first time user presses the 'Error Log'
"Button the mesages shud be read.It shud not be read repeatedly
"as the LOG HANDLER will be retained in memory and messages can be accessed using that

*****************************************************
* Call Error Log as a Pop-Up display *
*****************************************************
* $1: Create an initial log file
CALL FUNCTION 'BAL_LOG_CREATE'
EXPORTING
i_s_log = lwa_log
IMPORTING
e_log_handle = gv_log_handle
EXCEPTIONS
OTHERS = 1.
IF sy-subrc <> 0.
MESSAGE 'Error Log could not be displayed'(048) TYPE c_mess_i.
LEAVE LIST-PROCESSING.
ENDIF.
* $2: Add Error messages from Error log table to Message display FM

"Use Message number 000 from Message class ZHPT. This number is reserved
"for custom program message and contains '&&&&'. This will be replaced
"by Text passed in the Variables MSGV1,MSGV2,MSGV3,MSGV4

lwa_msg-msgid = c_msg_zhpt.
lwa_msg-msgno = c_msg_000.
lwa_msg-msgty = c_mess_e.

LOOP AT p_it_error INTO wa_error. "Internal table with error message which has been *collected during program execution.
* Derive message text
lwa_msg-msgv1 = wa_error-person.
lwa_msg-msgv2 = c_dash.
MOVE wa_error-mess TO lv_mess1.
lwa_msg-msgv3 = lv_mess1.
SHIFT wa_error-mess BY 50 PLACES LEFT.
MOVE wa_error-mess TO lv_mess2.
lwa_msg-msgv4 = lv_mess2.

* Add message to log file
CALL FUNCTION 'BAL_LOG_MSG_ADD'
EXPORTING
i_log_handle = gv_log_handle
i_s_msg = lwa_msg
EXCEPTIONS
OTHERS = 1.

ENDLOOP.
gv_err_flag = c_x.

ELSE.
* This when the Error log is displayed more than once i.e. the
* user presses the 'Error Log' button more for the next time.
* This code increases the performance as it reads the messages
* from the LOG_HANDLER which was created at the first time.

CLEAR lwa_msg.

CALL FUNCTION 'BAL_LOG_MSG_ADD'
EXPORTING
i_log_handle = gv_log_handle
i_s_msg = lwa_msg
EXCEPTIONS
OTHERS = 1.

ENDIF.

* $4: Get a prepared profile

CALL FUNCTION 'BAL_DSP_PROFILE_POPUP_GET'
IMPORTING
e_s_display_profile = lwa_display_profile
.

* Use grid for display of Error Messages
lwa_display_profile-use_grid = c_x.

* Set report to allow saving of variants
lwa_display_profile-disvariant-report = lv_prog.
* Set Title
lwa_display_profile-title = lv_title.
* 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:
lwa_display_profile-disvariant-handle = c_err_log.

* $5: Call display function module

* We do not specify any filter (like LWA_LOG_FILTER, ...,
* LT_MSG_HANDLE) since we want to display all logs available

CALL FUNCTION 'BAL_DSP_LOG_DISPLAY'
EXPORTING
i_s_display_profile = lwa_display_profile
EXCEPTIONS
profile_inconsistent = 1
internal_error = 2
no_data_available = 3
no_authority = 4
OTHERS = 5
.
IF sy-subrc <> 0.
MESSAGE 'Error Log could not be displayed'(048) TYPE c_mess_i.
LEAVE LIST-PROCESSING.
ENDIF.

No comments:

Post a Comment