Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

Using BAPI_PO_CHANGE to update custom field

Hi Experts,

The following code updates the 'Your Reference' field on PO header using BAPI_PO_CHANGE.

The code is also supposed to update a custom field on PO header (ZZSCOPE), but I cant seem to get that bit to work.

The custom field is contained in BAPI_TE_MEPOHEADER (BAPI Interface for Customer Enhancements for MEPOHEADER).

Can anyone please advise the code which I am missing (I suspect I am missing a couple of lines of code during CALL FUNCTION 'BAPI_PO_CHANGE')

Any advice is much appreciated.

REPORT  Z_MASS_UNLOCK_PO.

PARAMETERS: DOCNO(10) OBLIGATORY,
            MESSAGE(20) OBLIGATORY.

DATA: s_header TYPE bapimepoheader,
        s_headerx TYPE bapimepoheaderx,
        s_TE_header TYPE bapi_te_mepoheader,
        s_TE_headerx TYPE bapi_te_mepoheaderx,
        i_return TYPE bapiret2 OCCURS 0 WITH HEADER LINE,
        i_extension TYPE bapiparex OCCURS 0 WITH HEADER LINE,
        s_bapimepoheader TYPE bapimepoheader occurs 0 with header line,
        s_bapimepoheaderx TYPE bapimepoheaderx occurs 0 with header line,
        s_bapi_te_mepoheader TYPE bapi_te_mepoheader occurs 0 with header line,
        s_bapi_te_mepoheaderx TYPE bapi_te_mepoheaderx occurs 0 with header line,
        wa_message TYPE c LENGTH 100.

  s_bapimepoheaderx-po_number = 'X'.
  s_bapimepoheader-po_number = DOCNO.

*Update 'Your Reference' field
  s_bapimepoheaderx-REF_1 = 'X'.
  s_bapimepoheader-REF_1 = MESSAGE.

*Update 'ZZSCOPE' field
  s_bapi_te_mepoheaderx-ZZSCOPE = 'X'.
  s_bapi_te_mepoheader-ZZSCOPE = 'TEST123'.

  CALL FUNCTION 'BAPI_PO_CHANGE'
    EXPORTING
      purchaseorder = DOCNO
      POHEADER      = s_bapimepoheader
      POHEADERX     = s_bapimepoheaderx
    TABLES
      return        = i_return.

*Message types: S Success, E Error, W Warning, I Info, A Abort

*Supress all Warning Messages
 DELETE i_return WHERE ( TYPE EQ 'W' ).


*Commit only if no errors have been returned
  read table i_return with key type = 'E'.
  if sy-subrc ne 0.
    COMMIT WORK AND WAIT.
  endif.

*Display Return Messages on Screen
  LOOP AT i_return.
    WRITE: /   'RETURN MESSAGE: ',
    'ID: ',
    i_return-id,
    ' TYPE: ',
    i_return-type,
    ' NUMBER: ',
    i_return-number,
    ' ',
    i_return-message.
  ENDLOOP.

Former Member
Former Member replied

Hi,

I had same requirment and seems to be working.

Please look in following code.

We have a custom field EKKO-ZZDELIVERYDATE.

To work with BAPI, this field must be included in two structures:

1) BAPI_TE_MEPOHEADER, there is an include CI_EKKODB. Add the Z field there with the same type as on EKKO. (I actually didn't have to do this - either somebody has already done this or it happened automatically when the field was added, not sure).

2) BAPI_TE_MEPOHEADERX, include CI_EKKODBX. Add the field with the same name but type BAPIUPDATE (!).

PARAMETERS:  p_ebeln TYPE ebeln,
             p_date LIKE sy-datum.
 
DATA: s_header TYPE bapimepoheader,
      s_headerx TYPE bapimepoheaderx,
      i_return TYPE bapiret2 OCCURS 0 WITH HEADER LINE,
      i_extension TYPE bapiparex OCCURS 0 WITH HEADER LINE,
      s_bapi_te_mepoheader TYPE bapi_te_mepoheader,
      s_bapi_te_mepoheaderx TYPE bapi_te_mepoheaderx,
      wa_date TYPE ekko-zzdeliverydate,
      wa_message TYPE c LENGTH 100.
 
s_bapi_te_mepoheaderx-po_number = p_ebeln.
s_bapi_te_mepoheaderx-zzdeliverydate = 'X'.
s_bapi_te_mepoheader-po_number = p_ebeln.
s_bapi_te_mepoheader-zzdeliverydate = p_date.
i_extension-structure = 'BAPI_TE_MEPOHEADER'.
i_extension-valuepart1 = s_bapi_te_mepoheader.
APPEND i_extension.
i_extension-structure = 'BAPI_TE_MEPOHEADERX'.
i_extension-valuepart1 = s_bapi_te_mepoheaderx.
APPEND i_extension.
 
s_header-po_number = p_ebeln.
 
CALL FUNCTION 'BAPI_PO_CHANGE'
  EXPORTING
    purchaseorder = p_ebeln
  TABLES
    return        = i_return
    extensionin   = i_extension.
 
COMMIT WORK.
LOOP AT i_return.
  MESSAGE ID   i_return-id
       TYPE    i_return-type
       NUMBER  i_return-number WITH
               i_return-message_v1
               i_return-message_v2
               i_return-message_v3
               i_return-message_v4.
ENDLOOP.

Thanks & Regards,

ShreeMohan

0 View this answer in context

Helpful Answer

by
Not what you were looking for? View more on this topic or Ask a question