I am Following Class and Methods :
class testImport extends RunBaseBatch
{
DialogField dialogFileName;
FileName fileName;
FormStringControl fileNameControl;
TextIO textIO;
FileIOPermission permission;
Container c;
Empl_Temp importTable;
#File
#avifiles
#define.CurrentVersion(1)
#define.Version1(1)
#localmacro.CurrentList
fileName
[tag:end]
____________________________________________________________________________________
public Object dialog()
{
Dialog dialog;
DialogField dialogField;
Filename _fileName;
;
dialog = new Dialog("FileOpen");
dialogfield = dialog.addField(typeid(Filenameopen), "File Name");
dialog.run();
if (dialog.run())
{
_fileName = (dialogfield.value());
}
return dialog;
}
________
public boolean getFromDialog()
{
boolean ret;
ret = super();
fileName = dialogFileName.value();
return ret;
}
__________________________________________________________________________________________
void importFromTextFile()
{
SysOperationProgress simpleProgress;
;
permission = new fileIOpermission(fileName,#io_read);
permission.assert();
textIO = new TextIO(fileName,#io_read);
textIO.inFieldDelimiter("|");
textIO.inRecordDelimiter('\n');
simpleProgress = SysOperationProgress::newGeneral(#AviUpdate,"Import is in progress",100);
startLengthyOperation();
while(textIO.status() == IO_Status::Ok)
{
c = textIO.read();
if(conLen(c) > 1)
{
setPrefix(this.caption());
importTable.clear();
importTable. EmplId = conpeek(c,1);
importTable.New_EmplName = conpeek(c,2);
importTable.New_FirstName = conpeek(c,3);
importTable.New_LastName = conpeek(c,4);
importTable.New_Email = conpeek(c,5);
importTable.New_Telephone = conpeek(c,6);
importTable.New_Designation = conpeek(c,7);
importTable.New_DOB = conpeek(c,8);
}
}
endLengthyOperation();
}
------------------------------------------
public container pack()
{
return [#CurrentVersion,#CurrentList];
}
---------
public void run()
{
#OCCRetryCount
;
if (! this.validate())
throw error("Import has been cancel");
try
{
this.importFromTextFile(); // Import records of txt file
}
catch(Exception::Deadlock)
{
retry;
}
catch(Exception::Error)
{
info ('Import cancelled');
}
catch (Exception::UpdateConflict)
{
if (appl.ttsLevel() == 0)
{
if (xSession::currentRetryCount() >= #RetryNum)
{
throw Exception::UpdateConflictNotRecovered;
}
else
{
retry;
}
}
else
{
throw Exception::UpdateConflict;
}
}
}
------------------
public boolean unpack(container packedClass)
{
Version version = RunBase::getVersion(packedClass);
;
switch (version)
{
case #CurrentVersion:
[version,#CurrentList] = packedClass;
break;
default:
return false;
}
return true;
}
------------------
public boolean validate()
{
boolean ret = true;
Container checkType;
TextIO errorIo;
if (! fileName)
{
ret = checkFailed("Please specify file");
}
checkType = Docu::splitFilename(fileNameControl.text());
if(conpeek(checkType,2) != '.txt' || conpeek(checkType,2) != '.csv')
{
ret = checkFailed("file format is incorrect");
}
errorIo = new TextIO(fileName, 'r');
if (! errorIo)
{
return checkFailed(strfmt("@SYS18678", fileName));
}
return ret;
}
---------------------
static void main(Args args)
{
testImport importClass;
;
importClass = new testImport ();
// if (Empl_Temp.prompt());
// Empl_Temp.run();
importClass.run();
importClass.prompt();
}