Thursday, August 27, 2009

Code Snippet for BP_JOB_CREATE.

BP_JOB_CREATE is a function module for creation of new jobs instead of using sm36 transaction.
There is very less information on this function module and how it works on internet.
I have used this function module to create batch jobs.


TYPES: BEGIN OF x_fm_input,
jobname TYPE char32, "Job name.
abapname TYPE char128, "Program name.
variant TYPE char255, "Variable name.
username TYPE tbtcstep-authcknam, "User Id
printer TYPE tbtcstep-pdest, "Output printer device
language TYPE tbtcstep-language, "Language
END OF x_fm_input.
DATA:
lt_excel_tab TYPE STANDARD TABLE OF x_fm_input,
t_inputtofunct TYPE STANDARD TABLE OF tbtcstep,
w_fm_input TYPE x_fm_input.
LOOP AT t_tab_excel
INTO w_tab_excel.
IF w_tab_excel-jobname IS NOT INITIAL AND
w_tab_excel-comments_controlm IS INITIAL.
w_fm_input-jobname = w_tab_excel-jobname.
w_fm_input-abapname = w_tab_excel-abapname.
w_fm_input-variant = w_tab_excel-variant.
w_fm_input-username = w_tab_excel-username.
APPEND w_fm_input TO lt_excel_tab.
CLEAR w_fm_input.
ENDIF.
ENDLOOP.
SORT lt_excel_tab BY jobname.
LOOP AT lt_excel_tab INTO w_fm_input.
w_fm_import-jobname = w_fm_input-jobname.
w_fm_import-status = c_stat. "Default Y
w_inputtofunct-program = w_fm_input-abapname.
w_inputtofunct-parameter = w_fm_input-variant.
w_inputtofunct-authcknam = w_fm_input-username.
w_inputtofunct-typ = c_inty. "Default A
w_inputtofunct-language = g_language.
w_inputtofunct-language = w_fm_input-language.
APPEND w_inputtofunct TO t_inputtofunct.
CLEAR w_inputtofunct.
AT END OF jobname.
***** TO CREATE JOBS *****
CALL FUNCTION 'BP_JOB_CREATE'
EXPORTING
job_cr_dialog = c_dlg "Default N
job_cr_head_inp = w_fm_import
TABLES
job_cr_steplist = t_inputtofunct
EXCEPTIONS
cant_create_job = 1
invalid_dialog_type = 2
invalid_job_data = 3
job_create_canceled = 4
OTHERS = 5.
REFRESH t_inputtofunct.
ENDAT.
CLEAR: w_inputtofunct, w_fm_import.
ENDLOOP.


If any doubt please post in comments I will surely answer. :)
cheers!!!

2 comments:

  1. Tany, i used your code, and found the job in sm37 as scheduled....But i want the job to getinto ACTIVE state, so that i can avoid getting into SM37

    Thanks.

    ReplyDelete
  2. Hi Uma ,
    Sorry for late reply,
    I know that's a problem with this code, I am very new to SAP(just 1 year experience) and now studying again. There is one more problem with the code, you can give the printer name but somehow the arguments for printer name does not work intutivly. My next job is not at all close to SAP so I would suggest you to go to sdn for this one.
    Cheers
    Tanmay

    ReplyDelete