Step 4 Create Function iiiFN17 Create PDF Output for Employees

LANSA Integrator

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

INT013 - Create PDF Output using PDFDocumentService

In this step you will copy function iiiFN16 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 iiiFN17, will be called by an RDML function iiiFN18 – Test Employee PDF Output, which will input STD_FLAG, EMPNO, DEPTMENT and SURNAME, then EXCHANGE these values and call function iiiFN17.

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

When function iiiFN17 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 iiiFN16 to create an RDMLX enabled function iiiFN17 in process iiiPRO10.

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

#empno := A0090

 

#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 iiiFN17 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:

  • Page number, REP1PAGE is incremented after output for each employee.
  • OUTSTS is used to control the CLOSE of the PDF document, to avoid writing an empty PDF document. OUTSTS is set to OK when output has been produced for one or more employees. An alternative if no employees are output, could be to write a page containing the text "No employee details found".
  • The PDF XML template contains <page orientation="landscape"/> in the FOOTER1 content, which starts a new page for the next employee output.

13. Compile function iiiFN17 and correct errors if necessary.

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