SAP: Explosion BOM

44 篇文章 0 订阅

*&---------------------------------------------------------------------*
*& Progarm      :  ZMM_EXPLOSION_BOM              Author : Jimmy Wong
*& Created      :  07 Jan 2013                    App    : PP
*& Title        :  Explosion BOM
*& Description  :  Explosion BOM
*&---------------------------------------------------------------------*
*&  Version       Author      Date        description
*&                Jimmy       07 Jan 2013  the first version
*&  the last update time  2013.01.09  12:00
*&---------------------------------------------------------------------*

report  zmm_explosion_bom no standard page heading.

tables:mast,mara.
data: begin of it_matnr occurs 0,
      matnr like mara-matnr,
      werks like mast-werks,
      end of  it_matnr.
data: begin of it_stpo occurs 0 .
        include structure stpox.
data: end of  it_stpo.
data: begin of it_matcat occurs 0 .
        include structure cscmat.
data: end of it_matcat.
data:it_zctp001 like zctp001 occurs with header line.
data:begin of it_del occurs 0,
    werks_h like zctp001-werks_h,
    matnr_h like zctp001-matnr_h,
    matnr_m like zctp001-matnr_h,
    matnr_l like zctp001-matnr_h,
    posnr_l like zctp001-matnr_h,
    end of it_del.
data:lv_total_line type i,
   lv_line type decimals 3.
*----------------------------------------------------------------------*
*  Parameter & Select-Options                                          *
*----------------------------------------------------------------------*
selection-screen begin of block with frame title text-001.
select-options : s_werks for mast-werks.
select-options : s_matnr for mast-matnr.
select-options : s_mtart for mara-mtart. "default 'ZVFG'.
parameters : p_sel as checkbox default 'X'.
parameters : p_bom as checkbox .
selection-screen end of block 1.


*&---------------------------------------------------------------------*
* start of process
*&---------------------------------------------------------------------*
start-of-selection.
  if p_bom is initial.
    perform delete_record.
  endif.
  perform get_material.
  if it_matnr[] is initial.
    message  i003(zmm).
    exit.
  endif.
  perform explosion_bom.
  if p_bom is initial.
    perform insert_data.
  endif.
*&---------------------------------------------------------------------*
*&      Form  DELETE_RECORD
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form delete_record .
  if p_sel is initial.
    delete from zctp001.
    commit work and wait.
  else.
    if s_werks[] is initial and s_matnr[] is initial and s_mtart[] is initial.
      delete from zctp001.
      commit work and wait.
    else.
      select a~werks_h a~matnr_h   a~matnr_m  a~matnr_l  a~posnr_l
        into corresponding fields of table it_del
        from zctp001  as a inner join mara as on a~matnr_h b~matnr
        where a~werks_h in s_werks
          and a~matnr_h in s_matnr
          and b~mtart in s_mtart.
      if it_del[] is not initial.
        loop at it_del.
          delete from zctp001 where werks_h it_del-werks_h
            and matnr_h it_del-matnr_h and  matnr_m it_del-matnr_m
            and matnr_l it_del-matnr_l and posnr_l it_del-posnr_l  .
        endloop.
        commit work and wait.
        free it_del.
      endif.
    endif.
  endif.
endform.                    " DELETE_RECORD

*&---------------------------------------------------------------------*
*&      Form  GET_MATERIAL
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form get_material .
  call function 'SAPGUI_PROGRESS_INDICATOR'
    exporting
      text 'Getting Data........'.
  clear:it_matnr,it_matnr[].
  select distinct a~matnr a~werks
     into corresponding fields of table it_matnr
    from mast as a inner join mara as on a~matnr b~matnr
      inner join stko as k  on a~stlnr k~stlnr and a~stlal k~stlal
    where a~matnr in s_matnr
      and a~werks in s_werks
      and b~mtart in s_mtart
      and k~stlst '02'.
endform.                    " GET_MATERIAL
*&---------------------------------------------------------------------*
*&      Form  EXPLOSION_BOM
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form explosion_bom .
  describe table it_matnr lines lv_total_line.
  sort it_matnr by matnr werks.
  loop at it_matnr.
    lv_line =  sy-tabix  / lv_total_line * 100.
    call function 'SAPGUI_PROGRESS_INDICATOR'
      exporting
        percentage lv_line
        text       'Explosion BOM........'.
    call function 'CS_BOM_EXPL_MAT_V2'
      exporting
        capid                 'PP01'
        datuv                 sy-datum
        emeng                 1000
        mtnrv                 it_matnr-matnr
        mehrs                 'X'
        mmory                 'X'
        werks                 it_matnr-werks
        aumgb                 'X'
      tables
        stb                   it_stpo
        matcat                it_matcat
      exceptions
        material_not_found    4
        no_plant_data         8
        no_bom_found          12
        no_suitable_bom_found 16
        alt_not_found         24
        missing_authorization 28
        conversion_error      36.
    " if p_bom is initial.
    if sy-subrc eq 0 .
      sort it_stpo by ttidx.
      delete adjacent duplicates from it_matcat comparing matnr index.
      sort it_matcat by index.
      loop at it_stpo.
        move-corresponding it_stpo to it_zctp001.
        check it_stpo-idnrk is not initial.
        it_zctp001-matnr_h it_matnr-matnr.
        it_zctp001-werks_h it_matnr-werks.
        it_zctp001-matnr_l it_stpo-idnrk .
        it_zctp001-posnr_l it_stpo-posnr.
        it_zctp001-menge_l it_stpo-mngko / 1000.
        it_zctp001-menge_h it_stpo-mngko / 1000.
        read table  it_matcat with key index it_stpo-ttidx binary search.
        if sy-subrc eq 0.
          it_zctp001-matnr_m it_matcat-matnr .
        endif.
        append it_zctp001.
        clear: it_zctp001.
      endloop.
    endif.
    " endif.
    clear:it_stpo,it_stpo[],it_matcat,it_matcat[].
  endloop.
endform.                    " EXPLOSION_BOM
*&---------------------------------------------------------------------*
*&      Form  INSERT_DATA
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form insert_data .
  if not it_zctp001[] is initial.
    sort  it_zctp001 by werks_h matnr_h matnr_m matnr_l posnr_l.
    modify zctp001 from table it_zctp001.
    write: 'Excute Successed.'.
    refresh it_zctp001.
    free:it_matnr,it_zctp001,it_stpo,it_matcat.
  endif.
endform.                    " INSERT_DATA

 

MANDT MANDT
WERKS_H WERKS_D
MATNR_H MATNR
MATNR_M MATNR
MATNR_L MATNR
POSNR_L POSNR
TTIDX TTIDX
VWEGX WEGXX
STUFE HISTU
WEGXX CS_E_VWEGX
MENGE_L KMPMG
MENGE_H KMPMG
MEINS KMPME
MMEIN MEINS
MTART MTART
ALPGR CS_ALPGR

EWAHR EWAHR

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值