Skip to Content

Insert Items using the default numbering

I am using SAP 9.2 with UI and DI API and C#. I need to insert Items one by one, but automatically at the background, without displaying any UI forms for the Items. I understand that I need to do this with the SDK. Something like this.:

public Item InsertItem(InsertItemParameters p)
    SAPbobsCOM.Items newItem = oCompany.GetBusinessObject(BoObjectTypes.oItems);

    var itemCode = "Get autoincrement here?";
    newItem.ItemCode = itemCode;
    newItem.ItemType = p.ItemType;
    newItem.ItemsGroupCode = p.ItmsGroupCod;
    if (p.ItemName != null)
        newItem.ItemName = p.ItemName;
    if (p.SWW != null)
        newItem.SWW = p.SWW;
    if (p.SuppCatNum != null)
        newItem.SupplierCatalogNo = p.SuppCatNum;
    if (p.BuyUnitMsr != null)
        newItem.PurchaseUnit = p.BuyUnitMsr;
    if (p.PurPackMsr != null)
        newItem.PurchasePackagingUnit = p.PurPackMsr;
    if (p.SalUnitMsr != null)
        newItem.SalesUnit = p.SalUnitMsr;
    int res = newItem.Add();
    if (res != 0)
        int errorCode = 0;
        string errorDesc = "";
        oCompany.GetLastError(out errorCode, out errorDesc);
        if (errorCode == -10 && errorDesc.Contains("already exists"))
            throw new InsertFailedException($"ItemCode Autoincrement Failed. ItemCode:{itemCode}");

        throw new InsertFailedException("Inserting Item failed (" + errorCode + "," + errorDesc + "). Based on " + newItem.ToString());

    // check if newItem.ItemCode is valid -> Insert and return?
    return null;

My problem is the ItemCode, how can I set it using the SDK so I keep the default numbering?

I tried finding a solution, but all I found was this.:

In theory, I should just run the query using the sdk, but I looked at the ONNM table and for the object type 4 (Item Master data), the stored value (AutoKey) was 28779, while the latest key used for the items currently is 38767.Also, what bothers me is, even If the numbers would match, I should run this query to the ONNM table and the Item insert inside a transaction.

Is there a way to request a new ItemCode from the SDK? Something like:

oCompany.GetNewNumber(int objectCode);


Okay, I found that the NNM1 table holds the correct Next Number. Do I just run an update to it myself or is there any SDK way?


Somehow I figured out how to get the current number, now I just need to increment it somehow.. Inside a transaction :(

  SeriesService seriesService = oCompany.GetCompanyService().GetBusinessService(ServiceTypes.SeriesService);
            DocumentTypeParams typeParams = seriesService.GetDataInterface(SeriesServiceDataInterfaces.ssdiDocumentTypeParams);
            typeParams.Document = "4";
            Series series = seriesService.GetDefaultSeries(typeParams);

            var itemCode = ""+series.NextNumber;
            newItem.ItemCode = itemCode;
Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

1 Answer

  • Best Answer
    Feb 27, 2018 at 01:41 AM

    Hi Szabolcs

    Why not:

    1. Create a document numbering series for Items and let SAP handles the numbering.

    2. Use the below code to add the item

        Private Sub createTestItem()
            Dim item As SAPbobsCOM.Items = comp.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oItems)
            item.Series = 129   'The item numbering series key that you will use
            item.ItemName = "Test"
            Dim err As Integer = item.Add
            If err <> 0 Then
                MessageBox.Show(String.Format("Item {0} created", comp.GetNewObjectKey))
            End If
        End Sub



    Add comment
    10|10000 characters needed characters exceeded