pralash
6th October 2017, 16:48
Hi....

I'm fresher in LN Programming...I write a data into the file by using seq.puts function. But I want to know that how to write the data one by one into the file... Is there any switch are available in baan like \n or \t to do this task. Can anybody please let me know that about this task.

Regards,
Pralash

bhushanchanda
7th October 2017, 07:39
Hi Pralash,

seq.puts() will take care of adding a new line character.

seq.open(file.name,"w+")
select ...
from ...
selectdo
seq.puts(...,fp) |# Insert data in the text file
endselect

seq.close(fp)

So, with every seq.puts() a new line character is added and every record will be added to a new line in the text file.

pralash
8th October 2017, 17:21
Thanks for your information.... But how can I apply the new line char in seq.puts() function...
Thanks,
Pralash

pralash
9th October 2017, 08:14
Hi, I'm new to LN Programming. I have stored some data into the file by using seq.open(). But I don't know how to write the record one by one into the file...
We can write the records one by one in "C" Language by using the switch '\n' char...Similarly is there any characters are available in Bann for seq.put() in order to write the records one by one...
Can anybody assist me how to write the record one by one in with sample script...

Regards,
Senthil

JaapJD
9th October 2017, 09:25
seq.puts() writes a new line character. So for each line you need to write call the seq,puts() function with the data to write.

bdittmar
9th October 2017, 10:01
Hello,

avoid double posting, please 1
http://www.baanboard.com/baanboard/showthread.php?t=70483

Regards

bhushanchanda
9th October 2017, 11:05
Please do not create new threads if one already exists. As already said and confirmed by Jaap, seq.puts() will add new line character automatically. You just need to pass the string you want to write to the file.

e.g. Lets write item code and description from tcibd001 to a file.

string filename(100)
long fp
string str(100)

filename = creat.tmp.file$( bse.tmp.dir$() ) |# Create temp file
fp = seq.open(filename,"w+") |# Open temp file

select tcibd001.item, tcibd001.dsca
from tcibd001
selectdo
str = tcibd001.item & "," & tcibd001.dsca |# Item Code , Description
seq.puts(str,fp) |# Write to file
endselect

seq.close(fp) |# Close file

This should create and write the item code and description with comma separator the the output file in bse\temp directory. Each item will be written to a new line.

bhushanchanda
9th October 2017, 11:06
Please do not create new threads if one already exists. Merged threads now. As already said and confirmed by Jaap, seq.puts() will add new line character automatically. You just need to pass the string you want to write to the file.

e.g. Lets write item code and description from tcibd001 to a file.

string filename(100)
long fp
string str(100)

filename = creat.tmp.file$( bse.tmp.dir$() ) |# Create temp file
fp = seq.open(filename,"w+") |# Open temp file

select tcibd001.item, tcibd001.dsca
from tcibd001
selectdo
str = tcibd001.item & "," & tcibd001.dsca |# Item Code , Description
seq.puts(str,fp) |# Write to file
endselect

seq.close(fp) |# Close file

This should create and write the item code and description with comma separator the the output file in bse\temp directory. Each item will be written to a new line.

pralash
10th October 2017, 15:34
Thanks for your information...
Actually I read record from the table and also store a particular field in the text file...
But some additional value is automatically added with the end of the file as shown in the attachment... Also the records are not added one by one if I using the seq.put function...
Here is my script as follows.

function extern control.users.function()
{
file.name="c:\erpln\proj\users.txt"
file.pointer = seq.open(file.name, "w")

if file.pointer < 0 then
message("Can not find the file")
e = seq.close(file.pointer)
exit(1)
endif

select tccom200.user
from tccom200
where tccom200.stus="inactive"
selectdo
user.name=tccom200.user
seq.puts(strip$(shiftl$(user.name)),file.pointer)

selectempty

endselect
}
Can you please assist me to resolving this problem...
Thanks,
Pralash

JaapJD
10th October 2017, 15:37
You need to do this:

file.pointer = seq.open(file.name, "wt")

pralash
11th October 2017, 08:25
The issue is resolved right now...
Thanks a lot Jaapjd....
Regards,
Pralash

bdittmar
11th October 2017, 10:08
Hello,

seq.open()
Syntax:

function long seq.open (string file, string openmode, ref string pathnm)

Description

This opens a specified file. It uses the file $BSE/lib/fd ver.pack_combination to find the file. ver refers to a particular release of the software; pack_combination refers to a particular package combination (see pathname() ).

Arguments

string file The file name.

string openmode The mode in which the file must be opened. This can be one of the following options:

"r" Open for reading. The current file position is placed at the start of the file.
"w" Open for writing. The file is created if it does not already exist. The current file position is placed at the start of the file.
"a" Open for writing. The file is created if it does not already exist. The current file position is placed at the end of the file.

The file position is placed at end of the file before every write statement, even if the previous file action was a seq.seek().

"x" Open for writing. This is the same as "w", except that the function fails if the file already exists.
"r+" Same as "r", but the file can also be written to.
"w+" Same as "w", but the file can also be read.
"a+" Same as "a", but the file can also be read.
"x+" Same as "x", but the file can also be read.
Use the following modes to indicate whether the file is a binary or a text file. You can combine one of these modes with any one of the previous modes (for example, "rt+").
"b" Use for binary files. This is the default mode and need not be specified.
"t" The line separator(s) for text-files are different on Windows NT and UNIX systems. CRLF on the former; LF only on the latter. In addition, a Windows NT text file can include an EOF-character (^Z) that indicates the end of the file. This character should not be returned to a program reading the file.

So, you must specify the "t" option when reading from or writing to a text file on Windows NT systems (for example, "at+".) This ensures that line separators and EOF characters are handled correctly. Never use the "t" option when opening a binary file; on Windows NT systems this will corrupt the file data. The "t" option has no effect on UNIX systems.



ref string pathnm This returns the full path to the file.


Return values

>= 1 Success; File pointer returned for use in subsequent operations.
<1 Error; that is, the negative value of the system error (for example, for a permission error, the system returns 13 and the function returns -13, or if the internal table is full, the function returns -EAGAIN).


Regards

rohithdas
23rd September 2019, 12:55
( bse.tmp.dir$() ) |# Create temp file
how to create a temp file
on desktop or in becs
on desktop i created tempfile.text

mark_h
23rd September 2019, 17:24
I just create a temp file on the server. Then I user the server2client function to transfer the file to a location on the desktop.

DDPatel
26th August 2020, 09:14
I just create a temp file on the server. Then I user the server2client function to transfer the file to a location on the desktop.

Hii,

How server2client function is actually works?
How can i transfer that file from temp folder to other location (Users Location)?

Thanks in advance...
Regards,
DDPatel

andreas.toepper
26th August 2020, 09:31
Be aware that those client access functions are no longer working with LNUI.

This is a quote from the programmers guide:

client2server()
Syntax:
#include <bic_desktop>

function long client2server (string source, string dest, boolean text.mode [, boolean rm.file] [, boolean progress.window])

Description

Deprecated. This copies a specified file from the client to the server.


Arguments
string source The source file name, on the client. When this is an empty string, this function will show the file open dialog, through which the user can select an existing file on the client. The function get.local.filename() can be used afterwards to retrieve the actual filename on the client which was copied. The source parameter may include the string ${BSE_TMP} which indicates the ${BSE}\tmp directory in case of Baan Windows or Windows temp directory in case of WebUI.

string dest The destination file name, on the server.

boolean text.mode This is a boolean value that specifies whether the file is to be copied in text or binary mode:

true text mode

false binary mode

[boolean rm.file] Use this optional argument to specify whether the source file must be deleted after it has been copied:

true source file is deleted

false source file is not deleted

[boolean progress.window] Use this optional argument to specify whether a progress indicator must be displayed to indicate the progress of the copy action:

true progress indicator is displayed

false progress indicator is not displayed


Return values
0 File copy success.
1 Error. File copy canceled by the user.
<0 Error. Source file not copied to the destination file.

Context
This function is implemented in the 4GL Engine and can be used in all script types.

This function is marked as 'untrusted' and can therefore only be used in trusted objects. More about trusted and not trusted objects can be found in the section about managed execution..

Notes
In order to use a progress indicator, you must first create it with create.progress.indicator(). When you want the progress indicator to start with another value then 0, you must use change.progress.indicator() to change its initial value. If you specify the PROGRESS.STOP and/or PROGRESS.CANCEL modes when creating the indicator, the user can stop or cancel the copy operation before it has completed. In both cases, the destination file is deleted.
This function is not supported in LN UI. See the Implementing LN UI support for more information.
Example
create.progress.indicator("Title", PROGRESS.BAR + PROGRESS.STOP)
client2server
("C:\Program Files\Test.txt2", bse.tmp.dir$() &
"/test1.txt",
false, false, true)

GeekGirlAkshara
3rd September 2020, 08:36
How server2client function is actually works?
How can i transfer that file from temp folder to other location (Users Location)?


Hi!,
Function server2client copies a specified file from the server to the client.
I'm giving a small code snippet as an example for file creation and transfer using server2client function.


function create.file()
{
string server.input.file(100),server.output.file(100)
long fp.in,ret


server.input.file = creat.tmp.file$("$BSE/tmp/") & "File_Name.csv"
server.output.file = "c:\temp\File_Name.csv" |The desired path & file name of your client machine

fp.in = seq.open(server.input.file,"w+")

process.file() | Your Functionality

ret = seq.close(fp.in)

if get.ui.mode() = 1 then

server2client(server.input.file,server.output.file,1)
message("Report Generated") |If any
ret = app_start(server.output.file,"c:","","","")
else
client.download.file(server.input.file)
endif
}


Regards,
Akshara