Gneric Simple Way for Passing Multiple Inputs Feilds and defining out RFC Type #270
NDayakarChowdary
started this conversation in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hey Hi,
Good Day!!
This DLL Helps to write in more Generic Way,Thank you !!,Just Pasting this Code by using dll which help some one required even I Know some refactor is required
`using Dbosoft.YaNco;
using LanguageExt.ClassInstances;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Security;
using System.Threading.Tasks;
var sapConnectionString = "ASHOST=SERVERIP;SYSNR=001;CLIENT=00X;USER=Daya;PASSWD=T@stw0rd01;LANG=EN";
var connectionParams = sapConnectionString.Split(';')
.Select(part => part.Split('='))
.ToDictionary(split => split[0].Trim(), split => split[1].Trim());
var bapiName = "Z_BAPI_EQMT_DETAIL2";
// JSON string with input parameters
string inParamsJson = @"
[
{ ""Name"": ""INT_MATERIAL_DT"", ""Value"": ""2022-10-17T00:00:00"", ""Datatype"": ""DateTime"" },
{ ""Name"": ""EQUIPMENT"", ""Value"": ""20000000"", ""Datatype"": ""String"" }
]";
// Parse JSON string to a list of parameters
var inParamsList = JsonConvert.DeserializeObject<List<Dictionary<string, object>>>(inParamsJson);
var OutPutRFCType = "MapStructure";
var OutName = "EQUIMASTERS";
var resultJson = "";
var connectionBuilder = new ConnectionBuilder(connectionParams);
var connFunc = connectionBuilder.Build();
using (var context = new RfcContext(connFunc))
{
if (OutPutRFCType == "MapStructure")
{
await context.CallFunction(bapiName, Input: f =>
{
foreach (var input in inParamsList)
{
switch (input["Datatype"].ToString().ToLower())
{
case "datetime":
f = f.SetField(input["Name"].ToString(), (DateTime)(input["Value"]));
break;
case "string":
f = f.SetField(input["Name"].ToString(), input["Value"].ToString());
break;
case "double":
f = f.SetField(input["Name"].ToString(), (double)input["Value"]);
break;
case "int32":
f = f.SetField(input["Name"].ToString(), (int)input["Value"]);
break;
case "char":
f = f.SetField(input["Name"].ToString(), Convert.ToChar(input["Value"]));
break;
case "byte":
f = f.SetField(input["Name"].ToString(), Convert.ToByte(input["Value"]));
break;
case "sbyte":
f = f.SetField(input["Name"].ToString(), Convert.ToSByte(input["Value"]));
break;
case "single":
f = f.SetField(input["Name"].ToString(), Convert.ToSingle(input["Value"]));
break;
case "decimal":
f = f.SetField(input["Name"].ToString(), Convert.ToDecimal(input["Value"]));
break;
// Add more cases for other data types as needed
}
Console.ReadKey();`
Beta Was this translation helpful? Give feedback.
All reactions