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

How to call a function in (CALL FUNCTION ..) in background - syntax

Former Member
0 Likes
696

Hi - ,

Can we call a function in background. If so, what is the syntax for it.

I need to call a function in backgorund with return parameter as timeout variable & do further processing.

Any updates will be highly helpful.

Thanks,

Gyanaraj

3 REPLIES 3
Read only

jayesh_gupta
Active Participant
0 Likes
536

Hi,

You may create a separate report program and call your function module in that report normally.

Then call this report program in your program by submitting it as a background job.

Regards,

Jayesh

Read only

jayesh_gupta
Active Participant
0 Likes
536

You may use the following code in your report to submit the new report rpt_call_func(containing the function module)

DATA: global_job        LIKE tbtcjob.
  DATA: global_start_date LIKE tbtcstrt.
  DATA: global_step_tbl   LIKE tbtcstep OCCURS 0 WITH HEADER LINE.

  DATA: ls_jobs_of_step TYPE ty_bpxminfo.

  global_job-jobname        = 'MYJOBFOR_CALL_FUNC'.
  global_job-jobclass       = 'B'.
  global_job-newflag        = 'O'.
  global_step_tbl-program   = 'RSBTCPT3'.    "dummy step
  global_step_tbl-typ       = 'A'.
  global_step_tbl-status    = 'P'.     "scheduled
  global_step_tbl-authcknam = sy-uname.
  APPEND global_step_tbl.

  CALL FUNCTION 'BP_JOB_CREATE'
       EXPORTING
            job_cr_dialog   = 'N'
            job_cr_head_inp = global_job
       IMPORTING
            job_cr_head_out = global_job
            job_cr_stdt_out = global_start_date
       TABLES
            job_cr_steplist = global_step_tbl.

  SUBMIT rpt_call_func AND RETURN
          USER sy-uname
          VIA JOB global_job-jobname NUMBER global_job-jobcount
          WITH p_func_param1 = gv_var1
          WITH p_func_param2 = gv_var2
          WITH p_func_param3 = gv_var3
          WITH p_func_param4 = gv_var4.


  
  CALL FUNCTION 'JOB_CLOSE'
       EXPORTING
            jobcount             = global_job-jobcount
            jobname              = global_job-jobname
            strtimmed            = 'X'
       EXCEPTIONS
            cant_start_immediate = 1
            invalid_startdate    = 2
            jobname_missing      = 3
            job_close_failed     = 4
            job_nosteps          = 5
            job_notex            = 6
            lock_failed          = 7
            OTHERS               = 8.

Read only

jayesh_gupta
Active Participant
0 Likes
536

Hi,

If your function module is RFC enabled, you can call the function module in background by using IN BACKGROUND TASK as follows:

CALL FUNCTION <function module name> IN BACKGROUND TASK [DESTINATION]

EXPORTING....

EMPORTING....

TABLES.....

EXCEPTIONS....

Regards,

Jayesh