创建PR:
BAPI_REQUISITION_CREATE
BAPI_PR_CREATE "Create Enjoy Purchase Requisistion(这是新函数)
BAPI_PR_CHANGE
BAPI_PR_CREATE
BAPI_PR_GETDETAIL
相关函数:
函数组 函数组短文本
功能模块名称 函数模块短文本
MEWF 批准的BAPI
BAPI_REQUISITION_RELEASE 批准采购请求
BAPI_REQUISITION_RELEASE_GEN
BAPI_REQUISITION_RESET_RELEASE 取消请购的下达
BAPI_REQUISITION_RESET_REL_GEN
MEWQ
BAPI_REQUISITION_CHANGE
BAPI_REQUISITION_CREATE
BAPI_REQUISITION_DELETE
BAPI_REQUISITION_GETDETAIL
BAPI_REQUISITION_GETITEMS
BAPI_REQUISITION_GETITEMSREL
BAPI_REQUISITION_GETRELINFO
FUNCTION ZRFC_OA_CREATE_PR.
*"----------------------------------------------------------------------
*"*"Local interface:
*" EXPORTING
*" VALUE(EX_RESULT) TYPE CHAR1
*" VALUE(EX_BANFN) TYPE BANFN
*" TABLES
*" DATA_TAB STRUCTURE ZOA_PR01
*" RETURN STRUCTURE BAPIRET2
*" PR_NEW STRUCTURE ZOA_PR02
*"----------------------------------------------------------------------
DATA: GT_DATA TYPE TABLE OF ZOA_PR01 WITH HEADER LINE .
DATA: PR_ITEM LIKE TABLE OF BAPIEBANC WITH HEADER LINE,
PR_ACCOUNT LIKE TABLE OF BAPIEBKN WITH HEADER LINE,
PR_ITEM_ID LIKE TABLE OF BAPIEBANTX WITH HEADER LINE,
PR_RETURN LIKE TABLE OF BAPIRETURN WITH HEADER LINE,
PR_REL LIKE TABLE OF BAPIMMPARA WITH HEADER LINE.
DATA: L_RETURN LIKE PR_RETURN.
DATA: LV_MESSAGE(255).
DATA: PR_NO TYPE BAPIEBANC-PREQ_NO.
DATA: BNFPO TYPE BNFPO.
DATA: PP_FILE TYPE STRING.
RETURN-MESSAGE = '开始调用接口。创建采购申请'.
RETURN-TYPE = 'I'.
APPEND RETURN.
IF DATA_TAB[] IS INITIAL.
RETURN-MESSAGE = '没有可以处理数据'.
RETURN-TYPE = 'E'.
APPEND RETURN.
ENDIF.
LOOP AT DATA_TAB.
MOVE-CORRESPONDING DATA_TAB TO GT_DATA.
DATA: LINE(10) TYPE C.
DATA: LV_DATE TYPE SY-DATUM.
WRITE SY-TABIX TO LINE.
IF DATA_TAB-MATNR IS INITIAL .
CONCATENATE '行 ' LINE ' 请输入物料编号' INTO RETURN-MESSAGE .
APPEND RETURN.
ELSE.
GT_DATA-MATNR = DATA_TAB-MATNR."物料编号
ENDIF.
IF DATA_TAB-MENGE IS INITIAL.
CONCATENATE '行 ' LINE ' 请输入数量' INTO RETURN-MESSAGE .
APPEND RETURN.
ELSE.
GT_DATA-MENGE = DATA_TAB-MENGE."数量
ENDIF.
IF DATA_TAB-MEINS IS INITIAL.
CONCATENATE '行 ' LINE ' 请输入单位' INTO RETURN-MESSAGE .
APPEND RETURN.
ELSE.
GT_DATA-MEINS = DATA_TAB-MEINS."单位
ENDIF.
* GT_DATA-MEINS = 'PCS'. "强制使用PCS
IF DATA_TAB-EEIND IS INITIAL.
CONCATENATE '行 ' LINE ' 请输入交货时间' INTO RETURN-MESSAGE .
APPEND RETURN.
ELSE.
* CONCATENATE DATA_TAB-EEIND+0(4) DATA_TAB-EEIND+5(2) DATA_TAB-EEIND+8(2) INTO LV_DATE.
** gt_data-eeind = data_tab-value_0005."交货时间
* CALL FUNCTION 'DATE_CHECK_PLAUSIBILITY'
* EXPORTING
* DATE = LV_DATE
* EXCEPTIONS
* PLAUSIBILITY_CHECK_FAILED = 1
* OTHERS = 2.
* IF SY-SUBRC <> 0.
** WRITE : / '请按格式YYYY-MM-DD 输入正确的日期'.
* CONCATENATE '行 ' LINE ' 请按格式YYYY-MM-DD 输入正确的日期' INTO RETURN-MESSAGE .
* APPEND RETURN.
* ELSEIF SY-SUBRC = 0 .
* GT_DATA-EEIND = LV_DATE.
GT_DATA-EEIND = DATA_TAB-EEIND.
* ENDIF.
ENDIF.
GT_DATA-BSART = DATA_TAB-BSART."'NB'. "凭证类型
GT_DATA-WERKS = DATA_TAB-WERKS ."'1000'. "工厂
COLLECT GT_DATA.
CLEAR GT_DATA.
ENDLOOP.
LOOP AT GT_DATA.
BNFPO = GT_DATA-BNFPO.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
INPUT = BNFPO
IMPORTING
OUTPUT = BNFPO.
PR_ITEM-PREQ_ITEM = BNFPO. "项目
PR_ITEM-MATERIAL = GT_DATA-MATNR.
PR_ITEM-DOC_TYPE = GT_DATA-BSART. "凭证类型
PR_ITEM-ACCTASSCAT = GT_DATA-KNTTP."科目分配类别
PR_ITEM-SHORT_TEXT = GT_DATA-TXZ01."短文本
PR_ITEM-QUANTITY = GT_DATA-MENGE. "数量
PR_ITEM-UNIT = GT_DATA-MEINS."单位
PR_ITEM-DELIV_DATE = GT_DATA-EEIND. "交货日期
PR_ITEM-MAT_GRP = GT_DATA-MATKL. "物料组
PR_ITEM-PLANT = GT_DATA-WERKS."工厂
PR_ITEM-PUR_GROUP = GT_DATA-EKGRP."采购组
PR_ITEM-PREQ_NAME = GT_DATA-AFNAM."申请者
PR_ITEM-TRACKINGNO = GT_DATA-BEDNR."需求跟踪号
PR_ITEM-C_AMT_BAPI = GT_DATA-PREIS."评估价格
PR_ITEM-CURRENCY = GT_DATA-WAERS."货币码
PR_ITEM-PRICE_UNIT = GT_DATA-PEINH."价格单位
PR_ITEM-MRP_CONTR = GT_DATA-DISPO."MRP控制者
PR_ITEM-TRACKINGNO = GT_DATA-BEDNR."跟踪号
PR_ITEM-STORE_LOC = GT_DATA-LGORT."库存
PR_ITEM-VEND_MAT = GT_DATA-IDNLF." OA : ID
PR_ITEM-GR_IND = 'X'."GR
PR_ITEM-IR_IND = 'X'."IR
APPEND PR_ITEM.
CLEAR PR_ITEM.
pr_account-preq_item = bnfpo. "项目
pr_account-g_l_acct = gt_data-sakto. "总帐科目
pr_account-cost_ctr = gt_data-kostl. "成本中心
* pr_account-asset_no = gt_data-anln1. "资产
* pr_account-order_no = gt_data-aufnr. "订单
* pr_account-co_area = 'BELL'.
APPEND pr_account.
CLEAR pr_account.
PR_REL-PO_REL_IND = 'X'.
PR_REL-REL_IND ='X'.
APPEND PR_REL.
*
* pr_item_id-preq_item = bnfpo."项目
* pr_item_id-text_id = 'B03'.
* pr_item_id-text_line = gt_data-str1."行项目文本-传送文本
* APPEND pr_item_id.
* CLEAR pr_item_id.
*
* pr_item_id-preq_item = bnfpo."项目
* pr_item_id-text_id = 'B07'.
* pr_item_id-text_line = gt_data-str2."行项目文本-预算年度
* APPEND pr_item_id.
* CLEAR pr_item_id.
*
* pr_item_id-preq_item = bnfpo."项目
* pr_item_id-text_id = 'B08'.
* pr_item_id-text_line = gt_data-str3."行项目文本-资产类别
* APPEND pr_item_id.
* CLEAR pr_item_id.
*
* AT END OF BEDNR.
*
*
* ENDAT.
ENDLOOP.
CALL FUNCTION 'BAPI_REQUISITION_CREATE'
EXPORTING
AUTOMATIC_SOURCE = ''
SKIP_ITEMS_WITH_ERROR = ''
IMPORTING
NUMBER = PR_NO
TABLES
REQUISITION_ITEMS = PR_ITEM
REQUISITION_ACCOUNT_ASSIGNMENT = pr_account
RETURN = PR_RETURN.
LOOP AT PR_RETURN .
MOVE-CORRESPONDING PR_RETURN TO RETURN.
APPEND RETURN.
ENDLOOP.
* APPEND LINES OF PR_RETURN TO RETURN.
READ TABLE PR_RETURN WITH KEY TYPE = 'E' .
IF SY-SUBRC = 0.
CLEAR: LV_MESSAGE.
CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
LOOP AT PR_RETURN INTO L_RETURN WHERE TYPE = 'E' .
CONCATENATE LV_MESSAGE L_RETURN-MESSAGE ';'
INTO LV_MESSAGE.
ENDLOOP.
CONCATENATE GT_DATA-BEDNR LV_MESSAGE INTO PR_NEW-TEXT.
APPEND PR_NEW.
CLEAR PR_NEW.
EX_RESULT = 'E'.
ELSE.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
WAIT = 'X'.
CONCATENATE PR_NO '创建成功' INTO PR_NEW-TEXT.
PR_NEW-BANFN = PR_NO.
APPEND PR_NEW.
CLEAR PR_NEW.
EX_RESULT = 'S'.
EX_BANFN = PR_NO.
*批准采购申请
WAIT UP TO 5 SECONDS.
PERFORM APPROVE_PR USING PR_NO.
ENDIF.
FREE PR_ITEM.
FREE PR_ACCOUNT.
FREE PR_ITEM_ID.
FREE PR_RETURN.
RETURN-MESSAGE = '结束调用接口。创建采购申请'.
RETURN-TYPE = 'I'.
APPEND RETURN.
ENDFUNCTION.