SAP R/3 форум ABAP консультантов
Russian ABAP Developer's Club

Home - FAQ - Search - Memberlist - Usergroups - Profile - Log in to check your private messages - Register - Log in - English
Blogs - Weblogs News

ActiveX Timer Control in ABAP



 
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> OLE2, Excel, WinWord
View previous topic :: View next topic  
Author Message
admin
Администратор
Администратор



Joined: 01 Sep 2007
Posts: 1640

PostPosted: Mon Sep 03, 2007 10:21 am    Post subject: ActiveX Timer Control in ABAP Reply with quote

For anyone interested in timer control in abap, a new approch is discussed here.

This approach is different from all known solutions. Using a new z class called ZCL_GUI_TIMER, you can program so that an OKCODE is executed periodically. In between the intervals, you can continue to work with the transaction.

From the example below, you will learn how to embed 3rd party Activex controls into SAPGUI.

Step A) Download a small freeware activex control from the following url and install it. This url is safe.
http://www.programmersheaven.com/download/17755/download.aspx

Step B) Create a z class called ZCL_GUI_TIMER. Code is given below.

Step C) Example program ZGUI_TIMER_TEST. Code is given below.

CLASS ZCL_GUI_TIMER

Code:
Class:ZCL_GUI_TIMER
       Inh.from:CL_GUI_CONTROL
Attribute
 Privateattribute
       M_OKCODE    Inst  TYPE SYUCOMM
       M_INTERVAL  Inst  TYPE I

Events
       Publicevents
       Timer   Interval reached     
Methods
 Publicmethods
    CONSTRUCTOR DEFINITION
       Description:Constructor
       Instancemthd
       Importingparameter
         PARENT TYPE REF TO CL_GUI_CONTAINER(AbstractContainerforGUIControls)
         VALUE(LIFETIME) TYPE I DEFAULT LIFETIME_DEFAULT(Lifetime)
         VALUE(SHELLSTYLE) TYPE I DEFAULT LIFETIME_DEFAULT OPTIONAL(ShellStyle)
         VALUE(NAME) TYPE STRING DEFAULT LIFETIME_DEFAULT OPTIONAL(Name)
       Exceptions
         CNTL_ERROR(Errorincntl_version_errorCallStack)
         CNTL_INSTALL_ERROR(ControlIncorrectlyInstalled)
         CNTL_VERSION_ERROR(InsertedControlIsObsolete)

     CONSTRUCTOR IMPLEMENTATION.
         DATA: clsid(80).
         IF NOT activex IS INITIAL.
       *    SAPGUI for Windows OR HTML(www_isactive not initial) environment
           clsid  = 'RSTIMER.RSTimerCtrl'.
         ELSEIF NOT javabean IS INITIAL.
       *    SAPGUI for Java environment
           clsid  = ''.
           RAISE cntl_error.
         ENDIF.
         CALL METHOD super->constructor
           EXPORTING
             clsid             = clsid
             shellstyle        = shellstyle
             parent            = parent
             lifetime          = lifetime
             name              = name
           EXCEPTIONS
             cntl_system_error = 2
             OTHERS            = 3.
         CASE sy-subrc.
           WHEN 0.
           WHEN 2.
             RAISE cntl_install_error.
           WHEN OTHERS.
             RAISE cntl_error.
         ENDCASE.
         DATA: lt_event TYPE cntl_simple_events,
               l_event LIKE LINE OF lt_event.
         l_event-eventid = 1.
         APPEND l_event TO lt_event.
         CALL METHOD set_registered_events
           EXPORTING
             events = lt_event
           EXCEPTIONS
             OTHERS = 1.
         IF sy-subrc NE 0.
           RAISE cntl_error.
         ENDIF.
         CALL METHOD set_property
           EXPORTING
             property = 'Enabled'                                  "#EC NOTEXT
             value    = 0
           EXCEPTIONS
             OTHERS   = 1.
         IF sy-subrc NE 0.
           RAISE cntl_error.
         ENDIF.
         CALL METHOD set_property
           EXPORTING
             property = 'AllTicks'                            "#EC NOTEXT
             value    = 0
           EXCEPTIONS
             OTHERS   = 1.
         IF sy-subrc NE 0.
           RAISE cntl_error.
         ENDIF.
       ENDMETHOD.

    SET_INTERVAL DEFINITION
       Description:SetInterval
       Instancemthd
       Importingparameter
         INTERVAL TYPE I(Intervalinminutes)
       Exceptions
         CNTL_ERROR(ControlErrorwhensettinginterval)

    set_interval IMPLEMENTATION.
         m_interval = interval * 1000.
       ENDMETHOD.

    START DEFINITION
       Description:StartTimer
       Instancemthd
       Importingparameter
         VALUE(OKCODE_TO_TRIGGER) TYPE SYUCOMM  OPTIONAL(Screens,functioncodetrigger
       Exceptions
         CNTL_ERROR(ControlErrorwhenstartingtimer)

    start IMPLEMENTATION.
         SET HANDLER handle_event
             FOR me.
         m_okcode = okcode_to_trigger.
         CALL METHOD set_property
           EXPORTING
             property = 'Enabled'                                  "#EC NOTEXT
             value    = 1
           EXCEPTIONS
             OTHERS   = 1.
         IF sy-subrc NE 0.
           RAISE cntl_error.
         ENDIF.
         CALL METHOD cl_gui_cfw=>flush.
         CALL METHOD set_property
           EXPORTING
             property = 'Interval'                                 "#EC NOTEXT
             value    = m_interval
           EXCEPTIONS
             OTHERS   = 1.
         IF sy-subrc NE 0.
           RAISE cntl_error.
         ENDIF.
       ENDMETHOD.
 
    STOP DEFINITION
       Description:StopTimer
       Instancemthd
       Exceptions
         CNTL_ERROR(ControlErrorwhenstartingtimer)

    stop IMPLEMENTATION.
         CALL METHOD set_property
           EXPORTING
             property = 'Enabled'                                  "#EC NOTEXT
             value    = 0
           EXCEPTIONS
             OTHERS   = 1.
         IF sy-subrc NE 0.
           RAISE cntl_error.
         ENDIF.
         CALL METHOD set_property
           EXPORTING
             property = 'Interval'                                 "#EC NOTEXT
             value    = 0
           EXCEPTIONS
             OTHERS   = 1.
         IF sy-subrc NE 0.
           RAISE cntl_error.
         ENDIF.
         CALL METHOD cl_gui_cfw=>flush.
       ENDMETHOD.

Privatemethods
  HANDLE_EVENT DEFINITION
       Description:HandleWhentimerreachesinterval
       Eventhandlerfor:ZCL_GUI_TIMER=>TIMER
       Instancemthd
 
   handle_event IMPLEMENTATION.
         CALL METHOD cl_gui_cfw=>set_new_ok_code
           EXPORTING
             new_code = m_okcode.
       ENDMETHOD.

       RedefinedMethods
       DISPATCH
       METHOD dispatch .
         CASE eventid.
           WHEN 1.
             RAISE EVENT timer.
           WHEN OTHERS.
         ENDCASE.
       ENDMETHOD.
 


EXAMPLE PROGRAM ZGUI_TIMER_TEST

Code:
REPORT  ZGUI_TIMER_TEST                            .

DATA: g_cont TYPE REF TO cl_gui_custom_container,
      g_timer TYPE REF TO zcl_gui_timer,
      g_interval TYPE i,

      g_okcode TYPE sy-ucomm,
      g_old_okcode LIKE g_okcode,
      g_no_intervals(5) TYPE n.


START-OF-SELECTION.
  CALL SCREEN 100.


MODULE initialize OUTPUT.
*Create Container
  SET PF-STATUS 'MAIN'.
  IF g_cont IS INITIAL.
    CREATE OBJECT g_cont
      EXPORTING
        container_name              = 'G_CONT'
      EXCEPTIONS
        cntl_error                  = 1
        cntl_system_error           = 2
        create_error                = 3
        lifetime_error              = 4
        lifetime_dynpro_dynpro_link = 5
        OTHERS                      = 6
        .
    IF sy-subrc <> 0.
      MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
                 WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
    ENDIF.

  ENDIF.

*Create instance of Timer Class
  IF g_timer IS INITIAL.
    CREATE OBJECT g_timer
      EXPORTING
        parent             = g_cont
      EXCEPTIONS
        cntl_error         = 1
        cntl_install_error = 2
        cntl_version_error = 3
        OTHERS             = 4
        .
    IF sy-subrc <> 0.
      MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
                 WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
    ENDIF.
  ENDIF.
ENDMODULE.                 " initialize  OUTPUT


MODULE user_command_0100 INPUT.
  g_old_okcode = g_okcode.
  CLEAR: g_okcode.
  CASE g_old_okcode.
    WHEN 'SET'.
      PERFORM set_interval.
    WHEN 'INTERVAL_REACHED'.
      ADD 1 TO g_no_intervals.
      MESSAGE s016(38) WITH
          'It works! -'
          g_interval
          ' sec interval reached -'
          g_no_intervals.

    WHEN 'EXIT'.
      LEAVE PROGRAM.
    WHEN OTHERS.
  ENDCASE.
ENDMODULE.                 " USER_COMMAND_0100  INPUT


FORM set_interval.
  CALL METHOD g_timer->set_interval
    EXPORTING
      interval = g_interval
    EXCEPTIONS
      OTHERS   = 1.
  IF sy-subrc <> 0.
    MESSAGE i016(38) WITH
          'Error setting interval on control'.
  ENDIF.
  CALL METHOD g_timer->start
    EXPORTING
      okcode_to_trigger = 'INTERVAL_REACHED'.
ENDFORM.                    "SET_INTERVAL
 

EXAMPLE PROGRAM ZGUI_TIMER_TEST SCREEN 100
Screen Elements

Code:
G_INTERVAL   Text   8
G_INTERVAL   I/O   10
G_SET                   Push   12
G_CONT                   CCtrl   5
G_OKCODE   OK   20


Screen Flow Logic
Code:
PROCESS BEFORE OUTPUT.
  module initialize.

PROCESS AFTER INPUT.
 MODULE USER_COMMAND_0100.


Автор: Silent_Devil
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> OLE2, Excel, WinWord All times are GMT + 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


All product names are trademarks of their respective companies. SAPNET.RU websites are in no way affiliated with SAP AG.
SAP, SAP R/3, R/3 software, mySAP, ABAP, BAPI, xApps, SAP NetWeaver and any other are registered trademarks of SAP AG.
Every effort is made to ensure content integrity. Use information on this site at your own risk.