Step 4. Create Function iiiFN15 - Create PDF Output for Employees

INT013 - Create PDF Output using PDFDocumentService

In this step you will copy function iiiFN14 and extend it to output a PDF document for a single or multiple employees, selected by employee number, department or surname.

The new RDMLX function iiiFN15, which will be called by form iiiFRM08 – Test Employee PDF Output, will allow the user to enter STD_FLAG, EMPNO, DEPTMENT and SURNAME, then EXCHANGE these values and call function iiiFN15.

A practical consideration is that the form iiiFRM08, will validate EMPNO against the file PSLMST. Function iiiFN15, when called passing EMPNO, the employee number will always be valid and iiiFN15 will therefore always output a PDF document and the document should be closed.

When function iiiFN15 is called passing DEPTMENT or SURNAME to produce a one or more page PDF document, there may be no output. Closing the PDF document conditionally will avoid writing an empty pdf document.

1.  Copy function iiiFN14 to create an RDMLX enabled function iiiFN15 in process iiiPRO11.

2.  Delete these two lines from the top of the function

#empno := A1009

#rep1page := 1

3.  Locate the * Add Footers comment line. Create a FOOTER subroutine and move add footers logic into it. Your code should look like the following

Subroutine Name(FOOTER)

Clr_list #FOOTER1

Add_entry #FOOTER1

#jsmxcmd := 'ADD CONTENT(FOOTER1)'

Use Builtin(JSMX_COMMAND) With_Args(#JSMXHDLE1 #JSMXCMD #FOOTER1) To_Get(#JSMSTS #JSMMSG)

Execute Subroutine(CHECK_STS) With_Parms(#JSMXHDLE1)

Endroutine

 

4.  Add an EXECUTE subroutine to replace the code moved into the subroutine. Your code should look like the following:

* Add Footers

EXECUTE Subroutine(FOOTER)

5.  Locate the * Close document comment. Create a CLOSE subroutine, and move the code shown into it:

Subroutine Name(CLOSE)

#jsmxcmd := CLOSE

Use Builtin(JSMX_COMMAND) With_Args(#JSMXHDLE1 #JSMXCMD) To_Get(#JSMSTS #JSMMSG)

Execute Subroutine(CHECK_STS) With_Parms(#JSMXHDLE1)

#rep1page -= 1

Message Msgtxt('Employees PDF Report produced with ' + #rep1page.asstring + ' pages')

* Unload PDF Service

#jsmxcmd := SERVICE_UNLOAD

Use Builtin(JSMX_COMMAND) With_Args(#JSMXHDLE1 #JSMXCMD) To_Get(#JSMSTS #JSMMSG)

Execute Subroutine(CHECK_STS) With_Parms(#JSMXHDLE1)

* Close the JSM

Use Builtin(JSMX_CLOSE) With_Args(#jsmxhdle1) To_Get(#JSMSTS #JSMMSG)

Execute Subroutine(CHECK_STS) With_Parms(#JSMXHDLE1)

Endroutine

 

6.  Add an Execute subroutine to replace the code moved into the subroutine. Your code should look like the following:

* Close document

EXECUTE Subroutine(CLOSE)

7.  Function iiiFN15 will receive fields EMPNO, DEPTMENT, SURNAME and STD_FLAG. STD_FLAG will contain the search request type, E=Employee Number, D=Department Code, S=Surname search.

8.  Add a case loop for STD_FLAG around your existing single employee logic. The new code is shown in red. For example:

Case Of_Field(#STD_FLAG)

* Search for single employee number

When (= E)

* Add Logo

Change Field(#JSMXCMD) To('ADD CONTENT(LOGO) ')

Use Builtin(JSMX_COMMAND) With_Args(#JSMXHDLE1 #JSMXCMD) To_Get(#JSMSTS #JSMMSG)

Execute Subroutine(CHECK_STS) With_Parms(#JSMXHDLE1)

. . . . . . . . . .

. . . . . . . . . .

* Add Footer

Execute Subroutine(FOOTER1)

* Close the PDF Document and the PDF Service

Execute Subroutine(CLOSE)

Endcase

 

9.  At the top of the function, define a work field OUTSTS based on field IO$STS. This field will be used to control whether the PDF document should be closed, because output was produced.

10. Your existing CASE loop handles a single employee only. The CASE loop should now be extended by adding the next WHEN condition below EXECUTE FOOTER for the single employee. Copy the code to handle search by surname and search by department which is supplied in INT013 - Appendix C.

11. Save your changes.

12. Review the logic just added, for STD_FLAG = S and STD_FLAG = D:

13. Compile function iiiFN15 and correct errors if necessary.

14. If running functions on the IBM i server, check in and compile on the server.