Working with databases
Lesson 9: Manipulating data
This lesson will show how to use a business process to manipulate data.
- From within the DataFlex Studio select the ‘Create New’ icon from the top toolbar.
![](/ContentData/1227-WorkingWithDBsL9_1_new.png)
- Select the ‘Other’ tab.
- Select ‘Business Process.’ Select OK.
![](/ContentData/1228-WorkingWithDBsL9_2_bizPrcss.png)
- Enter “ReduceRating” as the ‘Object Name.’ Select OK.
![](/ContentData/1229-WorkingWithDBsL9_3_reduceRtg.png)
- Write a find loop to calculate the rating of each recipe…
- Use the DDO Explorer on the right to add objects…
- Select the ‘Add DDO’ icon from the top of the panel.
![](/ContentData/1230-WorkingWithDBsL9_4_DDOexpl.png)
- Select ‘cRecipeDataDictionary’ form the list. Select ‘Select.’
![](/ContentData/1231-WorkingWithDBsL9_5_recipeDD.png)
- Write a find loop in ReduceRating.bp…
Procedure OnProcess
Integer iRating
Boolean bErr
Send Find of oRecipe_DD FIRST_RECORD 1
While (Found)
Send Update_Status (“Processing: “ + Field_Current_Value(oRecipe_DD, RefTable(Recipe.Name)))
Get Field_Current_Value of oRecipe_DD (RefTable(Recipe.Rating)) to iRating
Decrement iRating
If (iRating < 0) Begin
Move 0 to iRating
End
Set Field_Changed_Value of oRecipe_DD (RefTable(Recipe.Rating)) to iRating
Get Request_Validate of oRecipe_DD to bErr
If (not(bErr)) Begin
Send Request_Save of oRecipe_DD
End
Send Find of oRecipe_DD NEXT_RECORD 1
Loop
End_Procedure
![](/ContentData/1232-WorkingWithDBsL9_6_code.png)
- This business process now needs to be added to the application…
- Navigate to source view of ‘Cookbook.src’
- Scroll to the bottom to add a Use statement…
- Use ReduceRating.bp
![](/ContentData/1233-WorkingWithDBsL9_7_use.png)
- Add a menu item to the application’s toolbar…
- From the design view of ‘Cookbook.src [Design]’…
- Click ‘Help’ on the application’s menu.
- Click on the ‘Type Here’ prompt that appears.
![](/ContentData/1234-WorkingWithDBsL9_8_typeHere.png)
- Enter “Reduce Rating,” hit ENTER.
![](/ContentData/1235-WorkingWithDBsL9_8B_reduceRatings.png)
- Double click the text you just entered to open the source code where it has created a C Codejock menu item (cCJMenuItem).
![](/ContentData/1236-WorkingWithDBsL9_9_code.png)
- From within the menu item write code to implement the onExecute event.
- Press CTRL+2 to open the ‘Properties’ panel on the right for the specified object (the cursor must be located on the desired object).
- Select the ‘Events’ tab.
- Double click ‘OnExecute’ to generate the onExecute procedure in the code that will be triggered when the menu item is clicked.
![](/ContentData/1237-WorkingWithDBsL9_10_onExecute.png)
- Add details to the code
Send doProcess of oReduceRating
![](/ContentData/1238-WorkingWithDBsL9_11_code.png)
- To properly see the results of the procedure…
- Open the ‘Table Explorer’ on the left.
- Right click ‘Recipe,’ and select ‘View Table’ to the see the recipes and their ratings.
![](/ContentData/1239-WorkingWithDBsL9_12_tblVwr.png)
![](/ContentData/1240-WorkingWithDBsL9_13_table.png)
- Select the ‘Run’ icon from the top toolbar to launch the application.
- Select ‘Reduce Ratings’ from the application’s top menu. A status window will quickly show the process being run.
![](/ContentData/1241-WorkingWithDBsL9_14_reduceBtn.png)
- Return to the ‘Recipe [Table Viewer]’ in the Studio, and select the ‘refresh’ icon to see that the ratings have been reduced.
![](/ContentData/1242-WorkingWithDBsL9_15_refresh.png)