suhas-mahajan
30th March 2007, 15:04
Hi Friends,

I am using SEQ functions for inserting data into text file. But I want to skip data inserting if its already inserted (I mean search duplicate data).
Or after inserting all the data How to remove duplicate records.

Thanks in advance.

regards,

-Suhas

mark_h
30th March 2007, 15:32
Do you have to use seq.* functions? Can you use a report to suppress identical values? In UNIX I could use the sort command to suppress identical key values, not sure about the Baan sort. You might want to check the help on that.

Another option is to create a table - which would skip giving errors for duplicate records.

Last option is to write the file, sort it, then read it writing another file skipping the duplicates.

suhas-mahajan
30th March 2007, 15:51
Thanks for Info.

Yes...I have to. I dont have reports. And I dont want to create tmp tables.

Can you give any example of last option or may be any array example?

In unix I can use SORT and UNIQ. But I want BaaN's side.

regards,

-Suhas

mark_h
30th March 2007, 16:15
High level flow would look like this:
(1) Finish writing file seq.flush and seq.close.
(2) Run sort6.1 or your version sort6.1 help (http://www.baanboard.com/baanboard/showthread.php?t=3474&highlight=sort6.1)
(3) open the new sorted file.
(4) read first record and save key values
(5) write another new file
(6) get next record
(7) Do key values match goto 6
(8) Key values not match - write record, save new key values

Something like this.

Actually what I would do is write a report without headers(not attached to the session) to suppress key values. I would open it using ASCIF sending it to a temp file. Then when it is done I have what is already needed.

mr_suleyman
30th March 2007, 16:25
Hi, Infact marks way is good. AFAIK you don't want to use temp tables.
I imagine that solution for you . You know that array is limited. For big files it doesn't work. May be you can create baan report from source file. Use sort field part on report. In this way you can eliminate duplicate data by using baan. After that you can run another baan program in order to insert records.


That's all.


Good luck !

Hitesh Shah
30th March 2007, 16:55
Well , Mark's method is time tested and will work for sure .

If u are appending ur data at certain intervals to an existing file , function pattern.in.file in ottdllfilehand may be of use . Here is the function prototype.

function extern long pattern.in.file( const string file(),const string pattern() )

If u r writing to file to do some data transformation , then array can definitely be an answer . Bcos 5MB limit is on a single array . If u compare this limit with transformed records and NOT extracted ercords , this limit may not at all be big . Transformed records are much lower than extracted records . The lower the proportion , the higher the performance. And in addition it's extremely faster than slower disk sensitive seq.* operations . The key to it is successful use of QSS.* functions on array.

NPRao
30th March 2007, 22:45
Suhas,

If you use seq.flush() after every call to seq.write() or seq.puts() the buffer is written to the file and the file pointer is still open to write, then you can use the function - pattern.in.file() to check if the data is already in file or not.

suhas-mahajan
2nd April 2007, 16:49
Thanks everybody. I am working on given solution.

I am stuck-up on one more issue.

I would like to format string and numbers as per specs. Specs shows that if the string field is empty then use a space (" ") and if numeric field is empty then 0 (zero) should be displayed. There are hundreds of fields.

buff=format.string(tiitm001.ccde)

function string format.string(ref string str)
{
if isspace(str) then
str= " "
else
str=strip$(shiftl$(str))
endif
return(str)
}



If I tried above function, it seems tiitm001.ccde not changing its domain properties, it shows full space field, I want to show it is as " ". How to achive it?

regards,

-Suhas

mark_h
2nd April 2007, 17:18
Try this no subroutine needed:

buff= isspace(tiitm001.ccde) ? " " : strip$(shiftl$(tiitm001.ccde))

suhas-mahajan
2nd April 2007, 17:24
Thanks for the solution.

But as wrote, there are hundreds of fields.

May be macro, I am looking.

regards,

-Suhas

mark_h
2nd April 2007, 17:43
If it works for one then you can try the macro. I have never really used those but I do not see why it would not work.