Friday, March 29, 2019

How to use SAP.NET Connector 2.0


Introduction
SAP is an inalienable system for large enterprise firms. We have to connect to this system if we need some data that belongs to SAP. The platforms can be Visual Studio 2008, Visual Studio 2005, Eclipse, or any other development tool.
But, there is a problem when connecting to SAP with Visual Studio 2008. The problem is SAP does not have a connector for Visual Studio 2005 and Visual Studio 2008. Up to Visual Studio .NET 2003 platform, there were no problems about connections to SAP.
As I mentioned in my other articles, the reason there is no connector for Visual Studio 2005 and Visual Studio 2008 is primarily marketing strategies. Let's not think why SAP did not make available an add-on for Visual Studio 2008, but think how can we solve this problem with available technologies.
Prerequisite Technologies
  • Visual Studio .NET 2003
  • Visual Studio 2008
  • SAP.NET Connector 2.0
  • Any SAP Application Server

Using the Code

As I mentioned above, we will first use Visual Studio .NET 2003. Our purpose is to connect to SAP with Visual Studio 2003. While operating, we will create a class library project. Then, we will give a reference to this application to Visual Studio 2008. Thus, the problem about connection to SAP with Visual Studio 2008 will be solved. Meanwhile, this solution is recommended by SAP.
Let's start creating a class library project first.

After creating the class library project, we will need to create a SAP Connector Proxy item as shown below.

Because we will make a connection to SAP, we have to look at the SAP Servers under the Server Explorer section. We will use one of the BAPIs of SAP’s user information. This is the general view of the BOR objects.



 We will use the ‘GetDetail’ method of the USER object. Drag and drop this method onto the SAPProxy1.sapwsdl file. Later on, there is no need for another class in our project. I am deleting the Class1.cs file.

We have now completed the operations in the Visual Studio .NET 2003 side. You should now build your project. The output ‘SAPUserDetailComponent.dll’ will be a required file while connecting to SAP in Visual Studio 2008.
Now, we will create a Windows project under Visual Studio 2008.

Before adding the DLL file of the previous project, we should add two more DLLs to our project. First, copy ‘SAPUserDetailComponent.dll’ to your project folder. Then, go to “..\Program Files\SAP\SAP .NET Connector 2.0″ and copy “SAP.Connector.dll” and “SAP.Connector.Rfc.dll” to your project folder.

We should pay attention to another point. The SAP Proxy is based on the SOAP protocol. So, we need to add the “System.Web.Services” DLL to our references.

I have only added simple controls into Form1. The logic is simple, a SAP username will be taken, and the profiles authorization of this user will be printed into a table to show. Form1 will look as shown below.

First, I inform the Visual Studio builder about the usage of the SAPUserDetailComponent assembly file:

using SAPUserDetailComponent;


Then, I write the code for the GetProfiles button’s Click event.
SAPProxy1 proxy = new SAPProxy1();
The SAPProxy1 class is referenced in our SAPUserDetail component reference.
BAPIADDR3 address = new BAPIADDR3();
BAPIUSCOMP companyName = new BAPIUSCOMP();
BAPIDEFAUL defaults = new BAPIDEFAUL();
BAPILOGOND logonData = new BAPILOGOND();
BAPISNCU snc = new BAPISNCU();
BAPIAGRTable activeGroups = new BAPIAGRTable();
BAPICOMREMTable addcomrem = new BAPICOMREMTable();
BAPIADFAXTable addfax = new BAPIADFAXTable();
BAPIADPAGTable addpag = new BAPIADPAGTable();
BAPIADPRTTable addprt = new BAPIADPRTTable();
BAPIADRFCTable addrfc = new BAPIADRFCTable();
BAPIADRMLTable addrml = new BAPIADRMLTable();
BAPIADSMTPTable addsmtp = new BAPIADSMTPTable();
BAPIADSSFTable addssf = new BAPIADSSFTable();
BAPIADTELTable addtel = new BAPIADTELTable();
BAPIADTLXTable addtlx = new BAPIADTLXTable();
BAPIADTTXTable addttx = new BAPIADTTXTable();
BAPIADURITable adduri = new BAPIADURITable();
BAPIADX400Table addx400 = new BAPIADX400Table();
BAPIPARAMTable parameter = new BAPIPARAMTable();
BAPIPROFTable profiles = new BAPIPROFTable();
BAPIRET2Table return0 = new BAPIRET2Table();
The above variables will be used while calling the SAP function.
SAP.Connector.Destination destination = new SAP.Connector.Destination();

We need to create a destination object to connect SAP. Later on, we will set the properties of thisdestination object as I have shown below.
destination.AppServerHost = YOUR HOST NAME OR IP
destination.Client = YOUR CLIENT NUMBER
destination.Password = USER'S PASSWORD
destination.SystemNumber = SYSTEM NUMBER
destination.Username = USER'S NAME


Our destination object will be a parameter for the SAPConnection class.

SAP.Connector.SAPConnection connection =
   new SAP.Connector.SAPConnection(destination);

And, our connection object will be assigned to the proxy object.

proxy.Connection = connection;

Now, we open the connection.

proxy.Connection.Open();

Call the SAP function:

proxy.Bapi_User_Get_Detail(tbUsername.Text.Trim(), out address, out companyName,
   out defaults, out logonData, out snc, ref activeGroups,
   ref addcomrem, ref addfax, ref addpag, ref addprt, ref addrfc,
   ref addrml, ref addsmtp, ref addssf, ref addtel, ref addtlx,
   ref addttx, ref adduri, ref addx400,
   ref parameter, ref profiles, ref return0);

Then, close the connection.

proxy.Connection.Close();

And, I will convert the result table of this function to an ADO table as I have shown below:

DataTable dt = profiles.ToADODataTable();
The last operation is we give the data table as a source for the grid view.

dgProfiles.DataSource = dt;

The result screen will be:


Thank you 

Arjun walmiki


Friday, March 22, 2019

if not able to download the Source code from Code Project or any other website.

Hi All ,

Today i got issue from one of the colleague he raise an query he is not able to download the the source code from  the below url
https://www.codeproject.com/Articles/1277140/Simple-Transaction-Microservices-Sample-Architectu

the error is as below :-


this is happens because of

Failed login limit

Authenticating with invalid credentials will return 401 Unauthorized:
curl -i https://api.github.com -u foo:bar
HTTP/1.1 401 Unauthorized
{
  "message": "Not Found",
  "documentation_url": "https://developer.github.com/v3"
} 
After detecting several requests with invalid credentials within a short period, the API will temporarily reject all authentication attempts for that user (including ones with valid credentials) with 403 Forbidden:


Solution :-

when you in my case when you click download link

The url :- https://api.github.com/repos/johnph/simple-transaction/%7Barchive_format%7D%7B/ref%7D

So remove the "/%7Barchive_format%7D%7B/ref%7D" that part from query string
The correct your are as below:-
https://api.github.com/repos/johnph/simple-transaction

when you hit above url on browser you will get .json Response 


In above json i am highlight "clone_url": "https://github.com/johnph/simple-transaction.git",

clone the same :-

Hope it is resolve your issue.

Thank you

Arjun Walmiki

Wednesday, March 20, 2019

Nested Classes in C#

Hello all in this post i will explain you how to create class inside class means nested class in programming language.


class is a user-defined blueprint or prototype from which objects are created. Basically, a class combines the fields and methods (member function which defines actions) into a single unit. In C#, a user is allowed to define a class within another class. Such types of classes are known as nested class. This feature enables the user to logically group classes that are only used in one place, thus this increases the use of encapsulation, and create more readable and maintainable code.

Syntax:
class Outer_class {
       // Code..
       class Inner_class {
          // Code.. 
       } 
}

If you create object of above class

Outer_class test=new Outer_class ();
Outer_class.Inner_class test2 = new Outer_class.Inner_class();
In example i am create simple class you can yous according to your requirement.

Important points:
  • A nested class can be declared as a private, public, protected, internal, protected internal, or private protected.
  • Outer class is not allowed to access inner class members directly as shown in above example.
  • You are allowed to create objects of inner class in outer class.
  • Inner class can access static member declared in outer class.

Thank you,
Arjun Walmiki

Tuesday, March 19, 2019

Encapsulation in C#


Encapsulation is defined as the wrapping up of data under a single unit. It is the mechanism that binds together code and the data it manipulates. In a different way, encapsulation is a protective shield that prevents the data from being accessed by the code outside this shield.
  • Technically in encapsulation, the variables or data of a class are hidden from any other class and can be accessed only through any member function of own class in which they are declared.
  • As in encapsulation, the data in a class is hidden from other classes, so it is also known as data-hiding.
  • Encapsulation can be achieved by: Declaring all the variables in the class as private and using C# Properties in the class to set and get the values of variables.
Example:

// C# program to illustrate encapsulation
using System;
  
public class DemoEncap {
      
    // private variables declared
   // these can only be accessed by
    // public methods of class
    private String developerName;
    private int developerAge;
      
    // using accessors to get and set the value of developerName
    public String Name
    {
          
        get
        {
            return developerName;    
        }
          
        set 
        {
            developerName= value;
        }
          
    }
      
    // using accessors to get and set the value of developerAge
    public int Age
    {      
        get 
        {
            return developerAge;    
        } 
        set 
        {
            developerAge= value;
        }     
    }     
}  
// Driver Class
class GFG {
      
    // Main Method
    static public void Main()
    {
          
        // creating object
        DemoEncap obj = new DemoEncap();
  
        // calls set accessor of the property Name, 
        // and pass "Arjun" as value of the standard field 'value'
        obj.Name = "Arjun";
          
        // calls set accessor of the property Age, 
        // and pass "34" as value of the standard field 'value'
        obj.Age = 34;
  
        // Displaying values of the variables
        Console.WriteLine("Name: " + obj.Name);
        Console.WriteLine("Age: " + obj.Age);
    }
}
Output:
Name: Arjun
Age: 34
Explanation: In the above program the class DemoEncap is encapsulated as the variables are declared as private. To access these private variables we are using the Name and Age accessors which contains the get and set method to retrieve and set the values of private fields. Accessors are defined as public so that they can access in other class.
Advantages of Encapsulation:
  • Data Hiding: The user will have no idea about the inner implementation of the class. It will not be visible to the user that how the class is stored values in the variables. He only knows that we are passing the values to accessors and variables are getting initialized to that value.
  • Increased Flexibility: We can make the variables of the class as read-only or write-only depending on our requirement. If we wish to make the variables as read-only then we have to only use Get Accessor in the code. If we wish to make the variables as write-only then we have to only use Set Accessor.
  • Reusability: Encapsulation also improves the re-usability and easy to change with new requirements.
  • Testing code is easy: Encapsulated code is easy to test for unit testin