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: 

Purchase Order - save data via BADI failed

former_member496861
Participant
0 Kudos

Hi all,

I have created a zfield in a new tab at item level of the purchase order that saved data into a custom table successfully. This is via BADI.

However I like to save the zfield into ci_ekpodb which stored into EKPO. In the function module that does the

updates, i have for a new line item for it to insert into EKPO but it abended with error 'SAPSQL_ARRAY_INSERT_DUPREC".

This insert results in duplicate database records.

The codes are:

data: lt_item_new type table of zpo_trace.

'If lt_item_new is not initial'.

Insert EKPO from table lt_item_new.

Endif.

Have anyone experience insert new line item into EKPO via ci_ekpodb ? Pls share any thoughts.

thanks

Joyce

1 ACCEPTED SOLUTION

tamas_hoznek
Product and Topic Expert
Product and Topic Expert
0 Kudos

CI_EKPODB is a structure to add customer fields to the PO item. So you don't insert anything into a DB table on your own.

You add your new fields to this structure, activate it and then you can use the appropriate BAdI to populate the new fields during the PO processing.

Once you save the PO, these fields will be there in the PO item record.

21 REPLIES 21

tamas_hoznek
Product and Topic Expert
Product and Topic Expert
0 Kudos

CI_EKPODB is a structure to add customer fields to the PO item. So you don't insert anything into a DB table on your own.

You add your new fields to this structure, activate it and then you can use the appropriate BAdI to populate the new fields during the PO processing.

Once you save the PO, these fields will be there in the PO item record.

0 Kudos

Hi Tamas,

What i have have for the codes are:

data: lt_item_new type table of ekpo..

'If lt_item_new is not initial'.

Insert EKPO from table lt_item_new.

Endif.

Somehow, the new line item contain partial data and missing materila number. This is where i get the error.

thanks

Joyce

tamas_hoznek
Product and Topic Expert
Product and Topic Expert
0 Kudos

I'm not sure what exactly are you trying to achieve here.

If you need extra fields in the PO line item, using CI_EKPODB is the proper way to go.

You cannot create new PO item records like that. Nor should you attempt to do this either.

Please explain what you want to do in more detail.

0 Kudos

Hi Tamas,

I need to add 2 extra fields at po line item level using BADI. I used the CI_EKPODB structure which contain the 2 new extra fields. So i try to insert a new line into the PO but it failed.

Q: Is it possible to insert into ekpo using ci_ekpodb thru BADI ?

thanks

Joyce

Edited by: Joyce Chan on Apr 19, 2011 7:59 PM

tamas_hoznek
Product and Topic Expert
Product and Topic Expert
0 Kudos

You don't insert new records into EKPO. If all you want is two new fields in the PO line item, then add them to CI_EKPODB, use the BAdI to populate these new fields, and they will be saved together with the rest of the PO record when the user posts the PO.

Which BAdI are you using? Is it ME_PROCESS_PO? If so, look at the existing implementations to see how that is done... it is a powerful but somewhat complicated BAdI. It was quite a while ago when I used it the last time, so you'll have to investigate to understand how can you achieve your goal.

0 Kudos

Hi Tamas,

I am using ME_GUI_PO_CUST and ME_PROCESS_PO_CUST. The existing implemenataion shows the new custom fields are saved into a custom table. I was trying to save into EKPO instead of using the custom table. Maybe it cannot be done this way. Agree with you that BADI is somewhat complicated.

thank you for your info.

Joyce

former_member628395
Active Participant
0 Kudos

Hi Joyce,

If you are using the BADI, ME_PROCESS_PO_CUST , you can used the method PROCESS_ITEM .

You have a object IM_ITEM on which the method get_data or set_data can be called to populate the data to be sent to the EKPO Table.

Example :


data : ls_ekpo TYPE mepoitem.

CALL METHOD im_item->get_data
    RECEIVING
      re_data = ls_ekpo.

Populate the values against the desired line item as per requirement in the structure ls_ekpo .

Once done, you can use the method set_data of the same instance to pass the data to the structure.


CALL METHOD im_item->set_data
        EXPORTING
          im_data = ls_ekpo.

Hope this helps.

Regards,

Sagar

0 Kudos

HI Sagar,

Thanks for the info. Once populated the data to ls_ekpo and using set_data method, do i still have to use the post method ?

thanks

Joyce

0 Kudos

Method POST is to do something additional when the PO gets saved (so for instance save data in an additional, custom table and the like). You don't need to use it once the data for the item was set (like Sagar said).

0 Kudos

Hi Tamas,

Thanks for the info.

Joyce

0 Kudos

Hi Joyce,

As thamas rightly said, I don't think you will have to use the POST method for your requirement.

Regards,

Sagar

0 Kudos

HI Sagar,

I took out the POST method and add the method SET_DATA in the PROCESS_ITEM.

I got an error that an endless loop occurred during the processing of ME_PROCESS_PO_CUST.

Any ideas ?

thanks

Joyce

0 Kudos

Hi Joyce,

This is something strange. Could you please check the behavior of the same in the debug mode(putting break point in the process_item method).

Also if possible could you please post the code, if possible.

Regards,

Sagar

0 Kudos

Hi Sagar,

I don't get that error anymore. Now i am not able to change save data on the custom fields and not able to save quantity changed on a line item. Looking at the codes below, it_item brings in all line items.

Let me ask you this: Is this flow of get_data() and set_data() correct ?

Also, for each change on an item or addition of an item, you can only do it one at a time when you pass to ls_mepoitem in set_data(). MepoItem is the whole structure of ekpo. So i have to pass one line item at a time ?

data: ls_mepoitem type mepoitem.

data: ls_item type ekpo.

data: it_item type table of ekpo.

ls_mepoitem = im_item->get_data( ).

call function 'Z_MM_CUST_POST'

exporting

i_ebeln = ls_mepoitem-ebeln

tables

it_item = it_item.

loop at it_item into ls_item.

move-corresponding ls_item to ls_mepoitem.

endloop.

call method im_item->set_data

exporting

im_data = ls_mepoitem.

thanks

Joyce

0 Kudos

Hi Joyce,

The method gets called for every line item changed. Suppose you have 4 line item changed out of 10, the event will be getting called 4 times with the data pertaining to a particular line item at a time. You can change the data from the line item as per your requirement.

I assume you are fetching the line item data using your function module, which i feel is not required.

Regards,

Sagar

0 Kudos

Hi Sagar,

The method 'Set_Data' seems to work for every line item changed. However, when i create a new PO, the new line did not capture my custom field. Is there another method i have to use ?

thanks

Joyce

0 Kudos

Hi,

Can anyone please tell me how to implement save and retrieve?

i want to do so for the header data.

So i have added code in the process_header method as shown below:

  ls_ekko = im_header->get_data( ).


  call method im_header->set_data
  exporting
  im_data = ls_ekko.

but nothing is happening.

can u please help me with this?

thanks in advance

Regards,

Shraddha

0 Kudos

hey...i resolved the issue. If you are stuck anywhere lemme know.

Regards,

Shraddha

0 Kudos

HI Shraddha,

How do you save the data ? Also, how can add error messages to validation at the line item level ?

Can i get a pop-up to notify the user of an error ?

thanks

Joyce

0 Kudos

Hi Joyce,

Can you post your code so that i can understand exactly what u r doing..

Regards,

Shraddha

former_member496861
Participant
0 Kudos

thank you for all replies.