Try OpenEdge Now
skip to main content
Programming Interfaces
Input/Output Processes : Alternate I/O Sources : Changing the input source of a procedure : Receiving input from multiple sources
 
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 i-io3.p procedure to delete the customers.
i-io3.p
FOR EACH Customer WHERE Customer.CustNum > 89:
  DELETE Customer.
END.
The following figure shows the i-chgin2.p procedure.
Figure 28. Multiple input sources
These are the specific steps that the i-chgin2.p 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