Extend the sample procedure to pass a parameter
- Last Updated: October 16, 2024
- 8 minute read
- OpenEdge
- Version 12.8
- Documentation
Now you can try passing a ProDataSet as a parameter, by building a new
procedure in the AppBuilder to display the contents of your Order ProDataSet in a window, and calling the procedure that fills the
ProDataSet from the new procedure. The AppBuilder uses a special database called Temp-DB to hold temp-table definitions. It uses these definitions
to understand which fields are in which tables when you reference those fields in your code
or use them to build windows with browses and fields in them. The AppBuilder contains a
utility that provides support for creating and maintaining temp-table definitions using the
Temp-DB to store the definitions. This set of topics walks you through the process of using
this utility to generate a temp-table include file that the AppBuilder can process. This
procedure is a replacement for the original dsOrderTT.i
include file that you built by hand in Introduction to the OpenEdge DataSet.
To generate the temp-table include:
-
If you already have a database called
Temp-DBwhere you have stored temp-table definitions, you can continue to use it and make its definitions available to the AppBuilder by connecting the database at design time. If you have not done this, you must create an empty database calledTemp-DB, place it in your ProPath, and then follow the rest of the steps in this procedure. - In the AppBuilder, create a new Window procedure.
-
From the Tools menu, select the TEMP-DB
Maintenance Tool:

-
If the
Temp-DBis not already connected, the AppBuilder prompts you to connect it:
Select Connect and click OK.
-
The first time you use the Temp-DB Maintenance
Tool, it must add a special control table to the
Temp-DBwhere it holds meta-information about all the temp-table definitions it manages. If you get this prompt, press OK to load the definitions for this meta-table:
Next you need to create temp-table definitions in the
Temp-DBfor the three temp-tables in yourOrderProDataSet. You could import the include file you already have and start from that, but there is a good reason why you should not. Creating temp-table definitions that are defined to beLIKEthe corresponding database tables is a simple shortcut, but it is not a good way to build definitions for a real application. It ties the temp-table definitions to any later changes that are made to the database tables, and it creates a requirement that the application database be connected at compile time, even though it should not be connected to the client side of the application at run time.The Temp-DB Maintenance Tool can easily generate a temp-table definition that is initially the same as a database table definition, but it does this with each field independently defined, so that you can edit the definition to be exactly what the internal data definition should be, and remove any ongoing dependencies on the external table definition. For this reason, you will replace dsOrderTT.i in these steps.
The Temp-DB Maintenance Tool lets you create temp-table definitions based on database tables, or using your own field definitions, or any combination of the two. You do this in the editor part of the window. You can also import and manage any number of existing include files using the File Import tab, which displays all the temp-tables in the tool's browse control.
-
Right click in the editor to bring up its popup menu
and select Table Definition > Insert, as shown:

Note: You can also access this option through the Edit menu. -
Select the Order table from the
database as your first temp-table:

-
The tool builds a complete description of the
Ordertable as a series of temp-table field and index definitions and displays it in the editor. Modify this to change the table name tottOrder. -
Add the three field definitions for the additional fields
OrderTotal,CustName, andRepNameas you did when you created the first version of dsOrderTT.i, as shown in the editor. -
Remove all the index definitions except the unique primary
index
OrderNum. -
Repeat these steps for the
OrderLinetable. Select Table Definition > Insert to selectOrderLineand add its temp-table definition to the end of the editor contents. Rename the temp-tablettOline. Remove all but its primary index definition. -
Repeat these steps again for the
Itemtable. Name the temp-tablettItemand remove all but its unique primary index definition. -
When you are done, click the Save button
above the editor, as shown below. Select your
dsOrderTT.ifilename as the file to save the definitions to. The tool saves the include file, analyzes it, and displays the three temp-tables it contains in the browse, as shown:
The Use as Include toggle box above the editor (which is also shown as the Use Include browse column for the temp-tables) indicates that you want the tool to save the definition as an include file to be included in your AppBuilder procedures, rather than having the AppBuilder generate the temp-table definitions inline. This is beneficial for keeping your temp-table maintenance independent of the procedures the temp-tables are used in.
-
In the Definitions section of
your new Window procedure, include the
OrderProDataSet definition include file:/* *************************** Definitions **************************/ /* Parameters Definitions --- */ /* Local Variable Definitions --- */ {dsOrder.i}The AppBuilder will automatically generate a reference to the temp-table include file for you, when you bring those temp-tables into the procedure in a later step.
-
The temp-table definitions you just created are independent
of any particular procedure that you build in the AppBuilder. To tell
the AppBuilder that you want to use particular temp-table definitions
in your new window, you use the Temp-Table Maintenance utility.
To access this, click the Procedure settings button
in the AppBuilder main window, as shown:

-
Click the Temp-Table definitions button
(
-
) in the Procedure Properties dialog.
The Temp-Table Maintenance dialog appears, as shown:

-
Add a temp-table
LIKE ttOrderfrom theTemp-DBdatabase. Because you have already defined the temp-tables exactly as they should be, you do not need to change anything in the definition, including the temp-table name, as shown:
- Check off the NO-UNDO toggle for the table. Your tables will want to be able to take advantage of the AVM undo capability when you allow updates to the tables.
-
Do the same for the
ttOlineandttItemtables:
- Click OK to exit the Temp-Table Maintenance dialog and then the Procedure Settings dialog.
-
Name the window
dsOrderWin, and its default framedsFrame. -
Define several fill-in variables to display some of the
ttOrderfields in:integerfill-insiOrderNumandiCustNum,characterfill-inscCustNameandcRepName, and adecimalfielddOrderTotal. -
Make each of these fields Enabled, and
also set the Read-Only toggle box in the
field property sheet for each of them except the
iOrderNumfield.You will use
iOrderNumto enter anOrder Numberto pass to the ProDataSet fill procedure. The other fields simply display theOrdervalues that come back. Making them enabled but read-only gives them a field border that makes them easier to read. -
Drop a browse object from the AppBuilder palette onto the
window and use it to define a browse on the temp-table
ttOline.You do this by selecting Temp-Tables from the database list. The AppBuilder represents the temp-table definitions as if they were in a dummy database called
Temp-Tables, as shown:
-
Click the Fields… button and add some
or all of the
ttOlinefields to the browse. -
Call the new browse
OlineBrowse. -
Create another browse for the
ttItemtable and add theItemNumandItemNamefields to it. Name the browseItemBrowse. When you are done, your window should look something like this:
Now you need to run a separate procedure that fills the
OrderProDataSet with all the records for anOrder, and then displays what that procedure returns. -
Define this
LEAVEtrigger for theOrderNumfield:DO: ASSIGN iOrderNum. IF iOrderNum NE 0 THEN DO: DATASET dsOrder:EMPTY-DATASET. RUN fillDSOrder.p (iOrderNum, OUTPUT DATASET dsOrder BY-REFERENCE). FIND FIRST ttOrder. DO WITH FRAME dsFrame: ASSIGN iCustNum:SCREEN-VALUE = STRING(ttOrder.CustNum) cCustName:SCREEN-VALUE = ttOrder.CustName cRepName:SCREEN-VALUE = ttOrder.RepName dOrderTotal:SCREEN-VALUE = STRING(ttOrder.OrderTotal). {&OPEN-BROWSERS-IN-QUERY-{&FRAME-NAME}} END. END. END.If the user has entered an
Ordernumber, the trigger first empties the ProDataSet in case it still has data from a previous request. It then runs the procedure to fill theOrderProDataSet, passing in theOrdernumber and getting the ProDataSet back as anOUTPUTparameter with theBY-REFERENCEqualifier. Passing itBY-REFERENCEeliminates the need to copy all the data from fillDSOrder.p back to the window procedure, but requires that you explicitly empty the ProDataSet first so as not to append data to the existing ProDataSet in the window procedure when the call is made locally.The trigger then displays the
Orderfields and uses the AppBuilder-generated preprocessor to open the browses forOrderLinesandItems. -
Save this window procedure as ds
OrderWin.w. Now you need to modify the fill procedure to accept the parameters. -
Add these parameter definitions to fillDS
Order.p following the temp-table and ProDataSet definitions:{dsOrderTT.i} {dsOrder.i} DEFINE INPUT PARAMETER piOrderNum AS INTEGER NO-UNDO. DEFINE OUTPUT PARAMETER DATASET FOR dsOrder.The parameters need to follow the ProDataSet definition because the
OUTPUTparameter references the ProDataSetdsOrder. -
Change the
FOR EACHstatement in theOrderquery to use theOrdernumber passed in:QUERY qOrder:QUERY-PREPARE("FOR EACH Order WHERE Order.OrderNum = " + STRING(piOrderNum) + ", FIRST Customer OF Order, FIRST SalesRep OF Order"). -
Remove the
FOR EACH:…DISPLAYblocks from fillDSOrder.p. Now when you run the window you can enter anOrdernumber and see all its data, as shown:
The window shows that the ProDataSet parameter has returned, through a single handle, the fields from the
ttOrderrecord, the set ofOrderLinesin thettOlinetable, and all theirItemsin thettItemtable. When the ProDataSet comes back as anOUTPUTparameter in a remote call, all the local copies of its temp-tables are automatically populated.The
Order Totalis not filled in yet because that is a calculated field. In the next set of topics, you will learn about event procedures for ProDataSets and how to write code to calculate thatOrder Totalvalue for eachOrderas it is filled. Later, you will also learn how to synchronize theOrderLinebrowse and theItembrowse so that theItembrowse is repositioned to the currently selectedOrderLine.