Step 6 Update Employee Skills

Visual LANSA

Step 6. Update Employee Skills

FRM085 - Update from a Grid

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

  • To process all entries in the SKILLS grid (SELECTLIST/ENDSELECT) and update, delete or insert a new skill.
  • The SKILLS grid will now be loaded with 5 blanks entries, which may be used to add a new skill.
  • The field DATEACQR column will be used to identify "existing" skills entries.
  • If the Date Acquired (DATEACQ) is zero, the skill will be deleted.
  • All other skill entries will be updated.
  • The SKILLS grid will be rebuilt after a successful update to show current entries.

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:

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

Add an EXECUTE SKILLS command to the EMPLOYS ItemGotSelection routine

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

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

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).

    If the employee update is OK

    Read all entries in the SKILLS grid using SELECTLIST

    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

        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:

Insert an employee skill record, if DATEACQR is zero and skill code (SKILCODE) is not blank.

    If the insert is not OK, issue a message, update the current SKILL entry and stop processing SKILLS entries (using a LEAVE command).

    If no errors occurred, execute the SKILLS subroutine to rebuild the SKILLS grid.

 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 shown in red.

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:

a.  Select an employee to display employee details and skills

b.  Save with invalid data (e.g. surname=blank, salary=zero)

c.  Select a different employee in the EMPLOYS list view

d.  Notice that the error fields are still highlighted.

     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.