生產(chǎn)訂單組件創(chuàng)建熊杨、修改曙旭、刪除BAPI

1.創(chuàng)建 可批量

如果CO_XT_COMPONENT_ADD缺少需要的字段
可以拷貝出來(lái)盗舰,
在ZCO_XT_COMPONENT_ADD
添加字段例如:I_TEST 和 I_TESTX
或者memory id傳值
在220行左右添加代碼后調(diào)用BAPI即可
if i_testx is not initial.
ls_resbd_new-TEST = I_TEST.
endif.

也可以調(diào)用bapi后直接修改
(SAPLCOBC)RESB_BT[]
內(nèi)的對(duì)應(yīng)字段


data:is_order_key         type coxt_ord_key,
       i_material           type coxt_material,
       is_storage_location  type coxt_s_storage_location,
       is_storage_locationx type coxt_s_storage_locationx,
       is_requ_quan         type coxt_s_quantity,
       i_operation          type afvc-aplzl,
       i_posno              type cif_r3res-positionno,
       ls_return            type coxt_bapireturn,
       lv_error             type c.
  data:
    lv_matnr  type mara-matnr,
    lv_aufnr  type afpo-aufnr,
    lv_sortf  type resb-sortf,
    lv_sortfx type c,
    lv_posnr  type char4.

  types: begin of ty_resb_bt.
           include type resbb.
  types: indold type syst_tabix.
  types: no_req_upd type syst_datar.
  types: end of ty_resb_bt.

  types tt_resb_bt type table of ty_resb_bt.

  field-symbols: <ft_resb_bt> type tt_resb_bt,
                 <fs_resb_bt> type ty_resb_bt.

  data:begin of lt_aufnr occurs 0,
         aufnr type afpo-aufnr,
       end of lt_aufnr.

  refresh lt_aufnr.

  loop at gt_data1 assigning <fs_data1> where check eq 'X'
  and cellcolor is initial
  and icon ne icon_led_green.
    lt_aufnr-aufnr = <fs_data1>-aufnr.
    append lt_aufnr.
    clear  lt_aufnr.
  endloop.

  sort lt_aufnr.
  delete adjacent duplicates from lt_aufnr.

  loop at lt_aufnr.

    loop at gt_data1 assigning <fs_data1> where aufnr eq lt_aufnr-aufnr.

      clear:lv_matnr,lv_aufnr,lv_posnr,is_requ_quan,is_storage_location,is_storage_locationx,
      ls_return,lv_error,lv_sortf,lv_sortfx.

      unassign:<ft_resb_bt>,<fs_resb_bt>.

      lv_aufnr = <fs_data1>-aufnr.
      lv_matnr = <fs_data1>-matnr.

      call function 'CONVERSION_EXIT_ALPHA_INPUT'
        exporting
          input  = lv_aufnr
        importing
          output = lv_aufnr.

      call function 'CONVERSION_EXIT_ALPHA_INPUT'
        exporting
          input  = lv_matnr
        importing
          output = lv_matnr.

      is_order_key = lv_aufnr.
      i_material = lv_matnr.

      is_requ_quan-quantity = <fs_data1>-menge.

      is_storage_location-werks = <fs_data1>-werks.
      is_storage_locationx-werks =  'X'.

      if <fs_data1>-lgort is not initial.
        is_storage_location-lgort = <fs_data1>-lgort.
        is_storage_locationx-lgort =  'X'.
      endif.

      call function 'CO_XT_COMPONENT_ADD'
        exporting
          is_order_key         = is_order_key
          i_material           = i_material
          is_requ_quan         = is_requ_quan
          i_operation          = i_operation
          is_storage_location  = is_storage_location
          is_storage_locationx = is_storage_locationx
          i_postp              = 'L'
          i_posno              = i_posno
        importing
          es_bapireturn        = ls_return
          e_error_occurred     = lv_error.

      if lv_error is initial.

        assign ('(SAPLCOBC)RESB_BT[]') to <ft_resb_bt>.

        data(line) = lines( <ft_resb_bt> ).

        loop at <ft_resb_bt> assigning <fs_resb_bt>.

          "新增行數(shù)據(jù)處理
          if sy-tabix = line.

            if <fs_data1>-posnr is not initial.
              <fs_resb_bt>-posnr = <fs_data1>-posnr.
            else.

              select single max( posnr )
              into <fs_resb_bt>-posnr
              from resb
              where aufnr eq lv_aufnr.

              <fs_resb_bt>-posnr = <fs_resb_bt>-posnr + 1.
              lv_posnr = <fs_resb_bt>-posnr.
            endif.

            call function 'CONVERSION_EXIT_ALPHA_INPUT'
              exporting
                input  = <fs_resb_bt>-posnr
              importing
                output = <fs_resb_bt>-posnr.

            if <fs_data1>-sortf is not initial.
              <fs_resb_bt>-sortf = <fs_data1>-sortf.
            endif.

            if <fs_resb_bt>-xwaok is initial.
              <fs_resb_bt>-xwaok = 'X'.
            endif.

          endif.
        endloop.

        call function 'CO_XT_ORDER_PREPARE_COMMIT'
          importing
            es_bapireturn    = ls_return
            e_error_occurred = lv_error.

        if ( ls_return-type = 'S' or ls_return-type = 'W' or ls_return-type = 'I' ) or
        ls_return is initial.

          call function 'BAPI_TRANSACTION_COMMIT'
            exporting
              wait = 'X'.

          call function 'CO_XT_ORDER_INITIALIZE'.

          <fs_data1>-mseg = '新增成功'.
*          <fs_data1>-color = 'C500'.
          <fs_data1>-icon = icon_led_green.

          perform save_history_add using <fs_data1> lv_posnr.

        else.

          call function 'BAPI_TRANSACTION_ROLLBACK'.

          <fs_data1>-mseg = ls_return-message.
          <fs_data1>-icon = icon_led_red.

        endif.

      else.

        call function 'BAPI_TRANSACTION_ROLLBACK'.

        <fs_data1>-mseg = ls_return-message.
        <fs_data1>-icon = icon_led_red.
      endif.
      wait up to 1 seconds.
    endloop.
  endloop.

2.修改 單條

 data:lt_resb like table of resb with header line.
  data:lv_message type string,
       lv_matny   type mara-matnr.
  data:ft_return type table of bapiret2 with header line.
  data:lt_return type table of bapiret2 with header line.

  data:ls_return  type coxt_bapireturn,
       ls_return2 type bapiret2,
       error      type c.

  data:order   type coxt_ord_key,
       compkey type coxt_s_ord_comp_key,
       ret     type coxt_bapireturn,
       bapiret type coxt_t_bapireturn.

  data : is_order_key               type  coxt_ord_key,
         is_order_component_key     type  coxt_s_ord_comp_key,
         is_requirement_quantity    type  coxt_s_quantity,
         is_requirement_quantityx   type  coxt_s_quantityx,
         is_confirmed_quantity      type  coxt_s_quantity,
         is_confirmed_quantityx     type  coxt_s_quantityx,
         i_material                 type  coxt_material,
         i_materialx                type  coxt_materialx,
         is_order_operation_key     type  coxt_s_ord_opr_key,
         is_order_operation_keyx    type  coxt_s_ord_opr_keyx,
         is_requirement_date        type  coxt_s_date,
         is_requirement_datex       type  coxt_s_datex,
         is_storage_location        type  coxt_s_storage_location,
         is_storage_locationx       type  coxt_s_storage_locationx,
         i_batch                    type  coxt_batch,
         i_batchx                   type  coxt_batchx,
         i_mi_configuration_object  type  coxt_config_object,
         i_mi_configuration_objectx type  coxt_config_objectx.

  data :wa_resb          type resb,
        es_bapireturn    type  coxt_bapireturn,
        e_error_occurred type  c.

  data:begin of lt_aufnr occurs 0,
         aufnr type afpo-aufnr,
       end of lt_aufnr.

  refresh:lt_aufnr,lt_return.

  loop at gt_data2 assigning <fs_data2> where check eq 'X'
  and cellcolor is initial
  and icon ne icon_led_green.
    lt_aufnr-aufnr = <fs_data2>-aufnr.
    append lt_aufnr.
    clear  lt_aufnr.
  endloop.

  sort lt_aufnr.
  delete adjacent duplicates from lt_aufnr.

  loop at lt_aufnr.

    clear is_order_key.

    is_order_key = lt_aufnr-aufnr.

    call function 'CONVERSION_EXIT_ALPHA_INPUT'
      exporting
        input  = is_order_key
      importing
        output = is_order_key.

    loop at gt_data2 assigning <fs_data2> where aufnr eq lt_aufnr-aufnr.

      clear:lv_matny,ft_return[],ft_return,lv_message.

      lv_matny = <fs_data2>-matny.

      call function 'CONVERSION_EXIT_ALPHA_INPUT'
        exporting
          input  = lv_matny
        importing
          output = lv_matny.

      if <fs_data2>-potx1 is initial and p_bf ne 'X'.
        select *
        into corresponding fields of table lt_resb
        from resb
        where aufnr eq is_order_key
        and   matnr eq lv_matny
        and   xloek ne 'X'.
      else.
        select *
        into corresponding fields of table lt_resb
        from resb
        where aufnr eq is_order_key
        and   matnr eq lv_matny
        and   xloek ne 'X'
        and   potx1 eq <fs_data2>-potx1.
      endif.


      if lt_resb[] is initial.
        <fs_data2>-mseg = '無(wú)該原物料可替換'.
        <fs_data2>-icon = icon_led_red.
        continue.
      endif.

      loop at lt_resb.

        clear:ls_return,ls_return2,is_order_component_key,
        is_requirement_quantity,is_requirement_quantityx,
        is_storage_location,is_storage_locationx,i_material,i_materialx,
        is_storage_location,is_storage_locationx,lv_message,error.

        move-corresponding lt_resb to is_order_component_key.

        if <fs_data2>-matnr is initial.
          i_material = <fs_data2>-matny.
        else.
          i_material = <fs_data2>-matnr.
        endif.
        call function 'CONVERSION_EXIT_ALPHA_INPUT'
          exporting
            input  = i_material
          importing
            output = i_material.
        i_materialx = 'X'.

        is_storage_location-werks = lt_resb-werks.
        is_storage_locationx-werks = 'X'.

        if <fs_data2>-menge is not initial.
          is_requirement_quantity-quantity = <fs_data2>-menge.
          is_requirement_quantityx-quantity = 'X'.
        endif.
        if <fs_data2>-lgort is not initial.
          is_storage_location-lgort  = <fs_data2>-lgort.
          is_storage_locationx-lgort = 'X'.
        endif.

        clear lv_zcomp.


        if <fs_data2>-matnr is initial."新物料號(hào)為空 組件為原物料號(hào)
          concatenate lt_resb-posnr lt_resb-matnr into lv_zcomp separated by '/'.
        else."新物料號(hào)不為空 修改的是新物料號(hào)的 數(shù)量和庫(kù)區(qū)
          concatenate lt_resb-posnr <fs_data2>-matnr into lv_zcomp separated by '/'.
        endif.

        call function 'CO_XT_COMPONENT_CHANGE'
          exporting
            is_order_key               = is_order_key
            is_order_component_key     = is_order_component_key
            is_requirement_quantity    = is_requirement_quantity
            is_requirement_quantityx   = is_requirement_quantityx
            is_confirmed_quantity      = is_confirmed_quantity
            is_confirmed_quantityx     = is_confirmed_quantityx
            i_material                 = i_material
            i_materialx                = i_materialx
            is_storage_location        = is_storage_location
            is_storage_locationx       = is_storage_locationx
            i_batch                    = i_batch
            i_batchx                   = i_batchx
            i_mi_configuration_object  = i_mi_configuration_object
            i_mi_configuration_objectx = i_mi_configuration_objectx
          importing
            es_bapireturn              = ls_return
            e_error_occurred           = error.

        if error is initial.

          call function 'CO_XT_ORDER_PREPARE_COMMIT'
            importing
              e_order_key      = is_order_key
              es_bapireturn    = ret
              e_error_occurred = error.
          if ( ret-type = 'S' or ret-type = 'W' or ret-type = 'I' ) or ret is initial.

            data :lt_resb_get type table of resbdget,
                  lw_resb_get like line of lt_resb_get.
            clear:lt_resb_get[],lw_resb_get.
            call function 'CO_BC_RESBD_OF_ORDER_GET'
              exporting
                aufnr_act = is_order_key
*               GET_OLD   = ' '
*               NO_MAKTX  = 'X'
*               NO_STATX  = 'X'
*               CHECK_DELETED        = ' '
*               NO_READ   = ' '
*               CHECK_VBKZ_DEL       = 'X'
*               I_ARCHIVE = ' '
              tables
*               ARESB_EXP =
                resbd_get = lt_resb_get[].
            loop at lt_resb_get into lw_resb_get where rsnum = lt_resb-rsnum
            and rspos = lt_resb-rspos
            and rsart = lt_resb-rsart..
              if <fs_data2>-sortf is not initial.
                lw_resb_get-sortf = <fs_data2>-sortf.
              endif.
              modify lt_resb_get from lw_resb_get index sy-tabix.
            endloop.

            call function 'CO_BC_UPDATE_CMP_OF_ORDERS'
*   EXPORTING
*     FLG_BANF_UPD       = YX
*     FLG_CALC_CHK       = YX
*     FLG_LVS_CHK        = YX
*   IMPORTING
*     FLG_LVS            =
              tables
                resbd_get = lt_resb_get[].

          
            call function 'BAPI_TRANSACTION_COMMIT'
              exporting
                wait = 'X'.

            call function 'CO_XT_ORDER_INITIALIZE'.

          endif.

        else.

          call function 'BAPI_TRANSACTION_ROLLBACK'.

    
        endif.

        wait up to 1 seconds.

      endloop.

   
    endloop.
  endloop.

3.刪除 可批量

  data:lt_resb type table of resb with header line.
  data:lt_return type coxt_t_bapireturn with header line.
  data:ls_return type bapiret2.
  data it_resb type coxt_t_resbdel with header line .
  data:lv_matnr   type mara-matnr,
       lv_aufnr   type afko-aufnr,
       lv_message type string,
       lv_error   type c.


  data:ft_return type table of bapiret2 with header line.

  data:begin of lt_aufnr occurs 0,
         aufnr type afpo-aufnr,
       end of lt_aufnr.

  refresh lt_aufnr.

  loop at gt_data3 assigning <fs_data3> where check eq 'X'
  and cellcolor is initial
  and icon ne icon_led_green.
    lt_aufnr-aufnr = <fs_data3>-aufnr.
    append lt_aufnr.
    clear  lt_aufnr.
  endloop.

  sort lt_aufnr.
  delete adjacent duplicates from lt_aufnr.

  loop at lt_aufnr.

    clear:lt_resb[],lt_resb,lv_message,ft_return[],ft_return,ls_return,lv_error,
    lt_return[],lt_return,it_resb[],it_resb.

    loop at gt_data3 assigning <fs_data3> where aufnr eq lt_aufnr-aufnr.

      clear:lv_matnr,lv_aufnr.

      lv_matnr = <fs_data3>-matnr.
      lv_aufnr = <fs_data3>-aufnr.

      call function 'CONVERSION_EXIT_ALPHA_INPUT'
        exporting
          input  = lv_matnr
        importing
          output = lv_matnr.
      call function 'CONVERSION_EXIT_ALPHA_INPUT'
        exporting
          input  = lv_aufnr
        importing
          output = lv_aufnr.

      if <fs_data3>-potx1 is initial and p_bf ne 'X'.
        select rsnum rspos matnr posnr sortf aufnr
        into corresponding fields of table lt_resb
        from resb
        where aufnr eq lv_aufnr
        and   matnr eq lv_matnr
        and   xloek ne 'X'.
      else.
        select rsnum rspos matnr posnr sortf aufnr
        into corresponding fields of table lt_resb
        from resb
        where aufnr eq lv_aufnr
        and   matnr eq lv_matnr
        and   xloek ne 'X'
        and   potx1 eq <fs_data3>-potx1.
      endif.

      if lt_resb[] is initial.
        <fs_data3>-mseg = '無(wú)該物料可刪除'.
        <fs_data3>-icon = icon_led_red.
        continue.
      endif.

    endloop.

    call function 'CO_XT_COMPONENTS_DELETE'
      exporting
        it_resbkeys_to_delete = it_resb[]
      tables
        ct_bapireturn         = lt_return
      exceptions
        delete_failed         = 1
        others                = 2.

    if lt_return[] is initial.
*刷新變量
      perform change_flag_set(saplcozv).
*數(shù)據(jù)更新到DB
      call function 'CO_XT_ORDER_PREPARE_COMMIT'
        importing
          es_bapireturn    = ls_return
          e_error_occurred = lv_error.

      if ( ls_return-type = 'S' or ls_return-type = 'W' or ls_return-type = 'I' )
      or ls_return is initial.
*DB COMMMIT
        call function 'BAPI_TRANSACTION_COMMIT'
          exporting
            wait = 'X'.
*刷新變量
        call function 'CO_XT_ORDER_INITIALIZE'.

        loop at gt_data3 assigning <fs_data3> where aufnr eq lt_aufnr-aufnr.
          <fs_data3>-mseg = '刪除成功'.
          <fs_data3>-icon = icon_led_green.
        endloop.


      else.
        clear: lv_error,ls_return.
        call function 'BAPI_TRANSACTION_ROLLBACK'.
      endif.

    else.

      call function 'BAPI_TRANSACTION_ROLLBACK'.

   
      loop at gt_data3 assigning <fs_data3> where aufnr eq lt_aufnr-aufnr.
        <fs_data3>-mseg = lv_message.
        <fs_data3>-icon = icon_led_red.
      endloop.

      clear lv_message.

    endif.

  endloop.

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個(gè)濱河市桂躏,隨后出現(xiàn)的幾起案子钻趋,更是在濱河造成了極大的恐慌,老刑警劉巖剂习,帶你破解...
    沈念sama閱讀 217,084評(píng)論 6 503
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件蛮位,死亡現(xiàn)場(chǎng)離奇詭異,居然都是意外死亡鳞绕,警方通過(guò)查閱死者的電腦和手機(jī)失仁,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,623評(píng)論 3 392
  • 文/潘曉璐 我一進(jìn)店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來(lái)们何,“玉大人萄焦,你說(shuō)我怎么就攤上這事〈刮希” “怎么了楷扬?”我有些...
    開(kāi)封第一講書人閱讀 163,450評(píng)論 0 353
  • 文/不壞的土叔 我叫張陵,是天一觀的道長(zhǎng)贴见。 經(jīng)常有香客問(wèn)我烘苹,道長(zhǎng),這世上最難降的妖魔是什么片部? 我笑而不...
    開(kāi)封第一講書人閱讀 58,322評(píng)論 1 293
  • 正文 為了忘掉前任镣衡,我火速辦了婚禮,結(jié)果婚禮上档悠,老公的妹妹穿的比我還像新娘廊鸥。我一直安慰自己,他們只是感情好辖所,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,370評(píng)論 6 390
  • 文/花漫 我一把揭開(kāi)白布惰说。 她就那樣靜靜地躺著,像睡著了一般缘回。 火紅的嫁衣襯著肌膚如雪吆视。 梳的紋絲不亂的頭發(fā)上,一...
    開(kāi)封第一講書人閱讀 51,274評(píng)論 1 300
  • 那天酥宴,我揣著相機(jī)與錄音啦吧,去河邊找鬼。 笑死拙寡,一個(gè)胖子當(dāng)著我的面吹牛授滓,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播,決...
    沈念sama閱讀 40,126評(píng)論 3 418
  • 文/蒼蘭香墨 我猛地睜開(kāi)眼般堆,長(zhǎng)吁一口氣:“原來(lái)是場(chǎng)噩夢(mèng)啊……” “哼在孝!你這毒婦竟也來(lái)了?” 一聲冷哼從身側(cè)響起淮摔,我...
    開(kāi)封第一講書人閱讀 38,980評(píng)論 0 275
  • 序言:老撾萬(wàn)榮一對(duì)情侶失蹤浑玛,失蹤者是張志新(化名)和其女友劉穎,沒(méi)想到半個(gè)月后噩咪,有當(dāng)?shù)厝嗽跇?shù)林里發(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 45,414評(píng)論 1 313
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡极阅,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,599評(píng)論 3 334
  • 正文 我和宋清朗相戀三年胃碾,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片筋搏。...
    茶點(diǎn)故事閱讀 39,773評(píng)論 1 348
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡仆百,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出奔脐,到底是詐尸還是另有隱情俄周,我是刑警寧澤,帶...
    沈念sama閱讀 35,470評(píng)論 5 344
  • 正文 年R本政府宣布髓迎,位于F島的核電站峦朗,受9級(jí)特大地震影響,放射性物質(zhì)發(fā)生泄漏排龄。R本人自食惡果不足惜波势,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,080評(píng)論 3 327
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望橄维。 院中可真熱鬧尺铣,春花似錦、人聲如沸争舞。這莊子的主人今日做“春日...
    開(kāi)封第一講書人閱讀 31,713評(píng)論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽(yáng)竞川。三九已至店溢,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間流译,已是汗流浹背逞怨。 一陣腳步聲響...
    開(kāi)封第一講書人閱讀 32,852評(píng)論 1 269
  • 我被黑心中介騙來(lái)泰國(guó)打工, 沒(méi)想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留福澡,地道東北人叠赦。 一個(gè)月前我還...
    沈念sama閱讀 47,865評(píng)論 2 370
  • 正文 我出身青樓,卻偏偏與公主長(zhǎng)得像,于是被迫代替她去往敵國(guó)和親除秀。 傳聞我的和親對(duì)象是個(gè)殘疾皇子糯累,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 44,689評(píng)論 2 354

推薦閱讀更多精彩內(nèi)容