PDFSpoolFileService Example
This form opens the default JSM Instance and then explicitly connects to an IBM i to retrieve the relevant spool file information. Refer to commented code for an alternative approach, namely to explicitly OPEN the JSM Server on IBM i and then use an unqualified CONNECT statement to connect to the same machine.
Modify the default values to be displayed to suit your site.
* Uses Integrator Services: PDFSpoolFileService
* This form connects to an IBM i server to retrieve detail of the spool files in a nominated outq.
* A spool file can then be selected to convert to a PDF file. This form also deletes PDF files.
*
* The following fields must be defined in your data dictionary to support this function:
* filname *CHAR 10
* filnbr *CHAR 6
* jobname *CHAR 10
* jobuser *CHAR 10
* jobnbr *CHAR 6
* status *CHAR 10
* jsmserver *CHAR 10
* jsmpsswrd *CHAR 10
* jsmuserid *CHAR 10
* jsmoutq *CHAR 10
* jsmsts alpha 20
* jsmmsg alpha 255
* jsmhdle char 500
* jsmcmd alpha 4
function options(*DIRECT)
begin_com role(*EXTENDS #PRIM_FORM) clientheight(573) clientwidth(692) framestyle(Dialog) height(607) left(441) top(129) width(700)
define_com class(#jsmserver.Visual) name(#jsmserver) displayposition(1) height(19) left(9) marginleft(50) parent(#GPBX_1) tabposition(1) top(13) usepicklist(False) width(150)
define_com class(#jsmuserid.Visual) name(#jsmuserid) displayposition(2) left(169) marginleft(50) parent(#GPBX_1) tabposition(2) top(13) width(150)
define_com class(#jsmpsswrd.Visual) name(#jsmpsswrd) displayposition(3) left(329) marginleft(50) parent(#GPBX_1) tabposition(3) top(13) width(150)
define_com class(#jsmoutq.Visual) name(#jsmoutq) displayposition(4) height(19) left(489) marginleft(70) parent(#GPBX_1) tabposition(4) top(13) usepicklist(False) width(150)
define_com class(#jsmpdfdoc.Visual) name(#jsmpdfdoc) displayposition(1) left(9) parent(#GPBX_2) tabposition(1) top(18)
define_com class(#PRIM_PHBN) name(#GetSpoolFiles) caption('Connect + Get Spool File details') displayposition(1) left(5) parent(#PANL_2) tabposition(1) top(5) width(180)
define_com class(#PRIM_PHBN) name(#ConvertPDF) caption('Convert to PDF') displayposition(2) enabled(False) left(190) parent(#PANL_2) tabposition(2) top(5) width(120)
define_com class(#PRIM_PHBN) name(#Disconnect) caption('Disconnect') displayposition(4) enabled(False) left(440) parent(#PANL_2) tabposition(4) top(5) width(120)
define_com class(#PRIM_PHBN) name(#DeletePDF) caption('Delete PDF') displayposition(3) enabled(False) left(315) parent(#PANL_2) tabposition(3) top(5) width(120)
define_com class(#PRIM_STBR) name(#stbr_1) displayposition(1) height(24) left(0) messageposition(1) parent(#PANL_1) tabposition(1) tabstop(False) top(77) width(692)
define_com class(#PRIM_GPBX) name(#GPBX_1) caption('Connect to ') displayposition(1) height(45) left(0) parent(#COM_OWNER) tabposition(1) tabstop(False) top(0) width(692)
define_com class(#PRIM_GPBX) name(#GPBX_2) caption('PDF file details ') displayposition(2) height(45) left(0) parent(#COM_OWNER) tabposition(2) tabstop(False) top(47) width(692)
define_com class(#PRIM_PANL) name(#PANL_1) displayposition(4) height(101) left(0) parent(#COM_OWNER) tabposition(4) tabstop(False) top(472) width(692)
define_com class(#PRIM_PANL) name(#PANL_2) displayposition(2) height(34) left(5) parent(#PANL_1) tabposition(2) tabstop(False) top(34) width(692)
define_com class(#PRIM_LTVW) name(#LTVW_1) componentversion(1) displayposition(3) fullrowselect(True) height(378) left(0) parent(#COM_OWNER) tabposition(3) top(94) width(692)
define_com class(#PRIM_LVCL) name(#LvCL_1) componenttag('File Name') displayposition(1) parent(#LTVW_1) source(#FILNAME) width(18)
define_com class(#PRIM_LVCL) name(#LvCL_2) componenttag('File Number') displayposition(2) parent(#LTVW_1) source(#FILNBR) width(14)
define_com class(#PRIM_LVCL) name(#LvCL_3) componenttag('Job Name') displayposition(3) parent(#LTVW_1) source(#JOBNAME) width(18)
define_com class(#PRIM_LVCL) name(#LvCL_4) componenttag('Job User') displayposition(4) parent(#LTVW_1) source(#JOBUSER) width(18)
define_com class(#PRIM_LVCL) name(#LvCL_5) componenttag('Job Number') displayposition(5) parent(#LTVW_1) source(#JOBNBR) width(14)
define_com class(#PRIM_LVCL) name(#LvCL_6) componenttag('Status') displayposition(6) parent(#LTVW_1) source(#STATUS) width(18) widthtype(MinRemainder)
def_list name(#spoollst) fields(#filname #filnbr #jobname #jobuser #jobnbr #status) type(*WORKING) entrys(0000500)
evtroutine handling(#com_owner.Initialize)
set com(#com_owner) caption(*component_desc)
#jsmhdle := *default
* default values
#jsmserver := '<server>'
#jsmuserid := '<user id>'
#jsmpsswrd := '<password>'
#jsmoutq := '<outq>'
#jsmpdfdoc := mypdfdoc01.pdf
#jsmserver.SetFocus
endroutine
mthroutine name(Connect)
if (#jsmhdle.IsNull)
* connect the JSMX client to the Java Service Manager and start a thread for the service
* Start JSM Server on IBM i
* use builtin(jsmx_open) with_args('LANSA04:4570') to_get(#jsmsts #jsmmsg #jsmhdle)
* Start local JSM server
use builtin(jsmx_open) to_get(#jsmsts #jsmmsg #jsmhdle)
#com_owner.check( #jsmsts #jsmmsg )
* Load the service
#jsmcmd := 'service_load service(pdfspoolfileservice)'
use builtin(jsmx_command) with_args(#jsmhdle #jsmcmd) to_get(#jsmsts #jsmmsg)
#com_owner.check( #jsmsts #jsmmsg )
* If connected to IBM i JSM Server can use CONNECT w/o parms
* #jsmcmd := 'Connect '
* connect to the IBM i host if running local JSM Server
#jsmcmd := 'Connect Host(' + #jsmserver + ') User(' + #jsmuserid + ') password(' + #jsmpsswrd + ')'
use builtin(jsmx_command) with_args(#jsmhdle #jsmcmd) to_get(#jsmsts #jsmmsg)
#com_owner.check( #jsmsts #jsmmsg )
endif
endroutine
mthroutine name(ListSpoolFiles)
* Retrieve all spool files created by the nominated user with a *STD formtype
* #jsmcmd := 'List Library(qusrsys) queue(' + #jsmoutq + ') user(' + #jsmuserid + ') userdata(*ALL) formtype(*STD) service_list(flenam, flenum, jobname, jobuser, jobnumber, status)'
#jsmcmd := 'List Library(qusrsys) queue(' + #jsmoutq + ') user(' + #jsmuserid + ') userdata(*ALL) formtype(*STD)'
use builtin(jsmx_command) with_args(#jsmhdle #jsmcmd) to_get(#jsmsts #jsmmsg #spoollst)
#com_owner.check( #jsmsts #jsmmsg )
clr_list named(#ltvw_1)
selectlist named(#spoollst)
add_entry to_list(#ltvw_1)
endselect
endroutine
mthroutine name(Convert)
* add variables for any additional keywords you need to modify
#jsmcmd := 'Create document(' + #jsmpdfdoc + ') name(' + #filname + ') number(' + #filnbr + ') jobname(' + #jobname + ') jobuser(' + #jobuser + ') jobnumber(' + #jobnbr + ') author(' + jsmuserid + ') fontsize(8) leading(8.5) orientation(*landscape) margin(0, 50,50,50) service_list(pdfkey,pdfvalue)'
use builtin(jsmx_command) with_args(#jsmhdle #jsmcmd) to_get(#jsmsts #jsmmsg #spoollst)
#com_owner.check( #jsmsts #jsmmsg )
endroutine
mthroutine name(DeletePDFFile)
* delete tje nominated PDF file
#jsmcmd := 'Delete File(' + #jsmpdfdoc + ')'
use builtin(jsmx_command) with_args(#jsmhdle #jsmcmd) to_get(#jsmsts #jsmmsg #spoollst)
#com_owner.check( #jsmsts #jsmmsg )
endroutine
mthroutine name(DisConnect)
if (#jsmhdle <> *blank)
* disconnect from IBM i host
use builtin(jsmx_command) with_args(#jsmhdle disconnect) to_get(#jsmsts #jsmmsg)
#com_owner.check( #jsmsts #jsmmsg )
* unload the service
use builtin(jsmx_command) with_args(#jsmhdle service_unload) to_get(#jsmsts #jsmmsg)
#com_owner.check( #jsmsts #jsmmsg )
* Close the thread
use builtin(jsmx_close) with_args(#jsmhdle) to_get(#jsmsts #jsmmsg)
#jsmhdle := *null
endif
endroutine
* check the JSM return status
mthroutine name(check)
define_map for(*input) class(#jsmsts) name(#i_status)
define_map for(*input) class(#jsmmsg) name(#i_message)
message msgtxt(#i_status + ' : ' + #i_message)
endroutine
evtroutine handling(#GetSpoolFiles.Click)
#com_owner.Connect
if (#jsmsts = OK)
#com_owner.ListSpoolFiles
#getspoolFiles.enabled := false
#ConvertPDF.enabled := true
#disconnect.enabled := true
#DeletePDF.enabled := true
endif
endroutine
evtroutine handling(#ConvertPDF.Click)
#com_owner.Convert
#getspoolFiles.enabled := false
#ConvertPDF.enabled := true
#disconnect.enabled := true
#DeletePDF.enabled := true
endroutine
evtroutine handling(#Disconnect.Click)
#com_owner.DisConnect
#getspoolFiles.enabled := true
#ConvertPDF.enabled := false
#disconnect.enabled := false
#DeletePDF.enabled := false
endroutine
evtroutine handling(#DeletePDF.Click)
#com_owner.DeletePDFFile
#getspoolFiles.enabled := false
#ConvertPDF.enabled := true
#disconnect.enabled := true
#DeletePDF.enabled := true
endroutine
end_com