【ABAP】修改采购申请BAPI-BAPI_PR_CHANGE

修改采购申请供应商交期

*&---------------------------------------------------------------------*
*& Form frm_delay
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& -->  p1        text
*& <--  p2        text
*&---------------------------------------------------------------------*
FORM frm_delay .
  DATA:lt_mmt036 TYPE TABLE OF zmmt036,
          ls_mmt036 LIKE LINE OF  lt_mmt036.

*定义 BAPI部分
       DATA : lt_return           TYPE  TABLE  OF bapiret2 ,
             lv_number  LIKE  bapimereqheader-preq_no,
            lt_pritem_get       TYPE  TABLE  OF bapimereqitem ,
            ls_pritem_get  LIKE  LINE  OF lt_pritem_get ,
            lt_pritemx          TYPE TABLE  OF bapimereqitemx  ," OCCURS  0 ,
            ls_pritemx         TYPE bapimereqitemx ,
            lt_pritem           TYPE  TABLE  OF bapimereqitemimp ,
            ls_pritem      LIKE  LINE  OF lt_pritem,
            lt_pritemtext LIKE  bapimereqitemtext OCCURS 0 WITH HEADER LINE,
             l_flag TYPE c.


  LOOP AT gt_disp INTO gs_disp WHERE sel = 'X'.
        SELECT *
          FROM zmmt036
          INTO TABLE lt_mmt036
          WHERE banfn = gs_disp-banfn AND
                    bnfpo = gs_disp-bnfpo.
          READ TABLE lt_mmt036 INTO ls_mmt036 WITH  KEY banfn = gs_disp-banfn bnfpo = gs_disp-bnfpo.
          IF sy-subrc = 0.  "如果自建表存在,更改自建表交期和备注文本
              ls_mmt036-zitemtxt = gs_disp-txt.
              ls_mmt036-zlastchargdate = gs_disp-lfdat.
              gs_disp-zlastchargdate = gs_disp-lfdat.
              gs_disp-lfdat = gs_disp-zdate.
              ls_mmt036-zname = sy-uname.
              gs_disp-zname = sy-uname.

              ELSE.     "如果不存在,新增一条记录
                SELECT SINGLE badat
                  FROM eban
                  INTO ls_mmt036-zcrddate      "原交货日期
                  WHERE banfn = gs_disp-banfn AND
                          bnfpo = gs_disp-bnfpo.
                ls_mmt036-banfn = gs_disp-banfn.   "采购申请
                ls_mmt036-bnfpo = gs_disp-bnfpo.   "行项目
                ls_mmt036-zorgdate = gs_disp-lfdat.   "交货日期
                gs_disp-zlastchargdate = gs_disp-lfdat.   "最后一次更改前日期-显示的
                ls_mmt036-zlastchargdate = gs_disp-lfdat.  "最后一次更改前日期
                ls_mmt036-zitemtxt = gs_disp-txt.    "备注
                gs_disp-zorgdate = gs_disp-lfdat.    "显示的原始交货日期
                gs_disp-lfdat = gs_disp-zdate.     "显示的交货日期
                ls_mmt036-zname = sy-uname.    "显示更改者
                gs_disp-zname = sy-uname.      "更改者
          ENDIF.
  lv_number = gs_disp-banfn.
         CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
  EXPORTING
    input         = lv_number
  IMPORTING
    output        = lv_number.
*   Get pr details
       CALL  FUNCTION  'BAPI_PR_GETDETAIL'
         EXPORTING
           number        =  lv_number
          services      =  'X'
         TABLES
           return        = lt_return
          pritem        = lt_pritem_get.
   "       servicelines  = i_services .
       IF sy-subrc  =  0 .
         LOOP  AT lt_pritem_get  INTO ls_pritem_get WHERE preq_item = gs_disp-bnfpo.
          ls_pritem_get-deliv_date = gs_disp-zdate.
           MOVE-CORRESPONDING ls_pritem_get  TO ls_pritem .
          ls_pritemx-preq_item  = ls_pritem-preq_item .   "项目编号
          ls_pritemx-preq_itemx  =  'X' .
          ls_pritemx-deliv_date  =   'X' .
           APPEND ls_pritemx  TO lt_pritemx .
           APPEND ls_pritem  TO lt_pritem .
           CLEAR  ls_pritem .
         ENDLOOP .
     lt_pritemtext-preq_no   = gs_disp-banfn.
    lt_pritemtext-preq_item = gs_disp-bnfpo.
    lt_pritemtext-text_id   = 'B02'.
    lt_pritemtext-text_form = '*'.
    lt_pritemtext-text_line = gs_disp-txt.
    APPEND lt_pritemtext.
         CLEAR lt_return .
*       Call bapi to change the gross price.
         CALL  FUNCTION  'BAPI_PR_CHANGE'
           EXPORTING
             number         =  lv_number
           TABLES
             return         = lt_return
            pritem         = lt_pritem
            pritemx        = lt_pritemx
            pritemtext = lt_pritemtext.
       ENDIF .

CLEAR:l_flag.
    LOOP AT lt_return INTO DATA(ls_return) WHERE type = 'S' AND id = '06' AND number = '403'.
      l_flag = 'S'.
    ENDLOOP.
      IF l_flag = 'S'.
                 MODIFY gt_disp FROM gs_disp.
                  MODIFY zmmt036 FROM ls_mmt036.
           CALL  FUNCTION  'BAPI_TRANSACTION_COMMIT'
             EXPORTING
               wait  =  'X' .
             MESSAGE '保存成功!' TYPE 'S'.
           ELSE.
             CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
             MESSAGE '保存失败' TYPE 'S' DISPLAY LIKE 'E'.
      ENDIF.
      FREE:lt_return,lt_pritem,lt_pritemx,lt_pritemtext.
        CLEAR:gs_disp,ls_mmt036,lv_number.
  ENDLOOP.
ENDFORM.

给TA买糖
共{{data.count}}人
人已赞赏
ABAPSAP

【ABAP】BAPI_OUTB_DELIVERY_CONFIRM_DEC过账数量出错

2021-6-23 15:01:05

ABAPSAP

【ABAP】HR开发的几个函数

2021-6-23 19:58:28

0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧
个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索