05-21-2012 6:54 AM
Hi,
We have a requirement to CREATE an SO with billing plan, through an RFC. The header details of the SO and the Billing Plan table are provided as inputs.
We have used BAPI_SALESORDER_CREATEFROMDAT2 to create the SO, but we are not being able to create the Billing Plan thorugh the BAPI.
Actually prior to creating the SO we create a WBS Element with the same Milestone details. Our purpose will be served if we can copy the milestone details from the WBS Element throug code.
Any inputs in this regard will be highly appreciated.
Thanks in advance,
Sattam
05-21-2012 7:37 AM
After create sales order use(BAPI_SALESORDER_CREATEFROMDAT2) following FM :
BILLING_SCHEDULE_READ
BILLING_SCHEDULE_SAVE
SD_SALES_DOCUMENT_SAVE
BAPI_TRANSACTION_COMMIT
See the following Example:
i_bapi_view-header = 'X'.
i_bapi_view-item = 'X'.
i_bapi_view-partner = 'X'.
i_bapi_view-contract = 'X'.
i_bapi_view-sdcond = 'X'.
i_bapi_view-sdcond_add = 'X'.
i_bapi_view-billplan = 'X'.
i_bapi_view-configure = 'X'.
sales_documents-vbeln = v_order.
APPEND sales_documents.
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
order_contracts_out = order_contracts_out
order_billingplans_out = order_billingplans_out
order_billingdates_out = order_billingdates_out
order_partners_out = order_partners_out
order_conditions_out = order_conditions_out.
LOOP AT order_billingplans_out WHERE itm_number = '000000'.
hfplnr = order_billingplans_out-bill_plan.
ENDLOOP.
LOOP AT tab WHERE kbetr IS NOT INITIAL.
LOOP AT order_conditions_out WHERE itm_number = tab-itm_number
AND cond_type = 'ZRE'.
MOVE-CORRESPONDING order_conditions_out TO cond_ch.
IF order_conditions_out-cond_type = 'ZRE'.
cond_ch-cond_value = tab-kbetr.
APPEND cond_ch.
ENDIF.
ENDLOOP.
ENDLOOP.
* Read the billing plan
CALL FUNCTION 'BILLING_SCHEDULE_READ'
EXPORTING
fplnr = hfplnr
TABLES
zfpla = hfpla
zfplt = hfplt.
MOVE hfpla TO hfpla2.
*READ TABLE zfpla2 INDEX 1.
hfpla2-lodat = p_stat.
hfpla2-tndat = p_end.
hfpla2-rfpln = ''.
hfpla2-lodar = ''.
hfpla2-tndar = ''.
hfpla2-fpart = p_bplan.
hfpla2-perio = p_bplan.
hfpla2-horiz = p_hori.
*** Very important to set field updkz = 'U' ***
hfpla2-updkz = 'U'. "--> UPDATE!!
APPEND hfpla2.
CLEAR pos.
CALL FUNCTION 'BILLING_SCHEDULE_SAVE'
TABLES
fpla_new = hfpla2
fpla_old = hfpla
fplt_new = hfplt " --> NEW
fplt_old = hfplt.
CALL FUNCTION 'SD_SALES_DOCUMENT_SAVE'
EXPORTING
i_no_messages = ' '.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = 'X'.
*&---------------------------------------------------------------------*
*& END OF UPDATE Billing Plan Header level
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*& UPDATE Billing Plan Item level
*&---------------------------------------------------------------------*
LOOP AT zbill.
MOVE v_order TO doc .
CALL FUNCTION 'SD_SALES_DOCUMENT_READ'
EXPORTING
document_number = doc.
MOVE zbill-itm_number TO pos.
CALL FUNCTION 'SD_SALES_BILLINGPLAN_READ'
EXPORTING
i_vbeln = doc
i_posnr = pos
IMPORTING
e_fpla = e_fpla
TABLES
e_fplt = e_fplt
EXCEPTIONS
no_billingplan_allowed = 1
no_billingplan_found = 2
OTHERS = 3.
IF sy-subrc NE 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
* Read the billing plan
CALL FUNCTION 'BILLING_SCHEDULE_READ'
EXPORTING
fplnr = e_fpla-fplnr
* I_VFKDAT =
* I_BFKDAT =
TABLES
zfpla = zfpla
zfplt = zfplt.
MOVE zfpla TO zfpla2.
*READ TABLE zfpla2 INDEX 1.
zfpla2-lodat = zbill-datesfrom.
zfpla2-tndat = zbill-datesto.
zfpla2-rfpln = ''.
zfpla2-lodar = ''.
zfpla2-tndar = ''.
zfpla2-fpart = p_bplan.
zfpla2-horiz = p_hori.
*** Very important to set field updkz = 'U' ***
zfpla2-updkz = 'U'. "--> UPDATE!!
APPEND zfpla2.
ENDLOOP.
CLEAR pos.
CALL FUNCTION 'BILLING_SCHEDULE_SAVE'
TABLES
fpla_new = zfpla2
fpla_old = zfpla
fplt_new = zfplt " --> NEW
fplt_old = zfplt.
CALL FUNCTION 'SD_SALES_DOCUMENT_SAVE'
EXPORTING
i_no_messages = ' '.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = 'X'.
*-
*&---------------------------------------------------------------------*
*& UPDATE CONDITION VALUE [SD_SALESDOCUMENT_CHANGE]
*&---------------------------------------------------------------------*
LOOP AT cond_ch.
ls_order_header_x-updateflag = 'U'.
ls_cond-itm_number = cond_ch-itm_number.
ls_cond-cond_type = cond_ch-cond_type.
ls_cond-cond_value = cond_ch-cond_value.
ls_cond-currency = 'INR'.
ls_cond_x-itm_number = cond_ch-itm_number.
ls_cond_x-cond_type = cond_ch-cond_type.
ls_cond_x-cond_value = 'X'.
ls_cond_x-currency = 'X'.
APPEND ls_cond TO lt_cond.
APPEND ls_cond_x TO lt_cond_x.
ENDLOOP.
logic_switch-cond_handl = 'X'.
ls_cond_x-updateflag = 'U'.
CALL FUNCTION 'SD_SALESDOCUMENT_CHANGE'
EXPORTING
salesdocument = v_order
order_header_inx = ls_order_header_x
logic_switch = logic_switch
TABLES
return = lt_return
conditions_in = lt_cond
conditions_inx = lt_cond_x.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = 'X'.
11-03-2015 12:29 PM
11-04-2015 3:13 AM