Ash Gajjar
28th July 2015, 11:51
Over the years, I have managed not to use an external file output, due to the Baan report limitation of 255 characters...... until now :(

I have scoured the forum for some guidance, seems straight-forward
I have some questions though;

1. My motive is to output to a csv file. IS this ok?
2. I do not used any report scripts, thus assuming that I can open, write and close the seq file in the program script?
3. Does an empty seq file have to be present when running the script?

Any pointers would be gratefully appreciated. I have never used this technique before :confused:

Reg
ash

bdittmar
28th July 2015, 13:00
Over the years, I have managed not to use an external file output, due to the Baan report limitation of 255 characters...... until now :(

I have scoured the forum for some guidance, seems straight-forward
I have some questions though;

1. My motive is to output to a csv file. IS this ok?
2. I do not used any report scripts, thus assuming that I can open, write and close the seq file in the program script?
3. Does an empty seq file have to be present when running the script?

Any pointers would be gratefully appreciated. I have never used this technique before :confused:

Reg
ash

Hello,
1st :
CSV is only a semicolon separated fileformat as abc;def;ghi;123;rst....
2nd:
SEQ functions also can be used in session script.
3rd:
No, 1st you'll create the empty file by seq.open() and put the lines in with seq.puts() and close the file with seq.close().
Refer to the SEQ... functions in DEV-Guide !

Example as attachment.
Used in include for a LN-Interface called from userexits.
(creates a file for NAGIOS system monitoring)

Regards

Ash Gajjar
28th July 2015, 13:13
Thank you Bernard, will dive into the Dev manual also

PS: Just noticed the attached example, Thank you!

bhushanchanda
28th July 2015, 13:20
Hi,

Here's a sample -

string file.name(100)
long fp
long rc
string strseq(1500)


file.name = "my_file.csv"
fp = seq.open(file.name,"w")
|# This will create the file if doesn't exists. If its
|#Unix server, it will create a file in users home folder. Else, if its windows |#server, you can provide a path like file.name = "C:\temp\my_file.csv" and
|#make sure you have full permissions

if fp < 1 then
message("Error %d opening log file [{%s]. Aborting..",
fp, file.name)
exit()
endif

strseq = "Code,Description"
rc = seq.puts(strseq, fp)

strseq = "001,Alex"
rc = seq.puts(strseq, fp)

strseq = "002,Mike"
rc = seq.puts(strseq, fp)

rc = seq.close(fp) |# This will close the file

server2client(file.name,"C:\temp\my_file.csv",true) |# This will transfer the file to client machine

|# User start.application.local() to open the file in required application i.e. excel or notepad

Ash Gajjar
30th July 2015, 16:22
Hi Bhushan,
Thank you, getting most of my fields ( string format) to output fine.

I am still left with a problem converting date and UTC to string
For date field, I am using:
edit$(date.to.inputstr$(terms.expire.on, "%D002,3", 8)

for UTC, I am using:
edit$(utc.to.inputstr$(terms.start, "%U001,3)

Complies ok, but both returning errors

/ash

bhushanchanda
30th July 2015, 16:26
Hi,

Use sprintf$()

Try this -

strseq = sprintf$("%u(%02m/%02d/%04Y)",tdpur401.invd) & ","
& tdpur401.rcno & ","
& str$(tdpur401.rseq) & chr$(34)
rc = seq.puts(strseq, fp)

Ash Gajjar
3rd August 2015, 11:07
Thank you Bhushan!

Your code worked perfectly for UTC dates, but does not return correct date for 'date' fields.
See the highlighted columns.

Appreciate your assistance so far

ash

bhushanchanda
3rd August 2015, 11:11
Hi,

Look at the programmers guide for more info.

sprintf$() (http://www.baanboard.com/programmers_manual_baanerp_help_functions_formatting_io_sprintf)

For Date fields use this -

sprintf$("%D(%02m/%02d/%04Y)", date.num())

Ash Gajjar
5th August 2015, 13:32
Thank you Bhushan.

I can now create a temp file in $BSE/temp (we have unix) or can kickstart Excel without any problem.

My final issue is that I am going to run the script in batch, so need to specify the exact file name and directory.
At the moment, I just use creat.tmp.file$( bse.tmp.dir$() ) to create the file. However, in my production environemnt, I will need to place the file (say file.out) in a directory called baanrpt. I am failing to get this resolved

Reg
Ash

bhushanchanda
5th August 2015, 13:41
Hi,

Just declare a variable say file.name

string file.name(100)

file.name = "/path/my_file.csv"

fp = seq.open(file.name,"w+")

Make sure you have full permissions to the folder.

Ash Gajjar
10th August 2015, 09:14
Thank you Bhushan, it all now ties up nicely. :):):)

All your guidance much appreciated
ash