Baanboard.com

Go Back   Baanboard.com > Forum > Baan Quick Support: Functional & Technical > Tools Development

User login

Frontpage Sponsor

Main

Poll
For ERP LN feature pack upgrade, what method of install are you using?
Installation Wizard into existing VRC
37%
Installation Wizard into new VRC
39%
Manual into existing VRC
3%
Manual into new VRC
21%
Total votes: 38

Baanboard at LinkedIn


Reference Content

Reply
 
Thread Tools Display Modes
  #1  
Old 2nd July 2003, 20:55
ltannous's Avatar
ltannous ltannous is offline
Senior Member
 
Join Date: Sep 2002
Location: Canada
Posts: 280
ltannous is on a distinguished road
Baan: 4c4 - DB: Oracle - OS: UNIX
can't write file from server to baan table

I am trying to upload a file from our UNIX server to a baan table using a session update script. I can get the file into baan, but there are end of line characters messing up the data entry.

The first line inserted is blank
The second line inserted has a unrecognized charachter at the end.(end of line, then a new line character)

The file is created in Unix by ls * > listing.txt

Code:
before.program:
	
	path = "/apps/baan/bse/edi/logs/listing.txt"

functions:

function read.main.table()
{
	db.retry.point()
	
	select	wtedi011.*
	from	wtedi011 for update
	selectdo
 	fp = seq.open(path,"rt")
	
	if fp < 1 then 
		message("Error, cannot open file")
		endif
	if fp >= 1 then
	while seq.EOF(fp) = 0
		seq.read(reln,18,fp)
		wtedi011.reln = reln
		
	db.insert(twtedi011, db.retry)
	|			endif
	|			endif
		
		endwhile
		endif
	seq.close(fp)
	commit.transaction()
	endselect

}
Reply With Quote
  #2  
Old 2nd July 2003, 21:08
NPRao's Avatar
NPRao NPRao is offline
Guru
 
Join Date: Aug 2001
Location: Pacific NW, USA
Posts: 3,032
NPRao will become famous soon enough
Baan: iBaanERP-5.2a(Reger),SSA-ERP-LN-6.1,Infor LN-10.x - DB: Oracle-10g,11g,12c,MS-SQL - OS: HP-UX, Linux, Windows
Change your code to -
Code:
	fp = seq.open(fname, "r")
	if	fp < 0 then
		mess("zmadms0010", 1)
		|* File Handling Errors
		return
	endif
	while  not seq.gets(buffer, 1024, fp)
		do.something()
	endwhile

Refer to the link - seq.gets()

You can choose different mode options -
Quote:
mode
Use this optional argument to specify the read mode for seq.gets(). Possible values are:

GETS_NORMAL


The function continues reading characters until either the buffer (line) is full, a new line character is read, or EOF is reached.

If the buffer is full, any remaining characters on the line being read are discarded.

This is the default mode.


GETS_ALL_CHARS
The function continues reading characters until either the buffer (line) is full, a new line character is read, or EOF is reached.

If the buffer is full, the next seq.gets() call starts reading at the point where the current seq.gets() finished. The use of this mode ensures that all characters available in input file are eventually returned.


GETS_SKIP_ALL
This is the same as GETS_NORMAL, except that if the last line in the file does not end with a new line character, that line is discarded completely and EOF is returned.

there.was.more
When characters are discarded in GETS_NORMAL or GETS_SKIP_ALL mode, or when more characters are available in the line (but the buffer is full) in GETS_ALL_CHARS mode, this argument is set to 1. Otherwise, the argument returns 0.
__________________
The art of perfection does not lie in doing extraordinary things but, doing ordinary things extraordinarily well. [-N. Prashanth Rao]
How To Ask Questions The Smart Way,BaaNBoard,NPRao
Reply With Quote
  #3  
Old 2nd July 2003, 22:35
ltannous's Avatar
ltannous ltannous is offline
Senior Member
 
Join Date: Sep 2002
Location: Canada
Posts: 280
ltannous is on a distinguished road
Baan: 4c4 - DB: Oracle - OS: UNIX
Sort of worked?

I had 5 lines in the file,only the second line got loaded?
I made the following changes:

Code:
before.program:
	
	path = "/apps/baan/bse/edi/logs/listing.txt"

functions:

function read.main.table()
{
	db.retry.point()
	string buffer(256)
	
	
 	fp = seq.open(path, "rt")
	
	if fp < 0 then 
		message("Error, cannot open file")
	
		return
	endif
	
		
	while  not seq.gets(buffer, 1024, fp)
		select	wtedi011.*
	from	wtedi011 for update
	selectdo
	seq.gets(reln,18,fp)
	wtedi011.reln = reln
	db.insert(twtedi011, db.retry)
		
	endselect
	seq.close(fp)
	endwhile
	commit.transaction()

}
Reply With Quote
  #4  
Old 2nd July 2003, 22:43
NvanBeest's Avatar
NvanBeest NvanBeest is offline
Guru
 
Join Date: May 2003
Location: South Africa
Posts: 521
NvanBeest is on a distinguished road
Baan: BaanIVc4 - DB: Oracle, TBase, SQL Server - OS: AIX, Linux, Window$
You're reading two lines in the first iteration, and then closing it before the next iteration!
Code:
while not seq.gets(buffer, 1024, fp) <b>| read first line</b>
   select wtedi011.*
   from wtedi011 for update
   selectdo
      seq.gets(reln,18,fp) <b>| read second line</b>
      wtedi011.reln = reln
      db.insert(twtedi011, db.retry)
    endselect
    seq.close(fp) <b>| close the file</b>
endwhile
Change it to:
Code:
while not seq.gets(buffer, 1024, fp)
    select wtedi011.*
    from wtedi011 for update
    selectdo
      wtedi011.reln = buffer(1;18)
      db.insert(twtedi011, db.retry)
    endselect
endwhile
seq.close(fp)
__________________
Regards,
Nico
Reply With Quote
  #5  
Old 2nd July 2003, 23:38
ltannous's Avatar
ltannous ltannous is offline
Senior Member
 
Join Date: Sep 2002
Location: Canada
Posts: 280
ltannous is on a distinguished road
Baan: 4c4 - DB: Oracle - OS: UNIX
Smile Thanks for the help

It worked with some minor tweeking.
Reply With Quote
Sponsored Links
  #6  
Old 4th July 2003, 17:27
ltannous's Avatar
ltannous ltannous is offline
Senior Member
 
Join Date: Sep 2002
Location: Canada
Posts: 280
ltannous is on a distinguished road
Baan: 4c4 - DB: Oracle - OS: UNIX
Files can only be inserted if a line exists already

I can upload the file to a table, but only if the table has at least one record in it.

I need to send a db.clear.table first, and then load the table from a file.
Why can't I load the data if the table is empty?

choice.cont.process:
on.choice:
clear.table()
read.main.table()
remove.file()

|****************************** function section ****

before.program:

path = "/apps/baan/bse/edi/logs/listing.txt"

functions:

function read.main.table()
{
db.retry.point()
string buffer(256)


fp = seq.open(path, "rt")

if fp < 0 then
message("Error, cannot open file")

return
endif
select wtedi011.*
from wtedi011 for update
selectdo

while not seq.gets(buffer, 1024, fp)

wtedi011.reln = buffer(1;17)
db.insert(twtedi011, db.retry)

commit.transaction()
endwhile
endselect
seq.close(fp)


seq.close(fp)

message("Files Update")
}

function remove.file()

{

file.rm("/apps/baan/bse/edi/logs/listing.txt")


}


function clear.table()

{
db.clear.table(twtedi011,0,210)

}
Reply With Quote
  #7  
Old 4th July 2003, 17:32
NvanBeest's Avatar
NvanBeest NvanBeest is offline
Guru
 
Join Date: May 2003
Location: South Africa
Posts: 521
NvanBeest is on a distinguished road
Baan: BaanIVc4 - DB: Oracle, TBase, SQL Server - OS: AIX, Linux, Window$
The reason is that the enclosing select statement returns "false".

Change the code to:

Code:
db.clear.table(...)
select ...
where ...
selectdo
selectempty
   while ...
   endwhile
endselect
__________________
Regards,
Nico
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Delete a file from Win NT server learner Tools Development 9 13th March 2004 14:03
PHP or sth. like that and Baan ims_lenor Tools Development 10 28th January 2004 09:14
replicate file system objects across servers Hitesh Shah Code & Utilities 3 28th June 2003 09:41
Access to a table not in Baan balzamaor Tools Development 7 5th June 2003 13:56
BSP-US (LLC) added as a Baan Education Alliance svandenh General Discussion & Chat 1 20th August 2001 20:44


All times are GMT +2. The time now is 18:59.


©2001-2017 - Baanboard.com - Baanforums.com