1.环境:
a. win7+64位操作系统
b. VS2012
c. nco3.0(64bit 下载网址:http://www.dllbang.com/dll/sapnco_dll ),
d. Microsoft Visual C++ 2005 Service Pack 1 ,用于运行nco3.0的dll文件
下载网址:http://www.microsoft.com/en-us/download/details.aspx?id=14431
2.目的:将数据通过RFC插入SAP自建表。
3.步骤:
第一步:进入SAP界面:使用T- CODE:SE11 打开建表界面:建立表ZNCOTEST
![]()
图片1:
![](https://img-blog.csdn.net/20140103125123921?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQveHVhbnd1eml5b3U=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast)
第二步:针对自建表ZNCOTEST创建RFC。
使用T- CODE:SE37 打开建RFC界面:命名为:ZNCOTEST_RFC
图片2:
![](https://img-blog.csdn.net/20140103125104390?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQveHVhbnd1eml5b3U=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast)
![]()
RFC如下表:在TABLE参数TABLE里设置IT_MYNCOTEST 类型是刚才自建的表ZCHANNEL_MESSAG。
图片3:
![](https://img-blog.csdn.net/20140103125138125?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQveHVhbnd1eml5b3U=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast)
![]()
在EXPORT里设置出参R_SUBRC.
![]()
图片4:
![](https://img-blog.csdn.net/20140103125149265?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQveHVhbnd1eml5b3U=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast)
在SOURCE CODE里写代码:
图片5:
![](https://img-blog.csdn.net/20140103125204734?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQveHVhbnd1eml5b3U=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast)
![]()
IF IT_MYNCOTEST[] IS NOT INITIAL.
- MODIFY ZNCOTEST FROM TABLE IT_MYNCOTEST[].
IF SY-SUBRC = 0.
R_SUBRC = 'OKKK'.
ENDIF.
ENDIF.
- ENDFUNCTION.
然后,注意要把RFC属性设为允许远程访问:
图片6:
![](https://img-blog.csdn.net/20140103125217500?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQveHVhbnd1eml5b3U=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast)
![]()
到此在SAP这边的工作已经就绪。
第三步:剩下的都在VS2010下完成:
打开VS2010新建一个WINDOWS窗体应用程序:WindowsFormsApplication2
![](https://img-my.csdn.net/uploads/201210/11/1349924749_9794.png)
拖动一个按钮控件到主窗体:
![](https://img-my.csdn.net/uploads/201210/11/1349924749_1256.png)
在解决方案资源管理器,引用里引用NCO3.0的sapnco.dll和sapnco_utils
![](https://img-my.csdn.net/uploads/201210/11/1349924749_2930.png)
右击项目名称WindowsFormsApplication2,点击“属性”,打开属性面板:将目标框架里默认的.NET Framework 4 Client Profile 改为:.NET Framework 4。(很重要)
![](https://img-my.csdn.net/uploads/201210/11/1349924762_7128.png)
在解决方案资源管理器里打开配置文件APP.CONFIG,配置如下:
![]()
代码:
<?xml version="1.0"?>
<configuration>
<configSections>
<sectionGroup name="SAP.Middleware.Connector">
<sectionGroup name="ClientSettings">
<section name="DestinationConfiguration" type="SAP.Middleware.Connector.RfcDestinationConfiguration,sapnco"/>
</sectionGroup>
</sectionGroup>
</configSections>
<SAP.Middleware.Connector>
<ClientSettings>
<DestinationConfiguration>
<destinations>
<add NAME="DEV" USER="username" PASSWD="password" CLIENT="500"
LANG="ZH" ASHOST="198.16.0.66" SYSNR="00"
MAX_POOL_SIZE="10" IDLE_TIMEOUT="10"/>
</destinations>
</DestinationConfiguration>
</ClientSettings>
</SAP.Middleware.Connector>
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0"/>
</startup>
</configuration>
双击Button1按钮进入代码编辑器:
手工引用:using SAP.Middleware.Connector;
![](https://img-my.csdn.net/uploads/201210/11/1349924763_7637.png)
为按钮添加单击事件如下:
private void button1_Click(object sender, EventArgs e)
{
RfcDestination SapRfcDestination = RfcDestinationManager.GetDestination("DEV");
RfcRepository SapRfcRepository = SapRfcDestination.Repository;
// Create and invhuoke function moduleZCHANNEL_RFC_MESSAGE
IRfcFunction myfun = SapRfcRepository.CreateFunction("ZNCOTEST_RFC");
// Set some input values for the structure.
IRfcStructure import = null;
IRfcTable table = myfun.GetTable("IT_MYNCOTEST");
int i = 3;
while (i < 6)
{
int j = i + 1;
string s=j+"S";
import = SapRfcRepository.GetStructureMetadata("ZNCOTEST").CreateStructure();
import.SetValue("ID", s);
import.SetValue("NAME", "Name" + s);
import.SetValue("REMARK", "Remark" + s);
table.Insert(import);
i++;
}
myfun.Invoke(SapRfcDestination);
string RETURNStr = myfun.GetString("R_SUBRC");
MessageBox.Show(RETURNStr);
}
![]()
在sap的se16中查看 运行结果:
图片7:
![](https://img-blog.csdn.net/20140103125235046?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQveHVhbnd1eml5b3U=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast)
![]()
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)