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

background processing

Former Member
0 Likes
1,294

hi gurus,

I want write a code for a program which will run in background.

for example.

if <condition>.

run in back ground.

else.

run in foreground.

endif.

can i use sy-batch and how.

please advice.

thanks in advance.

9 REPLIES 9
Read only

Former Member
0 Likes
1,261

if sy-batch = 'X'

run in back ground.

else.

run in foreground.

endif.

Reward some points

Madhavi

Read only

Former Member
0 Likes
1,261

Hi Abhishek,

You can use sy-batch to run the program in background. Write the code like this.

if sy-batch = 'X'.

run in background.

else.

run in foreground.

endif.

Thanks & Regards

Haritha.

Read only

Former Member
0 Likes
1,261

Hi,

Check the code using sy-batch which u have to use with if condition

FORM download_html_file_on_pc tables YT_DOWNLOAD

using X_OUTFILE type string.

  • Use gui_download if file is located on the local PC.

  • WS_download only works in foreground

IF SY-batch EQ 'X'.

MESSAGE e001(AQ) WITH

'This program cannot be executed in background'.

  • ERROR: Unable to download locally stored files when running in

  • background

ELSE.

CALL FUNCTION 'GUI_DOWNLOAD'

EXPORTING

FILENAME = X_OUTFILE

FILETYPE = 'ASC'

TABLES

DATA_TAB = YT_DOWNLOAD

EXCEPTIONS

FILE_WRITE_ERROR = 1

NO_BATCH = 2

GUI_REFUSE_FILETRANSFER = 3

INVALID_TYPE = 4

NO_AUTHORITY = 5

UNKNOWN_ERROR = 6

HEADER_NOT_ALLOWED = 7

SEPARATOR_NOT_ALLOWED = 8

FILESIZE_NOT_ALLOWED = 9

HEADER_TOO_LONG = 10

DP_ERROR_CREATE = 11

DP_ERROR_SEND = 12

DP_ERROR_WRITE = 13

UNKNOWN_DP_ERROR = 14

ACCESS_DENIED = 15

DP_OUT_OF_MEMORY = 16

DISK_FULL = 17

DP_TIMEOUT = 18

FILE_NOT_FOUND = 19

DATAPROVIDER_EXCEPTION = 20

CONTROL_FLUSH_ERROR = 21

OTHERS = 22.

  • Status of download

CASE SY-subrc.

WHEN 0.

MESSAGE I002(AQ) WITH

'Code converted to HTML and downloaded as ' X_OUTFILE.

WHEN OTHERS.

  • Upload unsuccessful - error message

MESSAGE ID SY-MSGID TYPE 'E' NUMBER SY-MSGNO

WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDCASE.

ENDIF.

ENDFORM. " download_html_file_on_pc

Hope this help u

Reward points if useful

Regards,

Sreenivas

Read only

Former Member
0 Likes
1,261

Hi Abhishek,

Do you want to know how to submit a program in background ?

The SY-BATCH field will tell you if you are already running in background.

Can you clarify your requirement?

Best Regards,

Chester

Read only

0 Likes
1,261

hi,

actually what code i have to write to make a program to run in background.

means i have a simple program.

but i want to make it run in background and foreground both on a particular condition.

Is there any code to make a program to run in background.

so that i can put it inside IF condition.

IF sy-batch = 'X'.

code for background.

ENDIF.

I need code for background.

if u have any question please let me know.

thanks. please advice.

Read only

0 Likes
1,261

Hi Abhisbek,

Try something like this:

IF p_bkgrd IS NOT INITIAL.

  • Program is being run in background...

CALL FUNCTION 'JOB_OPEN'

EXPORTING

jobname = w_name

IMPORTING

jobcount = w_number

EXCEPTIONS

cant_create_job = 1

invalid_job_data = 2

jobname_missing = 3

OTHERS = 4.

SUBMIT program

WITH p_1 EQ p_1

VIA JOB w_name NUMBER w_number

AND RETURN.

CALL FUNCTION 'JOB_CLOSE'

EXPORTING

jobcount = w_number

jobname = w_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.

ELSE

  • Program is being run in foreground

SUBMIT program

WITH p_1 EQ p_1

AND RETURN.

ENDIF.

Regards,

Chester

Read only

0 Likes
1,261

Hi,

Chester's point is accurate, sy-batch is of no use to you here at all, it will only tell you if you are currently running in the background.

All this will do;

IF sy-batch = 'X'.

code for background.

ENDIF.

is perform 'code for background' if your program is already running in the background.

It run a program in the background you can use the SUBMIT statement. Take a look at the ABAP help for this statement, particularly the job_options.

So an example might be;

if counter gt 5000.

submit program (using job_options) and return.

else.

submit program and return.

endif.

Regards,

Nick

Read only

Former Member
0 Likes
1,261

Hi,

You can put what code to run in back ground and what code to run in foreground in the if conditions.

If sy-batch = 'X'.

write the code which u want to run in back ground.

else.

write the code which you want to run in foreground.

endif.

Check the status of the background job in sm30 transaction code.

Thanks & Regards

Haritha.

Read only

Former Member
0 Likes
1,261

Hi,

You have to use as below :

if sy-batch = 'X'.

Run the report in background.

else.

Run the report in foreground.

endif.

Thanks,

Sriram Ponna.