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

Send a press key event without Batch Input?

Former Member
0 Likes
1,155

Hi.

I need send a auto press key event (by example: press F8), by code.

When I put a instruction in the report, the report simulate the key pressed.

Exist some FM to do it? Is it posible?

Thanks!

1 ACCEPTED SOLUTION
Read only

Clemenss
Active Contributor
0 Likes
915

Hi Marcos,

no FM, but a method makes it possible.

You an use



    CALL METHOD cl_gui_cfw=>set_new_ok_code
      EXPORTING
        new_code = 'xxxx'.

Regards,

Clemens

7 REPLIES 7
Read only

Clemenss
Active Contributor
0 Likes
916

Hi Marcos,

no FM, but a method makes it possible.

You an use



    CALL METHOD cl_gui_cfw=>set_new_ok_code
      EXPORTING
        new_code = 'xxxx'.

Regards,

Clemens

Read only

Former Member
0 Likes
915

You can also check out the "SET USER-COMMAND" statement to do this.

Jonathan

Read only

0 Likes
915

Oh yes, there's also function module SAPGUI_SET_FUNCTIONCODE - a "where used" on this will turn up some sample code.

Jonathan

Read only

Former Member
0 Likes
915

Thanks by the reply, but it doesn't work

I need refresh an ALV Grid automatic, and I think send the 'AKTU' refresh code to the Sap system.

I have got the code that call a rutine in some times, but this code not works.

Read only

0 Likes
915

Hi,

Please give your query in detail. From your query it is not clear about requirement

if possible paste the code

a®

Read only

0 Likes
915

Hi Marcos,

you can use the method I recommended in an additional timer object method .

Please adapt the below sample program I used to display the current time with auto update:


*&---------------------------------------------------------------------*
*& Report  ZZCLOCK
*&
*&---------------------------------------------------------------------*
*& may be used to keep connection
*&
*&---------------------------------------------------------------------*

REPORT  zzclock.

*---------------------------------------------------------------------*
*       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.                    "lcl_gui_timer DEFINITION

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

  PUBLIC SECTION.

    CLASS-METHODS:

                on_finished
                       FOR EVENT finished OF lcl_gui_timer.

ENDCLASS.                    "lcl_event_handler DEFINITION


DATA: gui_timer TYPE REF TO lcl_gui_timer.
DATA: event_handler TYPE REF TO lcl_event_handler.
DATA: timeout_interval TYPE i VALUE '9'.

PARAMETERS:
            p_datum TYPE sy-datum,
            p_uzeit TYPE sy-uzeit.

AT SELECTION-SCREEN OUTPUT.
* set to time rounded to 10 seconds
  p_datum = sy-datum.
  p_uzeit = sy-uzeit.

  CREATE OBJECT gui_timer.

  SET HANDLER event_handler->on_finished FOR gui_timer.

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

*---------------------------------------------------------------------*
*       CLASS lcl_event_handler IMPLEMENTATION
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
CLASS lcl_event_handler IMPLEMENTATION.

  METHOD on_finished.

* Start Timer again
    gui_timer->interval = timeout_interval.
    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

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

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

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

  METHOD dispatch .

    CASE eventid.
      WHEN eventid_finished.
        RAISE EVENT finished.
    ENDCASE.

  ENDMETHOD.                    "dispatch

ENDCLASS.                    "lcl_gui_timer IMPLEMENTATION

Hope that's what you are looking for. I got the idea from a project where they used it to auto refresh an ALV grid...

You may also search this forum for keywords timer or autorefresh. It has been discussed here earlier.

Regards,

Clemens

Read only

Former Member
0 Likes
915

Sorry, I can't put the code. It's more for the reason of this thread.

And... for send a key as F8 ¿Is it posible?

Thanks