Skip to Content
avatar image
Former Member

BAPI BAPI_PO_CREATE1 not updating custom fields in Purchase Orders

Hi all,

I am trying to create a Purchase order with few custom fields using the BAPI BAPI_PO_CREATE1, but I am able to create PO successfully but not able to populate the custom fields.

I have extended the structures BAPI_TE_MEPOITEM & BAPI_TE_MEPOITEMX by extending CI_EKPODB & CI_EKPODBX respectively. The custom fields are added in the same sequence in both the structures. Please find the below code that I was using to create a PO with custom fields.

Kindly let me know if I am missing anything. The offset measurements are carefully crosschecked. (I have searched the SDN and other blogs before raising the question in this forum, and everywhere the same content is found which I am following)

ls_header-comp_code   = lv_compcode.
ls_header-doc_type    = lv_doctype.
ls_header-creat_date  = sy-datum .
ls_header-vendor      = lv_vendor.
ls_header-langu       = sy-langu.
ls_header-purch_org   = lv_purchorg.
ls_header-pur_group   = lv_grp.

ls_headerx-comp_code   = abap_true.
ls_headerx-doc_type    = abap_true.
ls_headerx-creat_date  = abap_true.
ls_headerx-vendor      = abap_true.
ls_headerx-langu       = abap_true.
ls_headerx-purch_org   = abap_true.
ls_headerx-pur_group   = abap_true.

ls_item-po_item  = '00010'.
ls_item-plant    = lv_plant.
ls_item-quantity = '10'.
ls_item-tax_code = lv_taxcode.
ls_item-material = lv_matnr.

APPEND ls_item TO lt_item.
CLEAR ls_item.


ls_itemx-po_item = '00010'.
ls_itemx-po_itemx = abap_true.


ls_itemx-plant = abap_true .
ls_itemx-quantity = abap_true .
ls_itemx-tax_code = abap_true.
ls_itemx-material = abap_true.
APPEND ls_itemx TO lt_itemx.
CLEAR ls_itemx.

ls_ext-structure = 'BAPI_TE_MEPOITEM'.
ls_ext-valuepart1+0(5) = '00010'. "line item
ls_ext-valuepart1+5(4) = lv_f1.
ls_ext-valuepart1+9(3) = lv_f2.
ls_ext-valuepart1+18(14) = lv_f3.
ls_ext-valuepart1+32(1) = lv_f4.


APPEND ls_ext TO lt_ext.
CLEAR ls_ext.

ls_ext-structure = 'BAPI_TE_MEPOITEMX'.
ls_ext-valuepart1+0(5) = '00010'. "line item
ls_ext-valuepart1+8(1) = abap_true. 
ls_ext-valuepart1+9(1) = abap_true.
 ls_ext-valuepart1+10(1) = abap_true. 
ls_ext-valuepart1+12(1) = abap_true. 
APPEND ls_ext TO lt_ext.
CLEAR ls_ext.


CALL FUNCTION 'BAPI_PO_CREATE1'
  EXPORTING
    poheader         = ls_header
    poheaderx        = ls_headerx
  IMPORTING
    exppurchaseorder = lv_purchase_ord
  TABLES
    return           = lt_return
    poitem           = lt_item
    poitemx          = lt_itemx
    extensionin      = lt_ext.


LOOP AT lt_return TRANSPORTING NO FIELDS
  WHERE type = 'E'
  AND  type = 'A'

  DATA(lv_error) = 'X'.

ENDLOOP.

IF  lv_error = 'X'.
  CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'
* IMPORTING
*   RETURN        =
    .
ELSE.
  CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
* EXPORTING
*   WAIT          =
* IMPORTING
*   RETURN        =
    . 
ENDIF.

Thanks in advance,

Vishal

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

2 Answers

  • Dec 15, 2017 at 05:15 PM

    check the offset here - ls_ext-valuepart1+8(1)= abap_true.

    I think it should be ls_ext-valuepart1+5(1)= abap_true.

    Add comment
    10|10000 characters needed characters exceeded

  • Dec 15, 2017 at 07:05 PM

    I don't know the specific answer but I did just a quick Google search for BAPI_TE_MEPOITEM, checked a couple of SCN posts in the top results and your code doesn't look at all like what is mentioned in the answers. For example, I see others are actually using structure BAPI_TE_MEPOITEM and not offset. I'd suggest to look again at the answered SCN questions, as well as SAP notes on this and this wiki, for example, and adjust your code accordingly. Also try with just one field first. When it works, you can add others.

    Also check the messages returned by BAPI. And there is always debugger, of course.

    Add comment
    10|10000 characters needed characters exceeded