Skip to Content
avatar image
Former Member

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.

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

3 Answers

  • Best Answer
    avatar image
    Former Member
    Aug 05, 2009 at 05:39 AM

    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

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member

      Hi ShreeMohan and Akagus,

      I am trying to do the same to unlock the po at the header fiield using a custom field called 'zzpoblock'. This field is a checked field. I used a combintion of the sample coding that both of you presented. I got a warning issued on my program.

      The warning is 'Error transferring ExtensionIn data for Enhancement CI_EKPODB'.

      The program ran and I am unable to get zzpoblock to become blank. I think i have to manipulate with ExtensionIN data.

      Did you get the warning in your program ?

      thanks

      Joyce

  • avatar image
    Former Member
    Aug 05, 2009 at 03:10 AM

    I dont understand your purpose.

    Why have you extended bapi_te_mepoheader the structure?

    I dont see that getting passed to the BAPI.

    You need to populate the below tables and send to the BAPI for custom fields. You can get more information about it in the Documentation of the BAPI.

    *" EXTENSIONIN STRUCTURE BAPIPAREX OPTIONAL

    *" EXTENSIONOUT STRUCTURE BAPIPAREX OPTIONAL

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member

      The ZZSCOPE custom field is currently only updated using IDOC type PORDCH which has been extended to use bapi_te_mepoheader to update the custom fields. So I have taken this logic to write my program.

      I am not an ABAP developer and my ABAP knowledge is limited. I am having difficulty understanding the BAPI documentation.

      Are you able to provide more specific guidance / code examples?

  • avatar image
    Former Member
    Mar 14, 2016 at 01:28 PM

    Unable to activate this code due to error "I_EXTENSION-VALUEPART1" and "S_BAPI_TE_MEPOHEADER" are not mutually convertible in Unicode systems in the line 'i_extension-valuepart1 = s_bapi_te_mepoheader.'

    Please suggest me how to activate this code?

    Add comment
    10|10000 characters needed characters exceeded

    • Hi Sunil,

      that means you have added a field that is not of type character (CHAR, NUMC, DATS etc.) to CI_EKPODB. That doesn't work since the field Transport is done by writing the record with the Extension fields to a Long character string. On Unicode Systems you cannot write a data structure containing a binary field to a text string.

      You Need to make sure all fields in CI_EKPODB are character based fields.

      Regards

      Oliver