‎2008 Aug 07 11:11 AM
Hello.
I create a Sales Order with reference to a contract by using function module BAPI_SALESORDER_CREATEFROMDAT2.
Now I want to take over the Pricing Coditions from the contract independent the amount (target_qty).
I play a lot with the import parameter logic_switch from the function module. As well I fill the conditions tables for bapi different.
Maybe my coding could help you.
I want to know what i have to do for the takeover of the contract conditions.
FUNCTION z_block_hours.
*"----
""Local Interface:
*" IMPORTING
*" REFERENCE(I_WQMSM) LIKE WQMSM STRUCTURE WQMSM
*" REFERENCE(I_VIQMEL) LIKE VIQMEL STRUCTURE VIQMEL
*" EXPORTING
*" VALUE(E_SUBRC) LIKE SY-SUBRC
*" TABLES
*" E_PROTOCOL STRUCTURE RQEVP
*"----
DATA: lv_contract TYPE vbeln_va,
ls_order_view TYPE order_view,
ls_partner TYPE bapiparnr,
ls_header_bapi TYPE bapisdhd1,
ls_headerx_bapi TYPE bapisdhd1x,
ls_headerx_ch TYPE BAPISDH1x,
ls_item TYPE bapisditm,
ls_itemx TYPE bapisditmx,
ls_schedule_bapi TYPE bapischdl,
ls_schedulex_bapi TYPE bapischdlx,
ls_condition TYPE bapicond,
ls_condx_bapi TYPE bapicondx,
ls_logic TYPE bapisdls,
ls_header TYPE bapi2080_nothdre,
lt_sales_order TYPE STANDARD TABLE OF sales_key,
lt_header TYPE STANDARD TABLE OF bapisdhd,
lt_item TYPE STANDARD TABLE OF bapisdit,
lt_item_bapi TYPE STANDARD TABLE OF bapisditm,
lt_itemx_bapi TYPE STANDARD TABLE OF bapisditmx,
lt_partner TYPE STANDARD TABLE OF bapisdpart,
lt_condition TYPE STANDARD TABLE OF bapisdcond,
lt_cond_head TYPE STANDARD TABLE OF bapicondhd,
lt_cond_item TYPE STANDARD TABLE OF bapicondit,
lt_cond_bapi TYPE STANDARD TABLE OF bapicond,
lt_condx_bapi TYPE STANDARD TABLE OF bapicondx,
lt_partner_bapi TYPE STANDARD TABLE OF bapiparnr,
lt_schedule_bapi TYPE STANDARD TABLE OF bapischdl,
lt_schedulex_bapi TYPE STANDARD TABLE OF bapischdlx,
lt_return TYPE STANDARD TABLE OF bapiret2.
FIELD-SYMBOLS: <ls_partner> TYPE bapisdpart,
<ls_header> TYPE bapisdhd,
<ls_item> TYPE bapisdit,
<ls_cond> TYPE bapisdcond,
<ls_cond_bapi> TYPE bapicond.
CHECK: i_viqmel-qmart EQ gc_not_type
AND i_wqmsm-aeknz EQ gc_insert.
"get contract
SELECT SINGLE kdauf
FROM viaufkst
INTO lv_contract
WHERE aufnr EQ i_viqmel-aufnr.
IF lv_contract IS INITIAL.
MESSAGE s005(zanx_blockhour).
EXIT.
ENDIF.
CALL SCREEN 0100 STARTING AT 10 5.
APPEND lv_contract TO lt_sales_order.
"Select which information is need
ls_order_view-header = ls_order_view-item
= ls_order_view-partner
= ls_order_view-sdcond
= gc_true.
"Select information from contract
CALL FUNCTION 'BAPISDORDER_GETDETAILEDLIST'
EXPORTING
i_bapi_view = ls_order_view
TABLES
sales_documents = lt_sales_order
order_headers_out = lt_header
order_items_out = lt_item
order_partners_out = lt_partner
order_conditions_out = lt_condition
order_cond_head = lt_cond_head
order_cond_item = lt_cond_item.
"Partner
LOOP AT lt_partner
ASSIGNING <ls_partner>.
MOVE-CORRESPONDING <ls_partner> TO ls_partner.
ls_partner-partn_numb = <ls_partner>-customer.
IF ls_partner-partn_numb IS INITIAL.
ls_partner-partn_numb = <ls_partner>-contact.
ENDIF.
APPEND ls_partner TO lt_partner_bapi.
ENDLOOP.
"Header
READ TABLE lt_header
INDEX 1
ASSIGNING <ls_header>.
MOVE-CORRESPONDING <ls_header> TO ls_header_bapi.
ls_header_bapi-ref_doc = lv_contract.
ls_header_bapi-refdoctype = <ls_header>-sd_doc_cat.
ls_header_bapi-refdoc_cat = <ls_header>-sd_doc_cat.
ls_header_bapi-refobjtype = gc_objtype.
ls_header_bapi-refobjkey = gc_objkey.
ls_header_bapi-doc_type = gc_doctype.
ls_header_bapi-req_date_h = sy-datum.
ls_header_bapi-purch_no_c = <ls_header>-purch_no.
ls_header_bapi-notif_no = i_viqmel-qmnum.
ls_header_bapi-bill_block = gc_bill_block.
CLEAR ls_header_bapi-wbs_elem.
ls_headerx_bapi-doc_type = ls_headerx_bapi-sales_org
= ls_headerx_bapi-distr_chan
= ls_headerx_bapi-division
= ls_headerx_bapi-bill_date
= ls_headerx_bapi-req_date_h
= ls_headerx_bapi-price_date
= ls_headerx_bapi-ref_doc
= ls_headerx_bapi-refdoc_cat
= ls_headerx_bapi-sd_doc_cat
= ls_headerx_bapi-currency
= ls_headerx_bapi-bill_block
= gc_true.
"item
READ TABLE lt_item
ASSIGNING <ls_item>
INDEX 1.
ls_item-refobjtype = gc_objtype.
ls_item-refobjkey = gc_objkey.
ls_item-ref_doc = lv_contract.
ls_item-ref_doc_it = 1.
ls_item-ref_doc_ca = <ls_header>-sd_doc_cat.
ls_item-material = <ls_item>-material.
ls_item-reason_rej = gc_abgru.
"ls_schedule_bapi-req_qty = gv_quan.
ls_schedule_bapi-req_qty = <ls_item>-target_qty.
ls_item-itm_number = ls_itemx-itm_number
= ls_schedule_bapi-itm_number
= ls_schedulex_bapi-itm_number
= 1.
CLEAR: ls_item-item_categ,
ls_item-wbs_elem.
ls_itemx-target_qty = ls_itemx-material
= ls_itemx-short_text
= ls_itemx-sales_unit
= ls_itemx-refobjtype
= ls_itemx-refobjkey
= ls_itemx-ref_doc
= ls_itemx-ref_doc_it
= ls_itemx-ref_doc_ca
= ls_schedulex_bapi-req_qty
= ls_itemx-target_qu
= ls_itemx-reason_rej
= gc_true.
APPEND: ls_item TO lt_item_bapi,
ls_itemx TO lt_itemx_bapi,
ls_schedule_bapi TO lt_schedule_bapi,
ls_schedulex_bapi TO lt_schedulex_bapi.
LOOP AT lt_condition
ASSIGNING <ls_cond>.
ls_condition-itm_number = <ls_cond>-condit_no.
MOVE-CORRESPONDING <ls_cond> TO ls_condition.
+ AT FIRST.+*
+ ls_condition-calctypcon = gc_pricing.+*
+ ls_condition-cond_p_unt = <ls_item>-target_qty.+*
+ ENDAT.+*
*"ls_condition-condvalue = ls_condition-conbaseval * <ls_item>-target_qty.*
APPEND ls_condition TO lt_cond_bapi.
ENDLOOP.
DELETE lt_cond_bapi
WHERE condclass IS INITIAL
OR groupcond IS NOT INITIAL.
LOOP AT lt_cond_bapi
ASSIGNING <ls_cond_bapi>.
ls_condx_bapi-itm_number = <ls_cond_bapi>-itm_number.
ls_condx_bapi-cond_st_no = <ls_cond_bapi>-cond_st_no.
ls_condx_bapi-cond_type = <ls_cond_bapi>-cond_type.
ls_condx_bapi-updateflag = gc_update.
ls_condx_bapi-cond_value = ls_condx_bapi-currency
= gc_true.
APPEND ls_condx_bapi TO lt_condx_bapi.
ENDLOOP.
ls_logic-pricing = gc_pricing. | 'G'
CALL FUNCTION 'BAPI_SALESORDER_CREATEFROMDAT2'
EXPORTING
order_header_in = ls_header_bapi
order_header_inx = ls_headerx_bapi
logic_switch = ls_logic
IMPORTING
salesdocument = ls_header-sales_ord
TABLES
return = lt_return
order_items_in = lt_item_bapi
order_items_inx = lt_itemx_bapi
order_partners = lt_partner_bapi
order_schedules_in = lt_schedule_bapi
order_schedules_inx = lt_schedulex_bapi
order_conditions_in = lt_cond_bapi
order_conditions_inx = lt_condx_bapi.
READ TABLE lt_return
WITH KEY type = gc_error
TRANSPORTING NO FIELDS.
IF sy-subrc <> 0.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = gc_true.
ELSE.
CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
ENDIF.
ENDFUNCTION.
Thanks for help,
Andrea
News: Now I know that VBAP-VBELV is missing/isn't set. I search know for the suitable parameter for BAPI.
Any ideas?
Greetz.
Edited by: Andrea Salzwedel on Aug 7, 2008 8:38 PM
‎2009 Aug 26 11:26 AM
Hi all.
I forgot to apply the conditions. This and the setting of the correct pricing indicator in parameter LOGIC_SWITCH solved the problem.
Thanks a lot
Salzi