midrange.com code scratchpad
Name:
RDYMEDLIB
Scriptlanguage:
Plain Text
Tabwidth:
4
Date:
10/04/2018 03:15:30 pm
IP:
Logged
Description:
Prepare the multidrive media libraries
Code:
  1.       /DEFINE HSpec
  2.       /INCLUDE ROUTINES/QRPGLESRC,HSPEC
  3.       /UNDEFINE HSpec
  4.  
  5.  
  6.       //**************************************************************************
  7.       // Program: Ready Media Library
  8.       // This program will read the list of media libraries.  All that are virtual
  9.       // media libraries will be varied on (if they are not).  Then their resources
  10.       // will be allocated properly.
  11.       //
  12.       // Modification log:
  13.       // 12/28/16 by R.Berendt, IBM Certified Systems Administrator, Dekko
  14.       //          Created.
  15.       //
  16.       // Compilation instructions:
  17.       //   (no special instructions this time.)
  18.       //
  19.       //**************************************************************************
  20.  
  21.  
  22.       /DEFINE DSpec
  23.  
  24.        dcl-pr RDYMEDLIB extpgm('RDYMEDLIB');
  25.        end-pr;
  26.  
  27.        dcl-pr ProcessListOfMediaLibraries;
  28.        end-pr;
  29.  
  30.        dcl-pr ProcessMediaLibraryResources;
  31.        end-pr;
  32.  
  33.        dcl-pi RDYMEDLIB; // *ENTRY PLIST
  34.        end-pi;
  35.  
  36.        dcl-ds Media_library_info extname('MEDIA_INFO') qualified alias end-ds;
  37.  
  38.        /if not defined(QCMDEXC)
  39.        /define QCMDEXC
  40.        dcl-pr QCMDEXC extpgm;
  41.         *n char(32767) const; // Cmd
  42.         *n packed(15: 5) const; // CmdLen
  43.        end-pr;
  44.        dcl-s Cmd varchar(2000);
  45.        /endif
  46.  
  47.       /UNDEFINE DSpec
  48.  
  49.        EXEC SQL
  50.         Set Option
  51.             Naming    = *Sys,
  52.             Commit    = *None,
  53.             UsrPrf    = *User,
  54.             DynUsrPrf = *User,
  55.             Datfmt    = *iso,
  56.             CloSqlCsr = *EndMod;
  57.  
  58.        ProcessListOfMediaLibraries();
  59.  
  60.        *inlr=*on;
  61.        return;
  62.  
  63.       /eject
  64.       //*********************************************************************
  65.        dcl-proc ProcessListOfMediaLibraries;
  66.       //*********************************************************************
  67.        dcl-pi ProcessListOfMediaLibraries;
  68.        end-pi;
  69.  
  70.        exec sql
  71.         Declare LibraryCursor insensitive cursor for
  72.           Select distinct Device_Name, Device_Status, Device_Type, Device_Model,
  73.                  Device_Description
  74.           from qsys2.Media_Library_info
  75.           where Device_name not like 'TAP%'
  76.           for fetch only;
  77.        // If you use an 'insensitive' cursor you can check sqlerrd(2), after you open the cursor,
  78.        // for the number of rows returned.
  79.        // ie:  NumberOfRows=sqlerrd(2);  For x = 1 to NumberOfRows; fetch...
  80.        // read up on insensitive for any side effects.  Depending on the
  81.        // situation it may be negligable.  Like I don't expect anyone to be
  82.        // adding tape drives to the system during the execution of this program.
  83.  
  84.        exec sql
  85.          Open LibraryCursor;
  86.  
  87.        dow sqlstate='00000';
  88.          exec sql
  89.          Fetch LibraryCursor into :Media_Library_Info.Device_Name,
  90.            :Media_Library_Info.Device_Status, :Media_Library_Info.Device_Type,
  91.            :Media_Library_Info.Device_Model,
  92.            :Media_Library_Info.Device_Description;
  93.          select;
  94.            When sqlstate='02000'; // All rows have been fetched
  95.              iter;
  96.            When sqlstate<>'00000'; //
  97.              sqlstate=sqlstate; // debugging
  98.            When Media_Library_Info.Device_Status='VARIED OFF';
  99.              cmd='VRYCFG CFGOBJ(' + %trim(Media_Library_Info.Device_Name) +
  100.                  ') CFGTYPE(*DEV) STATUS(*ON)';
  101.              callp QCMDEXC(Cmd:%len(Cmd));
  102.          ENDSL;
  103.          ProcessMediaLibraryResources();  // Ensure that the 'drives' are allocated unprotected
  104.        enddo;
  105.  
  106.        exec sql
  107.          Close LibraryCursor;
  108.  
  109.        return;
  110.        end-proc;
  111.  
  112.       /eject
  113.       //*********************************************************************
  114.        dcl-proc ProcessMediaLibraryResources;
  115.       //*********************************************************************
  116.        dcl-pi ProcessMediaLibraryResources;
  117.        end-pi;
  118.        exec sql
  119.         Declare ResourceCursor insensitive cursor for
  120.           Select Resource_Name, Resource_Status, Resource_Allocation_Status
  121.           from qsys2.Media_Library_info
  122.           where Device_name = :Media_Library_Info.Device_Name
  123.           for fetch only;
  124.  
  125.        exec sql
  126.          Open ResourceCursor;
  127.  
  128.        dow sqlstate='00000';
  129.          exec sql
  130.          Fetch ResourceCursor into :Media_Library_Info.Resource_Name,
  131.            :Media_Library_Info.Resource_Status,
  132.            :Media_Library_Info.Resource_Allocation_Status;
  133.          select;
  134.            When sqlstate='02000'; // All rows have been fetched
  135.              iter;
  136.            When sqlstate<>'00000'; //
  137.              sqlstate=sqlstate; // debugging
  138.            When Media_Library_Info.Resource_Allocation_Status='DEALLOCATED';
  139.              cmd='VRYCFG CFGOBJ(' + %trim(Media_Library_Info.Device_Name) +
  140.                  ') CFGTYPE(*MLBRSC) STATUS(*UNPROTECTED) RSRCNAME(' +
  141.                  %trim(Media_Library_Info.Resource_Name) +
  142.                  ')';
  143.              callp QCMDEXC(Cmd:%len(Cmd));
  144.          ENDSL;
  145.        enddo;
  146.  
  147.        exec sql
  148.          Close ResourceCursor;
  149.        return;
  150.  
  151.        end-proc;
  152.  
© 2004-2019 by midrange.com generated in 0.008s valid xhtml & css