‎2009 Aug 05 7:20 PM
Hello all,
i am trying to insert a items into SALESDOCUMENT, i am making the following process.
i have a SALESDOCUMENT from which a make a copy then i delete all the ITEMS and i try to insert the new one, i am trying to insert a new ITEMS which has relations with another material i am making this because i am expecting when i insert the ITEMS all the material will be recalculated.
for example
position material quantity.
10 6050 1 this is the main material
20 7228 30 This is child record of the main material
30 7143 1 this is child record of the main material.
when i run my function i need to modify the main material as this
position material quantity
10 6050 2.
so i am expecting
position material quantity.
10 6050 2 this is the main material
20 7228 60 This is child record of the main material
30 7143 2 this is child record of the main marial.
CALL FUNCTION 'BAPI_SALESORDER_CHANGE'
EXPORTING
salesdocument = p_copia "this is the copy
order_header_inx = are_headx " value U
TABLES
return = tab_retor
order_item_in = tab_items
order_item_inx = tab_itemx
schedule_lines = tab_sched
schedule_linesx = tab_schex.
but i really i don`t how to do it, i have been using the bapi BAPI_SALESORDER_CHANGE, this bapi delete the items this is ok , but not insert the items that i need , 'does anybody has make something like this, i will really apprecite if someone give a hand, please.
‎2009 Aug 06 1:53 PM
REPORT zsalesorder_change .
* Data declarations.
DATA:i_bapi_view LIKE order_view.
DATA:sales_documents LIKE sales_key OCCURS 0 WITH HEADER LINE.
*ORDER_OUT
DATA:order_items_out LIKE bapisdit OCCURS 0 WITH HEADER LINE.
DATA:order_headers_out LIKE bapisdhd OCCURS 0 WITH HEADER LINE.
DATA:order_header_inx LIKE bapisdh1x.
***ORDER_IN
DATA:order_item_in LIKE bapisditm OCCURS 0 WITH HEADER LINE.
DATA:order_header_in LIKE bapisdh1 OCCURS 0 WITH HEADER LINE.
DATA:order_item_inx LIKE bapisditmx OCCURS 0 WITH HEADER LINE.
DATA:schedule_lines LIKE bapischdl OCCURS 0 WITH HEADER LINE.
DATA:schedule_linesx LIKE bapischdlx OCCURS 0 WITH HEADER LINE.
DATA: i_hdr TYPE bapisdh1.
DATA: itab_item LIKE bapisditem OCCURS 0 WITH HEADER LINE.
DATA: itab_ch LIKE itab_item OCCURS 0 WITH HEADER LINE.
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.
DATA: BEGIN OF i_sched OCCURS 10.
INCLUDE STRUCTURE bapischdl.
DATA: END OF i_sched.
DATA: BEGIN OF i_schedx OCCURS 10.
INCLUDE STRUCTURE bapischdlx.
DATA: END OF i_schedx.
DATA : zmsg(50) TYPE c.
* Parameters
SELECTION-SCREEN : BEGIN OF BLOCK order WITH FRAME TITLE text-001.
SELECTION-SCREEN SKIP.
PARAMETERS: p_vbeln TYPE vbap-vbeln OBLIGATORY,
pval TYPE vbap-bwtar .
SELECTION-SCREEN : END OF BLOCK order.
order_header_in-sd_doc_cat = 'C'.
order_header_inx-updateflag = 'U'.
i_bapi_view-header = 'X'.
i_bapi_view-item = 'X'.
sales_documents-vbeln = p_vbeln.
APPEND sales_documents.
Edited by: krupa jani on Aug 6, 2009 2:54 PM
‎2009 Aug 05 7:28 PM
Hi,
try to flag UPDATEFLAG field as 'U', in ORDER_ITEM_INX table, for line item you are trying to modify.
Regards,
Frisoni
‎2009 Aug 05 7:41 PM
Hi ,
You need to update order_header_inx , ITEM_INX, schedule_in & schedule_inx structures..
Just pass.
wa_header_inx-updateflag = 'U'.
In ITEM_INX.
IT_items_INX-updateflag = 'U'.
Here you have to have the value of the field as 'X' for those which you planned to change.like
MATERIAL, TARGET_QTY etc etc..
v_cnt is the new item no calculated..
Populating Schedule Lines
it_schedule_in-itm_number = v_cnt.
it_schedule_in-sched_line = '0001'.
it_schedule_in-req_qty = 1.
it_schedule_in-req_date = sy-datum.
*Index Table
it_schedule_inx -updateflag = 'I'.
it_schedule_inx -itm_number = V_CNT.
it_schedule_inx -sched_line = 1.
Append all the tables...
‎2009 Aug 06 1:53 PM
REPORT zsalesorder_change .
* Data declarations.
DATA:i_bapi_view LIKE order_view.
DATA:sales_documents LIKE sales_key OCCURS 0 WITH HEADER LINE.
*ORDER_OUT
DATA:order_items_out LIKE bapisdit OCCURS 0 WITH HEADER LINE.
DATA:order_headers_out LIKE bapisdhd OCCURS 0 WITH HEADER LINE.
DATA:order_header_inx LIKE bapisdh1x.
***ORDER_IN
DATA:order_item_in LIKE bapisditm OCCURS 0 WITH HEADER LINE.
DATA:order_header_in LIKE bapisdh1 OCCURS 0 WITH HEADER LINE.
DATA:order_item_inx LIKE bapisditmx OCCURS 0 WITH HEADER LINE.
DATA:schedule_lines LIKE bapischdl OCCURS 0 WITH HEADER LINE.
DATA:schedule_linesx LIKE bapischdlx OCCURS 0 WITH HEADER LINE.
DATA: i_hdr TYPE bapisdh1.
DATA: itab_item LIKE bapisditem OCCURS 0 WITH HEADER LINE.
DATA: itab_ch LIKE itab_item OCCURS 0 WITH HEADER LINE.
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.
DATA: BEGIN OF i_sched OCCURS 10.
INCLUDE STRUCTURE bapischdl.
DATA: END OF i_sched.
DATA: BEGIN OF i_schedx OCCURS 10.
INCLUDE STRUCTURE bapischdlx.
DATA: END OF i_schedx.
DATA : zmsg(50) TYPE c.
* Parameters
SELECTION-SCREEN : BEGIN OF BLOCK order WITH FRAME TITLE text-001.
SELECTION-SCREEN SKIP.
PARAMETERS: p_vbeln TYPE vbap-vbeln OBLIGATORY,
pval TYPE vbap-bwtar .
SELECTION-SCREEN : END OF BLOCK order.
order_header_in-sd_doc_cat = 'C'.
order_header_inx-updateflag = 'U'.
i_bapi_view-header = 'X'.
i_bapi_view-item = 'X'.
sales_documents-vbeln = p_vbeln.
APPEND sales_documents.
Edited by: krupa jani on Aug 6, 2009 2:54 PM
‎2009 Aug 06 1:54 PM
continue..................................................
***GET LIST OF SALESORDER
CALL FUNCTION 'BAPISDORDER_GETDETAILEDLIST'
EXPORTING
i_bapi_view = i_bapi_view
TABLES
sales_documents = sales_documents
order_headers_out = order_headers_out
order_items_out = order_items_out.
LOOP AT order_items_out .
MOVE-CORRESPONDING order_items_out TO order_item_in.
order_item_in-val_type = pval.
APPEND order_item_in.
ENDLOOP.
LOOP AT order_item_in .
MOVE-CORRESPONDING order_item_in TO itab_ch.
APPEND itab_ch.
ENDLOOP.
LOOP AT itab_ch .
* Header update indicator
s_order_header_inx-updateflag = 'U'.
i_order_item_in-itm_number = itab_ch-itm_number .
i_order_item_in-material = itab_ch-material.
i_order_item_in-target_qty = itab_ch-target_qty.
i_order_item_in-sales_unit = itab_ch-sales_unit.
i_order_item_in-val_type = itab_ch-val_type.
i_order_item_inx-updateflag = 'I'.
i_order_item_inx-itm_number = itab_ch-itm_number .
i_order_item_inx-material = itab_ch-material.
i_order_item_inx-target_qty = 'X'.
i_order_item_inx-sales_unit = itab_ch-sales_unit.
i_order_item_inx-val_type = 'X'.
APPEND: i_order_item_in, i_order_item_inx.
** Fill schedule lines
i_sched-itm_number = itab_ch-itm_number .
i_sched-sched_line = '0001'.
i_sched-req_qty = itab_ch-target_qty.
APPEND i_sched.
* Fill schedule line flags
i_schedx-itm_number = itab_ch-itm_number .
i_schedx-sched_line = '0001'.
i_schedx-updateflag = 'I'.
i_schedx-req_qty = 'X'.
APPEND i_schedx.
ENDLOOP.
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
schedule_lines = i_sched
schedule_linesx = i_schedx.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = 'X'.
LOOP AT it_return.
WRITE / it_return-message.
ENDLOOP.
‎2009 Aug 06 2:53 PM
gilos,
i guess you have to use 'BAPI_SALESORDER_CREATEFROMDAT2'
to update (for example remove the items from) a sales order you are using the right BAPI, but to create a new one, you have to use the above one, both are very similar
Check more details in tcode BAPI
at the menu choose: "Sales and Distribution" >> Sales >> Sales Order >> Create from data 2
i hope it's was helpful.