BAPI_PO_CREATE1 to Create Purchase Order ME21N

  DATA: ls_poheader LIKE  bapimepoheader,
        ls_poheaderx  LIKE  bapimepoheaderx.
  DATA: ld_ponumber LIKE  bapimepoheader-po_number,
        ls_expheader  LIKE  bapimepoheader,
        ls_exppoexpimpheader  LIKE  bapieikp.
  DATA: lt_return  LIKE TABLE OF bapiret2 WITH HEADER LINE,
        lt_poitem  LIKE TABLE OF bapimepoitem WITH HEADER LINE,
        lt_poitemx  LIKE TABLE OF bapimepoitemx WITH HEADER LINE.

    CLEAR: ls_poheader, ls_poheaderx,
           ld_ponumber, ls_expheader, ls_exppoexpimpheader.
    FREE: lt_return, lt_poitem, lt_poitemx.

    ls_poheader-comp_code   = BUKRS.
    ls_poheader-doc_type    = BSART.
    ls_poheader-purch_org   = EKORG.
    ls_poheader-pur_group   = EKGRP.
    ls_poheader-doc_date    = sy-datum.
    ls_poheader-suppl_plnt  = WERKS.

    ls_poheaderx-comp_code  = 'X'.
    ls_poheaderx-doc_type   = 'X'.
    ls_poheaderx-purch_org  = 'X'.
    ls_poheaderx-pur_group  = 'X'.
    ls_poheaderx-doc_date   = 'X'.
    ls_poheaderx-suppl_plnt = 'X'.


      ADD 10 TO lt_poitem-po_item.
      lt_poitem-material  = MATNR.
      lt_poitem-plant     = WERKS. "receiving plant
      lt_poitem-stge_loc  = LGORT. "receiving sloc
      lt_poitem-quantity  = MENGE.
      lt_poitem-val_type  = BWTAR.
      APPEND lt_poitem.

      ADD 10 TO lt_poitemx-po_item.
      lt_poitemx-material = 'X'.
      lt_poitemx-plant    = 'X'.
      lt_poitemx-stge_loc = 'X'.
      lt_poitemx-quantity = 'X'.
      lt_poitemx-val_type = 'X'.
      APPEND lt_poitemx.

    CALL FUNCTION 'BAPI_PO_CREATE1'
      EXPORTING
        poheader          = ls_poheader
        poheaderx         = ls_poheaderx
      IMPORTING
        exppurchaseorder  = ld_ponumber
        expheader         = ls_expheader
        exppoexpimpheader = ls_exppoexpimpheader
      TABLES
        return            = lt_return
        poitem            = lt_poitem
        poitemx           = lt_poitemx.

    IF ld_ponumber IS NOT INITIAL.
      CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.
    ELSE.
      CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
    ENDIF. 
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s