Your Browser is not longer supported

Please use Google Chrome, Mozilla Firefox or Microsoft Edge to view the page correctly
Loading...

{{viewport.spaceProperty.prod}}

Setting and reading the data for the entire structure (for sending and receiving)

The data for an entire record or data group is read using the getBytes() method and written using the setBytes() method.

With the communication methods of BeanConnect for sending and receiving data (sndRecord(), rcvRecord() and call() methods with the ByteContainer parameter) it is also possible to specify the Java objects directly because all classes representing COBOL structures generated by Cobol2Java implement the ByteContainer interface.


Example 30 Sending and receiving data

// Java object which was created by Cobol2Java
EmployeeRecord emplRecord = new EmployeeRecord();
// Set encoding of the connection
emplRecord.setEncoding( connection.getEncoding() );
emplRecord.setEncodingActive( connection.isEncodingActive() );
// Connection object: sndRecord/rcvRecord method
connection.sndRecord(emplRecord);
connection.rcvRecord(emplRecord);

With the sndRecord() call the data from emplRecord is sent on the connection and with the rcvRecord() call the data from the connection is stored in emplRecord.

Detailed information on encoding is provided in the Encoding and national language support .

To modify a data field XXX, it is not sufficient simply to modify the object obtained via the get<XXX> method. Instead, the field has to be modified using one of the set<XXX> methods.


Example 31 Getting and storing data

// Data is received and stored in the EmployeeRecord
connection.rcvRecord(in);           (1)
PicX       lastName;
String     newName = "MyName";
lastName = in.getLastName();        (2)
lastName.setString(newName);        (3)
in.setLastName(lastName);           (4)
// or in.setLastName(newName);      (5)
// The data stored in EmployeeRecord is sent connection.sndRecord(in);

where:

(1) Java class which was created by Cobol2Java from a COBOL data structure

(2) Return data field as PicX object

(3) Modify PicX object

(4) Modify data field via set method with PicX parameter

(5) Modify data field via set method with String parameter