This website is not affiliated with, sponsored by, or approved by SAP AG.

0013 - Macros And Performs

Moderators: Snowy, thx4allthefish, Rich, ilya

0013 - Macros And Performs

Postby Rich » Thu Mar 26, 2009 11:58 am

Real-Time Displays.

There may be occasions where a report is showing real time data (for example the status of a queue). If the operator used the data displayed on the screen, invalid decisions may be made due to the data not being up to date.

This can be alleviated by having a ‘Refresh’ button on the button bar which the operator must remember to press if they require the latest information.

This however places the onus for getting the correct information on the operator.

There is however, a way to provide an ‘Auto-Refresh’ capability within a report, which can be expanded to include other functions.

Primarily, a timer is set running as a totally separate task, even in a different processor. SAP provides the ability to notify the calling program when this Remote Function Call (RFC) completes.

Function Z_WAIT_X_SECS should be written as an RFC capable function which waits a defined number of seconds before it exits. As this is a remote function call, the original program continues rather than waiting for the RFC to complete.

The call to Z_WAIT_X_SECS looks like this:

Code: Select all
Call Function 'Z_WAIT_X_SECS'
     Starting New Task 'IF'                 
   Performing Start_Refresh On End Of Task
    Exporting
       WAIT_TIME = w_pollrate
   Exceptions
       COMMUNICATION_FAILURE = 1 Message w_RFCText
       SYSTEM_FAILURE        = 2 Message w_RFCText
       OTHERS                = 3.


This introduces some new parameters to the ‘Call Function’ statement.

Starting New Task:
This addition starts a new task with the task id specified in quotes. This is a separate remote process to run this function.

Performing …. On End Of Task
This addition signifies that a ‘call back’ is required when the task completes. The routine specified (in this case start_refresh) is called when this routine exits.

Message
Any explanatory text will be placed in this variable if there is an exception.

Once the time limit has been reached, the RFC exits. The calling program is then notified of this and takes appropriate action.

Pushing Keys in ABAP.

Having set up the timer, using the statement :

Code: Select all
Set User-Command ‘RFSH’.


Will cause the button ‘RFSH’ to be pushed. By including this statement in the ‘On End Of Task’ call causes the program to automatically carry out whatever action is specified by the function code.

Taken in a program context you have:

Code: Select all
At User-Command.
   Data w_ucomm like sy-ucomm.
   Move sy-ucomm to w_ucomm.
   Case w_ucomm.
        When 'RFSH'. Perform Get_Data.
        When 'INCS'. Add 1 to g_seconds.
        When 'DECS'. If g_seconds > 1.
                        Subtract 1 from g_seconds.
                     EndIf.
        When 'STOP'. Move True to g_no_refresh.
        When 'STRT'. Move False to g_no_refresh.
        When 'PRCT'. If g_processed = False.
                        Move True to g_processed.
                     Else.
                        Move False to g_processed.
                     EndIf.
        When 'UPCK'. Perform Show_History.
        When 'UHLP'. Perform Prg_Doc_Help.
   Endcase.
   Perform Do_Report.
...
...
...
Form Do_Report.
     Loop at t_repdata.
          if w_prevkey <> <F_Sortfield>.
             Perform GHeader using w_sortfield w_sortdir False.
             Move <F_SortField> to w_prevkey.
          EndIf.
          Perform WriteLine tables t_repdata using Col_Normal.
     EndLoop.
     Perform TableLine.
     Perform WriteCentre using Text-013.
*
*    Make sure that this is the only report displayed....
*
     Move 0 to sy-lsind.
*
*    Do It Again Sam....
*
     if w_poll = True.
        Call Function 'Z_WAIT_X_SECS'
             Starting New Task 'IF'
             Performing Start_Refresh On End Of Task
            Exporting
                WAIT_TIME = w_pollrate
           Exceptions
                COMMUNICATION_FAILURE = 1 Message w_RFCText
                SYSTEM_FAILURE        = 2 Message w_RFCText
                OTHERS                = 3.
     EndIf.
*
* Give the report a kick.
*
Form Start_Refresh using p1.
     Set User-Command 'RFSH'.
EndForm.


Shortly after this was posted, ChristianF sent me this:

Instead of using ENQ_SLEEP or an asynchronous Function call there is a class (>6.10) called cl_gui_timer.

I have created a global class for our 4.6c system to get the same functionality.

The advantage of cl_gui_timer is that it does not occupy resources (like the asynchronous wait or set processes to halt).

To run the report create dynpro 9000 and create a output field g_time.

Code: Select all
REPORT Auto_refresh_demo .

* Demo for a dialog program with auto-refresh
* functionality.

* $1 define a class for the eventhandler
CLASS lcl_eventhandler DEFINITION.
PUBLIC SECTION.
METHODS: on_finished FOR EVENT finished OF z_cl_gui_timer.
ENDCLASS.

* $2 create a variable to hold the instance of
* the time class.
* In rel >6.1 use cl_GUI_TIMER.

DATA: gref_timer TYPE REF TO z_cl_gui_timer,
* §3 create a variable for the instance of the
* eventhandler
gref_eventhandler TYPE REF TO lcl_eventhandler.
DATA: g_time TYPE sy-uzeit,
* §4 create a variable for the number of secs of the refresh
g_secs TYPE i VALUE 3.

DATA: g_okcode TYPE sy-ucomm.

START-OF-SELECTION.
CALL SCREEN '9000'.


* $3 implement the eventhandler.
CLASS lcl_eventhandler IMPLEMENTATION.
METHOD on_finished.
* Force a PAI to refresh the dialog screen
CALL METHOD cl_gui_cfw=>set_new_ok_code
EXPORTING
new_code = 'REFRESH'.
ENDMETHOD.
ENDCLASS.


*&---------------------------------------------------------------------*
*& Module STATUS_9000 OUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE status_9000 OUTPUT.
SET PF-STATUS 'SEW/BC_DEV_AUTO_REFRESH_DEMO'.
SET TITLEBAR 'z_BC_DEV_AUTO_REFRESH_DEMO'.
* set instance and event handler only once.
IF gref_timer IS INITIAL.
CREATE OBJECT gref_timer.
CREATE OBJECT gref_eventhandler.
SET HANDLER gref_eventhandler->on_finished FOR gref_timer.
GET TIME FIELD g_time.

gref_timer->interval = g_secs.
CALL METHOD gref_timer->run.
ENDIF.
gref_timer->interval = g_secs.


ENDMODULE. " STATUS_9000 OUTPUT

*&---------------------------------------------------------------------*
*& Module USER_COMMAND_9000 INPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE user_command_9000 INPUT.
CASE g_okcode.
WHEN 'REFRESH'.
* If pai is triggered make sure that the old timer is stopped such
* that in pbo a new timer will be started.
CALL METHOD gref_timer->cancel.
GET TIME FIELD g_time.

CALL METHOD gref_timer->run.
WHEN 'EXIT' OR 'CANCEL' OR 'BACK'.
LEAVE TO SCREEN 0.
ENDCASE.
CLEAR g_okcode.

ENDMODULE. " USER_COMMAND_9000 INPUT
Regards

Rich

Image
Abap KC:http://www.richard-harper.me.uk/Kb
SFMDR:http://www.se37.com
Rich
 
Posts: 7112
Joined: Thu Oct 31, 2002 4:47 pm
Location: Liverpool

Return to ABAPers

Who is online

Users browsing this forum: No registered users and 2 guests





loading...


This website is not affiliated with, sponsored by, or approved by SAP AG.