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.
- Select the ‘Other’ tab.
- Select ‘Business Process.’ Select OK.
- Enter “ReduceRating” as the ‘Object Name.’ Select OK.
- 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.
- Select ‘cRecipeDataDictionary’ form the list. Select ‘Select.’
- Write a find loop in ReduceRating.bp…
Send Find of oRecipe_DD FIRST_RECORD 1
Send Update_Status (“Processing: “ + Field_Current_Value(oRecipe_DD, RefTable(Recipe.Name)))
Get Field_Current_Value of oRecipe_DD (RefTable(Recipe.Rating)) to iRating
If (iRating < 0) Begin
Move 0 to iRating
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
Send Find of oRecipe_DD NEXT_RECORD 1
- 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
- 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.
- Enter “Reduce Rating,” hit ENTER.
- Double click the text you just entered to open the source code where it has created a C Codejock menu item (cCJMenuItem).
- 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.
- Add details to the code
Send doProcess of oReduceRating
- 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.
- 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.
- Return to the ‘Recipe [Table Viewer]’ in the Studio, and select the ‘refresh’ icon to see that the ratings have been reduced.