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