程序中设置后台作业(background job) -有传入参数


转载自:http://caoxuhuan.iteye.com/blog/1124985

FORM frm_set_bgex . 
  DATA: 
        lc_ind TYPE char1, 
        lt_par_tab TYPE STANDARD TABLE OF rsparams, 
        ls_par_tab TYPE rsparams, 
        lc_jobname TYPE tbtcjob-jobname VALUE 'Z03P2R1104_CALC', 
        lc_jobnum  TYPE tbtcjob-jobcount 
        . 
  CALL FUNCTION 'POPUP_TO_CONFIRM' 
    EXPORTING 
      text_question         = text-010 
      default_button        = '2' 
      display_cancel_button = '' 
    IMPORTING 
      answer                = lc_ind. 
  CHECK lc_ind EQ '1'. 
  CONCATENATE lc_jobname '_' sy-datum INTO lc_jobname. 
* Par: BUKRS 
  CLEAR ls_par_tab. 
  ls_par_tab-selname = 'P_BUKRS'. 
  ls_par_tab-kind = 'P'. 
  ls_par_tab-low = z03p2s002-bukrs. 
  APPEND ls_par_tab TO lt_par_tab. 
* Par: GJAHR 
  CLEAR ls_par_tab. 
  ls_par_tab-selname = 'P_GJAHR'. 
  ls_par_tab-kind = 'P'. 
  ls_par_tab-low = z03p2s002-gjahr. 
  APPEND ls_par_tab TO lt_par_tab. 
* Par: MONAT 
  CLEAR ls_par_tab. 
  ls_par_tab-selname = 'P_MONAT'. 
  ls_par_tab-kind = 'P'. 
  ls_par_tab-low = z03p2s002-monat. 
  APPEND ls_par_tab TO lt_par_tab. 
* Select-option: S_RCODE 
  CLEAR ls_par_tab. 
  ls_par_tab-selname = 'S_RCODE'. 
  ls_par_tab-kind = 'S'. 
  ls_par_tab-sign = 'I'. 
  ls_par_tab-option = 'EQ'. 
  LOOP AT gt_alv INTO gs_alv 
    WHERE mark EQ 'X'. 
    ls_par_tab-low = gs_alv-rcode. 
    APPEND ls_par_tab TO lt_par_tab. 
  ENDLOOP. 
  CLEAR ls_par_tab. 
  ls_par_tab-selname = 'P_BATCH'. 
  ls_par_tab-kind = 'P'. 
  ls_par_tab-low = 'Y'. 
  APPEND ls_par_tab TO lt_par_tab. 
* Create Job 
  CALL FUNCTION 'JOB_OPEN' 
    EXPORTING 
      jobname          = lc_jobname 
    IMPORTING 
      jobcount         = lc_jobnum 
    EXCEPTIONS 
      cant_create_job  = 1 
      invalid_job_data = 2 
      jobname_missing  = 3 
      OTHERS           = 4. 
  IF sy-subrc NE 0. 
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno 
            WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. 
  ELSE. 
    SUBMIT z03p2r002  WITH SELECTION-TABLE lt_par_tab"z03p2r002程序随后附上 
    VIA JOB lc_jobname NUMBER lc_jobnum AND RETURN. 
    IF sy-subrc EQ 0. 
"CLOSE JOB DEFINITION 
      CALL FUNCTION 'JOB_CLOSE' 
        EXPORTING 
          jobcount             = lc_jobnum 
          jobname              = lc_jobname 
          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 <> 0. 
        MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno 
                WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. 
      ELSE. 
        MESSAGE i016(z03p2). 
      ENDIF. 
    ELSE. 
    ENDIF. 
  ENDIF. 


ENDFORM.                    " FRM_SET_BGEX 


z03p2r002中的选择屏幕 
*&---------------------------------------------------------------------* 
*&  包括                Z03P2X0007 
*&---------------------------------------------------------------------* 

PARAMETERS: 
  p_bukrs TYPE z03p2s002-bukrs DEFAULT '1201' OBLIGATORY, 
  p_gjahr TYPE z03p2s002-gjahr NO-DISPLAY, 
  p_monat TYPE z03p2s002-monat NO-DISPLAY, 
  p_batch TYPE sy-batch DEFAULT 'X' NO-DISPLAY. 
. 

SELECT-OPTIONS s_rcode FOR z03p2r1104m-rcode NO-DISPLAY. 








你可能感兴趣的:(BACKGROUND,JOB)