FM call in background task

Hi,
I have called a function module in background task. Inside this FM I create application log and put in all the messages in the log which can be viewed using the transaction SLG1. But if the creation of the log fails I want to display the info to the user and exit the FM. I cannot display the info using the Message statement here. I tried to raise an exception, etc. from this FM so that I can process the exception in the calling FM and display a message. But this does not work as the execution of the calling FM and called FM in rfc proceeds simultaneosly. I know I can see the error using transaction sm58 but I am looking for an option wherein I can directly inform the user. Does someone have a suggestion how can proceed with this?
Thanks.
Best Regards,
Pooja

Hi
There are two ways for you to handle,
one manually setting up the job through SM36 which is better and convinient,
secondly through program using FM's JOB_OPEN, SUBMIT, JOB_CLOSE.
Find below steps in doing both:
Procedure 1:
1. Goto Trans -> SM36
2. Define a job with the program and variant if any
3. Click on start condition in application tool bar
4. In the pop-up window, click on Date/Time
5. Below you can see a check box "Periodic Job"
6. Next click on Period Values
7. Select "Other Period"
8. Now give '15' for Minutes
9. Save the job
In SM37 u can check the status of the jobs that u have assigned to background...
Here u mention the job name or the report name to check the status of the job...
After mentioning the job name or program name u just execute it.. ( without any name also u can execute then it gives u all the jobs set by your user name..
the status colud be released,active,finished etc..
Procedure 2 via Program:
Below is a sample code for the same. Note the ZTEMP2 is the program i am scheduling with 15mins frequency.
DATA: P_JOBCNT LIKE TBTCJOB-JOBCOUNT,
      L_RELEASE(1) TYPE c.
   CALL FUNCTION 'JOB_OPEN'
     EXPORTING
       JOBNAME                = 'ZTEMP2'
    IMPORTING
      JOBCOUNT               = P_JOBCNT
    EXCEPTIONS
      CANT_CREATE_JOB        = 1
      INVALID_JOB_DATA       = 2
      JOBNAME_MISSING        = 3
      OTHERS                 = 4.
   IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
        WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
   ENDIF.
   SUBMIT ZTEMP2 VIA JOB 'ZTEMP2' NUMBER P_JOBCNT
          TO SAP-SPOOL WITHOUT SPOOL DYNPRO
          WITH DESTINATION = 'HPMISPRT'
          WITH IMMEDIATELY = SPACE
          WITH KEEP_IN_SPOOL = 'X' AND RETURN.
   CALL FUNCTION 'JOB_CLOSE'
     EXPORTING
       JOBCOUNT                          = P_JOBCNT
       JOBNAME                           = 'ZTEMP2'
       STRTIMMED                         = 'X'
       PRDMINS                          = 15
    IMPORTING
      JOB_WAS_RELEASED                  = L_RELEASE
    EXCEPTIONS
      CANT_START_IMMEDIATE              = 1
      INVALID_STARTDATE                 = 2
      JOBNAME_MISSING                   = 3
      JOB_CLOSE_FAILED                  = 4
      JOB_NOSTEPS                       = 5
      JOB_NOTEX                         = 6
      LOCK_FAILED                       = 7
      INVALID_TARGET                    = 8
      OTHERS                            = 9.
   IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
        WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
   ENDIF.
Hope the above helps you.
Alternately use CALL FUNCTION func IN BACKGROUND TASK
Regards,
Sree

Similar Messages

  • Use of function called "in background task"

    Hi folks!
    In my company there are rumors that a function called "in background task" can be used to make sure that all database changes of previous statements are already persisted. This would mean that a function called "in background task" can be used to read data from database that has been written by the same report - in any case (update dispatching over several instances,...). Usually this won't be a good idea (we know well about SAPs update concepts and read everything about it on help.sap.com). Has anybody some experiences about this or is there even a guru, able to explain why it will always work (or not)? We don't have evidence that the database has finished writing for sure when the function starts - that's why I'm worried.
    Example:
    REPORT test.
    INSERT something to database.
    CALL FUNCTION function in background task.
    End of the report
    Will it always work (when testing, it does)?
    Any help will be appreciated!
    Greetings

    Hi,
    Logically it is correct. BACKGROUND TASK Triggers an asynchronous process. This FM is executed in multiple steps.
    In first step system save the data passed to FM interface to buffer. When ever program encounters Explicit/implicit commit, the source code of the FM is processed.
    Note: You can't get back the data from this FM call.
    Check the F1 help on call function statement. You will get much more details.
    Thanks,
    Vinod.

  • How to capture errors when a Function module is called as BACKGROUND TASK

    How to capture errors when a Function module is called as BACKGROUND TASK?.Please advise.
    FUNCTION ZRPM_DELETE_PROJECT_DATA_API.
    ""Local interface:
    *"  IMPORTING
    *"     VALUE(IV_EXTERNAL_ID) TYPE  RPM_TV_EXTID OPTIONAL
    *"     VALUE(IV_PROJECT_GUID) TYPE  RPM_TV_GUID OPTIONAL
    *"     VALUE(FLAG) TYPE  BOOLEAN OPTIONAL
    *"  EXPORTING
    *"     VALUE(EV_RC) TYPE  I
    *"     VALUE(EV_MSG) TYPE  STRING
    *"     VALUE(ET_MSG) TYPE  RPM_TT_MESSAGES
      IF flag = cl_rpm_co=>sc_true.
        Call function 'RPM_DELETE_PROJECT_DATA' IN BACKGROUND TASK
          EXPORTING
            IV_EXTERNAL_ID  = IV_EXTERNAL_ID
            IV_PROJECT_GUID = IV_PROJECT_GUID
          IMPORTING
            EV_RC           = EV_RC
            EV_MSG          = EV_RC
            ET_MSG          = ET_MSG.
        COMMIT WORK.
      ELSE.
        CALL FUNCTION 'RPM_DELETE_PROJECT_DATA'
          EXPORTING
            IV_EXTERNAL_ID  = IV_EXTERNAL_ID
            IV_PROJECT_GUID = IV_PROJECT_GUID
          IMPORTING
            EV_RC           = EV_RC
            EV_MSG          = EV_MSG
            ET_MSG          = ET_MSG.
      ENDIF.
    ENDFUNCTION.
    In above code how to capture 'EV_RC' when FM is called as background task.

    Prakash,
    CALL FUNCTION IN BACKGROUND TASK allows no IMPORTING parameters, so that your code will produce a syntax error.
    The calling program can only handle errors of remote function calls (RFC) if these are either
    - synchronous RFC  (that is CALL FUNCTION ... DESTINATION ...) or
    - asynchronous RFC (that is CALL FUNCTION STARTING NEW TASK ... DESTINATION ...).
    Both synchronous and asynchronous RFC allow the capturing of errors by means of exceptions. But that is a different topic.

  • BAPI CALL IN BACKGROUND TASK

    Hi,
    We have a sales order workflow for exceptional demand.
    In one of the steps of the workflow,the corresponding task executes in background.
    Sales Order Change BAPI is called within this task.
    Now the problem is that in case the sales order is locked for execution by some other user, the BAPI call returns a message of type 'E'.
    Currently we send a mail to the concerned people to indicate that the sales order change has failed. However the users are concerned, since there is no immediate feeback on the errors.
    Is there any way that the user's can be informed instantly that an error has occured and also a retry option so that the BAPI call can be reexecuted at a later time.
    Regards,
    Jitender

    You can do this in two ways
    1. Put the BAPI call after a WHILE loop, that always checks for SY-SUBRC and within it you call the FM to lock the order
    OR
    2. Do this in workflow by using the return message type E to start the same task with some delay, say 30 mins or so...
    Good Luck
    Ravi

  • Function called IN BACKGROUND TASK goes to work process DIA, not BGD

    I'm calling a function IN BACKGROUND TASK
    In SM50, I see it running in a DIA work process.
    I want it to run in a BGD work process.
    Can this be done?  If so, how?  If not, why not?

    Hi...
    It looks like, it will always run in DIA process and not Background process...I am not sure that we can change the work process
    Check the below link..
    http://help.sap.com/saphelp_40b/helpdata/pt/69/c24f864ba111d189750000e8322d00/content.htm
    What is written in the link is...
    "Background updates (CALL FUNCTION IN BACKGROUND TASK) represent a variant of remote function call that is synchronous with the end of a transaction (COMMIT WORK). In background updating, an update is run in another dialog work process that may be in the same or in another application server and R/3 System. Because such updates run in their own LUWs, they may start only after all critical updates have been completed. Otherwise, it would not be possible to roll back background changes in the event of an error in another update component. "
    IF you get the answer of whether we can change the work process then please let us know...

  • Function Module MASTER_IDOC_DISTRIBUTE to be called in background task?

    Hi,
    We are generating outbound Idocs in a report. In this report we are using Function Module Master_Idoc_Distribute. Now we have faced some performance issues and the basis consultant is asking us to:
    Call the function module using CALL FUNCTION Master_Idoc_Distribute IN BACKGROUND TASK.
    1) How will calling the FM Master_IDOC_Distribute in background task help improve the performance?
    2) By calling the function module in background task, will it have any impact on the sequencing of the idocs? If yes what is the way out, as the idoc sequence is very important.
    Thanks in advance,
    Mick

    1) How will calling the FM Master_IDOC_Distribute in background task help improve the performance?
    ->Calling the FM in background task will help in performance as it will be called in the background process mode like a tRFC.So it will not occupy any dialog process which are limited.
    2) By calling the function module in background task, will it have any impact on the sequencing of the idocs? If yes what is the way out, as the idoc sequence is very important.
    ->It will not have any impact on IDoc sequence.

  • How can I see if a function has been called in background task?

    I tried to see sy-batch, but it doesn't work.
    thanks
    Gabriele

    Try calling function module ID_OF_BACKGROUNDTASK.
    DATA: lv_tid type ARFCTID.
    CALL FUNCTION 'ID_OF_BACKGROUNDTASK'
       IMPORTING
         tid = lv_tid.
    IF lv_tid IS NOT INITIAL.
    * This was called with CALL FUNCTION ... IN BACKGRUND TASK.
    ELSE.
    ENDIF.

  • What is the use of CALL FUNCTION MODULE - AT BACKGROUND TASK?

    Hi experts,
    I found Call functional module in background task will make the FM run at the next commit work as some people said. So I have some questions:
    1 if we use COMMIT WORK commend, the pending FM will be called? If there are several FMs called at background task, what is the sequence of them? How many conditions will trigger the running of these FMs?
    2 Where can I find the log of this pending FMs? In SAP library, it says there are 2 tables. But I checked these tables and can only find the FM name and user of it. And I can not understand content of these tables. It seems one is for the main information of FM, and the other is for the data of the FM, maybe the parameters.
    3 If I call a FM in this way, Can I canncel it before the next commit work in some way?
    Finally, thanks for reading and help.

    HI,
    When the COMMIT WORK statement is executed, the function modules registered for the current SAP-LUW are started in the order in which they were registered. ROLLBACK WORK deletes all previous registrations for the current SAP-LUW.
    If the specified destination is not available when COMMIT WORK is executed, an executable program called RSARFCSE is started in background processing. By default, this tries to start the function modules registered for a SAP-LUW in their destination every 15 minutes and up to 30 times. These parameters can be changed in the transaction SM59. If the destination does not become available within the defined time, it is recorded in the database table ARFCSDATA as the entry "CPICERR". The entry in the database table ARFCSSTATE is deleted after a standard period of eight days

  • Call FM remotely in Background task

    Hello,
    I need some help regarding calling function modules through RFC call in background task in 4.6C.
    We are calling some standard FMs in our Z program to perform some actions in a remotely called system and based on the return value from the RFC call we are deciding further processing steps in our program. The Z program takes lot of execution time (due to huge data) and hence is executed in background and when the RFC call is made to the standard FM, the FM also is taking long execution time. Because of the long execution time in the remote system (which also is 4.6C SAP system), a TIME_OUT dump is occuring and due to this  the original job (Zprogram) also gets cancelled.
    As a solution we are trying to implement the RFC call as a background task, so that both the zprogram and the RFC call happen in background and get executed successfully.
    But, while calling the RFC FM in background it is not allowing us to fetch any return values (which is in accordance with the standard SAP behaviour). For us to proceed further in our program we need the return value and hence want an idea to approach this issue.
    Please suggest any means to solve this problem.
    Many thanks,
    Chaithanya.

    Hi Ganesh,
    Thanks for the reply.
    We already have an alternate solution to adjust the design of the Z program but we want to try out any possible solutions from SAP standard (any flag to be set or any settings to be done) instead of changing the design of our Z program.
    We would be really glad to have such a solution as the design change would take a lot of effort and is similar to developing a new program.
    Regards,
    Chaithanya.

  • Calling function module in background task

    Hello,
    There is one function module which is called in background task. Is there any chance that background task is not created and function module is not executed. That function module is supposed to send some outbound message. The FM is called in one user exit. I don't have any idea as why it is called as background task. The probem is that this message is not getting send sometimes.(sometimes it gets send ). Because of this I am not able to make any conclusion.
    Please respond if anyone has come across such scenario before.
    Thanks in advance,
    Minal

    Check the below link...it might be helpfull
    It should be executed....check it with different data as to what might fail
    http://help.sap.com/saphelp_nw04/helpdata/EN/8f/53b67ad30be445b0ccc968d69bc6ff/content.htm
    http://help.sap.com/abapdocu/en/ABAPCALL_FUNCTION_BACKGROUND_TASK.htm

  • Calling function modules in background task

    Hi All,
    I am creating a notification in the background and linking it to an order. This I am doing inside a function module which is called in background task as a separate unit. I should change the user status of this newly created notification. This I am doing in another FM called as a separate unit. Now my requirement is that, I need to perform the status change only after the new notification is committed to the database. I would like to know if i can provide some time lag between the 2 FM execution. Can anyone tell me how much time will be consumed to commit the data to the database tables irrespective of the length of the data. Say for example, if i have hundreds of notifications within the object list tab of an order, I want to know what is the maximum time it will take to commit this to the database table so that I can put a wait conditionat the stat of the second FM call.
    Thanks

    Ok thanks. But let me tell you 1 thing, actually I am calling these 2 FMs within an enhancement section just before another FM CO_ZV_ORDER_POST which is actually doing a commit work. So is it OK if I call the 1st FM in background task and the second FM in update task in the same place as I am calling the FMs now(i.e., before CO_ZV_ORDER_POST)?

  • How to see the status of a FM IN BACKGROUND TASK?

    Hi experts,
    If I call a FM IN BACKGROUND TASK addition. I can't Debug the FM called in BACKGROUND TASK. Then whether there is a way to see the status of this FM IN BACKGROUND TASK? I want to know this task is finish or not.
    Thanks.

    Hi Kelvin,
    I am also facing similar problem. I have come across few documents which have suggeted the way to test the FM in background. For this you will have to change the debugging settings, its in the  Settings->Display and change all. Check the oprion for In background task.
    A good document on settings of debugging.
    http://www.sappro.com/downloads/Settings&SystemAreas.pdf
    Regards,
    Sana.

  • Qs about call FM in background task, and monitoring in SM37.

    Hi, guys, i got a question here, if I call a FM using addition "in background task" in a Z program, does this mean the FM process is running in background? And can I monitor my task in sm37?
    i've tried to do that, the FM was successfully proceeded, but I cannot see anything related to that task in SM37 under mine user ID.

    No, you cannot see that in SM37.
    What it means is that the function is being executed in a seprated thread and the program that called the function will continue the execution without waiting for the function finish execution, that means the function is called in a synchronous manner.
    Regards,
    Ravi
    Note : Please mark all the helpful answers

  • Windows 8.1 background task Javascript - Call angular controller function from task js

    Hi,
    The Ionic Side menu starter template for windows 8.1 is a very good option to run the ionic apps on Windows  8.1 phones.
    I am not sure whether this is related to Ionic/angular or VS2013 CTP 3.1 but if anyone can give some tips ,that would be great. I registered a background task as per the VS tutorial (Run JS task in background) and i tested it with windows toast notifications.However
    my requirement is to access webservice in background which I am not able to implement.
    The setup for background task is path to the js file but my requirement is to call a function defined within a controller.Is there any way i can access the controller function from an outside js file.I am new to Ionic,Angular and VS 2013.Any help would be great
    The structure of background task js file is as below
    (function() {
       --- I need to call my controller/service  function here---
        var notifications = Windows.UI.Notifications;
        var template = notifications.ToastTemplateType.toastImageAndText01;
        var toastXml = notifications.ToastNotificationManager.getTemplateContent(template);
        var toast = new notifications.ToastNotification(toastXml);
        var toastTextElements = toastXml.getElementsByTagName("text");
        toastTextElements[0].appendChild(toastXml.createTextNode("From Background!"));
        var toastNotifier = notifications.ToastNotificationManager.createToastNotifier();
        toastNotifier.show(toast);
        close();
     

    Are there any updates on this issue? I'm currently seeing this on a Lumia 822 with WP8.1, and the app has never been published to the store. I've only ever deployed the app from Visual Studio to my device. It worked when deploying the Debug build, then I
    tried a Release build, and it crashed immediately upon launch when trying to register the background task, but then I was able to go back to deploying/debugging the Debug build on the device for awhile. I made more changes, and now neither Debug nor Release
    builds work--both fail on the BackgroundTaskBuilder.Register() call with the error described in the original question:
    "The drive cannot locate a specific area or track on the disk. (Exception from HRESULT: 0x80070019)"
    I've tried changing the Task name during registration, rev-ing the version number of the application, adding the call to BackgroundExecutionManager.RemoveAccess() before BackgroundExecutionManager.RequestAccessAsync(), changing the name of the IBackgroundTask
    concrete implementation and changing the corresponding EntryPoint in the package.appxmanifest (as well as in the BackgroundTaskBuilder instance), and changing the package DisplayName to a new reserved name, all to no avail. The only thing I didn't try
    was associating with an entirely new app in the app store or paving my phone, as these are both fairly undesirable "workarounds."
    Even if this won't affect clients downloading the app from the store, this is a major roadblock during development, as we can essentially only use the emulator to test an app specifically designed to help solve problems involving moving around physically
    in the real world.
    Any more information would be greatly appreciated. If there's any information I can provide, please let me know.

  • Creation of spool for job created by calling FM in background task

    Hi Gurus,
    1.Wanted to confirm if it is possible to attach spool to the job that has been created by calling a function module in background task.
    Currently I have created one RFC enabled FM and called it in background task. It runs fine, and the job is created which can be seen in SM37. But it does not contain the spool even if the RFC FM contains the code for list ALV.
    2. Also is it possible to control the name of the job created by calling the RFC FM in background task?
    Code for calling the FM is given below(ZK_XX is th RFC FM):
    CALL FUNCTION 'ZK_XX' IN BACKGROUND TASK
    CALL FUNCTION 'START_OF_BACKGROUNDTASK'
    EXPORTING
       startdate       = sy-datum
       starttime       = sy-uzeit
      NOSEND          = ' '
    COMMIT WORK.
    Thanks a lot for your help!!
    Warm Regards,
    Raveesh

    Thanks for replying.
    I need to do the processing in background. Hence using 'IN BACKGROUND TASK' addition.
    Please let me knowif you have some idea.
    Thanks & Warm Regards,
    Raveesh

Maybe you are looking for