SAP MM BAPI_PO_CREATE1的用法

dicksonjyl560101發表於2015-04-01

SAP MM BAPI_PO_CREATE1的用法  

初步BAPI_PO_CREATE1有了一點了解,下面對這個bapi做一些我的體會講:

下面先程式上, 在程式中我只簡單poheaderpoitem做了一些,生了一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.  "poitem增加容的標記 工作
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.

 

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/29829936/viewspace-1482196/,如需轉載,請註明出處,否則將追究法律責任。

相關文章