Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

on-the-fly WRITE when processing program

Former Member
0 Likes
1,005

Hi there dear UI specialists.

I would like to ask you if there is a possibility to display WRITEs on-the-fly during the program flow?

I mean for example


DATA: BEGIN OF itab OCCURS 0,
        item_1(50) ,
      END OF itab .
DATA: line LIKE LINE OF itab .
 
DATA: ctr_i TYPE i .
DATA: ctr_c(3) .
 
ctr_i = 1 .
 
DO 5 TIMES .
  ctr_c = ctr_i .
  CLEAR line .
  CONCATENATE 'This is a' ctr_c 'line of log.'
  INTO line SEPARATED BY SPACE .
  ctr_i = ctr_i + 1 .
 
  APPEND line TO itab .
 
ENDDO .
 
LOOP AT itab INTO line .
  WAIT UP TO 1 SECONDS.
  WRITE / line-item_1 .
 
ENDLOOP .

that code will show an output list after 5 seconds and it looks like

This is a 1 line of log.

This is a 2 line of log.

This is a 3 line of log.

This is a 4 line of log.

This is a 5 line of log.

Whilst I would like to display an empty screen when the program begins and populate it with each line every second, so user would have the current log of program.

Is it possible to do with WRITE statement? Or maybe there is some other solution to reach such effect?

I did a ALV_GRID -based solution, but I don't like it because to refresh grid I have to refresh screen with


    CALL FUNCTION 'SAPGUI_SET_FUNCTIONCODE'
      EXPORTING  FUNCTIONCODE = '/00'
      EXCEPTIONS FUNCTION_NOT_SUPPORTED = 1 .

when each item is processed. So instead of LOOP I have to use READ statement then, because SAPGUI_SET_FUNCTIONCODE would probably break the LOOP.

I will be thankful for help. Greetings. P.

1 ACCEPTED SOLUTION
Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
956

Not sure that this is really user friendly, but you can do an auto-refresh on a list display. Here is an example. Copy this code and run the program. You can see that it will report that the job is running, then show you the log entries as they are added each time. This is just an example program, but this should give you some idea of how you can refresh the display,

REPORT  zrich_0001.

DATA: BEGIN OF itab OCCURS 0,
        item_1(50) ,
      END OF itab .
DATA: line LIKE LINE OF itab .

DATA: ctr_i TYPE i .
DATA: ctr_c(3) .

*---------------------------------------------------------------------*
*       CLASS lcl_event_handler DEFINITION
*---------------------------------------------------------------------*
CLASS lcl_event_handler DEFINITION.

  PUBLIC SECTION.

    CLASS-METHODS: on_finished FOR EVENT finished OF cl_gui_timer.

ENDCLASS.                    "lcl_event_handler DEFINITION

DATA: lo_gui_timer TYPE REF TO cl_gui_timer.
DATA: lv_timeout TYPE i VALUE '3'.

START-OF-SELECTION.

  CREATE OBJECT lo_gui_timer.
  lo_gui_timer->interval = lv_timeout.
  lo_gui_timer->run( ).
  SET HANDLER lcl_event_handler=>on_finished FOR lo_gui_timer.

  ctr_i = 1 .

*  DO 5 TIMES .
*    ctr_c = ctr_i .
*    CLEAR line .
*    CONCATENATE 'This is a' ctr_c 'line of log.'
*    INTO line SEPARATED BY space .
*    ctr_i = ctr_i + 1 .
*    APPEND line TO itab .
*  ENDDO .

  WRITE:/ 'Job Running'.

AT USER-COMMAND.

  sy-lsind = sy-lsind - 1.

  WRITE:/ 'Job Running'.
  LOOP AT itab INTO line .
    WRITE / line-item_1 .
  ENDLOOP .

* Add another line for the next time we write.
  ctr_c = ctr_i .
  CLEAR line .
  CONCATENATE 'This is a' ctr_c 'line of log.'
  INTO line SEPARATED BY space .
  ctr_i = ctr_i + 1 .
  APPEND line TO itab .

*---------------------------------------------------------------------*
*       CLASS lcl_event_handler IMPLEMENTATION
*---------------------------------------------------------------------*
CLASS lcl_event_handler IMPLEMENTATION.

  METHOD on_finished.

* Start Timer again
    lo_gui_timer->interval = lv_timeout.
    lo_gui_timer->run( ).

* cause PAI
    CALL METHOD cl_gui_cfw=>set_new_ok_code
      EXPORTING
        new_code = 'REFR'.

  ENDMETHOD.                    "on_finished

ENDCLASS.                    "lcl_event_handler

Regards,

Rich Heilman

Edited by: Rich Heilman on Jan 21, 2010 8:59 AM

7 REPLIES 7
Read only

Sm1tje
Active Contributor
0 Likes
956

Not sure where you are heading, but sounds like you could use FM SAPGUI_PROGRESS_INDICATOR. This will display progress info on status bar.

Read only

Former Member
0 Likes
956

Micky Oestreich

But I would like the output to be "cumulated" and process indicator don't give me such functionality, I need sth like this ...

> after 1st second output looks like:

This is a 1 line of log.

> after 2nd second output looks like::

This is a 1 line of log.

This is a 2 line of log.

> after 3rd second output looks like:

This is a 1 line of log.

This is a 2 line of log.

This is a 3 line of log.

... ... ...

Read only

kesavadas_thekkillath
Active Contributor
0 Likes
956

its not possible.

But in debugging mode see the list ouput and hit F5.

Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
957

Not sure that this is really user friendly, but you can do an auto-refresh on a list display. Here is an example. Copy this code and run the program. You can see that it will report that the job is running, then show you the log entries as they are added each time. This is just an example program, but this should give you some idea of how you can refresh the display,

REPORT  zrich_0001.

DATA: BEGIN OF itab OCCURS 0,
        item_1(50) ,
      END OF itab .
DATA: line LIKE LINE OF itab .

DATA: ctr_i TYPE i .
DATA: ctr_c(3) .

*---------------------------------------------------------------------*
*       CLASS lcl_event_handler DEFINITION
*---------------------------------------------------------------------*
CLASS lcl_event_handler DEFINITION.

  PUBLIC SECTION.

    CLASS-METHODS: on_finished FOR EVENT finished OF cl_gui_timer.

ENDCLASS.                    "lcl_event_handler DEFINITION

DATA: lo_gui_timer TYPE REF TO cl_gui_timer.
DATA: lv_timeout TYPE i VALUE '3'.

START-OF-SELECTION.

  CREATE OBJECT lo_gui_timer.
  lo_gui_timer->interval = lv_timeout.
  lo_gui_timer->run( ).
  SET HANDLER lcl_event_handler=>on_finished FOR lo_gui_timer.

  ctr_i = 1 .

*  DO 5 TIMES .
*    ctr_c = ctr_i .
*    CLEAR line .
*    CONCATENATE 'This is a' ctr_c 'line of log.'
*    INTO line SEPARATED BY space .
*    ctr_i = ctr_i + 1 .
*    APPEND line TO itab .
*  ENDDO .

  WRITE:/ 'Job Running'.

AT USER-COMMAND.

  sy-lsind = sy-lsind - 1.

  WRITE:/ 'Job Running'.
  LOOP AT itab INTO line .
    WRITE / line-item_1 .
  ENDLOOP .

* Add another line for the next time we write.
  ctr_c = ctr_i .
  CLEAR line .
  CONCATENATE 'This is a' ctr_c 'line of log.'
  INTO line SEPARATED BY space .
  ctr_i = ctr_i + 1 .
  APPEND line TO itab .

*---------------------------------------------------------------------*
*       CLASS lcl_event_handler IMPLEMENTATION
*---------------------------------------------------------------------*
CLASS lcl_event_handler IMPLEMENTATION.

  METHOD on_finished.

* Start Timer again
    lo_gui_timer->interval = lv_timeout.
    lo_gui_timer->run( ).

* cause PAI
    CALL METHOD cl_gui_cfw=>set_new_ok_code
      EXPORTING
        new_code = 'REFR'.

  ENDMETHOD.                    "on_finished

ENDCLASS.                    "lcl_event_handler

Regards,

Rich Heilman

Edited by: Rich Heilman on Jan 21, 2010 8:59 AM

Read only

0 Likes
956

Hi Rich,

That was nice...Keep Rocking.

but all ther records are getting displayed when i hit enter and not one by one

Read only

0 Likes
956

Rich's demo worked for me... here's another example to prove "on-the-fly" writes can work... sorry for format but the 2,500 SDN char limit kills good style!

Jonathan


report zjc_sdn.
types:
begin of gtys_step,
step type sytabix,
start type syuzeit,
end type syuzeit,
text type sytitle,
end of gtys_step,
gtyt_step type table of gtys_step.
data:
gt_step type gtyt_step,
g_stop type sap_bool.
at user-command.perform user_command.
start-of-selection.
perform write_report.
set user-command 'ZREFRESH'."1st time
form user_command.
if g_stop = 'X'. exit.endif.
if sy-ucomm = 'ZREFRESH'.  perform do_next_step.  sy-lsind = sy-lsind - 1.  endif.
endform.
form do_next_step.
data:
  l_progress type sytitle, l_delay type sytabix, l_step_number type sytabix, l_top_line type sytabix, ls_step type gtys_step.
if not gt_step[] is initial.
l_top_line = lines( gt_step[] ).
read table gt_step into ls_step index l_top_line.
l_step_number = ls_step-step.
endif.
add 1 to l_step_number.
get time.
clear: ls_step.  ls_step-step = l_step_number.  ls_step-start = sy-uzeit.
write: l_step_number to ls_step-text left-justified.
case l_step_number.
when 1. ls_step-text = 'Fill@ the kettle'. l_delay = 1.
when 2. ls_step-text = 'Boil@ kettle'. l_delay = 5.
when 3. ls_step-text = 'Pour@ water'. l_delay = 1.
when 4. ls_step-text = 'Mash@ tea'. l_delay = 3.
when 5. ls_step-text = 'Add@ milk'. l_delay = 1.
endcase.
l_progress = ls_step-text.
replace '@' with 'ing' into l_progress.
translate l_progress+0(1) to lower case.
concatenate 'Busy' l_progress '...'
  into l_progress separated by space.
call function 'SAPGUI_PROGRESS_INDICATOR'
  exporting  text = l_progress.
call function 'ENQUE_SLEEP'
  exporting seconds = l_delay.
get time.
ls_step-end = sy-uzeit.
replace '@' with 'ed' into ls_step-text.
append ls_step to gt_step.
perform write_report.
call function 'SAPGUI_SET_FUNCTIONCODE'
exporting functioncode = '=ZREFRESH'
exceptions others= 0.
endform.
form write_report.
data: ls_step type gtys_step.
set pf-status '1000REFR'. "=Std + ZREFRESH (F8)
if not gt_step[] is initial.
loop at gt_step into ls_step.
  write: /  'Step', ls_step-step, ls_step-text, 'Started at:', ls_step-start, 'End at:', ls_step-end, at sy-linsz space.
  if ls_step-step ge 5. g_stop = 'X'. endif.
endloop.
if not g_stop is initial. write: / 'Ended'. endif.
else. write: / 'Started...'. endif.
endform.

Read only

0 Likes
956

great tea jonathan...

Loved it..

Regards,

Sumit