Application Development and Automation 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: 
Read only

problem with automatic ALV refresh

Former Member
0 Likes
642

Hi all,

I have been reading the forums for automatic alv refresh.

Still, i couldnt get my alv refreshed automatically.

I have seen the blog of Rich H for automatic timer.

Can u guys just explain it with a small example ( just started learning oops concept).

Thanks.

1 ACCEPTED SOLUTION
Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
524

If you are on release 4.7 or better, then implement this program. It will show how to do an automatic refresh for ALV grid.

Please copy and paste this code and run it, every 3 seconds a new record will be written to the ALV Grid. Again, this assumes that the class CL_GUI_TIMER exists in your system.




REPORT zrich_0002.

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.                    "on_finished

ENDCLASS.                    "lcl_event_handler IMPLEMENTATION

REgards,

Rich Heilman

3 REPLIES 3
Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
525

If you are on release 4.7 or better, then implement this program. It will show how to do an automatic refresh for ALV grid.

Please copy and paste this code and run it, every 3 seconds a new record will be written to the ALV Grid. Again, this assumes that the class CL_GUI_TIMER exists in your system.




REPORT zrich_0002.

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.                    "on_finished

ENDCLASS.                    "lcl_event_handler IMPLEMENTATION

REgards,

Rich Heilman

Read only

Former Member
0 Likes
524
Read only

Former Member
0 Likes
524

thanks for helping me guys....

the code worked.

thanks again...........