Release 10.1A: OpenEdge Development:
Progress 4GL Handbook

> ## Defining a procedure to return Order Lines

> This section discusses a procedure that retrieves the Order Lines from the database. This sample procedure is called`h-fetchOlines.p`. It takes the current Order Number as an `INPUT` parameter. It then defines a temp-table with the fields from the OrderLine table plus the Item Name and the total Weight for the quantity ordered. Finally, it defines an `OUTPUT` parameter to return the set of Order Lines as a temp-table to the caller:

>     /* h-fetchOlines.p -- retrieve all orderlines for an Order
>         and return them in a temp-table. */
>         DEFINE TEMP-TABLE ttOline LIKE OrderLine
>             FIELD ItemName LIKE ITEM.ItemName
>         FIELD TotalWeight AS DECIMAL LABEL "Tot.Wgt." .
>         DEFINE INPUT  PARAMETER piOrderNum AS INTEGER     NO-UNDO.
>         DEFINE OUTPUT PARAMETER TABLE FOR ttOline.

> Notice that you must define the temp-table before you use it in a parameter definition.

> Using the `INPUT` parameter that passed in the Order Number, the code retrieves all the Order Lines for that Order. For each one, it creates a temp-table record.

> The procedure then needs to move all the OrderLine fields from the database record into the temp-table. In addition, it must copy the Item Name from the Item table and a calculation of the total weight for the Order Line based on the weight of the item and the quantity ordered.

> You could do this with a long `ASSIGN` statement that names and assigns each field, but there’s a shorter way to do this, using the `BUFFER-COPY` statement, as in this example:

>     FOR EACH OrderLine WHERE Orderline.OrderNum = piOrderNum,
>         ITEM OF OrderLine:
>             CREATE ttOline.
>             BUFFER-COPY OrderLine TO ttOline
>                 ASSIGN ttOline.ItemName = Item.ItemName
>                     ttOline.TotalWeight = OrderLine.Qty * Item.Weight.
>       END.

Copyright © 2005 Progress Software Corporation www.progress.com Voice: (781) 280-4000 Fax: (781) 280-4095