批量更改BOM平台

*&---------------------------------------------------------------------*
*& Report ZPPU056
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
report zppu056.

tables:mast,mara,rc29p ,stpo,csci_stpo.

types:begin of gy_tab ,
  num       type int4 ,
  box       type  c ,"复选框
  icon      type  statusicon,
  msg       type  string ,
  matnr     type  mast-matnr ,"物料
  maktx     type  makt-maktx,"bom物料描述
  werks     type  mast-werks ,"工厂
  stlan     type  mast-stlan,"BOM 用途
  stlal     type  mast-stlal,"方案组
  stlst      type  stko-stlst,"BOM 状态
  stlnr     type  stko-stlnr,"物料单
  stlkn     type  stpo-stlkn,"BOM 项目节点号
  stpoz     type  stpo-stpoz," 内部计数器
  datuv      type  stpo-datuv,"有效起始日期
  bmeng     type   stko-bmeng,"基本数量
  posnr     type   stpo-posnr,"BOM 项目号
  stlty     type  stpo-stlty,"物料清单类别
  postp     type  stpo-postp,"项目类别(物料单)
  idnrk     type   stpo-idnrk,"组件
  maktx1    type  makt-maktx,"组件描述
  idnrk_n   type   stpo-idnrk,"组件
  maktx1_n  type  makt-maktx,"组件描述
  zzbismt   type  mara-zzbismt ,"旧物料号
  zzbismt_n type  mara-zzbismt ,"旧物料号
  menge      type  stpo-menge,"组件数量
  menge_n    type  stpo-menge,"组件数量
  meins      type  stpo-meins,"组件计量单位
  ausch     type   stpo-ausch,"组件报废百分比
  ausch_n   type   stpo-ausch,"组件报废百分比
  ausch_fl  type c ,
  alpgr     type  rc29p-alpgr ,"替代项目:组
  alpgr_n   type  rc29p-alpgr ,"替代项目:组
  alpgr_fl  type c ,
  alprf     type  rc29p-alprf ,"替代项目:评比定单 有先级
  alprf_n   type  rc29p-alprf ,"替代项目:评比定单
  alprf_fl  type c ,
  alpst     type  rc29p-alpst ,"替代项目:策略
  alpst_n   type  rc29p-alpst ,"替代项目:策略
  alpst_fl  type c ,
  ewahr     type  rc29p-ewahr ,"使用可能性按 % (可选项目)
  ewahr_n   type  rc29p-ewahr ,"使用可能性按 % (可选项目)
  ewahr_fl  type c ,
  potx1     type  rc29p-potx1 ,"BOM 项目文本(行1)
  potx1_n   type  rc29p-potx1 ,"BOM 项目文本(行1)
  potx1_fl  type c ,
  potx2     type  rc29p-potx2 ,"BOM 项目文本(行2)
  potx2_n   type  rc29p-potx2 ,"BOM 项目文本(行2)
  potx2_fl  type c ,
  zzcombn   type  csci_stpo-zzcombn ,"组合号
  zzcombn_n type  csci_stpo-zzcombn ,"组合号
  zzcombn_fl  type c ,
  zmtyp     type   csci_stpo-zmtyp ,"物料类别
  zmtyp_n   type   csci_stpo-zmtyp ,"物料类别
  zmtyp_fl  type c ,


  zsc       type c,
  sanko     type stpo-sanko ,
  sanfe     type stpo-sanfe ,
  sanka     type stpo-sanka ,
  zbombz    type stko-zbombz ,
  zzbiniv   type stko-zzbiniv ,
  zzbinxy   type stko-zzbinxy ,
  zzbinvf   type stko-zzbinvf ,
  zzxpbdz   type stko-zzxpbdz ,
  zzxpnam   type stko-zzxpnam ,
  zzxppet   type stko-zzxppet ,
  zzjiam2   type stko-zzjiam2 ,
  zzhtyq    type stko-zzhtyq ,
  labor     type stko-labor ,
  bmein     type stko-bmein ,
  matkl     type mara-matkl,"物料组
end of gy_tab .




data:gt_tab          type table of gy_tab.
data:gw_tab          type gy_tab .
data: gw_fieldcat    type lvc_s_fcat,
      gt_fieldcat    type lvc_t_fcat.
data: ok_code        type sy-ucomm ,
      save_ok        type sy-ucomm .
data:gv_ausch type c ,
     gv_alpgr type c ,
     gv_alprf type c,
     gv_alpst type c,
     gv_ewahr type c,
     gv_potx1 type c ,
     gv_potx2 type c ,
     gv_zzcombn type c ,
     gv_zmtyp type c ,
     gv_meins type c .
data:gw_rc29p type rc29p .
data:gw_csci_stpo type csci_stpo .



selection-screen begin of block bk1 with frame title text-001.

select-options: s_werks  for mast-werks default '1000' obligatory ,
                s_matnr  for mast-matnr  ,"销售BOM
                s_stlan  for mast-stlan default '1' ,"BOM状态
                s_stlal  for mast-stlal  ,"方案组
                s_matkl  for mara-matkl  ."物料组
selection-screen end of block bk1 .
selection-screen begin of block bk2 with frame title text-003.
selection-screen comment /1(58) text-002.
selection-screen end of block bk2 .


start-of-selection .

call function 'ZUSER_RECORD' .

perform frm_get_data .

perform frm_set_fact.

perform frm_dispaly_alv .

*&---------------------------------------------------------------------*
*& Form FRM_GET_DATA
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& -->  p1        text
*& <--  p2        text
*&---------------------------------------------------------------------*
form frm_get_data .
data:  lcl_cng_stlty like stas-stlty,
       lcl_cng_stlnr like stas-stlnr,
       lcl_cng_stlal like stas-stlal,
       lcl_cng_stlkn like stas-stlkn.


         select  mast~matnr  ,mast~werks  ,mast~stlan  ,mast~stlal  ,mast~stlnr,
                 stko~datuv  ,stpo~aennr  ,stpo~idnrk  ,stpo~stlty  ,stpo~stlkn,  stpo~stpoz,
                 stpo~posnr  ,stpo~sortf  ,stpo~netau  ,
                 stpo~postp  ,stpo~menge  ,stpo~meins  ,stpo~ausch  ,
                 stpo~alpgr  ,stpo~alprf  ,stpo~alpst  ,stpo~ewahr  ,stpo~potx1,stpo~potx2,stpo~zzcombn ,stpo~zmtyp ,
                 stpo~sanko  ,stpo~sanfe  ,stpo~sanka  ,
                 stas~stasz  ,stas~lkenz  ,
                 stko~stlst  ,stko~bmeng  ,stko~stkoz  ,stko~zbombz ,stko~zzbiniv,
                 stko~zzbinxy,stko~zzbinvf,stko~zzxpbdz,stko~zzxpnam,stko~zzxppet,
                 stko~zzjiam2,stko~zzhtyq ,stko~labor  ,stko~zsc    ,stko~bmein
     into  table @data(lt_st2)
     from mast  inner join stpo    on  mast~stlnr  = stpo~stlnr
                inner join stas    on  stpo~stlty  = stas~stlty
                                   and mast~stlnr  = stas~stlnr
                                   and stpo~stlkn  = stas~stlkn
                                   and mast~stlal  = stas~stlal
                inner join stko    on  stas~stlty  = stko~stlty
                                   and stas~stlnr  = stko~stlnr
                                   and stas~stlal  = stko~stlal
                inner join mara    on  mast~matnr  = mara~matnr
     where mast~matnr  in @s_matnr and mast~werks in @s_werks  and stpo~stlty eq 'M'
     and   mara~matkl  in @s_matkl and mast~stlan in @s_stlan  and mast~stlal in @s_stlal.

data:iw_st  like line of  lt_st2 .
types :begin of gy_st,
    num   type i ,
   datub type sy-datum .
  include structure iw_st .
types : end of  gy_st .
data:  lt_st  type table of gy_st ,
       lt_st1 type table of gy_st ,
       lw_st  type gy_st ,
       lw_st1 type gy_st.


       refresh :  lt_st ,lt_st1 .
       move-corresponding lt_st2 to lt_st .
       sort  lt_st by stlty  stlnr  stlal stlkn stasz.
       field-symbols :<fs_st> type gy_st.

      loop at lt_st assigning <fs_st> .
                clear <fs_st>-netau .
                <fs_st>-num = sy-tabix .
                if lcl_cng_stlty     ne <fs_st>-stlty
                    or lcl_cng_stlnr ne <fs_st>-stlnr
                    or lcl_cng_stlal ne <fs_st>-stlal
                    or lcl_cng_stlkn ne <fs_st>-stlkn.

                    lcl_cng_stlty = <fs_st>-stlty.
                    lcl_cng_stlnr = <fs_st>-stlnr.
                    lcl_cng_stlal = <fs_st>-stlal.
                    lcl_cng_stlkn = <fs_st>-stlkn.
                    loop at lt_st1 into lw_st.
                      read table lt_st1 into lw_st1 index sy-tabix + 1 .
                      if sy-subrc eq 0.
                        lw_st-datub = lw_st1-datuv .
                        modify lt_st from lw_st index lw_st-num .
                      else.
                        lw_st-datub = '99991230' .
                        modify lt_st from lw_st index lw_st-num .
                      endif.
                    endloop.
                    refresh :lt_st1 .
                endif .
             append  <fs_st> to lt_st1.
        endloop.

        loop at lt_st1 into lw_st.
          read table lt_st1 into lw_st1 index sy-tabix + 1 .
          if sy-subrc eq 0.
            lw_st-datub = lw_st1-datuv .
            modify lt_st from lw_st index lw_st-num .
          else.
            lw_st-datub = '99991230' .
            modify lt_st from lw_st index lw_st-num .
          endif.
        endloop.
        refresh :lt_st1 .

        loop at lt_st assigning <fs_st>.
          if <fs_st>-datub >= sy-datum .
            <fs_st>-netau = 'X'.
          endif.
        endloop.
        if lt_st is not initial.
          delete lt_st where netau is initial or lkenz eq 'X'.
          refresh:gt_tab .
          move-corresponding lt_st to gt_tab .
        endif.
        if gt_tab is not initial.
          "物料描述
          "bom
          select makt~matnr ,makt~maktx  into table @data(lt_makt1)
            from makt
            for all entries in @gt_tab
            where makt~matnr eq @gt_tab-matnr and spras eq @sy-langu .
          sort lt_makt1 by matnr .
          "组件描述
          select makt~matnr ,makt~maktx,mara~zzbismt,mara~matkl into table @data(lt_makt2)
            from makt inner join mara on makt~matnr = mara~matnr
            for all entries in @gt_tab
            where makt~matnr eq @gt_tab-idnrk and makt~spras eq @sy-langu .
          sort lt_makt2 by matnr .
        endif.

        loop at gt_tab assigning field-symbol(<gs_tab>).
          "物料描述
          "bom
          read table  lt_makt1 into data(lw_makt1) with key matnr = <gs_tab>-matnr binary search .
          if sy-subrc eq 0.
            <gs_tab>-maktx = lw_makt1-maktx .
          endif.
          "组件描述
          read table lt_makt2 into data(lw_makt2) with key matnr = <gs_tab>-idnrk binary search .
          if sy-subrc eq 0.
            <gs_tab>-maktx1  = lw_makt2-maktx .
            <gs_tab>-zzbismt = lw_makt2-zzbismt .
            <gs_tab>-matkl   = lw_makt2-matkl .
          endif.
          call function 'CONVERSION_EXIT_ALPHA_OUTPUT'
            exporting
              input         = <gs_tab>-matnr
           importing
             output         = <gs_tab>-matnr  .
          call function 'CONVERSION_EXIT_ALPHA_OUTPUT'
            exporting
              input         = <gs_tab>-idnrk
           importing
             output         = <gs_tab>-idnrk .
         <gs_tab>-icon  =   icon_led_inactive .
        endloop.



endform.
*&---------------------------------------------------------------------*
*& Form FRM_SET_FACT
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& -->  p1        text
*& <--  p2        text
*&---------------------------------------------------------------------*
form frm_set_fact .
define fcatadd.
  clear gw_fieldcat.
  gw_fieldcat-fieldname = &1.
  gw_fieldcat-tabname = &2.
  gw_fieldcat-scrtext_l = &3.
  gw_fieldcat-scrtext_m = &3.
  gw_fieldcat-scrtext_s = &3.
  gw_fieldcat-outputlen = &4.
  gw_fieldcat-ref_field = &5.
  gw_fieldcat-ref_table = &6.
  gw_fieldcat-just      = 'C'.
  gw_fieldcat-intlen      = '40'.

  if   &1 eq 'IDNRK_N'
    or &1 eq 'MENGE_N'    or  &1 eq 'AUSCH_N'
    or &1 eq 'AUSCH_FL'   or  &1 eq 'ALPGR_N'
    or &1 eq 'ALPGR_FL'   or  &1 eq 'ALPRF_N'  or &1 eq 'ALPRF_FL'
    or &1 eq 'ALPST_N'    or  &1 eq 'ALPST_FL' or &1 eq 'EWAHR_N'
    or &1 eq 'EWAHR_FL'   or  &1 eq 'POTX1_N'  or &1 eq 'POTX1_FL'
    or &1 eq 'POTX2_N'    or  &1 eq 'POTX2_FL' or &1 eq 'ZZCOMBN_N'
    or &1 eq 'ZZCOMBN_FL' or  &1 eq 'ZMTYP_N'  or &1 eq 'ZMTYP_FL'
    or &1 eq 'MEINS'.
    gw_fieldcat-edit      = 'X'.
  endif.

  append gw_fieldcat to gt_fieldcat.
end-of-definition.

  fcatadd  'ICON'           'GT_TAB'   '指示灯'                     '4' '' ''.
  fcatadd  'MSG'            'GT_TAB'   '消息'                       '8' '' ''.
  fcatadd  'WERKS'          'GT_TAB'   '工厂'                       '4' '' ''.
  fcatadd  'MATNR'          'GT_TAB'   'BOM物料'                    '10' '' ''.
  fcatadd  'STLAN'          'GT_TAB'   'BOM用途'                    '6' '' ''.
  fcatadd  'STLAL'          'GT_TAB'   '方案组'                    '6' '' ''.
  fcatadd  'MAKTX'          'GT_TAB'   'BOM物料描述'                '15' '' ''.
  fcatadd  'STLST'          'GT_TAB'   'BOM状态'                    '5' '' ''.
  fcatadd  'STLNR'          'GT_TAB'   '物料单'                     '10' '' ''.
  fcatadd  'STLKN'          'GT_TAB'   'BOM项目节点号'              '10' '' ''.
  fcatadd  'STPOZ'          'GT_TAB'   '内部计数器'                 '8' '' ''.
  fcatadd  'DATUV'          'GT_TAB'   '有效起始日期'               '10' '' ''.
  fcatadd  'BMENG'          'GT_TAB'   '基本数量'                   '10' '' ''.
  fcatadd  'POSNR'          'GT_TAB'   'BOM项目号'                  '8' '' ''.
  fcatadd  'STLTY'          'GT_TAB'   '物料清单类别'               '8' '' ''.
  fcatadd  'POSTP'          'GT_TAB'   '项目类别(物料单)'         '8' '' ''.
  fcatadd  'MATKL'          'GT_TAB'   '组件物料组'                 '10' '' ''."by 曾存修 20201015
  fcatadd  'IDNRK'          'GT_TAB'   '组件'                       '10' '' ''.
  fcatadd  'MAKTX1'         'GT_TAB'   '组件描述(旧)'               '10' '' ''.
  fcatadd  'ZZBISMT'        'GT_TAB'   '旧物料号(旧)'                   '10' '' ''.
  fcatadd  'IDNRK_N'        'GT_TAB'   '更改组件'                   '10' '' ''.
  fcatadd  'MAKTX1_N'       'GT_TAB'   '组件描述(新)'                '10' '' ''.
  fcatadd  'ZZBISMT_N'      'GT_TAB'   '旧物料号(新)'                   '10' '' ''.
  fcatadd  'MENGE'          'GT_TAB'   '组件数量'                   '10' '' ''.
  fcatadd  'MENGE_N'        'GT_TAB'   '更改组件数量'               '10' 'MENGE' 'EKPO'.
  fcatadd  'MEINS'          'GT_TAB'   '组件计量单位'               '10' '' ''.
  fcatadd  'AUSCH'          'GT_TAB'   '组件报废百分比'             '10' '' ''.
  fcatadd  'AUSCH_N'        'GT_TAB'   '更改组件报废百分比'         '10' '' ''.
  fcatadd  'AUSCH_FL'       'GT_TAB'   '组件报废百分比清空标记'     '10' '' ''.
  fcatadd  'ALPGR'          'GT_TAB'   '替代项目:组'                '10' '' ''.
  fcatadd  'ALPGR_N'        'GT_TAB'   '更改替代项目:组'            '10' '' ''.
  fcatadd  'ALPGR_FL'       'GT_TAB'   '替代项目:组清空标记'        '10' '' ''.
  fcatadd  'ALPRF'          'GT_TAB'   '优先级'                     '4' '' ''.
  fcatadd  'ALPRF_N'        'GT_TAB'   '更改优先级'                 '8' '' ''.
  fcatadd  'ALPRF_FL'       'GT_TAB'   '优先级清空标记'             '10' '' ''.
  fcatadd  'ALPST'          'GT_TAB'   '策略'                       '4' '' ''.
  fcatadd  'ALPST_N'        'GT_TAB'   '更改策略'                   '8' '' ''.
  fcatadd  'ALPST_FL'       'GT_TAB'   '策略清空标记'               '10' '' ''.
  fcatadd  'EWAHR'          'GT_TAB'   '使用可能性'                 '10' '' ''.
  fcatadd  'EWAHR_N'        'GT_TAB'   '更改使用可能性'             '10' '' ''.
  fcatadd  'EWAHR_FL'       'GT_TAB'   '使用可能性清空标记'         '10' '' ''.
  fcatadd  'POTX1'          'GT_TAB'   '文本1'                      '10' '' ''.
  fcatadd  'POTX1_N'        'GT_TAB'   '更改文本1'                  '10' '' ''.
  fcatadd  'POTX1_FL'       'GT_TAB'   '文本1清空标记'              '10' '' ''.
  fcatadd  'POTX2'          'GT_TAB'   '文本2'                      '10' '' ''.
  fcatadd  'POTX2_N'        'GT_TAB'   '更改文本2'                  '10' '' ''.
  fcatadd  'POTX2_FL'       'GT_TAB'   '文本2清空标记'              '10' '' ''.
  fcatadd  'ZZCOMBN'        'GT_TAB'   '组合号'                     '10' '' ''.
  fcatadd  'ZZCOMBN_N'      'GT_TAB'   '更改组合号'                 '10' '' ''.
  fcatadd  'ZZCOMBN_FL'     'GT_TAB'   '组合号清空标记'             '10' '' ''.
  fcatadd  'ZMTYP'          'GT_TAB'   '物料类别'                   '10' '' ''.
  fcatadd  'ZMTYP_N'        'GT_TAB'   '更改物料类别'               '10' '' ''.
  fcatadd  'ZMTYP_FL'       'GT_TAB'   '物料类别清空标记'           '10' '' ''.
  fcatadd  'SANKO'          'GT_TAB'   '标识:与工程相关项目'       '10' '' ''.
  fcatadd  'SANFE'          'GT_TAB'   '标识:与生产相关项目'       '10' '' ''.
  fcatadd  'SANKA'          'GT_TAB'   '成本核算相关项的标识符'     '10' '' ''.
  fcatadd  'ZBOMBZ'         'GT_TAB'   'BOM备注'                    '10' '' ''.
  fcatadd  'ZZJIAM2'        'GT_TAB'   '支架型号'                   '10' '' ''.
  fcatadd  'ZZHTYQ'         'GT_TAB'   '混贴要求'                   '10' '' ''.
  fcatadd  'LABOR'          'GT_TAB'   '实验室'                     '10' '' ''.
  fcatadd  'BMEIN'          'GT_TAB'   '抬头单位'                   '10' '' ''.
  fcatadd  'ZSC'            'GT_TAB'   '是否试产'                   '8' '' ''.
  fcatadd  'ZZBINIV'        'GT_TAB'   '亮度/有效幅宽'              '10' '' ''.
  fcatadd  'ZZBINXY'        'GT_TAB'   '色区'                       '10' '' ''.
  fcatadd  'ZZBINVF'        'GT_TAB'   '电压'                       '10' '' ''.
  fcatadd  'ZZXPBDZ'        'GT_TAB'   '芯片波段'                   '10' '' ''.
  fcatadd  'ZZXPNAM'        'GT_TAB'   '芯片品牌'                   '10' '' ''.
  fcatadd  'ZZXPPET'        'GT_TAB'   '芯片尺寸'                   '10' '' ''.


endform.
*&---------------------------------------------------------------------*
*& Form FRM_DISPALY_ALV
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& -->  p1        text
*& <--  p2        text
*&---------------------------------------------------------------------*
form frm_dispaly_alv .
data:ls_layout  type lvc_s_layo.
data:l_events type slis_t_event.

  ls_layout-box_fname = 'BOX'.
 call function 'REUSE_ALV_GRID_DISPLAY_LVC'
    exporting
      i_callback_program = sy-repid
*      I_CALLBACK_TOP_OF_PAGE   = 'FRM_TOP_OF_PAGE'
*      I_CALLBACK_HTML_TOP_OF_PAGE = 'HTML_TOP_OF_PAGE'
*      I_GRID_TITLE           = I_GRID_TITLE
      i_callback_user_command = 'USER_COMMAND'
      i_callback_pf_status_set = 'F_SET_STATUS'
      is_layout_lvc      = ls_layout
      it_fieldcat_lvc    = gt_fieldcat
      i_save             = 'A'
      it_events          = l_events[]
      i_html_height_top  =  24
    tables
      t_outtab           = gt_tab
    exceptions
      program_error      = 1
      others             = 2.

endform.
form f_set_status using p_extab type slis_t_extab.
  set pf-status  'ZGUI100'.
endform.
form user_command using ucomm type syucomm selfield type slis_selfield.

  data: lr_grid type  ref to cl_gui_alv_grid ,
        zline   type string ,
        zanswer type c .
data:it_tab type table of gy_tab .
data:lv_str type string.
data:zanswer1 type c .

  call function 'GET_GLOBALS_FROM_SLVC_FULLSCR'
    importing
      e_grid = lr_grid.
  "刷新
  call method lr_grid->check_changed_data.

        selfield-refresh = 'X'.

   case ucomm .
   when 'F1'.
     refresh :it_tab .
     move-corresponding gt_tab to it_tab .
     delete it_tab where box eq ''.
     if  it_tab is not initial.
       call screen 100 starting at 15 5 ending at 100  18.
     else.
       message s000(zmm) with '请至少选择一行进行内容的批量更改!' display like 'E'  .
     endif.
   when 'OK' .
     perform  frm_update_bom  using '1'.
   when 'ADD'.
     refresh :it_tab .
     move-corresponding gt_tab to it_tab .
     delete it_tab where box eq ''.
     if  it_tab is not initial.
       call screen 200 starting at 15 5 ending at 100  18.
     else.
       message s000(zmm) with '请至少选择一行进行内容的批量更改!' display like 'E'  .
     endif.
   when 'DELETE'.
     lv_str = '批量删除BOM项目,请确认是否删除!'.
          clear:zanswer1.
         call function 'POPUP_TO_CONFIRM_STEP'
           exporting
*            defaultoption        = 'Y'
             textline1            = lv_str
*            textline2            = ' '
             titel                = '控制'
*            start_column         = 25
*            start_row            = 6
             cancel_display       = ''
          importing
            answer               = zanswer1 .

          if zanswer1 eq 'N'.
            exit .
          endif.

     perform  frm_update_bom  using '2'.
    when '&IC1'. "双击
     if selfield-fieldname eq 'MATNR'   .
       read table gt_tab into data(iw_tab) index selfield-tabindex .
       if sy-subrc eq 0.
          set parameter id: 'MAT' field iw_tab-matnr.
          set parameter id: 'CSV' field iw_tab-stlan.
          set parameter id: 'WRK' field iw_tab-werks.
          call transaction 'CS03' with authority-check
                                 and skip first screen.
       endif.

     endif.
   endcase .
endform .
*&---------------------------------------------------------------------*
*& Module STATUS_0100 OUTPUT
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
module status_0100 output.
 set pf-status 'ZGUI1001'.

 if ok_code eq 'S1'.
  clear:rc29p ,csci_stpo.
 endif.

endmodule.
*&---------------------------------------------------------------------*
*&      Module  USER_COMMAND_0100  INPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
module user_command_0100 input.
  save_ok = ok_code .

  case save_ok.
    when 'S1'.
      clear: gw_tab .
        if rc29p-idnrk is not initial.
          select single makt~maktx  mara~zzbismt into (gw_tab-maktx1_n,gw_tab-zzbismt_n)
            from mara inner join makt on mara~matnr = makt~matnr
            where mara~matnr eq rc29p-idnrk.
        endif.
        gw_tab-idnrk_n = rc29p-idnrk+8 ."
        gw_tab-menge_n = rc29p-menge."组件数量
        gw_tab-ausch_n = rc29p-ausch  ."组件报废百分比
        gw_tab-ausch_fl = gv_ausch ."
        gw_tab-alpgr_n = rc29p-alpgr  ."替代项目:组
        gw_tab-alpgr_fl = gv_alpgr ."
        gw_tab-alprf_n = rc29p-alprf  ."替代项目:评比定单 优先级
        gw_tab-alprf_fl = gv_alprf ."
        gw_tab-alpst_n = rc29p-alpst  ."替代项目:策略
        gw_tab-alpst_fl = gv_alpst ."
        gw_tab-ewahr_n = rc29p-ewahr  ."使用可能性按 % (可选项目)
        gw_tab-ewahr_fl = gv_ewahr ."
        gw_tab-potx1_n = rc29p-potx1  ."BOM 项目文本(行1)
        gw_tab-potx1_fl = gv_potx1 ."
        gw_tab-potx2_n = rc29p-potx2  ."BOM 项目文本(行2)
        gw_tab-potx2_fl = gv_potx2 ."
        gw_tab-zzcombn_n = csci_stpo-zzcombn  ."组合号
        gw_tab-zzcombn_fl = gv_zzcombn .
        gw_tab-zmtyp_n = csci_stpo-zmtyp  ."物料类别
        gw_tab-zmtyp_fl = gv_zmtyp .
        if  rc29p-meins ne ''.
           gw_tab-meins   = rc29p-meins .
          modify gt_tab from gw_tab transporting idnrk_n menge_n ausch_n ausch_fl alpgr_n alpgr_fl
           alprf_n alprf_fl alpst_n alpst_fl ewahr_n ewahr_fl potx1_n potx1_fl potx2_n potx2_fl meins
           zzcombn_n zzcombn_fl zmtyp_n zmtyp_fl maktx1_n zzbismt_n where box eq 'X'.
        else.
          modify gt_tab from gw_tab transporting idnrk_n menge_n ausch_n ausch_fl alpgr_n alpgr_fl
           alprf_n alprf_fl alpst_n alpst_fl ewahr_n ewahr_fl potx1_n potx1_fl potx2_n potx2_fl "meins
           zzcombn_n zzcombn_fl zmtyp_n zmtyp_fl  maktx1_n zzbismt_n  where box eq 'X'.
        endif.

      leave to screen 0 .
    when 'S2'."取消
      leave to screen 0 .
    when 'ALL'.
      gv_ausch = 'X'.
      gv_alpgr = 'X'.
      gv_alprf = 'X'.
      gv_alpst = 'X'.
      gv_ewahr = 'X' .
      gv_potx1 = 'X'.
      gv_potx2 = 'X'.
      gv_zzcombn = 'X'.
      gv_zmtyp = 'X'.
    when 'CANCEL'.
      gv_ausch = ''.
      gv_alpgr = ''.
      gv_alprf = ''.
      gv_alpst = ''.
      gv_ewahr = '' .
      gv_potx1 = ''.
      gv_potx2 = ''.
      gv_zzcombn = ''.
      gv_zmtyp = ''.
  endcase.
  clear :ok_code.
endmodule.
*&---------------------------------------------------------------------*
*& Form FRM_UPDATE_BOM
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& -->  p1        text
*& <--  p2        text
*&---------------------------------------------------------------------*
form frm_update_bom using lv_num type c.
data:lv_datuv type datuv_bi .
data:lv_matnr type char40.
data:lv_stlan type csap_mbom-stlan .
data:lw_stko  type stko_api01 .
data:lt_tab   type table of gy_tab ,
     lt_tab1  type table of gy_tab .
data:lw_stpo  type stpo_api03 ,
     lt_stpo  type table of stpo_api03 .
data:lv_matnr1 type char18 .
**add luan 20221215
DATA: lt_stpo2        TYPE TABLE OF stpo_api02,
      lw_stpo2       LIKE LINE OF lt_stpo2.
DATA:lw_stpov TYPE stpo_api02.
  refresh :lt_tab ,lt_tab1 .
  if gt_tab is not initial.
    append lines of gt_tab to lt_tab.
    append lines of gt_tab to lt_tab1.
    delete lt_tab where box eq '' .
    delete lt_tab1 where box eq '' .
    sort lt_tab1 by  matnr werks stlan stlal.
    delete  adjacent duplicates from lt_tab1 comparing matnr werks stlan stlal .
  endif.

  loop at  lt_tab1  into data(lw_tab1).
    lv_datuv =  lw_tab1-datuv .
    clear:lw_stko.
    lw_stko-base_quan   = lw_tab1-bmeng .
    lw_stko-bom_status  = lw_tab1-stlst. "BOM 状态
    lw_stko-zbombz      = lw_tab1-zbombz .
    lw_stko-zzbiniv     = lw_tab1-zzbiniv."有效幅宽
    lw_stko-zzbinxy     = lw_tab1-zzbinxy."[WLD]
    lw_stko-zzbinvf     = lw_tab1-zzbinvf."
    lw_stko-zzxpbdz     = lw_tab1-zzxpbdz   ."
    lw_stko-zzxpnam     = lw_tab1-zzxpnam   ."
    lw_stko-zzxppet     = lw_tab1-zzxppet   ."
    lw_stko-zzjiam2     = lw_tab1-zzjiam2.   "支架型号
    lw_stko-zzhtyq      = lw_tab1-zzhtyq.   " 混贴要求
    lw_stko-laboratory  = lw_tab1-labor .
    lw_stko-zsc         = lw_tab1-zsc .
    lw_stko-base_unit   = lw_tab1-bmein .


    refresh :lt_stpo .
    loop at lt_tab into data(lw_tab) where  matnr eq lw_tab1-matnr  and werks eq lw_tab1-werks and
      stlan eq lw_tab1-stlan and stlal eq lw_tab1-stlal and box eq 'X'.
      clear lw_stpo .
      "项目类别
*      lw_stpo-item_categ = lw_tab-stlty.
*      if lw_stpo-item_categ eq 'M'.
*        lw_stpo-item_categ = 'L'.
*      endif.
      lw_stpo-item_categ =  lw_tab-postp .

      "bom 项目
      lw_stpo-item_no = lw_tab-posnr .

      lw_stpo-component = lw_tab-idnrk_n .
      "组件
      if lw_stpo-component is initial .
        lw_stpo-component = lw_tab-idnrk .
      endif.
      lv_matnr1 = lw_stpo-component .
      call function 'CONVERSION_EXIT_ALPHA_INPUT'
        exporting
          input         = lv_matnr1
       importing
         output         = lv_matnr1 .
       lw_stpo-component = lv_matnr1.
      "组件数量
      lw_stpo-comp_qty = lw_tab-menge_n .
      if lw_tab-menge_n eq 0.
        lw_stpo-comp_qty = lw_tab-menge .
      endif.
      shift lw_stpo-comp_qty  left deleting leading space.
      "单位
      lw_stpo-comp_unit = lw_tab-meins .
      "物料单
      lw_stpo-bom_no  = lw_tab-stlnr .
      "BOM 项目节点号
      lw_stpo-item_node = lw_tab-stlkn .
      "内部计数器
      lw_stpo-item_count = lw_tab-stpoz .
      ""可选的 BOM
      lw_stpo-bom_alt   = lw_tab-stlal .
      "组件报废百分比
      if gv_ausch ne 'X'.
        lw_stpo-comp_scrap = lw_tab-ausch_n.
        if lw_tab-ausch_n = '0.00'   .
          lw_stpo-comp_scrap = lw_tab-ausch .
        endif.
      endif.
      "替代项目:组
      if gv_alpgr ne 'X' .
        lw_stpo-ai_group = lw_tab-alpgr_n.
        if lw_stpo-ai_group  is initial.
          lw_stpo-ai_group  = lw_tab-alpgr.
        endif.
      endif .
      "优先级
      if gv_alprf ne 'X'.
        lw_stpo-ai_prio = lw_tab-alprf_n.
        if lw_stpo-ai_prio eq '00'.
          lw_stpo-ai_prio = lw_tab-alprf .
        endif.
      endif.
      "策略
      if gv_alpst ne 'X'.
        lw_stpo-ai_strateg = lw_tab-alpst_n .
        if lw_stpo-ai_strateg is initial .
          lw_stpo-ai_strateg = lw_tab-alpst .
        endif.
      endif.
      "使用可能性
      if gv_ewahr ne 'X'.
        lw_stpo-usage_prob = lw_tab-ewahr_n .
        if lw_tab-ewahr_n eq '0' .
          lw_stpo-usage_prob = lw_tab-ewahr .
        endif.
      endif.
      "文本1
      if gv_potx1 ne 'X'.
          lw_stpo-item_text1 = lw_tab-potx1_n .
          if lw_stpo-item_text1 is initial.
            lw_stpo-item_text1 = lw_tab-potx1 .
          endif.
      endif.
      "文本2
      if gv_potx2 ne 'X'.
          lw_stpo-item_text2 = lw_tab-potx2_n .
          if lw_stpo-item_text2 is initial.
            lw_stpo-item_text2 = lw_tab-potx2 .
          endif.
      endif.
      "组合号
      if gv_zzcombn ne 'X'.
        lw_stpo-zzcombn = lw_tab-zzcombn_n .
        if  lw_stpo-zzcombn is initial .
           lw_stpo-zzcombn = lw_tab-zzcombn .
        endif.
      endif.
      "物料类别
      if gv_zmtyp ne 'X'.
        lw_stpo-zmtyp = lw_tab-zmtyp_n .
        if lw_stpo-zmtyp is initial .
          lw_stpo-zmtyp = lw_tab-zmtyp .
        endif.
      endif.

      if lv_num = '2'.
        lw_stpo-fldelete = 'X'.
      endif.
       lw_stpo-rel_engin  = lw_tab-sanko .
       lw_stpo-rel_prod   = 'X'.".lw_tab-sanfe .
       lw_stpo-rel_cost   = 'X'."lw_tab-sanka .
************8by曾存修 包材不需要成本核算20201015********
       if lw_tab-werks eq '1000' or lw_tab-werks eq '1100' .
        if lw_tab-matkl eq '2080100' or lw_tab-matkl eq '2080200'.
          lw_stpo-rel_cost   = ''."lw_tab-sanka .
        endif.
       endif.

************8by曾存修 包材不需要成本核算20201015********
      append lw_stpo to lt_stpo .
    endloop.

    lv_matnr1 = lw_tab1-matnr .
    call function 'CONVERSION_EXIT_ALPHA_INPUT'
      exporting
        input         = lv_matnr1
     importing
       output        = lv_matnr1 .
    lv_matnr = lv_matnr1 .

*   call function 'CSAP_MAT_BOM_MAINTAIN'
*     exporting
*       material                  = lv_matnr
*       plant                     = lw_tab1-werks
*       bom_usage                 = lw_tab1-stlan
*       alternative               = lw_tab1-stlal
*       valid_from                = lv_datuv
*       i_stko                    = lw_stko
*       fl_commit_and_wait        = 'X'
*       fl_bom_create             = 'X'
*       fl_new_item               = 'X'
*       fl_complete               = 'X'
*    tables
*       t_stpo                    = lt_stpo
*    exceptions
*      error                     = 1
*      others                    = 2 .
*** change luan 20221215

   CALL FUNCTION 'CSAP_MAT_BOM_OPEN'
     EXPORTING
       material               = lv_matnr
       PLANT                  = lw_tab1-werks
       bom_usage              = lw_tab1-stlan
       ALTERNATIVE            = lw_tab1-stlal
       VALID_FROM             = lv_datuv
     TABLES
       T_STPO                 = lt_stpo2
    EXCEPTIONS
      ERROR                  = 1
      OTHERS                 = 2.
   LOOP AT lt_stpo INTO lw_stpo.
     MOVE-CORRESPONDING lw_stpo TO lw_stpo2.
       CALL FUNCTION 'CSAP_BOM_ITEM_MAINTAIN'
         EXPORTING
           i_stpo                   = lw_stpo2
         IMPORTING
           O_STPO                   = lw_stpov
        EXCEPTIONS
           ERROR                    = 1
           OTHERS                   = 2.
   ENDLOOP.
   CALL FUNCTION 'CSAP_MAT_BOM_CLOSE'
        EXCEPTIONS
          error = 1.
***
**

    clear:gw_tab.
    if sy-subrc eq 0.
      call function 'BAPI_TRANSACTION_COMMIT'
       exporting
          wait = 'X'.
      gw_tab-icon = icon_led_green.
    else.
     gw_tab-icon = icon_led_red.
    endif.


    call function 'MESSAGE_TEXT_BUILD'
      exporting
        msgid                     = sy-msgid
        msgnr                     = sy-msgno
        msgv1                     = sy-msgv1
        msgv2                     = sy-msgv2
        msgv3                     = sy-msgv3
        msgv4                     = sy-msgv4
     importing
       message_text_output       = gw_tab-msg .

    modify gt_tab from gw_tab transporting  msg  icon where matnr eq lw_tab1-matnr  and werks eq lw_tab1-werks and
      stlan eq lw_tab1-stlan and stlal eq lw_tab1-stlal and box eq 'X'.
    if lv_num = '2'.
     delete gt_tab where  box eq 'X'.
    endif.
    loop at gt_tab assigning field-symbol(<gs_tab>) where  icon = icon_led_green and box eq 'X'.
      if <gs_tab>-idnrk_n  ne ''.
        <gs_tab>-idnrk   = <gs_tab>-idnrk_n.
        <gs_tab>-maktx1  = <gs_tab>-maktx1_n.
        <gs_tab>-zzbismt = <gs_tab>-zzbismt_n.
      endif.
      if <gs_tab>-menge_n ne 0.
        <gs_tab>-menge = <gs_tab>-menge_n.
      endif.
      if <gs_tab>-ausch_n ne '0.00'   .
        <gs_tab>-ausch = <gs_tab>-ausch_n.
      endif.
      if <gs_tab>-alpgr_n  is not initial.
        <gs_tab>-alpgr  = <gs_tab>-alpgr_n.
      endif.

      if <gs_tab>-alprf_n ne '00'.
        <gs_tab>-alprf = <gs_tab>-alprf_n.
      endif.
      if <gs_tab>-alpst_n is not initial .
        <gs_tab>-alpst = <gs_tab>-alpst_n .
      endif.
      if <gs_tab>-ewahr_n ne '0' .
        <gs_tab>-ewahr = <gs_tab>-ewahr_n .
      endif.

      if <gs_tab>-potx1_n is not initial.
        <gs_tab>-potx1 = <gs_tab>-potx1_n .
      endif.
      if <gs_tab>-potx2_n is not initial.
        <gs_tab>-potx2 = <gs_tab>-potx2_n .
      endif.

      if  <gs_tab>-zzcombn_n is not initial .
         <gs_tab>-zzcombn = <gs_tab>-zzcombn_n .
      endif.

      if <gs_tab>-zmtyp_n is not initial .
        <gs_tab>-zmtyp = <gs_tab>-zmtyp_n .
      endif.


    endloop.
  endloop.








endform.
*&---------------------------------------------------------------------*
*& Module STATUS_0200 OUTPUT
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
module status_0200 output.
 set pf-status 'ZGUI1002'.

endmodule.
*&---------------------------------------------------------------------*
*&      Module  USER_COMMAND_0200  INPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
module user_command_0200 input.
data:lw_tab   type  gy_tab ,
     lt_tab1  type table of gy_tab .
data:lt_tab2  type table of gy_tab .
  save_ok = ok_code .
  case save_ok.
    when 'S3'."更改内容

  refresh :lt_tab1,lt_tab2 .
  if gt_tab is not initial.
    append lines of gt_tab to lt_tab1.
    append lines of gt_tab to lt_tab2.
    delete lt_tab1 where box eq '' .
    sort lt_tab1 by  matnr werks stlan stlal posnr descending .
    delete  adjacent duplicates from lt_tab1 comparing matnr werks stlan stlal .
       clear: gw_tab .
        if rc29p-idnrk is not initial.
          select single makt~maktx  mara~zzbismt into (gw_tab-maktx1_n,gw_tab-zzbismt_n)
            from mara inner join makt on mara~matnr = makt~matnr
            where mara~matnr eq rc29p-idnrk.
        endif.
        gw_tab-idnrk_n    = gw_rc29p-idnrk+8 ."
        gw_tab-menge_n    = gw_rc29p-menge."组件数量
        gw_tab-ausch_n    = gw_rc29p-ausch  ."组件报废百分比
        gw_tab-alpgr_n    = gw_rc29p-alpgr  ."替代项目:组
        gw_tab-alprf_n    = gw_rc29p-alprf  ."替代项目:评比定单 优先级
        gw_tab-alpst_n    = gw_rc29p-alpst  ."替代项目:策略
        gw_tab-ewahr_n    = gw_rc29p-ewahr  ."使用可能性按 % (可选项目)
        gw_tab-potx1_n    = gw_rc29p-potx1  ."BOM 项目文本(行1)
        gw_tab-potx2_n    = gw_rc29p-potx2  ."BOM 项目文本(行2)
        gw_tab-zzcombn_n  = gw_csci_stpo-zzcombn  ."组合号
        gw_tab-zmtyp_n    = gw_csci_stpo-zmtyp  ."物料类别
        gw_tab-meins      = gw_rc29p-meins .
        sort lt_tab2 by  matnr werks stlan stlal posnr descending .
        loop at lt_tab1 into data(lw_tab1).
          clear: lw_tab .
          move-corresponding gw_tab to lw_tab.
          lw_tab-bmeng       = lw_tab1-bmeng .
          lw_tab-stlst       = lw_tab1-stlst. "BOM 状态
          lw_tab-zbombz      = lw_tab1-zbombz .
          lw_tab-zzbiniv     = lw_tab1-zzbiniv."有效幅宽
          lw_tab-zzbinxy     = lw_tab1-zzbinxy."[WLD]
          lw_tab-zzbinvf     = lw_tab1-zzbinvf."
          lw_tab-zzxpbdz     = lw_tab1-zzxpbdz   ."
          lw_tab-zzxpnam     = lw_tab1-zzxpnam   ."
          lw_tab-zzxppet     = lw_tab1-zzxppet   ."
          lw_tab-zzjiam2     = lw_tab1-zzjiam2.   "支架型号
          lw_tab-zzhtyq      = lw_tab1-zzhtyq.   " 混贴要求
          lw_tab-labor       = lw_tab1-labor .
          lw_tab-zsc         = lw_tab1-zsc .
          lw_tab-bmein       = lw_tab1-bmein .
          lw_tab-postp       = lw_tab1-postp.
          read table lt_tab2 into data(lw_tab2) with key matnr = lw_tab1-matnr  werks = lw_tab1-werks
           stlan = lw_tab1-stlan  stlal = lw_tab1-stlal binary search .
          if sy-subrc eq 0.
            lw_tab-posnr       = lw_tab2-posnr  + 10 .
          endif.
          lw_tab-sanfe       = 'X'.
          lw_tab-sanka       = 'X'.
          lw_tab-sanko       = lw_tab1-sanko.
          lw_tab-datuv       = sy-datum - 32.
          lw_tab-matnr       = lw_tab1-matnr .
          lw_tab-werks       = lw_tab1-werks .
          lw_tab-stlan       = lw_tab1-stlan .
          lw_tab-stlal       = lw_tab1-stlal .
          append lw_tab to gt_tab .
        endloop.
         sort gt_tab by  matnr werks stlan stlal posnr .
  endif.

      leave to screen 0 .
    when 'S4'."取消更改
      leave to screen 0 .
  endcase.




endmodule.
*&---------------------------------------------------------------------*
*&      Module  MDL_MEINS  INPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
module mdl_meins input.

  select single meins into rc29p-meins
    from mara where matnr eq rc29p-idnrk .

endmodule.
*&---------------------------------------------------------------------*
*&      Module  MDL_MEINS1  INPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
module mdl_meins1 input.
  select single meins into gw_rc29p-meins
    from mara where matnr eq gw_rc29p-idnrk .
endmodule.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值