‎2009 Oct 12 10:54 AM
I have a small requirement to execute a piece of code in background.
It is basically a subroutine which calls a BAPI to update the database.
the first idea u thought of was to change the subroutine into a FM and call it in background task.
or, i was wondering if there's any other method which best suits my simple criteria.
any help would be appreciated
‎2009 Oct 12 11:10 AM
Hi Poornima,
Replace the subroutine with a Function Module and call it in background. That is the SIMPLE and BEST option for the requirement. Dont look for alternatives.
Best Regards,
Ram.
‎2009 Oct 12 11:18 AM
Is there any way to debug a FM in background task?
I cant do that from SM37 as this doesn't seem to create a job
‎2009 Oct 12 11:23 AM
‎2009 Oct 12 11:41 AM
Hallo!
Using FM and call it in background task - is the best method for your purpose.
But in some cases is better to use Submit VIA JOB statement.
You can put your subroutine into report and call it like this:
DATA: number TYPE tbtcjob-jobcount,
name TYPE tbtcjob-jobname VALUE 'JOB_TEST',
print_parameters TYPE pri_params.
...
CALL FUNCTION 'JOB_OPEN'
EXPORTING
jobname = name
IMPORTING
jobcount = number
EXCEPTIONS
cant_create_job = 1
invalid_job_data = 2
jobname_missing = 3
OTHERS = 4.
IF sy-subrc = 0.
SUBMIT submitable TO SAP-SPOOL
SPOOL PARAMETERS print_parameters
WITHOUT SPOOL DYNPRO
VIA JOB name NUMBER number
AND RETURN.
IF sy-subrc = 0.
CALL FUNCTION 'JOB_CLOSE'
EXPORTING
jobcount = number
jobname = name
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.
IF sy-subrc <> 0.
...
ENDIF.
ENDIF.
ENDIF.
‎2009 Oct 12 11:48 AM
Alright, i've created a FM now and called in background. I've used a COMMIT WORK right after the FM call. doesnt update still.
i tried using a COMMIT WORK inside the FM as well just in case, doesnt work either. am i missing something?
‎2009 Oct 12 1:00 PM
HI Poornima,
If you can reply to the author who have given the answer then he/she can get back to you soon.
If you are replying to yourself then it will become hard for us to check and reply.
Use commit work as shown
CALL FUNCTION '<NAME Function module>'
EXPORTING
document_data = doc_chng
put_in_outbox = 'X'
commit_work = 'X'
TABLES
packing_list = t_packing_list
Cheers!!
VENk@
‎2009 Oct 12 1:46 PM
Hello,
Is COMMIT_WORK an implicit import paramenter for the FM? Could you please explain this bit more? How does this actually work?
‎2009 Oct 12 12:53 PM
The FM seems to work fine in the foreground. In background task it doesn't execute as i was expecting. how could i debig it?
‎2009 Oct 12 1:00 PM
Use the command JDBG to debug the background job. Hope you are not updating any standard table in the FM