To continue with this content, please log in with your Data Access ID or create a new account.
Cancel Data Access ID
You may not be authorized to see this content. Please contact Data Access Europe for more information.
Cancel Data Access Europe
You are not authorized to see this content.
Cancel Data Access Europe
Next lesson:
Use embedded SQL
Cancel

Working with databases

Lesson 9: Manipulating data

This lesson will show how to use a business process to manipulate data.

  1. From within the DataFlex Studio select the ‘Create New’ icon from the top toolbar.
  2. Select the ‘Other’ tab.
  3. Select ‘Business Process.’ Select OK.
  4. Enter “ReduceRating” as the ‘Object Name.’ Select OK.
  5. Write a find loop to calculate the rating of each recipe…
  6. Use the DDO Explorer on the right to add objects…
  7. Select the ‘Add DDO’ icon from the top of the panel.
  8. Select ‘cRecipeDataDictionary’ form the list. Select ‘Select.’
  9. 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



  10. This business process now needs to be added to the application…
  11. Navigate to source view of ‘Cookbook.src’
  12. Scroll to the bottom to add a Use statement…
  13. Use ReduceRating.bp 
  14. Add a menu item to the application’s toolbar…
  15. From the design view of ‘Cookbook.src [Design]’…
  16. Click ‘Help’ on the application’s menu.
  17. Click on the ‘Type Here’ prompt that appears.
  18. Enter “Reduce Rating,” hit ENTER.
  19. Double click the text you just entered to open the source code where it has created a C Codejock menu item (cCJMenuItem).
  20. From within the menu item write code to implement the onExecute event.
  21. Press CTRL+2 to open the ‘Properties’ panel on the right for the specified object (the cursor must be located on the desired object).
  22. Select the ‘Events’ tab.
  23. Double click ‘OnExecute’ to generate the onExecute procedure in the code that will be triggered when the menu item is clicked.
  24. Add details to the code
     Send doProcess of oReduceRating

  25. To properly see the results of the procedure…
  26. Open the ‘Table Explorer’ on the left.
  27. Right click ‘Recipe,’ and select ‘View Table’ to the see the recipes and their ratings.

  28. Select the ‘Run’ icon from the top toolbar to launch the application.
  29. Select ‘Reduce Ratings’ from the application’s top menu. A status window will quickly show the process being run.
  30. Return to the ‘Recipe [Table Viewer]’ in the Studio, and select the ‘refresh’ icon to see that the ratings have been reduced.