Loading...
Searching...
No Matches
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 mp_abort.sas
38 @li mpe_getgroups.sas
39 @li mpe_getvars.sas
40 @li mpeinit.sas
41
42 @version 9.2
43 @author 4GL Apps Ltd
44 @copyright 4GL Apps Ltd. This code may only be used within Data Controller
45 and may not be re-distributed or re-sold without the express permission of
46 4GL Apps Ltd.
47
48 @sasjslint {"maxLineLength": 87}
49
50**/
51
52%mpeinit()
53
54%global MPLIB;
55
56/* load parameters */
57%mpe_getvars(SASControlTable, SASControlTable)
58
59/**
60 * assign the Library
61 */
62%put &=MPLIB;
63%dc_assignlib(READ,&MPLIB)
64
65%mp_abort(iftrue= (&syscc ne 0 )
66 ,mac=&_program..sas
67 ,msg=%str(Unable to assign &mplib library)
68)
69
70/**
71 * get the tables
72 */
73data members; /* empty table */
74 name='';
75 memtype='';
76run;
77ods output Members=Members;
78proc datasets library=&mplib ;
79quit;
80
81/* cannot avoid the proc datasets warn!ng for an empty lib */
82/* nolist means no output and nowarn has no effect */
83%put &=syscc;
84data _null_;
85 if "&syscc" ne "0" then do;
86 putlog "Library &mplib is empty, setting syscc to zero";
87 call symputx('syscc',0);
88 end;
89run;
90%put &=syscc;
91
92proc sql;
93create table work.mptables as
94 select distinct case when memtype='CATALOG' then cats(name,'-FC')
95 else name end as memname
96 from members;
97
98/* get security groups */
99%mpe_getgroups(user=%mf_getuser(),outds=groups)
100
101/* get security settings */
102data sec;
103 set &mpelib..mpe_security;
104 where &dc_dttmtfmt. lt tx_to and ACCESS_LEVEL='VIEW';
105 where also libref in ('*ALL*',"%upcase(&mplib)");
106run;
107
108/* check for any matching groups */
109proc sql noprint;
110create table matches as
111 select * from sec
112 where upcase(sas_group) in (select upcase(groupname) from groups);
113select count(*) into: securitygroupscount from matches;
114select count(*) into: ALL_CNT from matches
115 where libref='*ALL*'
116 or (libref="&mplib" and dsn='*ALL*');
117
118%mp_abort(iftrue= (&syscc ne 0)
119 ,mac=&_program..sas
120 ,msg=%str(syscc=&syscc)
121)
122
123%macro mpestp_viewtables();
124%if not %symexist(DC_RESTRICT_VIEWER) %then %let DC_RESTRICT_VIEWER=NO;
125
126/* scenario 1 - user is in admin group, hence can view all libraries */
127proc sql noprint;
128select count(*) into: scenario1 from groups where groupname="&mpeadmins";
129%if &scenario1>0 %then %return;
130
131/* scenario 2 - viewer unrestricted and no groups listed */
132%if &DC_RESTRICT_VIEWER=NO and &securitygroupscount=0 %then %return;
133
134/* scenario 3 - an *ALL* libref or DSN is listed */
135%if &all_cnt>0 %then %return;
136
137/* scenario 4 - specific tables listed */
138%if &securitygroupscount>0 %then %do;
139 proc sql;
140 delete from mptables
141 where upcase(memname) not in (select upcase(dsn) from sec);
142 %return;
143%end;
144
145/* viewer restricted and no groups listed */
146%if &DC_RESTRICT_VIEWER=YES and &securitygroupscount=0 %then %do;
147 data mptables;
148 set mptables;
149 stop;
150 run;
151 %return;
152%end;
153
154%mp_abort(iftrue= (1=1)
155 ,mac=&_program..sas
156 ,msg=%str(unhandled security logic error!)
157)
158
159%mend mpestp_viewtables;
160%mpestp_viewtables()
161
162
163/* get libinfo */
164proc sql;
165create table work.libinfo as
166 select a.engine,
167 a.libname,
168 a.paths,
169 a.perms,
170 a.owners,
171 a.schemas,
172 a.libid,
173 coalesce(b.libsize,0) as libsize,
174 coalesce(b.table_cnt,0) as table_cnt,
175 coalesce(b.catalog_cnt,0) as catalog_cnt
176 from &mpelib..mpe_datacatalog_libs(where=(&dc_dttmtfmt. lt tx_to)) a
177 left join &mpelib..mpe_datastatus_libs(where=(&dc_dttmtfmt. lt tx_to)) b
178 on a.libref=b.libref
179 where a.libref="&MPLIB";
180
181
182%webout(OPEN)
183%webout(OBJ,mptables)
184%webout(OBJ,libinfo)
185%webout(CLOSE)
186
187
188%mpeterm()