SAP ABAP OBJECTS Tutorials

Example 3: Event handling – System event

System events are passed irrespective of the flow-logic of the screen. To implement a system event change the code from example 2 as follows:

Code:

CLASS lcl_event_handler IMPLEMENTATION.

METHOD catch_dblclick.

*—  event_type = ‘Event DBLCLICK raised’.

* Reacting to the system event

call method cl_gui_cfw=>set_new_ok_code

exporting new_code = ‘SHOW’.

MODULE user_command_0100 INPUT.

CASE ok_code.

code………

WHEN ‘SHOW’.

event_type = ‘System dblclick’.

WHEN OTHERS.

*—-    call method cl_gui_cfw=>Dispatch.

ENDCASE.

ENDMODULE.                 ” USER_COMMAND_0100  INPUT

MODULE status_0100 OUTPUT.

Code …………….

*—    wa_events-appl_event = ‘X’. “This is an application event

wa_events-appl_event = space. “This is a system event

ENDIF.

ENDMODULE.                 ” STATUS_0100  OUTPUT

Result:

When you double clicks on the TextEdit control nothing happens, since the flow-logic of the screen an dthe fielde transport is ignore.

Example 4: Calling methods of the control

In this exercise a function that loads the texts of an internal table into the text window, is implemented.

Steps:

Define anoterh pushbutton on the screen, that activates the method that fills the TextEdit control. Give itname PUSHBUTTON_IMPORT and function code IMP.

Define a form CREATE_TEXTS that carries out the text import.

Only changes to the code in example 2 is show.

Code:

MODULE user_command_0100 INPUT.

CASE ok_code.

code………

WHEN ‘IMP’.

perform load_texts.

ENDCASE.

ENDMODULE.                 ” USER_COMMAND_0100  INPUT

*&———————————————————————*

*&      Form  load_texts

*&———————————————————————*

* This form creates an internal table with texts. The the contents of

* the table is instered into the TextEdit control using method

* set_text_as_r3table

*———————————————————————-*

FORM load_texts.

TYPES:

BEGIN OF t_texttable,

line(line_length) TYPE c,

END OF t_texttable.

DATA

i_texttable TYPE TABLE OF t_texttable.

* Create internal table with texts

APPEND ‘This a method that fills the TextEdit control’ TO i_texttable.

APPEND ‘with a text.’ TO i_texttable.

DO 10 TIMES.

APPEND ‘hallo world !’ TO i_texttable.

ENDDO.

* Load TextEdit control with texts

CALL METHOD editor->set_text_as_r3table

EXPORTING table = i_texttable.

IF sy-subrc > 0.

*   Display an error message

EXIT.

ENDIF.

* All methods that operates on controls are transferred to the frontend

* by a RFC calls. the method FLUSH is used to determine when this is done.

CALL METHOD cl_gui_cfw=>flush.

IF sy-subrc > 0.

*   Display an error message

ENDIF.

ENDFORM.                    ” create_texts