Loading...
Searching...
No Matches
postdata.sas
Go to the documentation of this file.
1/**
2 @file postdata.sas
3 @brief Either returns the file diffs or actually loads the data to target
4 @details Before loading the target, a check is made against the time the
5 target was last updated (backend) and the time the DIFF was generated
6 (frontend). If the target was updated whilst the DIFF was on the screen,
7 then the provided diff may have been incorrect and so a new DIFF should be
8 generated and approved before load.
9
10 Only 100 rows (of each DIFF type) are displayed on the DIFF screen.
11
12 <h4> Service Inputs </h4>
13
14 <h5> SASCONTROLTABLE </h5>
15 |ACTION:$char10.|TABLE:$char32.|DIFFTIME:$char29.|
16 |---|---|---|
17 |SHOW_DIFFS|DC20220208T142124517_124703_1184|"Tue, 08 Feb 2022 14:23:05 GMT"|
18
19 <h4> SAS Macros </h4>
20 @li dc_assignlib.sas
21 @li dc_cassave.sas
22 @li mf_existvar.sas
23 @li mf_getapploc.sas
24 @li mf_getattrn.sas
25 @li mf_getengine.sas
26 @li mf_getquotedstr.sas
27 @li mf_getuniquelibref.sas
28 @li mf_getuser.sas
29 @li mf_nobs.sas
30 @li mf_verifymacvars.sas
31 @li mp_abort.sas
32 @li mp_cntlout.sas
33 @li mp_lockanytable.sas
34 @li mpe_accesscheck.sas
35 @li mpe_alerts.sas
36 @li mpe_runhook.sas
37 @li mpe_targetloader.sas
38 @li removecolsfromwork.sas
39
40
41 @version 9.2
42 @author 4GL Apps Ltd
43 @copyright 4GL Apps Ltd. This code may only be used within Data Controller
44 and may not be re-distributed or re-sold without the express permission of
45 4GL Apps Ltd.
46
47**/
48
49/* this could be a config setting if required */
50%let maxdiff=100;
51
52%mpeinit()
53
54/* load parameters */
55data _null_;
56 set work.sascontroltable;
57 call symputx('ACTION',ACTION);
58 call symputx('LOAD_REF',TABLE);
59 /* DIFFTIME is when the DIFF was generated on the frontend */
60 call symputx('DIFFTIME',DIFFTIME);
61 putlog (_all_)(=);
62run;
63
64%global action is_err err_msg msg;
65%let is_err=0;
66
67%let user=%mf_getuser();
68%let sastime=%sysfunc(datetime());
69data sastime;
70 dt_sastime=&sastime;
71run;
72
73PROC FORMAT;
74 picture yymmddhhmmss other='%0Y-%0m-%0d %0H:%0M:%0S' (datatype=datetime);
75 picture flatdate other='%0Y%0m%0d_%0H%0M%0S' (datatype=datetime);
76RUN;
77
78/* SHOW_DIFFS works by getting the temp tables from the bitemporal loader */
79/* so we share much of the logic from the actual load process */
80%let isfmtcat=0;
81data APPROVE1;
82 set &mpelib..mpe_submit;
83 where TABLE_ID="&LOAD_REF";
84 /* fetch mpe_submit data */
85 libds=cats(base_lib,'.',base_ds);
86 REVIEWED_ON=put(reviewed_on_dttm,datetime19.);
87 call symputx('REVIEW_STATUS_ID',submit_status_cd,'l');
88 call symputx('NUM_OF_APPROVALS_REQUIRED',NUM_OF_APPROVALS_REQUIRED);
89 call symputx('num_of_approvals_remaining',num_of_approvals_remaining);
90
91 /* other stuff that's useful to do in data step */
92 call symputx('orig_libds',libds);
93 call symputx('libds',libds);
94 if substr(cats(reverse(libds)),1,3)=:'CF-' then do;
95 libds=scan(libds,1,'-');
96 putlog "Format Catalog Captured";
97 call symputx('isfmtcat',1);
98 libds='work.fmtextract';
99 call symputx('libds',libds);
100 end;
101 putlog (_all_)(=);
102 /* convert provided string DIFFTIME back to a numeric SAS datetime */
103 if "&action" ne "SHOW_DIFFS" then do;
104 call symputx('DIFFTIME',input(symget('DIFFTIME'),anydtdtm18.));
105 end;
106 length difftime $32;
107 DIFFTIME=put(&sastime,datetime19.2);
108run;
109
110%mp_cntlout(
111 iftrue=(&isfmtcat=1)
112 ,libcat=&orig_libds
113 ,fmtlist=0
114 ,cntlout=work.fmtextract
115)
116
117%mp_abort(
118 iftrue=(%mf_verifymacvars(difftime orig_libds libds load_ref)=0)
119 ,mac=&_program
120 ,msg=%str(Missing: difftime orig_libds libds load_ref)
121)
122
123/* security checks */
124%mpe_accesscheck(&orig_libds,outds=authEDIT,user=&user,access_level=EDIT)
125%mpe_accesscheck(&orig_libds,outds=authAPP,user=&user,access_level=APPROVE)
126
127%mp_abort(iftrue= (&syscc ne 0)
128 ,mac=&_program
129 ,msg=%str(syscc=&syscc Before entering postdata macro)
130)
131
132%mp_abort(
133 iftrue=(
134 %mf_getattrn(work.authEDIT,NLOBS)=0 & %mf_getattrn(work.authAPP,NLOBS)=0
135 )
136 ,mac=&_program
137 ,msg=%str(&user not authorised to view approval screen for &orig_libds)
138)
139
140%macro quickmacro(inds,outds);
141 data &outds ;
142 %if %length(&VAR_BUSFROM)>0 %then %do;
143 format &VAR_BUSFROM &VAR_BUSTO yymmddhhmmss.;
144 %end;
145 if 0 then set &emptybasetable;
146 set &inds;
147 %if %mf_existvar(&libds,&var_txfrom) %then %do;
148 drop &var_txfrom &var_txto;
149 %end;
150 %if %mf_existvar(&inds,_____DELETE__THIS__RECORD_____) %then %do;
151 drop _____DELETE__THIS__RECORD_____;
152 %end;
153 %if %mf_existvar(&inds,&VAR_PROCESSED) %then %do;
154 drop &VAR_PROCESSED;
155 %end;
156 run;
157%mend quickmacro;
158
159%macro postdata();
160
161%if %quote(&REVIEW_STATUS_ID)=%quote(REJECTED)
162 or %quote(&REVIEW_STATUS_ID)=%quote(APPROVED) %then
163%do;
164 data params; set approve1; run;
165 %webout(OPEN)
166 %webout(OBJ,PARAMS)
167 %webout(CLOSE)
168 %return;
169%end;
170
171%mp_abort(iftrue= (&syscc ne 0)
172 ,mac=&_program..sas
173 ,msg=%str(syscc=&syscc)
174)
175
176%if &action=APPROVE_TABLE %then %do;
177
178 /* check user is authorised to approve table */
179 /* user could be an editor but not an approver */
180 %mp_abort(iftrue= (%mf_getattrn(work.authAPP,NLOBS)=0)
181 ,mac=&_program
182 ,msg=%str(&user may not APPROVE changes)
183 )
184
185 /* see if this user has already submitted an approval */
186 %let prev_upload_check=1;
187 proc sql;
188 select count(*) into: prev_upload_check from &mpelib..mpe_review
189 where TABLE_ID="&LOAD_REF" and REVIEWED_BY_NM="&user"
190 and REVIEW_STATUS_ID ne "SUBMITTED";
191 %let authcheck=%mf_getattrn(work.authAPP,NLOBS);
192 %if &authcheck=0 or &prev_upload_check=1 %then %do;
193 %put %str(WARN)ING: &=authcheck &=prev_upload_check;
194 data apPARAMS;
195 AUTHORISED=&authcheck;
196 PREV_UPLOAD_CHECK=&prev_upload_check;
197 run;
198 %webout(OPEN)
199 %webout(OBJ,apPARAMS);
200 %webout(CLOSE)
201 %return;
202 %end;
203
204 /* now check if table has been updated since DIFF screen shown */
205 %local fmt_tm usernm last_load etlsource;
206 %let last_load=0;
207 proc sql noprint;
208 select max(processed_dttm) format=16.2 into: last_load
209 from &mpelib..mpe_dataloads
210 where libref="%scan(&orig_libds,1,.)" and dsn="%scan(&orig_libds,2,.)";
211 select processed_dttm format=datetime19., user_nm, etlsource
212 into: fmt_tm, :usernm, :etlsource
213 from &mpelib..mpe_dataloads
214 where libref="%scan(&orig_libds,1,.)" and dsn="%scan(&orig_libds,2,.)"
215 and processed_dttm=&last_load;
216 %put TIMECHECK: &last_load>&difftime;
217 %if %sysevalf(&last_load>&difftime,boolean)=1 %then %do;
218 %let is_err=1;
219 %let err_msg=&orig_libds was updated in batch %trim(&etlsource
220 ) by %trim(&usernm) on &fmt_tm - please refresh the page!!;
221 %return;
222 %end;
223 %if &syscc ne 0 %then %do;
224 %let is_err=1;
225 %let err_msg=syscc=&syscc before logchange;
226 %return;
227 %end;
228
229 /* upload about to commence so ensure logs */
230 options notes mprint source2;
231 %local oldloc is_test applocus;
232 %if %symexist(SYSPRINTTOLOG) %then %let oldloc=&SYSPRINTTOLOG;
233 %else %let oldloc=%qsysfunc(getoption(LOG));
234
235 /* A test is deployed under <appLoc>/tests/, and its log is the artefact the
236 run reports - redirecting it into the approval folder hides the very output
237 a failing test is being read for. Deployed services sit under
238 <appLoc>/services/ instead, so the segment after the appLoc decides it. */
239 %let applocus=%mf_getapploc(&_program);
240 %let is_test=%index(%upcase(&_program),%upcase(&applocus)/TESTS/)>0;
241
242 %if &is_test=0 %then %do;
243 %if %length(&oldloc)>0 %then %do;
244 proc printto
245 log="&mpelocapprovals/&LOAD_REF/approval.log";
246 run;
247 data _null_;
248 if _n_=1 then do;
249 length oldloc $1000;
250 oldloc=symget('oldloc');
251 putlog "****** redirected:" oldloc " *****";
252 end;
253 infile &oldloc;
254 input; putlog _infile_;
255 run;
256 %end;
257 %else %do;
258 proc printto
259 log="&mpelocapprovals/&LOAD_REF/approval.log";
260 run;
261 %end;
262 %end;
263
264 %if &syscc ne 0 %then %do;
265 %let is_err=1;
266 %let err_msg=syscc=&syscc after logchange;
267 %return;
268 %end;
269%end;
270
271/**
272 * upload the actual table
273 */
274%local libref ds;
275%let libref=%scan(&orig_libds,1,.);
276%let ds=%scan(&orig_libds,2,.);
277
278proc sql noprint;
279select PRE_APPROVE_HOOK, POST_APPROVE_HOOK, LOADTYPE, var_txfrom, var_txto
280 ,BUSKEY, VAR_BUSFROM, VAR_BUSTO
281 ,AUDIT_LIBDS, NOTES, coalesce(NUM_OF_APPROVALS_REQUIRED,1)
282 ,VAR_PROCESSED
283 into: PRE_APPROVE_HOOK, :POST_APPROVE_HOOK, :LOADTYPE,:var_txfrom,:var_txto
284 ,:BUSKEY,:VAR_BUSFROM,:VAR_BUSTO
285 ,:AUDIT_LIBDS, :TABLE_DESC, :NUM_OF_APPROVALS_REQUIRED_TOT
286 ,:VAR_PROCESSED
287 from &mpelib..mpe_tables
288 where &dc_dttmtfmt. lt tx_to
289 and libref="&libref"
290 and dsn="&ds";
291
292%mp_abort(
293 iftrue=(%mf_verifymacvars(mpelocapprovals orig_libds)=0)
294 ,mac=&_program
295 ,msg=%str(Missing: mpelocapprovals orig_libds)
296)
297
298/* get dataset from approvals location (has same name as load_ref) */
299%let tmplib=%mf_getuniquelibref();
300libname &tmplib "&mpelocapprovals/&LOAD_REF";
301data STAGING_DS;
302 set &tmplib..&LOAD_REF;
303run;
304
305%mp_abort(iftrue= (&syscc ne 0)
306 ,mac=&_program..sas
307 ,msg=%str(syscc=&syscc before preapprove)
308)
309
310%dc_assignlib(WRITE,&libref)
311
312/* run pre-approve hook - occurs both BEFORE _and_ AFTER the diff */
313%mpe_runhook(PRE_APPROVE_HOOK)
314
315%mp_abort(iftrue= (&syscc ne 0)
316 ,mac=&_program..sas
317 ,msg=%str(syscc=&syscc after preapprove)
318)
319
320%if &num_of_approvals_remaining>1 and &action=APPROVE_TABLE %then %do;
321
322 /* append to mpe_review table */
323 %let apprno=%eval(&num_of_approvals_required-&num_of_approvals_remaining+1);
324 data work.append_review;
325 if 0 then set &mpelib..mpe_review;
326 TABLE_ID="&LOAD_REF";
327 BASE_TABLE="&orig_libds";
328 REVIEW_STATUS_ID="APPROVED";
329 REVIEWED_BY_NM="&user";
330 REVIEWED_ON_DTTM=&sastime;
331 REVIEW_REASON_TXT="APPROVAL &apprno of &num_of_approvals_required";
332 output;
333 stop;
334 run;
335 %mp_lockanytable(LOCK,
336 lib=&mpelib,ds=mpe_review,ref=%str(&LOAD_REF Approval),
337 ctl_ds=&mpelib..mpe_lockanytable
338 )
339 proc append base=&mpelib..mpe_review data=work.append_review;
340 run;
341 %mp_lockanytable(UNLOCK,
342 lib=&mpelib,ds=mpe_review,
343 ctl_ds=&mpelib..mpe_lockanytable
344 )
345
346 /* update mpe_submit table */
347 %mp_lockanytable(LOCK,
348 lib=&mpelib,ds=mpe_submit,ref=%str(&LOAD_REF Approval),
349 ctl_ds=&mpelib..mpe_lockanytable
350 )
351 proc sql;
352 update &mpelib..mpe_submit
353 set num_of_approvals_remaining=&num_of_approvals_remaining-1,
354 reviewed_by_nm="&user",
355 reviewed_on_dttm=&sastime
356 where table_id="&LOAD_REF";
357 %mp_lockanytable(UNLOCK,
358 lib=&mpelib,ds=mpe_submit,
359 ctl_ds=&mpelib..mpe_lockanytable
360 )
361
362 data apReqd;
363 AUTHORISED=1;
364 ALREADY_UPDATED=0;
365 ALREADY_UPDATED_DTTM=.;
366 set approve1; /* js will test for NUM_OF_APPROVALS_REQUIRED */
367 run;
368 %removecolsfromwork(___TMP___MD5)
369 %webout(OPEN)
370 %webout(OBJ,apReqd);
371 %webout(CLOSE)
372 %return;
373
374%end;
375
376%mp_abort(iftrue= (&syscc ne 0)
377 ,mac=&_program..sas
378 ,msg=%str(syscc=&syscc entering TARGETLOADER)
379)
380%mpe_targetloader(libds=&orig_libds
381 ,now= &sastime
382 ,etlsource=&LOAD_REF
383 ,STAGING_DS=STAGING_DS
384 ,dclib=&mpelib
385%if &action=APPROVE_TABLE %then %do;
386 ,LOADTARGET=YES
387%end;
388%else %do;
389 ,LOADTARGET=NO
390%end;
391 ,dc_dttmtfmt=&dc_dttmtfmt.
392)
393
394
395%if %mf_getattrn(STAGING_DS,NLOBS)=0 %then %do;
396 /* empty dataset! */
397 data out;
398 set STAGING_DS;
399 run;
400 %return;
401%end;
402
403%mp_abort(iftrue= (&syscc ne 0)
404 ,mac=&_program..sas
405 ,msg=%str(syscc=&syscc entering SHOWDIFFS)
406)
407%if &action=SHOW_DIFFS %then %do;
408
409 /**
410 * Now prepare the SHOW DIFFS (approve) screen
411 */
412
413 /*To create the CURRENT diffs, we compare with the ACTUAL data. But first
414 need to find out what version TIME to query it for.. */
415 proc sql noprint;
416 select max(processed_dttm)-1 format=datetime19. into: tstamp
417 from &mpelib..mpe_dataloads
418 where libref="&libref" and dsn="&ds" and ETLSOURCE="&LOAD_REF";
419 quit;
420 %if &tstamp=. %then %let tstamp=%sysfunc(datetime(),datetime19.);
421
422 /**
423 * now create the DIFFS dataset
424 * If using a database, then utilise pass through!
425 * Create a temporary table inside the database for joins..
426 */
427 options mprint;
428 %let engine_type=%mf_getEngine(%scan(&libds,1,.));
429 %put &libds engine type = &engine_type;
430 %local inner_table ;
431 %if &engine_type=OLEDB %then %do;
432 /* generate a unique ID for the temporary table */
433 data _null_;
434 call symputx('UNIQUE_REF'
435 ,cats(round(datetime(),1)
436 ,'_'
437 ,round(ranuni(0)*100000,1)
438 )
439 ,'l'
440 );
441 run;
442 %let inner_table=&libref.."##DIFF_&UNIQUE_REF"n;
443 proc sql;
444 create table &inner_table as
445 select * from work.outds_mod;
446 %end;
447 %else %let inner_table=work.outds_mod;
448 proc sql;
449 create view work.originals2 as
450 select b.*
451 from &inner_table a
452 inner join &libds
453 %if &loadtype=BITEMPORAL or &loadtype=TXTEMPORAL %then %do;
454 (where=("&tstamp"dt < &VAR_TXTO))
455 %end;
456 b
457 on 1
458 %do idx_pk=1 %to %sysfunc(countw(&buskey));
459 %let idx_val=%scan(&buskey,&idx_pk);
460 and a.&idx_val=b.&idx_val
461 %end;
462 order by %mf_getquotedstr(in_str=&buskey,dlm=%str(,),quote=)
463 ;
464
465 create view bitemp5c_updates2 as
466 select * from work.outds_mod
467 order by %mf_getquotedstr(in_str=&buskey,dlm=%str(,),quote=)
468 ;
469
470 data; set &libds;stop;run;
471 %let emptybasetable=&syslast;
472
473 options varlenchk=nowarn; /* for small numerics (<8) */
474 %quickmacro(work.outds_del,deleted)
475 %quickmacro(work.outds_add,new)
476 %quickmacro(bitemp5c_updates2,updates)
477 %quickmacro(originals2,originals)
478
479 %mp_abort(iftrue= (&syscc ne 0)
480 ,mac=&_program..sas
481 ,msg=%str(syscc=&syscc in quickmacro)
482 )
483
484 /* extract colnames for md5 creation / change tracking */
485 proc contents noprint data=work.updates
486 out=cols (keep=name type length varnum format);
487 run;
488 proc sort data=cols out=cols(drop=varnum); by varnum;run;
489 data cols; set cols; name=upcase(name);run;
490 %let tempDIFFS_CSV=tempDiffs_%trim(
491 %sysfunc(datetime(),flatdate.)).csv;
492
493 /**
494 * Store temp tables so we have a record of diffs
495 * do not change this libname or table name as it is used in some
496 * post approve hooks
497 */
498
499 data TEMPDIFFS (compress=no) /* for realistic file size */;
500 length _____status $10;
501 set work.deleted (in=_____del)
502 work.new(in=_____new)
503 work.updates (in=_____upd)
504 work.originals2 (in=_____orig);
505 if _____del then _____status='DELETED ';
506 else if _____new then _____status='NEW';
507 else if _____upd then _____status='UPDATED';
508 else if _____orig then _____status='ORIGINAL';
509 run;
510 proc export data=TEMPDIFFS dbms=csv replace
511 outfile="&mpelocapprovals/&LOAD_REF/&tempDIFFS_CSV" ;
512 run;
513 proc sql noprint;
514 select filesize format=sizekmg10.1, filesize as filesize_raw
515 into: filesize,:filesize_raw
516 from dictionary.tables
517 where libname='WORK' and memtype='DATA' and memname='TEMPDIFFS';
518
519 data params;
520 set approve1;
521 DIFFS_CSV="&tempDIFFS_CSV";
522 FILESIZE="&filesize";
523 FILESIZE_RAW=&filesize_raw;
524 if %mf_nobs(work.originals)>&maxdiff
525 or %mf_nobs(work.new)>&maxdiff
526 or %mf_nobs(work.deleted)>&maxdiff
527 or %mf_nobs(work.updates)>&maxdiff
528 then TRUNCATED="YES";
529 else TRUNCATED="NO";
530
531 NUM_ADDED=%mf_getattrn(work.new,NLOBS);
532 NUM_DELETED=%mf_getattrn(work.deleted,NLOBS);
533 NUM_UPDATED=%mf_getattrn(work.updates,NLOBS);
534 SUBMITTED_ON=put(submitted_on_dttm,datetime19.);
535 %if %mf_getattrn(work.authAPP,NLOBS)>0 %then %do;
536 ISAPPROVER='YES';
537 %end;
538 %else %do;
539 ISAPPROVER='NO';
540 %end;
541 run;
542
543 /*
544 * The PRE_APPROVE_HOOK may have applied custom formats to the staged table.
545 * To ensure consistency in the DIFF screen, we should apply the same formats
546 * to the base table. Limit rows at the same time.
547 */
548 data work.originals;
549 if 0 then set deleted new updates;
550 set work.originals;
551 if _n_>&maxdiff then stop;
552 run;
553
554 /* get additional submits against the same base table */
555 proc sort data=&mpelib..mpe_submit(where=(
556 submit_status_cd='SUBMITTED'
557 and cats(base_lib,'.',base_ds)="&orig_libds"
558 and table_id ne "&LOAD_REF"
559 )) out=submits;
560 by descending submitted_on_dttm;
561 run;
562
563 /* filter last 10 */
564 data submits;
565 set submits;
566 if _n_>10 then stop;
567 run;
568
569 %mp_abort(iftrue= (&syscc ne 0)
570 ,mac=&_program..sas
571 ,msg=%str(syscc=&syscc SHOWDIFFS prior to streamout)
572 )
573
574 %removecolsfromwork(___TMP___MD5)
575 %webout(OPEN)
576 %webout(OBJ,params)
577 %webout(OBJ,cols)
578 %webout(OBJ,submits)
579 %webout(OBJ,deleted,fmt=N,missing=STRING,maxobs=&maxdiff)
580 %webout(OBJ,new,fmt=N,missing=STRING,maxobs=&maxdiff)
581 %webout(OBJ,updates,fmt=N,missing=STRING,maxobs=&maxdiff)
582 %webout(OBJ,ORIGINALS,fmt=N,missing=STRING)
583 /* need same for formatted view */
584 %webout(OBJ,deleted,dslabel=fmt_deleted,fmt=Y,missing=STRING,maxobs=&maxdiff)
585 %webout(OBJ,new,dslabel=fmt_new,fmt=Y,missing=STRING,maxobs=&maxdiff)
586 %webout(OBJ,updates,dslabel=fmt_updates,fmt=Y,missing=STRING,maxobs=&maxdiff)
587 %webout(OBJ,originals,dslabel=fmt_ORIGINALS,fmt=Y,missing=STRING)
588 %webout(CLOSE)
589
590 %if &engine_type=OLEDB %then %do;
591 proc sql; /* needs to be dropped AFTER view execution */
592 drop table &inner_table;
593 %end;
594
595 %return;
596%end;
597
598
599%if &action=APPROVE_TABLE %then %do;
600 %approve:
601 /**
602 * store temp tables so we have a record of diffs
603 * do not change this libname or table name as it is used in some
604 * post approve hooks
605 * for REPLACE loads, temp tables not made, so make them
606 */
607 %if &LOADTYPE=REPLACE %then %do;
608 data work.outds_add; run;
609 data work.outds_mod; run;
610 data work.outds_del; run;
611 %end;
612 libname approve "&mpelocapprovals/&LOAD_REF";
613 data; set &libds;stop;run;
614 %let emptybasetable=&syslast;
615 data approve.ActualDiffs;
616 length _____STATUS_____ $10;
617 if 0 then set &emptybasetable;
618 set work.outds_del (in=_____del)
619 work.outds_add (in=_____new)
620 work.outds_mod (in=_____upd);
621 if _____del then _____STATUS_____='DELETED';
622 else if _____new then _____STATUS_____='NEW';
623 else if _____upd then _____STATUS_____='UPDATED';
624
625 %if %mf_existvar(&libds,&var_txfrom) %then %do;
626 drop &var_txfrom &var_txto;
627 %end;
628 %if %mf_existvar(&libds,&VAR_PROCESSED) %then %do;
629 drop &VAR_PROCESSED;
630 %end;
631 run;
632
633 proc export data=approve.ActualDiffs
634 outfile="&mpelocapprovals/&LOAD_REF/ActualDiffs.csv"
635 dbms=csv
636 replace;
637 run;
638
639 /* update the control table to show table as approved */
640 /* append to mpe_review table */
641 %let apprno=%eval(&num_of_approvals_required-&num_of_approvals_remaining+1);
642 data work.append_review;
643 if 0 then set &mpelib..mpe_review;
644 TABLE_ID="&LOAD_REF";
645 BASE_TABLE="&orig_libds";
646 REVIEW_STATUS_ID="APPROVED";
647 REVIEWED_BY_NM="&user";
648 REVIEWED_ON_DTTM=&sastime;
649 REVIEW_REASON_TXT="APPROVAL &apprno of &num_of_approvals_required";
650 output;
651 stop;
652 run;
653 %mp_lockanytable(LOCK,
654 lib=&mpelib,ds=mpe_review,ref=%str(&LOAD_REF Approval),
655 ctl_ds=&mpelib..mpe_lockanytable
656 )
657 proc append base=&mpelib..mpe_review data=work.append_review;
658 run;
659 %mp_lockanytable(UNLOCK,
660 lib=&mpelib,ds=mpe_review,
661 ctl_ds=&mpelib..mpe_lockanytable
662 )
663
664 /* update mpe_submit table */
665 %mp_lockanytable(LOCK,
666 lib=&mpelib,ds=mpe_submit,ref=%str(&LOAD_REF Approval in auditors/postdata),
667 ctl_ds=&mpelib..mpe_lockanytable
668 )
669 proc sql;
670 update &mpelib..mpe_submit
671 set submit_status_cd='APPROVED',
672 num_of_approvals_remaining=&num_of_approvals_remaining-1,
673 reviewed_by_nm="&user",
674 reviewed_on_dttm=&sastime
675 where table_id="&LOAD_REF";
676 %mp_lockanytable(UNLOCK,
677 lib=&mpelib,ds=mpe_submit,
678 ctl_ds=&mpelib..mpe_lockanytable
679 )
680
681 /* save table to disk (if viya + cas) */
682 %dc_cassave(&libds)
683
684 /* run post-approve hook */
685 %mpe_runhook(POST_APPROVE_HOOK)
686
687 data apPARAMS;
688 AUTHORISED=1;
689 ALREADY_UPDATED=0;
690 ALREADY_UPDATED_DTTM=.;
691 DIFFTIME="&difftime";
692 if &syscc=0 then RESPONSE='SUCCESS!';
693 else response="SYSCC=&syscc.";
694 run;
695
696 %mp_abort(iftrue= (&syscc ne 0)
697 ,mac=&_program 582
698 ,msg=%superq(msg)
699 )
700
701 %mpe_alerts(alert_event=APPROVED
702 , alert_lib=&libref
703 , alert_ds=&ds
704 , dsid=&LOAD_REF
705 )
706
707 %removecolsfromwork(___TMP___MD5)
708 %webout(OPEN)
709 %webout(OBJ,apPARAMS)
710 %webout(CLOSE)
711 %return;
712%end;
713%mend postdata;
714
715%postdata()
716
717/* mp_abort cannot exit cleanly from inside a %include, so an abort there
718 (eg in a hook script run via mp_include) only records the failure in
719 work.mp_abort_errds. mode=INCLUDE picks that up and aborts properly here. */
720%mp_abort(mode=INCLUDE)
721
722%mp_abort(iftrue= (&is_err=1)
723 ,mac=&_program
724 ,msg=%superq(err_msg)
725)
726
727%mpeterm()