Registration

Dear SAP Community Member,
In order to fully benefit from what the SAP Community has to offer, please register at:
http://scn.sap.com
Thank you,
The SAP Community team.
Skip to end of metadata
Go to start of metadata

Author: Holger Pakirnus

Submitted:  2008-06-20

Simple example of asynchronous RFC used here to refresh a list automatically 

Do NOT forget to mark the Function as RFC enabled (FM attributes). 

Error rendering macro 'code': Invalid value specified for parameter 'lang'
 REPORT  zdgf_hp_test_710 NO STANDARD PAGE HEADING.
* DEMO asynchronous RFC I
*      self refreshing list
*      define FUNCTION at the and seperately - check REMOTE at attrib.
* GLOBAL DATA      *****************************************************
 DATA: max_tasks TYPE i.
 DATA: free_tasks TYPE i.
 DATA: gl_done TYPE xfeld.
* SELECTION-SCREEN (PARAMETERS/SELECT OPTIONS) *************************
 PARAMETERS: time TYPE i DEFAULT 1.
************************************************************************
 INITIALIZATION.
 START-OF-SELECTION.
   PERFORM rfc_info_get.
 END-OF-SELECTION.
   SET PF-STATUS 'MAIN'. "define own including FCODE 'REFR'
   PERFORM write_list.
   PERFORM auto_refresh.
 AT USER-COMMAND.
   CHECK sy-ucomm = 'REFR'.
*   SET PF-STATUS 'MAIN' EXCLUDING 'REFR'.
   sy-lsind = 0.
   PERFORM rfc_info_get.
   PERFORM write_list.
   PERFORM auto_refresh.
************************************************************************
*&--------------------------------------------------------------------*
*&      Form  auto_refresh
*&--------------------------------------------------------------------*
 FORM auto_refresh.
   CLEAR gl_done.
   CALL FUNCTION 'Z_DGF_WAIT_N'
     STARTING NEW TASK 'TIM'
     DESTINATION 'WORKFLOW_LOCAL_010'
     PERFORMING handler ON END OF TASK
     EXPORTING
       i_waittime            = time
     EXCEPTIONS
       communication_failure = 1.
   IF sy-subrc NE 0.
     EXIT.
   ENDIF.
*    WAIT UNTIL NOT gl_done IS INITIAL.
 ENDFORM.                               " AUTO_REFRESH

*&--------------------------------------------------------------------*
*&      Form  handler
*&--------------------------------------------------------------------*
 FORM handler USING    value(p_taskname).
   RECEIVE RESULTS FROM FUNCTION 'Z_DGF_WAIT_N'
       IMPORTING  e_done = gl_done
       EXCEPTIONS
          communication_failure = 1     "MESSAGE msg
          system_failure        = 2.    "MESSAGE msg.
   IF sy-subrc NE 0.
     LEAVE PROGRAM.
   ENDIF.
   CHECK gl_done EQ 'X'.
   SET USER-COMMAND 'REFR'.
 ENDFORM.                               " HANDLER
*&---------------------------------------------------------------------*
*&      Form  rfc_info_get
*&---------------------------------------------------------------------*
 FORM rfc_info_get .
   CALL FUNCTION 'SPBT_INITIALIZE'
* EXPORTING
*   GROUP_NAME                           = ' '
    IMPORTING
      max_pbt_wps                          = max_tasks
      free_pbt_wps                         = free_tasks
    EXCEPTIONS
      invalid_group_name                   = 1
      internal_error                       = 2
      pbt_env_already_initialized          = 3
      currently_no_resources_avail         = 4
      no_pbt_resources_found               = 5
      cant_init_different_pbt_groups       = 6
      OTHERS                               = 7.
   CASE sy-subrc.
     WHEN 0. "ok
     WHEN 3.
       CALL FUNCTION 'SPBT_GET_CURR_RESOURCE_INFO'
         IMPORTING
           max_pbt_wps                 = max_tasks
           free_pbt_wps                = free_tasks
         EXCEPTIONS
           internal_error              = 1
           pbt_env_not_initialized_yet = 2
           OTHERS                      = 3.
       IF sy-subrc <> 0.
         MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
                 WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
       ENDIF.
     WHEN OTHERS.
       MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
               WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
   ENDCASE.
 ENDFORM.                    " rfc_info_get
*&---------------------------------------------------------------------*
*&      Form  write_list
*&---------------------------------------------------------------------*
 FORM write_list .
   WRITE:  'max. tasks:', max_tasks  LEFT-JUSTIFIED.
   WRITE: /'avl. tasks:', free_tasks LEFT-JUSTIFIED.
   WRITE: /'time      :', sy-uzeit.
 ENDFORM.                    " write_list
*FUNCTION z_dgf_wait_n.
**"---------------------------------
**-------------------------------------
**"*"Lokale Schnittstelle:
**"  IMPORTING
**"     VALUE(I_WAITTIME) TYPE  I DEFAULT 10
**"  EXPORTING
**"     VALUE(E_DONE) TYPE  BOOLEAN
**"---------------------------------
**-------------------------------------
*  TABLES indx.
*  IF i_waittime GE 3600.                                    "1h
*    i_waittime = 1.
*  ENDIF.
*  IF i_waittime LE 1.
*    i_waittime = 1.
*  ENDIF.
*
*  WAIT UP TO i_waittime SECONDS.
*  e_done = 'X'.
*
*ENDFUNCTION.