前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >SAP BOM反查

SAP BOM反查

作者头像
matinal
发布2020-11-27 15:58:48
7620
发布2020-11-27 15:58:48
举报
文章被收录于专栏:SAP TechnicalSAP Technical

正文部分

TCODE::CS15

或者函数::CS_WHERE_USED_MAT

代码语言:javascript
复制
​

tables : stpo,stas,mara,makt.

data : begin of itab occurs 200,
       matnr like mast-matnr,
       menge like stpo-menge,
       end of itab.

data : begin of alttab occurs 200,
       matnr like mast-matnr,
       menge like stpo-menge,
       end of alttab.

data : begin of top_code occurs 100,
       matnr(18),
       maktx(40),
       meins(3),
       menge like stpo-menge,
       matkl(9),
       wrkst(14),
       end of top_code.

data : begin of makr occurs 10,
       maker(7),
       idnlf(22),
       end of makr.

data : begin of usedtab occurs 100.
        include structure stpov.
data : end of usedtab.

data : begin of equicat occurs 100.
        include structure  cscequi.
data : end of equicat.

data : begin of kndcat occurs 100.
        include structure  cscknd.
data : end of kndcat.

data : begin of matcat occurs 100.
        include structure  cscmat.
data : end of matcat.

data : begin of stdcat occurs 100.
        include structure   cscstd.
data : end of stdcat.

data : begin of tplcat occurs 100.
        include structure   csctpl.
data : end of tplcat.

data : top_cnt(5) type n,
       m_cnt(5) type n,
       lin(5) type n,
       line_cnt(5) type n.

selection-screen begin of block blk1 with frame.
selection-screen : comment 1(60) text-001,
                   skip.
parameters : matnr like marc-matnr obligatory,
             werks like marc-werks obligatory default 'PQ50'.
select-options : bdate for sy-datum default sy-datum to sy-datum
                 no-extension obligatory.
selection-screen end of block blk1.

start-of-selection.
  itab-matnr = matnr.
  itab-menge = 1.
  append itab.
  clear itab.

  perform get_top_code.

************************************
*&---------------------------------------------------------------------*
*&      Form  GET_TOP_CODE
*&---------------------------------------------------------------------*
form get_top_code.

  clear lin.
  describe table itab lines lin.
  if lin = 0.
    exit.
  endif.

  loop at itab.
    call function 'CS_WHERE_USED_MAT'
         exporting
              datub                      = bdate-high
              datuv                      = bdate-low
              matnr                      = itab-matnr
              werks                      = werks
         tables
              wultb                      = usedtab
              equicat                    = equicat
              kndcat                     = kndcat
              matcat                     = matcat
              stdcat                     = stdcat
              tplcat                     = tplcat
         exceptions
              call_invalid               = 1
              material_not_found         = 2
              no_where_used_rec_found    = 3
              no_where_used_rec_selected = 4
              no_where_used_rec_valid    = 5
              others                     = 6.

    clear line_cnt.
    describe table usedtab lines line_cnt.
    if line_cnt = 0.          
      move itab-matnr to top_code-matnr.
      top_code-menge = itab-menge.
      collect top_code.
      clear top_code.
    else.
      loop at usedtab where postp ne 'F' and datuv le bdate-high
                      and ( sumfg = ' ' or sumfg = 'x' ).
        select single lkenz into stas-lkenz from stas
               where stlty = 'M'
               and   stlnr = usedtab-stlnr
               and   stlal = '01'
               and   stlkn = usedtab-stlkn
               and   datuv le bdate-low
               and   lkenz = 'X'.
        if sy-subrc ne 0.
          move usedtab-matnr to alttab-matnr.
          alttab-menge = usedtab-menge * itab-menge.
          collect alttab.
        endif.
        clear alttab.
      endloop.
    endif.
    refresh : usedtab,equicat,kndcat,matcat,stdcat,tplcat.

  endloop.

  refresh itab.
  itab[] = alttab[].
  refresh alttab.
  perform get_top_code.

endform.                    " GET_TOP_CODE

​
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2017-02-13 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 正文部分
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档