当前位置:网站首页>C interface with SAP
C interface with SAP
2022-07-21 15:16:00 【I Can -Jiang】
1、 Incoming and outgoing are tables
try
{
RfcDestination destination = RfcDestinationManager.GetDestination("DEV");
RfcFunctionMetadata BAPI_COMPANYCODE_GETDETAIL_MD = destination.Repository.GetFunctionMetadata("ZMM_PR_CHANGE"); //RFC The name of the function
myfun = BAPI_COMPANYCODE_GETDETAIL_MD.CreateFunction(); // Define input function
IRfcTable tSAP = myfun.GetTable("IT_PR");
for (int i = 0; i < dt.Rows.Count; i++)
{
IRfcStructure struSAP = tSAP.Metadata.LineType.CreateStructure();
#region
struSAP.SetValue("PREQ_NO", dt.Rows[i][" Purchase requisition No "].ToString());
struSAP.SetValue("PREQ_ITEM", dt.Rows[i][" Item number of the purchase requisition "].ToString());
struSAP.SetValue("DELETE_IND", dt.Rows[i][" Purchase voucher deletion id "].ToString());
#endregion
tSAP.Append(struSAP);
}
myfun.SetValue("IT_PR", tSAP); //table Parameters
myfun.Invoke(destination);
IRfcTable dtSAPData = myfun.GetTable("IT_PR");
string errRow = "", errMessage = "";
for (int i = 0; i < dtSAPData.RowCount; i++)
{
IRfcStructure stru = dtSAPData[i];
#region
sql = "update MM_purPurchaseApplyDetail set MTYPE = '" + stru.GetValue("MTYPE").ToString().Trim() + "',MESSAGE = '" + stru.GetValue("MESSAGE").ToString().Trim() + "' where BillNo = '" + txt_BillNo.Text.Trim() + "' and RowCode = '" + stru.GetValue("PREQ_ITEM").ToString().Trim() + "' ";
if (!DB.AF.sqlExec(sql, sqlconnSAP, out errMsg))
{
XtraMessageBox.Show(" to update PR Details failed !");
}
#endregion
if (stru.GetValue("MTYPE").ToString().Trim() != "S")
{
errRow += stru.GetValue("PREQ_ITEM").ToString().Trim() + " ";
errMessage += " The first [" + stru.GetValue("PREQ_ITEM").ToString().Trim() + "] That's ok :" + stru.GetValue("MESSAGE").ToString() + "\n";
}
}
if (errRow.Length > 0)
{
XtraMessageBox.Show(" The first [" + errRow + "] That's ok Sap Failed to modify the document ! The reason for the failure is :" + "\n" + errMessage);
}
else
XtraMessageBox.Show("SAP The document has been modified successfully !");
}
catch (Exception ex)
{
XtraMessageBox.Show(ex.Message);
}
2、 Incoming table 、 Return to structure
RfcDestination destination = RfcDestinationManager.GetDestination("DEV");
RfcFunctionMetadata BAPI_COMPANYCODE_GETDETAIL_MD = destination.Repository.GetFunctionMetadata("ZMM_BAPI_GOODSMVT_CREATE_N"); //RFC The name of the function
myfun = BAPI_COMPANYCODE_GETDETAIL_MD.CreateFunction(); // Define input function
IRfcTable tSAP = myfun.GetTable("IT_RES");
for (int i = 0; i < GV.RowCount; i++)
{
IRfcStructure struSAP = tSAP.Metadata.LineType.CreateStructure();
#region
struSAP.SetValue("RSNUM", ""); // reserve / Number of relevant requirements
struSAP.SetValue("RSPOS", ""); // reserve / Project number of relevant requirements
struSAP.SetValue("AUFNR", GV.GetRowCellValue(i, " The order number ").ToString()); // The order number
#endregion
tSAP.Append(struSAP);
}
myfun.SetValue("IT_RES", tSAP); //table Parameters
try
{
myfun.Invoke(destination);
}
catch (Exception ex)
{
XtraMessageBox.Show(" Failed to call interface !"+ex.Message);
}
IRfcStructure getstu = myfun.GetStructure("O_RETURN");
DOCNO = getstu.GetValue("DOCNO").ToString();
MTYPE = getstu.GetValue("MSGTP").ToString();
MESSAGE = getstu.GetValue("MSTXT").ToString();
3、 Incoming table 、 Return field
try
{
RfcDestination destination = RfcDestinationManager.GetDestination("DEV");
RfcFunctionMetadata BAPI_COMPANYCODE_GETDETAIL_MD = destination.Repository.GetFunctionMetadata("ZMM_PR_CREATE"); //RFC The name of the function
myfun = BAPI_COMPANYCODE_GETDETAIL_MD.CreateFunction(); // Define input function
//IRfcFunction func = rfcRep.CreateFunction("ZMM_IS_PR_CREATE");
IRfcTable tSAP = myfun.GetTable("IT_PR");
for (int i = 0; i < dt.Rows.Count; i++)
{
IRfcStructure struSAP = tSAP.Metadata.LineType.CreateStructure();
#region
struSAP.SetValue("PREQ_ITEM", dt.Rows[i][" Item number of the purchase requisition "].ToString());
struSAP.SetValue("PR_TYPE", dt.Rows[i][" Order type "].ToString());
struSAP.SetValue("PR_TEXT", dt.Rows[i][" remarks "].ToString());
struSAP.SetValue("PLANT", dt.Rows[i][" factory "].ToString());
struSAP.SetValue("PUR_GROUP", dt.Rows[i][" Procurement section "].ToString());
#endregion
tSAP.Append(struSAP);
}
myfun.SetValue("IT_PR", tSAP); //table Parameters
myfun.Invoke(destination);
EV_NUMBER = myfun.GetString("EV_NUMBER");
MTYPE = myfun.GetString("MTYPE");
MESSAGE = myfun.GetString("MESSAGE");
4、 Incoming fields 、 Go back to the table
sesstab.Clear();
try
{
RfcDestination destination = RfcDestinationManager.GetDestination("DEV");
RfcFunctionMetadata BAPI_COMPANYCODE_GETDETAIL_MD = destination.Repository.GetFunctionMetadata("ZMM_GET_STOCK_QUANTITY_MUL"); //RFC The name of the function
myfun = BAPI_COMPANYCODE_GETDETAIL_MD.CreateFunction(); //
myfun.SetValue("IV_MATERIAL", "" + txt_MaterialID.Text.Trim() + ""); // Material number
myfun.SetValue("IV_PLANT", "" + ddl_Company.EditValue.ToString().Trim() + ""); // factory
myfun.SetValue("IV_STGE_LOC", "" + ddl_Warehouse.EditValue.ToString().Trim() + ""); // Place of stock
myfun.SetValue("IV_BATCH", "" + txt_BatchNo.Text.Trim() + ""); // Batch number
myfun.Invoke(destination);
MTYPE = myfun.GetString("MTYPE");
MESSAGE = myfun.GetString("MESSAGE");
IRfcTable tSAP = myfun.GetTable("ET_STOCK");
XtraMessageBox.Show(MTYPE+":"+ MESSAGE);
for (int i = 0; i < tSAP.RowCount; i++)
{
IRfcStructure stru = tSAP[i];
DataRow dr = sesstab.NewRow();
dr[" Material number "] = stru.GetValue("MATERIAL").ToString();
dr[" factory "] = stru.GetValue("PLANT").ToString();
dr[" Place of stock "] = stru.GetValue("STGE_LOC").ToString();
dr[" Batch number "] = stru.GetValue("BATCH").ToString();
dr[" stock "] = stru.GetValue("LABST").ToString();
dr[" Material description "] = stru.GetValue("MAKTX").ToString();
dr[" Specifications and models "] = stru.GetValue("GROES").ToString();
dr[" The basic unit of measurement "] = stru.GetValue("MEINS").ToString();
sesstab.Rows.Add(dr);
}
GC.DataSource = sesstab;
}
catch (Exception ex)
{
XtraMessageBox.Show(ex.Message);
}
边栏推荐
- asp.net -GridView自带的删除行项超链接用法(DeleteButton)
- Flask 源码剖析(一)请求入口
- (2022版)零基础入门网络安全/Web安全,收藏这一篇就够了
- Vulnhub靶机-doubletrouble
- Xshell determines that if the file exceeds the specified size, the file will be emptied
- 第二章第六节:字符串的补充和总结
- Opportunities and challenges coexist for financial enterprises to go to sea in emerging markets, advance AI ensures its safety and compliance development
- DAMA-第五章(数据建模与设计)
- message: 没有找到可以构建的 NPM 包,请确认需要参与构建的 npm 都在 `miniprogramRoot` 目录内,或配置 project.config.json 的 packNpmMa
- Construction of combat battalion module 7 operation
猜你喜欢
Skillfully using roaringbitmap to deal with the memory diff problem of massive data
【CVA估值训练营】读懂上市公司年报_第二讲
Section 8 of Chapter II: addition, deletion, modification and query of the list
Section 10 of Chapter 2: supplementary knowledge points of the list
DevExpress TreeList 实现父节点列值选中,其下子节点也全部选中
HVV蓝队之入侵排查
mysql数据900W+从17s到300ms是怎么做到的?sql优化的魅力(荣耀典藏版)
TCP sliding window explanation (very practical)
金融企业出海新兴市场机遇与挑战并存,ADVANCE.AI保障其安全合规发展
Math.random()的用法
随机推荐
openGauss内核分析:查询重写
[leetcode] 29. Divide two numbers
xshell 判断文件超出指定大小则清空文件
Winform窗体使用Assembly实例化及传参
Section 4 of Chapter 2: replacement and cutting
Section 6 of Chapter 2: supplement and summary of strings
第二章第十一节:元组
Indoor positioning of mobile robot and application of Internet of things based on visible light communication
Math.random()的用法
Idea 2021 automatically generates serialVersionUID
巧用RoaringBitMap处理海量数据内存diff问题
基于可见光通信的移动机器人室内定位及物联网应用
Section 10 of Chapter 2: supplementary knowledge points of the list
.NET Core 加载程序集AssemblyLoadContext
Vulnhub靶机-doubletrouble
很多人认为元宇宙的发展逻辑和互联网是一致的,但笔者并不觉得
04 提取最新的数据
【二叉树】分裂二叉树的最大乘积
Arithmetic operator 2 (Gretel software - Jiuye practical training)
浅聊一下 布隆过滤器