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 /* check for valid loadtype */
43 if LOADTYPE not in ('UPDATE','TXTEMPORAL','FORMAT_CAT','BITEMPORAL','REPLACE')
44 then do;
45 call symputx('errmsg',"Invalid LOADTYPE: "!!LOADTYPE);
46 call symputx('errflag',1);
47 end;
48
49 /* force correct BUSKEY and DSN when loading format catalogs */
50 if LOADTYPE='FORMAT_CAT' then do;
51 BUSKEY='TYPE FMTNAME FMTROW';
52 DSN=scan(dsn,1,'-')!!'-FC';
53 end;
54
55 /* convert tabs into spaces */
56 buskey=translate(buskey," ","09"x);
57 rk_underlying=translate(rk_underlying," ","09"x);
58run;
59
60%mp_abort(iftrue=(&errflag=1)
61 ,mac=mpe_tables_postedit
62 ,msg=%superq(errmsg)
63)
64
65/* get distinct list of audit libs */
66proc sql;
67create table work.liblist as
68 select distinct audit_libds
69 from work.staging_ds
70 where audit_libds not in ('','0', "&dc_libref..MPE_AUDIT")
71 and upcase(_____DELETE__THIS__RECORD_____) ne "YES";
72
73/* assign the libs */
74data _null_;
75 set work.liblist;
76 call symputx(cats('lib',_n_),audit_libds);
77 libref=scan(audit_libds,1,'.');
78 call execute('%dc_assignlib(WRITE,'!!libref!!')');
79run;
80
81/* check the audit tables exist */
82data _null_;
83 set work.liblist;
84
85 if exist(audit_libds,"DATA")=0 then do;
86 call symputx('errmsg',
87 "Audit Table "!!audit_libds!!" does not exist, or could not be assigned."
88 );
89 call symputx('errflag',1);
90 end;
91run;
92
93%mp_abort(iftrue=(&errflag=1)
94 ,mac=mpe_tables_postedit
95 ,msg=%superq(errmsg)
96)
97