Exercise 3: Calling Methods of the Control 
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.
To generate a text, declare an internal table and a work area globally in your main program. Declare also global flag g_loaded:
Syntax
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.
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).
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
DO 20 TIMES. WRITE TEXT-001 TO TEXTSTRUCT-LINE. APPEND TEXTSTRUCT TO MYTABLE. ENDDO.
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
In the PAI module, determine the function code in the existing CASE statement, and create subroutine LOAD_TAB:
Syntax
WHEN 'IMP'.
PERFORM LOAD_TAB.
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
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
Activate your new objects, and start your program.
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
In this exercise, you called a control method within a subroutine. For a discussion of this subject, see Exercise 3: Control Methods in Subroutines.