Step 1. Create a Trigger Function

FRM105 - A Trigger Function

In this step you will create a file level trigger function for file PSLMST using a template. You will complete the trigger function based on the code supplied in Appendix A. FRM105.

Note that you must change the email recipient to an email address to which you have access.

1.  Create a Process iiiPRO02 – iii Trigger Functions

2.  Create a new function iiiFN03 – Employee Salary Trigger, using template BBFILTRIG for file PSLMST

3.  Remove all CASE, WHEN clauses except BEFUPD. Your code should look like the following:

Function Options(*DIRECT *NOMESSAGES *LIGHTUSAGE *MLOPTIMISE) Rcv_List(#TRIG_LIST) Trigger(*FILE PSLMST)
Def_List Name(#TRIG_LIST) Type(*WORKING) Entrys(2)
* Assume a "good" return initially
Change Field(#TRIG_RETC) To('OK')
Case Of_Field(#TRIG_OPER)
* Handle a before update event
When Value_Is('= BEFUPD')
* Handle an event not catered for
Otherwise
Abort Msgtxt('File PSLMST trigger function invalidly invoked/ used.')
Endcase
* Return control to the invoker
Return

 

     Note: Comment lines have been removed.

4.  Complete most of the trigger logic by copying the code provided in FRM105 Appendix A. FRM105 These subroutines should be pasted after the Return command.

     Change this statement to use your own email address:

#std_textl := 'SMTP:[email protected]'

5.  Review the supplied code.

6.  Change the email recipient address to be any email address to which you have access.

7.  Your email client may also require that the email originator address is a recognized address. Change this if necessary.

8.  Complete the BEFUPD logic:

Notes:

     Your own trigger code should look like the following and is followed by the supplied subroutines (see 4. above)

Function Options(*DIRECT *NOMESSAGES *LIGHTUSAGE *MLOPTIMISE) Rcv_List(#TRIG_LIST) Trigger(*FILE PSLMST)

Def_List Name(#TRIG_LIST) Type(*WORKING) Entrys(2)

Change Field(#TRIG_RETC) To('OK')

Define Field(#Phonebusw) Reffld(#PhoneBus)

Case Of_Field(#TRIG_OPER)
* Handle an before update event
When Value_Is('= BEFUPD')
Define Field(#increase) Reffld(#salary)
Define Field(#newsal) Reffld(#salary)
Get_Entry Number(1) From_List(#TRIG_LIST)
#phonebusw := #phonebus
#newsal := #salary
Get_Entry Number(2) From_List(#TRIG_LIST)
#increase := #newsal - #salary

If ((#increase *GT 1000) *And (#phonebusw *NE 'A100'))
Execute Subroutine(send_EMAIL)
* reset salary to previous value
Get_Entry Number(1) From_List(#TRIG_LIST)
#salary := #newsal - #increase
Upd_Entry In_List(#trig_list)
Endif
* reset business phone if contains A100
Get_Entry Number(1) From_List(#TRIG_LIST)
If (#phonebus = 'A100')
#phonebus := N/A
Upd_Entry In_List(#trig_list)
Endif
* Handle an event not catered for
Otherwise
Abort Msgtxt('File PSLMST trigger function invalidly invoked/ used.')
Endcase
* Return control to the invoker
Return

Subroutine Name(checksts)

. . . . . 

9.  Compile your trigger function.