DEMO: ME51N 创建PR BAPI_PR_CREATE

时间:2022-10-01 07:17:57

货铺QQ群号:834508274


DEMO: ME51N  创建PR   BAPI_PR_CREATE



*&---------------------------------------------------------------------*
*& BAPI_REQUISITION_CREATE 和 BAPI_PR_CREATE 相关问题查看NOTE
*& 499627 - FAQ BAPIs for
*&---------------------------------------------------------------------*
REPORT ZLM_PR_CREATE.
DATA:LV_BANFN TYPE EBAN-BANFN .
DATA:LV_BNFPO TYPE EBAN-BNFPO .
DATA:LS_PRITEM TYPE BAPIMEREQITEMIMP .
DATA:LS_PRITEMX TYPE BAPIMEREQITEMX .
DATA:LT_PRITEM TYPE TABLE OF BAPIMEREQITEMIMP .
DATA:LT_PRITEMX TYPE TABLE OF BAPIMEREQITEMX .
DATA:LS_HEAD TYPE BAPIMEREQHEADER .
DATA:LS_HEADX TYPE BAPIMEREQHEADERX.
DATA:LT_BAPIRETURN TYPE TABLE OF BAPIRET2 .
*
PARAMETERS:P_MATNR TYPE MATNR .
PARAMETERS:P_EKORG TYPE EKORG .
PARAMETERS:P_WERKS TYPE WERKS_D .
START-OF-SELECTION.
'NB'."订单类型
LS_HEADX-PR_TYPE = 'X' .
CLEAR LV_BNFPO.
LV_BNFPO = LV_BNFPO + 10 ."项目号
LS_PRITEM-PREQ_ITEM = LV_BNFPO .
LS_PRITEM-PREQ_NAME = SY-UNAME.
*ls_PRITEM-TRACKINGNO = 'TRACKNO'.
LS_PRITEM-MATERIAL = P_MATNR.
LS_PRITEM-PLANT = P_WERKS.
LS_PRITEM-PURCH_ORG = P_EKORG.
10.
LS_PRITEM-DELIV_DATE = SY-DATUM.
*ls_PRITEM-FIXED = 'X'
*ls_PRITEM-PUR_GROUP = '109'.
APPEND LS_PRITEM TO LT_PRITEM .
LS_PRITEMX-PREQ_ITEM = LV_BNFPO .
'X'.
'X'.
'X'.
'X'.
'X'.
*ls_PRITEMX-FIXED = 'X'
*ls_PRITEMX-PREQ_NAME = 'X'.
*ls_PRITEMX-TRACKINGNO = 'X'
*IF ls_PRITEM-PUR_GROUP <> ''
* ls_PRITEMX-PUR_GROUP = 'X'.
*ENDIF .
APPEND LS_PRITEMX TO LT_PRITEMX .
FUNCTION 'BAPI_PR_CREATE' EXPORTING PRHEADER = LS_HEAD PRHEADERX = LS_HEADX IMPORTING NUMBER = LV_BANFN TABLESRETURN PRITEM = LT_PRITEM PRITEMX = LT_PRITEMX.
IF
FUNCTION 'BAPI_TRANSACTION_COMMIT' EXPORTING'X'.
WRITE:LV_BANFN.
ELSE.
FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
ENDIF.