3.2 Working with a Web application that calls an RPG program

 < Day Day Up > 

3.2 Working with a Web application that calls an RPG program

This section covers how to implement a Web application which calls the RPG program on OS/400.

3.2.1 Scenario overview: The Loan Service application

The Loan Service is a simple representation of a credit application system. A customer can apply for a loan or a line of credit, and the application either accepts or rejects the loan or line of credit based on the salary of the applicant and past loans. The maximum total loan amount for any one applicant is 10 percent of their annual salary. If a line of credit is established, future loan applications can be automatically approved.

You can execute the same application from an OS/400 command line since ITSOWS library includes the legacy application using the DDS file and the RPG program. Use the following commands:


The application displays the interface shown in Figure 3-56.

click to expand
Figure 3-56: Loan Application Entry display

The structure of the Loan Service application

The Loan Service application is a Java application that calls the RPG program on OS/400.

There are a couple of different ways you can call an RPG program from Java. You can use a simple JNI native call, or Program Call Markup Language (PCML) through the IBM Toolbox for Java. This Loan Service application uses PCML. PCML is the simplest way to create a Java Bean that interfaces directly with a native iSeries program.

The loan application consists of the following OS/400 objects:

  • APPL01 is the RPG program that provides the business logic.

  • APPLPF is the file that stores the customer names.

The loan application processes work in the following steps (see Figure 3-57):

  1. The client calls the Java application on the WebSphere Application Server on Linux with the browser.

  2. The Java Beans call the RPG program (APPL01) on the OS/400 with the web.xml file and the PCML file. The web.xml file has information such as the host name of an OS/400, a user ID, and a password, which are used to log onto the OS/400 as shown in Figure 3-58 on page 128. The PCML file has information about the RPG program such as the program name and library name on which the RPG program exists, as shown in Figure 3-59 on page 131.

    click to expand
    Figure 3-57: Structure of the Loan Service application

    start figure

     <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE web-app PUBLIC "-//Sun Microsystems,Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web -app_2_3.dtd">    <web-app >       <display-name>CallRPGweb</display-name>       <context-param >          <param-name>WDT_HOSTNAME</param-name>          <param-value>as05</param-value>          <description>iSeries ProgramCall host name</description>       </context-param>       <context-param >          <param-name>WDT_USERID</param-name>          <param-value>user1</param-value>          <description>iSeries ProgramCall user id</description>       </context-param>       <context-param >          <param-name>WDT_PASSWORD</param-name>          <param-value>password</param-value>          <description>iSeries ProgramCall user password</description>       </context-param>       <context-param >          <param-name>WDT_RUNTIMELIB</param-name>          <param-value>ITSOWS</param-value>          <description>iSeries ProgramCall runtime library list</description>       </context-param>       <context-param >          <param-name>WDT_FLGERRORDETAILS</param-name>          <param-value>false</param-value>          <description>To enable the iSeries Webtooling detailed runtime trace.</description>       </context-param>       <context-param >          <param-name>WDT_USEPGMCALLJCA</param-name>          <param-value>false</param-value>          <description>Use program call JCA connector</description>       </context-param> : : : 

    end figure

    Figure 3-58: Structure of web.xml file

    start figure

     <pcml version="4.0">     <program name="LoanServiceBean" path="/QSYS.LIB/ITSOWS.LIB/APPL01.PGM" threadsafe="false">         <data bidistringtype="DEFAULT" chartype="onebyte" length="40"             name="name" trim="none" type="char" usage="input"/>         <data length="15" name="income" precision="2" type="packed" usage="input"/>         <data length="15" name="amount" precision="2" type="packed" usage="input"/>         <data bidistringtype="DEFAULT" chartype="onebyte" length="1"             name="signed" trim="none" type="char" usage="input"/>         <data bidistringtype="DEFAULT" chartype="onebyte" length="1"             name="result" trim="none" type="char" usage="output"/>     </program> </pcml> 

    end figure

    Figure 3-59: CallRPGweb.pcml

  3. APPL01 execute the business logic, and returns a result, as shown in Figure 3-60 on page 132.

    start figure

      FAPPLPF   UF A E         K DISK     I*     C* Definition of parameters     C    *ENTRY       Plist     C* Applicant Name     C               Parm                 Name           40   C* Annual Income (Dollars). If zero, use existing data (Line of Credit)     C               Parm                 Income         15 2     C* Requested Loan Amount     C               Parm                 Amount         15 2     C* Loan is signed for     C               Parm                 Signed          1    C* Application Result ('A'=Approved ,'R'=Rejected)     C               Parm                 Result          1     C *Check for previous loans     C               Z-add    *ZERO        Loans     C    Name        Chain    APPL1                         50    C* If income isn't stated,check if customer has line of credit     C               if      *IN50 = *OFF and Income = 0     C                Eval    Income = Salary     C                 Endif     C* Calculate Loan Limit     C    Income      Mult    0.1         Limit          11 2    C* If previous loans exist, subtract from limit     C              Sub      Loans       Limit     C              If       Amount > Limit    C* If loan amount greater than limit, reject     C              Eval     Result = 'R'     C               Else    C* If loan amount less equal limit, accept and add to loan     C               If       Signed = 'Y'     C               Add      Amount       Loans     C                Endif     C               Eval     Salary = Income     C               Eval     Result = 'A'     C   *IN50       IfEQ      *OFF    C* Update existing loan     C              Update   APPL1     C              Else     C* Create new loan     C               Write    APPL1     C               EndIf     C               EndIf    C* Return to caller, but stay in memory      C                    Return 

    end figure

    Figure 3-60: RPG program— /QSYS.LIB/ITSDOWS.LIB/APPL01.PGM

  4. The Java Beans get the result from APPL01, work with it, and present results to the browser, as shown in Figure 3-66 on page 138.

Connecting to an iSeries server

The application uses the web.xml file to connect to an iSeries server. This web.xml file (Figure 3-58) includes a host name of iSeries, user ID, and password. Change these fields to the correct values for your installation after deploying the application. We used the following values:

  • Host name: as05

  • User ID: user1

  • Password: password

Calling an RPG program

The Java program shown in Example 3-1 executes the following logic:

  • Get the client information from the browser, and call the RPG program with that information as the parameter.

  • Get the parameter from the RPG program.

  • Work with the parameter which comes from the RPG program, and present the result to the browser.

Example 3-1: LoanServiceAction.java

start example
 /** *Description - Use PCML to call iSeries ILE program */ import java.math.*; import java.util.*; import javax.servlet.http.*; import org.apache.struts.action.*; import com.ibm.iseries.webint.*; public class LoanServiceAction extends ISeriesAction {    public LoanServiceAction() {       super();       setProgramName("LoanServiceBean");       setPcmlName("CallRPGweb");       setInvalidateSession(false);       setOutputPage("LoanServiceResults");    }    public ActionForward perform(       ActionMapping mapping,       ActionForm form,       HttpServletRequest request,       HttpServletResponse response) {       try {          preprocessing(request, response, form);          HttpSession session = request.getSession();          LoanServiceInputForm inputForm = (LoanServiceInputForm) form;          String[] strName = (String[]) inputForm.getValues("name");          String[] strIncome = (String[]) inputForm.getValues("income");          String[] strAmount = (String[]) inputForm.getValues("amount");          String[] strSigned = (String[]) inputForm.getValues("signed");          ProgramRecord_LoanServiceBean dataBean =             new ProgramRecord_LoanServiceBean();          dataBean.setName("");          if ((strName != null)             && (strName.length > 0)             && (strName[0] != null)             && (strName[0].length() > 0)) {             dataBean.setName(strName[0]); }                   dataBean.setIncome(new BigDecimal("0"));          if ((strIncome != null)             && (strIncome.length > 0)             && (strIncome[0] != null)             && (strIncome[0].length() > 0)) {             dataBean.setIncome(                new BigDecimal(                   stripNonNumeric(strIncome[0].trim(), 15, 2)));          }          dataBean.setAmount(new BigDecimal("0"));          if ((strAmount != null)             && (strAmount.length > 0)             && (strAmount[0] != null)             && (strAmount[0].length() > 0)) {             dataBean.setAmount(                new BigDecimal(                   stripNonNumeric(strAmount[0].trim(), 15, 2)));          }          dataBean.setSigned("");          if ((strSigned != null)             && (strSigned.length > 0)             && (strSigned[0] != null)             && (strSigned[0].length() > 0)) {             dataBean.setSigned(strSigned[0]);          }          processDebugging(request, form);          LoanServiceOutputForm resultsForm = new LoanServiceOutputForm();          invokeHostProgram(request, dataBean, form, resultsForm);          String[] strOut = null;          strOut = new String[1];          strOut[0] = dataBean.getResult().toString();          // Check the response and send a meaningfull message to the output          // form          if (strOut[0].compareTo("A") == 0) {             strOut[0] = "Your loan has been approved.";          } else {             strOut[0] =                "Your loan application has been rejected.\nPlease, contact our customer support center.";          }          resultsForm.setValues("result", strOut);          postprocessing(request, form, resultsForm);          return getForward(mapping, session);       } catch (Exception ex) {          handleError(request, response, ex);          return mapping.findForward("wdt_error");       }    } } 
end example

In this program, you can see "setPcmName("CallRPGweb")". The pcm file, CallRPGweb, is called here. The pcm file has the information about the RPG program, such as the library name and the program name, as shown in Figure 3-59.

The file shown in Figure 3-59 is the pcml file. This file is used by the LoanServiceAction program (shown in Example 3-1) to call the RPG program. You can see the path of the OS/400 program on the pcml file, /QSYS.LIB/ITSOWS.LIB/APPL01.PGM.

The file shown in Figure 3-60 is the RPG program (APPL01) which is called by the LoanServiceAction program. This program works with some parameters provided by the Java application, and it returns the result to the Java program.

3.2.2 Deploying the Loan Service application

In this section, we describe how to install the Loan Service application in your WebSphere Application Server.

To install the Loan Service application:

  1. Prepare your Web Archive (WAR) file for the local PC or the server. We prepared it on the local PC.

  2. To open the Application Server Administrative Console, start your Web browser and enter the following URL:


  3. In the Administrative Console Login window, enter a user ID and click OK.

  4. Select Application Install New Application in the navigation pane on the left.

  5. In the Preparing for the application installation window, browse to the specific folder which has the application and select the WAR file you want to install.

  6. Enter the Context Root, as illustrated in Figure 3-61. In our case, the Context Root is CallRPGweb . Click Next.

    click to expand
    Figure 3-61: Preparing for the application installation— Path and Context Root

  7. Specify a virtual host. In our example, illustrated in Figure 3-62, we selected "Default virtual host name for web modules," and specified default_host.

    click to expand
    Figure 3-62: Preparing for the application installation— Virtual host

    Click Next to continue installing the application.

  8. In the Install New Application window, specify the directory in which to install the application. As shown in Figure 3-63, we specified installedApps.

    click to expand
    Figure 3-63: Install New Application AppDeployment Options

  9. Click Next to accept the defaults for Step 2: Map virtual hosts for Web modules.

  10. Click Next to accept the defaults for Step 3: Map modules to application servers. If you have more than one server, select the server you want to work with that application.

  11. In Step 4: Summary, review your selections and click Finish to deploy the application.

  12. Click Save after successfully installing the application.

  13. Edit the web.xml file to access your iSeries system.

    1. Use the following commands to open the web.xml file:

       cd /opt/WebSphere/AppServer/installedApps/CallRPGweb_war.ear/ CallRPGweb.war/WEB-INF vi web.xml 

    2. Edit the following parameters in the web.xml file, as shown in Figure 3-58 on page 128:

      • Host name: enter the host name of your system.

      • User ID: enter the user ID that exists on your system.

      • Password: enter the password.

  14. By default, the newly installed applications are not started. To start the application, select Applications Enterprise Applications, and check CallRPGweb in the application list (Figure 3-64). Click Start to run the application.

    click to expand
    Figure 3-64: Start Enterprise Application

  15. Select Environment Update Web Server Plugin in the navigation tree, then click OK to update the Web server.

  16. Using a Web browser, enter the URL for the application:


Enter the Name, Income, Loan Amount, and Signed, as shown in Figure 3-65, and click Submit. The window shown in Figure 3-66 is returned.

click to expand
Figure 3-65: Loan Service Input Form

click to expand
Figure 3-66: Loan Service Result Form

USER1 is approved because the total loan amount (in this case, 400.00) is not over 10% of USER1's annual salary (4000.00).

USER1 is added on the APPLPF file because USER1 previously didn't exist in this file, and USER1 has a 400.00 Loan because 'Y' is set on the Signed parameter (Figure 3-67 on page 138).

start figure

 Display Report                                               Report width . . . . . : 86  Position to line  . . . . .            Shift to column  . . . . . .  Line ....+....1....+....2....+....3....+....4....+....5....+....6....+....7..         NAME                                                  LOANS  000001 Bjarne                                                  .00  000002 Scott                                              2,000.00  000003 SCOTT                                                   .00  000004 Mike                                                    .00  000005 Emily                                                   .00  000006 Doug                                                    .00  000007 USER1                                                400.00 

end figure

Figure 3-67: USER1 on APPLPF.file

You can see the results of the operation in the APPLPF.file under the OS/400 environment, as shown in Figure 3-67.

 < Day Day Up > 

Websphere for Linux on Iseries. Implementation Guide
Websphere for Linux on Iseries: Implementation Guide
ISBN: 0738498955
EAN: 2147483647
Year: 2003
Pages: 56
Authors: IBM Redbooks

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net