Working with IccResource subclasses

To illustrate working with IccResource subclasses, consider writing a queue item to CICS® temporary storage using IccTempstore class.

IccTempStore store("TEMP1234");
IccBuf buffer(50);
The IccTempStore object created is the application's view of the CICS temporary storage queue named "TEMP1234". The IccBuf object created holds a 50-byte data area (it also happens to be 'extensible').
buffer = "Hello Temporary Storage Queue";
store.writeItem(buffer);

The character string "Hello Temporary Storage Queue" is copied into the buffer. This is possible because the operator= method has been overloaded in the IccBuf class.

The IccTempStore object calls its writeItem method, passing a reference to the IccBuf object as the first parameter. The contents of the IccBuf object are written out to the CICS temporary storage queue.

Now consider the inverse operation, reading a record from the CICS resource into the application program's IccBuf object:
buffer = store.readItem(5);

The readItem method reads the contents of the fifth item in the CICS Temporary Storage queue and returns the data as an IccBuf reference.

The C++ compiler resolves the given line of code into two method calls, readItem defined in class IccTempStore and operator= which has been overloaded in class IccBuf . This second method takes the contents of the returned IccBuf reference and copies its data into the buffer.

The given style of reading and writing records using the foundation classes is typical. The final example shows how to write code – using a similar style to the above example – but this time accessing a CICS transient data queue.
IccDataQueue queue("DATQ");
IccBuf buffer(50);
buffer = queue.readItem();
buffer << "Some extra data";
queue.writeItem(buffer);

The readItem method of the IccDataQueue object is called, returning a reference to an IccBuf which it then assigns (via operator= method, overloaded in class IccBuf ) to the buffer object. The character string – "Some extra data" – is appended to the buffer (via operator chevron « method, overloaded in class IccBuf ). The writeItem method then writes back this modified buffer to the CICS transient data queue.

You can find further examples of this syntax in the samples presented in the following sections, which describe how to use the foundation classes to access CICS services.

Refer to the reference section for further information on the IccBuf class. You might also find the supplied sample – ICC$BUF – helpful.