Example of Temporary Storage
This sample program demonstrates how to use the IccTempStore and IccTempStoreId classes.
This program,
and the expected output from it, can be found in
C++ sample programs
, as file
ICC$TMP.
The sample is presented here without the terminal IO requests.
#include "icceh.hpp"
#include "iccmain.hpp"
#include <stdlib.h>
The first three lines include the header files for the
foundation classes, the standard
main
function that sets up
the operating environment for the application program, and the standard
library.
const char* bufferItems[] =
{
"Hello World - item 1",
"Hello World - item 2",
"Hello World - item 3"
};
This defines some buffer for the sample program.
void IccUserControl::run()
{
The
run
method of
IccUserControl
class contains
the user code for this example.
short itemNum = 1;
IccTempStoreId id("ICCSTORE");
IccTempStore store( id );
IccBuf buffer( 50 );
store.empty();
This fragment first creates an identification object,
IccTempStoreId
containing
the field "ICCSTORE". It then creates an
IccTempStore
object
representing the temporary storage queue "ICCSTORE", which it empties
of records.
for (short j=1 ; j <= 3 ; j++)
{
buffer = bufferItems[j-1];
store.writeItem( buffer );
}
This loop writes the three data items to the Temporary
Storage object. The data is passed by means of an
IccBuf
object
that was created for this purpose.
buffer = store.readItem( itemNum );
while ( store.condition() == IccCondition::NORMAL )
{
buffer.insert( 9, "Modified " );
store.rewriteItem( itemNum, buffer );
itemNum++;
buffer = store.readItem( itemNum );
}
This next fragment reads the items back in, modifies the
item, and rewrites it to the temporary storage queue. First, the
readItem
method
is used to read the buffer from the temporary storage object. The
data in the buffer object is changed using the
insert
method
of
IccBuf
class and then the
rewriteItem
method overwrites
the buffer. The loop continues with the next buffer item being read.
itemNum = 1;
buffer = store.readItem( itemNum );
while ( store.condition() == IccCondition::NORMAL )
{
term->sendLine( " - record #%d = [%s]", itemNum,
(const char*)buffer );
buffer = store.readNextItem();
}
This loop reads the temporary storage queue items again
to show they have been updated.
return;
}
The end of run , which returns control to CICS®.