Show TOC

Procedure documentationExercise 3: Calling Methods of the Control Locate this document in the navigation structure

 

Once you have created an instance of a control, you affect its behavior by means of methods. These methods help you to use the functions of the control and determine its properties. In order to execute control methods, you must normally transfer them to the frontend.

In this exercise, you implement a function that loads a text from an internal table into the text window.

Procedure

  1. To generate a text, declare an internal table and a work area globally in your main program. Declare also global flag g_loaded:

    Syntax Syntax

    1. TYPES: begin of mytable_line,
                line(line_length) type C,
                end of mytable_line.
      DATA: MYTABLE TYPE TABLE OF MYTABLE_LINE,
            TEXTSTRUCT TYPE MYTABLE_LINE,
            g_loaded TYPE C. 
      
    End of the source code.

    Note Note

    The line length of the internal table was intentionally set to the position of the line break in the textedit control (see Exercise 2: Creating a Control and its Container).

    End of the note.
  2. Define a text element and have your internal table filled with text in the PBO module. As the system should do this only once, include your statements in the IF block for creating the control:

    Syntax Syntax

    1. DO 20 TIMES.
         WRITE TEXT-001 TO TEXTSTRUCT-LINE.
         APPEND TEXTSTRUCT TO MYTABLE.
      ENDDO.
      
    End of the source code.
  3. To make the new function accessible, define another pushbutton on screen 100 that has the following properties:

    • Function code: IMP

    • Text: Import

    • icon: ICON_IMPORT

  4. In the PAI module, determine the function code in the existing CASE statement, and create subroutine LOAD_TAB:

    Syntax Syntax

    1. WHEN 'IMP'.
            PERFORM LOAD_TAB.
      
    End of the source code.
  5. To load the text of the internal table into the editor, call method set_text_as_r3table in your subroutine. Flag g_loaded tells you that the text has been loaded:

    Syntax Syntax

    1. FORM LOAD_TAB.
         call method editor->set_text_as_r3table
                   exporting table = mytable
            exceptions
                others = 1.
         if sy-subrc ne 0.
             CALL FUNCTION 'POPUP_TO_INFORM'
                   EXPORTING
                        TITEL = repid
                        TXT2 = ' '
                        TXT1 = 'Error in set_text_as_r3table'(600).
         else.
            g_loaded = 'X'.
         endif.
         CALL METHOD CL_GUI_CFW=>FLUSH.
         IF SY-SUBRC NE 0.
            CALL FUNCTION 'POPUP_TO_INFORM'
                EXPORTING
                      TITEL = REPID
                      TXT2 = sy-subrc
                      TXT1 = 'Form LOAD_TAB: Error in FLUSH'(601).
         ENDIF.
      ENDFORM.                   " LOAD_TAB
      
    End of the source code.
  6. Activate your new objects, and start your program.

Check Your Work

If you click the Import pushbutton you created, twenty lines appear that display the text of text element TEXT-001. If not, you probably have forgotten to create the text element.

Note Note

In this exercise, you called a control method within a subroutine. For a discussion of this subject, see Exercise 3: Control Methods in Subroutines.

End of the note.