Using EntireX RPC for RPG under IBM i

This document describes how to build a server application using the IBM i ILE language RPG. The server will be named CALC_RPG. Its functionality and implementation is based on the ILE COBOL server CALC as described in the document Using the COBOL Wrapper.

The function CALC_RPG is a calculator that can add, subtract, multiply and divide two binary values PIC S9(8) BINARY and return a result.

This document covers the following topics:

The EntireX RPC Server for IBM i of EntireX version 7.1.1 running under IBM i (AS/400) is no longer supported. We strongly recommend using the new RPC Server for AS/400 or the EntireX Adapter. See also Connection Parameters for AS/400 Connections.


Creating the Client/Server Interface

The PLIST in the RPG program is a good source of type information for the interface when you create the Software AG IDL file:

...
 D OPERATOR        S              1A
 D OPERAND_1       S             10I 0
 D OPERAND_2       S             10I 0
 D FCT_RESULT      S             10I 0
  *
 C     *ENTRY        PLIST
 C                   PARM                    OPERATOR
 C                   PARM                    OPERAND_1
 C                   PARM                    OPERAND_2
 C                   PARM                    FCT_RESULT
....

The assumption is made that the program is implemented in library EXAMPLE. Convert the linkage section function above to Software AG IDL syntax as follows:

Library 'EXAMPLE' Is
 Program 'CALC_RPG' Is
  Define Data Parameter
   1 Operator         (A1) In
   1 Operand_1        (I4) In
   1 Operand_2        (I4) In
   1 Function_Result  (I4) Out
  End-Define

Note:
A 10-digit RPG integer takes 4 bytes, so it must be mapped to an (I4) IDL field definition.

For details on how IDL field definitions are mapped to RPG elementary field items, see divname_rpc_rpg_map.

Creating a Sample Server in RPG

The server is implemented as an ILE RPG program of type *PGM.

For our IDL example CALC, the implemented server looks similar to the example below.

  *--------------------------------------------------
  * Member          CALC_RPG
  * Description     Calculation Engine.
  *
  * Author          (c) Software AG
  * Platform        OS/400
  *
  * UUU YYYY-MM-DD  History
  * HBA 2003-05-20  Created
  *
  *--------------- CALC Interface ------------------------------
 D OPERATOR        S              1A
 D OPERAND_1       S             10I 0
 D OPERAND_2       S             10I 0
 D FCT_RESULT      S             10I 0
  *-------------------------------------------------------------
 C     *ENTRY        PLIST
 C                   PARM                    OPERATOR
 C                   PARM                    OPERAND_1
 C                   PARM                    OPERAND_2
 C                   PARM                    FCT_RESULT
 C                   CLEAR                   FCT_RESULT
  *
 C                   SELECT
 C                   WHEN      OPERATOR = '+'
 C                   EVAL      FCT_RESULT = OPERAND_1 + OPERAND_2
 C                   WHEN      OPERATOR = '-'
 C                   EVAL      FCT_RESULT = OPERAND_1 - OPERAND_2
 C                   WHEN      OPERATOR = '*'
 C                   EVAL      FCT_RESULT = OPERAND_1 * OPERAND_2
 C                   WHEN      OPERATOR = '/'
 C                   IF        OPERAND_2 <> *ZERO
 C                   EVAL      FCT_RESULT = OPERAND_1 / OPERAND_2
 C                   ENDIF
 C                   ENDSL
  *
 C     PGM_EX        TAG
 C                   MOVE      *ON           *INLR

Compiling and Linking the Server

Compile the server source using the IBM i command CRTRPGMOD (create bound RPG module) and bind it as a dynamically callable program of type *PGM using the command CRTPGM. Make sure your server fulfills all requirements to be callable by the IBM i host server.

As an alternative to the commands CRTRPGMOD and CRTPGM, you can use the command CRTBNDRPG to compile and bind RPG sources in one step.

Name the resulting server program like the program name in the IDL file and put it in a library whose name corresponds to the library name in the IDL file.

Example

If a client performs an RPC which is based on the IDL program CALC_RPG in the IDL library EXAMPLE, the RPC Server for AS/400 or the EntireX Adapter (see Connection Parameters for AS/400 Connections) will dynamically try to execute the ILE program CALC_RPG in the IBM i library EXAMPLE. If no corresponding program can be found, the access fails.

Verifying the Server

To verify the server program CALC_RPG, use the EntireX IDL Tester when the RPC Server for AS/400 and EntireX Broker are used.

Start of instruction setTo verify the server

  1. Confirm that an EntireX Broker and an RPC Server for AS/400 are available in your network.

  2. Make sure the IBM i host is started on your IBM i machine.

  3. Create a Software AG IDL File using the IDL Editor as described under Creating the Client/Server Interface.

  4. Start the IDL Tester using the IDL file created in step 3.

Note:
When using the EntireX Adapter, use the Service Development perspective of the Software AG Designer for testing.