SAP MM BAPI_PO_CREATE1的用法
初步对BAPI_PO_CREATE1有了一点了解,下面对这个bapi做一些我的体会讲解:
下面先将程式上传, 在程式中我只简单的对poheader和poitem做了一些输入,产生了一张po,并且po中只可以有一个项被采购,其实其中还有其他可以加入,例如:
schedule,account,一起其他一些东西,,在这个程式中我就不在做介绍了,我将在后续的文章中说出我对这个bapi的其他体会,希望大家关注我的博克,谢!
REPORT
ZCREATPOBAPI
.
TABLES
BAPIMEPOHEADER.
CONSTANTS : C_X
VALUE 'X'.
DATA
WA_POHEADER TYPE BAPIMEPOHEADER. "所要增加的内容
DATA WA_POHEADERX TYPE BAPIMEPOHEADERX. "针对要增加的内容做一个标记,其实标记过了才可以被修改的
DATA WA_POITEM TYPE BAPIMEPOITEM. "po中item的内容,工作区
DATA ITAB_POITEM LIKE TABLE OF WA_POITEM. po中item的内容,内表
DATA WA_POITEMX
TYPE BAPIMEPOITEMX. "po中item增加内容的标记 工作区
DATA ITAB_POITEMX LIKE TABLE OF WA_POITEMX."po中item增加内容的标记 内表
DATA WA_RETURN TYPE BAPIRET2. "消息 返回 ,工作区
DATA ITAB_RETURN LIKE TABLE OF WA_RETURN. "消息返回, 内表
*HEADER.
PARAMETERS: P_NUMBER LIKE BAPIMEPOHEADER-PO_NUMBER,
P_COCODE
LIKE BAPIMEPOHEADER-COMP_CODE DEFAULT 'CN01',
P_DOTYPE
LIKE BAPIMEPOHEADER-DOC_TYPE DEFAULT 'ZST3',
P_STATUS
LIKE BAPIMEPOHEADER-STATUS DEFAULT 'I',
P_CRDATE
LIKE BAPIMEPOHEADER-CREAT_DATE ,
P_CRDABY
LIKE BAPIMEPOHEADER-CREATED_BY DEFAULT SY-UNAME,
P_ITEMIN
LIKE BAPIMEPOHEADER-ITEM_INTVL DEFAULT '1',
P_VENDOR
LIKE BAPIMEPOHEADER-VENDOR DEFAULT 'TWM4',
P_LANGU LIKE BAPIMEPOHEADER-LANGU,
P_PMNTTR
LIKE BAPIMEPOHEADER-PMNTTRMS DEFAULT 'COD',
P_PURCH LIKE BAPIMEPOHEADER-PURCH_ORG DEFAULT 'CN01',
P_PURGR LIKE BAPIMEPOHEADER-PUR_GROUP DEFAULT 'KXX',
P_DOCDAT
LIKE BAPIMEPOHEADER-DOC_DATE,
P_VATCN LIKE BAPIMEPOHEADER-VAT_CNTRY DEFAULT 'CNY'.
*ITEM
SELECTION-SCREEN SKIP.
PARAMETERS: P_POITEM LIKE BAPIMEPOITEM-PO_ITEM DEFAULT '1',
P_MATNER LIKE BAPIMEPOITEM-MATERIAL,
P_PLANT LIKE BAPIMEPOITEM-PLANT DEFAULT 'CKH1',
P_LOCT LIKE BAPIMEPOITEM-STGE_LOC DEFAULT '0000',
P_QUANTI LIKE BAPIMEPOITEM-QUANTITY ,
P_NETPRI LIKE BAPIMEPOITEM-NET_PRICE,
P_PRICEU LIKE BAPIMEPOITEM-PRICE_UNIT,
P_RENAME LIKE BAPIMEPOITEM-PREQ_NAME DEFAULT SY-UNAME,
P_PRDATE LIKE BAPIMEPOITEM-PERIOD_IND_EXPIRATION_DATE DEFAULT
'D'.
*herader data
wa_poheader-po_number = P_NUMBER .
wa_poheader-comp_code = P_COCODE .
wa_poheader-doc_type = P_DOTYPE .
wa_poheader-status = P_STATUS .
wa_poheader-creat_date = P_CRDATE.
wa_poheader-CREATED_BY = P_CRDABY.
wa_poheader-item_intvl = P_ITEMIN.
wa_poheader-vendor = P_VENDOR.
wa_poheader-langu = P_LANGU .
wa_poheader-pmnttrms = P_PMNTTR.
wa_poheader-purch_org = P_PURCH .
wa_poheader-pur_group = P_PURGR .
wa_poheader-doc_date = P_DOCDAT.
wa_poheader-vat_cntry = P_VATCN .
*po header flag
wa_poheaderx-po_number = 'X' .
wa_poheaderx-comp_code = 'X' .
wa_poheaderx-doc_type = 'X' .
wa_poheaderx-status = 'X' .
wa_poheaderx-creat_date = 'X'.
wa_poheaderx-created_by = 'X'.
wa_poheaderx-item_intvl = 'X'.
wa_poheaderx-vendor = 'X'.
wa_poheaderx-langu = 'X' .
wa_poheaderx-pmnttrms = 'X'.
wa_poheaderx-purch_org = 'X' .
wa_poheaderx-pur_group = 'X' .
wa_poheaderx-doc_date = 'X'.
wa_poheaderx-vat_cntry = 'X' .
*po item data
wa_poitem-po_item
= P_POITEM.
wa_poitem-MATERIAL
= P_MATNER .
wa_poitem-PLANT
= P_PLANT .
WA_POITEM-STGE_LOC
= P_LOCT .
wa_poitem-QUANTITY
= P_QUANTI .
wa_poitem-NET_PRICE
= P_NETPRI .
wa_poitem-PRICE_UNIT
= P_PRICEU .
wa_poitem-PREQ_NAME
= P_RENAME .
wa_poitem-PERIOD_IND_EXPIRATION_DATE = P_PRDATE .
APPEND WA_POITEM TO ITAB_POITEM.
*po item flag
wa_poitemx-po_item
= p_poitem.
wa_poitemx-po_itemx
= 'X'.
wa_poitemx-MATERIAL
= 'X' .
wa_poitemx-PLANT
= 'X'.
WA_POITEMX-STGE_LOC
= 'X'.
wa_poitemx-QUANTITY
= 'X'.
wa_poitemx-NET_PRICE
= 'X'.
wa_poitemx-PRICE_UNIT
= 'X'.
wa_poitemx-PREQ_NAME
= 'X'.
wa_poitemx-PERIOD_IND_EXPIRATION_DATE = 'X'.
append wa_poitemx to itab_poitemx.
*call bapi
CALL FUNCTION 'BAPI_PO_CREATE1'
EXPORTING
POHEADER = wa_poheader
POHEADERX = wa_poheaderX
TABLES
RETURN =
ITAB_RETURN
POITEM =
ITAB_POITEM
POITEMX = itab_poitemx.
* POACCOUNT = I_PO_ACCOUNT
* POACCOUNTX = I_PO_ACCOUNTX
* POSCHEDULE = I_PO_SCHEDULE
* POSCHEDULEX = I_PO_SCHEDULEX.
DATA ERROR_LOG
TYPE C.
LOOP AT ITAB_RETURN INTO WA_RETURN.
IF WA_RETURN-TYPE = 'E'.
ERROR_LOG = 'X'.
EXIT.
ENDIF.
CLEAR WA_RETURN.
ENDLOOP.
IF ERROR_LOG = 'X'.
CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'
.
WRITE 'MESSAGE ERROR'.
LOOP AT ITAB_RETURN INTO WA_RETURN.
WRITE: / WA_RETURN-TYPE, WA_RETURN-MESSAGE.
CLEAR WA_RETURN.
ENDLOOP.
ELSE.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
WAIT = 'X'.
LOOP AT ITAB_RETURN INTO WA_RETURN.
WRITE: / WA_RETURN-TYPE ,WA_RETURN-MESSAGE.
CLEAR WA_RETURN.
ENDLOOP.
ENDIF.