Accessing Applications on the CICS Server

This section describes two methods of handling data with standard CICS object-orientated support through the ECI and secondly using VisualAge InterSpace services.

Let’s look at some extracts taken from the Visual Basic Project module, comsubs.bas, of our sample application. Comsubs.bas is concerned with the connection to the CICS server application by native CICS calls. The data-handling methods used with VisualAge Interspace is discussed Creating the VisualAge Interspace Service for the NACT02 CICS Server Application later in this chapter.

The definitions of the Visual Basic GUI data fields used by NACT05 are shown in Example 13-1.

Note how nested structures contained within the COMMAREA are handled. The COMMAREA definition contains a datatype AccRecord whose definition includes a datatype of PayHistory. The datatype AccRecord is defined as shown in Example 13-2.

PayHistory is itself a data structure of fields of type String. The datatype of String used in the Visual Basic application corresponds to a datatype of CHAR on the OS/390 host. PayHistory is defined in Example 13-3.

This section shows extracts from the Visual Basic module comsubs.bas that are used to link to the CICS Browser application. The Visual Basic application makes use of the ECI Component Object Module (COM) library supplied with the CICS Universal Clients Version 3.1. A set of samples is also supplied in the \cicsadp\IBM CICS Universal Client\Samples\VB directory.

The following guidelines will help you make an ECI link call to CICS:

  1. Declare and instantiate the objects to be used. This can be done in the Form_Load subroutine or at some later stage in response to some user action. Note that a CclOECI must be created first to allow use of the ECI COM class. The definitions look like this:

    Public  ECI As New CclOECI
    Private Connect As New CclOConn
    Private Flow As New CclOFlow
    Private buffer As New CclOBuf
    Private UOW As New CclOUOW
  2. Set the length of the buffer to the required COMMAREA size for the Browser program NACT05:

    buffer.SetLength commBRWSlength
  3. Provide details of the CICS server to be used. The CICS server name variable CICSServer has been left as null, forcing the first entry in the CICS Client initiation file ctg.ini to be used. The user ID and password values are those supplied by the user at Log in. Details are supplied using the details method for the Connect COM class. Before the Connect COM class can be used it needs to be initialized using the details method:

    Connect.Details CICSServer, Userid, Password
  4. Build the buffer. This is done automatically, because the required fields for the input COMMAREA have already been set within the Data Structure, as described in the Data field definitions earlier in this chapter.

  5. Move data into the COMMAREA byte array. The parameters used are:

    Example 13-4 shows the routine that is used to move data into the COMMAREA byte array.

  6. Use the SetData for the CclOBuffer object to populate the buffer with the contents of the byte array ca:

    buffer.SetData ca
  7. Now we are ready to make the call to CICS. The Link method takes as parameters the Flow object, the name of the CICS server program to be invoked, the buffer object, and a UOW object. In this example, the UOW object has been defined but not set explicitly. Java initializes it to a null value; this call is not part of a recoverable unit of work:

    Connect.Link Flow, prog, buffer, UOW
  8. The updated data contained in the buffer object is stored in the variable tempca and then restored to the COMMAREA byte array ca:

    For i = 0 To commlen
            ca(i) = tempca(i)
    Next i
  9. Finally, the CICS COM objects are deleted:

    Public Sub deleteECIobjects()
        ' Delete the ECI objects we created
        Set buffer = Nothing
        Set Flow = Nothing
        Set Connect = Nothing
        Set ECI = Nothing
    End Sub

The recommended way of handling errors with the CICS ECI COM classes is to use the standard Visual Basic On Error statement.

The form of the call used in the sample Visual Basic application is shown in the following code extract:

' Execute the CICS NACT05 program

    On Error GoTo ErrorHandler
    Connect.Link Flow, prog, buffer, UOW

When an error condition occurs, the program logic drops through to the label ErrorHandler at the end of the subroutine, or in this case, function. The code below shows how the error information is stored. CclExceptionCodes contains details of the possible error exception codes that can be returned from CICS. Each exception code has a number and associated message that can be displayed to the application user. Where an abend has occurred, the value of the error returned is cclTransaction (code 13) and the Abendcode can be queried and displayed.

Tip

Example 13-5 shows the use of the preceding Exit Function statement to stop the error handler code being run as part of the normal flow through the function.

There are a number of methods for using VisualAge Interspace with CICS as a starting point for new CICS applications. We have focused on using a service to communicate using the CICS ECI with the existing CRUD program NACT02.

The following steps are required:

We now look at each of these steps in more detail in the following sections.

VisualAge Interspace thinks of a service for communicating with an application as providing a request to which it receives a reply. The request is the COMMAREA being sent to the NACT02 program and the reply is the COMMAREA returned from the NACT02 program. Figure 13-3 shows the Defaults window.

The Distributed Environment for which the new services will be used is CICS. The Buffer Type is STRING that corresponds to the datatype of CHAR used for the COMMAREA field definitions used in our COBOL program NACT02. The field definitions and services created are stored in a plain text catalog file that we have chosen to call NACT and placed under the Interspace base directory. These are the only default settings we need to concern ourselves with for this example.

In order to set up the COMMAREA for the service we first need to provide Interspace with definitions for fields to be used in the COMMAREA. This can be done in one of two ways:

For more information about the Importing Fields topic, refer to the Interspace online help.

VisualAge Interspace allows for a request header and request data. The request header can be thought of as the fields at the start of the COMMAREA, and the request data as a set of records of the same layout returned at the end of the COMMAREA. We have chosen to split the COMMAREA between the request header and request data but could equally as well have chosen to supply the entire COMMAREA as the request data. The design of VisualAge Interspace is such that it normally expects a set of control character fields at the start of a transmission from the calling application which, amongst other information, gives the number of records of the type specified as request data that are being returned.

There is also an option Suppress Control Fields; this must be set here as the NACT02 program will not supply or understand these control fields. When set, the Suppress Control Fields option does not send any control data or expect any to be returned from the called application. Interspace assumes that it is to receive one record whose structure is specified by the fields set up in the Request Data. This simplifies the communication with any CICS ECI application.

NACT02 only ever receives one record. If we were to work with a different application that provided a list of records, then there are additional steps which would need to be implemented. VisualAge Interspace uses the idea of what it calls a composite service to deal with this type of CICS application. The data area used to hold the records being returned by the CICS application is defined as a single field. This field can then be supplied as the request data to a composite service set up by the user which transforms it into a field array using the record structure detailed in the reply data of the composite service.

Taking a simple case the field RecordData returned from a CICS application contains several customer records. This data is supplied as the request data to a composite service. The reply data is defined as consisting of three fields:

Data is extracted from RecordData using the field structure specified in the reply data for the composite service. The process is then repeated on the remaining characters in the string until it is used up, as shown in the following table:

Reply Data Provided from CICS Application

Request Data Supplied to Composite Service

Reply Data from Composite Service

field1 xxxx

  

field2 xxxx

  

RecordData SMITH….12JONES…. 34

RecordData SMITH….12JONES…. 34

name(1) SMITH….

  

valuea(1) 1

  

valueb(1) 2

  

name(2) JONES….

  

valuea(2) 3

  

valueb(2) 4

Again, this idea is explained in more detail in the online help provided with VisualAge Interspace.

Once the necessary fields have been set up within the Service Interface Painter, you can then create the service itself.

Click on the Add icon to create a new service.

The Add Service panel, as shown in Figure 13-4, is then used to add the fields in the order required for the NACT02 COMMAREA.

Once the service has been tested and data successfully retrieved, you can generate the required Visual Basic module that will link to NACT02:

  1. Click on the Generate icon to display the Service Interface Generation window, shown in Figure 13-6.

  2. Check the Visual Basic box, if it is not already checked.

  3. Specify a suitable destination directory and select the appropriate template from the set provided by VisualAge Interspace. For this synchronous communication with CICS we specify the vbsync.tpl (see Figure 13-6).

  4. Click OK. This causes the Visual Basic module NACT02.bas to be generated in the specified directory:

The module generated contains all the necessary procedures required to communicate with the NACT02 program, and includes all the relevant data structures.

Programming steps include:

These steps are described in more detail below.

Initialize Interspace to CICS at startup. The application name field has been specified as NACT rather than NACT02. We are making use of the catalog file nact.cat, which contains the details of the NACT02 service and could be used to hold additional services. It is not unusual to keep a large number of services for related applications in the same catalog. The nact.cat file needs to be made available to VisualAge Interspace by placing it in the Windows NT path or current directory. The code looks like this:

ReturnCode = dcifx_init("CICS", "NACT", Userid, Password)
If ReturnCode = -1 Then
   dcifx_show_error vbCritical, "Interspace Initialization Failed"
   Call endProgram
End If

Create instances of the structures for NACT02 used to send and receive data. In order to communicate with the NACT02 server application, we need to create instances of the request and reply structures that will be used by the Interspace service. These are then accessed from within two separate forms, so we have chosen to add the declaration to the NACT02.bas module. The code looks like this:

'Create instances of the request message NACT02_request_msg
'and reply message NACT02_reply_msg.
Global NACT02_Request As NACT02_request_msg
Global NACT02_Reply As NACT02_reply_msg

Prepare the COMMAREA fields required to be sent. Now we need to set the required COMMAREA fields. The code looks like this:

'Set value of version in request service header
NACT02_Request.header.ca_version = "V1A"
'Set value of request type in request Service Header
NACT02_Request.header.ca_request = "E"
'Ensure we can write data into the RequestData
ReDim NACT02_Request.data(1)
'Set value of account number in request data
NACT02_Request.data(1).Acct = "10000"

Notice the use of header and data prefixes together with the fields names that were used in the Service Interface Painter service.

Issue the Interspace request and receive the reply. Once the required data has been added to the request COMMAREA we can issue the call to the NACT02 program through Interspace and check the response. Interspace returns the reply from NACT02 in the NACT02_Reply object structure. The code looks like this:

'Issue the relevant call for Interspace to send the request
'to NACT02 and receive the reply
ReturnCode = receive_NACT02_sync(NACT02_Request, NACT02_Reply)
'Check request issued correctly
     If ReturnCode = -1 Then
        dcifx_show_error vbCritical, "Call to the CICS application NACT02 failed
        to complete"
        Exit Sub
     End If

Exit Interspace when ending the program. To end communication using Interspace, issue the dcifx_exit call for CICS:

'Check to see if Interspace was initialized
If CICSOpen = 1 Then
       'Issue call to exit Interspace
        ReturnCode = dcifx_exit("CICS")
       'Check request issued correctly
       If ReturnCode = -1 Then
          dcifx_show_error vbCritical, "Interspace Exit Call Failed"
       End If
  End If

Interspace insulates the Visual Basic programmer from needing to know anything about CICS in order to make use of the NACT02 program. You can use the same Visual Basic application to communicate with several CICS server applications by generating additional service modules using the Service Interface Painter, and then adding them to the project.