‎2019 May 01 9:29 AM
I have a mass upload program . I want to run the program in background even though the user tries to run it in foreground.
My basic requirement is that I don't want the program to run in foreground in any way.It should be triggered it background job only. I tried modifying the code and added open job and close job FMs but it is not working.
Also , I don't want any dialog processes in between , the program should work the ways it works but in background always.
Can anyone please help?
‎2019 May 01 10:56 AM
You can use SUBMIT (with batch option) to call the own program. By the time the program is running in background, you're able to manipulate statements by using sy-batch system variable. Just like that:
IF sy-batch = ' ' .
CALL FUNCTION 'JOB_OPEN'
EXPORTING
jobname = jobname
IMPORTING
jobcount = jobcount .
SUBMIT <program> WITH <param1> = <im_param1>
WITH <param2> = <im_param2>
.. and so on ..
VIA job jobname number jobcount
USER <user name>
AND return .
* Schedule and close job.
CALL FUNCTION 'JOB_CLOSE'
EXPORTING
jobcount = jobcount
jobname = jobname
sdlstrtdt = sy-datum
sdlstrttm = sy-uzeit .
ELSEIF sy-batch = 'X' .
* place the program logic here ...
ENDIF .
Check SM37 for the job results. The result itself is stored in the spool.
KR,
Arthur Silva
‎2019 May 01 9:38 AM
Define a job using SM36 of that program. - to run in background at defined time
‎2019 May 01 10:18 AM
The requirement is not to schedule the job but to run the program in background through code when any user runs it in foreground.
‎2019 May 01 10:20 AM
Okay, then use SUBMIT option. (using batch option).
or
try your background code using function - as
CALL FUNCTION...IN BACKGROUND TASK | UPDATE TASK | and STARTING NEW TASK.
‎2019 May 01 10:49 AM
For submit or FM, I need to create a different program or FM with all logic but I want to use the same program.Is it possible using same program?
‎2019 May 01 10:54 AM
Yes, I believe you have to have two codes..
If yu can explain me clearly, why you want to execute the same prgram twice as forground and background as well, then we can have a better solution.
‎2019 May 01 11:04 AM
The requirement is to always run that program in background .
It should be scheduled in background only even if the user runs it in the foreground .
‎2019 May 01 3:16 PM
Please use the COMMENT button if you ask for more details. ANSWER is only to propose a solution. Try to think to future visitors who will have to filter between true and false answers.
‎2019 May 01 10:56 AM
You can use SUBMIT (with batch option) to call the own program. By the time the program is running in background, you're able to manipulate statements by using sy-batch system variable. Just like that:
IF sy-batch = ' ' .
CALL FUNCTION 'JOB_OPEN'
EXPORTING
jobname = jobname
IMPORTING
jobcount = jobcount .
SUBMIT <program> WITH <param1> = <im_param1>
WITH <param2> = <im_param2>
.. and so on ..
VIA job jobname number jobcount
USER <user name>
AND return .
* Schedule and close job.
CALL FUNCTION 'JOB_CLOSE'
EXPORTING
jobcount = jobcount
jobname = jobname
sdlstrtdt = sy-datum
sdlstrttm = sy-uzeit .
ELSEIF sy-batch = 'X' .
* place the program logic here ...
ENDIF .
Check SM37 for the job results. The result itself is stored in the spool.
KR,
Arthur Silva
‎2019 May 01 11:11 AM
I will try doing this.Will come back to you in case of queries 🙂
‎2019 May 01 6:19 PM
IF sy-batch EQ abap_false.
MESSAGE 'Nope. Only run this program in background' TYPE 'E'.
ENDIF.
‎2019 May 01 7:01 PM
if sy-batch = abap_false! and message TYPE 'E' only in the PAI and I would do it only for (sscrfields-)ucomm = 'ONLI'
‎2019 May 02 6:42 AM