@abaplint/runtime 2.4.12 → 2.4.14
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.
- package/build/src/binary_search.d.ts +5 -0
- package/build/src/binary_search.js +49 -0
- package/build/src/statements/call_function.js +12 -0
- package/build/src/statements/loop.js +3 -27
- package/build/src/statements/read_table.d.ts +7 -1
- package/build/src/statements/read_table.js +34 -13
- package/build/src/types/data_reference.d.ts +1 -1
- package/build/src/types/field_symbol.d.ts +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { ICharacter } from "./types/_character";
|
|
2
|
+
import { INumeric } from "./types/_numeric";
|
|
3
|
+
export declare function binarySearchFromRow(array: readonly any[], left: number, right: number, keyField: (i: any) => any, keyValue: INumeric | ICharacter): number;
|
|
4
|
+
export declare function binarySearchFrom(array: readonly any[], left: number, right: number, keyField: string, keyValue: INumeric | ICharacter): number;
|
|
5
|
+
export declare function binarySearchTo(array: readonly any[], left: number, right: number, keyField: string, keyValue: INumeric | ICharacter): number;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.binarySearchTo = exports.binarySearchFrom = exports.binarySearchFromRow = void 0;
|
|
4
|
+
/* eslint-disable max-len */
|
|
5
|
+
const compare_1 = require("./compare");
|
|
6
|
+
const types_1 = require("./types");
|
|
7
|
+
function binarySearchFromRow(array, left, right, keyField, keyValue) {
|
|
8
|
+
const isStructured = array[0] instanceof types_1.Structure;
|
|
9
|
+
while (right - left > 1) {
|
|
10
|
+
const middle = Math.floor(((right - left) / 2) + left);
|
|
11
|
+
const a = array[middle];
|
|
12
|
+
const row = isStructured ? Object.assign({ table_line: a }, a.get()) : { table_line: a };
|
|
13
|
+
if ((0, compare_1.ge)(keyField(row), keyValue)) {
|
|
14
|
+
right = middle;
|
|
15
|
+
}
|
|
16
|
+
else {
|
|
17
|
+
left = middle;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
return right;
|
|
21
|
+
}
|
|
22
|
+
exports.binarySearchFromRow = binarySearchFromRow;
|
|
23
|
+
function binarySearchFrom(array, left, right, keyField, keyValue) {
|
|
24
|
+
while (right - left > 1) {
|
|
25
|
+
const middle = Math.floor(((right - left) / 2) + left);
|
|
26
|
+
if ((0, compare_1.ge)(array[middle].get()[keyField], keyValue)) {
|
|
27
|
+
right = middle;
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
left = middle;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return right;
|
|
34
|
+
}
|
|
35
|
+
exports.binarySearchFrom = binarySearchFrom;
|
|
36
|
+
function binarySearchTo(array, left, right, keyField, keyValue) {
|
|
37
|
+
while (right - left > 1) {
|
|
38
|
+
const middle = Math.floor(((right - left) / 2) + left);
|
|
39
|
+
if ((0, compare_1.le)(array[middle].get()[keyField], keyValue)) {
|
|
40
|
+
left = middle;
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
right = middle;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return right;
|
|
47
|
+
}
|
|
48
|
+
exports.binarySearchTo = binarySearchTo;
|
|
49
|
+
//# sourceMappingURL=binary_search.js.map
|
|
@@ -7,6 +7,18 @@ class CallFunction {
|
|
|
7
7
|
}
|
|
8
8
|
// note: this is only called if DESTINIATION is supplied
|
|
9
9
|
async callFunction(options) {
|
|
10
|
+
if (options.destination.trim() === "") {
|
|
11
|
+
const param = {
|
|
12
|
+
exporting: options.exporting,
|
|
13
|
+
importing: options.importing,
|
|
14
|
+
tables: options.tables,
|
|
15
|
+
changing: options.changing,
|
|
16
|
+
exceptions: options.exceptions,
|
|
17
|
+
};
|
|
18
|
+
// @ts-ignore
|
|
19
|
+
await abap.FunctionModules[options.name](param);
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
10
22
|
const dest = this.context.RFCDestinations[options.destination];
|
|
11
23
|
if (dest === undefined) {
|
|
12
24
|
throw new Error(`RFC destination ${options.destination} does not exist`);
|
|
@@ -25,32 +25,8 @@ var __asyncGenerator = (this && this.__asyncGenerator) || function (thisArg, _ar
|
|
|
25
25
|
};
|
|
26
26
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
27
27
|
exports.loop = void 0;
|
|
28
|
-
const
|
|
28
|
+
const binary_search_1 = require("../binary_search");
|
|
29
29
|
const types_1 = require("../types");
|
|
30
|
-
function binarySearchFrom(array, left, right, keyField, keyValue) {
|
|
31
|
-
while (right - left > 1) {
|
|
32
|
-
const middle = Math.floor(((right - left) / 2) + left);
|
|
33
|
-
if ((0, compare_1.ge)(array[middle].get()[keyField], keyValue)) {
|
|
34
|
-
right = middle;
|
|
35
|
-
}
|
|
36
|
-
else {
|
|
37
|
-
left = middle;
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
return right;
|
|
41
|
-
}
|
|
42
|
-
function binarySearchTo(array, left, right, keyField, keyValue) {
|
|
43
|
-
while (right - left > 1) {
|
|
44
|
-
const middle = Math.floor(((right - left) / 2) + left);
|
|
45
|
-
if ((0, compare_1.le)(array[middle].get()[keyField], keyValue)) {
|
|
46
|
-
left = middle;
|
|
47
|
-
}
|
|
48
|
-
else {
|
|
49
|
-
right = middle;
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
return right;
|
|
53
|
-
}
|
|
54
30
|
function determineFromTo(array, topEquals, key) {
|
|
55
31
|
if (topEquals === undefined) {
|
|
56
32
|
// if there is no WHERE supplied, its using the sorting of the secondary key
|
|
@@ -62,8 +38,8 @@ function determineFromTo(array, topEquals, key) {
|
|
|
62
38
|
const keyField = key.keyFields[0].toLowerCase();
|
|
63
39
|
const keyValue = topEquals[keyField];
|
|
64
40
|
if (keyField && keyValue) {
|
|
65
|
-
from = binarySearchFrom(array, from, to, keyField, keyValue);
|
|
66
|
-
to = binarySearchTo(array, from, to, keyField, keyValue);
|
|
41
|
+
from = (0, binary_search_1.binarySearchFrom)(array, from, to, keyField, keyValue);
|
|
42
|
+
to = (0, binary_search_1.binarySearchTo)(array, from, to, keyField, keyValue);
|
|
67
43
|
// console.dir("from: " + from + ", to: " + to);
|
|
68
44
|
}
|
|
69
45
|
return {
|
|
@@ -8,8 +8,14 @@ export interface IReadTableOptions {
|
|
|
8
8
|
from?: INumeric | ICharacter | Structure | Table | DataReference;
|
|
9
9
|
referenceInto?: DataReference;
|
|
10
10
|
assigning?: FieldSymbol;
|
|
11
|
+
binarySearch?: boolean;
|
|
12
|
+
withKeyValue?: {
|
|
13
|
+
key: (i: any) => any;
|
|
14
|
+
value: any;
|
|
15
|
+
}[];
|
|
11
16
|
}
|
|
12
|
-
export declare
|
|
17
|
+
export declare type ReadTableReturn = {
|
|
13
18
|
subrc: number;
|
|
14
19
|
foundIndex: number;
|
|
15
20
|
};
|
|
21
|
+
export declare function readTable(table: Table | FieldSymbol, options?: IReadTableOptions): ReadTableReturn;
|
|
@@ -1,8 +1,27 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.readTable = void 0;
|
|
4
|
+
const binary_search_1 = require("../binary_search");
|
|
4
5
|
const compare_1 = require("../compare");
|
|
5
6
|
const types_1 = require("../types");
|
|
7
|
+
function searchWithKey(arr, withKey, startIndex = 0) {
|
|
8
|
+
const isStructured = arr[0] instanceof types_1.Structure;
|
|
9
|
+
for (let index = startIndex; index < arr.length; index++) {
|
|
10
|
+
const a = arr[index];
|
|
11
|
+
const row = isStructured ? Object.assign({ table_line: a }, a.get()) : { table_line: a };
|
|
12
|
+
if (withKey(row) === true) {
|
|
13
|
+
return {
|
|
14
|
+
found: a,
|
|
15
|
+
foundIndex: index + 1,
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
return {
|
|
20
|
+
found: undefined,
|
|
21
|
+
foundIndex: 0,
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
/////////////////
|
|
6
25
|
function readTable(table, options) {
|
|
7
26
|
var _a, _b;
|
|
8
27
|
let found = undefined;
|
|
@@ -18,19 +37,20 @@ function readTable(table, options) {
|
|
|
18
37
|
foundIndex = index;
|
|
19
38
|
}
|
|
20
39
|
}
|
|
40
|
+
else if ((options === null || options === void 0 ? void 0 : options.binarySearch) === true
|
|
41
|
+
&& options.withKeyValue
|
|
42
|
+
&& options.withKey) {
|
|
43
|
+
// note: it currently only uses the first key field for binary search, todo
|
|
44
|
+
const first = options.withKeyValue[0];
|
|
45
|
+
const startIndex = (0, binary_search_1.binarySearchFromRow)(arr, 0, arr.length, first.key, first.value) - 1;
|
|
46
|
+
const searchResult = searchWithKey(arr, options.withKey, startIndex);
|
|
47
|
+
found = searchResult.found;
|
|
48
|
+
foundIndex = searchResult.foundIndex;
|
|
49
|
+
}
|
|
21
50
|
else if (options === null || options === void 0 ? void 0 : options.withKey) {
|
|
22
|
-
const
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
const row = isStructured ? Object.assign({ table_line: a }, a.get()) : { table_line: a };
|
|
26
|
-
if (options.withKey(row) === true) {
|
|
27
|
-
found = a;
|
|
28
|
-
break;
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
if (found === undefined) {
|
|
32
|
-
foundIndex = 0;
|
|
33
|
-
}
|
|
51
|
+
const searchResult = searchWithKey(arr, options.withKey);
|
|
52
|
+
found = searchResult.found;
|
|
53
|
+
foundIndex = searchResult.foundIndex;
|
|
34
54
|
}
|
|
35
55
|
else if (options === null || options === void 0 ? void 0 : options.from) {
|
|
36
56
|
if (options.from instanceof types_1.FieldSymbol) {
|
|
@@ -69,7 +89,8 @@ function readTable(table, options) {
|
|
|
69
89
|
throw new Error("runtime, readTable, unexpected input");
|
|
70
90
|
}
|
|
71
91
|
let subrc = found ? 0 : 4;
|
|
72
|
-
if ((options === null || options === void 0 ? void 0 : options.from)
|
|
92
|
+
if (((options === null || options === void 0 ? void 0 : options.from) || (options === null || options === void 0 ? void 0 : options.binarySearch) === true)
|
|
93
|
+
&& subrc === 4) {
|
|
73
94
|
subrc = 8;
|
|
74
95
|
}
|
|
75
96
|
// @ts-ignore
|
|
@@ -19,7 +19,7 @@ export declare class DataReference {
|
|
|
19
19
|
clear(): void;
|
|
20
20
|
get(): any;
|
|
21
21
|
array(): any;
|
|
22
|
-
set(value: any): void | Float |
|
|
22
|
+
set(value: any): void | Float | ABAPObject | this | Structure;
|
|
23
23
|
getOffset(input: {
|
|
24
24
|
offset?: number | INumeric | Hex;
|
|
25
25
|
length?: number | INumeric | Hex;
|
|
@@ -18,7 +18,7 @@ export declare class FieldSymbol {
|
|
|
18
18
|
unassign(): void;
|
|
19
19
|
isAssigned(): boolean;
|
|
20
20
|
getPointer(): any;
|
|
21
|
-
dereference(): INumeric | Float | ICharacter |
|
|
21
|
+
dereference(): INumeric | Float | ICharacter | ABAPObject | Table | Structure | undefined;
|
|
22
22
|
clear(): void | Structure | undefined;
|
|
23
23
|
get(): any;
|
|
24
24
|
appendInitial(): import("./table").TableRowType | undefined;
|