Skip to Content
author's profile photo Former Member
Former Member

Synchronous User Interaction in Instance-Method

Hey Guys!

I got a problem getting information by user synchronous.

To make it understandable I abstracted the problem a little:

I have a class 'player'. It has an attribute 'name' and a method 'get_name'.

In get_name i want to ask the actual user for his/her name. A dialogue should open with a text-field and an ok-button.

(Solvable with DD_Documents -> no Problem as far).

But then I want to save the given value in text-field in the 'name'-variable.

This is a problem: Not because of getting the data out of the input field but because of the flow-control!

I know I could write a method in the same class to react to the interaction and save the variable. But if I want to use one or more players in a program, it does not wait until the variable is set to go on.

I do not want to go on with the code in the method as long as the user didn't press ok.

Can I wait for an event in a method?

Hope you get my problem!

Thank you for your help!

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

2 Answers

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on Nov 09, 2011 at 06:00 AM

    Hi Wolfgang,

    I assume the events used are from classes CL_GUI_DIALOGBOX_CONTAINER and CL_DD_BUTTON_ELEMENT. Seems these events will be triggered asynchronously in the order the user clicks on the popup.

    Using Function Module TRM_POPUP_TEXT_INPUT instead of class CL_DD_DOCUMENT could be easier and synchronous for such requirements. Also check function modules like POPUP_TO_GET_VALUE and CC_POPUP_STRING_INPUT.



    Add a comment
    10|10000 characters needed characters exceeded

    • I would say Varun has the right approach... I was not aware that those dialog methods were asynchronous but I know I have used at least one of those FMs for a popup. I believe it will process in a "blocking" mode such that only one will display until the user has input and then it would move to the next call.


      Ryan Crosby

  • Posted on Nov 04, 2011 at 04:10 PM

    Hi Wolfgang,

    You should be able to register an event within your class 'player' that you can then RAISE when the user clicks 'OK' to save their name. All you would need to do is register a handler for the event in a local class for your program and you could then add any event specific logic that you want to have happen when they click 'OK'. (It is commonly used for example in the ALV class CL_GUI_ALV_GRID).


    Ryan Crosby

    Add a comment
    10|10000 characters needed characters exceeded

    • Hi Wolfgang,

      I would try this kind of approach and see if it will solve your problem (I'm assuming your EVENTS are raised in the method display_document):

      First, I would cut the following lines from the method ask_for_name:

      set handler dbox_close for all instances.

      set handler dd_btn_clicked for all instances.

      set handler dd_ie_entered for all instances.

      Second, I would add this DEFINITION of a local class & object declaration (I guessed on parameter & class names):

      ** Local class definition for event receiver
      CLASS lcl_event_receiver DEFINITION.
            FOR EVENT dbox_close OF zcl_player_class
              IMPORTING e_name,
            FOR EVENT dd_btn_clicked OF zcl_player_class
              IMPORTING e_name,
            FOR EVENT dd_ie_entered OF zcl_player_class
              IMPORTING e_name.
      ENDCLASS.                    "lcl_event_receiver DEFINITION
      DATA: g_event_receiver TYPE REF TO lcl_event_receiver.

      Third, I would make the following changes in your main method:

      method main.
        CREATE OBJECT g_event_receiver
        create object s1.
        create object s2.
        create object s3.
        SET HANDLER g_event_receiver->handle_dbox_close FOR ALL INSTANCES.
        SET HANDLER g_event_receiver->handle_dd_btn_clicked FOR ALL INSTANCES.
        SET HANDLER g_event_receiver->handle_dd_ie_entered FOR ALL INSTANCES.
        s1->ask_for_name( ).
        s2->ask_for_name( ).
        s3->ask_for_name( ).
      write:/ s1->name.
      write:/ s2->name.
      write:/ s3->name.

      And lastly, insert the implementation for each of the handler methods:

      *&       Class (Implementation)  lcl_event_receiver
      *        Event receiver for player class
      *       CLASS lcl_event_receiver IMPLEMENTATION
      CLASS lcl_event_receiver IMPLEMENTATION.
        METHOD handle_dbox_close.
        METHOD handle_dd_btn_clicked.
        METHOD handle_dd_ie_entered.
      ENDCLASS.               "lcl_event_receiver


      Ryan Crosby

      Edited by: Ryan Crosby on Nov 8, 2011 9:50 AM

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.