Skip to Content
avatar image
Former Member

Function modules 'JOB_OPEN' & 'JOB_CLOSE'

Hello All,

Could anyone please tell me the functionality of the function modules 'JOB_OPEN', 'JOB_CLOSE'. Any sample code will be of great help.

Regards

Indrajit

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

4 Answers

  • Best Answer
    avatar image
    Former Member
    Jun 15, 2007 at 06:57 AM

    Hi,

    report abc.

    BREAK-POINT.

    DATA : JN(32) TYPE C.

    JN = 'JOB001'.

    BREAK-POINT.

    DATA : J(8) TYPE C.

    CALL FUNCTION 'JOB_OPEN'

    EXPORTING

    • DELANFREP = ' '

    • JOBGROUP = ' '

    jobname = JN

    • SDLSTRTDT = NO_DATE

    • SDLSTRTTM = NO_TIME

    • JOBCLASS =

    IMPORTING

    JOBCOUNT = J

    • CHANGING

    • RET =

    • 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.

    DATA : P TYPE PRI_PARAMS.

    P-PDEST = 'PRINTER'.

    P-PDEST = 'LOCL'.

    CALL FUNCTION 'GET_PRINT_PARAMETERS'

    EXPORTING NO_DIALOG = 'X'

    MODE = 'CURRENT'

    • NEW_LIST_ID = $PRNEW

    IMPORTING OUT_PARAMETERS = P.

    CALL FUNCTION 'JOB_SUBMIT'

    EXPORTING

    • ARCPARAMS =

    authcknam = 'MAMIT'

    • COMMANDNAME = ' '

    • OPERATINGSYSTEM = ' '

    • EXTPGM_NAME = ' '

    • EXTPGM_PARAM = ' '

    • EXTPGM_SET_TRACE_ON = ' '

    • EXTPGM_STDERR_IN_JOBLOG = 'X'

    • EXTPGM_STDOUT_IN_JOBLOG = 'X'

    • EXTPGM_SYSTEM = ' '

    • EXTPGM_RFCDEST = ' '

    • EXTPGM_WAIT_FOR_TERMINATION = 'X'

    jobcount = J

    jobname = JN

    • LANGUAGE = SY-LANGU

    PRIPARAMS = P

    REPORT = 'HINCF160'

    VARIANT = 'A'

    • IMPORTING

    • STEP_NUMBER =

    EXCEPTIONS

    BAD_PRIPARAMS = 1

    • BAD_XPGFLAGS = 2

    • INVALID_JOBDATA = 3

    • JOBNAME_MISSING = 4

    • JOB_NOTEX = 5

    • JOB_SUBMIT_FAILED = 6

    • LOCK_FAILED = 7

    • PROGRAM_MISSING = 8

    • PROG_ABAP_AND_EXTPG_SET = 9

    OTHERS = 10

    .

    IF sy-subrc <> 0.

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

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

    ENDIF.

    CALL FUNCTION 'JOB_CLOSE'

    EXPORTING

    • AT_OPMODE = ' '

    • AT_OPMODE_PERIODIC = ' '

    • CALENDAR_ID = ' '

    • EVENT_ID = ' '

    • EVENT_PARAM = ' '

    • EVENT_PERIODIC = ' '

    jobcount = J

    jobname = JN

    • LASTSTRTDT = NO_DATE

    • LASTSTRTTM = NO_TIME

    • PRDDAYS = 0

    • PRDHOURS = 0

    • PRDMINS = 0

    • PRDMONTHS = 0

    • PRDWEEKS = 0

    • PREDJOB_CHECKSTAT = ' '

    • PRED_JOBCOUNT = ' '

    • PRED_JOBNAME = ' '

    • SDLSTRTDT = NO_DATE

    • SDLSTRTTM = NO_TIME

    • STARTDATE_RESTRICTION = BTC_PROCESS_ALWAYS

    STRTIMMED = 'X'

    • TARGETSYSTEM = ' '

    • START_ON_WORKDAY_NOT_BEFORE = SY-DATUM

    • START_ON_WORKDAY_NR = 0

    • WORKDAY_COUNT_DIRECTION = 0

    • RECIPIENT_OBJ =

    • TARGETSERVER = ' '

    • DONT_RELEASE = ' '

    • TARGETGROUP = ' '

    • DIRECT_START =

    • IMPORTING

    • JOB_WAS_RELEASED =

    • CHANGING

    • RET =

    • 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.

    BREAK-POINT.

    <b>Reward points</b>

    Regards

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Jun 15, 2007 at 07:01 AM

    hi

    JOB_OPEN->For opening a job in the background

    JOB_SUBMIT->For submitting the job

    JOB_CLOSE->For closing the job.

    Take a look at the example code for these functions.

    http://www.sap-basis-abap.com/sapac018.htm

    *Submit report as job(i.e. in background)  
    data: jobname like tbtcjob-jobname value
                                 ' TRANSFER TRANSLATION'.
    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.
    
    * Insert process into job
     SUBMIT zreport and return 
                    with p_param1 = 'value'
                    with p_param2 = 'value'
                    user sy-uname
                    via job jobname
                    number jobcount.
      if sy-subrc > 0.
                                           "error processing
      endif.
    
    * Close job
      starttime-sdlstrtdt = sy-datum + 1.
      starttime-sdlstrttm = '220000'.
      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            = 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.
    

    Regards

    Sudheer

    Add comment
    10|10000 characters needed characters exceeded

  • Jun 15, 2007 at 07:04 AM

    Hi,

    There can be more than one jobs with the same name and Job count is the unique key to identify a job in a particular system. JOB_OPEN reserve a unique Job count and allows you to submit a Job (using JOB_SUBMIT) with that Job Count and Job name. JOB_CLOSE does a commit work for specific Job Count.

    Rewards points if helpful.

    Regards,

    Ram

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Jun 15, 2007 at 07:01 AM

    job_open:

    Open Job Scheduling Without Dialog (Including COMMIT WORK)

    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.

    job_close:

    Close Background Request With COMMIT WORK

    Use JOB_CLOSE to pass a background job to the background processing system to be run. Once you have "closed" a job, you can no longer add job steps to it or change job/job step specifications.

    The function module returns an indicator as to whether the job was automatically released or not. A job is automatically released to run only if the user who scheduled the job has RELE release authorization for the authorization object Operations on background jobs.

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

    Related function modules include:

    JOB_OPEN: Create a background job.

    JOB_SUBMIT: Add job steps to a job.

    Note: if a user does not have the authorization to release a job, then the job is scheduled with the status planned. The job cannot be started until it is released, regardless of any start specifications made for the job.

    following is the code using these:

    REPORT Z_GENERATE_JOB.

    DATA: JOBCOUNT LIKE TBTCO-JOBCOUNT.

    PARAMETER: JOBNAME LIKE TBTCO-JOBNAME,

    REPORT LIKE SY-REPID,

    VARIANT LIKE RALDB-VARIANT,

    BTCHUSER LIKE SY-UNAME.

    START-OF-SELECTION.

    CALL FUNCTION 'JOB_OPEN'

    EXPORTING JOBNAME = JOBNAME

    IMPORTING JOBCOUNT = JOBCOUNT.

    CALL FUNCTION 'JOB_SUBMIT'

    EXPORTING AUTHCKNAM = BTCHUSER

    JOBCOUNT = JOBCOUNT

    JOBNAME = JOBNAME

    REPORT = REPORT

    VARIANT = VARIANT.

    WRITE: / JOBNAME, JOBCOUNT,

    REPORT, VARIANT, BTCHUSER.

    CALL FUNCTION 'JOB_CLOSE'

    EXPORTING JOBCOUNT = JOBCOUNT

    JOBNAME = JOBNAME.

    regards,

    Ruchika

    reward if useful.............

    Add comment
    10|10000 characters needed characters exceeded