二维码

[BAPI] ME51N创建采购申请BAPI_REQUISITION_CREATE

Twilight发表于 2019-05-10 11:08Twilight 最后回复于 2019-05-10 11:08 [复制链接] 4485 0

创建采购申请有两个BAPI:BAPI_REQUISITION_CREATE/BAPI_PR_CREATE可以使用,BAPI_REQUISITION_CREATE只能创建简单的采购申请,如果创建L类型委外加工,带有BOM的PR,只能用BAPI_PR_CREATE

程序代码:
  1. FUNCTION zpufm002.
  2. *"----------------------------------------------------------------------
  3. *"*"本地接口
  4. *"  EXPORTING
  5. *"     VALUE(E_MESSAGE) TYPE  ZOTS001
  6. *"     VALUE(E_BANFN) TYPE  BANFN
  7. *"  TABLES
  8. *"      T_ITEM STRUCTURE  ZPUS003
  9. *"      T_TEXT STRUCTURE  ZPUS004 OPTIONAL
  10. *"      T_ACCOUNT STRUCTURE  ZPUS005 OPTIONAL
  11. *"----------------------------------------------------------------------
  12.   DATA:lt_items LIKE TABLE OF  bapiebanc WITH HEADER LINE,
  13.        lt_account LIKE TABLE OF bapiebkn WITH HEADER LINE,
  14.        lt_item_text LIKE TABLE OF bapiebantx WITH HEADER LINE,
  15.        lt_return LIKE bapireturn OCCURS 0 WITH HEADER LINE.

  16.   LOOP AT t_item.
  17.     CLEAR:lt_items.
  18.     IF t_item-banfn IS NOT INITIAL.
  19.       PERFORM frm_conv_input CHANGING t_item-banfn.
  20.     ENDIF.
  21.     IF t_item-flief IS NOT INITIAL.
  22.       PERFORM frm_conv_input CHANGING t_item-flief.
  23.     ENDIF.
  24.     IF t_item-infnr IS NOT INITIAL.
  25.       PERFORM frm_conv_input CHANGING t_item-infnr.
  26.     ENDIF.
  27.     IF t_item-lifnr IS NOT INITIAL.
  28.       PERFORM frm_conv_input CHANGING t_item-lifnr.
  29.     ENDIF.
  30.     lt_items-preq_no    = t_item-banfn.
  31.     lt_items-preq_item  = t_item-bnfpo.
  32.     lt_items-doc_type   = t_item-bsart.
  33.     lt_items-item_cat   = t_item-pstyp.
  34.     lt_items-acctasscat = t_item-knttp.
  35.     lt_items-distrib    = t_item-vrtkz.
  36.     IF t_item-matnr IS NOT INITIAL.
  37.       PERFORM frm_conversion_matnr_input CHANGING t_item-matnr.
  38.       lt_items-material = t_item-matnr.
  39.     ENDIF.
  40.     lt_items-batch      = t_item-charg.
  41.     lt_items-short_text = t_item-txz01.
  42.     lt_items-mat_grp    = t_item-matkl.
  43.     lt_items-vend_mat   = t_item-idnlf.
  44.     lt_items-quantity   = t_item-menge.
  45.     lt_items-unit       = t_item-meins.
  46.     lt_items-del_datcat = t_item-lpein.
  47.     lt_items-deliv_date = t_item-lfdat.
  48.     lt_items-preq_date = t_item-badat.
  49.     lt_items-rel_date = t_item-frgdt.
  50.     lt_items-gr_ind = t_item-wepos.
  51.     lt_items-gr_non_val = t_item-weunb.
  52.     lt_items-ir_ind = t_item-repos.
  53.     lt_items-agreement = t_item-konnr.
  54.     lt_items-agmt_item = t_item-ktpnr.
  55.     lt_items-fixed_vend = t_item-flief.
  56.     lt_items-info_rec = t_item-infnr.
  57.     lt_items-des_vendor = t_item-lifnr.
  58.     lt_items-purch_org = t_item-ekorg.
  59.     lt_items-suppl_plnt = t_item-reswk.
  60.     lt_items-req_blocked = t_item-blckd.
  61.     lt_items-reason_blocking = t_item-blckt.
  62.     lt_items-created_by = sy-uname.
  63.     lt_items-preq_name = t_item-afnam.
  64.     lt_items-trackingno = t_item-bednr.
  65.     lt_items-pur_group = t_item-ekgrp.
  66.     lt_items-mrp_contr = t_item-dispo.
  67.     lt_items-plant = t_item-werks.
  68.     lt_items-store_loc = t_item-lgort.
  69.     APPEND lt_items.
  70.   ENDLOOP.

  71.   IF t_account[] IS NOT INITIAL.
  72.     LOOP AT t_account.
  73.       CLEAR:lt_account.
  74.       IF t_account-banfn IS NOT INITIAL.
  75.         PERFORM frm_conv_input CHANGING t_account-banfn.
  76.       ENDIF.
  77.       IF t_account-sakto IS NOT INITIAL.
  78.         PERFORM frm_conv_input CHANGING t_account-sakto.
  79.       ENDIF.
  80.       IF t_account-kostl IS NOT INITIAL.
  81.         PERFORM frm_conv_input CHANGING t_account-kostl.
  82.       ENDIF.
  83.       IF t_account-anln1 IS NOT INITIAL.
  84.         PERFORM frm_conv_input CHANGING t_account-anln1.
  85.       ENDIF.
  86.       IF t_account-anln2 IS NOT INITIAL.
  87.         PERFORM frm_conv_input CHANGING t_account-anln2.
  88.       ENDIF.
  89.       IF t_account-aufnr IS NOT INITIAL.
  90.         PERFORM frm_conv_input CHANGING t_account-aufnr.
  91.       ENDIF.
  92.       IF t_account-vbeln IS NOT INITIAL.
  93.         PERFORM frm_conv_input CHANGING t_account-vbeln.
  94.       ENDIF.
  95.       lt_account-preq_no   = t_account-banfn.
  96.       lt_account-preq_item = t_account-bnfpo.
  97.       lt_account-serial_no = t_account-dzebkn.
  98.       lt_account-preq_qty  = t_account-menge.
  99.       lt_account-unload_pt = t_account-ablad.
  100.       lt_account-g_l_acct  = t_account-sakto.
  101.       lt_account-co_area   = t_account-kokrs.
  102.       lt_account-cost_ctr  = t_account-kostl.
  103.       lt_account-asset_no  = t_account-anln1.
  104.       lt_account-sub_number = t_account-anln2.
  105.       lt_account-order_no  = t_account-aufnr.
  106.       lt_account-sd_doc    = t_account-vbeln.
  107.       lt_account-sdoc_item = t_account-vbelp.
  108.       lt_account-delete_ind = t_account-loekz.
  109.       APPEND lt_account.
  110.     ENDLOOP.
  111.   ENDIF.

  112.   IF t_text[] IS NOT INITIAL.
  113.     LOOP AT t_text.
  114.       CLEAR:lt_item_text.
  115.       IF t_text-banfn IS NOT INITIAL.
  116.         PERFORM frm_conv_input CHANGING t_text-banfn.
  117.       ENDIF.
  118.       lt_item_text-preq_no   = t_text-banfn.
  119.       lt_item_text-preq_item = t_text-bnfpo.
  120.       lt_item_text-text_id   = t_text-text_id.
  121.       lt_item_text-text_form = t_text-text_form.
  122.       lt_item_text-text_line = t_text-text_line.
  123.       APPEND lt_item_text.
  124.     ENDLOOP.
  125.   ENDIF.


  126.   CALL FUNCTION 'BAPI_REQUISITION_CREATE'
  127. * EXPORTING
  128. *   SKIP_ITEMS_WITH_ERROR                =
  129. *   AUTOMATIC_SOURCE                     = 'X'
  130.     IMPORTING
  131.       number                         = e_banfn
  132.     TABLES
  133.       requisition_items              = lt_items
  134.       requisition_account_assignment = lt_account
  135.       requisition_item_text          = lt_item_text
  136.       return                         = lt_return.

  137.   LOOP AT lt_return WHERE type CA 'AEX'.
  138.     IF e_message-message IS INITIAL.
  139.       e_message-message   = lt_return-message.
  140.     ELSE.
  141.       CONCATENATE e_message-message lt_return-message INTO e_message-message SEPARATED BY '/'.
  142.     ENDIF.
  143.   ENDLOOP.
  144.   IF sy-subrc = 0.
  145.     CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
  146.     e_message-type   = 'E'.
  147.   ELSE.
  148.     CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
  149.       EXPORTING
  150.         wait = 'X'.
  151.     e_message-type    = 'S'.
  152.     e_message-message = '采购申请创建成功!'.
  153.   ENDIF.

  154. ENDFUNCTION.
  155. FORM frm_conversion_matnr_input  CHANGING pc_matnr TYPE mara-matnr.
  156.   CALL FUNCTION 'CONVERSION_EXIT_MATN1_INPUT'
  157.     EXPORTING
  158.       input        = pc_matnr
  159.     IMPORTING
  160.       output       = pc_matnr
  161.     EXCEPTIONS
  162.       length_error = 1
  163.       OTHERS       = 2.
  164. ENDFORM.                    " FRM_INPUTSAP_DATA
  165. FORM frm_conv_input CHANGING pc_vbeln.
  166.   CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
  167.     EXPORTING
  168.       input  = pc_vbeln
  169.     IMPORTING
  170.       output = pc_vbeln.
  171. ENDFORM.
复制代码
注意:BAPIEBANTX-TEXT_FORM 采购申请项目长文本,回车多行,直接赋值*即可,BAPI中会自动计算
回复

使用道具 举报

快速回帖

本版积分规则
您需要登录后才可以回帖 登录 | 注册有礼

快速回复 返回顶部 返回列表