Adding Sales Order Lines repeating for all orders

I have a C# program whereby I am trying to get Sales Orders from one database (source) and create them in another database (destination). I asked a question on how to set the current line and was helped.
The only problem now is that for all Business Partners, the lines being added are all the same (i.e. with the same row numbers and details as the first Sales Order to be entered)
Source database (TCount represents the number of lines in the document & the DocNum each separate sales order)
Destination database (compare columns with above)
As you can see the rows of Source docnum 6 are repeated in the destination table always
How can I fix it so that it adds the sales orders properly? My code snippet below:
unaddedSOs = sList.Except(dList).ToList();
            // Add the Sales Orders that are missing to destination database
            SAPbobsCOM.Documents sboSO = (SAPbobsCOM.Documents)oCompanyDestination.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oOrders);
            if (unaddedSOs.Count > 0)
                // Loop through unadded Sales Orders
                foreach (var item in unaddedSOs)
                    // Set properties of the Sales Order object
                    sboSO.CardCode = item.cardCode;
                    sboSO.CardName = item.cardName;
                    sboSO.DocDate = item.docDate;
                    sboSO.DocDueDate = item.docDueDate;
                    // Add Sales Order Document Lines
                    SAPbobsCOM.Recordset rsLines = oCompanySource.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset);
                    // Get Sales Orders from source database                   
                    rsLines.DoQuery("SELECT ItemCode, Quantity, Price FROM RDR1 WHERE DocEntry = '" + item.docNum + "'");
                    rsLines.MoveFirst();
                    if (rsLines.RecordCount > 0)
                        int row = 0;
                        while (!rsLines.EoF)
                            sboSO.Lines.SetCurrentLine(row);
                            sboSO.Lines.ItemCode = rsLines.Fields.Item("ItemCode").Value;
                            sboSO.Lines.Quantity = rsLines.Fields.Item("Quantity").Value;
                            sboSO.Lines.Price = rsLines.Fields.Item("Price").Value;
                            sboSO.Lines.Add();
                            rsLines.MoveNext();
                            row++;
                    // Try to add the Sales Order to the database        
                    int lRetCode = sboSO.Add();
                    if (lRetCode != 0)
                        int temp_int = lErrorCode;
                        string temp_string = sErrorMsg;
                        oCompanyDestination.GetLastError(out temp_int, out temp_string);
                        // Incase adding a Sales Order failed
                        if (lErrorCode != -4006)
                            // Display error message
                            MessageBox.Show(lErrorCode + " " + sErrorMsg);
            MessageBox.Show("Syncing Complete!!!");
Any help appreciated,
Regards Kinyanjui

Hi Kinyanjui,
Are you using the same SO for all unadded orders?
unaddedSOs = sList.Except(dList).ToList();
// Add the Sales Orders that are missing to destination database
if (unaddedSOs.Count > 0)
    // Loop through unadded Sales Orders
    foreach (var item in unaddedSOs)
        SAPbobsCOM.Documents sboSO = (SAPbobsCOM.Documents)oCompanyDestination.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oOrders);
        // Set properties of the Sales Order object
        sboSO.CardCode = item.cardCode;
        sboSO.CardName = item.cardName;
        sboSO.DocDate = item.docDate;
        sboSO.DocDueDate = item.docDueDate;
        // Add Sales Order Document Lines
        SAPbobsCOM.Recordset rsLines = oCompanySource.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset);
        // Get Sales Orders from source database               
        rsLines.DoQuery("SELECT ItemCode, Quantity, Price FROM RDR1 WHERE DocEntry = '" + item.docNum + "'");
        rsLines.MoveFirst();
        if (rsLines.RecordCount > 0)
            int row = 0;
            while (!rsLines.EoF)
                sboSO.Lines.SetCurrentLine(row);
                sboSO.Lines.ItemCode = rsLines.Fields.Item("ItemCode").Value;
                sboSO.Lines.Quantity = rsLines.Fields.Item("Quantity").Value;
                sboSO.Lines.Price = rsLines.Fields.Item("Price").Value;
                sboSO.Lines.Add();
                rsLines.MoveNext();
                row++;
        // Try to add the Sales Order to the database     
        int lRetCode = sboSO.Add();
        if (lRetCode != 0)
            int temp_int = lErrorCode;
            string temp_string = sErrorMsg;
            oCompanyDestination.GetLastError(out temp_int, out temp_string);
            // Incase adding a Sales Order failed
            if (lErrorCode != -4006)
                // Display error message
                MessageBox.Show(lErrorCode + " " + sErrorMsg);
        Marshal.ReleaseComObject(sboSO);
        GC.Collect();
MessageBox.Show("Syncing Complete!!!");
Best regards,
Pedro Magueija

Similar Messages

  • Sale Order MRP Run for All Order Line Items

    Greetings...
                     I have One Sales Order , in which i have ten different Line Items .
    Now I have to Run the MRP on basis of Created sales Order so that all Line items wi get consider insingle MRP Run on sales order base MRP Run.
    How to take MRP Run of One Sale Order for all Line Items.???
    In MD50 , we can have sales Order with Item..

    In MD50 you can give only one item at a time.
    Its a standard transaction meant to accomodate changes relevant for MRP after plant level MRP run  related to specific sales order Item.
    so either you need to do it multipal times by changing material or you need to go for MD02.
    Please explain bussiness case in detail why you want to restrict your MRP run for items in a specific sales order.
    Regards

  • How can I add a new line item for production order?

    HI all,
    How can I add a new line item for production order through BAPI/FM? Thanks in advance.

    Hi Mil,
      Unfortunetly SAP is not in front of me.
    But if possible go to BAPI transaction , check for any production order's bapi for CHANGE purpose. Where you will be able to add your new line.
    Reward if useful!

  • Creation of suspension line items for Subscription orders

    hi ,
           I am currently working on IS-Media project.
    I have a requirement that I need to create a suspension for all the line items available for the subscription orders.
    I mean I have to create a new line item for all the active line items of a subscription order.
    I have seen the FM : ISM_SALES_ORDER_CHANGE.
    it is working for only single active line item.
    Could you please suggest any of the Function moulesavailable in the SAP : IS-Media?
    Thanks in advance.
    Vijay.

    Vijay,
    The best FMs that would meet your needs are below. They are listed in the order that will best address what you are trying to accomplish. They are ISM_SALES_ITEM_UNLIMIT_CHANGE, ISM_SALES_ITEM_SUSPEND and ISM_SALES_SCHEDULE_CHANGE.
    I hope this helps.
    Sibu

  • KKBC_ORD for all orders in a plant

    Hi,
    Is there any report in CO-PC which would give me the information I can get in KKBC_ORD but for all orders in the plant at one run?
    My problem is that, I require to see the actual, target and plan activity quantities for particular production cost centers by month. I have found such information only in KKBC_ORD, but it can only be run for one order at a time. I wonder if there is any similar report, which can be run for whole plant or is there an easy way to create such report in ABAP as a copy of KKBC_ORD.
    Thank you for help,
    Karol

    Hi Karol,
    Have tried to run report "S_ALR_87013127 - Order Selection "
    Using this report you can see the plan and actual of orders in one plant.
    Please try, hope this would help you
    Irhasni

  • MPS run, planned orders were created for all levels ?

    Hello PP members
    I ran a small scenario
    material    MRP Type     Low Level    SG           M/T Type
    A      M0         000             40              FERT
    B               PD              001              40             HALB
    c               PD              002               10             ROH
    Maintained PIRs(MD61) for material A, and ran MD41( Single Item Multi level Planning)
    As material A is an MPS item, I was expecting that it should create planned orders only for material A, but in this MPS run it created planned orders for material B & C. (Looked into MD04, where I see planned orders were created
    for all the levels)
    As per the MPS run, it will plan only for one level of BOM (in this scenario for material A)
    Any suggestions, why planned orders were created for material B & C
    please clarify

    Just check
    System must have created a dependent requirement planned order and not the planned order for requirement you put in demand management for B and C
    i.e. if you enter a demand in MD61 for B and C, run the transaction, system will not consider this requirement during MPS run. MPS run will consider the requirement if the requirement for the child is comming from parement where parent is MPS item.
    Hence you need to run MRPm for B amd C if teh requirement(not dependdent requirement from A) is to be considered.
    I hope you are clear
    Edited by: Rajesha Vittal on Jan 28, 2008 8:06 AM

  • Missing Parts for all Orders

    Is there a single report which gives missing parts list for all orders with due allocation of components as per the order dates?

    Dear,
    Missing parts information we can see in CO24 tcode.
    In COHV or COMAC.
    in mass processing gtab page
    select function = material availability check, execute it.
    In selection tab page
    Plant
    Order type
    System status - MSPT.
    Or,
    COOIS : Production Order Information System
    Under this transaction you need to Select in List option as Components and then go on Selection Tab
    Regards,
    R.Brahmankar

  • Develop Order Search BAPI for web order

    hi all,
    Develop Order Search BAPI for web order.
    Z_IORDER_ORDER_SEARCH this is the function module i have to use.
    how can i do this as i am new to BAPI.
    thanks in advance.
    shravan

    have you tried this ...BAPI_ALM_ORDER_MAINTAIN

  • GR for Purchase order and GI for prod. order simultaneously

    Hi Guys,
    My client current has an external system, which does both GR for puchase order and GI for Prod. order at the same time. He is now migrating into SAP and he wants the same functionality. Do you have any idea how to do this.
    For eg., Pick list(CO27) will pick and issue the components to production order, if the component is in inventory. if it is not there, it will give error.
    Can we add, if material is not there, it should do GR and GI. is it possible with any customer exit in CO27?
    Thanks
    Srini

    Hi,
    In KANBAN, we have the possibility to do the GR (Goods Invard) if th container is Full and GI (to the production Order) if the Container is Empty.
    It's just a thaught..
    Regards,
    Siva

  • Stop user creating process order with material for specific order type

    Hey Team,
    Is there a way where I can stop creating process order with material for specific order type says Z*. We are using ZNMA  order type to create trial batch and we do not want to create process order with material for this order type.
    Any ideas?
    Thanks
    Bhavesh Patel.

    You can restrict the order creation in CO01 based on authorization, Remove the authorization for Z order type for the particular user,  Check with your basis Guy

  • Unit Cost is not Populating in Sales Order Line Level for OPM Enabled Org

    Dear All,
    This is to inform you that Unit Cost is not populating in Sales Order Lines. Ideally it should pick from OPM financials, but whenever i am running Cost Update it is throwing error. We need to pull out Unit Cost for Sales Analysis Report. Please suggest on the same ASAP. What are the steps needs be followed to populate the Unit Cost. Please suggest.
    Thanks & Regards,
    Patrick

    Hi
    I think it will pick from PRICE list. Why don't to you try by keeping this item in the mentioned Price list.
    Regards
    Raj

  • Reg WBS Element in Sales Order Line Item For Sales Order BOM

    Hi ,
    Greetings!!!!
    I have a requirement, in a Sales Order I am Exploding BOM. After that Projects will be Created.
    Once Project will be created i need to Assign WBS element for All Items in Sales Order.
    My requirement is When I assign WBS element for Header Material (Parent Item) system will auto assign WBS for Child Items.
    for this what Configuration I have to do.
    Please do need full.
    Thanks,
    Regards,
    Prasad.

    Hi Dayananda
    Check in transaction VTFL for given item category what copying routine are set. Check those copy routine and see if there is any data is being copied from table VBAP
    Similar to above also check transaction VTFA for copying routine (if any)
    As a standard SAP even we create an invoice with reference to the delivery document, still there are some data which is being copied from a sales order i.e. all pricing relevant information is copied from your sales order and not from delivery.

  • How to Close a Purchase Order line Item for GRN W/O Deleting the Line Item

    Hi,
    I want to Close a line item for Goods Receipt in a Purchase Order. How Do I do this?
    My Requirement is that the system should not allow for Goods Receipt for the Line Item.
    I know of 2 options which are difficult to Implement.
    1) I delete the Line item
    2) Put the delivery Completed Indicator - For this the system still allows for GR
    any Other way of Closing the line Item
    NS

    Hi, you can close the Line item by, doing partial GRPO, i.e if u use the Copy From option in GRPO, there comes a Draw docuemnt wizard, there you can choose one line item, and then put GRPO for that line item,
    The Wizard comes only in the Copy From option,
    Close the Line item, by right clicking on that Line item and then 'close Row'
    Edited by: Gayathri Panneerselvam on Dec 19, 2008 10:25 AM

  • Display report : plan line items for internal orders

    When running the report with KOBP tcode, although i have some plan cost line items in the order, i have the message :
    No plan line items were selected
    Message no. KB421
    Could anyone advise?
    However, the report with KOB1 tcode works well and i have the results as expected for actual line items.

    this is may be config issue.
    can you explain with accounting entries for said line items and offsetting GL for each line?
    regards.
    ashok

  • KKAO is showing ZERO value for all orders

    Hello All Experts,
    I am running a WIP report for Production Order via KKAO. I am getting "ZERO" values for all the orders available in system. All my orders are "Release (REL) and in "Partial Delivered (PDLV) status still I am getting ZERO values.
    Please find below screen shot for reference :
    Can experts guide on this why I am getting ZERO values here ? Guidance will be very helpful.
    Thank you.
    Regards,
    Sharu.

    Hello Rajnessh Sir,
    Please find below screen shot :
    OKG9 -
    OKG3 -
    I am really not sure what to check here, I am new to WIP area. Experts please guide. Is above said settings correct ?
    Regards,
    Sharu.

Maybe you are looking for