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

Auto-refresh for a dynpro

Former Member
0 Likes
5,216

Hi all,

I'm having a problem with a dynpro created using the Screen Painter. I need an auto-refresh function (every tot seconds) but I'm not able to do it managing the PBO and PAI modules.

Can you help me, please?

Thanks in advance.

Angelo

1 ACCEPTED SOLUTION
Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
2,436

Of course, if you are on newer version and the class does exists, then the code is a lot shorter.




report zrich_0003 .

* THIS IS A LOCAL IMPLEMENTATION OF THE CL_GUI_TIMER WHICH IS AVALIABLE
* IN WAS 6.2
*
* Add the following elements to screen 100

*SY-DATUM	      I/O	1	2	10	10	1	DATS
*SY-UZEIT	      I/O	2	2	10	10	1	TIMS
*TIMER_CONTAINER   CCtrl	19	1	1	1	1
*OK_CODE	      OK	0	0	20	20	1	 OK
*---------------------------------------------------------------------*
*       CLASS lcl_event_handler DEFINITION
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
class lcl_event_handler definition.

  public section.

    class-methods: on_finished for event finished of lcl_gui_timer.

endclass.

data: gui_timer type ref to <b>cl_gui_timer</b>.
data: event_handler type ref to lcl_event_handler.
data: timeout type i value '3'.
data: ok_code like sy-ucomm,
      save_ok like sy-ucomm.


call screen 100.


*&---------------------------------------------------------------------*
*&      Module  STATUS_0100  OUTPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
module status_0100 output.
  set pf-status '0100'.
*  SET TITLEBAR 'xxx'.

    create object gui_timer.

    set handler event_handler->on_finished for gui_timer.

    gui_timer->interval = timeout.
    call method gui_timer->run.

endmodule.
*&---------------------------------------------------------------------*
*&      Module  USER_COMMAND_0100  INPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
module user_command_0100 input.

  save_ok = ok_code.
  case ok_code.
    when 'BACK'.
      leave program.
  endcase.

endmodule.


*---------------------------------------------------------------------*
*       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.



Please remember to award points for helpful answers and mark this post as solved when solved completely. Thanks.

Regadrds,

Rich Heilman

9 REPLIES 9
Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
2,436

Yep, check out this sample program. Here we are updating a dynpro every couple secods, we are showing the date and time. It uses the class CL_GUI_TIMER. If you are on a release eariler than 6.20, you can do as I've done here and implemnent the timer as a local class. In newer version the CL_GUI_TIMER class is global. You can of course create a "ZCL_GUI_TIMER" global class with the code from the local class in this example. Create a screen 100, and put the date and time fields. Then run it.




report zrich_0003 .

* THIS IS A LOCAL IMPLEMENTATION OF THE CL_GUI_TIMER WHICH IS AVALIABLE
* IN WAS 6.2
*
* Add the following elements to screen 100

*SY-DATUM	      I/O	1	2	10	10	1	DATS
*SY-UZEIT	      I/O	2	2	10	10	1	TIMS
*TIMER_CONTAINER   CCtrl	19	1	1	1	1
*OK_CODE	      OK	0	0	20	20	1	 OK
*---------------------------------------------------------------------*
*       CLASS lcl_gui_timer DEFINITION
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
class lcl_gui_timer definition inheriting from cl_gui_control.

  public section.

    constants:  eventid_finished type i value 1 .

    class-data: interval type i value '0'.

    events:     finished .

    methods:
             cancel
                  exceptions
                     error,
             constructor
                 importing
                     lifetime type i optional
                     value(shellstyle) type i optional
                     value(parent) type ref to cl_gui_container optional
                 exceptions
                     error,
             run
                 exceptions
                     error,
             dispatch redefinition.


endclass.

*---------------------------------------------------------------------*
*       CLASS lcl_event_handler DEFINITION
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
class lcl_event_handler definition.

  public section.

    class-methods: on_finished for event finished of lcl_gui_timer.

endclass.

data: gui_timer type ref to lcl_gui_timer.
data: event_handler type ref to lcl_event_handler.
data: timeout type i value '3'.
data: ok_code like sy-ucomm,
      save_ok like sy-ucomm.


call screen 100.


*&---------------------------------------------------------------------*
*&      Module  STATUS_0100  OUTPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
module status_0100 output.
  set pf-status '0100'.
*  SET TITLEBAR 'xxx'.

    create object gui_timer.

    set handler event_handler->on_finished for gui_timer.

    gui_timer->interval = timeout.
    call method gui_timer->run.

endmodule.
*&---------------------------------------------------------------------*
*&      Module  USER_COMMAND_0100  INPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
module user_command_0100 input.

  save_ok = ok_code.
  case ok_code.
    when 'BACK'.
      leave program.
  endcase.

endmodule.


*---------------------------------------------------------------------*
*       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.

*---------------------------------------------------------------------*
*       CLASS lcl_gui_timer IMPLEMENTATION
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
class lcl_gui_timer implementation.

  method constructor.

    type-pools: sfes.

    data clsid(80).
    data event_tab type cntl_simple_events.
    data event_tab_line type cntl_simple_event.

    if clsid is initial.
      data: return,
            guitype type i.

      guitype = 0.
      call function 'GUI_HAS_OBJECTS'
           exporting
                object_model = sfes_obj_activex
           importing
                return       = return
           exceptions
                others       = 1.
      if sy-subrc ne 0.
        raise error.
      endif.

      if return = 'X'.
        guitype = 1.
      endif.
      if guitype = 0.
        call function 'GUI_HAS_OBJECTS'
             exporting
                  object_model = sfes_obj_javabeans
             importing
                  return       = return
             exceptions
                  others       = 1.
        if sy-subrc ne 0.
          raise error.
        endif.

        if return = 'X'.
          guitype = 2.
        endif.
      endif.

      case guitype.
        when 1.
          clsid = 'Sapgui.InfoCtrl.1'.
        when 2.
          clsid = 'com.sap.components.controls.sapImage.SapImage'.
      endcase.
    endif.

    call method super->constructor
      exporting
        clsid = clsid
        shellstyle = 0
        parent = cl_gui_container=>default_screen
        autoalign = space
         exceptions others = 1.
    if sy-subrc ne 0.
      raise error.
    endif.

    call method cl_gui_cfw=>subscribe
      exporting
         shellid = h_control-shellid
         ref = me
         exceptions others = 1.
    if sy-subrc ne 0.
      raise error.
    endif.

* Register the events
    event_tab_line-eventid = lcl_gui_timer=>eventid_finished.
    append event_tab_line to event_tab.

    call method set_registered_events
      exporting
        events = event_tab.

  endmethod.

  method cancel.

    call method call_method
        exporting
                  method  = 'SetTimer'
                  p_count = 1
                  p1      = -1
                  queue_only = 'X'
         exceptions others = 1.
    if sy-subrc ne 0.
      raise error.
    endif.


  endmethod.

  method run.

    call method call_method
        exporting
                  method = 'SetTimer'
                  p_count = 1
                  p1     = interval
                  queue_only = 'X'
         exceptions others = 1.
    if sy-subrc ne 0.
      raise error.
    endif.


  endmethod.

  method dispatch .

    case eventid.
      when  eventid_finished.
        raise event finished.

    endcase.

  endmethod.

endclass.

REgards,

Rich Heilman

Read only

Former Member
0 Likes
2,436

hi,

check this class cl_gui_timer , it may help you.

check in the forum..

regards

vijay

Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
2,437

Of course, if you are on newer version and the class does exists, then the code is a lot shorter.




report zrich_0003 .

* THIS IS A LOCAL IMPLEMENTATION OF THE CL_GUI_TIMER WHICH IS AVALIABLE
* IN WAS 6.2
*
* Add the following elements to screen 100

*SY-DATUM	      I/O	1	2	10	10	1	DATS
*SY-UZEIT	      I/O	2	2	10	10	1	TIMS
*TIMER_CONTAINER   CCtrl	19	1	1	1	1
*OK_CODE	      OK	0	0	20	20	1	 OK
*---------------------------------------------------------------------*
*       CLASS lcl_event_handler DEFINITION
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
class lcl_event_handler definition.

  public section.

    class-methods: on_finished for event finished of lcl_gui_timer.

endclass.

data: gui_timer type ref to <b>cl_gui_timer</b>.
data: event_handler type ref to lcl_event_handler.
data: timeout type i value '3'.
data: ok_code like sy-ucomm,
      save_ok like sy-ucomm.


call screen 100.


*&---------------------------------------------------------------------*
*&      Module  STATUS_0100  OUTPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
module status_0100 output.
  set pf-status '0100'.
*  SET TITLEBAR 'xxx'.

    create object gui_timer.

    set handler event_handler->on_finished for gui_timer.

    gui_timer->interval = timeout.
    call method gui_timer->run.

endmodule.
*&---------------------------------------------------------------------*
*&      Module  USER_COMMAND_0100  INPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
module user_command_0100 input.

  save_ok = ok_code.
  case ok_code.
    when 'BACK'.
      leave program.
  endcase.

endmodule.


*---------------------------------------------------------------------*
*       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.



Please remember to award points for helpful answers and mark this post as solved when solved completely. Thanks.

Regadrds,

Rich Heilman

Read only

0 Likes
2,436

Thank you very much Rich, it works, but I need another help if you can. In my dynpro there's a dynamic document whose data is not updated after the refresh.

Any idea?

Thanks again.

Angelo

Read only

0 Likes
2,436

When refreshing you need to make sure that you are re-reading the data for the dynamic document.

Please remember to award points for helpful answers and mark you post as solved when solved completely. Thanks.

Regards,

Rich Heilman

Read only

0 Likes
2,436

The data are re-read but if I set the parameter reuse_control (of method display_document) to 'X' I receive a dump... do you know why?

Regards.

Angelo

Read only

0 Likes
2,436

I haven't work this dynamic documents. It may be better to open a separate thread for that problem. Please make sure to award and close this thread. Thanks.

Regards,

Rich Heilman

Read only

0 Likes
2,436

Ok, thank you very much again.

Regards,Angelo

Read only

mandar_shete
Active Participant
0 Likes
2,436

REPORT ZAUTO_REFRESH .
DATA: G_INIT_ONCE,
      OK_CODE(20),
      G_REF_FROM_TIMER.

DATA: BEGIN OF ITAB OCCURS 0,
        CARRID TYPE SPFLI-CARRID,
        CONNID TYPE SPFLI-CONNID,
        COUNTRYFR TYPE SPFLI-COUNTRYFR,
        CITYFROM TYPE SPFLI-CITYFROM,
        AIRPFROM TYPE SPFLI-AIRPFROM,
        COUNTRYTO TYPE SPFLI-COUNTRYTO,
        CITYTO TYPE SPFLI-CITYTO,
        AIRPTO TYPE SPFLI-AIRPTO,
        FLTIME TYPE SPFLI-FLTIME,
        DEPTIME TYPE SPFLI-DEPTIME,
        ARRTIME TYPE SPFLI-ARRTIME,
        DISTANCE TYPE SPFLI-DISTANCE,
        DISTID TYPE SPFLI-DISTID,
        FLTYPE TYPE SPFLI-FLTYPE,
        PERIOD TYPE SPFLI-PERIOD,
      END OF ITAB.


IF G_INIT_ONCE <> 'X'.
  G_INIT_ONCE = 'X'.
  CALL FUNCTION 'Z_ENQUE_SLEEP'
     STARTING NEW TASK 'WAIT'
     PERFORMING WHEN_FINISHED ON END OF TASK.

ENDIF.

WRITE:/ 'wait for 10 sec....'.

AT USER-COMMAND.
  CASE OK_CODE.
    WHEN 'FCT_R'.
      SELECT * FROM SPFLI INTO CORRESPONDING FIELDS OF TABLE ITAB.
      WRITE:/ SY-UZEIT.
      LOOP AT ITAB.
        WRITE:/ ITAB-CARRID,ITAB-CONNID.
      ENDLOOP.
      SY-LSIND = 0.
      IF G_REF_FROM_TIMER = 'X'.

        CALL FUNCTION 'Z_ENQUE_SLEEP'
          STARTING NEW TASK 'INFO'
          PERFORMING WHEN_FINISHED ON END OF TASK.

        G_REF_FROM_TIMER = ''.
      ENDIF.
  ENDCASE.


*---------------------------------------------------------------------*
*       FORM WHEN_FINISHED                                            *
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
*  -->  TASKNAME                                                      *
*---------------------------------------------------------------------*
FORM WHEN_FINISHED USING TASKNAME.
  RECEIVE RESULTS FROM FUNCTION 'Z_ENQUE_SLEEP'.

  G_REF_FROM_TIMER = 'X'.

* Trigger an event to run the at user-command
  SET USER-COMMAND 'FCT_R'.
  OK_CODE = 'FCT_R'.
  SY-UCOMM = 'FCT_R'.

ENDFORM.                    " WHEN_FINISHED

*************************************************************************

Function Module for refreshing the report (in SE37)


FUNCTION Z_ENQUE_SLEEP.
*"----------------------------------------------------------------------
*"*"Local interface:
*"----------------------------------------------------------------------

CALL FUNCTION 'ENQUE_SLEEP'
          EXPORTING
           SECONDS = 10.

ENDFUNCTION.