Application Development 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: 

JOB_CLOSE and Background Job Process a FM

Former Member
0 Kudos

HI Guys,

I have my code like this:

data: jobname like tbtcjob-jobname value

'TESTJOB'.

data: jobcount like tbtcjob-jobcount,

host like msxxlist-host.

data: begin of starttime.

include structure tbtcstrt.

data: end of starttime.

data: starttimeimmediate like btch0000-char1.

  • Job open

call function 'JOB_OPEN'

exporting

delanfrep = ' '

jobgroup = ' '

jobname = jobname

sdlstrtdt = sy-datum

sdlstrttm = sy-uzeit

importing

jobcount = jobcount

exceptions

cant_create_job = 01

invalid_job_data = 02

jobname_missing = 03.

if sy-subrc ne 0.

"error processing

endif.

data: lv_weekday type WEEK_DAY.

CALL FUNCTION 'DATE_TO_DAY'

EXPORTING

DATE = sy-datum

IMPORTING

WEEKDAY = lv_weekday.

  • Close job

starttime-sdlstrtdt = sy-datum.

starttime-sdlstrttm = SY-UZEIT.

call function 'JOB_CLOSE'

exporting

event_id = starttime-eventid

event_param = starttime-eventparm

event_periodic = starttime-periodic

jobcount = jobcount

jobname = jobname

laststrtdt = starttime-laststrtdt

laststrttm = starttime-laststrttm

prddays = 1

prdhours = 0

prdmins = 0

prdmonths = 0

prdweeks = 0

sdlstrtdt = starttime-sdlstrtdt

sdlstrttm = starttime-sdlstrttm

strtimmed = 'X' "starttimeimmediate

  • targetsystem = host

exceptions

cant_start_immediate = 01

invalid_startdate = 02

jobname_missing = 03

job_close_failed = 04

job_nosteps = 05

job_notex = 06

lock_failed = 07

others = 99.

if sy-subrc eq 0.

"error processing

endif.

This is the Program I want the Batch Job to Execute a BAPI Function Module in the Place of DATE_TO_DAY function module. Is it Possible ??????

And also I get an error at the JOB_CLOSE Function Module with SY-SUBRC = 5.

Can anyone know why this is happening and what should be done to overcome this.

Thanks & Regards,

YJR.

1 ACCEPTED SOLUTION

former_member181962
Active Contributor
0 Kudos

Hi YJR,

YOu use JOB_OPEN/JOB_SUBMIT/JOB_CLOSE function modules if you have to prcessa job that has been already created in sm35.

I did not understand what are you trying to do here.

I assume the you need to create a job using a se38 program which calls the BAPI and run it in background.

Then you get the job count number which you can pass to the JOB_OPEN/JOB_SUBMIT/JOB_CLOSE function modules.

If your aim is to run a FM in background, the you can use the syntax:

<b>CALL FUNCTION func IN BACKGROUND TASK.</b>

Regards,

Ravi

13 REPLIES 13

Former Member
0 Kudos

I don't think a FM can be executed separately as a part of the background job and more over you have not made it as a part of the job.

What you can do is to write this FM as a part of the report program and then SUBMIT the program along with JOBCOUNT which is one of the parameters of the SUBMIT statement. Only then it will be scheduled in the background.

SUBMIT report VIA JOB job NUMBER n

Regards,

Ravi

Note : Please mark all the helpful answers

Message was edited by: Ravikumar Allampallam

former_member181962
Active Contributor
0 Kudos

Hi YJR,

YOu use JOB_OPEN/JOB_SUBMIT/JOB_CLOSE function modules if you have to prcessa job that has been already created in sm35.

I did not understand what are you trying to do here.

I assume the you need to create a job using a se38 program which calls the BAPI and run it in background.

Then you get the job count number which you can pass to the JOB_OPEN/JOB_SUBMIT/JOB_CLOSE function modules.

If your aim is to run a FM in background, the you can use the syntax:

<b>CALL FUNCTION func IN BACKGROUND TASK.</b>

Regards,

Ravi

Former Member
0 Kudos

HI yjr,

1. And also I get an error at the JOB_CLOSE Function Module with SY-SUBRC = 5.

Thats bcos we have not specified

any steps.

(ie. we have not used JOB_SUBMIT

or submit statement

for background purpose program)

2.

This is the Program I want the Batch Job to Execute a BAPI Function Module in the Place of DATE_TO_DAY function module. Is it Possible ??????

Directly calling FM in background,

is not possible.

3. U will have to create a

NEW Z Program,

and call that BAPI in this Z program.

4. Create a new variant for this z program.

5. and using FM JOB_SUBMIT,

mention the name of this program,

and variant.

regards,

amit m.

0 Kudos

Hi Guys,

Thanks for your Inputs. I have created a Z Program which I am calling after the Job is created using JOB_OPEN using SUBMIT ...... AND RETURN VIA JOBNAME ....

Here in this Program I am performing and IMPORT commands to import variable which have been EXPORT in another Program and a CALL TRANSACTION 'XXXX' to which I am passing these IMPORT Values.

But somehow this Program works fine and values get updated with the CALL TRANSACTION but not when Executed in Background.

Now My Questions are:

1) Will IMPORT command work when we execute a Program in Background.

2) What should be the Mode for CALL TRANSACTION 'XXXX' when we execute the Program in Background which has this CALL TRANSACTION.....

Thanks & Regards,

YJR.

0 Kudos

Hi,

1) Will IMPORT command work when we execute a Program in Background.

No reason why it should not work.

2) What should be the Mode for CALL TRANSACTION 'XXXX' when we execute the Program in Background which has this CALL TRANSACTION.....

Ideally the Mode should not matter, the CALL Transaction program can work in the background and import also should be successfull.

Are you able to execute this successfully in the foreground? Did you debug and see if you are getting the expected values?

Regards,

Ravi

0 Kudos

Hi,

It works fine in Foreground and I am able to Debug it and see the Flow.

But when I do it from the JOB_OPEN I don't have the chance of seeing the Flow. Is there any way for seeing it by any chance.... If I can see the flow of the Program in JOB then I think we can Cract it.

Thanks & Regards,

YJR

0 Kudos

There is a way to debug the background job. See this thread ... you will get some pointers.

Regards,

Ravi

0 Kudos

Hi Ravi,

The below code which has an EXPORT and IMPORT commands

The IMPORT does'nt work in Background.

Do I need to do anything else.

REPORT ZTEST_LM22.

DATA: LV_NAME(10) TYPE C.

LV_NAME = 'HELLO'.

export lv_name to memory id 'ZNAM'.

submit ztest_lm22_a.

*********************************************************

REPORT ZTEST_LM22_A.

DATA: GV_JOBNAME TYPE BTCJOB VALUE 'TEST_UNPACK',

GV_JOBCOUNT TYPE BTCJOBCNT.

data: lv_date type SYDATUM,

lv_time type SYUZEIT.

lv_date = SY-datum.

lv_time = sy-uzeit.

CALL FUNCTION 'JOB_OPEN'

EXPORTING

JOBNAME = GV_JOBNAME

SDLSTRTDT = lv_date

SDLSTRTTM = lv_time

IMPORTING

JOBCOUNT = GV_JOBCOUNT

EXCEPTIONS

CANT_CREATE_JOB = 1

INVALID_JOB_DATA = 2

JOBNAME_MISSING = 3

OTHERS = 4.

IF SY-SUBRC <> 0.

MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

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

ENDIF.

SUBMIT ztest_lm22_b AND RETURN

VIA JOB GV_JOBNAME

NUMBER GV_JOBCOUNT.

CALL FUNCTION 'JOB_CLOSE'

EXPORTING

JOBCOUNT = GV_JOBCOUNT

JOBNAME = GV_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

INVALID_TARGET = 8

OTHERS = 9.

IF SY-SUBRC <> 0.

MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

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

ENDIF.

*********************************************************

REPORT ZTEST_LM22_B.

DATA: LV_NAME(10) TYPE C,

GV_NAME(10) TYPE C.

IMPORT LV_NAME = GV_NAME FROM MEMORY ID 'ZNAM'.

WRITE: GV_NAME.

*********************************************************

If you see in SM37 the Spool does'nt have this value.

Could you just run a quick test and see what else should be done...

Thanks & Regards,

YJR.

0 Kudos

I just tried and you are right, for some weird reason, its not working.

I will try and let you know.

Regards,

Ravi

0 Kudos

Hi there,

Here is the issue.

The IMPORT and EXPORT commands are valid for the same session. Now, If I simply submit the program B (Not in background) from program A my EXPORT and IMPORT are working.

But If I execute the Program B in a different session it doesn't work. So, when you submit the program B in the background, its a different session so the IMPORT does not work. This uses the ABAP memory.

You will have to use SET PARAMETER and GET PARAMETER which uses the GLOBAL SAP Memory.

Regards,

Ravi

0 Kudos

Hi Ravi,

Even SET PARAMETER and GET PARAMETER does'nt solve the problem. I tries using them.

Thanks & Regards,

YJR

0 Kudos

Hi,

I am trying that ... mean while here is a work around.

Can you create the field as a parameter for the second report and pass the value for the selection parameter along with the SUBMIT STATEMEMT.

SUBMIT reportb WITH P_PARA1 = 'XXX' .....

Regards,

Ravi

Former Member
0 Kudos

Hello YJR,

Instead of using IMPORT via memory use database option, this way it will write the value in the database which can be retrived later.

IMPORT obj1 ... objn FROM DATABASE dbtab(ar) ID key

The only concern is if multiple jobs are scheduled then there caould be issue. If this is not the case then u can go ahead and use this method otherwise I would suggest u can use Job number as the key which will be unique.