‎2018 Nov 30 5:27 PM
Hello,
I would like to create a program whose fields of time are refreshed via a timer.
the code works very well, and it refreshes the time. but the problem is that all the fields and the screen are refreshed, and I would like the first field of time that refreshed without the rest of the fields.

Code :
REPORT ZTESTTIMER.
PARAMETERS : time type t DEFAULT 300.
PARAMETERS : Name type STRING.
PARAMETERS : City type STRING.
PARAMETERS : Phone type STRING.
CLASS my DEFINITION.
PUBLIC SECTION.
METHODS : run_handler FOR EVENT finished OF cl_gui_timer.
ENDCLASS.
DATA timer TYPE REF TO cl_gui_timer.
DATA myh TYPE REF TO my.
CLASS my IMPLEMENTATION.
METHOD run_handler.
CALL METHOD timer->run.
call method CL_GUI_CFW=>SET_NEW_OK_CODE
EXPORTING
new_code = 'REFR'.
ENDMETHOD.
ENDCLASS.
at SELECTION-SCREEN OUTPUT.
time = time - 1.
CREATE OBJECT timer.
CREATE OBJECT myh.
timer->interval = '1'.
CALL METHOD timer->run.
SET HANDLER myh->run_handler FOR ALL INSTANCES.
‎2018 Nov 30 8:22 PM
Hi
I know this is a demo report, but please don't use CALL METHOD for static method call, or CREATE OBJECT!
REPORT ztimer.
CLASS my DEFINITION.
PUBLIC SECTION.
METHODS: run_handler FOR EVENT finished OF cl_gui_timer.
ENDCLASS.
DATA timer TYPE REF TO cl_gui_timer.
DATA myh TYPE REF TO my.
SELECTION-SCREEN: BEGIN OF BLOCK bl1 WITH FRAME.
PARAMETERS: time TYPE t DEFAULT 300.
PARAMETERS: name TYPE string.
PARAMETERS: city TYPE string.
PARAMETERS: phone TYPE string.
SELECTION-SCREEN: END OF BLOCK bl1.
AT SELECTION-SCREEN OUTPUT.
time = time - 1.
IF timer IS INITIAL.
timer = NEW #( ).
myh = NEW #( ).
SET HANDLER myh->run_handler FOR ALL INSTANCES.
timer->interval = '1'.
timer->run( ).
ENDIF.
START-OF-SELECTION.
END-OF-SELECTION.
CLASS my IMPLEMENTATION.
METHOD run_handler.
cl_gui_cfw=>set_new_ok_code( 'REFR' ).
timer->run( ).
ENDMETHOD.
ENDCLASS.
Since cl_gui_cfw=>set_new_ok_code will trigger a PAI/PBO, the dynpro gets refreshed, there is no other way!
But you could put the countdown field to a HTML control an only refresh this HTML or better do the countdown with javascript and only tigger the PAI at the end of the countdown!
regards
Domi
‎2018 Dec 02 12:38 PM
dominik.bigl2 thank you for your reply.
Could you guide me how I can refresh that HTML control without the rest of the components. (because I'm still a beginner in abap).
regards,
‎2018 Dec 02 1:38 PM
bzakaria the timer is to be implemented in javascript inside the html page, not in abap : https://www.w3schools.com/js/js_timing.asp
+ javascript "submit" (of an HTML form) at the end of the countdown, to trigger ABAP code.
‎2018 Dec 02 3:08 PM
sandra.rossi thank you for your reply,
In fact, i wish to execute queries and calculations by the timer, and the countdown is just to test the timer and auto-refresh !
regards,
‎2018 Dec 02 4:49 PM
bzakaria so your screen contains one part with some input fields that you don't want be refreshed, and another part which contains output fields which are recalculated in ABAP every X seconds and refreshed.
Are they recalculated based on the input fields? If so, the problem is to know how you can get the input values without enterfering with the current input. Instead, I guess that you want something like the input field for entering an object name in the SE80 repository browser, which automatically outputs the list of matching object names after one or more characters have been pressed. The input fields should not be in the dynpro but in the HTML form, and the output fields can be anywhere else. Moreover, your ABAP code would be triggered by the timer, not by the keyboard.
‎2018 Dec 02 5:00 PM
Hi bzakaria
Have a look at report SAPHTML_EVENTS_DEMO. With this report and the link by sandra.rossi you can implement your requirement!
regards
Domi
‎2018 Dec 02 10:34 PM
sandra.rossi
No they will not be calculated based on the input fields, but by request independent of the other fields.
After each x seconds I will execute querie (example: read a field from a table filled by other programs) and I display the result in the field that will be refreshed.
Example : display in real time the number of items sold.
regards,
‎2018 Dec 03 8:25 AM
okay, with dynpro the result below is just awful, I recommend to use web browser solutions only (SAPUI5), forget dynpros.
The following two "awful" demos refresh data from the table of banks (transaction code FI01 to create or FI02 to maintain them)
This one with input fields in a dynpro:
DATA timer TYPE REF TO cl_gui_timer.
CLASS my DEFINITION.
PUBLIC SECTION.
METHODS pbo.
PRIVATE SECTION.
METHODS:
run_handler FOR EVENT finished OF cl_gui_timer,
init_alv,
reload_alv.
DATA: gt_output TYPE STANDARD TABLE OF bnka,
salv TYPE REF TO cl_salv_table,
go_docking TYPE REF TO cl_gui_docking_container.
ENDCLASS.
SELECTION-SCREEN: BEGIN OF BLOCK bl1 WITH FRAME.
PARAMETERS: name TYPE string.
PARAMETERS: city TYPE string.
PARAMETERS: phone TYPE string.
SELECTION-SCREEN: END OF BLOCK bl1.
CLASS my IMPLEMENTATION.
METHOD pbo.
IF timer IS INITIAL.
" FIRST TIME ONLY
timer = NEW #( ).
SET HANDLER run_handler FOR timer.
timer->interval = 1.
timer->run( ).
init_alv( ).
ENDIF.
ENDMETHOD.
METHOD init_alv.
CREATE OBJECT go_docking
EXPORTING
repid = sy-repid
dynnr = sy-dynnr
side = go_docking->DOCK_AT_LEFT
extension = 180.
CALL METHOD cl_salv_table=>factory
EXPORTING
r_container = go_docking
IMPORTING
r_salv_table = salv
CHANGING
t_table = gt_output[].
salv->display( ).
reload_alv( ).
ENDMETHOD.
METHOD run_handler.
reload_alv( ).
timer->run( ).
ENDMETHOD.
METHOD reload_alv.
SELECT * FROM bnka INTO TABLE @gt_output.
salv->refresh( s_stable = VALUE #( row = abap_true col = abap_true ) ).
ENDMETHOD.
ENDCLASS.
LOAD-OF-PROGRAM.
DATA(myh) = NEW my( ).
AT SELECTION-SCREEN OUTPUT.
myh->pbo( ).
This one with input fields in a web browser:
DATA timer TYPE REF TO cl_gui_timer.
CLASS my DEFINITION.
PUBLIC SECTION.
METHODS pbo.
PRIVATE SECTION.
METHODS:
run_handler FOR EVENT finished OF cl_gui_timer,
init_alv,
reload_alv.
DATA: gt_output TYPE STANDARD TABLE OF bnka,
salv TYPE REF TO cl_salv_table,
go_splitter TYPE REF TO cl_gui_easy_splitter_container.
ENDCLASS.
PARAMETERS dummy.
CLASS my IMPLEMENTATION.
METHOD pbo.
IF timer IS INITIAL.
" FIRST TIME ONLY
timer = NEW #( ).
SET HANDLER run_handler FOR timer.
timer->interval = 1.
timer->run( ).
init_alv( ).
ENDIF.
ENDMETHOD.
METHOD init_alv.
CREATE OBJECT go_splitter
EXPORTING
parent = cl_gui_container=>screen0
orientation = cl_gui_easy_splitter_container=>orientation_horizontal.
CALL METHOD cl_salv_table=>factory
EXPORTING
r_container = go_splitter->top_left_container
IMPORTING
r_salv_table = salv
CHANGING
t_table = gt_output[].
salv->display( ).
reload_alv( ).
cl_abap_browser=>show_html( html_string = `<html><body>Type something: <input></body></html>` container = go_splitter->bottom_right_container ).
ENDMETHOD.
METHOD run_handler.
reload_alv( ).
timer->run( ).
ENDMETHOD.
METHOD reload_alv.
SELECT * FROM bnka INTO TABLE @gt_output.
salv->refresh( s_stable = VALUE #( row = abap_true col = abap_true ) ).
ENDMETHOD.
ENDCLASS.
LOAD-OF-PROGRAM.
DATA(myh) = NEW my( ).
AT SELECTION-SCREEN OUTPUT.
myh->pbo( ).
‎2018 Dec 11 8:13 AM