Rational Developer for System z
PL/I for Windows, Version 7.6, Programming Guide

Example of an interactive program

The example program in Figure 13 creates a consecutive data set PHONES using a dialog with the user. By default, SYSIN is associated with the CON device. You can override this association by setting an environment variable for the SYSIN file or by using the TITLE option on the OPEN statement. The output data set is associated with a disk file INT1.DAT and contains names and phone numbers that the user enters from the keyboard.

Figure 13. A sample interactive program
 /********************************************************************/
 /*                                                                  */
 /*  DESCRIPTION                                                     */
 /*    Create a SEQUENTIAL data set using a console dialog.          */
 /*                                                                  */
 /*  USAGE                                                           */
 /*    The following command is required to establish                */
 /*    the environment variable to run this program:                 */
 /*                                                                  */
 /*      SET DD:PHONES=INT1.DAT,APPEND(Y)                            */
 /*                                                                  */
 /********************************************************************/

 INT1: proc options(main);

   dcl Phones stream env(recsize(40));

   dcl Eof bit(1) init('0'b);

   dcl 1 PhoneBookEntry,
        3 NameField char(19),
        3 PhoneNumber char(21);
   dcl InArea char(40);

   open file (Phones) output;

   on endfile(sysin) Eof='1'b;

   /* start creating phone book */
   put list('Please enter name:');
   get edit(NameField)(a(19));
   if ¬Eof then
    do;
      put list('Please enter number:');
      get edit(PhoneNumber)(a(21));
    end;
   do while (¬Eof);
      put file(Phones) edit(PhoneBookEntry)(a(40));
      put list('Please enter name:');
      get edit(NameField)(a(19));
      if ¬Eof then
       do;
         put list('Please enter number:');
         get edit(PhoneNumber)(a(21));
       end;
   end;

   close file(Phones);

 end INT1;

Terms of use | Feedback

This information center is powered by Eclipse technology. (http://www.eclipse.org)