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 make a program run in background programatically even though the user runs it in foreground.

0 Likes
11,206

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?

1 ACCEPTED SOLUTION
Read only

arthursilva
Active Participant
9,216

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

12 REPLIES 12
Read only

venkateswaran_k
Active Contributor
0 Likes
9,216

Define a job using SM36 of that program. - to run in background at defined time

Read only

0 Likes
9,216

The requirement is not to schedule the job but to run the program in background through code when any user runs it in foreground.

Read only

venkateswaran_k
Active Contributor
0 Likes
9,216

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.

Read only

0 Likes
9,216

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?

Read only

venkateswaran_k
Active Contributor
0 Likes
9,216

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.

Read only

0 Likes
9,216

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 .

Read only

0 Likes
9,216

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.

Read only

arthursilva
Active Participant
9,217

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

Read only

9,216

I will try doing this.Will come back to you in case of queries 🙂

Read only

matt
Active Contributor
9,216
IF sy-batch EQ abap_false.
  MESSAGE 'Nope. Only run this program in background' TYPE 'E'.
ENDIF.
Read only

Sandra_Rossi
Active Contributor
9,216

if sy-batch = abap_false! and message TYPE 'E' only in the PAI and I would do it only for (sscrfields-)ucomm = 'ONLI'

Read only

matt
Active Contributor
0 Likes
9,216

Oops. Fixed now.