2

以下のコードを使用して、SAP B1 の製造オーダーの期日を変更/更新しようとしています。

public static void ChangeDueDateForProductionOrder(SAPB1Credentials credentials, int poAbsEntry, DateTime dueDate)
{
    DebugLogger.Log(credentials.CompanyDB, $"Changing due date for production order '{poAbsEntry}' to '{dueDate.ToString(C_DATE_FORMAT_NL)}'.");

    using (var sap = new SAPB1Connection(credentials))
    {
        ProductionOrders productionOrder = sap.Company.GetBusinessObject(BoObjectTypes.oProductionOrders);

        if(productionOrder.GetByKey(poAbsEntry))
        {
            productionOrder.DueDate = dueDate;

            if (productionOrder.Update() != 0)
            {
                var message = $"Error while changing due date for '{poAbsEntry}' to '{dueDate.ToString(C_DATE_FORMAT_NL)}', the following error is given '{sap.Company.GetLastErrorDescription()}'.";
                DebugLogger.Log(credentials.CompanyDB, message);
                throw new Exception(message);
            }
        }
        else
            throw new Exception($"PoId '{poAbsEntry}' does not exists.");
    }
}

ただし、次のエラーが発生します。

「145」の期日を「11-09-2016」に変更中にエラーが発生しました。「フィールドを更新できません (ODBC -1029)」というエラーが表示されます。

そして、SAPが与えるエラーは次のとおりです。

フィールドを更新できません (ODBC -1029)

追加情報:

  • ステータスが の新しい製造オーダーですPlanned
  • 作成日はTodayです。
  • 期日を に変更しようとしていToday + 5 daysます。
  • 製造オーダーの ID (AbsEntry) は です145
  • SAP ビジネスワン 9.1
  • はい、問題なく SAP B1 GUI で期日を変更できます。

短い、自己完結型、正しい (コンパイル可能)、例

以下のコードでは、まったく同じエラーが発生します。接続設定を に置き換えました??

using System;
using SAPbobsCOM; // Reference to SAP B1 DI SDK (32-bit)

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            var credentials = new SAPB1Credentials
            {
                Server = "??",
                CompanyDB = "??",
                Username = "??",
                Password = "??"
            };

            SAPbobsCOM.Company sap = new SAPbobsCOM.Company();
            sap.Server = credentials.Server;
            sap.DbServerType = credentials.ServerType;
            sap.CompanyDB = credentials.CompanyDB;
            sap.UserName = credentials.Username;
            sap.Password = credentials.Password;
            sap.language = credentials.Language;
            sap.UseTrusted = credentials.UseTrusted;

            var returnCode = sap.Connect();

            if (returnCode != 0)
            {
                var error = sap.GetLastErrorDescription();
                throw new Exception(error);
            }

            ProductionOrders productionOrder = sap.GetBusinessObject(BoObjectTypes.oProductionOrders);

            if (productionOrder.GetByKey(145))
            {
                productionOrder.DueDate = DateTime.Now.AddDays(5);

                if (productionOrder.Update() != 0)
                {
                    var error = sap.GetLastErrorDescription();
                    throw new Exception(error);
                }
            }
            else
                throw new Exception($"PoId does not exists.");
        }

        public class SAPB1Credentials
        {
            public string Server { get; set; }
            public string CompanyDB { get; set; }
            public string Username { get; set; }
            public string Password { get; set; }
            public BoSuppLangs Language { get; set; } = BoSuppLangs.ln_English;
            public BoDataServerTypes ServerType { get; set; } = BoDataServerTypes.dst_MSSQL2008;
            public bool UseTrusted { get; set; } = false;
        }
    }
}

何が足りないのですか? なぜこのエラーが発生するのですか?

4

1 に答える 1