‎2007 Aug 14 9:38 AM
Hi all,
I'm using BAPI_PO_CHANGE to delete the PO line item. Below are my codes:
K_POITEM-PO_ITEM = P_LINEITEM.
K_POITEM-DELETE_IND = 'L'.
APPEND K_POITEM TO I_POITEM.
K_POITEMX-PO_ITEM = P_LINEITEM.
K_POITEMX-PO_ITEMX = 'X'.
K_POITEMX-DELETE_IND = 'X'.
APPEND K_POITEMX TO I_POITEMX.
CALL FUNCTION 'BAPI_PO_CHANGE'
EXPORTING
PURCHASEORDER = P_PO
TABLES
RETURN = I_PO_RETURN
POITEM = I_POITEM
POITEMX = I_POITEMX.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING WAIT = C_X.
LOOP AT I_PO_RETURN INTO K_PO_RETURN.
IF K_PO_RETURN-TYPE EQ C_E.
V_FAIL = C_X.
ENDIF.
ENDLOOP.
The problem is, sometime the BAPI is successful, and sometime, in the I_PO_RETURN table, i will have the below errors:
1. I Changing of PO using Enjoy BAPI unsuccessful
2. E PO header data still faulty
3. E User ABC already processing Purch. requisition17504750 0010.
Line 2 & 3 is an error which cause the BAPI to fail.
But when I try to run it in debug mode and stepping into it line by line, it succeed. I was thinking some locks are not released before I call the BAPI, but I have checked and found no locking occur before the BAPI even being called. Is the BAPI itself causing the problem?
Can anyone help me with this?
‎2007 Aug 14 9:47 AM
Hi Mil,
Try using WAIT 5 seconds after COMMT WORK
Regards,
Atish
‎2007 Aug 14 10:01 AM
Hi Atish,
How can I do that? You mean after the BAPI_TRANSACTION_COMMIT? But the return table is already being defined before the BAPI_TRANSACTION_COMMIT. So, putting a WAIT will not change the content of the return table, if I'm not mistaken
‎2007 Aug 15 3:38 AM
‎2007 Aug 15 3:58 AM
Infact you can do this way..
* Call the BAPI to change the Asset Master
CALL FUNCTION 'BAPI_FIXEDASSET_CHANGE'
EXPORTING
companycode = is_final-bukrs
asset = is_final-anln1
subnumber = is_final-anln2
leasing = is_leasing
leasingx = is_leasingx
IMPORTING
return = it_return.
* If Asset Master is changed with out any errors
READ TABLE it_return WITH KEY type = 'E'.
IF sy-subrc = 0.
flag = ' '.
ELSE.
flag = 'X'.
* Call the COMMIT BAPI
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = 'X'.
WAIT UP TO 2 SECONDS.
ENDIF.
* If the Asset Master is changed with out any errors
IF flag = 'X'.
READ TABLE it_output INTO is_output WITH KEY
bukrs = is_final-bukrs
anln1 = is_final-anln1
anln2 = is_final-anln2
BINARY SEARCH.
IF sy-subrc = 0.
* is_output-c_icon = c_green.
is_output-leabg_n = is_final-leabg.
is_output-message = it_return-message.
* Modify the output internal table with the changed new values
MODIFY it_output FROM is_output
TRANSPORTING leabg_n message
WHERE bukrs = is_output-bukrs
AND anln1 = is_output-anln1
AND anln2 = is_output-anln2.
ENDIF.
ELSEIF flag = ' '.
READ TABLE it_output INTO is_output WITH KEY
bukrs = is_final-bukrs
anln1 = is_final-anln1
anln2 = is_final-anln2
BINARY SEARCH.
IF sy-subrc = 0.
* is_output-c_icon = c_red.
is_output-leabg_n = is_leasing-start_date.
is_output-message = it_return-message.
* Modify the output internal table with the changed new values
MODIFY it_output FROM is_output
TRANSPORTING leabg_n message
WHERE bukrs = is_output-bukrs
AND anln1 = is_output-anln1
AND anln2 = is_output-anln2.
ENDIF.
ENDIF.
ENDIF.
Regards
Gopi
‎2007 Aug 15 4:31 AM
I saw your code and no problem at your coding ..
there should be data problem while deleting purchase order
Before deleting ,please lock po number ,and unlock the po once you done ( I guess 3rd erors seems to be lock issue)
Try to do manually in ME22n and see the results.
Thanks
Seshu
‎2007 Aug 15 3:55 AM
Hi. There are two listing's of BAPI's available.
1) BAPI
Transaction BAPI if you have access to the backend. This is a bit flawed as it only lists Function modules that have been defined as BAPI's. I couldn't find your "bapi_poec_create" listed let aloan any others.
2) WebService browser
http://<host>:<port>/sap/bc/bsp/sap/webservicebrowser/search.html
Where <host> = Your SAP WebAS Host name; and <Port> is the active port - In the backend call transaction SMICM if you aren't sure.
This webservicebrowser will list all function modules with the 'RFC' indicator set e.g. that you can call externally. It also lists the WSDL file as it is intended to be used via a SOAP call.
unfortunately both options that you are looking for don't exist - the cange and delete functionality. So I guess it will need to be a bespoke development.
Just as a by the by in R/3 we don't ussally delete PO's once they have been created, but rather delete the line items. That leaves a PO with no line items which in effect is a deleted PO. If that is the way forward then you only need one bespoke process i.e. CHANGE as this could handle change & delete.