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: 

BAPI_PO_CHANGE

Former Member
0 Kudos

I am working on an interface where I need to change the price of the PO's, and for this I will be getting an input file which will have the material no's and the price associated to those. I need to select PO's based on the following conditions:

document type = 'NB' and purchasing group = '111' and DCI = ' '. name of the requistner = 'ABC' and item_delivery date = 06/12/2007

and then once the PO is selected I need to update the price of the PO's for a specific material from the input file.

For this so far I have written the following code.

select ebeln into table it_ekko

from ekko

where bsart = 'NB' and

ekgrp = 111.

select ebeln ebelp matnr netpr into table it_ekpo

from ekpo

for all entries in it_ekko

where elikz = ' ' and

afnam = 'ABC'

ebeln = it_ekko-ebeln.

select ebeln eindt into table it_eket

from ekrt

for all entries in it_ekpo

where eindt = '6/12/2007' and

ebeln = it_ekpo-ebeln.

can you please tell me is this is right and if this is right can you also tell me how to proceed further, I mean now I just need to change the netpr with the price that I have in my input table as per the matnr.

Thanks

Rajeev

4 REPLIES 4

Former Member
0 Kudos

One thing to check when you use for all entries is to make sure the internal table you are referring to has values. Otherwise it will get the all entries from the second table. look at the code below

select ebeln into table it_ekko

from ekko

where bsart = 'NB' and

ekgrp = 111.

if not it_ekko[] is initial. " This is crucial when you use for all entries

select ebeln ebelp matnr netpr into table it_ekpo

from ekpo

for all entries in it_ekko

where elikz = ' ' and

afnam = 'ABC'

ebeln = it_ekko-ebeln.

endif.

if not it_ekpo[] is initial.

select ebeln eindt into table it_eket

from eket

for all entries in it_ekpo

where eindt = '6/12/2007' and

ebeln = it_ekpo-ebeln.

endif.

0 Kudos

Thanks very much for the reply Krishna....can you please tell how to proceed further...I mean can you please help me in changing the price of the PO's.

Thanks

Rajeev

0 Kudos

Check this sample code for BAPI_PO_CHANGE.

This should help you in your coding.

http://www.sap-img.com/abap/sample-abap-code-on-bapi-po-change.htm

ashish

0 Kudos

Here is some sample code

sort infile by ebeln ebelp.

loop at infile.

  • Remove any commas

translate infile-onetpr using ', '.

  • Condense after removing the commas

condense infile-onetpr no-gaps.

i_poitem-po_item = infile-ebelp.

i_poitemx-po_item = infile-ebelp.

  • Update price only if the old value is diff. from new value.

if infile-nnetpr ne infile-onetpr.

i_poitem-net_price = infile-onetpr.

i_poitemx-net_price = 'X'.

endif.

  • Update currency if the old value is diff. from new value.

if infile-owaers ne infile-nwaers.

v_header-currency = infile-owaers.

v_headerx-currency = 'X'.

v_flag = 'X'.

endif.

  • Update price unit if the old value is diff. from new val.

if infile-opeinh ne infile-npeinh.

i_poitem-price_unit = infile-opeinh.

i_poitemx-price_unit = 'X'.

endif.

append i_poitem.

append i_poitemx.

clear: i_poitem, i_poitemx.

at end of ebeln.

refresh i_return.

if v_flag = 'X'.

  • If the currency change is needed

call function 'BAPI_PO_CHANGE'

exporting

purchaseorder = infile-ebeln

poheader = v_header

poheaderx = v_headerx

testrun = p_test

no_messaging = 'X'

no_price_from_po = 'X'

importing

expheader = v_headerout

tables

poitem = i_poitem

poitemx = i_poitemx

return = i_return.

else.

  • If currency change is not neeeded.

call function 'BAPI_PO_CHANGE'

exporting

purchaseorder = infile-ebeln

testrun = p_test

no_messaging = 'X'

no_price_from_po = 'X'

importing

expheader = v_headerout

tables

poitem = i_poitem

poitemx = i_poitemx

return = i_return.

endif.

clear: v_flag, v_header, v_headerx.

clear v_first.

sort i_return by type id number.

delete adjacent duplicates from i_return.

loop at i_return where type = 'E' or

( type = 'S' and id = '06' and number = '022' ).

if v_first is initial.

write: / 'Unable to update', infile-ebeln.

v_first = 'X'.

endif.

i_err-ebeln = infile-ebeln.

i_err-message = i_return-message.

append i_err.

write: /5 i_return-message.

delete i_return.

endloop.

if sy-subrc ne 0.

refresh i_return.

call function 'BAPI_TRANSACTION_COMMIT'

importing

return = i_return.

loop at i_return where type = 'E'.

write: / i_return-message.

endloop.

if sy-subrc ne 0.

write: / 'Successfully updated the PO', infile-ebeln.

endif.

endif.

refresh i_poitem.

refresh i_poitemx.

endat.

endloop.