Release 10.1A: OpenEdge Development:
Programming Interfaces

> ## Receiving input from multiple sources

> At some points in a procedure you might want to get input from the terminal, but at other points you might want to get input from a file. A single procedure can use multiple input sources.

> For example, suppose you want to create records for the customers in the `i-datf1.d` data file. Before creating the records, you probably want to display the customer numbers in the file and ask if the user wants to create customer records for those numbers. To do this, you need input from the terminal. If the user wants to create customer records for the customers in the `i-datf1.d` file, you also need input from the file.

> The `i-chgin2.p` procedure uses multiple input sources to perform the work described above. Because `i-chgin2.p` uses the same data file (`i-datf1.d`) you used in the previous section to create customer records, you must delete customers 90, 91, and 92 from your database before you run `i-chgin2.p`. Use the following procedure to delete the customers:

> i-io3.p
>     FOR EACH customer WHERE cust-num > 89:
>       DELETE customer.
>     END.

> Figure 5–7 shows the `i-chgin2.p` procedure.

> Figure 5–7: Multiple input sources

> These are the specific steps the procedure follows:

> 1. The `DISPLAY` statement displays some text.

> 2. The first `INPUT` `FROM` statement redirects the input source to the `i-datf1.d` file.

> 3. The `SET` statement assigns the values in the `i-datf1.d` file to the `cust–num–var`, `name–var`, and `sales–rep–var` variables. As it assigns the values to these variables, you see the values on the terminal screen.

> 4. The `INPUT FROM TERMINAL` statement redirects the input source to the terminal. The `INPUT CLOSE` statement could have been used instead of the `INPUT FROM TERMINAL` statement. However, since this procedure might have been called from another procedure, it is better to be explicit about the input source you want to use.

> 5. The `SET` answer statement prompts you to create database records for the customer data just displayed. If you answer yes, the procedure:

> - Redirects the input source to come from the beginning of the `i-datf1.d` file.
> - Creates a customer record and assigns values to the cust–num., name, and sales–rep fields in that record for each iteration of a `REPEAT` block.
> - Ends the `REPEAT` block when the `SET` statement reaches the end of the input file.

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