Exercise 3: Calling Methods of the Control
Usage
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
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.

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).DO 20 TIMES.
WRITE TEXT-001 TO TEXTSTRUCT-LINE.
APPEND TEXTSTRUCT TO MYTABLE.
ENDDO.
WHEN 'IMP'.
PERFORM LOAD_TAB.
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
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.
In this exercise, you called a control method within a subroutine. For a discussion of this subject, see