Skip to main content

By clicking Submit, you agree to the developerWorks terms of use.

The first time you sign into developerWorks, a profile is created for you. Select information in your profile (name, country/region, and company) is displayed to the public and will accompany any content you post. You may update your IBM account at any time.

All information submitted is secure.

  • Close [x]

The first time you sign in to developerWorks, a profile is created for you, so you need to choose a display name. Your display name accompanies the content you post on developerworks.

Please choose a display name between 3-31 characters. Your display name must be unique in the developerWorks community and should not be your email address for privacy reasons.

By clicking Submit, you agree to the developerWorks terms of use.

All information submitted is secure.

  • Close [x]

developerWorks Community:

  • Close [x]

Calling IBM i programs from EGL using Rational Business Developer

Claus Weiss, Advisory Software Consultant, IBM
Claus Weiss is an advisory software consultant with the Rational Software System i – Ecosystem team at the IBM Canada Toronto Laboratory. He has degrees in industrial engineering and computer science from the University of Hamburg in Germany. He worked as a systems engineer with IBM Germany and joined the IBM Toronto Laboratory in 1984. He was a developer and team leader for System/38 development tools. He has been a member of the Design Control Group for the AS/400 development tools. He has worked as a consultant for IBM iSeries Application Development for the past 10 years, specializing in Visual Tools. Claus is a frequent speaker at COMMON and other iSeries conferences and a six-time winner of COMMON's Speaker Excellence award. He is also the lead author of the book title "Understanding the IBM WebFacing Tool," published by IBM Press, and has co-authored several IBM Redbooks.

Summary:  This tutorial describes how to write Enterprise Generation Language (EGL) code that calls programs (RPG, COBOL, CL, CL Commands, or programs written in any supported language) on your IBM® System i5™ machine. The process for you to call an existing IBM i™ program from EGL has been very much improved in IBM® Rational® Developer for System i™ V7.1 (and later), and is incredibly simple. EGL leverages the IBM i Toolbox for Java™, which in turn utilizes the System i5’s Remote Command Host Server (QZRCSRVSD in the QSYSWRK subsystem).

Date:  19 Aug 2008
Level:  Intermediate PDF:  A4 and Letter (3472 KB | 44 pages)Get Adobe® Reader®

Activity:  290 views

Create and configure the Web page

Now it is time to create the Web UI.

Creating a web page to provide a user interface for the application

It provides the input and output fields for the data that is sent to the RPG program and received from the program. It also provides a button to invoke the EGL function that calls the GETDATAE RPG program.

  1. Right-click the WebContent directory and select New > Web page, as shown in Figure 26.

Figure 26. Create a new Web page
pop-up menu

In the New Web Page dialog shown in Figure 27:

  1. Type a name for your Java™Server Pages (JSP) file. In this example, the File Name is CALLEGL001R.jsp.
  2. Click Finish.

Figure 27. Select a name, location, and template
template on left, preview on right
  1. The Page designer opens. Perform the following steps, as shown in Figure 28.
    1. Make sure that the Design view is active (the tab at the bottom of the designer).
    2. Type Customer inquiry in the white space in the page designer,
    3. Click the text that you just wrote to select it.
    4. Click the Properties tab at the bottom of the screen.
    5. Adjust the appearance of Heading 2.
    6. Save by clicking Ctrl+S.

Figure 28. The Page designer
Properties tab at the bottom of the view

Now you write some EGL code in the page handler file, as shown in Figure 29.

  1. Right-click anywhere in the white space on the Web page and Select Edit Page Code.

Figure 29. Write EGL code
pop-up menu

Create EGL Code to call the RPG program

The EGL Pagehandler appears. The pagehandler is a type of EGL program that controls interaction with a JSF Web page.

Since your RPG program contains three parameters, you must define some variables to hold the data when interacting with the program.

You will insert these variables immediately following the:
viewRoot UIViewRoot:

record declaration.

Note: The UIViewRoot is an EGL special record variable that provides access to the various parts of the Web page.

  1. Figure 30 illustrates what your code should look like after you have declared the three variables.

You are using the following variables

  • cinput for the customer number that gets passed to the RPG program. It is of type CUSTNO (which you got from the customl3 record format).
  • Feedback is a 20-character variable.
  • cds is a structure of type Customl3, (the basicrecord that you created previously).

Tip: Make use of content assist (Ctrl+Spacebar) to find the correct datatypes, as shown in Figure 30.

Figure 30. Using content assist
selection options presented in context

Figure 31 shows your variables (cinput, feedback, and cds).

Figure 31. Variables
code list showing variables and types

Now you need to create a simple EGL function with a couple of statements to call your RPG program.

  1. Write the function as shown in Listing 2.

Here is a bit more information on the code that you see in the pagehandler program:

Figure 32 illustrates the completed pagehandler code required to call the RPG Program GETDATAE. As you can see, the code is very intuitive and simple.

Listing 2. Completed code
function callRPG()
	syslib.writeStdout("before call");
	syslib.setRemoteUser("egl4rpg", "egl4you");
	call "GETDATAE" (cinput, cds, feedback);
	syslib.writeStdout("after call");

Figure 32. Completed code
code shown in Listing 2

In this program, as in all EGL JSF Web programs, there are two functions automatically added when a new JSFhandler program gets created:

  • onConstruction
  • onPrerender.

These functions are invoked when the page is loaded. You will not use these functions in this program, because you have no upfront processing to do when loading your Web page. Therefore, leave these functions empty.

In the UI, after a user enters data into the input field cinput, you will add a button that allows the user to invoke the callRPG function.

In callRPG you added two statements that write to Stdout to show in the IBM® WebSphere® Application Server console that the call is initiated, and that it has been finished. These statements are just there for informational purposes and can be removed in real code.

Note: In callRPG you use the syslib.RemoteUser(“userid”, “password”) built-in EGL function to set constants for the User ID and Password for the logged in user. You would normally write a routine that stores user information in a session or other persistent area of storage, instead of using constants in your code. This routine is simplified for illustration purposes.

Note that the Java Toolbox used to access your System i5 requires that you authenticate prior to every call to IBM I, ensuring security and integrity of the system.

Finally, you have a simple call statement:

	call “GETDATAE”  (cinput, cds, feedback);

In this statement, you specify the program name that you had previously defined in the EGL build file’s Linkage options, as well as the parameters to pass.

You can now create the Web form to capture input from the user, call the RPG program, and display the result.

Create fields and a button on the Web page

  1. Click the Page Data tab in the lower left corner of the workbench to select it, as shown in Figure 33.
    1. Expand JSFHandler
    2. Expand Data
    3. Expand Actions

Figure 33. Page Data tab
tree view on left, design view on right

Under the Data node, you can see the three variables that you created in the pagehandler.

Under the Actions node, you can see the callRPG function that you created.

  1. Select the cinput variable, as shown in Figure 34.
  2. Drag it on to the Web design area below the page title.

Figure 34. Drag the variable to the design area
drag from lower left to upper right

A dialog displays, indicating that you are about to create a new control on the page, as shown in Figure 35.

  1. Be sure that the Updating an existing record radio button is selected. This will default the Control Type to Input field.
  2. Click the label area and change the label to Enter customer number:
  3. Click the Options button.

Figure 35. Insert Control dialog
Configure data controls and fields
  1. Clear both the Submitbutton and Deletebutton check boxes, as shown in Figure 36. You will create a call button in the next step.
  2. Click OK.
  3. Click Finish on the main dialog.

Figure 36. Do not create buttons
Buttons, Labels, and Advanced tabs

Now, you will add the button to invoke the callRPG function.

  1. Make some space beneath the input field: position the cursor before the error message control, and then press Enter a couple of times.

To create a button that, when a user clicks it, invokes your callRPG function, in the data view:

  1. Select the callRPG function in the Page Data view.
  2. Drag it below the input field in the page designer, as shown in Figure 37.

Figure 37. Create a button to invoke the callRPG function
drag from lower left to upper right

Now a button gets created on the Web page. This button is bound to the function in the page handler. One last step, and you are ready to run your application.

  1. Drag the variable cds from the Page Data view to the Web page below the button, as shown in Figure 38.

Figure 38. Drag cds to the Web page
drag from lower left to middle right

The Configure Data Controls dialog appears, as shown in Figure 39.

  1. Select the Displaying an existing record (read only) radio button.

This changes the control type for all fields to output.

  1. Click Finish.

Figure 39. Configure Data Controls dialog
list of fields to display

Figure 40 shows the completed Web page.

  1. Save your page (Ctrl+S).
  2. Right-click the page and select Run on server.

Figure 40. Completed Web page
input, button, errors, and fields in design view

If a dialog comes up to select an application server, perform these steps:

  1. Select WebSphere Application Server v6.1.
  2. Select the Set server as project default check box.
  3. Click Finish.

You should see your Web page in the default browser, as shown in Figure 41.

Figure 41. Web page in browser
same fields in preview view
  1. Now, enter a valid customer number (for example, 0010100) as shown in Figure 42.
  2. Click callRPG.

Figure 42. Enter a valid customer number
Customer details on Web page

The data should appear on the page.

6 of 9 | Previous | Next


Zone=Rational, Sample IT projects
TutorialTitle=Calling IBM i programs from EGL using Rational Business Developer