Skip to content

Commit

Permalink
closes #6
Browse files Browse the repository at this point in the history
Refactor RfcType
  • Loading branch information
nunomaia committed Sep 21, 2019
1 parent d8ac8e8 commit ae4b660
Show file tree
Hide file tree
Showing 25 changed files with 638 additions and 54 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -342,3 +342,4 @@ healthchecksdb
/samples/BapiCompanyList/Properties/launchSettings.json
/samples/BapiCustomerDetail/Properties/launchSettings.json
/samples/BapiCustomerList/Properties/launchSettings.json
/samples/BapiGetGlAccountBalance/Properties/launchSettings.json
17 changes: 16 additions & 1 deletion NwRfcNet.sln
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BapiCompanyList", "samples\
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BapiCustomerList", "samples\BapiCustomerList\BapiCustomerList.csproj", "{973E85D8-8F8B-45F1-B062-B110595371C7}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BapiCustomerDetail", "samples\BapiCustomerDetail\BapiCustomerDetail.csproj", "{D506F2A9-D77B-490B-872B-680729E5529E}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BapiCustomerDetail", "samples\BapiCustomerDetail\BapiCustomerDetail.csproj", "{D506F2A9-D77B-490B-872B-680729E5529E}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BapiGetGlAccountBalance", "samples\BapiGetGlAccountBalance\BapiGetGlAccountBalance.csproj", "{F4C2ADD5-BA4C-45C2-AEF6-3340A5CDF0C2}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down Expand Up @@ -89,6 +91,18 @@ Global
{D506F2A9-D77B-490B-872B-680729E5529E}.Release|x64.Build.0 = Release|Any CPU
{D506F2A9-D77B-490B-872B-680729E5529E}.Release|x86.ActiveCfg = Release|Any CPU
{D506F2A9-D77B-490B-872B-680729E5529E}.Release|x86.Build.0 = Release|Any CPU
{F4C2ADD5-BA4C-45C2-AEF6-3340A5CDF0C2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F4C2ADD5-BA4C-45C2-AEF6-3340A5CDF0C2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F4C2ADD5-BA4C-45C2-AEF6-3340A5CDF0C2}.Debug|x64.ActiveCfg = Debug|Any CPU
{F4C2ADD5-BA4C-45C2-AEF6-3340A5CDF0C2}.Debug|x64.Build.0 = Debug|Any CPU
{F4C2ADD5-BA4C-45C2-AEF6-3340A5CDF0C2}.Debug|x86.ActiveCfg = Debug|Any CPU
{F4C2ADD5-BA4C-45C2-AEF6-3340A5CDF0C2}.Debug|x86.Build.0 = Debug|Any CPU
{F4C2ADD5-BA4C-45C2-AEF6-3340A5CDF0C2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F4C2ADD5-BA4C-45C2-AEF6-3340A5CDF0C2}.Release|Any CPU.Build.0 = Release|Any CPU
{F4C2ADD5-BA4C-45C2-AEF6-3340A5CDF0C2}.Release|x64.ActiveCfg = Release|Any CPU
{F4C2ADD5-BA4C-45C2-AEF6-3340A5CDF0C2}.Release|x64.Build.0 = Release|Any CPU
{F4C2ADD5-BA4C-45C2-AEF6-3340A5CDF0C2}.Release|x86.ActiveCfg = Release|Any CPU
{F4C2ADD5-BA4C-45C2-AEF6-3340A5CDF0C2}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -99,6 +113,7 @@ Global
{914BE78B-9205-4DD1-89A9-3059F2CA5469} = {813ACAE4-6905-4DE0-BD6B-AADF0535B2B5}
{973E85D8-8F8B-45F1-B062-B110595371C7} = {813ACAE4-6905-4DE0-BD6B-AADF0535B2B5}
{D506F2A9-D77B-490B-872B-680729E5529E} = {813ACAE4-6905-4DE0-BD6B-AADF0535B2B5}
{F4C2ADD5-BA4C-45C2-AEF6-3340A5CDF0C2} = {813ACAE4-6905-4DE0-BD6B-AADF0535B2B5}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {3BA7E01A-BE1C-404B-838B-0766A1657F8B}
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,4 @@ Included samples in project
* List FI Comapnies
* List FI Customers
* Get Details of a FI Customer
* FI General Ledger Account
2 changes: 1 addition & 1 deletion samples/BapiCompanyList/BapiCompanyList.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

<ItemGroup>
<PackageReference Include="CommandLineParser" Version="2.6.0" />
<PackageReference Include="NwRfcNet" Version="0.0.1" />
<PackageReference Include="NwRfcNet" Version="0.0.3" />
</ItemGroup>

</Project>
5 changes: 1 addition & 4 deletions samples/BapiCustomerDetail/BapiCustomerDetail.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@

<ItemGroup>
<PackageReference Include="CommandLineParser" Version="2.6.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\NwRfcNet\NwRfcNet.csproj" />
<PackageReference Include="NwRfcNet" Version="0.0.3" />
</ItemGroup>

</Project>
6 changes: 5 additions & 1 deletion samples/BapiCustomerList/BapiCustomerList.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@

<ItemGroup>
<PackageReference Include="CommandLineParser" Version="2.6.0" />
<PackageReference Include="NwRfcNet" Version="0.0.1" />
<PackageReference Include="NwRfcNet" Version="0.0.3" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\NwRfcNet\NwRfcNet.csproj" />
</ItemGroup>

</Project>
18 changes: 3 additions & 15 deletions samples/BapiCustomerList/BapiParameters.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
namespace Sample.BapiCustomerList
using NwRfcNet.Bapi;

namespace Sample.BapiCustomerList
{
public class ListCustomersInputParameters
{
Expand All @@ -21,20 +23,6 @@ public class CustomerAddress
public string Name { get; set; }
}

public class BapiReturn
{
public string Type { get; set; }
public string Id { get; set; }
public string Number { get; set; }
public string Message { get; set; }
public string LogNumber { get; set; }
public string LogMsgNumber { get; set; }
public string Message1 { get; set; }
public string Message2 { get; set; }
public string Message3 { get; set; }
public string Message4 { get; set; }
}


public class ListCustomersOutputParameters
{
Expand Down
15 changes: 15 additions & 0 deletions samples/BapiGetGlAccountBalance/BapiGetGlAccountBalance.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.2</TargetFramework>
<AssemblyName>Sample.BapiGetGlAccountBalance</AssemblyName>
<RootNamespace>Sample.BapiGetGlAccountBalance</RootNamespace>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="CommandLineParser" Version="2.6.0" />
<PackageReference Include="NwRfcNet" Version="0.0.3" />
</ItemGroup>

</Project>
43 changes: 43 additions & 0 deletions samples/BapiGetGlAccountBalance/BapiParameters.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using NwRfcNet.Bapi;

namespace Sample.BapiGetGlAccountBalance
{
public class BapiParametersInput
{
public string CompanyCode { get; set; }

public string GlAccount { get; set; }

public int FiscalYear { get; set; }

public string CurrencyType { get; set; }
}

public class BapiParametersOutput
{
public GlBalanceDetail[] Detail { get; set; }

public BapiReturn BapiReturn { get; set; }
}

public class GlBalanceDetail
{
public string CompanyCode { get; set; }

public string GlAccount { get; set; }

public int FiscalYear { get; set; }

public int FiscalPeriod { get; set; }

public decimal TotalDebit { get; set; }

public decimal TotalCredit { get; set; }

public decimal MontlySales { get; set; }

public decimal AccountBalance { get; set; }

public string Currency { get; set; }
}
}
171 changes: 171 additions & 0 deletions samples/BapiGetGlAccountBalance/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
using CommandLine;
using NwRfcNet;
using NwRfcNet.Bapi;
using NwRfcNet.TypeMapper;
using System;

namespace Sample.BapiGetGlAccountBalance
{

class Options
{
[Option('u', "username", Required = true, HelpText = "RFC User Name")]
public string UserName { get; set; }

[Option('p', "password", Required = true, HelpText = "RFC User Password")]
public string Password { get; set; }

[Option('h', "hostname", Required = true, HelpText = "RFC Server Hostname")]
public string Hostname { get; set; }

[Option('c', "client", Required = true, HelpText = "RFC Server Client Id")]
public string Client { get; set; }

[Option('a', "account", Required = true, HelpText = "G/L Account")]
public string GlAccount { get; set; }

[Option('k', "company", Required = true, HelpText = "FI Company Code")]
public string Company { get; set; }

[Option('f', "fiscalyear", Required = true, HelpText = "FI Fiscal Year")]
public int FiscalYear { get; set; }
}

class Program
{
static void ParameterMapping()
{
var mapper = RfcMapper.DefaultMapper;

mapper.Parameter<BapiParametersInput>()
.Property(x => x.CompanyCode)
.HasParameterName("COMPANYCODE")
.HasParameterType(RfcFieldType.Char)
.MaxLength(4);

mapper.Parameter<BapiParametersInput>()
.Property(x => x.GlAccount)
.HasParameterName("GLACCT")
.HasParameterType(RfcFieldType.Char)
.MaxLength(10);

mapper.Parameter<BapiParametersInput>()
.Property(x => x.FiscalYear)
.HasParameterName("FISCALYEAR")
.HasParameterType(RfcFieldType.Int);

mapper.Parameter<BapiParametersInput>()
.Property(x => x.CurrencyType)
.HasParameterName("CURRENCYTYPE")
.HasParameterType(RfcFieldType.Char)
.MaxLength(2);

mapper.Parameter<BapiParametersOutput>()
.Property(x => x.Detail)
.HasParameterName("ACCOUNT_BALANCES")
.HasParameterType(RfcFieldType.Table);

mapper.MapBapiReturn();

mapper.Parameter<BapiParametersOutput>()
.Property(x => x.BapiReturn)
.HasParameterName("RETURN")
.HasParameterType(RfcFieldType.Structure);

mapper.Parameter<GlBalanceDetail>()
.Property(x => x.CompanyCode)
.HasParameterName("COMP_CODE")
.MaxLength(4)
.HasParameterType(RfcFieldType.Char);

mapper.Parameter<GlBalanceDetail>()
.Property(x => x.GlAccount)
.HasParameterName("GL_ACCOUNT")
.MaxLength(10)
.HasParameterType(RfcFieldType.Char);

mapper.Parameter<GlBalanceDetail>()
.Property(x => x.FiscalYear)
.HasParameterName("FISC_YEAR")
.HasParameterType(RfcFieldType.Int);

mapper.Parameter<GlBalanceDetail>()
.Property(x => x.FiscalPeriod)
.HasParameterName("FIS_PERIOD")
.HasParameterType(RfcFieldType.Int);

mapper.Parameter<GlBalanceDetail>()
.Property(x => x.TotalDebit)
.HasParameterName("DEBITS_PER")
.HasParameterType(RfcFieldType.Bcd);

mapper.Parameter<GlBalanceDetail>()
.Property(x => x.TotalCredit)
.HasParameterName("CREDIT_PER")
.HasParameterType(RfcFieldType.Bcd);

mapper.Parameter<GlBalanceDetail>()
.Property(x => x.MontlySales)
.HasParameterName("PER_SALES")
.HasParameterType(RfcFieldType.Bcd);

mapper.Parameter<GlBalanceDetail>()
.Property(x => x.Currency)
.HasParameterName("CURRENCY")
.MaxLength(10)
.HasParameterType(RfcFieldType.Char);

}

static void Main(string[] args)
{
Parser.Default.ParseArguments<Options>(args)
.WithParsed<Options>(o =>
{
try
{
ParameterMapping();
var version = RfcConnection.GetLibVersion();
Console.WriteLine($"currently loaded sapnwrfc library version : Major {version.MajorVersion}, Minor {version.MinorVersion}, patchLevel {version.PatchLevel}");
using (var conn = new RfcConnection(userName: o.UserName, password: o.Password, hostname: o.Hostname, client: o.Client))
{
conn.Open();
using (var func = conn.CallRfcFunction("BAPI_GL_GETGLACCPERIODBALANCES"))
{
var inParams = new BapiParametersInput
{
CompanyCode = o.Company,
CurrencyType = "10", // document Currency
FiscalYear = o.FiscalYear,
GlAccount = o.GlAccount
};
func.Invoke(inParams);
var result = func.GetOutputParameters<BapiParametersOutput>();
Console.WriteLine(String.Format("|{0,-6}|{1,-6}|{2,-10}|{3,-10}", "Company", "Period", "Debit", "Credit"));
foreach (var row in result.Detail)
{
Console.WriteLine(String.Format("|{0,-6}|{1,-6}|{2,-10}|{3,-10}",
row.CompanyCode,
row.FiscalPeriod,
row.TotalCredit.ToString(),
row.TotalDebit.ToString()
)); ;
}
}
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
throw ex;
}
});

}
}
}
21 changes: 21 additions & 0 deletions src/NwRfcNet/Bapi/BapiMessageType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
namespace NwRfcNet.Bapi
{
public static class BapiMessageType
{
public static readonly string Success = "S";

public static readonly string Error = "S";

public static readonly string Warning = "W";

public static readonly string Information = "I";

public static readonly string Abort = "A";
}

public static class BapiMessageTypeExtentions
{
public static bool IsError(this BapiReturn bapiReturn)
=> bapiReturn.MessageType == BapiMessageType.Error || bapiReturn.MessageType == BapiMessageType.Abort;
}
}
Loading

0 comments on commit ae4b660

Please sign in to comment.