‎2008 Jun 24 8:59 AM
Hi,
I have a Problem. I would like create a salesorder with References to a other salesorder.
Unfortunately, I have no idea what I need reference property.
Following objects I have tried: "BUS2032" "/AFS/ORDER".
I hope you can help me.
thx
‎2008 Jun 24 9:06 AM
BAPI_SALESORDER_CREATEFROMDAT2 is not possible....
use...BAPISDORDER_GETDETAILEDLIST
then BAPI_SALESORDER_CREATEFROMDATA
example code...
ORM sub_create_ret_order TABLES p_posqty TYPE zslo_posnr_qty_t
CHANGING p_ret_order TYPE zslo_ret_dispo.
Sales order creation using reference is not possible in BAPI, So
getting details of original return order using this subroutine
PERFORM sub_get_o_ret_order_dtls USING p_ret_order-zzret_ord.
Subroutine for preparing the reture order line items for subsequent
return order
PERFORM sub_make_order_items USING p_ret_order.
Subroutine for creating the subsequent return order using BAPI
PERFORM sub_create_order_bapi TABLES p_posqty
CHANGING p_ret_order.
ENDFORM. " sub_create_ret_order
&----
*& Form sub_get_o_ret_order_dtls
&----
This subroutine is used to get the details of original ret order
----
--> P_VBELN Sales order no
----
FORM sub_get_o_ret_order_dtls USING p_vbeln TYPE vbeln_va.
wa_order_view = c_str.
wa_sales_key-vbeln = p_vbeln.
APPEND wa_sales_key TO i_sales_key.
CALL FUNCTION 'BAPISDORDER_GETDETAILEDLIST'
EXPORTING
i_bapi_view = wa_order_view
TABLES
sales_documents = i_sales_key
order_headers_out = i_bapisdhd
order_items_out = i_bapisdit
order_schedules_out = i_bapisdhedu
order_business_out = i_bapisdbusi
order_partners_out = i_bapisdpart
order_address_out = i_bapisdcoad
order_statusheaders_out = i_bapisdhdst
order_statusitems_out = i_bapisditst
order_conditions_out = i_bapisdcond
order_cond_head = i_bapicondhd
order_cond_item = i_bapicondit
order_cond_qty_scale = i_bapicondqs
order_cond_val_scale = i_bapicondvs
order_contracts_out = i_bapisdcntr
order_textheaders_out = i_bapisdtehd
order_textlines_out = i_bapitextli
order_flows_out = i_bapisdflow
order_cfgs_curefs_out = i_bapicurefm
order_cfgs_cucfgs_out = i_bapicucfgm
order_cfgs_cuins_out = i_bapicuinsm
order_cfgs_cuprts_out = i_bapicuprtm
order_cfgs_cuvals_out = i_bapicuvalm
order_cfgs_cublbs_out = i_bapicublbm
order_cfgs_cuvks_out = i_bapicuvkm
order_billingplans_out = i_bapisdbpl
order_billingdates_out = i_bapisdbpld
order_creditcards_out = i_bapiccardm
extensionout = i_bapiparex.
ENDFORM. " sub_get_o_ret_order_dtls
&----
*& Form sub_make_order_items
&----
This subroutine is used to prepare the line items
----
--> P_RET_ORDER Return disposition work area
----
FORM sub_make_order_items USING p_ret_order TYPE zslo_ret_dispo.
DATA : l_wa_posnr LIKE LINE OF i_posnr.
Delete the line item where the material are not matching
DELETE i_bapisdit WHERE material NE p_ret_order-zzmat_no.
Populating the position nos in a range table
l_wa_posnr-sign = 'I'.
l_wa_posnr-option = 'EQ'.
LOOP AT i_bapisdit INTO wa_bapisdit.
l_wa_posnr-low = wa_bapisdit-itm_number.
APPEND l_wa_posnr TO i_posnr.
ENDLOOP.
Deleting the position nos from other Bapi internal tables
DELETE i_bapisdhedu WHERE itm_number NOT IN i_posnr.
DELETE i_bapisditst WHERE itm_number NOT IN i_posnr.
DELETE i_bapisdcond WHERE itm_number NOT IN i_posnr.
ENDFORM. " sub_make_order_items
&----
*& Form sub_create_order_bapi
&----
This subroutine is used to create subsequent return order using BAPI
----
*--> P_RET_ORDER Return disposition work area
----
FORM sub_create_order_bapi TABLES p_posqty TYPE zslo_posnr_qty_t
CHANGING p_ret_order TYPE zslo_ret_dispo.
DATA : l_quantity TYPE i, " Quantity to be apportioned
l_wa_posqty TYPE zslo_posnr_qty. " Line item wise quantity
l_quantity = p_ret_order-zzqty_entered.
READ TABLE i_bapisdhd INTO wa_bapisdhd INDEX 1.
MOVE-CORRESPONDING wa_bapisdhd TO wa_bapisdhead.
wa_bapisdhead-doc_type = p_ret_order-zzsub_ord_typ.
wa_bapisdhead-ref_doc = p_ret_order-zzret_ord.
wa_bapisdhead-ref_doc_ca = c_h.
CLEAR wa_bapisdhead-doc_number.
LOOP AT i_bapisdit INTO wa_bapisdit.
MOVE-CORRESPONDING wa_bapisdit TO wa_bapiitemin.
wa_bapiitemin-ref_doc = p_ret_order-zzret_ord.
wa_bapiitemin-ref_doc_it = wa_bapiitemin-itm_number.
wa_bapiitemin-ref_doc_ca = c_h.
wa_bapiitemin-part_dlv = 'D'.
wa_bapiitemin-item_categ = p_ret_order-zzsub_ord_itmcat.
READ TABLE i_o_ret_ord INTO wa_o_ret_ord WITH KEY
posnr = wa_bapiitemin-itm_number.
IF sy-subrc = 0.
IF wa_o_ret_ord-openflg = c_check.
IF wa_o_ret_ord-openqty GE l_quantity.
IF v_posnr_mod IS INITIAL.
wa_bapiitemin-itm_number = '000010'.
p_ret_order-zzsub_ord_item = wa_bapiitemin-itm_number.
v_posnr_mod = wa_bapiitemin-itm_number.
ELSE.
wa_bapiitemin-itm_number = v_posnr_mod + 10.
p_ret_order-zzsub_ord_item_t = wa_bapiitemin-itm_number.
v_posnr_mod = wa_bapiitemin-itm_number.
ENDIF.
wa_bapiitemin-req_qty = l_quantity * 1000.
l_wa_posqty-posnr = v_posnr_mod.
l_wa_posqty-qty = l_quantity.
l_wa_posqty-qty_mod = l_quantity.
APPEND l_wa_posqty TO p_posqty.
APPEND wa_bapiitemin TO i_bapiitemin.
EXIT.
ELSE.
IF v_posnr_mod IS INITIAL.
wa_bapiitemin-itm_number = '000010'.
p_ret_order-zzsub_ord_item = wa_bapiitemin-itm_number.
v_posnr_mod = wa_bapiitemin-itm_number.
ELSE.
wa_bapiitemin-itm_number = v_posnr_mod + 10.
p_ret_order-zzsub_ord_item_t = wa_bapiitemin-itm_number.
v_posnr_mod = wa_bapiitemin-itm_number.
ENDIF.
wa_bapiitemin-req_qty = wa_o_ret_ord-openqty * 1000.
l_wa_posqty-posnr = v_posnr_mod.
l_wa_posqty-qty = wa_o_ret_ord-openqty.
l_wa_posqty-qty_mod = wa_o_ret_ord-openqty.
APPEND l_wa_posqty TO p_posqty.
l_quantity = l_quantity - wa_o_ret_ord-openqty.
ENDIF.
ENDIF.
APPEND wa_bapiitemin TO i_bapiitemin.
ENDIF.
ENDLOOP.
v_posnr_mod = '000010'.
LOOP AT i_bapisdpart INTO wa_bapisdpart.
MOVE-CORRESPONDING wa_bapisdpart TO wa_bapipartnr.
wa_bapipartnr-partn_numb = wa_bapisdpart-customer.
APPEND wa_bapipartnr TO i_bapipartnr.
ENDLOOP.
CALL FUNCTION 'BAPI_SALESORDER_CREATEFROMDATA'
EXPORTING
order_header_in = wa_bapisdhead
IMPORTING
salesdocument = v_order_no
return = wa_return2
TABLES
order_items_in = i_bapiitemin
order_partners = i_bapipartnr.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = c_check.
endform.
‎2008 Jun 24 9:06 AM
BAPI_SALESORDER_CREATEFROMDAT2 is not possible....
use...BAPISDORDER_GETDETAILEDLIST
then BAPI_SALESORDER_CREATEFROMDATA
example code...
ORM sub_create_ret_order TABLES p_posqty TYPE zslo_posnr_qty_t
CHANGING p_ret_order TYPE zslo_ret_dispo.
Sales order creation using reference is not possible in BAPI, So
getting details of original return order using this subroutine
PERFORM sub_get_o_ret_order_dtls USING p_ret_order-zzret_ord.
Subroutine for preparing the reture order line items for subsequent
return order
PERFORM sub_make_order_items USING p_ret_order.
Subroutine for creating the subsequent return order using BAPI
PERFORM sub_create_order_bapi TABLES p_posqty
CHANGING p_ret_order.
ENDFORM. " sub_create_ret_order
&----
*& Form sub_get_o_ret_order_dtls
&----
This subroutine is used to get the details of original ret order
----
--> P_VBELN Sales order no
----
FORM sub_get_o_ret_order_dtls USING p_vbeln TYPE vbeln_va.
wa_order_view = c_str.
wa_sales_key-vbeln = p_vbeln.
APPEND wa_sales_key TO i_sales_key.
CALL FUNCTION 'BAPISDORDER_GETDETAILEDLIST'
EXPORTING
i_bapi_view = wa_order_view
TABLES
sales_documents = i_sales_key
order_headers_out = i_bapisdhd
order_items_out = i_bapisdit
order_schedules_out = i_bapisdhedu
order_business_out = i_bapisdbusi
order_partners_out = i_bapisdpart
order_address_out = i_bapisdcoad
order_statusheaders_out = i_bapisdhdst
order_statusitems_out = i_bapisditst
order_conditions_out = i_bapisdcond
order_cond_head = i_bapicondhd
order_cond_item = i_bapicondit
order_cond_qty_scale = i_bapicondqs
order_cond_val_scale = i_bapicondvs
order_contracts_out = i_bapisdcntr
order_textheaders_out = i_bapisdtehd
order_textlines_out = i_bapitextli
order_flows_out = i_bapisdflow
order_cfgs_curefs_out = i_bapicurefm
order_cfgs_cucfgs_out = i_bapicucfgm
order_cfgs_cuins_out = i_bapicuinsm
order_cfgs_cuprts_out = i_bapicuprtm
order_cfgs_cuvals_out = i_bapicuvalm
order_cfgs_cublbs_out = i_bapicublbm
order_cfgs_cuvks_out = i_bapicuvkm
order_billingplans_out = i_bapisdbpl
order_billingdates_out = i_bapisdbpld
order_creditcards_out = i_bapiccardm
extensionout = i_bapiparex.
ENDFORM. " sub_get_o_ret_order_dtls
&----
*& Form sub_make_order_items
&----
This subroutine is used to prepare the line items
----
--> P_RET_ORDER Return disposition work area
----
FORM sub_make_order_items USING p_ret_order TYPE zslo_ret_dispo.
DATA : l_wa_posnr LIKE LINE OF i_posnr.
Delete the line item where the material are not matching
DELETE i_bapisdit WHERE material NE p_ret_order-zzmat_no.
Populating the position nos in a range table
l_wa_posnr-sign = 'I'.
l_wa_posnr-option = 'EQ'.
LOOP AT i_bapisdit INTO wa_bapisdit.
l_wa_posnr-low = wa_bapisdit-itm_number.
APPEND l_wa_posnr TO i_posnr.
ENDLOOP.
Deleting the position nos from other Bapi internal tables
DELETE i_bapisdhedu WHERE itm_number NOT IN i_posnr.
DELETE i_bapisditst WHERE itm_number NOT IN i_posnr.
DELETE i_bapisdcond WHERE itm_number NOT IN i_posnr.
ENDFORM. " sub_make_order_items
&----
*& Form sub_create_order_bapi
&----
This subroutine is used to create subsequent return order using BAPI
----
*--> P_RET_ORDER Return disposition work area
----
FORM sub_create_order_bapi TABLES p_posqty TYPE zslo_posnr_qty_t
CHANGING p_ret_order TYPE zslo_ret_dispo.
DATA : l_quantity TYPE i, " Quantity to be apportioned
l_wa_posqty TYPE zslo_posnr_qty. " Line item wise quantity
l_quantity = p_ret_order-zzqty_entered.
READ TABLE i_bapisdhd INTO wa_bapisdhd INDEX 1.
MOVE-CORRESPONDING wa_bapisdhd TO wa_bapisdhead.
wa_bapisdhead-doc_type = p_ret_order-zzsub_ord_typ.
wa_bapisdhead-ref_doc = p_ret_order-zzret_ord.
wa_bapisdhead-ref_doc_ca = c_h.
CLEAR wa_bapisdhead-doc_number.
LOOP AT i_bapisdit INTO wa_bapisdit.
MOVE-CORRESPONDING wa_bapisdit TO wa_bapiitemin.
wa_bapiitemin-ref_doc = p_ret_order-zzret_ord.
wa_bapiitemin-ref_doc_it = wa_bapiitemin-itm_number.
wa_bapiitemin-ref_doc_ca = c_h.
wa_bapiitemin-part_dlv = 'D'.
wa_bapiitemin-item_categ = p_ret_order-zzsub_ord_itmcat.
READ TABLE i_o_ret_ord INTO wa_o_ret_ord WITH KEY
posnr = wa_bapiitemin-itm_number.
IF sy-subrc = 0.
IF wa_o_ret_ord-openflg = c_check.
IF wa_o_ret_ord-openqty GE l_quantity.
IF v_posnr_mod IS INITIAL.
wa_bapiitemin-itm_number = '000010'.
p_ret_order-zzsub_ord_item = wa_bapiitemin-itm_number.
v_posnr_mod = wa_bapiitemin-itm_number.
ELSE.
wa_bapiitemin-itm_number = v_posnr_mod + 10.
p_ret_order-zzsub_ord_item_t = wa_bapiitemin-itm_number.
v_posnr_mod = wa_bapiitemin-itm_number.
ENDIF.
wa_bapiitemin-req_qty = l_quantity * 1000.
l_wa_posqty-posnr = v_posnr_mod.
l_wa_posqty-qty = l_quantity.
l_wa_posqty-qty_mod = l_quantity.
APPEND l_wa_posqty TO p_posqty.
APPEND wa_bapiitemin TO i_bapiitemin.
EXIT.
ELSE.
IF v_posnr_mod IS INITIAL.
wa_bapiitemin-itm_number = '000010'.
p_ret_order-zzsub_ord_item = wa_bapiitemin-itm_number.
v_posnr_mod = wa_bapiitemin-itm_number.
ELSE.
wa_bapiitemin-itm_number = v_posnr_mod + 10.
p_ret_order-zzsub_ord_item_t = wa_bapiitemin-itm_number.
v_posnr_mod = wa_bapiitemin-itm_number.
ENDIF.
wa_bapiitemin-req_qty = wa_o_ret_ord-openqty * 1000.
l_wa_posqty-posnr = v_posnr_mod.
l_wa_posqty-qty = wa_o_ret_ord-openqty.
l_wa_posqty-qty_mod = wa_o_ret_ord-openqty.
APPEND l_wa_posqty TO p_posqty.
l_quantity = l_quantity - wa_o_ret_ord-openqty.
ENDIF.
ENDIF.
APPEND wa_bapiitemin TO i_bapiitemin.
ENDIF.
ENDLOOP.
v_posnr_mod = '000010'.
LOOP AT i_bapisdpart INTO wa_bapisdpart.
MOVE-CORRESPONDING wa_bapisdpart TO wa_bapipartnr.
wa_bapipartnr-partn_numb = wa_bapisdpart-customer.
APPEND wa_bapipartnr TO i_bapipartnr.
ENDLOOP.
CALL FUNCTION 'BAPI_SALESORDER_CREATEFROMDATA'
EXPORTING
order_header_in = wa_bapisdhead
IMPORTING
salesdocument = v_order_no
return = wa_return2
TABLES
order_items_in = i_bapiitemin
order_partners = i_bapipartnr.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = c_check.
endform.