gethistory.sas
Go to the documentation of this file.
1 /**
2  @file
3  @brief Returns the list of previously approved / rejected items.
4  @details History is taken from MPE_SUBMIT (where status_cd ne 'SUBMITTED') and
5  filtered according to the groups in MPE_SECURITY (unless the user is in the
6  DC admin group).
7 
8  <h4> SAS Macros </h4>
9  @li mpe_getvars.sas
10  @li mpe_getgroups.sas
11  @li mp_abort.sas
12  @li mf_getuser.sas
13 
14  <h4> Service Inputs </h4>
15  <h5> BROWSERPARAMS </h5>
16  The following variables MAY be provided from frontend (HIST can also be set
17  in MPE_CONFIG):
18 
19  @li HIST - number of records to return
20  @li STARTROW - the starting row (default is 1)
21 
22  <h4> Service Outputs </h4>
23 
24  <h5> FROMSAS </h5>
25  This table is returned, starting from &STARTROW for &HIST rows (ordered
26  descending on SUBMITTED datetime)
27  @li TABLE_ID
28  @li BASE_TABLE
29  @li SUBMITTED
30  @li SUBMITTED_REASON_TXT
31  @li SUBMITTER
32  @li REVIEWED
33  @li STATUS
34  @li REVIEWED_ON_DTTM
35  @li APPROVER
36 
37  <h5> HISTPARAMS </h5>
38 
39  @li HIST - rows returned
40  @li STARTROW - starting row used
41  @li NOBS - Number of observations (rows) available
42 
43  @version 9.3
44  @author 4GL Apps Ltd
45  @copyright 4GL Apps Ltd. This code may only be used within Data Controller
46  and may not be re-distributed or re-sold without the express permission of
47  4GL Apps Ltd.
48 
49 **/
50 
51 %mpeinit()
52 
53 /* hard coded HIST value */
54 %let hist=40;
55 %let startrow=1;
56 
57 /* load parameters from frontend (HIST and STARTROW) */
58 data _null_;
59  set &DC_LIBREF..mpe_config(where=(
60  var_scope="DC_REVIEW"
61  and var_name='HISTORY_ROWS'
62  and &dc_dttmtfmt. lt tx_to
63  and var_active=1
64  ));
65  call symputx('hist',var_value,'G');
66  putlog 'mpe_config: ' var_name "=" var_value;
67 run;
68 
69 /* load parameters (override HIST again if provided) */
70 %mpe_getvars(BrowserParams, BrowserParams)
71 
72 
73 /* determine users group membership */
74 %mpe_getgroups(user=%mf_getuser(),outds=work.usergroups)
75 
76 PROC FORMAT;
77  picture yymmddhhmmss other='%0Y-%0m-%0d %0H:%0M:%0S' (datatype=datetime);
78 RUN;
79 
80 /* check to see if the user is an admin, or has *ALL* access rights */
81 %let authcheck=0;
82 proc sql noprint;
83 create table work.authcheck
84  as select *
85  from usergroups
86  where upcase(groupname)="%upcase(&mpeadmins)"
87  or upcase(groupname) in (
88  select upcase(sas_group) from &mpelib..mpe_security
89  where libref='*ALL*' and &dc_dttmtfmt. lt tx_to
90  );
91 select count(*) into: authcheck from &syslast;
92 
93 %mp_abort(iftrue= (&syscc > 0)
94  ,mac=&_program
95  ,msg=%str(syscc=&syscc after auth check)
96 )
97 
98 /* now get the previous &hist records from mpe_submit */
99 proc sql;
100 create view work.submits as
101  select distinct a.TABLE_ID
102  ,cats(a.base_lib,'.',a.base_ds) as base_table
103  ,put(a.SUBMITTED_ON_DTTM,yymmddhhmmss.) as submitted
104  ,a.submitted_reason_txt
105  ,a.submitted_by_nm as submitter
106  ,put(a.REVIEWED_ON_DTTM,yymmddhhmmss.) as REVIEWED
107  ,a.submit_status_cd as status
108  ,a.reviewed_on_dttm
109  ,a.reviewed_by_nm as approver
110  from &mpelib..mpe_submit(where=(submit_status_cd ne 'SUBMITTED')) a
111 
112 %macro gethistory();
113 %if &authcheck=0 %then %do;
114  /* filter for allowed items */
115  left join &mpelib..mpe_security(where=(&dc_dttmtfmt. lt tx_to)) b
116  on a.base_lib=b.libref
117  and (a.base_ds=b.dsn or b.dsn='*ALL*')
118  where upcase(b.SAS_GROUP) in (select upcase(groupname) from work.usergroups)
119  and b.access_level in ('VIEW','AUDIT','EDIT','APPROVE')
120 %end;
121 %mend gethistory;
122 %gethistory()
123 
124  order by a.submitted_on_dttm desc;
125 
126 %mp_abort(iftrue= (&syscc > 0)
127  ,mac=&_program
128  ,msg=%str(syscc=&syscc after fetching submits)
129 )
130 
131 data work.fromsas;
132  set work.submits;
133  if _n_ ge &startrow;
134  n+1;
135  if n>&hist then stop;
136  drop n;
137 run;
138 
139 proc sql noprint;
140 select count(*) into: nobs from work.submits;
141 data work.histparams;
142  hist=&hist;
143  startrow=&startrow;
144  nobs=&nobs;
145 run;
146 
147 %mp_abort(iftrue= (&syscc > 0)
148  ,mac=&_program
149  ,msg=%str(syscc=&syscc)
150 )
151 %webout(OPEN)
152 %webout(OBJ,fromSAS)
153 %webout(OBJ,histparams)
154 %webout(CLOSE)
155 
156 %mpeterm()