Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Code for refresh icon in alv report

Former Member
0 Kudos

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.

1 ACCEPTED SOLUTION

Former Member
0 Kudos

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.

8 REPLIES 8

raymond_giuseppi
Active Contributor
0 Kudos

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

Former Member
0 Kudos

Hi Anuradha,

Use this event  "LOAD-OF-PROGRAM " in your program .

Regard's

Smruti

Former Member
0 Kudos

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

0 Kudos

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

Former Member
0 Kudos

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.

0 Kudos

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

Former Member
0 Kudos

Hi Raymond,

Thanks for the suggestion.

I just tested the performance side of both the code.

Here are the result.

Regards,

Rohan

0 Kudos

About 20% gain, but did you also check memory consumption after a dozen of refresh ?

Regards,

Raymond