RPGIV @ Work

A unique site for RPG and System i Lovers

Welcome!

Hi, this site will provide all what you need in System i and RPG developments.

My Name is Chamara Withanachchi, System i Expert and RPG Developer. And in the field for last 11 years.

I hope you will find lot of valuable information from this site

List actual library sizes using IBM API QLIRLIBD Print E-mail
User Rating: / 0
PoorBest 
Written by Chamara Withanachchi   
      *‚Library size data structure (QLIRLIBD)
      *
     D LibSizeDS       DS
     D   LibSize                     10I 0
     D   LibSizeMult                 10I 0
     D   LibInfSts                     N
     D                                3A
      *
      *‚List API header structure (QUSLOBJ)
      *
     D QUSH0100        DS                  Based(QUSH0100@) Qualified
     D   UserArea                    64A
     D   GenHdrSize                  10I 0
     D   StructRlsLvl                 4A
     D   FormatName                   8A
     D   ApiUsed                     10A
     D   DatTimCrt                   13A
     D   InfStatus                    1A
     D   UsrSpcSize                  10I 0
     D   InpParmOS                   10I 0
     D   InpParmSize                 10I 0
     D   HeaderOS                    10I 0
     D   HeaderSize                  10I 0
     D   ListDataOS                  10I 0
     D   ListDataSize                10I 0
     D   EntryNbr                    10I 0
     D   EntrySize                   10I 0
     D   EntryCCSID                  10I 0
     D   CountryID                    2A
     D   LanguageID                   3A
     D   SubSetInd                    1A
     D                               42A
     D APIEntryPoint                256A
     D                              128A
      *
      *‚OBJL0200 returned data structure (QUSLOBJ)
      *
     D OBJL0200        DS                  Qualified Based(OBJL0200@)
     D   ObjName                     10A
     D   ObjLib                      10A
     D   ObjType                     10A
     D   ObjInfSts                    1A
     D   ObjExtAtr                   10A
     D   ObjText                     50A
     D   ObjUsrAtr                   10A
     D                                7A
      *
      *---------------------------------------------------------------------
      *‚Global variables
      *---------------------------------------------------------------------
      *
     D UsrSpc@         S               *
     D qUsrSpc         DS
     D   UsrSpc                      10A   Inz('QUSLOBJ')
     D   UsrSpcLib                   10A   Inz('QTEMP')
     D UsrSpcSize      C                   10000000
      *
     D                 DS
     D L                             10I 0
     D LibDArr                             Dim(5000)
     D LibName                       10A   Overlay(LibdArr)
     D LibText                       50A   Overlay(LibdArr:*Next)
     D NbrLibObj                     10I 0 Overlay(LibdArr:*Next)
     D LibTotSize                    20I 0 Overlay(LibdArr:*Next)
      *
     D R                             10I 0
     D TotLibX         S             10A
     D NbrLibObjX      S             10A
     D LibTotSizeX     S             20A
      *
      *---------------------------------------------------------------------
      *‚Program interface
      *---------------------------------------------------------------------
      *
     D main            PR                  Extpgm(ThisProgram)
     D   P_Lib                       10A   Const
     D   P_Sort                       5A   Const
      *
     D main            PI
     D   P_Lib                       10A   Const
     D   P_Sort                       5A   Const
      *
      *=====================================================================
      *‚MAINLINE
      *=====================================================================
      /free

        //‚Set variables

        LibAtrToRtvDS.Nbr    = 2;
        LibAtrToRtvDS.Elm(1) = 6; //‚Library size
        LibAtrToRtvDS.Elm(2) = 7; //‚Objects in library
        L          = 0;
        LibName    = *HIVAL;
        LibText    = *HIVAL;
        NbrLibObj  = *HIVAL;
        LibTotSize = *HIVAL;

        open(e) QSYSPRT;

        //‚Create the user space

        reset QUSEC;
        quscrtus( qUsrSpc : *blanks : UsrSpcSize : x'00' : '*ALL' :
                  *blanks : '*NO' : QUSEC );
        if QUSEC.ErrBytesAvail > 0 and QUSEC.ErrMsgID <> 'CPF9870';
          exsr *pssr;
        endif;

        //‚Retrieve the pointer to the user space.

        reset QUSEC;
        qusptrus( qUsrSpc : UsrSpc@ : QUSEC );
        if QUSEC.ErrBytesAvail > 0;
          exsr *pssr;
        endif;

        //‚List all the specified libraries into the user space

        reset QUSEC;
        quslobj( qUsrSpc : 'OBJL0200' : P_Lib + 'QSYS' : '*LIB' : QUSEC );
        if QUSEC.ErrBytesAvail > 0;
          exsr *pssr;
        endif;

        //‚Process each library in the user space

        QUSH0100@ = UsrSpc@;
        OBJL0200@ = QUSH0100@ + QUSH0100.ListDataOS;
        for L = 1 to QUSH0100.EntryNbr;
          exsr RtvLibDtls;
          OBJL0200@ = OBJL0200@ + QUSH0100.EntrySize;
        endfor;

        //‚Sort the array

        select;
          when P_Sort = '*NAME';
            sorta LibName;
          when P_Sort = '*TEXT';
            sorta LibText;
          when P_Sort = '*OBJ';
            sorta NbrLibObj;
          when P_Sort = '*SIZE';
            sorta LibTotSize;
          other;
        endsl;

        //‚Write out the output

        TotLibX = %char( QUSH0100.EntryNbr );
        except Header;

        for L = 1 to QUSH0100.EntryNbr;
          evalr NbrLibObjX  = %char( NbrLibObj( L ) );
          evalr LibTotSizeX = %char( LibTotSize( L ) );
          except Detail;
        endfor;

        except Footer;

        qusdltus( qUsrSpc : QUSEC );
        close(e) QSYSPRT;

        return;

        //‚RtvLibDtls: Retrieve library details

        begsr RtvLibDtls;

          //‚Don't try to process QSYS

          if OBJL0200.ObjName = 'QSYS';
            LibName( L )    = OBJL0200.ObjName;
            LibText( L )    = OBJL0200.ObjText;
            NbrLibObj( L )  = 0;
            LibTotSize( L ) = 0;
            leavesr;
          endif;

          //‚Retrieve the library details

          clear QLIRR;
          reset QUSEC;
          qlirlibd( QLIRR : %size( QLIRR ) : OBJL0200.ObjName :
                    LibAtrToRtvDS : QUSEC );
          if QUSEC.ErrBytesAvail > 0;
            LibName( L )    = OBJL0200.ObjName;
            LibText( L )    = '**UNABLE TO RETRIEVE DETAILS**';
            NbrLibObj( L )  = 0;
            LibTotSize( L ) = 0;
            leavesr;
          endif;

          LibName( L ) = OBJL0200.ObjName;
          LibText( L ) = OBJL0200.ObjText;

          //‚Process the library detail variable-length records

          VarLen@ = %addr( QLIRR ) + 16;
          for R = 1 to QLIRR.VarLenRcdRtn;
            select;
              when VarLenDS.KeyID = 6; //‚Library total size
                LibSizeDS = VarLenDS.FldValue;
                LibTotSize( L ) = LibSize * LibSizeMult;
              when VarLenDS.KeyID = 7; //‚Number of objects in library
                NbrLibObj( L ) = VarLenDS.FldValInt;
              other;
            endsl;
            VarLen@ = VarLen@ + VarLenDS.RtnDtaLen;
          endfor;

        endsr;

        //‚*PSSR Error subroutine

        begsr *pssr;
          close(e) QSYSPRT;
          qusdltus( qUsrSpc : QUSEC );
        endsr;

      /end-free
      *=====================================================================
     OQSYSPRT   E            Header         1  3
     O                                              'Library details for -
     O                                              library '''
     O                       P_Lib
     O                                              ''' (ordered by'
     O                       P_Sort              +1
     O                                              ')'
     O          E            Header      1  1
     O                                              'Libraries processed:'
     O                       TotLibX             +1
     O          E            Header      1  1
     O                                            7 'Library'
     O                                           16 'Text'
     O                                           73 'Objects'
     O                                           96 'Total size (bytes)'
     O          E            Header      1  1
     O                                           10 '=========='
     O                                           37 '========================='
     O                                           62 '========================='
     O                                           76 '=========='
     O                                           98 '===================='
      *---------------------------------------------------------------------
     O          E            Detail      1  1
     O                       LibName(L)          10
     O                       LibText(L)          62
     O                       NbrLibObjX          76
     O                       LibTotSizeX         98
      *---------------------------------------------------------------------
     O          E            Footer      2
     O                                              'End of library details -
     O                                              for library '''
     O                       P_Lib
     O                                              ''' (ordered by'
     O                       P_Sort              +1
     O                                              ')'

User Comments

Please login or register to add comments

<Previous   Next>