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 create a batch-job dynamically?

Former Member
0 Likes
4,875

Hello,

I would like to create a batch-job from within my abap code.

Therefore I want to determine a abap-report to be executed every X-Hours.

Do you have some sample code for creating a batch job?

I need to do it in abap because I want to create a TN to trigger the code creating the job.

So the user interaction will be minimal to start a periodic batch job.

thanks.

18 REPLIES 18
Read only

Sm1tje
Active Contributor
0 Likes
3,343

use FM job_open and job_close (job_submit or SUBMIT). for examples do a where used on job_open FM,

Read only

Former Member
0 Likes
3,343
REPORT  Z_DG_CREATE_BATCH_JOB.
 CALL FUNCTION 'JOB_OPEN'
EXPORTING
JOBNAME = 'Dynamic'
IMPORTING
JOBCOUNT = 
EXCEPTIONS
CANT_CREATE_JOB = 1
INVALID_JOB_DATA = 2
JOBNAME_MISSING = 3
OTHERS = 4.

thank you.

Can you tell me what that job count is?

The Jobname is be be set my me, isn't it, but where does jobcount come from?

Read only

Former Member
0 Likes
3,343

Hi micky,

I implemented the code but the debugger says that the jobname has a wrong type. I gave him a c(7). what type do I need to use?

Read only

Former Member
0 Likes
3,343

Hi,

take the structure BTCEVTJOB. there 2 fields jobname & jobcount.

Reward if helpful.

Thanks.

Read only

Former Member
0 Likes
3,343

give C(8) buddy.

Read only

Former Member
0 Likes
3,343

thank you. that works.

I cannot find the fitting type for JOB_WAS_RELEASED.

Can you tell me?

Read only

Former Member
0 Likes
3,343

Hi,

job_was_released = 'x' ......if it gets successful....

This parameter is returned with the value X, if the job was automatically released for execution at the scheduled start time.

A job is automatically released if the user has release authorizaton (authorization Background Processing: Operations on Background Jobs), RELE authorization or object Background Processing: Background Administrator.

no need to provide i think...u can proceed in dat way....

Thanks.

Edited by: Sagar@MM on May 26, 2008 5:34 PM

Read only

Former Member
0 Likes
3,343

hi,

but it is at IMPORTING which means the FM will give me that value, my problem is that I don't know where I can save it in. And that part will give me debug errors.

Read only

Former Member
0 Likes
3,343

Hi,

create 1 variable type SY-BATCH. pass that thru.

Thanks.

Read only

Former Member
0 Likes
3,343

great the errors are gone. thank you guys.

Now there are neither syntax errors nor debug errors.

Once I start it now I get an announcement saying: "Printer for Jobsteps inappliably. No autmatic ouput available"

Could the problem be that the programms I use in the background job write something to screen?

Should I delete the code writing to screen?

Where do I specify the intervalls the job is called?

Edited by: Daniel Gerne on May 26, 2008 11:53 AM

Read only

Sm1tje
Active Contributor
0 Likes
3,343

this is probably due to the printer you have defined. Try and use the default frontend printer (LOCL).

Read only

Former Member
0 Likes
3,343

hm I am not using a printer I just write to standardoutput

Read only

Former Member
0 Likes
3,343

Still 2 Questions:

Where is the intervall for the jobs defined?

How do I set the starttime of the first run?

Read only

former_member435013
Active Participant
0 Likes
3,343

Hi,

- define user event by sm62

- create the required job event periodic with your new event

- create a very small report with only call of function BP_EVENT_RAISE with your new event

- make a transaction for your new small start report

regards

Walter Habich

Read only

0 Likes
3,343

Hi walter,

that's what I tried first. But the problem is that once a job is event-periodic i can't define the intervalls anymore. Therefore I need to create the job in abap.

edit: OK I think the fm will get me that jobcount after executing.

Edited by: Daniel Gerne on May 26, 2008 10:46 AM

Read only

0 Likes
3,343

Hi

U need to indicate all chararcteristics of the job while closing it by fm JOB_CLOSE

Max

Read only

0 Likes
3,343

job count will show you the "ID Number of Background Job", you should declare it of type Char length 8, any variable will do.

This method is called as "Full Control Method".

Use JOB_OPEN to create a background job. The function module returns the unique ID number which, together with the job name, is required for identifying the job.

Once you have "opened" a job, you can add job steps to it with JOB_SUBMIT and submit the job for processing with JOB_CLOSE.

Use JOB_SUBMIT to add a job step to a background job that you have opened with JOB_OPEN.

A job step is an independent unit of work in a job, the execution of an ABAP or external program. Each job step can have its own authorizations user and printer/optical archiving specifications.

Hope this helps, reward points it useful.

Vishal.

Read only

former_member435013
Active Participant
0 Likes
3,343

Hi Daniel,

select options could be stored by export/import to/from database:

...

...

...

DESCRIBE TABLE t_vkpos LINES n.

READ TABLE t_vkpos INDEX n.

lastmaxvbeln = t_vkpos-vbeln.

PERFORM get_varimemkey USING p_vari CHANGING vkposmemkey.

EXPORT lastmaxvbeln TO DATABASE indx(zk) ID vkposmemkey.

IF NOT sy-subrc IS INITIAL.

...

...

...

PERFORM get_varimemkey USING p_vari CHANGING vkposmemkey.

IMPORT lastmaxvbeln FROM DATABASE indx(zk) ID vkposmemkey.

IF sy-subrc IS INITIAL.

ls_vbeln-sign = 'I'.

ls_vbeln-option = 'GT'.

ls_vbeln-low = lastmaxvbeln.

APPEND ls_vbeln.

ENDIF

...

...

...

FORM get_varimemkey USING vari TYPE raldb_vari

CHANGING memkey TYPE char22.

IF vari IS INITIAL.

RAISE get_varimemkey_unexepected.

ENDIF.

CONCATENATE 'Z_VKPOS_' vari INTO memkey.

ENDFORM. "

regards

Walter Habich