ERP Integrator V2 - Online Help
ERP Integrator V2
Questions / Feedback?

Using SapServer with SAP NetWeaver

This is a short primer that explains how to use the SapServer component with a SAP NetWeaver 7 install, with SAPGUI. It is meant only as a guide, and is not designed to be all-encompassing.

The code below installs the function "Z_HELLO" and begins accepting and listening for connections from the SAP system.

  SapServer1.AcceptConnections("Hello.App", "localhost", "sapgw00");
  SapServer1.InstallFunction("Z_HELLO", "Simple greeting app.");
  SapServer1.Listening = true;
Note that if the UseClientConnection config is set to true, or if the SapConnection.ConnectionType field is set to ctNetWeaver (default), you must also set the appropriate fields in the SapConnection property. So the code would look like this instead:
  SapClient1.Config("UseClientConnection=true");
  SapClient1.SapConnection.ConnectionType = ConnectionTypes.ctNetWeaver;
  SapClient1.SapConnection.Client = "000";
  SapClient1.SapConnection.Destination = "";
  SapClient1.SapConnection.Host = "localhost";
  SapClient1.SapConnection.User = "BCUSER";
  SapClient1.SapConnection.Password = "minisap";
  SapClient1.SapConnection.SystemNumber = 0;
  SapClient1.AcceptConnections("Hello.App", "localhost", "sapgw00");
  SapServer1.InstallFunction("Z_HELLO", "Simple greeting app.");
  SapClient1.Listening = true;

Note that the credentials above are for connecting to a trial NetWeaver installation. You will need to provide your own credentials when connecting to your own SAP installation. Also, please ensure that all dependencies in the Dependencies section below are fulfilled.

Once you've called AcceptConnections , installed your functions, and set Listening to true as shown above, you may use the SAP NetWeaver system to execute your functions. To access this functionality from within NetWeaver, the first thing you need to do is Register an RFC Destination. Then you need to create a new function which is remote enabled. Finally, you need to execute that function on the RFC destination you created. The instructions below outline how to do this on the NetWeaver 7 platform with SAPGUI.

Creating an RFC Destination

First run transaction SM59, which manages RFC Connection configuration. Open the "TCP/IP connections" branch and then click the "Create" button. Under "RFC Destination" put in a name that will identify this destination. For this example, we're using "TESTDEST". Click the "Technical Settings" tab, and under "Activation Type" slick the "Registered Server Program" radio button. Below that, set the "Program ID" field to the same ProgramId you passed into the AcceptConnections method ("Hello.App" in this case).

You can now click the "Connection Test" button, and NetWeaver will attempt to connect to and ping your server application. You will not see this in the FunctionCall event, as the component will automatically respond to a ping. You may override this functionality by installing "RFC_PING" with InstallFunction.

Creating a new function

To create a new function you must first define a new function group, and then add a function module to that group. To do this, open the Object Navigator, or execute transaction SE80. On the left menu screen, click the "Repository Browser" bar. In the selection box displayed below, choose "Function Group". Under that, type a name for your new function group and press enter. This function group must start with "Z_" (capital Z, underscore), otherwise you will be asked for an access key. For this example, we will use "Z_TEST_GROUP". If the function group does not exist, you will be asked if you want to create the object. Select Yes, fill in the short text field, (just a simple description) and click Save. On the next screen, leave the "Package" field empty and click "Local Object" to save the function group.

You should now have your new function group listed in the left hand frame. Right click on your function group and select Create->Function Module. Put in a new name for your function module. This must match the name of the function you install with the SapServer component's InstallFunction method. Like the function group, it should also start with "Z_". For this example, we'll use "Z_HELLO". This will be the name of the function you'll implement on your server, and is the same name you'll register with the InstallFunction method.

The new function will now be displayed in the right frame. Click the "Attributes" tab, and under Processing Type select the "Remote-Enabled Module" radio button. The "Import" tab allows you to specify import parameters. These correspond to the ReceiveParams in the SapServer component. For this example, we'll add two parameters, "FIRSTNAME" and "LASTNAME". The "Typing" field should be set to "TYPE", and the Associated Type to "CHAR256" for both parameters. Check the "Pass Value" box for both as well.

Next, click the "Export" tab, and create a parameter called "GREETING", with typing "TYPE" and associated type "CHAR512". Pass Value should also be checked here as well. This corresponds to the ReplyParams property in the SapServer component. You may also add tables using the "Table" tab, but that will not be necessary for this example. Under the "Exceptions" tab you may define any exception you like. (There is no master list, you just name them as you see fit). Press ctrl-S to save (Or select "Function Module->Save" from the menu bar).

Running your function

Close all the open windows until you're back at the home screen. Now run transaction SE37. Put the name of the function you wish to call in the "Function Module" field (in this case "Z_HELLO") and click the "Display" button. Press F8 to test the function module. On this screen fill in the "RFC Target sys" field with the RFC destination you created above ("TESTDEST"). Fill the import parameters with the data you wish to send to the server. Check the "Uppercase/Lowercase" checkbox if you don't want NetWeaver to send uppercase parameter values. Now press either the Activate or Debugging button to execute the function.

If everything is set up correctly, the FunctionCall event will now fire with the FunctionName parameter "Z_HELLO". Add the FIRSTNAME and LASTNAME ReceiveParams and call UpdateReceiveParams(). Add the greeting you wish to send to the ReplyParams property, and then call SendReply(). For instance:

void SapServer1_OnFunctionCall(object sender, SapserverFuncionCallEventArgs e) {
  if (e.FunctionName.Equals("Z_HELLO")) {
    SapServer1.ReceiveParams.Add(new nsoftware.InERP.SapParam("FIRSTNAME", "",ptCharacters));
    SapServer1.ReceiveParams.Add(new nsoftware.InERP.SapParam("LASTNAME", "", ptCharacters));
    SapServer1.UpdateReceiveParams();
        
    String greeting = "Hello " + SapServer1.ReceiveParams.ElementAt(0).Value + " " +
                      SapServer1.ReceiveParams.ElementAt(1).Value + ", I hope that you are well.";
    SapServer1.ReplyParams.Add(new nsoftware.InERP.SapParam("GREETING", greeting, ptCharacters));
    SapServer1.SendReply();
  }
}
The result of calling this function from NetWeaver with FIRSTNAME "John" and LASTNAME "Smith" is: "Hello John Smith, I hope that you are well.", and is contained in the "GREETING" export parameter.

For more detailed information creating function modules, including the use of tables, please see: http://help.sap.com/saphelp_nw04/helpdata/en/26/64f61dfa8911d386e70000e82011b8/frameset.htm

Creating New tables

Transaction Code SE11 allows you to display existing tables or create new ones. Run SE11 and select the "Database table" radio button. Enter a name for your table, making sure it begins with a capital 'Z' character, (in this example, we'll use "ZMYTAB"). Then click the "Create" button. Fill in the short description field first. Then under "Delivery and Maintenance" set the "Delivery Class" to "A". Next click the "Fields" tab and add your fields. The very first field you add should be the key for this table. (This key is necessary and is used by the SAP system). Note that the "KEY" name is reserved, the first field in any table must be a key, and the maximum length for a key is 120 characters. (The maximum length for all other fields is 255 characters).

When adding fields, you may use predefined types or use existing data elements. For this example we will manually create each fields. To begin doing this, press the "Predefined Fields" button. Then, on each line enter the name of your field, the Data Type, Length, and Short Description. We'll add two fields this way. The first is named "MYKEY", has the "Key" checkbox marked, data type is CHAR, and length is 120. The next data element is named "DATA", data type CHAR, and length 255 (the maximum length for a field). You may also create other types of fields, but note that for some Data Types (INT1, INT2, etc) the SAP system will automatically select the correct field length.

After adding all of your data fields, you're not quite done yet. Click the "Extras" menu and then "Enhancement Category". Click the checkbox on the error message that pops up, and then on the "Maintain Enhancement Category" window select the "Cannot Be Enhanced" radio button, then press the "Copy" button.

Press CTRL-S (or Table->Save) to save the table. On the "Create Object Directory Entry" window that pops up, click the "Local Object" button. Ignore the warning message that the application table should be client-specific. We're almost done now. Click the "Technical Settings" button near the top of the current window. Set the "Data Class" field to "USER" and the "Size category" to 0. CTRL-S to save, and then the Back button (or press F3) to exit out. Now select the "Table" menu one last time, and click "Activate." (or press CTRL-F3). Your table is now activated and may be used by the functions you create.

To add a table, find a function you've already created (using the steps above) with Transaction Code SE37. Click the "Change" button, then click the "Tables" tab. Under "Parameter Name", make up a name for your table (eg, "GREETING"). In the "Typing" column put the word "LIKE", and in the "Associated Type" column, the name of the table you created (eg, "ZMYTAB"). Ctrl-S to save and Ctrl-F3 will activate the function. If you press F8 now you will see an entry under "Tables" called "GREETING". You can edit this table to send table data when calling the remote function, and when you add or edit RowData in the FunctionCall event it will show up in a result table of the same name.

Note that you can also use the fields in the Columns collection to modify the table. These fields will be populated when RowIndex is set, which will be set back to 0 whenever TableIndex is set.

SapServer Dependencies

In addition to the requirements detailed in Setting Up a Connection with a SAP System, the following services must be added to %WINDIR%\system32\drivers\etc\services, or /etc/services if your system is running Linux or Mac OS X. If SAP NetWeaver is already installed on the machine,then no further action is required.

Service Name Port Number/Protocol
sapdp00 3200/tcp
sapdp01 3201/tcp
sapdp02 3202/tcp
sapdp03 3203/tcp
sapdp04 3204/tcp
sapdp05 3205/tcp
sapdp06 3206/tcp
sapdp07 3207/tcp
sapdp08 3208/tcp
sapdp09 3209/tcp
sapdp10 3210/tcp
sapdp11 3211/tcp
sapdp12 3212/tcp
sapdp13 3213/tcp
sapdp14 3214/tcp
sapdp15 3215/tcp
sapdp16 3216/tcp
sapdp17 3217/tcp
sapdp18 3218/tcp
sapdp19 3219/tcp
sapdp20 3220/tcp
sapdp21 3221/tcp
sapdp22 3222/tcp
sapdp23 3223/tcp
sapdp24 3224/tcp
sapdp25 3225/tcp
sapdp26 3226/tcp
sapdp27 3227/tcp
sapdp28 3228/tcp
sapdp29 3229/tcp
sapdp30 3230/tcp
sapdp31 3231/tcp
sapdp32 3232/tcp
sapdp33 3233/tcp
sapdp34 3234/tcp
sapdp35 3235/tcp
sapdp36 3236/tcp
sapdp37 3237/tcp
sapdp38 3238/tcp
sapdp39 3239/tcp
sapdp40 3240/tcp
sapdp41 3241/tcp
sapdp42 3242/tcp
sapdp43 3243/tcp
sapdp44 3244/tcp
sapdp45 3245/tcp
sapdp46 3246/tcp
sapdp47 3247/tcp
sapdp48 3248/tcp
sapdp49 3249/tcp
sapdp50 3250/tcp
sapdp51 3251/tcp
sapdp52 3252/tcp
sapdp53 3253/tcp
sapdp54 3254/tcp
sapdp55 3255/tcp
sapdp56 3256/tcp
sapdp57 3257/tcp
sapdp58 3258/tcp
sapdp59 3259/tcp
sapdp60 3260/tcp
sapdp61 3261/tcp
sapdp62 3262/tcp
sapdp63 3263/tcp
sapdp64 3264/tcp
sapdp65 3265/tcp
sapdp66 3266/tcp
sapdp67 3267/tcp
sapdp68 3268/tcp
sapdp69 3269/tcp
sapdp70 3270/tcp
sapdp71 3271/tcp
sapdp72 3272/tcp
sapdp73 3273/tcp
sapdp74 3274/tcp
sapdp75 3275/tcp
sapdp76 3276/tcp
sapdp77 3277/tcp
sapdp78 3278/tcp
sapdp79 3279/tcp
sapdp80 3280/tcp
sapdp81 3281/tcp
sapdp82 3282/tcp
sapdp83 3283/tcp
sapdp84 3284/tcp
sapdp85 3285/tcp
sapdp86 3286/tcp
sapdp87 3287/tcp
sapdp88 3288/tcp
sapdp89 3289/tcp
sapdp90 3290/tcp
sapdp91 3291/tcp
sapdp92 3292/tcp
sapdp93 3293/tcp
sapdp94 3294/tcp
sapdp95 3295/tcp
sapdp96 3296/tcp
sapdp97 3297/tcp
sapdp98 3298/tcp
sapdp99 3299/tcp
sapgw00 3300/tcp
sapgw01 3301/tcp
sapgw02 3302/tcp
sapgw03 3303/tcp
sapgw04 3304/tcp
sapgw05 3305/tcp
sapgw06 3306/tcp
sapgw07 3307/tcp
sapgw08 3308/tcp
sapgw09 3309/tcp
sapgw10 3310/tcp
sapgw11 3311/tcp
sapgw12 3312/tcp
sapgw13 3313/tcp
sapgw14 3314/tcp
sapgw15 3315/tcp
sapgw16 3316/tcp
sapgw17 3317/tcp
sapgw18 3318/tcp
sapgw19 3319/tcp
sapgw20 3320/tcp
sapgw21 3321/tcp
sapgw22 3322/tcp
sapgw23 3323/tcp
sapgw24 3324/tcp
sapgw25 3325/tcp
sapgw26 3326/tcp
sapgw27 3327/tcp
sapgw28 3328/tcp
sapgw29 3329/tcp
sapgw30 3330/tcp
sapgw31 3331/tcp
sapgw32 3332/tcp
sapgw33 3333/tcp
sapgw34 3334/tcp
sapgw35 3335/tcp
sapgw36 3336/tcp
sapgw37 3337/tcp
sapgw38 3338/tcp
sapgw39 3339/tcp
sapgw40 3340/tcp
sapgw41 3341/tcp
sapgw42 3342/tcp
sapgw43 3343/tcp
sapgw44 3344/tcp
sapgw45 3345/tcp
sapgw46 3346/tcp
sapgw47 3347/tcp
sapgw48 3348/tcp
sapgw49 3349/tcp
sapgw50 3350/tcp
sapgw51 3351/tcp
sapgw52 3352/tcp
sapgw53 3353/tcp
sapgw54 3354/tcp
sapgw55 3355/tcp
sapgw56 3356/tcp
sapgw57 3357/tcp
sapgw58 3358/tcp
sapgw59 3359/tcp
sapgw60 3360/tcp
sapgw61 3361/tcp
sapgw62 3362/tcp
sapgw63 3363/tcp
sapgw64 3364/tcp
sapgw65 3365/tcp
sapgw66 3366/tcp
sapgw67 3367/tcp
sapgw68 3368/tcp
sapgw69 3369/tcp
sapgw70 3370/tcp
sapgw71 3371/tcp
sapgw72 3372/tcp
sapgw73 3373/tcp
sapgw74 3374/tcp
sapgw75 3375/tcp
sapgw76 3376/tcp
sapgw77 3377/tcp
sapgw78 3378/tcp
sapgw79 3379/tcp
sapgw80 3380/tcp
sapgw81 3381/tcp
sapgw82 3382/tcp
sapgw83 3383/tcp
sapgw84 3384/tcp
sapgw85 3385/tcp
sapgw86 3386/tcp
sapgw87 3387/tcp
sapgw88 3388/tcp
sapgw89 3389/tcp
sapgw90 3390/tcp
sapgw91 3391/tcp
sapgw92 3392/tcp
sapgw93 3393/tcp
sapgw94 3394/tcp
sapgw95 3395/tcp
sapgw96 3396/tcp
sapgw97 3397/tcp
sapgw98 3398/tcp
sapgw99 3399/tcp

 
 
Copyright (c) 2017 /n software inc. - All rights reserved.
Build 2.0.6240.0