Notice: This Wiki is now read only and edits are no longer possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.
EDT:Support for IBM i
< Resource Binding Introduction
Contents
Introduction
As an EGL developer, you can access IBM i called programs, as well as procedures in IBM service programs.
Access to any of those host programs is by way of the JTOpen toolkit, which determines what program types are supported. For an overview of the toolkit, see the following web site: (JTOpen).
Your coding task has the following aspects:
- You write an EGL proxy function for IBM i. The proxy function might be in any of the following types that is generated to Java code: an EGL Library, Service, Handler, or Program. The function has no logic, and any logic you place there will be ignored. Instead, you write one or more annotations there to tell the EGL Java generator how to structure the runtime call.
The main annotation is IBMiProgram. In most cases, that annotation references a resource binding in the EGL deployment descriptor. One runtime effect of referencing a resource binding is that you gain the performance benefits of using a connection from the AS400 connection pool.
- When you write the EGL code that calls the function, you might access the proxy function and rely on the details provided there. Alternatively, Two variations apply:
- If you access the function remotely, you cannot override that annotation. At this time, remote access is possible only from a Rich UI application.
- If you access the function locally in generated Java code, you might code a variable that references a different resource binding or that specifies new detail; and then refer to that variable in the using clause of the call statement.
- When you include a using clause, the coded detail overrides any IBMiProgram annotation reference to the EGL deployment descriptor. If the using clause references a different deployment-descriptor entry, you still gain the performance benefits of using a pooled connection. However, the using clause might represent a connection that you define in your code; and in that case, you typically do not use a pooled connection, but rely on the AS400 connection object that is available in the JTOpen toolkit.
- The parameters of the EGL proxy function represent the parameters of the host program, and your call can pass simple data, as well as records and handlers. If a value is returned from the proxy function, the type of value is an EGL Int. (On IBM i, a return value is possible from a service program but not from a called program.)
In general, a Rich UI application uses an asynchronous version of the call statement to get enterprise data from a service. In relation to an IBM i program, the application calls a public proxy function that is defined in an EGL Service type.
Runtime process
At run time, the proxy function is an endpoint for accessing an IBM i program. That function acts as follows:
- Retrieves a connection for the AS400 connection pool, if you are using that kind of connection.
- Converts your data from an EGL format to byte arrays. The structure of those arrays is based on a set of AS400DataType classes that are provided by the JTOpen toolkit.
- Creates a JTOpen ProgramCall or ServiceProgramCall object, depending on whether the call is to an IBM i called program or service program.
- Creates JTOpen ProgramParameter objects and passes the byte arrays to them.
- Calls the host program by calling the run method on the ProgramCall or ServiceProgramCall object.
- Reformats the returned value (if any) to EGL format.
- Converts the returned byte arrays to EGL format. The structure of those arrays is based on a set of AS400DataType classes that are provided by the JTOpen toolkit.
- Returns the connection to the AS400 connection pool, if you are using that kind of connection.
Development process
The objects expected by the host are based on fixed-size types, whereas many EGL types are variably sized. You handle the difference by annotating the variably sized objects.
The annotations you specify are in the eglx.jtopen.annotations package, with annotation type names that of the form AS400xxxx. The annotation type names correspond to the JTOpen com.ibm.as400.access.AS400Datatype class names.
To determine which annotations to specify, refer to the table shown later, along with the Javadoc for the com.ibm.as400.access.AS400Datatype classes.
EGL proxy functions for IBM i
Here is an example of an EGL proxy function, including the annotations named ExternalName and IBMiProgram:
function GETRECA(CUST CUST[] inout, EOF string inout, COUNT decimal (2,0) inout) { @ExternalName{value="MyHostProc"} @IBMiProgram { programName = "GETREC", libraryName = "/QSYS.LIB/VARLABXX.LIB/" isServiceProgram=true, parameterAnnotations = [ @AS400Array{elementCount = 10}, @AS400Text{length = 1}, null ], connectionResourceBindingURI = @Resource{uri = "binding:file:EGLDDFile#MyConnection"} } } end
The ExternalName annotation is optional. It holds the name of the IBM i procedure and defaults to the name of the EGL proxy function.
The IBMiProgram is the primary annotation that structures the call. The annotation holds the following detail:
- The path of the library and program on IBM i.
You can specify both details on the programName field; in the current example, the field value would be "/QSYS.LIB/VARLABXX.LIB/GETREC". In any case, the EGL runtime code appends a file extension to the value of the programName field: .SRVPGM for service programs, .PGM for called programs.
- A flag as to whether a service program is being invoked.
- Annotations for each parameter, as described later.
- A reference to a binding that is defined in the EGL deployment descriptor. Your call to the EGL proxy function can refer to a different binding in the deployment descriptor, and that reference in the call statement overrides any connection detail that is specified in the function.
The EGL runtime code uses the binding details to construct a JTOpen object of type AS400ConnectionPool.
A resource of type IBMiConnection contains a library field. Any value specified in that field replaces the library field in the IBMiProgram annotation.
For general details on binding, see Resource bindings.
Annotations for data conversion
The data-conversion annotations cause the use of converters that are found in the following JTOpen package: com.ibm.as400.access. The EGL annotation name is the same as the Java class name.
When you set a value for the parameterAnnotations field, you specify an annotation or the null keyword for every annotation:
- Values of simple reference types require an annotation. Example types are String, Decimal, and Timestamp.
- Values of simple value types require an annotation only if you do not want to accept the defaults. Example types are String(7), Decimal (5,2), and Timestamp("yyyyMMddHHmm").
- Lists require a parameter annotation.
- null is always used for a variable that is based on a Record or Handler type.
If you do not set a value for the parameterAnnotations field, the defaults are used for every parameter.
Record Example // Convert using the default AS400Bin4 f1 int; // After the host program call, f2 is resized using the data returned in f3 f2 int[]{@AS400Array{elementCount = 10, returnCountVariable = f3}}; // A fixed text with a length 2 characters using the default encoding f3 string{@AS400Text{length = 2}}; // Convert a number to a AS400DecFloat f4 number?{@AS400DecFloat{length = 34}}; // Convert using the default AS400PackedDecimal f5 decimal(10,2); // Convert using the AS400ZonedDecimal f6 decimal(10,4){@AS400ZonedDecimal{}}; end
Call statements
You write a call statement to invoke the EGL proxy function. A using clause, if present, refers to a connection. If a using clause is not present in the call statement, the IBMiProgram annotation in the proxy function must reference a deployment descriptor entry. Consider the following proxy function, which resides in an EGL Program type: Program TestSimpleProgram //On IBM i, only service programs support a return function MyHostProcedure(p1 string, p2 string)RETURNS(INT) { @IBMiProgram{ programName = "/QSYS.LIB/VARLABXX.LIB/GETREC", connectionResourceBindingURI = @Resource{uri = "binding:file:someConnection"}, isServiceProgram= true, parameterAnnotations = [@AS400Text{length = 10}, @AS400Text{length = 10}] } } end end
cust Customer; result Int; myString String = "abc"; try call MyHostProcedure(myString, cust) returns (result); onException(exception AnyException); //handle exception end
cust Customer; result int; myString String = "abc"; conn IBMiConnection? = SysLib.getResource(uri="binding:file:someOtherConnection"); try call MyHostProcedure(myString, cust) using conn returns (result); onException(exception AnyException) //handle exception end
cust Customer; result int; myString String = "abc"; try call MyHostProcedure(myString, cust) using SysLib.getResource(uri="binding:file:someOtherConnection") as IBMiConnection returns (result); onException(exception AnyException) //handle exception end
cust Customer; result int; myString String = "abc"; conn IBMiConnection? = getMyDefinedConnection(); try call MyHostProcedure(myString, cust) using conn returns (result); onException(exception AnyException) //handle exception end
externalType JTOpenConnections type JavaObject private constructor(); static function getAS400ConnectionPool()returns(AS400ConnectionPool); end
Fields in the EGL deployment descriptor entry
You can set a variety of fields in the EGL deployment descriptor entry. The type of each entry is AS400Connection, which is compatible with the IBMiConnection type that is used in the code examples.
You can use the fields in the deployment descriptor to override default behavior. In addition, you can set annotations on a field or parameter that is being passed to the proxy function, and that annotation overrides all other settings.
Here are the fields of the deployment descriptor entry:
dateFormat
- The date format for AS400Date objects.
- This value overrides the default date format, which is com.ibm.as400.access.AS400Date.FORMAT_ISO. The format specifies a separator character, but that character can be overridden; for details, see the next description.
dateSeparator
- The date separator for AS400Date objects.
- This value overrides the date separator that is specified in the dateFormat field value.
encoding
- The character encoding for AS400Text objects.
- This value overrides the default encoding, which is obtained from the CCSID value of the AS400 connection.
library
- The library where the program is located. If you specify a value for this field, you replace any value specified in the IBMiProgram annotation, library field.
password
- The password for the specified user ID.
system
- The IBM i system name.
timeFormat
- The time format for AS400Time objects.
- This value overrides the default time format, which is com.ibm.as400.access.AS400Time.FORMAT_ISO. The format specifies a separator character, but that character can be overridden; for details, see the next description.
timeSeparator
- The time separator for AS400Time objects.
- This value overrides the time separator that is specified in the timeFormat field value.
timeZone
- The time zone for AS400Date, AS400Time, and AS400Timestamp objects.
- This value overrides the default time zone, which is obtained from the timezone field value of the AS400 connection.
userid
- The user ID that provides access to the IBM i system.
For further details
For further details, see the last sections in the following help-system topic: "Accessing an IBM i called or service program."