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.

Table maintenace generator events

http://wiki.sdn.sap.com/wiki/pages/viewpage.action?pageId=93454609


http://help.sap.com/saphelp_nw04s/helpdata/EN/91/ca9f0ea9d111d1a5690000e82deaaa/content.htm

Monday, December 21, 2009

ALV with row selection

1:
*
MODULE user_command_0001 INPUT.
CASE sy-ucomm.
WHEN gc_back.
LEAVE TO SCREEN 0.
WHEN gc_exit OR gc_cancel.
LEAVE PROGRAM.
WHEN gc_select.
PERFORM read_selected_row.
WHEN gc_download.
PERFORM download.
ENDCASE. "sy-ucomm
ENDMODULE. " USER_COMMAND_0001 INPUT

2:
FORM read_selected_row .
DATA: li_index TYPE lvc_t_roid,
lwa_index TYPE lvc_s_roid,
lv_line TYPE i.

CALL METHOD lv_alv_grid->get_selected_rows
IMPORTING
* ET_INDEX_ROWS =
et_row_no = li_index
.
* Get the number of lines selected
DESCRIBE TABLE li_index LINES lv_line.

IF lv_line IS INITIAL.
MESSAGE e000(zpp) WITH text-047.
ELSE.
LOOP AT gi_final INTO gwa_final.
READ TABLE li_index INTO lwa_index WITH KEY row_id = sy-tabix.
IF sy-subrc = 0.
SET PARAMETER ID gc_mat FIELD gwa_final-matnr.
SET PARAMETER ID gc_wrk FIELD gwa_final-werks.
SET PARAMETER ID gc_pln FIELD gwa_final-plnnr.
IF gwa_final-plnty = gc_r.
CALL TRANSACTION gc_ca23 AND SKIP FIRST SCREEN.
ELSEIF gwa_final-plnty = gc_n.
CALL TRANSACTION gc_ca03 AND SKIP FIRST SCREEN.
ENDIF.
ENDIF. "sy-subrc = 0
ENDLOOP. "AT gi_final
ENDIF. "lv_line IS INITIAL

ENDFORM. " READ_SELECTED_ROW

Display Internal Table as ALV popup screen




This can be done using normal 'REUSE_ALV_GRID_DISPLAY' by mentioning the 'X' co-ordinate in the Importing parameters of the FM. Following code describes the way:

data:lt_fcat TYPE slis_t_fieldcat_alv,
lwa_fcat TYPE slis_fieldcat_alv.

CONSTANTS: c_fcat_pop TYPE lvc_tname VALUE 'IT_ERROR'.

REFRESH lt_fcat.
CLEAR lwa_fcat.

lwa_fcat-fieldname = 'PERSON'.
lwa_fcat-tabname = c_fcat_pop.
lwa_fcat-seltext_m = 'PERNR/Identifier'.
APPEND lwa_fcat TO lt_fcat.
CLEAR lwa_fcat.

lwa_fcat-fieldname = 'MESS'.
lwa_fcat-tabname = c_fcat_pop.
lwa_fcat-seltext_m = 'Error Message'.
lwa_fcat-outputlen = 100.
APPEND lwa_fcat TO lt_fcat.
CLEAR lwa_fcat.
*****************************************************
* Call ALV POP-UP FM to display table *
*****************************************************
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
* I_INTERFACE_CHECK = ' '
* I_BYPASSING_BUFFER = ' '
* I_BUFFER_ACTIVE = ' '
I_CALLBACK_PROGRAM = sy-repid
* I_CALLBACK_PF_STATUS_SET = ' '
* I_CALLBACK_USER_COMMAND = ' '
* I_CALLBACK_TOP_OF_PAGE = ' '
* I_CALLBACK_HTML_TOP_OF_PAGE = ' '
* I_CALLBACK_HTML_END_OF_LIST = ' '
* I_STRUCTURE_NAME =
* I_BACKGROUND_ID = ' '
* I_GRID_TITLE =
* I_GRID_SETTINGS =
* IS_LAYOUT =
IT_FIELDCAT = lt_fcat
* IT_EXCLUDING =
* IT_SPECIAL_GROUPS =
* IT_SORT =
* IT_FILTER =
* IS_SEL_HIDE =
* I_DEFAULT = 'X'
* I_SAVE = ' '
* IS_VARIANT =
* IT_EVENTS =
* IT_EVENT_EXIT =
* IS_PRINT =
* IS_REPREP_ID =

I_SCREEN_START_COLUMN = 30
I_SCREEN_START_LINE = 10
I_SCREEN_END_COLUMN = 100
I_SCREEN_END_LINE = 20

* I_HTML_HEIGHT_TOP = 0
* I_HTML_HEIGHT_END = 0
* IT_ALV_GRAPHICS =
* IT_HYPERLINK =
* IT_ADD_FIELDCAT =
* IT_EXCEPT_QINFO =
* IR_SALV_FULLSCREEN_ADAPTER =
* IMPORTING
* E_EXIT_CAUSED_BY_CALLER =
* ES_EXIT_CAUSED_BY_USER =
TABLES
t_outtab = p_it_error
EXCEPTIONS
PROGRAM_ERROR = 1
OTHERS = 2
.
IF sy-subrc <> 0.
MESSAGE i000 WITH 'Error calling Pop-Up screen'.
LEAVE TO TRANSACTION c_tcode.
ENDIF.