Loading...
Searching...
No Matches
getstagetable.sas
Go to the documentation of this file.
1/**
2 @file getstagetable.sas
3 @brief Retrieves the actual table that is being sent for update
4 @details Fetches the staged table (unformatted and formatted versions) for
5 a submitted change, given its TABLE_ID.
6
7 <h4> Service Inputs </h4>
8
9 <h5> IWANT </h5>
10 |TABLE_ID:$char32.|
11 |---|
12 |DC20220208T142124517_124703_1184|
13
14 <h4> SAS Macros </h4>
15 @li dc_assignlib.sas
16 @li mp_abort.sas
17 @li mp_applyformats.sas
18 @li mp_getcols.sas
19 @li mp_validatecol.sas
20
21 @version 9.2
22 @author 4GL Apps Ltd
23 @copyright 4GL Apps Ltd. This code may only be used within Data Controller
24 and may not be re-distributed or re-sold without the express permission of
25 4GL Apps Ltd.
26
27**/
28%mpeinit()
29
30/* table_id arrives in the web request (work.iwant) and is used in libname,
31 set and where statements below - so validate it strictly (must be a valid
32 SAS name) before ANY such use, to prevent code injection */
33%let table_id=0;
34data _null_;
35 set work.iwant;
36 %mp_validatecol(table_id,ISNAME,is_name)
37 if is_name=1 then call symputx('table_id',table_id);
38 else putlog 'ERR' 'OR: Invalid table_id: ' table_id;
39 stop;
40run;
41%mp_abort(iftrue= ("&table_id"="0")
42 ,mac=&_program..sas
43 ,msg=%str(Invalid table_id provided)
44)
45
46/* whitelist check - the table_id must also exist in mpe_submit. The same
47 lookup provides the base library & dataset, used further down to source
48 the formats. These are also validated before use in code. */
49%let base_lib=;
50%let base_ds=;
51data _null_;
52 set &mpelib..mpe_submit;
53 where TABLE_ID="&table_id";
54 length base_libds $41;
55 base_libds=cats(base_lib,'.',base_ds);
56 %mp_validatecol(base_libds,LIBDS,is_base_libds)
57 if is_base_libds=1 then do;
58 call symputx('base_lib',base_lib);
59 call symputx('base_ds',base_ds);
60 end;
61 else putlog 'ERR' 'OR: Invalid base libds: ' base_libds;
62run;
63%mp_abort(iftrue= ("&base_lib"="" or "&base_ds"="")
64 ,mac=&_program..sas
65 ,msg=%str(No valid mpe_submit record found for table_id=&table_id)
66)
67
68libname loc "&mpelocapprovals/&table_id";
69data stagetable;
70 set loc.&table_id;
71run;
72
73%mp_abort(iftrue= (&syscc ne 0)
74 ,mac=&_program..sas
75 ,msg=%str(syscc=&syscc)
76)
77
78/* the staged dataset on disk has no formats, so apply those of the base
79 table (sourced from mpe_submit above) to the work copy - this drives the
80 frontend's Formatted/Unformatted toggle */
81%dc_assignlib(READ,&base_lib)
82%mp_getcols(&base_lib..&base_ds,outds=work.basecols)
83data work.stagefmts;
84 set work.basecols;
85 length lib $8 ds $32 var $32 fmt $49;
86 lib='WORK';
87 ds='STAGETABLE';
88 var=name;
89 fmt=format;
90 keep lib ds var fmt;
91run;
92%mp_applyformats(work.stagefmts)
93
94%mp_abort(iftrue= (&syscc ne 0)
95 ,mac=&_program..sas
96 ,msg=%str(syscc=&syscc after applying base formats)
97)
98
99%webout(OPEN)
100%webout(OBJ,stagetable,missing=STRING)
101/* same table again with SAS formats applied */
102%webout(OBJ,stagetable,dslabel=fmt_stagetable,fmt=Y,missing=STRING)
103%webout(CLOSE)
104
105
106%mpeterm()