Nco 2 vs nco 3 syntax
是咁的, sap 的世界, 網上既資料好凌散, SNR 極低. 有見及此, 我黎緊就嘗試將呢d 有用既整理下, 希望諸君同我都有用, 齊齊發SAP財. 第一炮, 係關於so called sap .net connector (nco3). 唔知點解佢果d tutorial 呀, official 既書 都寫得唔到point. 點唔到point? 其實用得nco3 有一個好major既原因, 就係將nco2 d code轉成 nco3 既寫法.唔知點解, 無人比較過. SAP既community好奇怪, d 人答野好冗長, 一係得code, 一係答非所問. 以下係本人對nco2 同nco3 syntax既濃缩版.
/********Old syntax************/ //declaration SAPProxy.BAPI1_Input bapi1_Input = new SAPProxy.BAPI1_Input(); SAPProxy.BAPI1_Input bapi1_Output = new SAPProxy.BAPI1_Output(); SAPProxy sapProxy = new SapProxy(sapConn); //關於咩係field, structure, table, 自已se37 睇睇啦 //input (set parameter value in Import which is a field) bapi1_Input.Para1 = fooBar1; bapi1_Input.Para2 = fooBar2; bapi1_Input.Para3 = fooBar3; bapi1_Input.Para4 = fooBar4; //input (set parameter value in Import which is a table) For(int i = 0; i < numberOfInputItems; i++){ //table入面既row, 又有個class 俾你去整個instance出黎. TABLE2_CREATE table2 = new TABLE2_CREATE(); table2.TABLE2PARA1 = fooBar1ForTable2Para1; bapi1_Input.TABLE2.Add(table2); } //output (get parameter value in Export which is a table) bapi1_Input.Table1 = new someSortOfTable(); bapi1_Ouput.Table1 = new someSortOfTable(); //新版唔洗將table structure拉落.net 到. 所以唔會有以上兩行 //call bapi bapi1_Output = sapProxy.Bapi1( bapi1_Input ); //舊版call bapi就係用個proxy instance食過input instance, 結果就嘔番落個output instance 到 //output (get parameter value in Export which is a field); bapi1_Output.OUTPUT_PARA1; //output (get parameter value in Export which is a strucutre) bapi1_Output.STRUCT1.OUTPUT_KEY1; bapi1_Output.STRUCT1.OUTPUT_KEY2; bapi1_Output.STRUCT1.OUTPUT_KEY3; bapi1_Output.STRUCT1.OUTPUT_KEY4; bapi1_Output.STRUCT1.OUTPUT_KEY5; //output (get parameter value in Export which is a table) string [] table1StringArray = new string [bapi1_Output.TABLE1.Count]; for (int i = 0 ; i< table1StringArray.Length ; i++){ table1StringArray[i] = bapi1_Output.Table1[i].TableStrucutureName; } /*******New syntax*******************/ //declaration IrfcFunction function = rfcDestination.Repository.CreateFunction("BAPI1"); //見到嗎? nco3完全唔用proxy玩法. 唔會input 同output各自一個instance, 清爽好多. //input (set parameter value in Import) function.SetValue("PARA1",fooBar1); function.SetValue("PARA2",fooBar1); function.SetValue("PARA3",fooBar1); function.SetValue("PARA4",fooBar1); //input (set parameter value in Import which is a table) IrfcTable tableList = function.GetTable("TABLE2"); tableList.Append(numberOfInputItems); For(int i = 0; i < numberOfInputItems; i++){ tableList[i].SetValue("TABLE2PARA1", fooBar1ForTable2Para1); } //call bapi function.Invoke(rfcDestination); //how to set rfcDesitnation is skipped in here. //output (get parameter value in Export which is a field); function.GetString("OUTPUT_PARA1"); //output (get parameter value in Export which is a strucutre) IRfcStructure outputStructIRfc = function.GetStrcuture("STRUCT1"); outputStructIRfc.GetString("OUTPUT_KEY1"); outputStructIRfc.GetString("OUTPUT_KEY2"); outputStructIRfc.GetString("OUTPUT_KEY3"); outputStructIRfc.GetString("OUTPUT_KEY4"); outputStructIRfc.GetString("OUTPUT_KEY5"); //output (get parameter value in Export which is a table) IRfcTable outputIrfcTbl = function.GetTable("TABLE1"); //you can find a method to convert IrfcTable to DataTable //(http://stackoverflow.com/questions/17440728/how-to-save-data-from-sap-structure-to-microsoft-sql-table) ToADODataTable(outputIrfcTbl);
總括來說, upgrade 做nco3都係因為.net 1.1 以上無得選. 禁nco3都算係禁. 下次我地再瞭解一下點樣set rfcDestination 同如果要俾.net user各自用自已既sap account login有咩做法同可能出現既問題












