Example of file control
This sample program demonstrates how to use the IccFile and IccFileIterator classes.
#include "icceh.hpp"
#include "iccmain.hpp"
const char* fileRecords[] =
{
//NAME KEY PHONE USERID
"BACH, J S 003 00-1234 BACH ",
"BEETHOVEN, L 007 00-2244 BEET ",
"CHOPIN, F 004 00-3355 CHOPIN ",
"HANDEL, G F 005 00-4466 HANDEL ",
"MOZART, W A 008 00-5577 WOLFGANG "
};
void IccUserControl::run()
{
short recordsDeleted = 0;
IccFileId id("ICCKFILE");
IccKey key(3,IccKey::generic);
IccFile file( id );
file.registerRecordIndex( &key );
key = "00";
recordsDeleted = file.deleteRecord();
IccBuf buffer(40);
key.setKind( IccKey::complete );
for (short j = 0; j < 5; j++)
{
buffer = fileRecords[j];
key.assign(3, fileRecords[j]+15);
file.writeRecord( buffer );
}
This next fragment writes all the data provided into records in the file. The data is passed by means of an IccBuf object that is created for this purpose. setKind method is used to change key from 'generic' to 'complete'.
IccFileIterator fIterator( &file,
&key );
key = "000";
buffer = fIterator.readNextRecord();
while (fIterator.condition() == IccCondition::NORMAL)
{
term->sendLine("- record read: [%s]",(const char*) buffer);
buffer = fIterator.readNextRecord();
}
The loop shown here lists to the terminal, using sendLine , all the records in ascending order of key. It uses an IccFileIterator object to browse the records. It starts by setting the minimum value for the key which, as it happens, does not exist in this example, and relying on CICS® to find the first record in key sequence.
key = "\xFF\xFF\xFF";
fIterator.reset( &key );
buffer = fIterator.readPreviousRecord();
while (fIterator.condition() == IccCondition::NORMAL)
{
buffer = fIterator.readPreviousRecord();
}
key = "008";
buffer = file.readRecord( IccFile::update );
buffer.replace( 4, "5678", 23);
file.rewriteRecord( buffer );
buffer = file.readRecord();
return;
}
The end of run , which returns control to CICS.
See C++ sample programs for the expected output from this sample.