Call a simple function module: RFC CUSTOMER GET English

From Theobald Software

Jump to: navigation, search

German Version: Einen einfachen Baustein aufrufen: RFC CUSTOMER GET


The function module RFC_CUSTOMER_GET used in this article is not supported by SAP anymore (rel. mySAP ERP 2004 or higher)


RFC_CUSTOMER_GET is an RFC-enabled function module that should be present in every SAP system. It is designed for demonstration purposes. As an import parameter, a customer number should be transferred to the module and the customer's address is sent back to the calling program contained in a table parameter.

The code below shows how to log on to the SAP system. An RFCFunction object is created by the method CreateFunction. The import parameter KUNNR is filled with the string given by the user. Execute executes the function module. After the call, the program loops through the table CUSTOMER_T and writes some columns to the console.

Screenshot of the sample program
Enlarge
Screenshot of the sample program

[C#]

static void Main(string[] args)
  {
 
   R3Connection con = new R3Connection("hamlet",11,"theobald","pw","DE","800");
   con.Open(false);
 
   // Create a function object
   RFCFunction func = con.CreateFunction("RFC_CUSTOMER_GET");
 
   Console.WriteLine("Please enter customer number ...");
   Console.WriteLine("(and do not forget the leading zeros ...");
 
   // fill the export parameter
   StringBuilder CustomerNo =  new StringBuilder(Console.ReadLine());
   func.Exports["KUNNR"].ParamValue = CustomerNo.ToString();
 
   try 
   {
    func.Execute();
   }
   catch (ERPException e)
   {
    Console.WriteLine(e.Message);
    Console.ReadLine();
    return;
   }
 
   // Output the result of the function module
   Console.WriteLine("Name of customer:");
   Console.WriteLine(func.Tables["CUSTOMER_T"].Rows[0,"NAME1"]);
   Console.ReadLine();
   }

[VB]

Sub Main()
        Dim con As New R3Connection("hamlet", 11, "theobald", "pw", "DE", "800")
        con.Open(False)
 
        ' Create a function object
        Dim func = con.CreateFunction("RFC_CUSTOMER_GET")
 
        Console.WriteLine("Please enter customer number ...")
        Console.WriteLine("(and do not forget the leading zeros ...")
 
        ' fill the export parameter
        Dim CustomerNo As New StringBuilder(Console.ReadLine())
        func.Exports("KUNNR").ParamValue = CustomerNo.ToString()
 
        Try
            func.Execute()
        Catch e As ERPException
            Console.WriteLine(e.Message)
            Console.ReadLine()
            Return
        End Try
 
        ' Output the result of the function module
        Console.WriteLine("Name of customer:")
        Console.WriteLine(func.Tables("CUSTOMER_T").Rows(0, "NAME1"))
        Console.ReadLine()
    End Sub
DeutschEnglish
Personal tools
Navigation
XtractQL Provider
Xtract RS