zoukankan      html  css  js  c++  java
  • 【ABAP系列】SAP BOM反查

    公众号:matinal
    本文作者:matinal
     

    前言部分

    大家可以关注我的公众号,公众号里的排版更好,阅读更舒适。

    正文部分

    TCODE::CS15

    或者函数::CS_WHERE_USED_MAT 

    ​
    
    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
    
  • 相关阅读:
    Python class:定义类
    Python return函数返回值详解
    Python None(空值)及用法
    Python函数值传递和引用传递(包括形式参数和实际参数的区别)
    Python函数的定义
    Python函数(函数定义、函数调用)用法详解
    Python reversed函数及用法
    Python zip函数及用法
    Python break用法详解
    Python嵌套循环实现冒泡排序
  • 原文地址:https://www.cnblogs.com/SAPmatinal/p/11183534.html
Copyright © 2011-2022 走看看