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: 

auto refresh

Former Member
0 Kudos

I am trying to implement auto refresh functionality in one of my reports. The requirement is to automatically refresh the report with latest data after a selected time interval.i.e say after every 5 minutes.

Thanks in advance for your help,

1 ACCEPTED SOLUTION

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos

Basically, you will want to use the class CL_GUI_TIMER. If you are on a release > 6.20, you'll be fine. Here is an example report, which is an ALV grid, copy and paste and run it. You will notice that every 3 seconds a new row is added to the ALV output automatically. Use this report as your example. The TIMEOUT field is the number of seconds that you want the program to wait before refreshing.



REPORT rich_0001.


TYPE-POOLS : slis.

DATA: BEGIN OF itab OCCURS 0,
      fld1 TYPE i,
      fld2 TYPE i,
      END OF itab.

*---------------------------------------------------------------------*
*       CLASS lcl_event_handler DEFINITION
*---------------------------------------------------------------------*
CLASS lcl_event_handler DEFINITION.

  PUBLIC SECTION.

    CLASS-METHODS: on_finished FOR EVENT finished OF cl_gui_timer.

ENDCLASS.                    "lcl_event_handler DEFINITION


DATA: gui_timer TYPE REF TO cl_gui_timer.
DATA: event_handler TYPE REF TO lcl_event_handler.
DATA: timeout TYPE i VALUE '3'.


START-OF-SELECTION.

  CREATE OBJECT gui_timer.

  SET HANDLER event_handler->on_finished FOR gui_timer.

  gui_timer->interval = timeout.
  CALL METHOD gui_timer->run.

  PERFORM write_list.

*----------------------------------------------------
* FORM  alv_user_command
*----------------------------------------------------
FORM alv_user_command USING r_ucomm  TYPE sy-ucomm
                     rs_selfield  TYPE slis_selfield.

  PERFORM read_data.
  rs_selfield-refresh = 'X'.

ENDFORM.                    "alv_user_command

*----------------------------------------------------
* FORM  write_list
*----------------------------------------------------
FORM write_list.

  DATA: fieldcat TYPE slis_t_fieldcat_alv.
  DATA: repid TYPE sy-repid.

  repid = sy-repid.

  PERFORM read_data.

  CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
    EXPORTING
      i_program_name         = repid
      i_internal_tabname     = 'ITAB'
      i_inclname             = repid
    CHANGING
      ct_fieldcat            = fieldcat
    EXCEPTIONS
      inconsistent_interface = 1
      program_error          = 2
      OTHERS                 = 3.


  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
      it_fieldcat             = fieldcat
      i_callback_program      = repid
      i_callback_user_command = 'ALV_USER_COMMAND'
    TABLES
      t_outtab                = itab
    EXCEPTIONS
      program_error           = 1
      OTHERS                  = 2.


ENDFORM.                    "write_list

*---------------------------------------------------------------------*
*       FORM read_data                                                *
*---------------------------------------------------------------------*
FORM read_data.

* Use your own database table here.
  itab-fld1 = itab-fld1 + 1.
  itab-fld2 = itab-fld2 + 1.
  APPEND itab.

ENDFORM.                    "read_data
*---------------------------------------------------------------------*
*       CLASS lcl_event_handler IMPLEMENTATION
*---------------------------------------------------------------------*
CLASS lcl_event_handler IMPLEMENTATION.

  METHOD on_finished.

* Start Timer again
    gui_timer->interval = timeout.
    CALL METHOD gui_timer->run.

* cause PAI
    CALL METHOD cl_gui_cfw=>set_new_ok_code
      EXPORTING
        new_code = 'REFR'.

  ENDMETHOD.

ENDCLASS.


Regards,

Rich Heilman

2 REPLIES 2

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos

Basically, you will want to use the class CL_GUI_TIMER. If you are on a release > 6.20, you'll be fine. Here is an example report, which is an ALV grid, copy and paste and run it. You will notice that every 3 seconds a new row is added to the ALV output automatically. Use this report as your example. The TIMEOUT field is the number of seconds that you want the program to wait before refreshing.



REPORT rich_0001.


TYPE-POOLS : slis.

DATA: BEGIN OF itab OCCURS 0,
      fld1 TYPE i,
      fld2 TYPE i,
      END OF itab.

*---------------------------------------------------------------------*
*       CLASS lcl_event_handler DEFINITION
*---------------------------------------------------------------------*
CLASS lcl_event_handler DEFINITION.

  PUBLIC SECTION.

    CLASS-METHODS: on_finished FOR EVENT finished OF cl_gui_timer.

ENDCLASS.                    "lcl_event_handler DEFINITION


DATA: gui_timer TYPE REF TO cl_gui_timer.
DATA: event_handler TYPE REF TO lcl_event_handler.
DATA: timeout TYPE i VALUE '3'.


START-OF-SELECTION.

  CREATE OBJECT gui_timer.

  SET HANDLER event_handler->on_finished FOR gui_timer.

  gui_timer->interval = timeout.
  CALL METHOD gui_timer->run.

  PERFORM write_list.

*----------------------------------------------------
* FORM  alv_user_command
*----------------------------------------------------
FORM alv_user_command USING r_ucomm  TYPE sy-ucomm
                     rs_selfield  TYPE slis_selfield.

  PERFORM read_data.
  rs_selfield-refresh = 'X'.

ENDFORM.                    "alv_user_command

*----------------------------------------------------
* FORM  write_list
*----------------------------------------------------
FORM write_list.

  DATA: fieldcat TYPE slis_t_fieldcat_alv.
  DATA: repid TYPE sy-repid.

  repid = sy-repid.

  PERFORM read_data.

  CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
    EXPORTING
      i_program_name         = repid
      i_internal_tabname     = 'ITAB'
      i_inclname             = repid
    CHANGING
      ct_fieldcat            = fieldcat
    EXCEPTIONS
      inconsistent_interface = 1
      program_error          = 2
      OTHERS                 = 3.


  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
      it_fieldcat             = fieldcat
      i_callback_program      = repid
      i_callback_user_command = 'ALV_USER_COMMAND'
    TABLES
      t_outtab                = itab
    EXCEPTIONS
      program_error           = 1
      OTHERS                  = 2.


ENDFORM.                    "write_list

*---------------------------------------------------------------------*
*       FORM read_data                                                *
*---------------------------------------------------------------------*
FORM read_data.

* Use your own database table here.
  itab-fld1 = itab-fld1 + 1.
  itab-fld2 = itab-fld2 + 1.
  APPEND itab.

ENDFORM.                    "read_data
*---------------------------------------------------------------------*
*       CLASS lcl_event_handler IMPLEMENTATION
*---------------------------------------------------------------------*
CLASS lcl_event_handler IMPLEMENTATION.

  METHOD on_finished.

* Start Timer again
    gui_timer->interval = timeout.
    CALL METHOD gui_timer->run.

* cause PAI
    CALL METHOD cl_gui_cfw=>set_new_ok_code
      EXPORTING
        new_code = 'REFR'.

  ENDMETHOD.

ENDCLASS.


Regards,

Rich Heilman

Former Member
0 Kudos

If you are running the report in a SAPGUI, you can probably use the

CL_GUI_TIMER class for that. In the background, you can plan a job,

running every 5 minutes.

Cheers,

Chaitanya.