| Code: 
							
								
								
								| 
          /DEFINE HSpec
      /INCLUDE ROUTINES/QRPGLESRC,HSPEC
      /UNDEFINE HSpec
        //**************************************************************************
      // Program: Ready Media Library
      // This program will read the list of media libraries.  All that are virtual
      // media libraries will be varied on (if they are not).  Then their resources
      // will be allocated properly.
      //
      // Modification log:
      // 12/28/16 by R.Berendt, IBM Certified Systems Administrator, Dekko
      //          Created.
      //
      // Compilation instructions:
      //   (no special instructions this time.)
      //
      //**************************************************************************
        /DEFINE DSpec
        dcl-pr RDYMEDLIB extpgm('RDYMEDLIB');
       end-pr;
        dcl-pr ProcessListOfMediaLibraries;
       end-pr;
        dcl-pr ProcessMediaLibraryResources;
       end-pr;
        dcl-pi RDYMEDLIB; // *ENTRY PLIST
       end-pi;
        dcl-ds Media_library_info extname('MEDIA_INFO') qualified alias end-ds;
        /if not defined(QCMDEXC)
       /define QCMDEXC
       dcl-pr QCMDEXC extpgm;
        *n char(32767) const; // Cmd
        *n packed(15: 5) const; // CmdLen
       end-pr;
       dcl-s Cmd varchar(2000);
       /endif
       /UNDEFINE DSpec
        EXEC SQL
        Set Option
            Naming    = *Sys,
            Commit    = *None,
            UsrPrf    = *User,
            DynUsrPrf = *User,
            Datfmt    = *iso,
            CloSqlCsr = *EndMod;
        ProcessListOfMediaLibraries();
        *inlr=*on;
       return;
       /eject
      //*********************************************************************
       dcl-proc ProcessListOfMediaLibraries;
      //*********************************************************************
       dcl-pi ProcessListOfMediaLibraries;
       end-pi;
        exec sql
        Declare LibraryCursor insensitive cursor for
          Select distinct Device_Name, Device_Status, Device_Type, Device_Model,
                 Device_Description
          from qsys2.Media_Library_info
          where Device_name not like 'TAP%'
          for fetch only;
       // If you use an 'insensitive' cursor you can check sqlerrd(2), after you open the cursor,
       // for the number of rows returned.
       // ie:  NumberOfRows=sqlerrd(2);  For x = 1 to NumberOfRows; fetch...
       // read up on insensitive for any side effects.  Depending on the
       // situation it may be negligable.  Like I don't expect anyone to be
       // adding tape drives to the system during the execution of this program.
        exec sql
         Open LibraryCursor;
        dow sqlstate='00000';
         exec sql
         Fetch LibraryCursor into :Media_Library_Info.Device_Name,
           :Media_Library_Info.Device_Status, :Media_Library_Info.Device_Type,
           :Media_Library_Info.Device_Model,
           :Media_Library_Info.Device_Description;
         select;
           When sqlstate='02000'; // All rows have been fetched
             iter;
           When sqlstate<>'00000'; //
             sqlstate=sqlstate; // debugging
           When Media_Library_Info.Device_Status='VARIED OFF';
             cmd='VRYCFG CFGOBJ(' + %trim(Media_Library_Info.Device_Name) +
                 ') CFGTYPE(*DEV) STATUS(*ON)';
             callp QCMDEXC(Cmd:%len(Cmd));
         ENDSL;
         ProcessMediaLibraryResources();  // Ensure that the 'drives' are allocated unprotected
       enddo;
        exec sql
         Close LibraryCursor;
        return;
       end-proc;
       /eject
      //*********************************************************************
       dcl-proc ProcessMediaLibraryResources;
      //*********************************************************************
       dcl-pi ProcessMediaLibraryResources;
       end-pi;
       exec sql
        Declare ResourceCursor insensitive cursor for
          Select Resource_Name, Resource_Status, Resource_Allocation_Status
          from qsys2.Media_Library_info
          where Device_name = :Media_Library_Info.Device_Name
          for fetch only;
        exec sql
         Open ResourceCursor;
        dow sqlstate='00000';
         exec sql
         Fetch ResourceCursor into :Media_Library_Info.Resource_Name,
           :Media_Library_Info.Resource_Status,
           :Media_Library_Info.Resource_Allocation_Status;
         select;
           When sqlstate='02000'; // All rows have been fetched
             iter;
           When sqlstate<>'00000'; //
             sqlstate=sqlstate; // debugging
           When Media_Library_Info.Resource_Allocation_Status='DEALLOCATED';
             cmd='VRYCFG CFGOBJ(' + %trim(Media_Library_Info.Device_Name) +
                 ') CFGTYPE(*MLBRSC) STATUS(*UNPROTECTED) RSRCNAME(' +
                 %trim(Media_Library_Info.Resource_Name) +
                 ')';
             callp QCMDEXC(Cmd:%len(Cmd));
         ENDSL;
       enddo;
        exec sql
         Close ResourceCursor;
       return;
        end-proc;
  |  |