Tuesday, April 24, 2018

Job table

tbtco
*&---------------------------------------------------------------------*
*& Report  ZUTIL_RELEASE_JOB
*&
*&---------------------------------------------------------------------*
* Identification
*   Technical Object(s)   : Program  -->  ZUTIL_RELEASE_JOB.
*   Title                 : Utility program that releases the next job in a set of spawned jobs
*   Description           : Utility program to release batch jobs
*   Technical Consultant  : Anil Vithal
*   Solutions Architect   : Don Chamberland
*   Functional Consultant : Manish Govil
*   Creation Date         : 26.07.2017
*   Project/Ticket        : BREWS
*---------------------------------------------------------------------*
* 26.07.2017    AVITHAL      BREWS Project – Realization
*---------------------------------------------------------------------*
* 28.02.2018    RGILMORE     Adjusted to ensure older job is released first
*                            Covered under defect 327 TRANSPORT:ED1K906519
*----------------------------------------------------------------------*

REPORT  ZUTIL_RELEASE_JOB.

PARAMETERS:
  p_job LIKE tbtcm-jobname OBLIGATORY.

data:
  gv_job type string. " LIKE tbtcm-jobname.

START-OF-SELECTION.
  perform f_check_input.
  perform f_release_job .

*&---------------------------------------------------------------------*
*&      Form  F_CHECK_INPUT
*&---------------------------------------------------------------------*
form F_CHECK_INPUT .
  data:
     lv_len type i,
     lv_char.

  lv_len = strlen( p_job ) - 1.
  lv_char =  p_job+lv_len(1).
  if  lv_char ne '%'.
    CONCATENATE p_job '%' into gv_job.
  endif.
endform.                    " F_CHECK_INPUT


*&---------------------------------------------------------------------*
*&      Form  F_RELEASE_JOB
*&---------------------------------------------------------------------*
*      release the next job
*----------------------------------------------------------------------*
FORM f_release_job .

  DATA:

    lv_date    TYPE dats,
    lv_tbtcstrt TYPE tbtcstrt,
    lt_new_steplist TYPE TABLE OF  tbtcstep,
    lv_rand     LIKE qf00-ran_int,
    BEGIN OF ls_tbtco,
      jobname   TYPE tbtco-jobname,
      jobcount  TYPE tbtco-jobcount,
      SDLSTRTDT TYPE BTCSDATE,   "new defect 327  RGILMORE
      SDLSTRTTM TYPE BTCSTiME,   "new defect 327  RGILMORE
    END OF ls_tbtco,
    lt_tbtco LIKE TABLE OF ls_tbtco.


  SELECT jobname jobcount SDLSTRTDT SDLSTRTTM FROM tbtco
    INTO TABLE lt_tbtco UP TO 10 ROWS
   WHERE jobname LIKE gv_job
     AND status    = 'P'
    order by SDLSTRTDT ascending SDLSTRTTM ascending.
*   added order by RE: defect 327.  RGILMORE

  IF  sy-subrc NE 0.   " NO MORE JOBS
    EXIT.
  ENDIF.

* Added sort order re defect 327. RGILMORE
  SORT lt_tbtco by SDLSTRTDT ascending SDLSTRTTM ascending.  "we want to hit the oldest job first via planned start date.

  LOOP AT lt_tbtco INTO ls_tbtco.
*   more jobs found - release one
    CALL FUNCTION 'BP_JOB_RELEASE'
      EXPORTING
        jobname                           = ls_tbtco-jobname
        jobcount                          = ls_tbtco-jobcount
*        CHANGING
*         RET                               =
      EXCEPTIONS
       missing_jobname                   = 1
       missing_jobcount                  = 2
       missing_start_date                = 3
       status_not_scheduled              = 4
       cant_enq_job                      = 5
       cant_start_job_immediately        = 6
       no_privilege_to_release_job       = 7
       cant_release_job                  = 8
       job_not_exist                     = 9
       job_have_no_steps                 = 10
       error_job_modify                  = 11
       OTHERS                            = 12.

    IF  sy-subrc EQ 0.  " success
      EXIT.
    ENDIF.

  ENDLOOP.


ENDFORM.                    " F_RELEASE_JOB

No comments:

Post a Comment