Step 6. Update Employee Skills

FRM085 - Update from a Grid

In this step you will extend the SAVE Click event routine:

1.  In the SKILLS grid, select the column Skill Code by clicking on its column heading.  Change its ReadOnly property to false. Repeat this change for columns Grade, Comment and Date Acquired. 

2.  Create a "SKILLS" subroutine:

a.  Move the clear and populate SKILLS logic from the EMPLOYS ItemGotSelection routine into the SKILLS subroutine.

b.  Add an EXECUTE SKILLS command to the EMPLOYS ItemGotSelection routine

c.  Define a group_by  SKLLIST for all the SKILLS grid fields, excluding EMPNO

d.  Set the SKLLIST group_by fields to default values after populating the SKILLS grid

e.  Extend the SKILL subroutine logic to add 5 blank entries to the end of the SKILLS grid

     Your SKILLS subroutine should look like the following:

Subroutine Name(SKILLS)
Group_By Name(#skllist) Fields(#SKILCODE #GRADE #COMMENT #DATEACQ #SKILDESC #DATEACQR)
Clr_List Named(#SKILLS)
Select Fields(*all) From_File(pslskl) With_Key(#EMPNO)
Fetch Fields(#skildesc) From_File(skltab) With_Key(#skilcode)
Add_Entry To_List(#SKILLS)
Endselect
#skllist := *default
Begin_Loop To(5)
Add_Entry To_List(#SKILLS)
End_Loop
Endroutine

 

3.  Compile your form and test it. The SKILLS grid columns should be input capable (except Skill Description) and there should be 5 "blank" entries at the end of the grid. The Save button will not yet update employee skills.

4.  In this step you will extend the SAVE logic to update or delete employee skills (file PSLSKL).

a.  If the employee update is OK
Read all entries in the SKILLS grid using SELECTLIST

c.  If field DATEACQR is not zero
-  If field DATEACQ is not zero
-   UPDATE skill with a key of employee number and skill code
-   Otherwise, delete skill with a key of employee number and skill code

d.  If I/O status is not OK
-   Update current entry in SKILLS grid
-   Leave SELECTLIST

     Your SAVE logic should now look like the following:

Evtroutine Handling(#SAVE.Click)
Update Fields(*all) In_File(pslmst) Val_Error(*next)
If_Status Is(*okay)
Selectlist Named(#SKILLS)
If (#dateacqr *NE *zero)

If (#dateacq *NE *zeroes)

Update Fields(#SKILLS) In_File(pslskl) With_Key(#EMPNO #skilcode) Val_Error(*next)

Else

Delete From_File(pslskl) with_Key(#empno #skilcode) Val_Error(*next)

Endif

If_Status Is_Not(*okay)

Upd_Entry In_List(#SKILLS)

leave

Endif

Endif

Endselect

If_Status Is(*okay)

Execute Subroutine(SKILLS)

Endif

Else
Message Msgtxt('Error occurred on Employee update')
Endif
Endroutine

 

5.  Compile and test your form. You should now be able to update existing skills (e.g. change grade, comment or data acquired) or delete a skill by setting Date Acquired to zero.

     Notice that, when a validation error occurs (e.g. invalid Grade), the error is highlighted and processing of the SKILLS grid stops.

6.  In this step, you will extend the SELECTLIST logic:

     Define a Group_By, which contains only the fields needed to insert an employee skill record:
Group_By Name(#skilladd) Fields(#empno #skilcode #dateacq #comment #grade)

     Extend your save logic as outlined above. Use the SKILLADD Group_by when inserting an employee skills record.

     Your SAVE logic should now look like the following. Changes are highlighted.

Evtroutine Handling(#SAVE.Click)
Update Fields(*all) In_File(pslmst) Val_Error(*next)
If_Status Is(*okay)
Selectlist Named(#SKILLS)
If (#dateacqr *NE *zero)
If (#dateacq *NE *zeroes)
Update Fields(#SKILLS) In_File(pslskl) With_Key(#EMPNO #skilcode) Val_Error(*next)
Else
Delete From_File(pslskl) With_Key(#empno #skilcode) Val_Error(*next)
Endif
If_Status Is_Not(*okay)
Upd_Entry In_List(#SKILLS)
Leave
Endif

Else
If (#skilcode *NE *blank)
Insert Fields(#SKILLADD) To_File(pslskl) Val_Error(*next)
If_Status Is_Not(*OKAY)
Message Msgtxt('New Skill not inserted')
Upd_Entry In_List(#SKILLS)
Leave
Endif
Endif

Endif
Endselect
If_Status Is(*okay)
Execute Subroutine(SKILLS)
Endif
Else
Message Msgtxt('Error occurred on Employee update')
Endif
Endroutine
 

7.  Compile and test your form. You should be able to add new skill entries and also handle a validation error when inserting a skill.

     Hint: At this stage, you must know valid skill codes. Delete a skill (Date Acquired = zero) noting the skill code and then re-add the same skill.

     Notice that if a validation error occurs on an insert, the error is highlighted and processing of the SKILLS grid stops.

8.  In this step you will refine the error handling. Test your form as follows:

     Notice that the EMPLOYS ItemGotSelection routine definition has an OPTIONS() setting which does not clear errors and messages:

Evtroutine Handling(#EMPLOYS.ItemGotSelection) Options(*noclearerrors *noclearmessages)

 

9.  Remove the Options() parameter from the EMPLOYS ItemGotSelection event routine statement.

10. Compile and test your form and repeat the test in 8 above. Note that field highlighting is now cleared when a new employee is selected in the EMPLOYS list view.