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

Batch Job Creation

Former Member
0 Likes
766

Hi all,

i have a requirement where i need to create Background Job for a program when another program is being executed.

Can some one tell me any Function modules for the same along with parameters.

Regards,

AJ

Hi all,

i have a requirement where i need to create Background Job for a program when another program is being executed.

Can some one tell me any Function modules for the same along with parameters.

Regards,

AJ

5 REPLIES 5
Read only

Former Member
0 Likes
721

HI

Use FM- JOB_OPEN

then use

submit <name> and return <parameters>

FM- JOB_CLOSE.

http://help.sap.com/saphelp_bw21c/helpdata/en/c4/3a7f87505211d189550000e829fbbd/content.htm

You can also do ABAP code to create batch jobs, trigger batch jobs via events etc, e.g.

Triggering jobs inside and outside SAP

but SM36 sounds like all you need.

Regards

Aditya

Edited by: ADITYA MITTAL on Jul 31, 2008 2:24 PM

Read only

Former Member
0 Likes
721

Hi,

see this link it may useful to U,

'saptechnical.com/Tutorials/ABAP/BackgroundJob/OnEvent.htm'

Read only

Former Member
0 Likes
721

hi do like this..

*----


  • Here is an interface program to create the required no of jobs

  • automatically with the given path in the application server by

  • specifying filename no of files to be created and sites and

  • article range

*----


REPORT ztestreport LINE-SIZE 180

LINE-COUNT 65

NO STANDARD PAGE HEADING

MESSAGE-ID zr.

*----


  • database tables

*----


TABLES: t001w ,

mard .

*----


  • variables

*----


DATA: g_lines LIKE sy-tabix,

g_read LIKE sy-tabix,

g_filename LIKE edi_path-pthnam,

g_records TYPE sy-tabix,

g_total_rec TYPE i,

g_fileno TYPE i,

v_records TYPE i,

v_fileno(3) TYPE c .

*----


  • internal tables

*----


*---table for sites

TYPES: BEGIN OF ty_t001w ,

werks TYPE werks_d,

END OF ty_t001w.

*--types for plant store

TYPES:BEGIN OF ty_mard ,

matnr LIKE mard-matnr,

werks LIKE mard-werks,

lgort LIKE mard-lgort,

END OF ty_mard.

*---database tables

DATA: it_t001w TYPE STANDARD TABLE OF ty_t001w WITH HEADER LINE,

it_exp_t001w TYPE STANDARD TABLE OF ty_t001w WITH HEADER LINE,

it_mard TYPE STANDARD TABLE OF ty_mard WITH HEADER LINE .

*----


  • selection screen

*----


SELECTION-SCREEN: BEGIN OF BLOCK b1 WITH FRAME .

SELECT-OPTIONS:s_matnr FOR mard-matnr, "articles

s_werks FOR t001w-werks. "plant

PARAMETERS: p_file1(45) TYPE c , "filename

p_numjob(3) TYPE n . "no of jobs to be created

SELECTION-SCREEN: END OF BLOCK b1.

*----


  • ranges

*----


*--ranges for plant

RANGES: r_werks FOR t001w-werks.

----


  • AT SELECTION SCREEN

----


AT SELECTION-SCREEN .

*---if there is no message raise a message to enter file name

IF p_file1 IS INITIAL.

MESSAGE i001 WITH 'Enter File Name'.

ENDIF.

*---if the no of jobs to be create field is initial raise a message to enter a value

IF p_numjob EQ space.

MESSAGE i001 WITH 'Enter a valid no of files to be created'.

ENDIF.

*----


  • start of selection

*----


START-OF-SELECTION.

*---write the header of the output with filename and no of records downloaded

PERFORM header_name.

*--get the data for the plants

PERFORM get_data.

*--process the data for creating the file in application server

PERFORM process_data .

&----


*& Form get_data

&----


FORM get_data .

REFRESH:it_t001w.

*---get data for plants

SELECT werks

FROM t001w

INTO TABLE it_t001w

WHERE werks IN s_werks.

IF NOT it_t001w[] IS INITIAL.

SORT it_t001w BY werks.

*---count the no of records from plant table

DESCRIBE TABLE it_t001w LINES g_lines.

ENDIF.

ENDFORM. " get_data

&----


*& Form process_data

&----


FORM process_data .

*---get the no of plant records per job

g_read = g_lines / p_numjob.

*---this is to avoid the short dump

IF g_read = 0.

g_read = 1.

ENDIF.

CLEAR g_lines.

g_lines = p_numjob.

*--processing of the job

DO.

*---if the number of jobs to be create is greate than one

IF g_lines > 1.

*---send some of the records to the first job to process

APPEND LINES OF it_t001w FROM 1 TO g_read TO it_exp_t001w.

REFRESH r_werks.

*---fill the records into the ranges to be processed for first job

PERFORM fill_range.

*---get the the file no

ADD 1 TO g_fileno.

v_fileno = g_fileno.

CONCATENATE p_file1 '\test' v_fileno INTO g_filename.

*---get the filename with path

CONDENSE g_filename NO-GAPS.

*---get the no articles from the plants selected in the ranes

PERFORM get_mard_data.

CLEAR: it_exp_t001w, it_exp_t001w[].

*---decrease the no of jobs by one

g_lines = g_lines - 1.

*---check for further processing

IF it_t001w[] IS INITIAL.

g_lines = 0.

ENDIF.

*---if the no of jobs to be created is one

ELSEIF g_lines = 1.

*---send all the records to one internal table

APPEND LINES OF it_t001w TO it_exp_t001w.

REFRESH r_werks.

*---get the records in ranges

PERFORM fill_range.

REFRESH IT_MARD.

PERFORM get_mard_data.

CLEAR: it_exp_t001w, it_exp_t001w[], it_t001w[].

*--check for further processing

CHECK it_t001w[] IS INITIAL.

EXIT.

ELSE.

CHECK it_t001w[] IS INITIAL.

EXIT.

ENDIF.

ENDDO.

ENDFORM. " process_data

&----


*& Form get_mard_data

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM get_mard_data .

REFRESH: it_mard.

SELECT matnr

werks

lgort

FROM mard INTO TABLE it_mard

FOR ALL ENTRIES IN it_t001w

WHERE werks = it_t001w-werks.

IF NOT it_mard[] IS INITIAL.

SORT it_mard BY werks.

*----write the file into application server

PERFORM write_file.

ENDIF.

ENDFORM. " get_mard_data

&----


*& Form write_file

&----


FORM write_file .

DATA: outrec(100) TYPE c.

*---get the no of records from the mard table

DESCRIBE TABLE it_mard LINES v_records.

*---open file in appilication server to write these records

OPEN DATASET g_filename FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.

IF sy-subrc NE 0.

EXIT.

ENDIF.

LOOP AT it_mard.

outrec+0(18) = it_mard-matnr.

outrec+25(4) = it_mard-werks.

outrec+40(16) = it_mard-lgort.

TRANSFER outrec TO g_filename .

ENDLOOP.

*---write the file name and no of records downloaded

PERFORM file_name.

*---close the file in application server

CLOSE DATASET g_filename.

ENDFORM. " write_file

&----


*& Form fill_range

&----


FORM fill_range .

LOOP AT it_exp_t001w.

r_werks-low = it_exp_t001w-werks.

r_werks-sign = 'I'.

r_werks-option = 'EQ'.

APPEND r_werks.

ENDLOOP.

DELETE it_t001w FROM 1 TO g_read.

ENDFORM. " fill_range

&----


*& Form header_name

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM header_name .

WRITE:/1(130) sy-uline .

WRITE:/1 sy-vline,

2 'CREATED FILENAME' COLOR 7,

62 sy-vline,

64 'NO OF SUCCESSFUL RECORDS IN THIS FILE ' COLOR 7 ,

130 sy-vline.

WRITE:/1(130) sy-uline .

ENDFORM. " header_name

&----


*& Form FILE_NAME

&----


FORM file_name .

WRITE:/1(130) sy-uline .

WRITE:/1 sy-vline,

2 g_filename,

62 sy-vline,

64 v_records,

130 sy-vline.

WRITE:/1(130) sy-uline .

ENDFORM. " FILE_NAME

Read only

Former Member
0 Likes
721

Hi Venkat,

Basically, I have 8 Z Tcodes, and all the Z Tcodes needs to be executed using a single selection screen.

Fo this purpose i have created a single selection screen which contains selections for all the 8 z tcodes.

Now I need to execute the programs with respective parameters and create Batch jobs, which will be executed in back ground.

For this I need function module which can solve my purpose.

Regards,

AJ

Read only

Former Member
0 Likes
721

.