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