ABAP多线程

*&---------------------------------------------------------------------*
*& Report:    ZSDHQ0001
*&
*&---------------------------------------------------------------------*
*& Tcode:    ZSDHQ0001
*&---------------------------------------------------------------------*

report zsdhq0001 "no standard page heading
*                line-size 72
*                line-count 35
                .
tables: sscrfields,rzllitab,
        smp_dyntxt,vbak.

data:gt_data like table of ztsdhq0001_01 with header line.
data:gv_taskname(10) type c,                "task name(同时运行的任务名称必须保持唯一)
     gv_classname type rzllitab-classname,          "Server Group Name
     gv_applserver type rzllitab-applserver,"RFC Serve Group     excp_flag(1) TYPE c.
     gv_snd_jobs type i,
     gv_rcv_jobs type i,
     gv_task_num type i.
*data:gv_log(50) type c.
data:gv_date type dats.
data:begin of gt_msg occurs 0,
     txt(70) type c,
     uzeit like sy-uzeit,
    end of gt_msg.
*&---------------------------------------------------------------------*
* define ALV must variable
*&---------------------------------------------------------------------*
data: gr_grid   type ref to cl_gui_alv_grid,
      gt_fcat   type lvc_t_fcat,
      gs_fcat   type lvc_s_fcat,
      gt_sort   type lvc_t_sort,
      gs_sort   type lvc_s_sort,
      gs_layout type lvc_s_layo,   "alv的格式
      gv_repid  like sy-repid.

data: gt_events type slis_t_event,
      gs_events like line of gt_events.
data:
  gs_variant          type disvariant,  "显示变式结构
  gv_variant_save     type char1 value 'A',
  gs_print            type lvc_s_prnt,  "类型组
  gv_html_top_of_page type slis_formname.

selection-screen function key :1.
selection-screen begin of block b1 with frame title text-001.
select-options:s_odf for vbak-vbeln.
parameters:p_erdat like vbak-erdat.
selection-screen uline.
parameters:rb_exe radiobutton group r1 default 'X',
           rb_qur radiobutton group r1.
selection-screen end of block b1.
selection-screen begin of block b2 with frame title text-002.
parameters:ch_multi as checkbox default 'X'.
selection-screen uline.
parameters:p_wp type i default 5.
select-options:s_name for rzllitab-classname.
*           p_name type rzllitab-classname default 'parallel_generators'.
selection-screen end of block b2.

initialization.
  smp_dyntxt-icon_id   = icon_change.
  smp_dyntxt-icon_text = '基础配置表维护'(b01).
  sscrfields-functxt_01 = smp_dyntxt.

  p_erdat = sy-datum - 3.



at selection-screen output.


at selection-screen.
  case sscrfields-ucomm.
    when 'FC01'.
  endcase.

start-of-selection.
  "---抬头数据处理---------------------
  if rb_exe = 'X'.
    perform frm_get_hd.
    perform frm_pro_hd.
    perform frm_get_nd.
    perform frm_end_hd.
  endif.

end-of-selection.
*&---------------------------------------------------------------------*
*&      Form  FRM_CALL_VIEW
*&---------------------------------------------------------------------*
*       调用标准的
*----------------------------------------------------------------------*
*      -->P_0029   text
*----------------------------------------------------------------------*
form frm_call_view  using  uv_view.

  data:lv_view type dd02v-tabname . "要处理的视图/表格的名称



  lv_view = uv_view.

  call function 'VIEW_MAINTENANCE_CALL'
    exporting
      action                         = 'S'
*        CORR_NUMBER                    = '          '
*        GENERATE_MAINT_TOOL_IF_MISSING = ' '
*        SHOW_SELECTION_POPUP           = ' '
      view_name                      = lv_view
      no_warning_for_clientindep     = ''
      rfc_destination_for_upgrade    = ''
      client_for_upgrade             = ''
      variant_for_selection          = ''
      complex_selconds_used          = ''
      check_ddic_mainflag            = ''
      suppress_wa_popup              = ''
*      TABLES
*        DBA_SELLIST                    = LT_VIMSELLIST[]
      "EXCL_CUA_FUNCT                 =
    exceptions
      client_reference               = 1
      foreign_lock                   = 2
      invalid_action                 = 3
      no_clientindependent_auth      = 4
      no_database_function           = 5
      no_editor_function             = 6
      no_show_auth                   = 7
      no_tvdir_entry                 = 8
      no_upd_auth                    = 9
      only_show_allowed              = 10
      system_failure                 = 11
      unknown_field_in_dba_sellist   = 12
      view_not_found                 = 13
      maintenance_prohibited         = 14
      others                         = 15.
  if sy-subrc <> 0.
* Implement suitable error handling here
  endif.

endform.                    " FRM_CALL_VIEW
*&---------------------------------------------------------------------*
*&      Form  FRM_PRO_HD
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form frm_pro_hd .
 
  write:/'ODF数据处理完成',sy-uzeit.
endform.                    " FRM_PRO_HD
*&---------------------------------------------------------------------*
*&      Form  FRM_GET_HD
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form frm_get_hd .

  "-----------新的 odf ---------------
  select vbeln as odf
         from vbak
         into corresponding fields of table gt_data
         where vbeln in s_odf
           and erdat >= p_erdat
           and vbtyp = 'C.
  "-------------
  write:/'ODF数据获取完成',sy-uzeit.
endform.                    " FRM_GET_HD
*&---------------------------------------------------------------------*
*&      Form  FRM_GET_ITEM
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form frm_get_nd .
  data:lt_nd like table of ztsdhq0001_10 with header line.
  data:lt_data like table of ztsdhq0001_01 with header line.
  data:lv_fname type rs38l-name.
  data:lv_free type i,
       lv_wip(10) type c,
       lv_time type c.

  clear gt_msg[].
  "---------线程检查----------------------
  if ch_multi = 'X'.
    loop at s_name.
      perform frm_get_classname using s_name-low.
      call function 'SPBT_INITIALIZE'
        exporting
          group_name                     = gv_classname
        importing
*         MAX_PBT_WPS                    =
          free_pbt_wps                   = lv_free
        exceptions
          invalid_group_name             = 1
          internal_error                 = 2
          pbt_env_already_initialized    = 3
          currently_no_resources_avail   = 4
          no_pbt_resources_found         = 5
          cant_init_different_pbt_groups = 6
          others                         = 7.
      if sy-subrc <> 0 or lv_free <= 10.
        clear gv_classname. "--取消
      else.
        exit.
      endif.
    endloop.
    if gv_classname = ''.
      clear ch_multi.
    else.
      write:/ gv_classname, sy-uzeit.
    endif.
  endif.

  "----------------------------------------------
  "---zt
*** D	删除
***1  生产
***2  国内完成
***3  海外生产
***4  完成
*__________	____
*

  select * from ztsdhq0001_10 into table lt_nd where fnam <> ''.

  sort lt_nd by fnam sort nd.
  delete adjacent duplicates from lt_nd comparing fnam.
  clear:gv_snd_jobs,gv_rcv_jobs.
  loop at lt_nd.
    lv_fname = lt_nd-fnam.
    select single funcname
        from tfdir
        into lv_fname
       where funcname = lv_fname.
    check sy-subrc = 0.

    clear lt_data[].
    append lines of gt_data to lt_data.
    check lt_data[] is not initial.
    "-------------
*    add 1 to gv_taskname.
    if ch_multi = 'X'.
*      message '并行处理' type 'S'.
      "----------线程空闲检查-------------
      do.
        clear:lv_time,lv_free.
        call function 'SPBT_GET_CURR_RESOURCE_INFO'
          importing
*           MAX_PBT_WPS                 =
            free_pbt_wps                = lv_free
          exceptions
            internal_error              = 1
            pbt_env_not_initialized_yet = 2
            others                      = 3.
        if sy-subrc <> 0 or lv_free < 2.
* Implement suitable error handling here
          wait up to 10 seconds.
          add 1 to lv_time.
          if lv_time > 9.
            clear:ch_multi.
            exit.
          endif.
        else.
          exit.
        endif.
      enddo.
      lv_wip = lv_free.
      condense lv_wip.
      write:/ lv_time,lv_wip,lv_fname,sy-uzeit.
    endif.
    if ch_multi = 'X'.
      call function lv_fname
                    starting new task lv_fname
                    destination in group gv_classname
                    performing frm_subroutine_nd on end of task"子程序
               tables
                 it_tab = lt_data.
      if sy-subrc = 0.
        add 1 to gv_snd_jobs.
      endif.
      wait until gv_snd_jobs - gv_rcv_jobs <= p_wp.
    else.
      write:/ lv_fname,sy-uzeit.
      call function lv_fname
        tables
          it_tab = lt_data.
      write:/ lv_fname,'完成',sy-uzeit.
    endif.
  endloop.

  wait until gv_snd_jobs =< gv_rcv_jobs.
  sort gt_msg by txt.
  loop at gt_msg.
    write:/ gt_msg-txt,gt_msg-uzeit.
  endloop.
  write:/ '节点处理完成',sy-uzeit.
endform.                    " FRM_GET_ITEM *&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*&      Form  FRM_SUBROUTINE_MRP
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_IT_WEKRS  text
*      -->P_=  text
*      -->P_LT_WERKS  text
*      -->P_IT_AUFNR  text
*      -->P_=  text
*      -->P_LT_AUFNR  text
*----------------------------------------------------------------------*
form frm_subroutine_nd  using lv_fname.
  receive results from function lv_fname.
  if sy-subrc = 0.
    gv_rcv_jobs = gv_rcv_jobs + 1.
  endif.
*  write:/ lv_fname,'完成',sy-uzeit.
  gt_msg-txt = lv_fname.
  gt_msg-uzeit = sy-uzeit.
  append gt_msg.
endform.                    " FRM_SUBROUTINE_MRP
*&      Form  FRM_GET_CLASSNAME
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form frm_get_classname using p_name.
  clear gv_classname.
  if p_name <> ''.
    select single classname from rzllitab into gv_classname where classname = p_name.
  endif.

  if gv_classname = ''.
    call 'C_SAPGPARAM'                                    "#EC CI_CCALL
        id 'NAME'  field 'rdisp/myname'
        id 'VALUE' field gv_applserver.  "
    select single classname
      from rzllitab
      into gv_classname   "Server Group Name
      where applserver = gv_applserver
        and grouptype = 'S'.   "S:服务器组,空:登陆组
  endif.

*  clear:gv_tnum,gv_fnum.

endform.                    " FRM_GET_CLASSNAME
*&---------------------------------------------------------------------*
*&      Form  FRM_QUR_DATA
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form frm_qur_data .


endform.                    " FRM_QUR_DATA
*&---------------------------------------------------------------------*
*&      Form  FRM_ALV_SHOW
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form frm_alv_show .

endform.                    " FRM_ALV_SHOW
*&---------------------------------------------------------------------*
*&      Form  user_command
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->R_UCOMM      text
*      -->WS_SELFIELD  text
*----------------------------------------------------------------------*
form frm_alv_user_command using r_ucomm like sy-ucomm
                         ws_selfield type slis_selfield.

  case r_ucomm.
    when '&IC1'.

    when others.
  endcase.

endform. "user_command
*&---------------------------------------------------------------------*
*&      Form  FRM_ALV_FIELD
*&---------------------------------------------------------------------*
*       alv field
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form frm_alv_field  using iv_strname type tabname.

  data: lt_fcat type lvc_t_fcat,
        ls_fcat type lvc_s_fcat,
        lv_tabix like sy-tabix.
  data:lv_error type c.

  field-symbols: <ls_fcat> type lvc_s_fcat.

  refresh gt_fcat.

  call function 'LVC_FIELDCATALOG_MERGE'
    exporting
      i_structure_name       = iv_strname
    changing
      ct_fieldcat            = gt_fcat
    exceptions
      inconsistent_interface = 1
      program_error          = 2
      others                 = 3.
  if sy-subrc <> 0.
    message id sy-msgid type sy-msgty number sy-msgno
            with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  endif.
  delete gt_fcat where fieldname = 'MANDT'.
*  loop at gt_fcat assigning <ls_fcat>.
*    <ls_fcat>-scrtext_l =  <ls_fcat>-reptext.
*    <ls_fcat>-scrtext_m =  <ls_fcat>-reptext.
*    <ls_fcat>-scrtext_s =  <ls_fcat>-reptext.
*  endloop.
endform.                    " FRM_ALV_FIELD

*&---------------------------------------------------------------------*
*&      Form  FRM_END_HD
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form frm_end_hd .
 
endform.                    " FRM_END_HD

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值