Loading...
Searching...
No Matches
getdynamiccolvals.sas
Go to the documentation of this file.
1/**
2 @file getdynamiccolvals.sas
3 @brief Provide dynamic list of values according to a SAS program or service
4 @details Configuration is made in the MPE_VALIDATIONS table, the dropdown
5 can be either a SOFTSELECT_HOOK or HARDSELECT_HOOK.
6
7 Results are sent in ARRAY format for efficiency.
8
9 <h4> Service Inputs </h4>
10 <h5> SASCONTROLTABLE </h5>
11
12 |LIBDS:$41.|VARIABLE_NM:$32.|
13 |---|---|
14 |DC258467.MPE_SECURITY|SAS_GROUP|
15
16 <h5> SOURCE_ROW </h5>
17
18 This contains the raw values from the source table.
19
20 <h4> Service Outputs </h4>
21
22
23 <h5>DYNAMIC_VALUES</h5>
24 The RAW_VALUE column may be charactor or numeric. If DISPLAY_INDEX is not
25 provided, it is added automatically.
26
27 |DISPLAY_INDEX:best.|DISPLAY_VALUE:$|RAW_VALUE|
28 |---|---|---|
29 |1|$77.43|77.43|
30 |2|$88.43|88.43|
31
32 <h5>DYNAMIC_EXTENDED_VALUES</h5>
33 This table is optional. If provided, it will map the DISPLAY_INDEX from the
34 DYNAMIC_VALUES table to additional column/value pairs, that will be used to
35 populate dropdowns for _other_ cells in the _same_ row.
36
37 Should be used sparingly! The use of large tables here can slow down the
38 browser.
39
40 |DISPLAY_INDEX:best.|EXTRA_COL_NAME:$32.|DISPLAY_VALUE:$|DISPLAY_TYPE:$1.|RAW_VALUE_NUM|RAW_VALUE_CHAR:$5000|
41 |---|---|---|
42 |1|DISCOUNT_RT|"50%"|N|0.5||
43 |1|DISCOUNT_RT|"40%"|N|0.4||
44 |1|DISCOUNT_RT|"30%"|N|0.3||
45 |1|CURRENCY_SYMBOL|"GBP"|C||"GBP"|
46 |1|CURRENCY_SYMBOL|"RSD"|C||"RSD"|
47 |2|DISCOUNT_RT|"50%"|N|0.5||
48 |2|DISCOUNT_RT|"40%"|N|0.4||
49 |2|CURRENCY_SYMBOL|"EUR"|C||"EUR"|
50 |2|CURRENCY_SYMBOL|"HKD"|C||"HKD"|
51
52
53 <h4> SAS Macros </h4>
54 @li dc_assignlib.sas
55 @li dc_getservicecode.sas
56 @li mf_nobs.sas
57 @li mp_abort.sas
58 @li mp_include.sas
59 @li mp_validatecol.sas
60 @li mf_getapploc.sas
61
62
63 @version 9.3
64 @author 4GL Apps Ltd
65 @copyright 4GL Apps Ltd. This code may only be used within Data Controller
66 and may not be re-distributed or re-sold without the express permission of
67 4GL Apps Ltd.
68
69**/
70
71%mpeinit()
72
73/**
74 * Validate inputs
75 */
76%let err_msg=;
77data work.intest;
78 set work.SASCONTROLTABLE;
79
80 /* validate libds */
81 %mp_validatecol(LIBDS,LIBDS,is_libds)
82
83 /* validate varname */
84 is_name=nvalid(variable_nm,'v7');
85 putlog (_all_)(=);
86 if is_libds ne 1 then do;
87 msg='ERR'!!'OR: Invalid libds:'!!libds;
88 call symputx('err_msg',msg);
89 stop;
90 end;
91 else if is_name ne 1 then do;
92 msg='ERR'!!'OR: Invalid name:'!!variable_nm;
93 call symputx('err_msg',msg);
94 stop;
95 end;
96 else do;
97 call symputx('variable_nm',variable_nm);
98 call symputx('libds',libds);
99 end;
100 output;
101 stop;
102run;
103%mp_abort(iftrue= (&syscc ne 0)
104 ,mac=&_program..sas
105 ,msg=%str(syscc=&syscc after reading work.sascontroltable)
106)
107%mp_abort(iftrue= (%mf_nobs(work.intest)=0)
108 ,mac=&_program
109 ,msg=%str(&err_msg)
110)
111
112%dc_assignlib(READ,%scan(&libds,1,.))
113
114/* ensure that work.dynamic_extended_values exists */
115data work.dynamic_extended_values;
116run;
117
118/**
119 * Get the code to execute
120 */
121data work.codetest;
122 set &mpelib..MPE_VALIDATIONS;
123 where &dc_dttmtfmt. lt tx_to
124 and base_lib="%scan(&libds,1,.)"
125 and base_ds="%scan(&libds,2,.)"
126 and base_col="&variable_nm"
127 and RULE_TYPE in ('HARDSELECT_HOOK','SOFTSELECT_HOOK')
128 and RULE_ACTIVE=1;
129 putlog (_all_)(=);
130 if length(rule_value)>1 then do;
131 call symputx('pgmloc',rule_value);
132 if scan(upcase(rule_value),-1,'.')='SAS' then do;
133 call symputx('pgmtype','PGM');
134 call symputx('pgmloc',rule_value);
135 end;
136 else do;
137 apploc="%mf_getapploc()";
138 if substr(rule_value,1,1) ne '/'
139 then rule_value=cats(apploc,'/',rule_value);
140 call symputx('pgmloc',rule_value);
141 call symputx('pgmtype','JOB');
142 end;
143 output;
144 stop;
145 end;
146 else stop;
147run;
148%mp_abort(iftrue= (%mf_nobs(work.codetest)=0)
149 ,mac=&_program
150 ,msg=%str(Hook not found in &mpelib..mpe_validations for &libds..&variable_nm)
151)
152
153%macro getdynamiccolvals();
154%if &pgmtype=PGM %then %do;
155 filename sascode "&pgmloc";
156%end;
157%else %do;
158 %dc_getservicecode(loc=&pgmloc
159 ,outref=sascode
160 )
161%end;
162
163%mend getdynamiccolvals;
164%getdynamiccolvals()
165
166/* execute the dynamic code */
167%mp_include(sascode)
168%mp_abort(mode=INCLUDE)
169
170/* ensure that the DISPLAY_INDEX variable exists */
171data work.dynamic_values;
172 length DISPLAY_INDEX 8 DISPLAY_VALUE $32767;
173 if _n_=1 then call missing(of _all_);
174 set work.dynamic_values;
175 display_index=coalesce(display_index,_n_);
176 keep DISPLAY_INDEX DISPLAY_VALUE RAW_VALUE;
177run;
178
179/* ensure that work.dynamic_extended_values exists with correct types */
180data work.dynamic_extended_values;
181 length DISPLAY_INDEX 8 EXTRA_COL_NAME $32 DISPLAY_VALUE $5000 DISPLAY_TYPE $1
182 RAW_VALUE_NUM 8 RAW_VALUE_CHAR $5000 FORCED_VALUE 8;
183 if _n_=1 then call missing(of _all_);
184 set work.dynamic_extended_values;
185run;
186
187%webout(OPEN)
188%webout(ARR,dynamic_values,fmt=N)
189%webout(ARR,dynamic_extended_values,fmt=N)
190%webout(CLOSE)
191
192%mpeterm()