删除和创建PIR程序

TABLES: mdrs,AFKO,PBIM,PBED.
Include ZR_BDC_I0001.

DATA: BEGIN OF itab OCCURS 0,
       werks like mdrs-werks,
       MATNR LIKE mdrs-MATNR,
       bdter like mdrs-bdter,  "component req date
       labst like mard-labst,
       t_werks like mdrs-werks,
       enmng like mdrs-enmng,
       req_qty  like mdrs-bdmng,
       edatu like rm60e-edatu,
       versb like pbim-versb,
     end of itab.


data: begin of itab_pir occurs 0,
        matnr like pbim-matnr,
        werks like pbim-werks,
        t_date like sy-datum,
        edatu  like rm60e-edatu,
        wh_qty like pbed-plnmg,   "wharehouse qty
        loevr like pbim-loevr,
        pdatu  like pbed-pdatu,
        plnmg like pbed-plnmg,
        req_qty like pbed-plnmg,   "request qty
        bedae like pbim-bedae,
        versb like pbim-versb,
        vervs like pbim-vervs,
        entlu like rm60e-entlu,
      end of itab_pir.


data: tab_mess like table of bdcmsgcoll with header line.

DATA: del_count_suss TYPE i,
      del_count_unsuss TYPE i,
      upload_unsuss TYPE i,
      upload_suss TYPE i.
DATA  total_del TYPE i.

*& ----------------------------------------------*
*&   up_unsuss_tab for unsuccess  change pir *
*& ----------------------------------------------*
 data: begin of up_unsuss_tab occurs 0,
        matnr like mara-matnr,
        werks like marc-werks,
       versb like rm60x-versb,
      text(220) type c,
end of up_unsuss_tab.

* selection-screen

 selection-screen begin of block blk1 with frame. title text-001.
     parameters:  s_werks like mdrs-werks obligatory default 'AAAA'.
     parameters:  t_werks like marc-werks default 'PAUA'.
*     select-options: t_bdter for mdrs-bdter default sy-datum.
     select-options: t_matnr for mdrs-matnr.
*     parameters:   t_mode type c default 'N'.
 selection-screen end of  block blk1.


 start-of-selection.

    perform. get_data_form.
    perform. transfer_wh_form.
    perform. delete_pir_form.
    perform. transfer_data_form.
    perform. show_result_form.

*&----------------------------------------------------*
*&      Form  get_data_form
*&----------------------------------------------------*

FORM. get_data_form.

  data:  t_cur like sy-datum.
  data: t_last like mdrs-bdter.
  data: t_start like mdrs-bdter.
       t_cur = sy-datum.
   t_last = t_cur + 60.
   t_start = t_cur - 30.

   select mdrs~matnr  mdrs~werks mdrs~bdter
          mdrs~bdmng  mdrs~enmng

          into (itab-matnr,
                itab-werks,
                itab-bdter,
                itab-req_qty,
                itab-enmng)
          from mdrs
          where
           mdrs~werks = s_werks
          and  mdrs~matnr in t_matnr
           and   mdrs~bdart = 'AR'
           and   mdrs~bdter between t_start and t_last
           and   mdrs~xloek = ''.

         itab-req_qty = itab-req_qty - itab-enmng.

          itab-versb = 'PP'.
          itab-t_werks = t_werks.
          itab-edatu  =  itab-bdter.
          collect itab.
          clear itab.
    endselect.
ENDFORM.

*&----------------------------------------------------*
*&      Form  transfer_wh_form
*&-----------------------------------------------------*
FORM. transfer_wh_form.
 DATA: wh_qty like mdrs-bdmng.
 sort itab by  werks matnr bdter.
 loop at itab.
   AT NEW matnr.
     wh_qty = 0.
     select  sum( mard~labst )
          into   wh_qty
               from mard
               where mard~matnr = itab-matnr
               and   mard~werks = itab-werks
               and  mard~diskz = ''.

     if sy-subrc <> 0.
       wh_qty = 0.
     endif.
   ENDAT.

   if wh_qty > 0.
      if  wh_qty >= itab-req_qty.
          wh_qty = wh_qty - itab-req_qty.
          itab-req_qty = 0.
          modify itab.
       else.
           itab-req_qty  = itab-req_qty - wh_qty.
           modify itab.
           wh_qty = 0.
       endif.
    endif.

 endloop.
endform.

*&--------------------------------------------------*
*&      Form  delete_pir_form
*&---------------------------------------------------*
FORM. delete_pir_form.
   clear:itab_pir.
   refresh:itab_pir.
   select pbim~loevr pbim~matnr pbim~werks
             into (itab_pir-loevr,
                   itab_pir-matnr,
                   itab_pir-werks)
                      from pbim
                where
                pbim~werks = t_werks
                and pbim~matnr in t_matnr
                and   pbim~versb = 'PP'
                and   pbim~loevr = ''.
     append itab_pir.
   endselect.

    loop at itab_pir.

       perform. del_pir  using
                         itab_pir-matnr
                         t_werks
                          'PP'.

    endloop.
    refresh: bdcdata,tab_mess.
    clear:   bdcdata,tab_mess.
ENDFORM.


*&-----------------------------------------*
*&      Form  transfer_data_form
**&------------------------------------------*
FORM. transfer_data_form.
   loop at itab.
      perform. create_pir  using itab-matnr
                                t_werks
                                'PP'
                                pbim-pbdnr
                                'X'
                                'LSF'.


endloop.
ENDFORM.
*&-----------------------------------------------*
*&      Form  del_pir
*&------------------------------------------------*

FORM. del_pir USING    P_MATNR
                      P_WERKS
                      P_VERSB.

  CLEAR BDCDATA.
  REFRESH BDCDATA.

  perform. bdc_dynpro      using 'SAPMM60X' '0106'.

* -- Add parameters to internal table -- *
  perform. bdc_field using 'AM60X-MATAW'
                          'X'.
  perform. bdc_field using 'AM60X-MATNR'
                          p_matnr.

  perform. bdc_field using 'AM60X-PBDNR'
                          ''.

* -- Enter Plant according to selection screen -- *
  perform. bdc_field       using 'AM60X-WERKS'
                                p_werks.

* -- Select radiobutton for "Selected version -- *
  perform. bdc_field       using 'AM60X-VERAW'
                                'X'.

  perform. bdc_field       using 'RM60X-VERSB'
                                p_versb.

* - Click button ----- *
  perform. bdc_field       using 'BDC_OKCODE'
                                '=ANF1'.
* ---------------------------- *

  perform. bdc_dynpro      using 'SAPLM60E' '0200'.
  perform. bdc_field       using 'BDC_OKCODE'
                                '=ALMK'.
  perform. bdc_field       using  'BDC_SUBSCR'   'SAPLM60E'.
  perform. bdc_field       using  'BDC_SUBSCR'   'SAPLM60E'.
  perform. bdc_field       using  'BDC_CURSOR'   p_matnr.
* ---------------------------- *

  perform. bdc_dynpro      using 'SAPLM60E' '0200'.
  perform. bdc_field       using 'BDC_OKCODE'
                                '=POLO'.
* ---------------------------- *
  perform. bdc_dynpro      using 'SAPLSPO1' '0500'.
  perform. bdc_field       using 'BDC_OKCODE'
                                '=OPT1'.
* ------------------------------------------- *
  perform. bdc_dynpro      using 'SAPLM60E' '0200'.
  perform. bdc_field       using 'BDC_OKCODE'
                                '=SICH'.
* ------------------------------------------- *

  CALL TRANSACTION 'MD62' USING BDCDATA
                          update  'S'
                          mode    'N'
                          MESSAGES INTO TAB_MESS.

  commit work and wait.
ENDFORM.

*&--------------------------------------------------*
*&      Form  create_pir
*&--------------------------------------------------*

FORM. create_pir USING    P_MATNR
                         P_WERKS
                         P_VERSB
                         p_pbdnr
                         p_activ
                         p_bedvp.

data: item like BAPISITEMR.
data: shedule_line like table of BAPISSHDIN with header line.

data: return like table of BAPIRETURN1 with header line.

  item-MATERIAL   = p_matnr.
  item-PLANT      = p_werks.
  item-REQU_TYPE =  p_bedvp.

  item-VERSION    = p_versb.
  item-VERS_ACTIV = p_activ.

  loop at itab where matnr = p_matnr
                and t_werks =  p_werks
                and versb =  p_versb.
    select single PRGRS from tprg into
shedule_line-DATE_TYPE
     where SPRAS = 'EN'
       and PRGBZ = 'D'.
    shedule_line-REQ_DATE  = itab-edatu.
    shedule_line-REQ_QTY   = itab-req_qty.
    append shedule_line.
    clear shedule_line.
  endloop.

  CALL FUNCTION 'BAPI_REQUIREMENTS_CREATE'
    EXPORTING
      REQUIREMENTS_ITEM              = item
    TABLES
      REQUIREMENTS_SCHEDULE_IN       = shedule_line
      RETURN                         = return.

 commit work and wait.

  loop at return where TYPE = 'E'.
    add 1 to upload_unsuss.
    up_unsuss_tab-matnr = p_matnr.
    up_unsuss_tab-versb = p_versb.
    up_unsuss_tab-werks = p_werks.
    up_unsuss_tab-text  = return-MESSAGE.
    append up_unsuss_tab.
  endloop.

ENDFORM.
*&------------------------------------------------------*
*&      Form  show_result_form
*&-------------------------------------------------------*
FORM. show_result_form.

  loop at itab.
        write:/ 'The following material PIR For MRP'.
     write:/ itab-matnr,
             itab-werks,
             itab-req_qty,
             itab-edatu,
             itab-versb.
    endloop.

ENDFORM.

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/15117617/viewspace-551892/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/15117617/viewspace-551892/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值