Exercise 4: Using Multiple Controls

Use

You can create multiple controls of the same type or of a different type in your program. In this exercise, you create a second editor window that is designed to be used as a clipboard for short texts.

Procedure

  1. Create a new reference variable scratch to the class of the textedit control, and reference variable custom_container2 for the custom container control in your main program:

    DATA: scratch TYPE REF TO cl_gui_textedit,
         custom_container2 TYPE REF TO cl_gui_custom_container.
  2. Create a new container MYCONTAINER2 for a custom control on your screen.

  3. Create the control (including the custom container control) at PBO time and hide the status bar. To do this, insert the following lines of code into IF block IF EDITOR IS INITIAL:

    CREATE OBJECT custom_container2
          EXPORTING
             CONTAINER_NAME = 'MYCONTAINER2'
          EXCEPTIONS
             CNTL_ERROR = 1
             CNTL_SYSTEM_ERROR = 2
             CREATE_ERROR = 3
             LIFETIME_ERROR = 4
             LIFETIME_DYNPRO_DYNPRO_LINK = 5.
    
    
       CREATE OBJECT SCRATCH
          EXPORTING
             parent = custom_container2
             WORDWRAP_MODE = CL_GUI_TEXTEDIT=>WORDWRAP_AT_WINDOWBORDER
             WORDWRAP_TO_LINEBREAK_MODE = CL_GUI_TEXTEDIT=>TRUE.
       CALL METHOD SCRATCH->SET_STATUSBAR_MODE
          exporting
             STATUSBAR_MODE = CL_GUI_TEXTEDIT=>FALSE.
  4. Activate your new objects, and start your program.

Check Your Work

In the second container, the system displays a text editor without a status bar. Using the Copy function of the first editor and the Add function of the second editor, you can copy text into the second window.

Discussion

In the PBO module, you create multiple controls and call additional control methods. Transferring methods to the frontend only requires synchronization at PBO end. This means the methods of two different instances use the same Automation Queue.

Theoretically, you can buffer as many method calls in the queue as you like. However, the system limits the runtime for RFC calls. If this limit is exceeded, you must introduce additional points of synchronization, since otherwise the backend terminates the connection. Generally, this is not due to the number of RFC calls, but to the data volume to be transferred in such a call (long texts, for example).

Strategy

Especially if you use multiple controls, you can apply a certain strategy to reduce the number of flush calls. In many cases, you must retrieve the control properties with GET methods before you can determine control behavior with SET methods. Since you need the current values in your ABAP program after a GET method, a flush is indispensable (see also Exercise 1: Using Imported Values). In case of several GET calls independent of each other, you best proceed as follows:

  1. Bundle all GET calls in your source code.

  2. Call method FLUSH to transfer the methods to the frontend, and import the values of the GET calls.

  3. Read these values, and call all SET methods in a second block.

Grouping calls thus allows you to optimize performance.