FRM085 - Update from a Grid
In this step you will create Click events for both search buttons and complete the search logic using SELECT_SQL to populate the EMPLOYS List View.
1. Select the SEARCH_MONTH push button. Change its Enabled property to False and create a Click event routine.
2. The SQL will have a WHERE clause, which compares STARTDTER with a work field containing a mask "__nn__", where nn is the character value for the month selector field iiiMONTH.
Define a work field (inside the SEARCH_MONTH.Click event) as follows:
Define Field(#iiiDATE6) Type(*char) Length(6)
STARTDTER is a signed, length 6 field,
3. The date mask value can be created in field iiiDATE6 using the asString and RightAdjust intrinsic functions.
Hint: Use the F2 Feature help on field #iiiMONTH to discover the intrinsic functions (methods) available.
Note: On this occasion you are first using the function asString from the numeric field iiiMONTH and then using a RightAdjust function which is available once it is a string. You can use F2 Feature help on any Alpha or String field to discover the RightAdjust function. Then use F1 help on an intrinsic function (method) to display help text and examples.
The code required is:
#iiiDATE6 := '__' + #iiiMONTH.asDisplayString.RightAdjust( 2, "0" ) + '__'
The RightAdjust pads the result to length 2, with a pad character of 0.
There are two forms of SELECT_SQL available:
For full information on SELECT_SQL, refer to the Technical Reference Guide. You should do a detailed study of this Technical Reference information before attempting to use SELECT_SQL.
4. The SQL statement to retrieve employees with a start date in the required month is as follows:
SELECT EMPNO, SURNAME, GIVENAME, STARTDTER FROM XDEMOLIB.PSLMST WHERE ("STARDTER LIKE '__mm__')
Where mm = the month number required.
Complete the SEARCH_MONTH Click event routine as shown below:
Evtroutine Handling(#SEARCH_MONTH.Click)
#iiiDATE6 := '__' + #iiiMONTH.asDisplayString.rightAdjust( 2, "0" ) + '__'
Clr_List Named(#EMPLOYS)
#std_strng := 'WHERE (' + '"STARTDTER"' + ' LIKE ' + #quote + #iiiDATE6 + #quote + ')'
#std_strng := 'SELECT EMPNO, SURNAME, GIVENAME, STARTDTER FROM XDEMOLIB.PSLMST ' + #std_strng.trim
Select_Sql Fields(#EMPNO #SURNAME #GIVENAME #startdter) Using(#std_strng)
#fullname := #SURNAME + ', ' + #GIVENAME
Add_Entry To_List(#EMPLOYS)
Endselect
#EMPNO #SURNAME #GIVENAME := *default
Endroutine
Important Note:
5. Create a Changed event for field iiiMONTH. Add code to this event to enable the SEARCH_MONTH button. Your code should look like the following:
Evtroutine Handling(#IIIMONTH.Changed) Options(*NOCLEARMESSAGES *NOCLEARERRORS)
#SEARCH_MONTH.enabled := true
Endroutine
6. Compile your form and test it. You should be able to select a month. The search button should populate the list view. Hint: Try a number of different months.
7. Select the SEARCH_NAME button, change its Enabled property to false and create a Click event for it.
8. The SQL statement required to retrieve employees selecting by SURNAME based on in input search value such as 'S%' or %smi%' is as follows:
SELECT EMPNO, SURNAME, GIVENAME FROM XDEMOLIB.PSLMST WHERE (#SURNAME" LIKE 'XX')
where XX = the search criteria.
Note: Once again you need to know the schema name for table PSLMST in your local SQL Server database.
Your completed code should look like the following:
Evtroutine Handling(#SEARCH_NAME.Click)
Clr_List Named(#EMPLOYS)
#std_strng := #quote + #IIISRCNAME + #quote
#std_strng := 'SELECT EMPNO, SURNAME, GIVENAME FROM XDEMOLIB.PSLMST where ("surname" like ' + #std_strng.trim + ')'
Change Field(#EMPNO) To(*blank)
Select_Sql Fields(#EMPNO #SURNAME #GIVENAME) Using(#std_strng)
#fullname := #SURNAME + ', ' + #GIVENAME
Add_Entry To_List(#EMPLOYS)
Endselect
#EMPNO #SURNAME #GIVENAME := *blanks
Endroutine
9. Create a Changed event for the field iiiSRCNAME. Complete this event routine to enabled the SEARCH_NAME button. Your code should look like the following:
Evtroutine Handling(#IIISRCNAME.Changed) Options(*NOCLEARMESSAGES *NOCLEARERRORS)
#SEARCH_NAME.enabled := true
Endroutine
10. Compile your form and test it. Check the SEARCH_NAME logic using values such as SM% and %Y%.