on 10-30-2007 2:38 PM
Hi Friends,
I am trying to create a sales order with reference to an existing sales order but I am not getting the reference field populated.
I am using SD_SALESDOCUMENT_CREATE for this purpos and code as below
Header details
l_order_header_in-doc_type = vbak-auart.
l_order_header_in-sales_org = vbak-vkorg.
l_order_header_in-distr_chan = vbak-vtweg.
l_order_header_in-division = vbak-spart.
l_order_header_in-ref_doc_l = vbak-vbeln.
l_order_header_inx-doc_type = 'X'.
l_order_header_inx-sales_org = 'X'.
l_order_header_inx-distr_chan = 'X'.
l_order_header_inx-division = 'X'.
l_order_header_inx-ref_doc_l = 'X'.
l_order_header_inx-updateflag = 'I'.
CLEAR v_item_no.
v_item_no = '000010'.
Item details
LOOP AT i_unauth.
i_order_items_in-itm_number = v_item_no.
i_order_items_in-material = i_unauth-matnr.
i_order_items_in-target_qty = i_unauth-kwmeng.
i_order_items_inx-itm_number = i_order_items_in-itm_number.
i_order_items_inx-material = 'X'.
i_order_items_inx-target_qty = 'X'.
i_order_items_inx-updateflag = 'I'.
APPEND: i_order_items_in, i_order_items_inx.
CLEAR: i_order_items_in, i_order_items_inx.
schedule lines
i_sales_schedules_in-itm_number = v_item_no.
i_sales_schedules_in-sched_line = v_item_no+1(4).
i_sales_schedules_in-req_qty = i_unauth-kwmeng.
i_sales_schedules_inx-itm_number = i_sales_schedules_in-itm_number.
i_sales_schedules_inx-sched_line = i_sales_schedules_in-sched_line.
i_sales_schedules_inx-req_qty = 'X'.
i_sales_schedules_inx-updateflag = 'I'.
APPEND: i_sales_schedules_in, i_sales_schedules_inx.
CLEAR: i_sales_schedules_in, i_sales_schedules_inx.
v_item_no = v_item_no + 10.
ENDLOOP.
Partner details
i_order_partners-partn_role = 'AG'.
i_order_partners-partn_numb = vbak-kunnr.
APPEND i_order_partners. CLEAR i_order_partners.
SELECT SINGLE * FROM vbpa INTO vbpa
WHERE vbeln = vbak-vbeln AND
posnr = '000000' AND
parvw = 'WE '.
IF sy-subrc = 0.
i_order_partners-partn_role = vbpa-parvw.
i_order_partners-partn_numb = vbpa-kunnr.
APPEND i_order_partners. CLEAR i_order_partners.
ENDIF.
I tried to create it with using BAPI_SALESORDER_CREATEFROMDAT2 but was not sucessfull and has to try with the SD_SALESDOCUMENT_CREATE .
Could somebody please suggest me how to acheive this.
Thanks,
Kiran.
Will sort it out myself
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
There is an OSS note <a href="https://service.sap.com/sap/support/notes/370988">Note 370988 - BAPIs in SD: Creation with reference</a>
<i><b>Symptom</b>
This note describes the problems of the 'Create with reference' function when using BAPIs to create sales documents.
If you are working online, you can use this function module to create a sales document with reference to an existing sales document or a billing document (for example, a debit or credit memo request) according to fixed rules. The rules for transferring information from the source document to the target document are defined in the copying control on header and item level. The creation with reference permits an item selection.
When you use BAPIs in SD, a function of this type is not fully available. A reference is only possible for a quantity contract, so that the target quantity of the contract can be reduced by the order quantity of the sales document. Furthermore, the document flow is also updated.
As an alternative to 'Create with reference' in Transaction VA01, two variants are provided for solving the 'Create with reference' problem in the BAPI.
1. Create a '1:1 ' - that is, a document copy of a sales document (customer quotation, order) with 'BAPI_SALESDOCUMENT_COPY'. At this point, you cannot create the 1:1 copy of either a billing document or a delivery.
2. Create a sales document that refers to an existing document with 'BAPISDORDER_GETDETAILEDLIST' and 'BAPI_SALESORDER_CREATEFROMDAT2'.
<b>Other terms</b>
BAPI_SALESDOCUMENT_COPY, BAPI_SALESORDER_CHANGE, BAPI_CUSTOMERINQUIRY_CHANGE, BAPI_CUSTOMERQUOTATION_CHANGE, BAPI_SALESORDER_CREATEFROMDAT1, BAPI_SALESORDER_CREATEFROMDAT2, BAPI_SALESORDER_CREATEFROMDATA, BAPISDORDER_GETDETAILEDLIST
<b>Reason and Prerequisites</b>
As of yet, no method exists for creating a sales document that refers to an existing document.
Solution
For solution No. 1
1. Create the documents using the BAPI_SALESDOCUMENT_COPY function module. However, this only permits a 1:1 copy without factoring out individual items.
2. After you have created the document copy, you can use a change BAPI to edit this copy.
For solution No. 2
1. Collect the data for the reference document (for example a customer quotation) with the 'BAPISDORDER_GETDETAILEDLIST' function module. In the example code, focus exclusively on the partners, items, schedule lines and conditions.
2. Prepare the Data. Execute the 'copying control' manually. This way, you decide which values are to be transferred.
3. Create the sales document using the 'BAPI_SALESORDER_CREATEFROMDAT2' function module by transferring the prepared data.
4. Finally, you must remove a COMMIT WORK so that the sales document can be written into the database.
An example of solution 2 is attached as a text file. You are allowed to select items and quantities for example, if you use input parameters. If there are no entries, then transfer 1:1 from the reference document. When you enter the 'condition type' parameter, you can determine whether conditions are copied or recalculated ('G' for transferring from the preceding document; 'B' or ' ' for re-determining, and 'C' for re-determining with transfer of the manual elements).</i>
Sample : <a href="https://service.sap.com/~sapidb/012003146900000486112004E/BAPI_COPY_WITH_REF.txt">ZZ_MS_BAPI_COPY</a>
Regards
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
solution 1
As far as i undestand the note, you could try to BAPI_SALESDOCUMENT_COPY the order and then BAPI_SALESORDER_CHANGE the result wih your new values.
But i actually don't like their "<i>As of yet, no method exists for creating a sales document that refers to an existing document.</i>"
solution 2
In the sample , there is a field <b>refdoc_cat</b> near ref_doc.
Regards
User | Count |
---|---|
103 | |
12 | |
11 | |
6 | |
5 | |
4 | |
3 | |
3 | |
3 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.