ZPP_CHANGE_PR_BY_MRP_RUN:Change PR by MRP_Run

本博客介绍了一个用于批量变更采购请求状态的自动化脚本,包括获取数据、处理数据、更新数据以及释放采购请求等功能。脚本通过参数选择和筛选条件,实现了对特定工厂的采购请求进行批量操作。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

*&---------------------------------------------------------------------*
*& Progarm      :  ZPP_CHANGE_PR_BY_MRP_RUN       Author : Jimmy Wong
*& Created      :  22 Oct 2012                    App    : PP
*& Title        :  Change PR by MRP_Run
*& Description  :  Change PR by MRP_Run
*&---------------------------------------------------------------------*
*&  Version       Author      Date        description
*&                Jimmy       22 Oct 2012 the first version
*&                Lisa wong   11/28/2012  add parameter :Plant
*& M1             Jimmy       06 Dec 2012 Add Open qty check
*& M2             JImmy       18 Dec 2012 Open qty > 0 change Quantity = Quantity Ordered
*&  the last update time  2012.12.18 17:00
*&---------------------------------------------------------------------*

report  zpp_change_pr_by_mrp_run no standard page heading.
*&---------------------------------------------------------------------*
* database table
*&---------------------------------------------------------------------*
tables : eban.

data: prheaderexp like bapimereqheader,
      number like bapimereqheader-preq_no,
      return like bapiret2 occurs 0 with header line,
      pritem like bapimereqitemimp occurs 0 with header line,
      pritemx like bapimereqitemx occurs 0 with header line,
      it_return like bapireturn occurs 0 with header line.
data:begin of itab occurs 0,
    banfn   like eban-banfn,
    bnfpo   like eban-bnfpo,
    fixkz   like eban-fixkz,
    frgkz   like eban-frgkz,
    frgst   like eban-frgst,
    menge   like eban-menge,
    bsmng   like eban-bsmng,
    opqty   like eban-bsmng,
    message type c length 700,
    end of itab.
data: itab1 like table of itab with header line.
type-pools: slis.
data: fc_hier type slis_t_fieldcat_alv,
      wa_hier type slis_fieldcat_alv .
data: lv_flag type c.
*----------------------------------------------------------------------*
*  Parameter & Select-Options                                          *
*----------------------------------------------------------------------*
selection-screen begin of block 1 with frame title text-001.
parameters: p_werks like eban-werks obligatory default '8101'.           " Add by Lisa wong 11/28/2012
select-options : s_banfn for eban-banfn .
parameters: p_test  as checkbox.
selection-screen end of block 1.

*&---------------------------------------------------------------------*
* start of process
*&---------------------------------------------------------------------*
start-of-selection.
  perform get_data.
  if itab1[] is initial  .
    message 'No Record Found' type 'I'.
    exit.
  endif.
  perform process_data.
  if itab[] is initial  .
    message 'No Record Found' type 'I'.
    exit.
  endif.
  if p_test is initial.
    perform display_data.
  else.
    perform write_data.
  endif.

end-of-selection.

*&---------------------------------------------------------------------*
*&      Form  GET_DATA
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form get_data .

  select   banfn bnfpo fixkz frgst menge bsmng frgkz
    into corresponding fields of table itab1
    from eban
    where banfn in s_banfn
      and loekz = space
      and werks = p_werks .
  "      and ( fixkz = 'X' or frgst >= '51' ). "M2 Modify
endform.                    " GET_DATA
*&---------------------------------------------------------------------*
*&      Form  PROCESS_DATA
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form process_data .

  sort itab1 by banfn bnfpo.
  loop at itab1.
    move-corresponding itab1 to itab.
    itab-opqty = itab-menge -  itab-bsmng.
    check itab-opqty > 0.
    if  itab-bsmng > 0 or   itab-frgst >= '51' or itab-fixkz = 'X'.  "change 3 data
      if p_test is initial.
        number = itab-banfn.
        if  itab-bsmng > 0.     " 1 cancel pr " 先cancel pr 再修改qty 然后release PR

          call function 'ZBAPI_PR_RESET_RELEASE'
            exporting
              number                   = itab-banfn
              item                     = itab-bnfpo
              rel_code                 = itab-frgst
            tables
              return                   = it_return
            exceptions
              authority_check_fail     = 1
              requisition_not_found    = 2
              enqueue_fail             = 3
              prerequisite_fail        = 4
              release_already_posted   = 5
              responsibility_fail      = 6
              no_release_already       = 7
              no_new_release_indicator = 8
              others                   = 9.
          read table it_return with key type = 'E'.
          if sy-subrc ne 0.     " 修改qty
            wait up to 1 seconds.
            pritem-preq_item = itab-bnfpo.
            pritemx-preq_item = itab-bnfpo.
            pritemx-preq_itemx  = 'X'.
            pritem-quantity = itab-bsmng.
            pritemx-quantity = 'X'.
            if itab-frgst >= '51'.
              pritem-delete_ind = 'X'.
              pritemx-delete_ind = 'X'.
            endif.
            pritem-fixed = space.
            pritemx-fixed = 'X'.
            append pritem.
            append pritemx.

            call function 'BAPI_PR_CHANGE'
              exporting
                number      = number
              importing
                prheaderexp = prheaderexp
              tables
                return      = return
                pritem      = pritem
                pritemx     = pritemx
              exceptions
                others      = 1.
            commit work and wait.
            read table return with key type = 'E'.
            if sy-subrc eq 0.
              lv_flag = 'X'.
              concatenate 'E:' return-message into itab-message.
            else.
              wait up to 1 seconds.
              refresh : it_return.                  "release PR
              call function 'BAPI_REQUISITION_RELEASE'
                exporting
                  number                 = itab-banfn
                  item                   = itab-bnfpo
                  rel_code               = itab-frgst
                tables
                  return                 = it_return
                exceptions
                  authority_check_fail   = 1
                  requisition_not_found  = 2
                  enqueue_fail           = 3
                  prerequisite_fail      = 4
                  release_already_posted = 5
                  responsibility_fail    = 6
                  others                 = 7.
              commit work and wait.
              read table it_return with key type = 'E'.
              if sy-subrc eq 0.
                lv_flag = 'X'.
                concatenate 'E:' it_return-message into itab-message.
              endif.
            endif.
          else.
            lv_flag = 'X'.
            concatenate 'E:' it_return-message into itab-message.
          endif.
        else.
          pritem-preq_item = itab-bnfpo.
          pritemx-preq_item = itab-bnfpo.
          pritemx-preq_itemx  = 'X'.

          if itab-frgst >= '51'.
            pritem-delete_ind = 'X'.
            pritemx-delete_ind = 'X'.
          endif.
          if itab-fixkz = 'X'.
            pritem-fixed = space.
            pritemx-fixed = 'X'.
          endif.
          append pritem.
          append pritemx.


          call function 'BAPI_PR_CHANGE'
            exporting
              number      = number
            importing
              prheaderexp = prheaderexp
            tables
              return      = return
              pritem      = pritem
              pritemx     = pritemx
            exceptions
              others      = 1.
          commit work and wait.
          read table return with key type = 'E'.
          if sy-subrc eq 0.
            lv_flag = 'X'.
            concatenate 'E:' return-message into itab-message.
          endif.
        endif.
      endif.
      append itab.
      clear:itab,pritem,pritemx,return,number,it_return.
      refresh: pritem,pritemx,return,it_return.
    endif.
  endloop.
  free: itab1,pritem,pritemx,return,it_return.
endform.                    " PROCESS_DATA
*&---------------------------------------------------------------------*
*&      Form  DISPLAY_DATA
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form display_data .
  if lv_flag = 'X' .
    loop at itab where message <> ''.
      write :/3 itab-message.
    endloop.
  else.
    write: /3 'Changed Successed.'.
  endif.
endform.                    " DISPLAY_DATA
*&---------------------------------------------------------------------*
*&      Form  WRITE_DATA
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form write_data .
  define alv_field.
    clear:wa_hier.
    wa_hier-fieldname = &1.
    wa_hier-seltext_m = &2.
    wa_hier-seltext_l = &3.
    wa_hier-outputlen = &4.
    wa_hier-just = &5.
    wa_hier-do_sum = &6.
    wa_hier-ref_tabname = &7 .
    wa_hier-ref_fieldname = &8 .
    append wa_hier to fc_hier.
  end-of-definition.
  refresh: fc_hier.

  alv_field  'BANFN' '' '' '12' 'L' '' 'EBAN' 'BANFN'.
  alv_field  'BNFPO' '' '' '6' 'L' '' 'EBAN' 'BNFPO'.
  alv_field  'FIXKZ' '' 'PR is Fixed' '6' 'L' '' '' ''.
  alv_field  'FRGST' '' 'Release Strategy' '6' 'L' '' '' ''.
  alv_field  'MENGE' '' 'Quantity' '12' 'R' '' '' ''.
  alv_field  'BSMNG' '' 'Quantity Ordered' '12' 'R' '' '' ''.
  alv_field  'OPQTY' '' 'Open quantity' '12' 'R' '' '' ''.

 

  sort itab by banfn bnfpo.

  call function 'REUSE_ALV_GRID_DISPLAY'
    exporting
      it_fieldcat        = fc_hier[]
      i_save             = 'A'
      i_callback_program = sy-repid
    tables
      t_outtab           = itab[]
    exceptions
      program_error      = 1
      others             = 2.
endform.                    " WRITE_DATA

 

 

    IF lf_statu EQ 'B'." AND eban-bsmng IS INITIAL.         "632981 "Jimmy Remark

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值