Loading...
Searching...
No Matches
mpe_tables_postedit.sas
Go to the documentation of this file.
1/**
2 @file
3 @brief Post Edit Hook script for the MPE_TABLES table
4 @details Post edit hooks provide additional backend validation for user
5 provided data. The incoming dataset is named `work.staging_ds` and is
6 provided in mpe_loader.sas.
7
8 Available macro variables:
9 @li DC_LIBREF - The DC control library
10 @li LIBREF - The library of the dataset being edited (is assigned)
11 @li DS - The dataset being edited
12
13 This validation checks MPE_TABLES to ensure modified / added records are
14 valid. If a non-default AUDIT_LIBDS is being used, there is also a check
15 to ensure that this table already exists.
16
17
18**/
19
20%let errmsg=;
21%let errflag=0;
22
23/* ensure uppercasing */
24data work.staging_ds;
25 set work.staging_ds;
26 /* PK fields should not be upcased if we are trying to delete records */
27 if upcase(_____DELETE__THIS__RECORD_____) ne "YES" then do;
28 LIBREF=upcase(LIBREF);
29 DSN=upcase(DSN);
30 end;
31 loadtype=upcase(loadtype);
32 buskey=upcase(buskey);
33 var_txfrom=upcase(var_txfrom);
34 var_txto=upcase(var_txto);
35 var_busfrom=upcase(var_busfrom);
36 var_busto=upcase(var_busto);
37 var_processed=upcase(var_processed);
38 close_vars=upcase(close_vars);
39 audit_libds=upcase(audit_libds);
40 rk_underlying=upcase(rk_underlying);
41
42 /* do not accept certain librefs */
43 if LIBREF in ('WORK','CASUSER','SASUSER')
44 then do;
45 call symputx('errmsg',"Invalid LIBREF: "!!LIBREF);
46 call symputx('errflag',1);
47 end;
48
49 /* check for valid loadtype */
50 if LOADTYPE not in ('UPDATE','TXTEMPORAL','FORMAT_CAT','BITEMPORAL','REPLACE')
51 then do;
52 call symputx('errmsg',"Invalid LOADTYPE: "!!LOADTYPE);
53 call symputx('errflag',1);
54 end;
55
56 /* force correct BUSKEY and DSN when loading format catalogs */
57 if LOADTYPE='FORMAT_CAT' then do;
58 BUSKEY='TYPE FMTNAME FMTROW';
59 DSN=scan(dsn,1,'-')!!'-FC';
60 end;
61
62 /* convert tabs into spaces */
63 buskey=translate(buskey," ","09"x);
64 rk_underlying=translate(rk_underlying," ","09"x);
65run;
66
67%mp_abort(iftrue=(&errflag=1)
68 ,mac=mpe_tables_postedit
69 ,msg=%superq(errmsg)
70)
71
72/* REPLACE loadtype is incompatible with row level EDIT security (#211) */
73proc sql noprint;
74create table work.badloadtypes as
75 select distinct cats(upcase(a.libref),'.',upcase(a.dsn)) as libds
76 from work.staging_ds(where=(loadtype='REPLACE'
77 and upcase(_____DELETE__THIS__RECORD_____) ne 'YES')) a
78 inner join &dc_libref..mpe_row_level_security(where=(
79 rls_active=1 and &dc_dttmtfmt. lt tx_to
80 and upcase(rls_scope) in ('EDIT','ALL'))) b
81 on upcase(a.libref)=upcase(b.rls_libref)
82 and upcase(a.dsn)=upcase(b.rls_table);
83
84%let badloadtypes=0;
85%let badloadtype=;
86data _null_;
87 set work.badloadtypes;
88 call symputx('badloadtypes',_n_);
89 call symputx('badloadtype',libds);
90run;
91
92%mp_abort(iftrue=(&badloadtypes ne 0)
93 ,mac=mpe_tables_postedit
94 ,msg=%str(REPLACE loadtype cannot be applied to table(s) with row level%trim(
95 ) EDIT security, eg: &badloadtype. Remove the security rule(s) or change%trim(
96 ) the loadtype.)
97)
98
99/* get distinct list of audit libs */
100proc sql;
101create table work.liblist as
102 select distinct audit_libds
103 from work.staging_ds
104 where audit_libds not in ('','0', "&dc_libref..MPE_AUDIT")
105 and upcase(_____DELETE__THIS__RECORD_____) ne "YES";
106
107/* assign the libs */
108data _null_;
109 set work.liblist;
110 call symputx(cats('lib',_n_),audit_libds);
111 libref=scan(audit_libds,1,'.');
112 call execute('%dc_assignlib(WRITE,'!!libref!!')');
113run;
114
115/* check the audit tables exist */
116data _null_;
117 set work.liblist;
118
119 if exist(audit_libds,"DATA")=0 then do;
120 call symputx('errmsg',
121 "Audit Table "!!audit_libds!!" does not exist, or could not be assigned."
122 );
123 call symputx('errflag',1);
124 end;
125run;
126
127%mp_abort(iftrue=(&errflag=1)
128 ,mac=mpe_tables_postedit
129 ,msg=%superq(errmsg)
130)
131