Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

PO Header Z field is not updated, using classic BADI ME_PROCESS_PO_CUST

Former Member
0 Kudos

Hi Experts,

I have implemented classic badi ME_PROCESS_PO_CUST using interface METHOD if_ex_me_process_po_cust~post.

However the ZZDISPO field i created in PO header is not update, so i tried with standard field which is IHREZ, it is not updated as well. Is it something wrong with my code?

below is my code:


  break abap01.
  DATA: ls_mepoitem TYPE mepoitem,
      ls_mepoheader TYPE mepoheader,
      g_dispo TYPE dispo,
      cl_po TYPE REF TO cl_po_header_handle_mm.

  ls_mepoheader = im_header->get_data( ).

  IMPORT g_dispo TO g_dispo FROM MEMORY ID 'g_dispo'.
  IF g_dispo IS NOT INITIAL.
    ls_mepoheader-zzdispo = g_dispo.
    ls_mepoheader-ihrez = '12345'.

* Updating the Header
    cl_po ?= im_header.
    cl_po->my_ibs_firewall_on = 'X'.
    CALL METHOD im_header->set_data( im_data = ls_mepoheader ).
    CALL METHOD im_header->set_changed( ).
  ENDIF.

Any help is greatly appreciated.

Thanks.

10 REPLIES 10

Former Member

Try below code,

break abap01.
  DATA: ls_mepoitem TYPE mepoitem,
      ls_mepoheader TYPE mepoheader,
      ls_empoheaderx type mepoheaderx,       "New structure added"

      g_dispo TYPE dispo,
      cl_po TYPE REF TO cl_po_header_handle_mm.
 
  ls_mepoheader = im_header->get_data( ).
 
  IMPORT g_dispo TO g_dispo FROM MEMORY ID 'g_dispo'.
  IF g_dispo IS NOT INITIAL.
    ls_mepoheader-zzdispo = g_dispo.
    ls_mepoheader-ihrez = '12345'.

    ls_empoheaderx-zzdispo = 'X'.                 "Added"
    ls_empoheaderx-ihrez = 'X'.                     "Added"
* Updating the Header
    cl_po ?= im_header.
    cl_po->my_ibs_firewall_on = 'X'.
    CALL METHOD im_header->set_data( im_data = ls_mepoheader ).
    call method im_header->set_datax( im_data = ls_mepoheaderx ).               "Added"
    CALL METHOD im_header->set_changed( ).
  ENDIF.

Regards

Vinod

0 Kudos

Hi Vinod,

I got error "Method SAVE_DATAX does not exist" after inserting ur codes.

any solution?

Thanks.

0 Kudos

In Class builder (se24) for the class "cl_po_header_handle_mm" are you able to see the method "set_datax"? If yes do the following changes.

*ls_mepoheader = im_header->get_data( ).            "Comment"
**Add these lines
    call method cl_po->get_data                      
    importing
      ex_data = ls_mepoheader.
** Till here.
*    cl_po ?= im_header.                                           "Comment"
*   CALL METHOD im_header->set_data( im_data = ls_mepoheader ).  "Comment"
*    call method im_header->set_datax( im_data = ls_mepoheaderx ).  "Comment"
*    CALL METHOD im_header->set_changed( ).  "Comment"
**Add these lines
    CALL METHOD cl_po->set_data( im_data = ls_mepoheader ).
    call method cl_po->set_datax( im_data = ls_mepoheaderx ).
**Till here.

Regards

Vinod

0 Kudos

Hi Vinod,

Thanks for the reply.

But after applied your codes, the result is still same... PO Posted successfully without updating my custom field as well as standard field. Anything i still miss out?

I putting these codes in if_ex_me_process_po_cust~POST. Is tat correct?

Should i put in other interface like CLOSE?

0 Kudos

Method is correct, Try to use this line

call method ch_po->set_bapi_data( ls_header_new ) instead of CALL METHOD cl_po->set_data( im_data = ls_mepoheader ).

Regards

Vinod

0 Kudos

Hi Vinod,

Sorry i got the error Method 'SET_BAPI_DATA' does not exist.

0 Kudos

Is MM functional Consultant need to set something in their SPRO?

0 Kudos

In Class builder (se24) for the class "cl_po_header_handle_mm" are you able to see the method "set_bapi_data"?

Regards

Vinod

0 Kudos

Hi Vinod,

l_po_header_handle_mm contains method 'CHECK_BAPI_DATAX'.

it require parameter im_data_new, im_data_old and im_datax_old with the following codes:


METHOD check_badi_datax.

  DATA: lr_struct  TYPE REF TO cl_abap_structdescr,
        lr_element TYPE REF TO cl_abap_elemdescr.

  FIELD-SYMBOLS: <old>     TYPE ANY,
                 <target>  TYPE ANY,
                 <targetx> TYPE ANY,
                 <mapping> TYPE abap_compdescr,
                 <xmap>    TYPE abap_compdescr.

  ex_datax_new = im_datax_old.

  lr_struct  ?= cl_abap_structdescr=>describe_by_data( im_data_new ).

  LOOP AT lr_struct->components ASSIGNING <mapping>.

    ASSIGN COMPONENT <mapping>-name OF STRUCTURE im_data_old TO <old>.
    CHECK sy-subrc IS INITIAL.
    ASSIGN COMPONENT <mapping>-name OF STRUCTURE im_data_new TO <target>.
    CHECK: sy-subrc IS INITIAL,
           <old> NE <target>.                               "910250
    ASSIGN COMPONENT <mapping>-name OF STRUCTURE ex_datax_new TO <targetx>.
    CHECK sy-subrc IS INITIAL.
    CHECK <old> NE <target>.
    lr_element ?= cl_abap_typedescr=>describe_by_data( <targetx> ).
    CHECK lr_element->absolute_name EQ '\TYPE=BAPIUPDATE'.
    <targetx> = mmpur_yes.
  ENDLOOP.

ENDMETHOD.

Should I call this method?

arthur_fuscella
Participant
0 Kudos

Hi,

In the newest SAP versions, method set_datax is implicit in BAPI and you can't call it by your program.

I'm not sure if you can change header data during posting. Instead of using POST method to change header data uses method PROCESS_HEADER. This method will be called when you change any data, even items.

Please check the code that I implemented below:

*- begin of method data

   DATA: re_items  TYPE purchase_order_items ,

          re_item  LIKE LINE OF re_items ,

             item  TYPE REF TO if_purchase_order_item_mm ,

         poheader  TYPE mepoheader ,

           poitem  TYPE mepoitem ,

          stopper  TYPE sap_bool .

*- end of method data

   re_items  = im_header->get_items( ) . " items data

   CLEAR stopper .

   LOOP AT re_items  INTO re_item .

     CHECK stopper = ' ' .

     poitem  = re_item-item->get_data( ) .

     IF poitem-afnam <> ' ' .

*     requisitioner exists

       poheader  = im_header->get_data( ) " header data

       poheader-unsez  = poitem-afnam .

       IF im_header->is_changeable( ) = 'X' .

         im_header->set_data( poheader ) . " changing data

         im_header->set_changed( ) .

       ENDIF .

       stopper = 'X' .

     ENDIF .

   ENDLOOP .