tmannais
24th December 2018, 06:13
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
mark_h
27th December 2018, 16:47
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?
spool.device = "ASCIF"
spool.fileout = creat.tmp.file$(bse.tmp.dir$())
tmannais
3rd January 2019, 10:01
Can I have a whole example code on how to properly use the spool thing to print please?
mark_h
3rd January 2019, 14:27
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_h
3rd January 2019, 14:48
Example 1:
Library routine to print goods received notes.
|******************************************************************************
|* 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.
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_h
3rd January 2019, 15:12
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:
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.
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")
}
tmannais
4th January 2019, 03:33
Thank you very much mark_h.
I will try your code and will give you feedback soon.
tmannais
4th January 2019, 06:50
Here is what I got so far.
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
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.
mark_h
4th January 2019, 14:56
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.
tmannais
7th January 2019, 06:46
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.
tmannais
7th January 2019, 11:06
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.
mark_h
7th January 2019, 15:34
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.