‎2006 Aug 28 3:35 PM
I've read some contradicting posts regarding bapi: BAPI_PR_CHANGE. I was under the impression you could add line items to a requisition using this BAPI? Can it be said for certain it can not be done? The documentation is rather lacking.
Thanks!
Enrique Leon
‎2006 Aug 28 4:41 PM
Try to use BAPI_REQUISITION_CREATE or BAPI_REQUISITION_CHANGE
‎2006 Aug 28 4:55 PM
These bapis are more limited (can't maintain delivery address or even deletion indicator). Also, you can't add line items through these BAPI's as specified in the documentation or SAP Notes.
It isn't clear thought if adding line items to existing reqs is available for BAPI_PR_CHANGE. ThoughtS?
‎2006 Sep 05 3:01 PM
Just so everyone knows, I had a hell of a time finding a thread that answered this question....
BAPI_PR_CHANGE can in fact append line items to already existing requisitions. There are certain fields required and you must specify the req line number yourself. A commit is also needed.
Enrique Leon
‎2006 Oct 10 11:01 AM
Enrique,
I have attempted to use BAPI_PR_CHANGE to add line items, but even with all item update fields set and all basic data specified for the new item it does not insert the new item . In debug I can not see how it could perform this task. I use the BAPI commit function and also receive a success message back, but no new item is added.
You seem to have this working however, so could you specify here which fields are required to allow new items to be added?
James Grant
‎2006 Oct 10 1:11 PM
Could you post what code you are using? Or at least the x-structure?
Some key fields you must include are the PREQ_ITEM for the new line, it can not be blank. So if you want to add a new line with ID of say, 00050, then it must be specified in the pritem,pritemx,praccount,praccountx, etc.
Also, for serial # you might need to provide '01' in the account structure. I can't be certain what this is for however.
Also, please note that we have encountered some issues with this BAPI, particularly:
1. Text can not be changed on an existing req line
2. Price can not be changed on an existing req line
3. Long text is inserted incorrectly if more than one 133 character line is provided.
Hope this helps, good luck. BTW, we ended up using a BDC for this. Its a bit crazy, but functional.
‎2006 Oct 10 2:10 PM
Thanks for your reply. I have decided to use BDC for this as well. I had already tried those things you mention with no luck and with other issues surrounding this function it is less risky to use a BDC for now.
Cheers, James
‎2010 Mar 31 10:14 AM
it's very easy to do this with this BAPI.
If you have experiences with BAPI_PO_CHANGE you have done this within some minutes.
Here's some sample-coding. Maybe this will help you:
LOOP AT it_change_pr INTO wa_change_pr.
ADD 10 TO lv_pr_counter.
wa_pritem-preq_item = lv_pr_counter. "Item Number of Purchase Requisition
wa_pritem-material = wa_change_pr-orig_matnr. "Materialnumber
wa_pritem-plant = lv_plant. "Plant
wa_pritem-pur_group = lv_pur_group. "Purchasing Group
wa_pritem-store_loc = lv_store_loc. "Storage Location
wa_pritem-quantity = wa_change_pr-menge. "Purchase Requisition Quantity
wa_pritem-unit = wa_change_pr-meins. "Purchase Requisition Unit of Measure
wa_pritem-del_datcat_ext = lv_del_datcat. "Date type (day, week, month, interval)
wa_pritem-deliv_date = lv_deliv_date. "Item Delivery Date
wa_pritem-fixed_vend = wa_change_pr-lifnr. "Fixed Vendor
CLEAR: temp_matnr.
CONCATENATE '0000000000' wa_change_pr-matnr INTO temp_matnr.
SELECT SINGLE * FROM mbew
WHERE matnr = temp_matnr
AND bwkey = wa_change_pr-werks.
IF sy-subrc = 0.
wa_pritem-preq_price = mbew-stprs. "Price in purchase requisition
wa_pritem-price_unit = mbew-peinh. "Price Unit
ENDIF.
wa_pritem-purch_org = lv_purch_org. "Purchasing Organization
** wa_pritem-po_unit = wa_change_pr-meins. "Purchase Order Unit of Measure
wa_pritem-vend_mat = wa_change_pr-matnr. "Material number used by vendor
wa_pritemx-preq_item = lv_pr_counter.
wa_pritemx-preq_itemx = 'X'.
wa_pritemx-material = 'X'.
wa_pritemx-plant = 'X'.
wa_pritemx-store_loc = 'X'.
wa_pritemx-pur_group = 'X'.
wa_pritemx-quantity = 'X'.
wa_pritemx-unit = 'X'.
wa_pritemx-del_datcat_ext = 'X'.
wa_pritemx-deliv_date = 'X'.
wa_pritemx-fixed_vend = 'X'.
wa_pritemx-preq_price = 'X'.
wa_pritemx-price_unit = 'X'.
wa_pritemx-purch_org = 'X'.
wa_pritemx-vend_mat = 'X'.
APPEND wa_pritemx TO it_pritemx.
APPEND wa_pritem TO it_pritem.
ENDLOOP.
CALL FUNCTION 'BAPI_PR_CHANGE'
EXPORTING
number = lv_banfn
* PRHEADER =
* PRHEADERX =
* TESTRUN =
* IMPORTING
* PRHEADEREXP =
TABLES
return = it_change_return
pritem = it_pritem
pritemx = it_pritemx
* PRITEMEXP =
* PRITEMSOURCE =
* PRACCOUNT =
* PRACCOUNTPROITSEGMENT =
* PRACCOUNTX =
* PRADDRDELIVERY =
* PRITEMTEXT =
* PRHEADERTEXT =
* EXTENSIONIN =
* EXTENSIONOUT =
* PRVERSION =
* PRVERSIONX =
* ALLVERSIONS =
.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
* EXPORTING
* WAIT =
* IMPORTING
* RETURN =
.
‎2010 Apr 23 1:36 PM
Torsten,
Have you added items using BAPI_PR_CHANGE in a 4.7 system? I can change items using BAPI_PR_CHANGE but I can't seem to add items to a PR. I have to use this BAPI as I need to change the delivery address and it's not available in BAPI_REQUISITION_CHANGE.
I copied the code you specified, it did not work for me. The option I am faced with is coding a BDC.
Regards,
Derick Logan
‎2010 Apr 23 7:12 PM
Hi Torsten,
I figured this out. The code for BAPI_PR_CHANGE is flawed in 4.7 and will not allow you to add items. I copied the BAPI and corrected the code and it works.
Regards,
Derick Logan
‎2010 Aug 26 8:49 AM
Hi Torsten,
I want add a new line in PR document. So i am using your code to do the same.
But the BAPI is returning error mesasage 'Enter G/L Account'.
Then i passed the GL number to the table parameter PRACCOUNT and 'X' for GL number to the table parameter PRACCOUNTX.
But after passing these two values, again i am getting the same error in return table of BAPI.
Now there are no parameter in any of the table of this BAPI , where i can pass GL number.
So what could be the reason for this error?
Regards
Pankaj Giri