@abaplint/runtime 2.7.44 → 2.7.46

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -32,6 +32,7 @@ function readTable(table, options) {
32
32
  var _a, _b, _c, _d;
33
33
  let found = undefined;
34
34
  let foundIndex = 0;
35
+ let binarySubrc = undefined;
35
36
  if (table instanceof types_1.FieldSymbol) {
36
37
  if (table.getPointer() === undefined) {
37
38
  throw new Error("GETWA_NOT_ASSIGNED");
@@ -42,12 +43,28 @@ function readTable(table, options) {
42
43
  if ((options === null || options === void 0 ? void 0 : options.withTableKey) === undefined
43
44
  && (options === null || options === void 0 ? void 0 : options.withKeySimple)
44
45
  && (((_a = table.getOptions().primaryKey) === null || _a === void 0 ? void 0 : _a.keyFields) || []).length > 0) {
45
- const fields = new Set(table.getOptions().primaryKey.keyFields);
46
- for (const name in options.withKeySimple) {
47
- fields.delete(name.toUpperCase());
46
+ if (table instanceof types_1.HashedTable) {
47
+ // hashed tables requires all fields for fast lookup
48
+ const fields = new Set(table.getOptions().primaryKey.keyFields);
49
+ for (const name in options.withKeySimple) {
50
+ fields.delete(name.toUpperCase());
51
+ }
52
+ if (fields.size === 0) {
53
+ options.withTableKey = true;
54
+ }
48
55
  }
49
- if (fields.size === 0) {
50
- options.withTableKey = true;
56
+ else {
57
+ // while sorted just needs the first key field
58
+ const firstKeyField = table.getOptions().primaryKey.keyFields[0];
59
+ let useKey = false;
60
+ for (const name in options.withKeySimple) {
61
+ if (firstKeyField === name.toUpperCase()) {
62
+ useKey = true;
63
+ }
64
+ }
65
+ if (useKey === true) {
66
+ options.withTableKey = true;
67
+ }
51
68
  }
52
69
  }
53
70
  if (options === null || options === void 0 ? void 0 : options.index) {
@@ -97,6 +114,29 @@ function readTable(table, options) {
97
114
  const searchResult = searchWithKey(arr, options.withKey, startIndex, options.usesTableLine);
98
115
  found = searchResult.found;
99
116
  foundIndex = searchResult.foundIndex;
117
+ if (found === undefined) {
118
+ if (arr.length === 0) {
119
+ binarySubrc = 8;
120
+ foundIndex = 1;
121
+ }
122
+ else {
123
+ binarySubrc = 4;
124
+ foundIndex = startIndex + 1;
125
+ // check if going beyond the last row, todo: only checks one field
126
+ const last = arr[arr.length - 1];
127
+ const isStructured = last instanceof types_1.Structure;
128
+ let row = undefined;
129
+ if (options.usesTableLine === false && isStructured === true) {
130
+ row = last.get();
131
+ }
132
+ else {
133
+ row = isStructured ? Object.assign({ table_line: last }, last.get()) : { table_line: last };
134
+ }
135
+ if ((0, compare_1.ge)(first.value, first.key(row))) {
136
+ binarySubrc = 8;
137
+ }
138
+ }
139
+ }
100
140
  }
101
141
  else if (options === null || options === void 0 ? void 0 : options.withKey) {
102
142
  const arr = table.array();
@@ -142,7 +182,10 @@ function readTable(table, options) {
142
182
  throw new Error("runtime, readTable, unexpected input");
143
183
  }
144
184
  let subrc = found ? 0 : 4;
145
- if (((options === null || options === void 0 ? void 0 : options.from) || (options === null || options === void 0 ? void 0 : options.binarySearch) === true || (options === null || options === void 0 ? void 0 : options.keyName) !== undefined)
185
+ if (binarySubrc) {
186
+ subrc = binarySubrc;
187
+ }
188
+ else if (((options === null || options === void 0 ? void 0 : options.from) || (options === null || options === void 0 ? void 0 : options.binarySearch) === true || (options === null || options === void 0 ? void 0 : options.keyName) !== undefined)
146
189
  && subrc === 4) {
147
190
  subrc = 8;
148
191
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@abaplint/runtime",
3
- "version": "2.7.44",
3
+ "version": "2.7.46",
4
4
  "description": "Transpiler - Runtime",
5
5
  "main": "build/src/index.js",
6
6
  "typings": "build/src/index.d.ts",