Free Format SQLRPGLE Shell Program: part 3

Author: Lionel Halvorsen
Mar 1, 2010

To carry the shell example a little further, one could use the DSPOBJD command to create an outfile for the entire library and then run this program.

The program does a descending sort by object size and then prints a total at the bottom. This program could be easily modified to check library and/or object sizes.

*-------------------------------------
* library size
*-------------------------------------
fqsysprt   o    f  132        printer oflind(OverFlow)     
d total           s             13p 0 inz
d count           s              9p 0 inz
*                                                                                                    
d filestr         ds

d  odlbnm                       10a
d  odobnm                       10a
d  odobtp                        8a
d  odobat                       10a
d  odobtx                       50a
d  odobsz                       10p 0

      *
/free
// write column headers
exsr setup;

// loop through file
exec sql
declare C1 cursor for
SELECT odlbnm,odobnm,odobtp,odobat,odobtx,odobsz
FROM qgpl/dspobjd
ORDER BY odobsz desc
for fetch only;

exec sql OPEN C1;
dow sqlcod=0;
exec sql FETCH C1 INTO:filestr;
if sqlcod=0;
exsr movdet;
endif;
enddo;
exec sql CLOSE C1;
except tot1;
*inlr=*on;
return;

begsr movdet;
exsr overflowSR;
except det1;
total+=odobsz;
count+=1;
endsr;

begsr setup;
except head1;
endsr;

begsr overflowSR;
if OverFlow;
except head1;
endif;
endsr;
/end-free 

     oqsysprt   e            head1       2  1
     o                                           14 'Size'
     o                                           29 'Library' 
     o                                           40 'Object'
     o                                           51 'Type'
     o                                           63 'Attribute '
     o                                           75 'Description' 
     o          e            det1           1
     o                       odobsz        j     15
     o                       odlbnm              29
     o                       odobnm              40
     o                       odobtp              50
     o                       odobat              63
     o                       odobtx             114
     o          e            tot1           1 
     o                                           16 'Library Total='
     o                       total         j     34
     o                                           50 'Object Count='
     o                       count         j     65