viewtables.sas
Go to the documentation of this file.
1 /**
2  @file viewtables.sas
3  @brief List the tables and format catalogs the user can view
4  @details Provide a library and get list of tables and catalogs. Also return
5  the libinfo details.
6 
7  <h4> Service Inputs </h4>
8  <h5> SASControlTable </h5>
9  Just one input - MPLIB (the libref to get tables and info for)
10  |MPLIB:$char8.|
11  |---|
12  |SOMELIB|
13 
14  <h4> Service Outputs </h4>
15  <h5> work.mptables </h5>
16 
17  |MEMNAME:$char32.|
18  |---|
19  |DS1|
20  |DS2|
21  |DS3|
22 
23  etc
24 
25  <h5> work.libinfo </h5>
26  If attributes are empty, they don't need to be shown on screen.
27 
28  |engine $|libname $|paths $|perms $|owners $|schemas $ |libid $|libsize $|table_cnt |
29  |---|---|---|---|---|---|---|---|---|
30  |V9|SOMELIB|"some/path"|rwxrwxr-x|sassrv|` `|` `|636MB|33|
31 
32 
33 
34  <h4> SAS Macros </h4>
35  @li dc_assignlib.sas
36  @li mf_getuser.sas
37  @li mpe_getgroups.sas
38  @li mpe_getvars.sas
39  @li mpeinit.sas
40 
41  @version 9.2
42  @author 4GL Apps Ltd
43  @copyright 4GL Apps Ltd. This code may only be used within Data Controller
44  and may not be re-distributed or re-sold without the express permission of
45  4GL Apps Ltd.
46 **/
47 
48 %mpeinit()
49 
50 %global MPLIB;
51 
52 /* load parameters */
53 %mpe_getvars(SASControlTable, SASControlTable)
54 
55 /**
56  * assign the Library
57  */
58 %put &=MPLIB;
59 %dc_assignlib(READ,&MPLIB)
60 
61 %mp_abort(iftrue= (&syscc ne 0 )
62  ,mac=&_program..sas
63  ,msg=%str(Unable to assign &mplib library)
64 )
65 
66 /**
67  * get the tables
68  */
69 data members; /* empty table */
70  name='';
71  memtype='';
72 run;
73 ods output Members=Members;
74 proc datasets library=&mplib ;
75 quit;
76 
77 /* cannot avoid the proc datasets warn!ng for an empty lib */
78 /* nolist means no output and nowarn has no effect */
79 %put &=syscc;
80 data _null_;
81  if "&syscc" ne "0" then do;
82  putlog "Library &mplib is empty, setting syscc to zero";
83  call symputx('syscc',0);
84  end;
85 run;
86 %put &=syscc;
87 
88 proc sql;
89 create table work.mptables as
90  select distinct case when memtype='CATALOG' then cats(name,'-FC')
91  else name end as memname
92  from members;
93 
94 /* get security groups */
95 %mpe_getgroups(user=%mf_getuser(),outds=groups)
96 
97 /* get security settings */
98 data sec;
99  set &mpelib..mpe_security;
100  where &dc_dttmtfmt. lt tx_to and ACCESS_LEVEL='VIEW';
101  where also libref in ('*ALL*',"%upcase(&mplib)");
102 run;
103 
104 /* check for any matching groups */
105 proc sql noprint;
106 create table matches as
107  select * from sec
108  where upcase(sas_group) in (select upcase(groupname) from groups);
109 select count(*) into: securitygroupscount from matches;
110 select count(*) into: ALL_CNT from matches
111  where libref='*ALL*'
112  or (libref="&mplib" and dsn='*ALL*');
113 
114 %mp_abort(iftrue= (&syscc ne 0)
115  ,mac=&_program..sas
116  ,msg=%str(syscc=&syscc)
117 )
118 
119 %macro mpestp_viewtables();
120 %if not %symexist(DC_RESTRICT_VIEWER) %then %let DC_RESTRICT_VIEWER=NO;
121 
122 /* scenario 1 - user is in admin group, hence can view all libraries */
123 proc sql noprint;
124 select count(*) into: scenario1 from groups where groupname="&mpeadmins";
125 %if &scenario1>0 %then %return;
126 
127 /* scenario 2 - viewer unrestricted and no groups listed */
128 %if &DC_RESTRICT_VIEWER=NO and &securitygroupscount=0 %then %return;
129 
130 /* scenario 3 - an *ALL* libref or DSN is listed */
131 %if &all_cnt>0 %then %return;
132 
133 /* scenario 4 - specific tables listed */
134 %if &securitygroupscount>0 %then %do;
135  proc sql;
136  delete from mptables
137  where upcase(memname) not in (select upcase(dsn) from sec);
138  %return;
139 %end;
140 
141 /* viewer restricted and no groups listed */
142 %if &DC_RESTRICT_VIEWER=YES and &securitygroupscount=0 %then %do;
143  data mptables;
144  set mptables;
145  stop;
146  run;
147  %return;
148 %end;
149 
150 %mp_abort(iftrue= (1=1)
151  ,mac=&_program..sas
152  ,msg=%str(unhandled security logic error!)
153 )
154 
155 %mend mpestp_viewtables;
156 %mpestp_viewtables()
157 
158 
159 /* get libinfo */
160 proc sql;
161 create table work.libinfo as
162  select a.engine,
163  a.libname,
164  a.paths,
165  a.perms,
166  a.owners,
167  a.schemas,
168  a.libid,
169  coalesce(b.libsize,0) as libsize,
170  coalesce(b.table_cnt,0) as table_cnt
171  from &mpelib..mpe_datacatalog_libs(where=(&dc_dttmtfmt. lt tx_to)) a
172  left join &mpelib..mpe_datastatus_libs(where=(&dc_dttmtfmt. lt tx_to)) b
173  on a.libref=b.libref
174  where a.libref="&MPLIB";
175 
176 
177 %webout(OPEN)
178 %webout(OBJ,mptables)
179 %webout(OBJ,libinfo)
180 %webout(CLOSE)
181 
182 
183 %mpeterm()