SAP R/3 форум ABAP консультантов
Russian ABAP Developer's Club

Home - FAQ - Search - Memberlist - Usergroups - Profile - Log in to check your private messages - Register - Log in - English
Blogs - Weblogs News

Delete Sales Order Item using BAPI



 
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> SD
View previous topic :: View next topic  
Author Message
admin
Администратор
Администратор



Joined: 01 Sep 2007
Posts: 1640

PostPosted: Sun Oct 14, 2007 9:49 pm    Post subject: Delete Sales Order Item using BAPI Reply with quote

Author: Jelena

Here is a very quick test example of the line deletion:

Code:
PARAMETERS: p_vbeln TYPE vbeln,
p_posnr TYPE posnr.

DATA: s_order_header_in LIKE bapisdh1.
DATA: s_order_header_inx LIKE bapisdh1x.

DATA: BEGIN OF i_order_item_in OCCURS 0.
INCLUDE STRUCTURE bapisditm.
DATA: END OF i_order_item_in.
DATA: BEGIN OF i_order_item_inx OCCURS 0.
INCLUDE STRUCTURE bapisditmx.
DATA: END OF i_order_item_inx.
DATA: BEGIN OF it_return OCCURS 0.
INCLUDE STRUCTURE bapiret2.
DATA: END OF it_return.

* Header update indicator
s_order_header_inx-updateflag = 'U'.

* Line items
i_order_item_in-itm_number = p_posnr.
i_order_item_inx-updateflag = 'D'.
i_order_item_inx-itm_number = p_posnr.
APPEND: i_order_item_in, i_order_item_inx.

CALL FUNCTION 'BAPI_SALESORDER_CHANGE'
EXPORTING
salesdocument = p_vbeln
order_header_in = s_order_header_in
order_header_inx = s_order_header_inx
behave_when_error = 'P'
TABLES
return = it_return
order_item_in = i_order_item_in
order_item_inx = i_order_item_inx.

LOOP AT it_return.
MESSAGE
ID it_return-id
TYPE 'I'
NUMBER it_return-number
WITH
it_return-message_v1
it_return-message_v2
it_return-message_v3
it_return-message_v4.
ENDLOOP.

CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = 'X'.

Possible causes for the line not being deleted:
1. BAPI_TRANSACTION_COMMIT is missing
2. BAPI fields are populated incorrectly
3. A subsequent document (e.g. an outbound delivery) exists for the line item. Such line items can not be deleted.

Usually the message table returned by BAPI (it_return) should provide a clue. I'm using a hardcoded message type 'I' in this test to display all the messages. Sometimes the message type returned by BAPI does not make much sense (e.g. some messages that should really be errors are returned with type W or S). Also don't bother checking SY-SUBRC - it's almost always 0.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> SD All times are GMT + 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum


All product names are trademarks of their respective companies. SAPNET.RU websites are in no way affiliated with SAP AG.
SAP, SAP R/3, R/3 software, mySAP, ABAP, BAPI, xApps, SAP NetWeaver and any other are registered trademarks of SAP AG.
Every effort is made to ensure content integrity. Use information on this site at your own risk.