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: 

what to add to an program code in order to trigger an background job

Former Member
0 Kudos

Hi there

I wander what to add to an program code in order to trigger an event which consequently can trigger an background job

thx in advance

1 ACCEPTED SOLUTION

former_member156446
Active Contributor
0 Kudos

Check this code:

DATA : v_jobhead LIKE tbtcjob.
DATA : v_jobcount LIKE tbtcjob-jobcount.
DATA : v_eventparm LIKE tbtcjob-eventparm.
DATA : v_flg_released TYPE c.
DATA: e_error.
DATA: running LIKE tbtcv-run.
 
TYPES: esp1_boolean LIKE boole-boole.
 
CONSTANTS: esp1_false TYPE esp1_boolean VALUE ' ',
           esp1_true  TYPE esp1_boolean VALUE 'X'.
 
CONSTANTS: true  TYPE boolean VALUE esp1_true,
                          false TYPE boolean VALUE esp1_false.
 
PARAMETERS: v_jobnam LIKE tbtcjob-jobname,
            v_report LIKE sy-repid,
            v_varian LIKE  raldb-variant,
            v_uname  LIKE sy-uname.
 
START-OF-SELECTION.
 
* add the new job
  CALL FUNCTION 'JOB_OPEN'
       EXPORTING
*            delanfrep        = 'X'
            jobname          = v_jobnam
       IMPORTING
            jobcount         = v_jobcount
       EXCEPTIONS
            cant_create_job  = 1
            invalid_job_data = 2
            jobname_missing  = 3
            OTHERS           = 4.
  IF sy-subrc <> 0.
    e_error = true.
  ELSE.
    CALL FUNCTION 'JOB_SUBMIT'  " or you can use SUBMIT statement as well.
         EXPORTING
              authcknam               = v_uname
              jobcount                = v_jobcount
              jobname                 = v_jobnam
              report                  = v_report
              variant                 = v_varian
         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.
      e_error = true.
    ELSE.
      CALL FUNCTION 'JOB_CLOSE'
           EXPORTING
*               EVENT_ID                    = IC_WWI_WORKPROCESS_EVENT
*               EVENT_PARAM                 = V_EVENTPARM
*               EVENT_PERIODIC              = 'X'
                jobcount                    = v_jobcount
                jobname                     = v_jobnam
                strtimmed                   = 'X'
           IMPORTING
                job_was_released            = v_flg_released
           EXCEPTIONS
                cant_start_immediate        = 1
                invalid_startdate           = 2
                jobname_missing             = 3
                job_close_failed            = 4
                job_nosteps                 = 5
                job_notex                   = 6
                lock_failed                 = 7
                OTHERS                      = 8.
      IF sy-subrc <> 0.
        e_error = true.
      ELSE.
        DO.
          CALL FUNCTION 'SHOW_JOBSTATE'
            EXPORTING
              jobcount               = v_jobcount
              jobname                = v_jobnam
*            IMPORTING
*         ABORTED                =
*         FINISHED               =
*         PRELIMINARY            =
*         READY                  =
*              running                =
*         SCHEDULED              =
           EXCEPTIONS
             jobcount_missing       = 1
             jobname_missing        = 2
             job_notex              = 3
             OTHERS                 = 4.
 
          IF sy-subrc <> 0.
            e_error = true.
            MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
                    WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
          ENDIF.
          IF running = space.
            EXIT.
          ENDIF.
        ENDDO.
      ENDIF.
    ENDIF.
  ENDIF.

2 REPLIES 2

Former Member
0 Kudos

Check this [link>>>|;

former_member156446
Active Contributor
0 Kudos

Check this code:

DATA : v_jobhead LIKE tbtcjob.
DATA : v_jobcount LIKE tbtcjob-jobcount.
DATA : v_eventparm LIKE tbtcjob-eventparm.
DATA : v_flg_released TYPE c.
DATA: e_error.
DATA: running LIKE tbtcv-run.
 
TYPES: esp1_boolean LIKE boole-boole.
 
CONSTANTS: esp1_false TYPE esp1_boolean VALUE ' ',
           esp1_true  TYPE esp1_boolean VALUE 'X'.
 
CONSTANTS: true  TYPE boolean VALUE esp1_true,
                          false TYPE boolean VALUE esp1_false.
 
PARAMETERS: v_jobnam LIKE tbtcjob-jobname,
            v_report LIKE sy-repid,
            v_varian LIKE  raldb-variant,
            v_uname  LIKE sy-uname.
 
START-OF-SELECTION.
 
* add the new job
  CALL FUNCTION 'JOB_OPEN'
       EXPORTING
*            delanfrep        = 'X'
            jobname          = v_jobnam
       IMPORTING
            jobcount         = v_jobcount
       EXCEPTIONS
            cant_create_job  = 1
            invalid_job_data = 2
            jobname_missing  = 3
            OTHERS           = 4.
  IF sy-subrc <> 0.
    e_error = true.
  ELSE.
    CALL FUNCTION 'JOB_SUBMIT'  " or you can use SUBMIT statement as well.
         EXPORTING
              authcknam               = v_uname
              jobcount                = v_jobcount
              jobname                 = v_jobnam
              report                  = v_report
              variant                 = v_varian
         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.
      e_error = true.
    ELSE.
      CALL FUNCTION 'JOB_CLOSE'
           EXPORTING
*               EVENT_ID                    = IC_WWI_WORKPROCESS_EVENT
*               EVENT_PARAM                 = V_EVENTPARM
*               EVENT_PERIODIC              = 'X'
                jobcount                    = v_jobcount
                jobname                     = v_jobnam
                strtimmed                   = 'X'
           IMPORTING
                job_was_released            = v_flg_released
           EXCEPTIONS
                cant_start_immediate        = 1
                invalid_startdate           = 2
                jobname_missing             = 3
                job_close_failed            = 4
                job_nosteps                 = 5
                job_notex                   = 6
                lock_failed                 = 7
                OTHERS                      = 8.
      IF sy-subrc <> 0.
        e_error = true.
      ELSE.
        DO.
          CALL FUNCTION 'SHOW_JOBSTATE'
            EXPORTING
              jobcount               = v_jobcount
              jobname                = v_jobnam
*            IMPORTING
*         ABORTED                =
*         FINISHED               =
*         PRELIMINARY            =
*         READY                  =
*              running                =
*         SCHEDULED              =
           EXCEPTIONS
             jobcount_missing       = 1
             jobname_missing        = 2
             job_notex              = 3
             OTHERS                 = 4.
 
          IF sy-subrc <> 0.
            e_error = true.
            MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
                    WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
          ENDIF.
          IF running = space.
            EXIT.
          ENDIF.
        ENDDO.
      ENDIF.
    ENDIF.
  ENDIF.