注册 登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

XINBO'S SAP BLOG

你所浪费的今天,是昨天死去的人奢望的明天。你所厌恶的现在,是未来的你回不去的曾经

 
 
 

日志

 
 

通过mbew,mbewh找到某个期间物料的标准价格的逻辑  

2010-02-24 10:23:39|  分类: REPORTING&&OTHER |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |

REPORT ZCOCOSTANA .
TABLES: ztco31,
        bsis,
        mbewh.
TYPES: BEGIN OF ta_mbewh,
         matnr TYPE mbewh-matnr,
         bwkey TYPE mbewh-bwkey,
         bwtar TYPE mbewh-bwtar,
         lfgja TYPE mbewh-lfgja,
         lfmon TYPE mbewh-lfmon,
         stprs TYPE mbewh-stprs,
       END OF ta_mbewh,
       BEGIN OF ta_cost,
         lfgja TYPE mbewh-lfgja,
         lfmon TYPE mbewh-lfmon,
         matnr TYPE mbewh-matnr,
         stprs TYPE mbewh-stprs,
         mcvre TYPE ztco31-mcvre,
         acost TYPE ztco31-mcvre,
       END OF ta_cost.
DATA: it_ztco31 TYPE TABLE OF ztco31,
      wa_ztco31 TYPE ztco31,
      it_mbewh TYPE TABLE OF ta_mbewh,
      wa_mbewh TYPE ta_mbewh,
      it_cost TYPE TABLE OF ta_cost,
      wa_cost TYPE ta_cost.
SELECTION-SCREEN BEGIN OF BLOCK BLK01.
  PARAMETERS: p_gjahr TYPE bsis-gjahr.
  SELECT-OPTIONS: s_lfmon FOR mbewh-lfmon,
*                  s_prctr FOR bsis-prctr,
                  s_matnr FOR ztco31-matnr.
SELECTION-SCREEN END OF BLOCK BLK01.

LOAD-OF-PROGRAM.

AT SELECTION-SCREEN.

START-OF-SELECTION.
  PERFORM frm_get_data.
END-OF-SELECTION.
*&———————————————————————*
*&      Form  frm_get_data
*&———————————————————————*
*       text
*———————————————————————-*
*  –>  p1        text
*  <–  p2        text
*———————————————————————-*
FORM frm_get_data.
  RANGES: r_perod FOR ztco31-perod.
  LOOP AT s_lfmon.
    MOVE-CORRESPONDING s_lfmon TO r_perod.
    APPEND r_perod.
  ENDLOOP.

  SELECT * FROM ztco31 INTO TABLE it_ztco31
                       WHERE matnr IN s_matnr AND
                             gjahr = p_gjahr AND
                             perod IN r_perod.

  RANGES: r_bwkey FOR mbewh-bwkey.
  r_bwkey-sign = ‘I’.
  r_bwkey-option = ‘EQ’.
  r_bwkey-low = ‘HS01′.
  APPEND r_bwkey.
  r_bwkey-low = ‘ZH01′.
  APPEND r_bwkey.
  r_bwkey-low = ‘ZHA1′.
  APPEND r_bwkey.

  SELECT matnr bwkey bwtar lfgja lfmon stprs
           FROM mbewh INTO TABLE it_mbewh
            FOR ALL ENTRIES IN it_ztco31
           WHERE  matnr = it_ztco31-matnr AND
                  bwkey IN r_bwkey AND
                  bwtar = ” AND
                  lfgja = p_gjahr AND
                  lfmon IN s_lfmon.
  SELECT matnr bwkey bwtar lfgja lfmon stprs
           FROM mbew
           APPENDING CORRESPONDING FIELDS OF TABLE it_mbewh
            FOR ALL ENTRIES IN it_ztco31
           WHERE  matnr = it_ztco31-matnr AND
                  bwkey IN r_bwkey AND
                  bwtar = ” AND
                  lfgja = p_gjahr AND
                  lfmon IN s_lfmon.
  DATA: lv_lfmon TYPE mbewh-lfmon.
  LOOP AT it_ztco31 INTO wa_ztco31.
    lv_lfmon = wa_ztco31-perod+1(2).
    CLEAR wa_mbewh.
    READ TABLE it_mbewh INTO wa_mbewh WITH KEY matnr = wa_ztco31-matnr
                                               lfgja = p_gjahr
                                               lfmon = lv_lfmon.
    IF sy-subrc <> 0.
      DATA: lv_gjahr LIKE p_gjahr.
      lv_gjahr = p_gjahr.
      DO.
        PERFORM frm_get_next_mon USING lv_gjahr
                                       lv_lfmon.
        SELECT SINGLE stprs INTO wa_mbewh-stprs
                     FROM mbewh
                    WHERE matnr = wa_ztco31-matnr AND
                          bwkey IN r_bwkey AND
                          bwtar = ” AND
                          lfgja = lv_gjahr AND
                          lfmon = lv_lfmon.
        IF NOT wa_mbewh-stprs IS INITIAL.
          EXIT.
        ENDIF.
*        IF lv_gjahr = ‘2010′.
*          EXIT.
*        ENDIF.
      ENDDO.
    ENDIF.
    wa_cost-lfgja = p_gjahr.
    wa_cost-lfmon = wa_ztco31-perod+1(2).
    wa_cost-matnr = wa_ztco31-matnr.
    wa_cost-stprs = wa_mbewh-stprs.
    wa_cost-mcvre = wa_ztco31-mcvre.
    wa_cost-acost = wa_ztco31-mcvre + wa_mbewh-stprs.
    APPEND wa_cost TO it_cost.
  ENDLOOP.

ENDFORM.                    ” frm_get_data
*&———————————————————————*
*&      Form  frm_get_last_mon
*&———————————————————————*
*       text
*———————————————————————-*
*      –>P_LV_GJAHR  text
*      –>P_LV_LFMON  text
*———————————————————————-*
FORM frm_get_next_mon USING p_gjahr TYPE mbewh-lfgja
                            p_lfmon TYPE mbewh-lfmon.
  CASE p_lfmon.
  WHEN ‘12′.
    p_gjahr = p_gjahr + 1.
    p_lfmon = ‘01′.
  WHEN OTHERS.
    p_lfmon = p_lfmon + 1.
  ENDCASE.
ENDFORM.                    ” frm_get_last_mon

  评论这张
 
阅读(940)| 评论(0)
推荐 转载

历史上的今天

在LOFTER的更多文章

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2017