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.
  • 到期日我试图将其更改为 is 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

0

来自评论中链接的 SAP 线程。

埃迪西蒙 说:

嗨,拉尔斯,

必须是补丁级别的错误。

我可以使用您的代码在 SBO 881PL6 上对其进行更新。

您可能想在另一个版本上对其进行测试。

问候

伊迪

这解决了这个问题。

于 2021-02-24T07:31:34.127 回答