The purpose of this example is to make sure that your systems and software are correctly configured. The code checks the compiler, client software, middleware, server software, and the connection between the server and the R/3 system itself. The program simply sends a ping down to the R/3 system and responds with a message indicating whether the program was successful in connecting to the system. The example contains no graphics, and it skips several error messages and cleanup routines, in order to keep it as simple as possible. A fully functioning version of this program is provided in the 'Connecting to the SAP System' section in Chapter 11, 'Integrating Java with SAP through RFCs and BAPIs.'
The first step in this example is to get an SAP login and to log in to the SAP system via the SAP GUI (Graphical User Interface). After you get your login from your system administrator and have successfully logged in to the SAP system, you will need to get the properties for the GUI, as shown in Figure 5.1 and Figure 5.2. You will need the following:
Login ID
Password
SAP system URL
System number
Client number
Login language
Figure 5.1: Getting the properties of the SAP GUI login
Figure 5.2: The Properties page of the SAP GUI
This step involves the creation of a Java class named JavaPing, as well as a run-time version of this class. When you create the new project in the Microsoft Java Compiler, you should choose Console Application, as shown in Figure 5.3.
After the project has been created, you must rename the default name (Class1) JavaPing. To do so, right click on the Class1 object (on the right side of the screen) and then select Rename. This step is shown in Figure 5.4.
Figure 5.3: Creation of the project JavaPing
Figure 5.4: Renaming the default class to JavaPing
The Java code for this class follows.
// JavaPing, test the connection to a SAP instance and report // back the status. This is similar to the SAP samples example // RFCPING but is simpler. import com.sap.rfc.*; import com.sap.rfc.exception.*; import java.io.*; public class JavaPing { public static void main (String[] args) { // Simple declaration of variables String rfcHost = "testsystem", // Java RFC Host r3Host = "test.system.com", // SAP System Name r3SysNo = "00", // System Number client = "001", // SAP Client Number user = "kenkroes", // Your User Name password = "scoobydoo", // Your Password language = "EN"; // Your Login Language FactoryManager facMan = null; IRfcConnection connection = null; // Establish the connection to the Orbix Middleware MiddlewareInfo mdInfo = new MiddlewareInfo(); mdInfo.setMiddlewareType(MiddlewareInfo.middlewareTypeOrbix); mdInfo.setOrbServerName(rfcHost); // let the global factory manager use the middlewareInfo // to create all object factories by binding to the server facMan = FactoryManager.getSingleInstance(); facMan.setMiddlewareInfo(mdInfo); // Define The User information UserInfo userInfo = new UserInfo(); ConnectInfo connectInfo = new ConnectInfo(); userInfo.setClient(client); userInfo.setUserName(user); userInfo.setPassword(password); userInfo.setLanguage(language); // Set up the Connection connectInfo.setRfcMode(ConnectInfo.RFC_MODE_VERSION_3); connectInfo.setDestination("xxx"); connectInfo.setHostName(r3Host); connectInfo.setSystemNo((short)Integer.parseInt(r3SysNo)); connectInfo.setLoadBalancing(false); connectInfo.setCheckAuthorization(true); // Try to establish the connection try { connection = facMan.getRfcConnectionFactory() .createRfcConnection(connectInfo, userInfo); connection.open(); } catch (JRfcRfcConnectionException re) { System.out.println("Unexpected RfcError while opening connection.\n" + re.toString()); return; } catch (JRfcBaseRuntimeException je) { System.out.println("Unexpected JRFC runtime exception:\n" + " while opening connection.\n" + je.toString()); return; } System.out.println("Congratulations, Connection Established !"); } }
Figure 5.5 shows the Microsoft Java Compiler with the JavaPing class. After you enter the code, select Build from the pull-down example. Any errors will be shown in the bottom window. To get more details about the errors, place the cursor on the error message and then press the F1 key. Any errors you get probably will be due to a typographical error resulting in a Java syntax error. In addition to an explanation of the error, the error message will also indicate the line number that is close to the error (sometimes an error on one line may be due to an error on the lines above or below). Once the program is compiled successfully, you will be able to see the JavaPing executable program in Windows Explorer, as shown in Figure 5.6.
Figure 5.5: The JavaPing example
Figure 5.6: Windows Explorer view of the Project directory showing the JavaPing executable program
This step assumes that you are installing the server software without having the Orbix Daemon set up to start automatically as a Windows NT service. If the daemon starts up automatically on your system, or if the Java RFC (Remote Function Call) is already configured at your installation, you can skip this step.
To start the Orbix Daemon, simply go to the Windows Start menu and select Start Orbix Daemon, as shown in Figure 5.7. You can also select Server Manager at this time. If the Server Manager does not appear as shown in Figure 5.7, turn back to Chapter 4, 'Setting up the Development and Operating Environments,' and review the setup procedure for the Java RFC server.
Figure 5.7: Starting the Orbix Daemon and Server Manager
During this final step, you'll execute your newly created code by double-clicking on the JavaPing executable program. If all goes well, your screen should look like that in Figure 5.8.
You will also notice that the daemon has started another DOS window that displays the trace of the connection to the JAVA RFC server. You can control the level of trace through the Orbix Daemon window from the Daemon menu of the Daemon window, as shown in Figure 5.9
That does it for our first example. Although it required quite a few steps, if you have this example working, the rest of the examples should work well and should be easy to do. We've attempted to make this example simple enough for you to correct any problems you might have with it.
Note | Three samples come with the Java RFC you installed on your system. One of these examples is called RFCPING and is located by default in the following path: |
Figure 5.8: Execution of the JavaPing executable
Figure 5.9: Setting the level of trace for the Orbix Daemon
Team-Fly |