02-05-2013 9:30 AM
Hi,
I have a selection screen. On putting the inputs in the selection screen and on executing it alv output will come.
In that screen i will make one refresh icon and on clicking on that refresh icon the whole report program should be executed again
that is it should once again hit the database table and should show us the output in ALV format with the refreshed data.
So, I want the code for that refresh icon in my report so that it could give the refreshed data output.
Thanks.
02-05-2013 4:49 PM
Hi Anuradha,
Use Below reference code which will refresh whole program as if you have hit back button and again press F8.
Code:
REPORT Z_TEST MESSAGE-ID ZTES.
AT SELECTION-SCREEN.
PERFORM VALIDATE_SEL.
START-OF-SELECTION.
PERFORM GET_DATA.
END-OF-SELECTION.
PERFORM DISPLAY_DATA.
------------------------------------------------------------------------------------------------------------------------------
THIS WILL BE YOUR SUBROUTINE FOR DISPLAY DATA WITH "USER_COMMAND"
------------------------------------------------------------------------------------------------------------------------------
FORM DISPLAY_DATA.
DATA:X_LAYOUT TYPE SLIS_LAYOUT_ALV.
X_LAYOUT-ZEBRA = 'X'.
X_LAYOUT-BOX_FIELDNAME = 'SEL'.
X_LAYOUT-COLWIDTH_OPTIMIZE = 'X'.
IF IT_FIELDCAT[] IS INITIAL.
PERFORM BUILD_FIELDCAT.
ENDIF.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
I_CALLBACK_PROGRAM = SY-REPID
I_CALLBACK_PF_STATUS_SET = 'SET_PF_STATUS'
I_CALLBACK_USER_COMMAND = 'USER_COMMAND'
IT_FIELDCAT = IT_FIELDCAT
IS_LAYOUT = X_LAYOUT
TABLES
T_OUTTAB = IT_FINAL
EXCEPTIONS
PROGRAM_ERROR = 1
OTHERS = 2.
IF SY-SUBRC <> 0.
MESSAGE I000 WITH 'Error in displaying ALV-GRID.'(011).
ENDIF.
ENDFORM.
------------------------------------------------------------------------------------------------------------------------------
CODE FOR USER_COMMAND
TO CAPTURE ACTION ON TOOL BAR BUTTON (YOUR CUSTOM REFRESH BUTTON)
------------------------------------------------------------------------------------------------------------------------------
FORM USER_COMMAND USING P_UCOMM LIKE SY-UCOMM
P_SELFIELD TYPE SLIS_SELFIELD.
CASE P_UCOMM.
WHEN 'REFRESH'.
P_SELFIELD-EXIT = 'X'. MAIN COMMAND MARK IT AS 'X'
PERFORM REFRESH_TABLES.
PERFORM GET_DATA.
PERFORM DISPLAY_DATA.
WHEN OTHERS.
ENDCASE.
ENDFORM.
Marking P_SELFIELD-EXIT = 'X' will terminate current screen allowing your new screen to be seen without overlapping old screen.
------------------------------------------------------------------------------------------------------------------------------
Regards,
Rohan Uphade.
02-05-2013 9:43 AM
If your program is correctly modularized, execute the same routine "load data" than before first display and then use the "refresh" method of the ALV. What is the exact problem, can you post the code you tried without success?
Regards,
Raymond
02-05-2013 9:47 AM
02-05-2013 10:18 AM
Hi Anuradha,
once u r done with generating ALV output using "resuse_grid_alv_output".
please declare the following parameters in FM "resuse_grid_alv_output" as below.
I_CALLBACK_PF_STATUS_SET = 'PFTEST'
I_CALLBACK_USER_COMMAND = 'USER_COMMAND'
then,
form pftest using rt_extab type slis_t_extab.
*This is to Copy PF Status which to be assigned to the ALV
set pf-status 'PFTEST'.
endform. "pftest
->you can create the PFTEST in menu painter (se41) where u can create a button for REFRESH .
FORM user_command USING r_ucomm TYPE sy-ucomm
rs_selfield TYPE slis_selfield.
*** Here u add the code to fetch the data from dbtable and display.
ENDFORM.
Hope the above code helps u .
Regards,
Azhar
02-05-2013 11:59 AM
HELLO,
DATA: go_obj TYPE REF TO gcl_event_receiver,
go_grid TYPE REF TO cl_gui_alv_grid,
CLASS gcl_event_receiver DEFINITION.
PUBLIC SECTION.
METHODS:
handle_before_user_command FOR EVENT before_user_command OF cl_gui_alv_grid
IMPORTING e_ucomm.
ENDCLASS.
* After that please create object go_obj and set handler
IF NOT go_obj IS BOUND.
CREATE OBJECT go_obj.
SET HANDLER go_obj->handle_before_user_command FOR go_grid.
ENDIF.
* Call a subroutine inside the method.
METHOD handle_before_user_command.
PERFORM f_handle_before_user_command USING e_ucomm.
ENDMETHOD.
* Sub routine details.
FORM f_handle_before_user_command USING i_ucomm TYPE syucomm.
CASE i_ucomm.
WHEN '&REFRESH'.
* Populate your data again.
ENDFORM.
Thanks,
Abhijit
02-05-2013 4:49 PM
Hi Anuradha,
Use Below reference code which will refresh whole program as if you have hit back button and again press F8.
Code:
REPORT Z_TEST MESSAGE-ID ZTES.
AT SELECTION-SCREEN.
PERFORM VALIDATE_SEL.
START-OF-SELECTION.
PERFORM GET_DATA.
END-OF-SELECTION.
PERFORM DISPLAY_DATA.
------------------------------------------------------------------------------------------------------------------------------
THIS WILL BE YOUR SUBROUTINE FOR DISPLAY DATA WITH "USER_COMMAND"
------------------------------------------------------------------------------------------------------------------------------
FORM DISPLAY_DATA.
DATA:X_LAYOUT TYPE SLIS_LAYOUT_ALV.
X_LAYOUT-ZEBRA = 'X'.
X_LAYOUT-BOX_FIELDNAME = 'SEL'.
X_LAYOUT-COLWIDTH_OPTIMIZE = 'X'.
IF IT_FIELDCAT[] IS INITIAL.
PERFORM BUILD_FIELDCAT.
ENDIF.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
I_CALLBACK_PROGRAM = SY-REPID
I_CALLBACK_PF_STATUS_SET = 'SET_PF_STATUS'
I_CALLBACK_USER_COMMAND = 'USER_COMMAND'
IT_FIELDCAT = IT_FIELDCAT
IS_LAYOUT = X_LAYOUT
TABLES
T_OUTTAB = IT_FINAL
EXCEPTIONS
PROGRAM_ERROR = 1
OTHERS = 2.
IF SY-SUBRC <> 0.
MESSAGE I000 WITH 'Error in displaying ALV-GRID.'(011).
ENDIF.
ENDFORM.
------------------------------------------------------------------------------------------------------------------------------
CODE FOR USER_COMMAND
TO CAPTURE ACTION ON TOOL BAR BUTTON (YOUR CUSTOM REFRESH BUTTON)
------------------------------------------------------------------------------------------------------------------------------
FORM USER_COMMAND USING P_UCOMM LIKE SY-UCOMM
P_SELFIELD TYPE SLIS_SELFIELD.
CASE P_UCOMM.
WHEN 'REFRESH'.
P_SELFIELD-EXIT = 'X'. MAIN COMMAND MARK IT AS 'X'
PERFORM REFRESH_TABLES.
PERFORM GET_DATA.
PERFORM DISPLAY_DATA.
WHEN OTHERS.
ENDCASE.
ENDFORM.
Marking P_SELFIELD-EXIT = 'X' will terminate current screen allowing your new screen to be seen without overlapping old screen.
------------------------------------------------------------------------------------------------------------------------------
Regards,
Rohan Uphade.
02-05-2013 6:45 PM
You could here remove the PERFORM DISPLAY_DATA in the USER_COMMAND form, then replace the P_SELFIELD-EXIT = 'X' by a P_SELFIELD-REFRESH = 'X'. Else the recursive call of ALV let me worried the performance/memory point of view. (Try to refresh a dozen of times and check memory via SM04)
Regards,
Raymond
02-06-2013 9:35 AM
Hi Raymond,
Thanks for the suggestion.
I just tested the performance side of both the code.
Here are the result.
Regards,
Rohan
02-06-2013 10:11 AM
About 20% gain, but did you also check memory consumption after a dozen of refresh ?
Regards,
Raymond