A service interface is defined as a series of operations. In each operation, you create service interface fields that correspond to your COBOL program's entry point fields. At runtime, data is sent between the service and the program via these fields.
In COBOL, you describe a data item's data type precisely, using its picture clause. Java uses its own set of data types. The Interface Mapper enables you to create mappings between the COBOL types in your program and the types available in Java.
You use the Interface Mapper to define streamlined access to your program by defining an operation for each of the program's four possible actions - Read record, Add record, Delete record, and Next record. Each operation requires the client to send just the data needed by that particular operation.
The first logical operation to define for this Java service interface is one that enables you to add a record. The process entails identifying the COBOL program that contains the Add action, identifying the COBOL Entry point code for that program, determining which fields send and receive information, and defining your operation to interact with the program, specifying the Add action.
The programs available in your Visual Studio project appear on the Select program/copybook list. From studying the COBOL code in the application, you know that the book.cbl program performs the add record action.
The name of each entry point contained in the program appears farther down on the dialog box. This shows that Book.cbl contains only one entry point - BOOK.
In the Interface Mapper, you now see that the entry point fields have been placed into the COBOL Entry Point pane on the left.
This creates an interface field called lnk_file_status. A mapping is automatically created between the new field and the entry point field it was created from. The purpose of this field is to relay information back to the user; you need to change its direction from Input to Output.
The default direction, Input, is what you want because this group of fields receives data and then pass it on to the data items in lnk-b-details.
By default, the name of the new interface field group created is lnk_b_details. However, in this case you should change the default name. You need to use this same group of source fields to create similar groups of interface fields in other operations in this same service interface. The Interface Mapper requires that interface field groups have unique names across operations in the same service interface. Because the default name for each of these would be identical in each operation, you must change the name in each operation to ensure that each is different from that used in other operations.
When defining a service interface, knowledge of the application and how it is used can enable you to make refinements to the new interface. For example, looking at the COBOL Entry Point pane, notice that the retail price field lnk-b-retail is defined as 9(2)V9(2). If you fully expand the tree for addop_details in the Interface Fields pane, you see that lnk_b_retail has defaulted to BigDecimal. Imagine that you know from your experience with the application that the retail prices are in fact always in whole numbers of dollars, and that lnk_b_retail can be an int. You change the type of the lnk-b-retail interface field to reflect this:
For the Add operation, you want the program to perform the add-record action. From looking at the source code, you know that when the value in the lnk-function field is 2, the program performs an add-record action:
In looking a little closer as to what this all means, notice that the correspondence between the COBOL Entry Point fields and interface fields is set up when you do the drag-and-drop. If you right-click an elementary interface field, such as lnk_file_status, and click Mapping, you see a dialog box showing the COBOL Entry Point field associated with it. This correspondence is not affected by the names or order of interface fields. You can use the dialog box to alter the mapping if you want.
In the messages passed between the service and a client, the interface fields are identified by keywords. Their names in the Interface Fields pane are used as the keywords. Their order in the Interface Fields pane is the order in which they are seen by a client, so it is good practice to be aware of this order. You can re-order fields by dragging them.
In your indexed file, the primary key is the stock number. The program action that gets the next record takes a stock number as input, finds the record in the data file that has that stock number, and returns the next record found.
The program uses the COBOL Entry Point field lnk-b-details as both an input and an output field, although on input lnk-b-stockno is the only part of lnk-b-details actually used. In your operation, you use the same field to access the program action that gets the next record in the data file.
The Select program/copybook list shows the book program and the book-rec copybook. The book program is already selected for you. This is because each service interface can use only one program, and you specified the book program in the Add operation you defined earlier for this same Java interface.
The entry point details are shown on the right.
The Interface Fields and COBOL Assignments panes for the new operation are blank in anticipation of new definitions for this operation.
The program action that retrieves the next record gets the required record from the data file and returns it. So you need a set of output fields into which the fields of this record return.
The new interface field created is called lnk_b_details. As you did when defining the Add operation, you must change the field name to ensure that it is different from the name used for similar groupings in the other operations for this interface.
In the application, the lnk_b_stockno field serves as an output field and is also the field in which the key identifying the required record is input. To handle this, you create an input interface field to accept the key.
For the program action that reads a record, the caller supplies a book's stock reference number, title, or author in the appropriate field in the lnk-b-details group. The program looks it up in the indexed file and returns the data back to the lnk-b-details group. The program uses the fields contained in the lnk-b-details group as both input and output. On input, the program expects the stock number, title, or author to be supplied; the other data items in lnk-b-details are ignored. On output, lnk-b-details is used to return the record indicated by the supplied stock number, title, or author.
The program functionality that reads a record gets the required record from the data file and returns it. You need a set of output fields in which to return the fields of this record.
You have defined a group of reusable fields as shown here:
This creates an interface field of type lnk_b_details. By default, its name is also lnk_b_details.
Like the program action that reads a record, the action that deletes a record expects the stock number, title, or author to be supplied. The other data items in lnk-b-details are ignored. It deletes the record indicated by the supplied stock number, title, or author.