You can change the default device for a device file.
Example:
The following example illustrates how to change the default program device using the _Rpgmdev() function.
CRTDSPF FILE(MYLIB/T1520DDE) SRCFILE(QCPPLE/QADDSSRC) MAXDEV(2)
Figure 143. T1520DDE -- DDS Source for Name and Password Display
|
OVRPRTF FILE(STDOUT) TOFILE(QPRINT)
CRTBNDC PGM(MYLIB/T1520CDV) SRCFILE(QCPPLE/QACSRC)
Figure 144. T1520CDV -- ILE C Source to Change the Default Device
|
The ILE C program T1520CDV uses the _Racquire() function to explicitly acquire another device that is named DEVICE1. DEVICE1 becomes the current program device. The _Rpgmdev() function changes the current device that is named DEVICE1 to DEVICE2. The _Rreadindv() function reads records from DEVICE1. The _Release() function releases DEVICE1 and DEVICE2.
CALL PGM(MYLIB/T1520CDV)
The output is as follows:
+--------------------------------------------------------------------------------+ | | | | | | | | | | | | | Name: | | Password: | | | | | | | | | | | | | | | | | | | | | | | | | | | +--------------------------------------------------------------------------------+
When the application is run, a different display appears on each device. Data may be entered on both displays, but the data that is first entered is returned to the program. The output from the program is in QPRINT. For example, if the name SMITH and the address 10 MAIN ST is entered on DEVICE1 before any data is entered on DEVICE2, then the file QPRINT contains:
Data displayed on DEVICE1 is SMITH 10 MAIN ST
(C) Copyright IBM Corporation 1992, 2005. All Rights Reserved.