Skip to Content
author's profile photo Former Member
Former Member

Could not commit transaction when inserting new items

Hi all!

I'm trying to export item definitions to SAP B1 database. To do that I use the following approach:

int result = -1;

SAPbobsCOM.Items doc = (SAPbobsCOM.Items)cmp.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oItems);

/... here goes some code that checks whether the item already existst or not .../

doc.ItemCode = itemCode;

doc.ItemType = SAPbobsCOM.ItemTypeEnum.itItems;

doc.ItemsGroupCode = groupID;

doc.ItemName = itemName;

doc.VatLiable = SAPbobsCOM.BoYesNoEnum.tYES;

if (ItemIsNew)

{

result = doc.Add();

}

else

{

result = doc.Update();

}

ItemIsNew variable points whether the item is new (true) or already exists(false).

If the item is new the variable 'itemCode' is set to a value that ensures its uniqueness, if the item already exists the 'itemCode' variable points to the corresponding record.

Variable 'groupID' points to a valid item group and 'itemName' variable is just the name of the item.

This code works fine if the item already exists - goes through the Update method which returns 0. On the other hand the code fails to insert new items - when through the Add method - the result is 208 which says "Could not commit transaction".

I'm using PL 36. Do you have any ideas what's wrong with my code?

Thanks in advance for your reply

Add a comment
10|10000 characters needed characters exceeded

Related questions

5 Answers

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on Oct 25, 2007 at 11:42 AM

    Hi Yavor,

    I had a similar problem. I had some custom operations related to OITM table placed in sbo_sp_TransactionNotification, when I moved the code in the new stored procedure sbo_sp_PostTransactionNotice the problem was solved.

    May be this will solve your problem too.

    Regards,

    Svilen

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member Former Member

      Hi,

      I have still the problem.

      I create orders with DI API and have the error -1200 Could not commit transaction.

      Working with the StartTransaction of the company does not work since after I added the order, the companies InTransaction is true, but I cannot commit the transaction, the company.EndTransaction(SAPbobsCOM.BoWfTransOpt.wf_Commit) fails also saying the company is not in transaction.

      So I don't work with the company.StartTransaction, and I don't want to. I just do document.Add() like I did in PL earlier than PL36.

      I also do nothing in SBO_SP_TransactionNotification or in SBO_SP_PostTransactionNotice, so this wouldn't fix the problem either.

      What do I have to do?? Help will be very appreciated.

  • author's profile photo Former Member
    Former Member
    Posted on Oct 24, 2007 at 06:56 AM

    Hi Yavor,

    You can use Transaction Object.

    cmp.StartTransaction()

    -- Code --

    cmp.EndTransaction(SAPbobsCOM.BoWfTransOpt.wf_Commit)

    Hope it help for you. Give me reward points,

    Regards,

    G.Suresh

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member Former Member

      Hi, suresh!

      Did you try that code snippet? I really have no clue what might be wrong with my code and sadly it just won't do for me if it's a PL bug. If it's a PL bug then how does the SAP B1 application work, shouldn't it fail too? Unless there is another way to achieve that

      10x for the help though

  • author's profile photo Former Member
    Former Member
    Posted on Oct 24, 2007 at 08:44 AM

    Here is a sample method that demonstrates the problem.

    private string CreateNewItem(SAPbobsCOM.Company cmp)

    {

    if (null != cmp)

    {

    int result = 0;

    try

    {

    SAPbobsCOM.Items doc = (SAPbobsCOM.Items)cmp.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oItems);

    doc.ItemCode = "NEWItem_001";

    doc.ItemType = SAPbobsCOM.ItemTypeEnum.itItems;

    doc.ItemsGroupCode = 100; //at least on my test machine this corresponds to Items group

    doc.ItemName = "Name of new item to add";

    doc.VatLiable = SAPbobsCOM.BoYesNoEnum.tYES;

    //bool val = cmp.InTransaction; //at this point there is no transaction

    result = doc.Add(); // the result equals 208

    //val = cmp.InTransaction; //at this point the Company object reports being in transaction

    if (0 != result)

    {

    return cmp.GetLastErrorDescription();

    }

    }

    catch (Exception ex)

    {

    System.Diagnostics.Debug.WriteLine(ex.ToString());

    return ex.Message;

    }

    }

    return string.Empty;

    }

    When executed it returns a non-empty string that says "Could not commit transaction". The interesting thing is that before calling doc.Add() method the company reports not being in a transaction, but after the method that same company states it is in transaction. I don't get it really - I make no calls to cmp.StartTransaction() but when doc.Add() completes with error 208 it seems to have created a transaction which for some reason didn't commit successfully.

    Am I missing some data initialization - maybe the item requires some more properties to be set? That code worked on PL 26 and earlier PLs.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Oct 24, 2007 at 08:47 AM

    Hi Yavor,

    Why not try using the GetByKey method of the Items object? The following (vb6) code works fine for me on PL29:

    Dim oItm As SAPbobsCOM.Items

    Dim sItemC As String

    Dim lRet As Long

    sItemC = "TestItem"

    Set oItm = oCmp.GetBusinessObject(oItems)

    If oItm.GetByKey(sItemC) Then

    'Update item.

    oItm.itemType = SAPbobsCOM.ItemTypeEnum.itItems

    oItm.ItemsGroupCode = "135"

    oItm.ItemName = "item desc..."

    oItm.VatLiable = SAPbobsCOM.BoYesNoEnum.tYES

    lRet = oItm.Update

    Else

    'Add item.

    oItm.ItemCode = sItemC

    oItm.itemType = SAPbobsCOM.ItemTypeEnum.itItems

    oItm.ItemsGroupCode = "135"

    oItm.ItemName = "item desc..."

    oItm.VatLiable = SAPbobsCOM.BoYesNoEnum.tYES

    lRet = oItm.Add

    End If

    Regards,

    Andrew.

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member Former Member

      Hi, Andrew!

      I'll setup a fresh install of PL36 and test it there too (it may be due to the upgrade procedure, who knows) - to verify that abnormal behaviour. I could try and "patch" my code to perform Add and if it fails to try the Update, but it is a bad programming style - I'll be ashamed of such a code, lol.

      Regards

  • author's profile photo Former Member
    Former Member
    Posted on Oct 24, 2007 at 10:41 AM

    hi...

    use this code... like this..

    IRetCodeLine is a integer value... which gets the status code..

    if (IRetCodeLine == 0)

    {

    if (oCompany.InTransaction)

    oCompany.EndTransaction(SAPbobsCOM.BoWfTransOpt.wf_Commit);

    oSBOApplication.StatusBar.SetText("Opertaion Completed Successfully", BoMessageTime.bmt_Short, BoStatusBarMessageType.smt_Success);

    }

    else

    {

    if (oCompany.InTransaction)

    oCompany.EndTransaction(SAPbobsCOM.BoWfTransOpt.wf_RollBack);

    }

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member

      Hi, Deepak!

      The problem still remains cause the Add method keeps saying "Could not commit transaction", so the code i added would only rollback the transaction. I still don't understand why I have to commit/rollback a transaction i never called. If the Add method creates a transaction shouldn't it be its responsibility to close it i the appropriate way before it returns?

      Regards

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.