jueves, 9 de enero de 2020

Ejecutar programa con submit como un job de fondo

*&---------------------------------------------------------------------
*&      Form  SET_JOB
*&---------------------------------------------------------------------
*       text
*----------------------------------------------------------------------
*      -->P_L_ID_PROCESO  text
*      -->P_L_ROW_INIT  text
*      -->P_L_ROW_LAST  text
*      <--P_<FS_PROCESO>_E_JOB_NAME  text
*----------------------------------------------------------------------
FORM set_job  USING    p_id_proceso
                       p_i_row_init
                       p_i_row_last
              CHANGING p_ie_subrc
                       p_ie_job_name  TYPE btcjob
                       p_ie_jobcount  TYPE btcjobcnt.

  CALL FUNCTION 'JOB_OPEN'
    EXPORTING
      jobname          p_ie_job_name
    IMPORTING
      jobcount         p_ie_jobcount
    EXCEPTIONS
      cant_create_job  1
      invalid_job_data 2
      jobname_missing  3
      OTHERS           4.

  IF sy-subrc EQ 0.
    SUBMIT zf1_pr_ep_r_report_dinamicjobs VIA JOB p_ie_job_name
    NUMBER p_ie_jobcount
    USING SELECTION-SCREEN 1000
            TO SAP-SPOOL WITHOUT SPOOL DYNPRO
            IMMEDIATELY 'X'
            WITH  p_taskid EQ p_id_proceso
            WITH  p_jobnam EQ p_ie_job_name
            WITH  p_jobcon EQ p_ie_jobcount
            WITH  p_rini   EQ p_i_row_init
            WITH  p_rlas   EQ p_i_row_last
            WITH  p_fikrs  EQ p_fikrs
            WITH  p_gjahr  EQ p_gjahr
            WITH  p_versi  EQ p_versi
            WITH  p_ptype  EQ p_ptype
            WITH  p_consol EQ p_consol
            WITH  p_ltext  EQ p_ltext
            AND RETURN.
    IF sy-subrc EQ 0.
      CALL FUNCTION 'JOB_CLOSE'
        EXPORTING
          jobcount             p_ie_jobcount
          jobname              p_ie_job_name
          strtimmed            'X'
        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 NE 0.
        p_ie_subrc 4.
      ENDIF.
    ELSE.
      p_ie_subrc 4.
    ENDIF.
  ELSE.
    p_ie_subrc 4.
  ENDIF.
ENDFORM.