Baanboard.com

Go Back   Baanboard.com > Forum > Baan SIGs > AFS/DDC/OLE: Function servers

User login

Frontpage Sponsor

Main

Poll
How big is your Baan-DB (just Data AND Indexes)
0 - 200 GB
18%
200 - 500 GB
29%
500 - 800 GB
3%
800 - 1200 GB
8%
1200 - 1500 GB
8%
1500 - 2000 GB
11%
> 2000 GB
24%
Total votes: 79

Baanboard at LinkedIn


Reference Content

Reply
 
Thread Tools Display Modes
  #1  
Old 24th December 2018, 06:13
tmannais's Avatar
tmannais tmannais is offline
Senior Member
 
Join Date: Jul 2017
Location: Thailand, Bangkok
Posts: 230
tmannais is on a distinguished road
Baan: LN 10.5, 10.6, 10.7 - DB: MSSQL - OS: Windows
[AFS] Change Output File path when printing in a device in type "Rewrite File"

Hi,

I currently have a device named "PDF" configured to device type "Rewrite File" to print out a file in PDF format at the destination that is set in the Output File.

The question is how can I use AFS to change the file name in the Output File and then print out to PDF device? Right now I already have a way to select the desired device but I cannot change the file name. How can I do that?

Regards,
Thana
Reply With Quote
  #2  
Old 27th December 2018, 16:47
mark_h's Avatar
mark_h mark_h is offline
Guru
 
Join Date: Sep 2001
Location: Kentucky, USA
Posts: 7,382
mark_h will become famous soon enough
Baan: Baan 4C4 A&D1 - DB: Oracle - OS: Sun Solaris
Not sure I get what you are saying - can't you just set the device and output file like below. Does the device let you change the output file?
Code:
                spool.device = "ASCIF"
                spool.fileout = creat.tmp.file$(bse.tmp.dir$())
__________________
Mark

GO Cards!
My latest mantra - make sure you have latest stpapi patches and the latest session object. If on LN then please explore the option of using DAL2 functionality.

Shared Solutions for Baan systems provided free by Baan Board.
Play the Google game and help Baanboard get better rankings. Do your part. Click here to find how.
Reply With Quote
  #3  
Old 3rd January 2019, 10:01
tmannais's Avatar
tmannais tmannais is offline
Senior Member
 
Join Date: Jul 2017
Location: Thailand, Bangkok
Posts: 230
tmannais is on a distinguished road
Baan: LN 10.5, 10.6, 10.7 - DB: MSSQL - OS: Windows
Can I have a whole example code on how to properly use the spool thing to print please?
Reply With Quote
  #4  
Old 3rd January 2019, 14:27
mark_h's Avatar
mark_h mark_h is offline
Guru
 
Join Date: Sep 2001
Location: Kentucky, USA
Posts: 7,382
mark_h will become famous soon enough
Baan: Baan 4C4 A&D1 - DB: Oracle - OS: Sun Solaris
I can get an example - but are you trying to do multiple reports to multiple files? On 4c4 that requires I use qkey to pass variables around to make sure it gets a new file name. In some cases (when reports are not needed) I just let them all run to the same file to delete it.
__________________
Mark

GO Cards!
My latest mantra - make sure you have latest stpapi patches and the latest session object. If on LN then please explore the option of using DAL2 functionality.

Shared Solutions for Baan systems provided free by Baan Board.
Play the Google game and help Baanboard get better rankings. Do your part. Click here to find how.
Reply With Quote
  #5  
Old 3rd January 2019, 14:48
mark_h's Avatar
mark_h mark_h is offline
Guru
 
Join Date: Sep 2001
Location: Kentucky, USA
Posts: 7,382
mark_h will become famous soon enough
Baan: Baan 4C4 A&D1 - DB: Oracle - OS: Sun Solaris
Example 1:

Library routine to print goods received notes.

Code:
|******************************************************************************
|* API Code for printing Goods Received Notes
|******************************************************************************
function extern print_goods_received(domain  tcorno	print.order,
				domain	tdpur.kofl	print.line.type,
				ref     string          msg())
{
	msg = ""

	stpapi.put.field("tdpur4410m000","orno.f",str$(print.order))
	stpapi.put.field("tdpur4410m000","orno.t",str$(print.order))
	stpapi.put.field("tdpur4410m000","date.t",str$(date.num()+5000))
	stpapi.put.field("tdpur4410m000","printed",str$(print.line.type))
|012304 - addition default fields to reset.
	stpapi.put.field("tdpur4410m000","selection",str$(tcyesno.no))
	stpapi.put.field("tdpur4410m000","suno.f","")
	stpapi.put.field("tdpur4410m000","suno.t","ZZZZZZ")
	stpapi.put.field("tdpur4410m000","comp.f",str$(0))
	stpapi.put.field("tdpur4410m000","comp.t",str$(999))
	stpapi.put.field("tdpur4410m000","tdpur999.dpas",str$(tcyesno.yes))
	stpapi.put.field("tdpur4410m000","prnt.clan",str$(tcyesno.yes))
	stpapi.put.field("tdpur4410m000","prnt.options",str$(tcyesno.no))
|012304	
	stpapi.set.report("tdpur4410m000","rtdpur441001000",spool.device,msg)
	if isspace(msg) then
		stpapi.continue.process("tdpur4410m000",msg)
		stpapi.get.mess.code("tdpur4410m000",msg)
	endif
	stpapi.end.session("tdpur4410m000")
}

Code that calls the library - this is a mash up since I did not want to post the whole script.
Code:
	check_print_goods_received()
	if print.good.rec then
		rpt = spool.open("rtdpur441001000",spool.device,1)
		if not rpt then
			choice.again()
		endif
		spool.close()
		print_goods_received(purchase.order,tdpur.kofl.inc.printed,errmsg)
		if not isspace(errmsg) then
			errmsg = ""
			print_goods_received(purchase.order,tdpur.kofl.inc.backorders,errmsg)
			if not isspace(errmsg) then
				message("Print Goods Received Notes" & errmsg)
				choice.again()
			endif
		endif
	endif


                get_defa_printer(prog.name$,tdpur040.cwar)
| 20041104.end
		if isspace(tdapi100.key2) then
		| Warehouse not found
			spool.device = "ASCIF"
			spool.fileout = creat.tmp.file$(bse.tmp.dir$())
		else
			spool.device = strip$(tdapi100.key2)
			if strip$(spool.device) = "ASCIF" then
				spool.fileout = creat.tmp.file$(bse.tmp.dir$())
			endif
		endif

|||******Part of the check_print_goods_received subroutine.
	if print.good.rec then
| 20041104.st
                if isspace(tdpur040.cwar) then
                        select	tdpur041.cwar
                        from	tdpur041
                        where	tdpur041._index1 = {:purchase.order}
                        as set with 1 rows
                        selectdo
                        endselect
                        tdpur040.cwar = tdpur041.cwar
                endif
                get_defa_printer(prog.name$,tdpur040.cwar)
| 20041104.end
		if isspace(tdapi100.key2) then
		| Warehouse not found
			spool.device = "ASCIF"
			spool.fileout = creat.tmp.file$(bse.tmp.dir$())
		else
			spool.device = strip$(tdapi100.key2)
			if strip$(spool.device) = "ASCIF" then
				spool.fileout = creat.tmp.file$(bse.tmp.dir$())
			endif
		endif
	endif

That get get_defa_printer(prog.name$,tdpur040.cwar) - what we have is a table that stores printers to be used for different sessions. So each warehouse they are receiving in has its own printer. Some warehouses or sites do not want the print good received notes so the table would basically return ASCIF and create a temp file to run the report into.
__________________
Mark

GO Cards!
My latest mantra - make sure you have latest stpapi patches and the latest session object. If on LN then please explore the option of using DAL2 functionality.

Shared Solutions for Baan systems provided free by Baan Board.
Play the Google game and help Baanboard get better rankings. Do your part. Click here to find how.
Reply With Quote
  #6  
Old 3rd January 2019, 15:12
mark_h's Avatar
mark_h mark_h is offline
Guru
 
Join Date: Sep 2001
Location: Kentucky, USA
Posts: 7,382
mark_h will become famous soon enough
Baan: Baan 4C4 A&D1 - DB: Oracle - OS: Sun Solaris
Here is one that I have to do in 2 phases because of limitations we have run into with spool.device and spool.fileout. What we found was even changing spool.device and spool.fileout the sessions you called would keep using the original spool.device and spool.fileout. So in a few places we have to do the import to get the changed device. You might not have this issue, but we do in our 4c4. We use old zebra printers and rmcis label maker.

This is in my print pick tag session:
Code:
choice.print.data:
on.choice:
|20070529.st For phased run of the session in api.mode
	import("tag.run.mode",tag.run.mode)
	if api.mode and tag.run.mode = 1 then
		import("spool.device",spool.device)
		import("spool.fileout",spool.fileout)
		import("tag.temp.file",tag.temp.file)
		temp.file = tag.temp.file
		rprt_open()
		set.reprint.flag()
		get.pick.tags()
		rprt_close()
		spool.close()
		return
	endif
| Have to run in two phases to print the tags because of spool.device
| Phase 2 runs and reads the temp file from phase 2
	if api.mode and tag.run.mode = 2 then
		import("spool.device",spool.device)
		import("spool.fileout",spool.fileout)
		import("tag.temp.file",tag.temp.file)
		tag.copies = spool.pr.copies
		temp.file = tag.temp.file
		real.tag.printer = spool.device
		print.the.tags()
		return
	endif			| 20070529.end


And here is the api code that calls it.
Code:
function extern print_pick_tags(	domain	tcmcs.str12	runnumber,
					domain  tcorno		run.order.f,
					domain  tcorno		run.order.t,
					domain	tcpono		run.opno.f,
					domain	tcpono		run.opno.t,
					domain	tcitem		run.item.f,
					domain	tcitem		run.item.t,
					domain	tccwar		run.cwar.f,
					domain	tccwar		run.cwar.t,
					domain	tcmcs.str15	run.report,
					ref     string          msg())
{
	long	hold.copies
| Create temp files for phase 1 to create the data.	
	tag.temp.file = creat.tmp.file$(bse.tmp.dir$())
	tag.temp.file = strip$(tag.temp.file)
	msg = ""
	real.tag.printer = spool.device
	hold.copies = spool.pr.copies
	spool.device = "INTERFACE"
	spool.fileout = tag.temp.file
	export("spool.device",spool.device)
	export("spool.fileout",spool.fileout)
	export("tag.temp.file",tag.temp.file)
	export("real.tag.printer",real.tag.printer)
	tag.run.mode = 1
	stpapi.put.field("tdilc9401m000","orno.f",str$(run.order.f))
	stpapi.put.field("tdilc9401m000","orno.t",str$(run.order.t))
	stpapi.put.field("tdilc9401m000","pono.f","0")
	stpapi.put.field("tdilc9401m000","pono.t","9999")
	stpapi.put.field("tdilc9401m000","opno.f",str$(run.opno.f))
	stpapi.put.field("tdilc9401m000","opno.t",str$(run.opno.t))
	stpapi.put.field("tdilc9401m000","prdt.f",str$(date.num()-5000))
	stpapi.put.field("tdilc9401m000","prdt.t",str$(date.num()+5000))
	stpapi.put.field("tdilc9401m000","run.f",runnumber)
	stpapi.put.field("tdilc9401m000","run.t",runnumber)
	stpapi.put.field("tdilc9401m000","gendate.f",str$(date.num()))
	stpapi.put.field("tdilc9401m000","gendate.t",str$(date.num()))
	stpapi.put.field("tdilc9401m000","item.f",run.item.f)
	stpapi.put.field("tdilc9401m000","item.t",run.item.t)
	stpapi.put.field("tdilc9401m000","cwar.f",run.cwar.f)
	stpapi.put.field("tdilc9401m000","cwar.t",run.cwar.t)
	stpapi.put.field("tdilc9401m000","reprint.tags", str$(tcyesno.no) )
|	stpapi.set.report("tdilc9401m000","rtdilc940115000",spool.device, msg )
	stpapi.set.report("tdilc9401m000",run.report,spool.device, msg )
	stpapi.continue.process("tdilc9401m000",msg)
	stpapi.end.session("tdilc9401m000")

| Phase 2 will print the data in the temp file from phase 1
	tag.run.mode = 2
	spool.pr.copies = hold.copies
	spool.device = real.tag.printer
	spool.fileout = ""
	export("spool.device",spool.device)
	export("spool.fileout",spool.fileout)
	export("tag.temp.file",tag.temp.file)
	export("real.tag.printer",real.tag.printer)
	stpapi.put.field("tdilc9401m000","orno.f",str$(run.order.f))
	stpapi.put.field("tdilc9401m000","orno.t",str$(run.order.t))
	stpapi.put.field("tdilc9401m000","pono.f","0")
	stpapi.put.field("tdilc9401m000","pono.t","9999")
	stpapi.put.field("tdilc9401m000","opno.f",str$(run.opno.f))
	stpapi.put.field("tdilc9401m000","opno.t",str$(run.opno.t))
	stpapi.put.field("tdilc9401m000","prdt.f",str$(date.num()-5000))
	stpapi.put.field("tdilc9401m000","prdt.t",str$(date.num()+5000))
	stpapi.put.field("tdilc9401m000","run.f",runnumber)
	stpapi.put.field("tdilc9401m000","run.t",runnumber)
	stpapi.put.field("tdilc9401m000","gendate.f",str$(date.num()))
	stpapi.put.field("tdilc9401m000","gendate.t",str$(date.num()))
	stpapi.put.field("tdilc9401m000","item.f",run.item.f)
	stpapi.put.field("tdilc9401m000","item.t",run.item.t)
	stpapi.put.field("tdilc9401m000","cwar.f",run.cwar.f)
	stpapi.put.field("tdilc9401m000","cwar.t",run.cwar.t)
	stpapi.put.field("tdilc9401m000","reprint.tags", str$(tcyesno.no) )
	stpapi.set.report("tdilc9401m000",run.report,spool.device, msg )
	stpapi.continue.process("tdilc9401m000",msg)
	stpapi.end.session("tdilc9401m000")

}
__________________
Mark

GO Cards!
My latest mantra - make sure you have latest stpapi patches and the latest session object. If on LN then please explore the option of using DAL2 functionality.

Shared Solutions for Baan systems provided free by Baan Board.
Play the Google game and help Baanboard get better rankings. Do your part. Click here to find how.
Reply With Quote
  #7  
Old 4th January 2019, 03:33
tmannais's Avatar
tmannais tmannais is offline
Senior Member
 
Join Date: Jul 2017
Location: Thailand, Bangkok
Posts: 230
tmannais is on a distinguished road
Baan: LN 10.5, 10.6, 10.7 - DB: MSSQL - OS: Windows
Thank you very much mark_h.
I will try your code and will give you feedback soon.
Reply With Quote
  #8  
Old 4th January 2019, 06:50
tmannais's Avatar
tmannais tmannais is offline
Senior Member
 
Join Date: Jul 2017
Location: Thailand, Bangkok
Posts: 230
tmannais is on a distinguished road
Baan: LN 10.5, 10.6, 10.7 - DB: MSSQL - OS: Windows
Here is what I got so far.

Code:
spool.device = "PDF"
spool.fileout = creat.tmp.file$(bse.tmp.dir$() & "\PDF")
stpapi.set.report(session.code, report.code, spool.device, error.msg)
stpapi.form.command(session.code, 5, "exec.cont.process", error.msg)
stpapi.form.command is used to execute the print because it is a print session.
It does generate a temp file into the folder PDF I created for this but the file has 0KB and does not have any extension with it. So it is not usable.
I don't know what I did wrong.
I tried using

Code:
spool.open(report.code, spool.device, 1)
spool.close()
but it gives the same result as above.
What I want is to have the result PDF file with specific file name (I will use variable for the file name).

Please kindly guide me on how to achieve this.
Reply With Quote
  #9  
Old 4th January 2019, 14:56
mark_h's Avatar
mark_h mark_h is offline
Guru
 
Join Date: Sep 2001
Location: Kentucky, USA
Posts: 7,382
mark_h will become famous soon enough
Baan: Baan 4C4 A&D1 - DB: Oracle - OS: Sun Solaris
Try whichever session you are running with the display. This way you can make sure you are getting a report. I know on some of my stuff a 0 byte file means no data found when running a report.
__________________
Mark

GO Cards!
My latest mantra - make sure you have latest stpapi patches and the latest session object. If on LN then please explore the option of using DAL2 functionality.

Shared Solutions for Baan systems provided free by Baan Board.
Play the Google game and help Baanboard get better rankings. Do your part. Click here to find how.
Reply With Quote
  #10  
Old 7th January 2019, 06:46
tmannais's Avatar
tmannais tmannais is offline
Senior Member
 
Join Date: Jul 2017
Location: Thailand, Bangkok
Posts: 230
tmannais is on a distinguished road
Baan: LN 10.5, 10.6, 10.7 - DB: MSSQL - OS: Windows
I printed to device D to test your concern about the order having to data to print. It actually has data to print and the report is correctly displayed in device display by printing it manually. It works for both device display and device PDF that I want to print it out to.

Now that the program still gives me the temp file that has 0 byte in it so I don't know what is wrong here.
Moreover, another issue that I need to resolve is that how can I change the file name?
It is now "tmp" with some number such as "tmp614619481" without any file extension.
Reply With Quote
  #11  
Old 7th January 2019, 11:06
tmannais's Avatar
tmannais tmannais is offline
Senior Member
 
Join Date: Jul 2017
Location: Thailand, Bangkok
Posts: 230
tmannais is on a distinguished road
Baan: LN 10.5, 10.6, 10.7 - DB: MSSQL - OS: Windows
I got a way to solve this problem now.
Since the PDF device of mine specifies the file name to print out with a static file name.
I just use file.cp() command to copy the file to another file and I can decide what the destination file will be named, which is my variables.
It is now working as expected.
Anyways, I want to thank you, mark_h, for helping me with the suggested solutions.

Last edited by tmannais : 7th January 2019 at 11:47.
Reply With Quote
  #12  
Old 7th January 2019, 15:34
mark_h's Avatar
mark_h mark_h is offline
Guru
 
Join Date: Sep 2001
Location: Kentucky, USA
Posts: 7,382
mark_h will become famous soon enough
Baan: Baan 4C4 A&D1 - DB: Oracle - OS: Sun Solaris
Thumbs up

Never even thought about the device having a static file name. We never use that feature for some reason. I am glad you found the solution.
__________________
Mark

GO Cards!
My latest mantra - make sure you have latest stpapi patches and the latest session object. If on LN then please explore the option of using DAL2 functionality.

Shared Solutions for Baan systems provided free by Baan Board.
Play the Google game and help Baanboard get better rankings. Do your part. Click here to find how.
Reply With Quote
Sponsored Links
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
Programming Question mr_suleyman Tools Development 37 11th November 2016 09:14
Audit file structure baan_user Tools Development 8 4th May 2007 15:32
How to print Postcript in landscape orientation heliopaixao Tools Administration & Installation 8 28th July 2006 14:39
seq.open berthe Miscellaneous 4 12th May 2005 11:20
Device file path RekhaJ Tools Development 3 26th February 2004 06:27


All times are GMT +2. The time now is 22:44.


©2001-2018 - Baanboard.com - Baanforums.com