Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Two dimensional array with string type keys
#1
Hi!
I am making query to database and I am wondering is it possible to store data into 2 dim array where the keys are not integers but strings. I have tried IStringMap but executing data.Add(key value) requires that "value" must be str type (not another IStringMap). For example my array should be like:
[alpha][PROD_ID]=ab123
[alpha][PROD_NAME]=name_123
[alpha][PROD_QTY]=3
[beta][PROD_ID]=bb456
[beta][PROD_NAME]=name_456
[beta][PROD_QTY]=5

I couldn't find any format to store such array. Maybe it is even possible to ask values like:
value=data[alpha][PROD_QTY] ?

Thanks
#2
QM does not have such arrays.

Several workarounds are possible, but not easy. For example:
Macro Macro2132
Code:
Copy      Help
type T3882 str'KEY str'PROD_ID str'PROD_NAME PROD_QTY
ARRAY(T3882) a
T3882& r

&r=a[]; r.KEY="alpha"
r.PROD_ID="ab123"
r.PROD_NAME="name_123"
r.PROD_QTY=3
&r=a[]; r.KEY="beta"
r.PROD_ID="bb456"
r.PROD_NAME="name_456"
r.PROD_QTY=5

str KEY="ALPHA"
int i
for i 0 a.len
,if a[i].KEY="beta"
,,int value=a[i].PROD_QTY
,,out value
This is slow when there are many items. Can be optimized with IStringMap, need to create class for it.


Forum Jump:


Users browsing this thread: 1 Guest(s)