• .Net 调用SAP RFC


    1、引用包

    2、关键代码

    RfcConfigParameters rfcPar = new RfcConfigParameters();
    rfcPar.Add(RfcConfigParameters.Name, "DEV");
    rfcPar.Add(RfcConfigParameters.AppServerHost, "服务器地址");
    rfcPar.Add(RfcConfigParameters.SAPRouter, "路由地址");
    rfcPar.Add(RfcConfigParameters.Client, "401");
    rfcPar.Add(RfcConfigParameters.User, "用户名");
    rfcPar.Add(RfcConfigParameters.Password, "密码");
    //rfcPar.Add(RfcConfigParameters.SystemID="00");
    //rfcPar.Add(RfcConfigParameters.SystemNumber, "00");
    rfcPar.Add(RfcConfigParameters.Language, "ZH");
    rfcPar.Add(RfcConfigParameters.PoolSize, "5");
    rfcPar.Add(RfcConfigParameters.MaxPoolSize, "10");
    rfcPar.Add(RfcConfigParameters.IdleTimeout, "30");

    RfcDestination dest = RfcDestinationManager.GetDestination(rfcPar);
    RfcRepository rfcrep = dest.Repository;

    IRfcFunction myfun = null;

    // 1、查询
    myfun = rfcrep.CreateFunction("ZMMBI019_NEW");
    myfun.SetValue("I_EBELN", "4500045646");//SAP里面的传入参数
    myfun.Invoke(dest);
    IRfcTable searchTable = myfun.GetTable("T_ITEM");

    // 2、数据变更

    for (int i = 0; i < searchTable.RowCount; i++)
    {
    if (i == 0)
    {
    searchTable.CurrentRow["MENGE"].SetValue(0.001);//20.560改为10
    }
    }

    // 3、提交
    myfun = rfcrep.CreateFunction("ZMMBI020_NEW"); // 函数
    IRfcTable tableCommit = myfun.GetTable("T_ZMMBI020"); // 传入表
    IRfcStructure import = null;
    foreach (var item in searchTable)
    {
    // 封装传入表
    import = rfcrep.GetStructureMetadata("ZMMBI020_ITEM_NEW").CreateStructure();
    import.SetValue("EBELN", item.GetValue("EBELN"));
    import.SetValue("LIFNR", item.GetValue("LIFNR"));
    import.SetValue("NAME1", item.GetValue("NAME1"));
    import.SetValue("EBELP", item.GetValue("EBELP"));
    import.SetValue("BWART", item.GetValue("BWART"));
    import.SetValue("BEDAT", item.GetValue("BEDAT"));
    import.SetValue("TXZ01", item.GetValue("TXZ01"));
    import.SetValue("MEINS", item.GetValue("MEINS"));
    import.SetValue("ZMENGE", item.GetValue("MENGE"));
    import.SetValue("RETPO", item.GetValue("RETPO"));
    import.SetValue("CHARG", item.GetValue("CHARG"));
    import.SetValue("WERKS", item.GetValue("WERKS"));
    import.SetValue("LGORT", item.GetValue("LGORT"));
    import.SetValue("ELIKZ", item.GetValue("ELIKZ"));
    import.SetValue("LFBJA", item.GetValue("LFBJA"));
    import.SetValue("LFBNR", item.GetValue("LFBNR"));
    import.SetValue("LFPOS", item.GetValue("LFPOS"));

    tableCommit.Append(import);
    break;
    }
    myfun.SetValue("T_ZMMBI020", tableCommit);
    myfun.Invoke(dest);

    string strMsg = "";
    string strReturn = myfun.GetString("E_MBLNR");
    if (strReturn == "")
    {
    IRfcTable returnRfcTable = myfun.GetTable("T_RETURN"); //返回数据
    strMsg = returnRfcTable.GetString("MESSAGE");
    }
    else {
    strMsg = strReturn;
    }

  • 相关阅读:
    Codeforces Round #674 (Div. 3)C. Increase and Copy
    Calendar Game
    poj3255Roadblocks
    L2-008 最长对称子串
    L2-004 这是二叉搜索树吗?
    D. Boboniu Chats with Du Codeforces Round #664 (Div. 2)
    暑假了,冲冲冲
    逆元和同余
    懒惰的我
    Codeforces Round #594 (Div. 2) C题
  • 原文地址:https://www.cnblogs.com/chengeng/p/13187951.html
Copyright © 2020-2023  润新知