Annette,
Okay, back to basics in the SDO. Here's an example of the simplest method for inserting a calculated field into an SDO. For this example you need to be in an AppBuilder session and connected to the Sports or Sports2000 database, and you need to have built a basic SDO for the Employee table. One of the fields in the Employee table is DeptCode and the calculated field we're going to build will contain the corresponding department Name.
Firstly, in the Section Editor create a new Function GetDeptName and make sure it returns CHARACTER. Give it an input parameter pcDeptCode, and put the following in the function:
Code:
DEFINE VARIABLE cDeptName AS CHARACTER NO-UNDO.
FIND Department WHERE Department.DeptCode = pcDeptCode NO-LOCK NO-ERROR.
RETURN (IF AVAILABLE Department THEN Department.DeptName ELSE "").
Now display the SDO's Property Sheet, click the Fields button to display the Column Editor, and click the Calculated Field button to add a new field in the Calculated Field Editor. In the Expression editor widget enter:
Code:
GetDeptName(RowObject.DeptCode)
Click OK to return to the Column Editor. On the right-hand side you'll see the Name of the field is CALC. Change this to cfDeptName, and change the Format from x(8) to x(15) so that it matches the format of Department.DeptName. Click OK to return to the Property Sheet and click OK again to close the Property sheet.
Go back to the Section Editor and click the List button. You'll see that the AppBuilder has generated a new procedure DATA.CALCULATE. The code in this procedure should read:
Code:
ASSIGN
rowObject.cfDeptName = (GetDeptName(RowObject.DeptCode))
.
Save the SDO. You can now use RowObject.cfDeptName in a Smart Browser or Smart Viewer just like you can any other RowObject field.
This isn't the only method for creating calculated fields but it should be enough to get you going.
Anyone want me to tidy this up and post it as an FAQ ?
Mike.