.NET链接SAP

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using SAP.Middleware.Connector ;
using System.Windows.Forms;

……

        public string SetSapChgScr(string vbeln, string posnr,string mat,string net, string car,string con,string sel,string flag)
        {
            string tye = "";
            try
            {
                RfcDestination rfcDestination = RfcDestinationManager.GetDestination("EP1");
                RfcRepository rfcRepository = rfcDestination.Repository;
                IRfcFunction myfun = rfcRepository.CreateFunction("ZMM_BAPI_OFFCUT_CHANGE");

                IRfcStructure Hdata = myfun.GetStructure("HEADER_DATA");
                IRfcStructure Hctrl = myfun.GetStructure("HEADER_CONTROL");

                IRfcTable Ttext = myfun.GetTable("T_TEXT");
                IRfcStructure Stext = rfcRepository.GetStructureMetadata("ZZS_TEXT").CreateStructure();

                IRfcTable Tdata = myfun.GetTable("ITEM_DATA");
                IRfcStructure Idata = rfcRepository.GetStructureMetadata("BAPIOBDLVITEMCHG").CreateStructure();
                IRfcTable Tctrl = myfun.GetTable("ITEM_CONTROL");
                IRfcStructure Ictrl = rfcRepository.GetStructureMetadata("BAPIOBDLVITEMCTRLCHG").CreateStructure();

                Hdata.SetValue("DELIV_NUMB", vbeln);
                Hctrl.SetValue("DELIV_NUMB", vbeln);
                myfun.SetValue("ZBJL", flag);
                myfun.SetValue("DELIVERY", vbeln);

                Idata.SetValue("DELIV_NUMB",vbeln);
                Idata.SetValue("DELIV_ITEM",posnr);
                Idata.SetValue("MATERIAL",mat);
                Idata.SetValue("DLV_QTY",net);
                Idata.SetValue("FACT_UNIT_NOM","1");
                Idata.SetValue("FACT_UNIT_DENOM","1");
                Tdata.Insert(Idata);

                Ictrl.SetValue("DELIV_NUMB",vbeln);
                Ictrl.SetValue("DELIV_ITEM",posnr);
                Ictrl.SetValue("CHG_DELQTY","X");
                Tctrl.Insert(Ictrl);

                Stext.SetValue("DELIV_NUMB", vbeln);
                Stext.SetValue("DELIV_ITEM", posnr);
                Stext.SetValue("ZGH", con);
                Stext.SetValue("ZCH", car);
                Stext.SetValue("ZFTH", sel);
                Ttext.Insert(Stext);

                myfun.Invoke(rfcDestination);
                IRfcTable Rtables = myfun.GetTable("RETURN");
                tye = Rtables.GetString("TYPE").ToString();
                MSG = "";
                for (int Z = 0; Z <= Rtables.RowCount - 1; Z++)
                {
                    MSG = MSG + Rtables.GetString("MESSAGE").ToString();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            return tye;
        }

 

 

posted @ 2023-09-11 11:44  kang09  阅读(11)  评论(0编辑  收藏  举报