PDFSpoolFileService Example

LANSA Integrator

PDFSpoolFileService Example

This function allows connection to an IBM i and converts the first 3 spool files from the nominated output queue to PDF documents on the root directory of the active JSM Instance.

  • The Server, User and Password are optional if the active JSM Server is located on the same IBM i you want to retrieve spool file information from.
  • If the User is NOT specified, the option of *ALL will be used to retrieve spool files.  THIS MAY BE A PERFORMANCE OVERHEAD IF YOU NOMINATE AN OUTPUT QUEUE WITH A LARGE NUMBER OF SPOOL FILES.

Modify the default values to be displayed to suit your site.

 

* Uses Integrator Services: PDFSPOOLFILESERVICE

 
* This function connects to an IBM i & converts
* the 1st 3 spool files from the nominated outq to PDF
* documents on the root dir of the active JSM Instance.

* Server, User & Password are optional if the active JSM
* Server is located on the same IBM i as spool files

* If the User is NOT specified the option of *ALL is used
* THIS MAY BE A PERFORMANCE OVERHEAD

* Modify the default values to suit your site.

* Beginning of RDML commands **********
FUNCTION OPTIONS(*DIRECT)

DEFINE FIELD(#JSMSTS) TYPE(*CHAR) LENGTH(020)
DEFINE FIELD(#JSMCMD) TYPE(*CHAR) LENGTH(255)
DEFINE FIELD(#JSMMSG) TYPE(*CHAR) LENGTH(255)

DEFINE FIELD(#JSMSERVER) TYPE(*char) LENGTH(20)
DEFINE FIELD(#JSMUSER) TYPE(*CHAR) LENGTH(010) LABEL('User')
DEFINE FIELD(#JSMPSSWRD) TYPE(*char) LENGTH(10)
DEFINE FIELD(#JSMLIB) TYPE(*CHAR) LENGTH(010) LABEL('Library')
DEFINE FIELD(#JSMOUTQ) TYPE(*char) LENGTH(10)

DEFINE FIELD(#FLENAM) TYPE(*CHAR) LENGTH(010)
DEFINE FIELD(#FLENUM) TYPE(*CHAR) LENGTH(006)
DEFINE FIELD(#JOBNAME) TYPE(*CHAR) LENGTH(10)
DEFINE FIELD(#JOBUSER) REFFLD(#JOBNAME)
DEFINE FIELD(#JOBNUMBER) TYPE(*CHAR) LENGTH(006)
DEFINE FIELD(#SPLFILSTS) TYPE(*CHAR) LENGTH(010)

DEFINE FIELD(#PDFKEY) TYPE(*CHAR) LENGTH(020)
DEFINE FIELD(#PDFVALUE) TYPE(*CHAR) LENGTH(050)

DEFINE FIELD(#DOCNME) TYPE(*CHAR) LENGTH(150)
DEFINE FIELD(#DOCCNT) TYPE(*DEC) LENGTH(003) DECIMALS(0)

DEF_LIST NAME(#PDFLST) FIELDS((#PDFKEY *INP) (#PDFVALUE *INP)) TYPE(*WORKING)

DEF_LIST NAME(#SPOOLLST) FIELDS(#FLENAM #FLENUM #JOBNAME #JOBUSER #JOBNUMBER #SPLFILSTS) COUNTER(#LISTCOUNT) TYPE(*WORKING) ENTRYS(0009999)

* set default values for screen
CHANGE FIELD(#STD_INSTR) TO('''Set your appropriate information then press ENTER to generate PDF files''')
CHANGE FIELD(#JSMSERVER) TO(ISERIES01)
CHANGE FIELD(#JSMUSER) TO(USER)
CHANGE FIELD(#JSMPSSWRD) TO(PASSWORD)
CHANGE FIELD(#JSMLIB) TO(QUSRSYS)
CHANGE FIELD(#JSMOUTQ) TO(QEZJOBLOG)

* Connect to JSM Server
USE BUILTIN(JSM_OPEN) TO_GET(#JSMSTS #JSMMSG)
EXECUTE SUBROUTINE(CHECK) WITH_PARMS(#JSMSTS #JSMMSG)

* Load the PDF service
CHANGE FIELD(#JSMCMD) TO('SERVICE_LOAD SERVICE(PDFSPOOLFILESERVICE) TRACE(*YES)')
USE BUILTIN(JSM_COMMAND) WITH_ARGS(#JSMCMD) TO_GET(#JSMSTS #JSMMSG)
EXECUTE SUBROUTINE(CHECK) WITH_PARMS(#JSMSTS #JSMMSG)
MESSAGE MSGTXT('PDFSpoolFileService loaded')

BEGIN_LOOP

* Format and Process JSM commands
REQUEST FIELDS((#STD_INSTR *L004 *P002 *OUTPUT *NOID) (#JSMSERVER *L007 *P026) (#JSMUSER *L009 *P026) (#JSMPSSWRD *L011 *P026) (#JSMLIB *L13 *P26) (#JSMOUTQ *L15 *P26)) IDENTIFY(*LABEL) EXIT_KEY(*NO) MENU_KEY(*YES *NEXT) PROMPT_KEY(*NO)

IF_KEY WAS(*MENU)

* Close service
EXECUTE SUBROUTINE(DISCONNECT)
MENU

ENDIF

* Connect to IBM i server
EXECUTE SUBROUTINE(CONNECT)

* Get list of spool files to process
EXECUTE SUBROUTINE(LIST)

* Create PDF files
EXECUTE SUBROUTINE(PDF)

END_LOOP


* Connect to host database
SUBROUTINE NAME(CONNECT)

* Connect to the required IBM i host
USE BUILTIN(TCONCAT) WITH_ARGS('CONNECT HOST(' #JSMSERVER ') USER(' #JSMUSER ') PASSWORD(') TO_GET(#JSMCMD)
USE BUILTIN(TCONCAT) WITH_ARGS(#JSMCMD #JSMPSSWRD ')') TO_GET(#JSMCMD)
USE BUILTIN(JSM_COMMAND) WITH_ARGS(#JSMCMD) TO_GET(#JSMSTS #JSMMSG)
EXECUTE SUBROUTINE(CHECK) WITH_PARMS(#JSMSTS #JSMMSG)
MESSAGE MSGTXT('JSM Server connected')

ENDROUTINE

* Generate a list of spool files from selected location
SUBROUTINE NAME(LIST)

MESSAGE MSGTXT('Searching output queue ...') TYPE(*STATUS)
USE BUILTIN(TCONCAT) WITH_ARGS('LIST LIBRARY(' #JSMLIB ') QUEUE(' #JSMOUTQ ') USER(') TO_GET(#JSMCMD)

IF COND('#JSMUSER *NE *BLANK')
USE BUILTIN(TCONCAT) WITH_ARGS(#JSMCMD #JSMUSER) TO_GET(#JSMCMD)
ELSE
USE BUILTIN(TCONCAT) WITH_ARGS(#JSMCMD '*ALL') TO_GET(#JSMCMD)
ENDIF

USE BUILTIN(TCONCAT) WITH_ARGS(#JSMCMD ') USERDATA(*ALL) FORMTYPE(*STD) SERVICE_LIST(' 'FLENAM, FLENUM, JOBNAME, JOBUSER, JOBNUMBER, ' 'SPLFILSTS)') TO_GET(#JSMCMD)
USE BUILTIN(JSM_COMMAND) WITH_ARGS(#JSMCMD) TO_GET(#JSMSTS #JSMMSG #SPOOLLST)
EXECUTE SUBROUTINE(CHECK) WITH_PARMS(#JSMSTS #JSMMSG)
MESSAGE MSGTXT('List of spool files generated')

ENDROUTINE

* Create a PDF file from selected spool file
SUBROUTINE NAME(PDF)

MESSAGE MSGTXT('PDFs files being generated ...') TYPE(*STATUS)

* Create an entry for each consistent keyword
CLR_LIST NAMED(#PDFLST)
EXECUTE SUBROUTINE(ADDKEYWRD) WITH_PARMS(JOBNUMBER #JOBNUMBER)
EXECUTE SUBROUTINE(ADDKEYWRD) WITH_PARMS(AUTHOR 'LANSAUSER')
EXECUTE SUBROUTINE(ADDKEYWRD) WITH_PARMS(TITLE 'PDF example created using PDFSpoolFileService')
EXECUTE SUBROUTINE(ADDKEYWRD) WITH_PARMS(SUBJECT 'Generated by LANSA SUPPLIED Test Function')
EXECUTE SUBROUTINE(ADDKEYWRD) WITH_PARMS(CREATOR *FUNCTION)
EXECUTE SUBROUTINE(ADDKEYWRD) WITH_PARMS(PAGESIZE '*A4')
EXECUTE SUBROUTINE(ADDKEYWRD) WITH_PARMS(MARGIN '15')
CHANGE FIELD(#DOCCNT) TO(0)

SELECTLIST NAMED(#SPOOLLST)

* build a unique PDF file name
CHANGE FIELD(#DOCCNT) TO('#DOCCNT + 1')
SUBSTRING FIELD(#DOCCNT) INTO_FIELD(#DOCNME)
USE BUILTIN(TCONCAT) WITH_ARGS('PDFTST' #DOCNME '.pdf') TO_GET(#DOCNME)

* Build the CREATE command using list details
USE BUILTIN(TCONCAT) WITH_ARGS('CREATE SERVICE_LIST(PDFKEY,PDFVALUE) DOCUMENT(' #DOCNME ') NAME(' #FLENAM ') NUMBER(') TO_GET(#JSMCMD)
USE BUILTIN(TCONCAT) WITH_ARGS(#JSMCMD #FLENUM ') JOBNAME(' #JOBNAME ') JOBUSER(') TO_GET(#JSMCMD)
USE BUILTIN(TCONCAT) WITH_ARGS(#JSMCMD #JOBUSER ')') TO_GET(#JSMCMD)

* Create PDF
USE BUILTIN(JSM_COMMAND) WITH_ARGS(#JSMCMD) TO_GET(#JSMSTS #JSMMSG #PDFLST)
EXECUTE SUBROUTINE(CHECK) WITH_PARMS(#JSMSTS #JSMMSG)
USE BUILTIN(BCONCAT) WITH_ARGS('PDF document' #DOCNME 'created') TO_GET(#STD_TEXTL)
MESSAGE MSGID(DCM9899) MSGF(DC@M01) MSGDTA(#STD_TEXTL)

* Only create PDF files for first 3 spool files
LEAVE IF('#DOCCNT = 3')

ENDSELECT

ENDROUTINE

SUBROUTINE NAME(DISCONNECT)

* Unload service
USE BUILTIN(JSM_COMMAND) WITH_ARGS('SERVICE_UNLOAD') TO_GET(#JSMSTS #JSMMSG)
USE BUILTIN(JSM_CLOSE) TO_GET(#JSMSTS #JSMMSG)

* Close service
USE BUILTIN(JSM_CLOSE) TO_GET(#JSMSTS #JSMMSG)
EXECUTE SUBROUTINE(CHECK) WITH_PARMS(#JSMSTS #JSMMSG)

ENDROUTINE

* Keywords to list
SUBROUTINE NAME(ADDKEYWRD) PARMS((#PDFKEY *RECEIVED) (#PDFVALUE *RECEIVED))

ADD_ENTRY TO_LIST(#PDFLST)

ENDROUTINE

* Check the JSM return status
SUBROUTINE NAME(CHECK) PARMS((#JSMSTS *RECEIVED) (#JSMMSG *RECEIVED))

IF COND('#JSMSTS *NE OK')

USE BUILTIN(TCONCAT) WITH_ARGS(#JSMSTS ' : ' #JSMMSG) TO_GET(#STD_TEXTL)
MENU MSGID(DCM9899) MSGF(DC@M01) MSGDTA(#STD_TEXTL)

ENDIF

ENDROUTINE

* End of RDML commands **********