@abaplint/runtime 2.14.1 → 2.14.3

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.
@@ -0,0 +1,21 @@
1
+ import { FieldSymbol } from "../types";
2
+ import { ICharacter } from "../types/_character";
3
+ import { INumeric } from "../types/_numeric";
4
+ export interface ISubstringSearchInput {
5
+ val: ICharacter | FieldSymbol | string;
6
+ sub?: ICharacter | string;
7
+ regex?: ICharacter | string;
8
+ pcre?: ICharacter | string;
9
+ case?: ICharacter | string;
10
+ occ?: INumeric | number;
11
+ len?: INumeric | number;
12
+ }
13
+ /** The text and the occurrence substring_after( ), _before( ), _from( ) and _to( ) cut at,
14
+ * undefined when there is none. An empty sub or regex and occ = 0 raise CX_SY_STRG_PAR_VAL. */
15
+ export declare function substringOccurrence(input: ISubstringSearchInput): {
16
+ val: string;
17
+ offset: number;
18
+ length: number;
19
+ } | undefined;
20
+ /** len as substring_after( ) and its kin read it: a negative one, or one past the text, is out of bounds */
21
+ export declare function substringLength(len: INumeric | number | undefined, available: number): number | undefined;
@@ -0,0 +1,68 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.substringOccurrence = substringOccurrence;
4
+ exports.substringLength = substringLength;
5
+ const compare_1 = require("../compare");
6
+ const throw_error_1 = require("../throw_error");
7
+ const types_1 = require("../types");
8
+ const _position_1 = require("./_position");
9
+ const find_1 = require("./find");
10
+ /** The text and the occurrence substring_after( ), _before( ), _from( ) and _to( ) cut at,
11
+ * undefined when there is none. An empty sub or regex and occ = 0 raise CX_SY_STRG_PAR_VAL. */
12
+ function substringOccurrence(input) {
13
+ let source;
14
+ if (input.val instanceof types_1.FieldSymbol) {
15
+ const pointer = input.val.getPointer();
16
+ if (pointer === undefined) {
17
+ throw new Error("GETWA_NOT_ASSIGNED");
18
+ }
19
+ source = pointer;
20
+ }
21
+ else {
22
+ source = input.val;
23
+ }
24
+ let val = "";
25
+ if (typeof source === "string") {
26
+ val = source;
27
+ }
28
+ else if (source instanceof types_1.Character) {
29
+ val = source.getTrimEnd();
30
+ }
31
+ else {
32
+ val = source.get();
33
+ }
34
+ const text = (v) => typeof v === "string" ? v : v?.get();
35
+ const regex = text(input.regex) ?? text(input.pcre);
36
+ const sub = text(input.sub);
37
+ if (regex === undefined) {
38
+ if (sub === undefined || sub === "") {
39
+ (0, throw_error_1.throwError)("CX_SY_STRG_PAR_VAL");
40
+ }
41
+ // the same occurrence find( ) answers, from the left or the right, with or without case
42
+ const offset = (0, find_1.find)({ val, sub, occ: input.occ, case: input.case }).get();
43
+ return offset < 0 ? undefined : { val, offset, length: sub.length };
44
+ }
45
+ if (regex === "") {
46
+ (0, throw_error_1.throwError)("CX_SY_STRG_PAR_VAL");
47
+ }
48
+ let occ = (0, _position_1.position)(input.occ) ?? 1;
49
+ if (occ === 0) {
50
+ (0, throw_error_1.throwError)("CX_SY_STRG_PAR_VAL");
51
+ }
52
+ const insensitive = input.case !== undefined && (0, compare_1.initial)(input.case);
53
+ const matches = [...val.matchAll(new RegExp(regex, insensitive ? "gi" : "g"))];
54
+ if (occ < 0) {
55
+ occ = matches.length + occ + 1;
56
+ }
57
+ const match = matches[occ - 1];
58
+ return match === undefined ? undefined : { val, offset: match.index, length: match[0].length };
59
+ }
60
+ /** len as substring_after( ) and its kin read it: a negative one, or one past the text, is out of bounds */
61
+ function substringLength(len, available) {
62
+ const ret = (0, _position_1.position)(len);
63
+ if (ret !== undefined && (ret < 0 || ret > available)) {
64
+ (0, throw_error_1.throwError)("CX_SY_RANGE_OUT_OF_BOUNDS");
65
+ }
66
+ return ret;
67
+ }
68
+ //# sourceMappingURL=_substring_occurrence.js.map
@@ -0,0 +1,9 @@
1
+ import { FieldSymbol, Integer } from "../types";
2
+ import { ICharacter } from "../types/_character";
3
+ export interface IDistanceInput {
4
+ val1: ICharacter | FieldSymbol | string;
5
+ val2: ICharacter | FieldSymbol | string;
6
+ }
7
+ /** Levenshtein distance: the fewest characters to insert, delete or replace to turn val1
8
+ * into val2. Characters are UTF-16 code units, as in ABAP. */
9
+ export declare function distance(input: IDistanceInput): Integer;
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.distance = distance;
4
+ const types_1 = require("../types");
5
+ /** Reads a character-like argument; trailing blanks of a text field (type c) are ignored. */
6
+ function text(input) {
7
+ let source;
8
+ if (input instanceof types_1.FieldSymbol) {
9
+ const pointer = input.getPointer();
10
+ if (pointer === undefined) {
11
+ throw new Error("GETWA_NOT_ASSIGNED");
12
+ }
13
+ source = pointer;
14
+ }
15
+ else {
16
+ source = input;
17
+ }
18
+ if (typeof source === "string") {
19
+ return source;
20
+ }
21
+ else if (source instanceof types_1.Character) {
22
+ return source.getTrimEnd();
23
+ }
24
+ else {
25
+ return source.get();
26
+ }
27
+ }
28
+ /** Levenshtein distance: the fewest characters to insert, delete or replace to turn val1
29
+ * into val2. Characters are UTF-16 code units, as in ABAP. */
30
+ function distance(input) {
31
+ const val1 = text(input.val1);
32
+ const val2 = text(input.val2);
33
+ if (val1 === val2) {
34
+ return new types_1.Integer().set(0);
35
+ }
36
+ let previous = [];
37
+ for (let j = 0; j <= val2.length; j++) {
38
+ previous.push(j);
39
+ }
40
+ for (let i = 1; i <= val1.length; i++) {
41
+ const current = [i];
42
+ for (let j = 1; j <= val2.length; j++) {
43
+ const replace = previous[j - 1] + (val1.charAt(i - 1) === val2.charAt(j - 1) ? 0 : 1);
44
+ current.push(Math.min(previous[j] + 1, current[j - 1] + 1, replace));
45
+ }
46
+ previous = current;
47
+ }
48
+ return new types_1.Integer().set(previous[val2.length]);
49
+ }
50
+ //# sourceMappingURL=distance.js.map
@@ -14,6 +14,7 @@ export * from "./cos";
14
14
  export * from "./cosh";
15
15
  export * from "./count_any_of";
16
16
  export * from "./count";
17
+ export * from "./distance";
17
18
  export * from "./escape";
18
19
  export * from "./exp";
19
20
  export * from "./find";
@@ -31,6 +31,7 @@ __exportStar(require("./cos"), exports);
31
31
  __exportStar(require("./cosh"), exports);
32
32
  __exportStar(require("./count_any_of"), exports);
33
33
  __exportStar(require("./count"), exports);
34
+ __exportStar(require("./distance"), exports);
34
35
  __exportStar(require("./escape"), exports);
35
36
  __exportStar(require("./exp"), exports);
36
37
  __exportStar(require("./find"), exports);
@@ -15,6 +15,11 @@ function dereference(input) {
15
15
  }
16
16
  return input;
17
17
  }
18
+ /** with sub the text is inserted as it is, a replacer function is never read as a pattern;
19
+ * with regex or pcre $1, $& and the like refer to the match */
20
+ function substitute(val, search, wi, literal) {
21
+ return literal ? val.replace(search, () => wi) : val.replace(search, wi);
22
+ }
18
23
  function replace(input) {
19
24
  const source = dereference(input.val);
20
25
  const withSource = dereference(input.with);
@@ -73,13 +78,13 @@ function replace(input) {
73
78
  if (typeof sub === "string") {
74
79
  sub = new RegExp(sub);
75
80
  }
76
- val = val.replace(sub, wi);
81
+ val = substitute(val, sub, wi, regexInput === undefined);
77
82
  }
78
83
  else if (input.occ && (0, _position_1.position)(input.occ) === 0 && sub && wi !== undefined) {
79
84
  if (typeof sub === "string") {
80
85
  sub = new RegExp(sub, "g");
81
86
  }
82
- val = val.replace(sub, wi);
87
+ val = substitute(val, sub, wi, regexInput === undefined);
83
88
  }
84
89
  return new string_1.String().set(val);
85
90
  }
@@ -1,10 +1,4 @@
1
- import { FieldSymbol } from "../types";
2
1
  import { ICharacter } from "../types/_character";
3
- interface ISubstringAfterInput {
4
- val: ICharacter | FieldSymbol | string;
5
- sub?: ICharacter | string;
6
- regex?: ICharacter | string;
7
- pcre?: ICharacter | string;
8
- }
9
- export declare function substring_after(input: ISubstringAfterInput): ICharacter;
10
- export {};
2
+ import { ISubstringSearchInput } from "./_substring_occurrence";
3
+ /** The text after the occurrence occ of sub or regex, at most len characters of it */
4
+ export declare function substring_after(input: ISubstringSearchInput): ICharacter;
@@ -1,50 +1,16 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.substring_after = substring_after;
4
- const abap_regex_1 = require("../abap_regex");
5
- const types_1 = require("../types");
6
4
  const string_1 = require("../types/string");
5
+ const _substring_occurrence_1 = require("./_substring_occurrence");
6
+ /** The text after the occurrence occ of sub or regex, at most len characters of it */
7
7
  function substring_after(input) {
8
- let source;
9
- if (input.val instanceof types_1.FieldSymbol) {
10
- const pointer = input.val.getPointer();
11
- if (pointer === undefined) {
12
- throw new Error("GETWA_NOT_ASSIGNED");
13
- }
14
- source = pointer;
8
+ const found = (0, _substring_occurrence_1.substringOccurrence)(input);
9
+ if (found === undefined) {
10
+ return new string_1.String().set("");
15
11
  }
16
- else {
17
- source = input.val;
18
- }
19
- let val = typeof source === "string" ? source : source.get();
20
- if (source instanceof types_1.Character) {
21
- val = source.getTrimEnd();
22
- }
23
- let reg = "";
24
- if (typeof input.regex === "string") {
25
- reg = input.regex;
26
- }
27
- else if (typeof input.pcre === "string") {
28
- reg = input.pcre;
29
- }
30
- else if (input?.regex) {
31
- reg = input.regex.get();
32
- }
33
- else if (input?.pcre) {
34
- reg = input.pcre.get();
35
- }
36
- else if (typeof input.sub === "string") {
37
- reg = abap_regex_1.ABAPRegExp.escapeRegExp(input.sub);
38
- }
39
- else if (input?.sub) {
40
- reg = abap_regex_1.ABAPRegExp.escapeRegExp(input.sub.get());
41
- }
42
- const r = new RegExp(reg + "([\\s\\S]*)");
43
- const res = val.match(r);
44
- let ret = "";
45
- if (res && res[1]) {
46
- ret = res[1];
47
- }
48
- return new string_1.String().set(ret);
12
+ const start = found.offset + found.length;
13
+ const len = (0, _substring_occurrence_1.substringLength)(input.len, found.val.length - start);
14
+ return new string_1.String().set(found.val.substring(start, len === undefined ? undefined : start + len));
49
15
  }
50
16
  //# sourceMappingURL=substring_after.js.map
@@ -1,7 +1,4 @@
1
- import { FieldSymbol } from "../types";
2
1
  import { ICharacter } from "../types/_character";
3
- export declare function substring_before(input: {
4
- val: ICharacter | FieldSymbol | string;
5
- sub?: ICharacter | string;
6
- regex?: ICharacter | string;
7
- }): ICharacter;
2
+ import { ISubstringSearchInput } from "./_substring_occurrence";
3
+ /** The text before the occurrence occ of sub or regex, the len characters right in front of it */
4
+ export declare function substring_before(input: ISubstringSearchInput): ICharacter;
@@ -1,50 +1,15 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.substring_before = substring_before;
4
- const abap_regex_1 = require("../abap_regex");
5
- const types_1 = require("../types");
6
4
  const string_1 = require("../types/string");
5
+ const _substring_occurrence_1 = require("./_substring_occurrence");
6
+ /** The text before the occurrence occ of sub or regex, the len characters right in front of it */
7
7
  function substring_before(input) {
8
- let source;
9
- if (input.val instanceof types_1.FieldSymbol) {
10
- const pointer = input.val.getPointer();
11
- if (pointer === undefined) {
12
- throw new Error("GETWA_NOT_ASSIGNED");
13
- }
14
- source = pointer;
8
+ const found = (0, _substring_occurrence_1.substringOccurrence)(input);
9
+ if (found === undefined) {
10
+ return new string_1.String().set("");
15
11
  }
16
- else {
17
- source = input.val;
18
- }
19
- let val = "";
20
- if (typeof source === "string") {
21
- val = source;
22
- }
23
- else if (source instanceof types_1.Character) {
24
- val = source.getTrimEnd();
25
- }
26
- else {
27
- val = source.get();
28
- }
29
- let reg = "";
30
- if (typeof input.regex === "string") {
31
- reg = input.regex;
32
- }
33
- else if (input?.regex) {
34
- reg = input.regex.get();
35
- }
36
- else if (typeof input.sub === "string") {
37
- reg = abap_regex_1.ABAPRegExp.escapeRegExp(input.sub);
38
- }
39
- else if (input?.sub) {
40
- reg = abap_regex_1.ABAPRegExp.escapeRegExp(input.sub.get());
41
- }
42
- const r = new RegExp("([\\s\\S]*?)" + reg);
43
- const res = val.match(r);
44
- let ret = "";
45
- if (res && res[1]) {
46
- ret = res[1];
47
- }
48
- return new string_1.String().set(ret);
12
+ const len = (0, _substring_occurrence_1.substringLength)(input.len, found.offset);
13
+ return new string_1.String().set(found.val.substring(len === undefined ? 0 : found.offset - len, found.offset));
49
14
  }
50
15
  //# sourceMappingURL=substring_before.js.map
@@ -53,11 +53,17 @@ function replace(input) {
53
53
  else {
54
54
  rr = input.with.get();
55
55
  }
56
- rr = rr.replace(/\\\$/g, "$");
57
- rr = rr.replace(/\\\{/g, "{");
58
- rr = rr.replace(/\\\}/g, "}");
56
+ if (!input.of) {
57
+ // only a regex replacement reads escapes, REPLACE ... OF inserts the text as it is
58
+ rr = rr.replace(/\\\$/g, "$");
59
+ rr = rr.replace(/\\\{/g, "{");
60
+ rr = rr.replace(/\\\}/g, "}");
61
+ }
62
+ }
63
+ if (input.replacementLength && input.of) {
64
+ input.replacementLength.set(rr.length);
59
65
  }
60
- if (input.replacementLength) {
66
+ else if (input.replacementLength) {
61
67
  const match = temp.match(search);
62
68
  let replacement = rr;
63
69
  for (let counter = 1; counter < 10; counter++) {
@@ -72,7 +78,13 @@ function replace(input) {
72
78
  const match = temp.match(search);
73
79
  input.replacementCount.set(match?.length || 0);
74
80
  }
75
- temp = temp.replace(search, rr);
81
+ if (input.of) {
82
+ // a replacer function, JS reads $&, $$, $1 in a replacement string as patterns
83
+ temp = temp.replace(search, () => rr);
84
+ }
85
+ else {
86
+ temp = temp.replace(search, rr);
87
+ }
76
88
  const subrc = found ? 0 : 4;
77
89
  abap.builtin.sy.get().subrc.set(subrc);
78
90
  input.target.set(temp);
@@ -59,6 +59,10 @@ class Date {
59
59
  return this.value;
60
60
  }
61
61
  getNumeric() {
62
+ // the initial date and content that is not a date, eg. blanks, convert to 0
63
+ if (this.value === "00000000" || /^\d{8}$/.test(this.value) === false) {
64
+ return 0;
65
+ }
62
66
  return (0, _date_helper_1.getNumberFromDate)(this.value);
63
67
  }
64
68
  getOffset(input) {
@@ -2,8 +2,11 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.DecFloat34 = void 0;
4
4
  const _1 = require(".");
5
+ const date_1 = require("./date");
5
6
  const hex_1 = require("./hex");
6
7
  const xstring_1 = require("./xstring");
8
+ const time_1 = require("./time");
9
+ const field_symbol_1 = require("./field_symbol");
7
10
  class DecFloat34 {
8
11
  value;
9
12
  constructor() {
@@ -30,9 +33,24 @@ class DecFloat34 {
30
33
  else if (value instanceof DecFloat34) {
31
34
  this.value = value.getRaw();
32
35
  }
36
+ else if (value instanceof date_1.Date) {
37
+ // d is converted to the number of days since 01.01.0001, not the YYYYMMDD digits
38
+ this.value = value.getNumeric();
39
+ }
33
40
  else if (value instanceof _1.Float) {
34
41
  this.value = value.getRaw();
35
42
  }
43
+ else if (value instanceof field_symbol_1.FieldSymbol) {
44
+ // dispatch on the type the field symbol points to, get() would only give its plain value
45
+ if (value.getPointer() === undefined) {
46
+ throw new Error("GETWA_NOT_ASSIGNED");
47
+ }
48
+ this.set(value.getPointer());
49
+ }
50
+ else if (value instanceof time_1.Time) {
51
+ // t is converted to the number of seconds since midnight, not the HHMMSS digits
52
+ this.value = value.getNumeric();
53
+ }
36
54
  else if (value instanceof hex_1.Hex || value instanceof xstring_1.XString) {
37
55
  // todo, how/if should this work?
38
56
  this.set(parseInt(value.get(), 16));
@@ -2,10 +2,13 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Float = void 0;
4
4
  const throw_error_1 = require("../throw_error");
5
+ const date_1 = require("./date");
5
6
  const hex_1 = require("./hex");
6
7
  const xstring_1 = require("./xstring");
7
8
  const integer8_1 = require("./integer8");
8
9
  const decfloat34_1 = require("./decfloat34");
10
+ const time_1 = require("./time");
11
+ const field_symbol_1 = require("./field_symbol");
9
12
  // A float writes itself out with a comma for the decimal separator, so
10
13
  // reading one back has to accept a comma. Both are allowed rather than only
11
14
  // the comma: ABAP source literals carry a point, `CONV f( '0.25' )` is
@@ -70,6 +73,8 @@ class Float {
70
73
  value = "-" + value.substring(0, value.length - 1);
71
74
  }
72
75
  if (FLOAT_DIGITS.test(value) === false) {
76
+ // a system clears the target before it raises, so the handler sees it initial
77
+ this.value = 0;
73
78
  (0, throw_error_1.throwError)("CX_SY_CONVERSION_NO_NUMBER");
74
79
  }
75
80
  this.value = parseFloat(value.replace(",", "."));
@@ -77,9 +82,24 @@ class Float {
77
82
  else if (value instanceof integer8_1.Integer8) {
78
83
  this.value = Number(value.get());
79
84
  }
85
+ else if (value instanceof date_1.Date) {
86
+ // d is converted to the number of days since 01.01.0001, not the YYYYMMDD digits
87
+ this.value = value.getNumeric();
88
+ }
80
89
  else if (value instanceof Float || value instanceof decfloat34_1.DecFloat34) {
81
90
  this.value = value.getRaw();
82
91
  }
92
+ else if (value instanceof field_symbol_1.FieldSymbol) {
93
+ // dispatch on the type the field symbol points to, get() would only give its plain value
94
+ if (value.getPointer() === undefined) {
95
+ throw new Error("GETWA_NOT_ASSIGNED");
96
+ }
97
+ this.set(value.getPointer());
98
+ }
99
+ else if (value instanceof time_1.Time) {
100
+ // t is converted to the number of seconds since midnight, not the HHMMSS digits
101
+ this.value = value.getNumeric();
102
+ }
83
103
  else if (value instanceof hex_1.Hex || value instanceof xstring_1.XString) {
84
104
  // todo, how/if should this work?
85
105
  this.set(parseInt(value.get(), 16));
@@ -23,6 +23,7 @@ export declare class Integer implements INumeric {
23
23
  getQualifiedName(): string | undefined;
24
24
  clone(): Integer;
25
25
  setConstant(): this;
26
+ private fromText;
26
27
  set(value: INumeric | ICharacter | Hex | string | number | Integer | Float | DecFloat34): this;
27
28
  clear(): void;
28
29
  get(): number;
@@ -4,6 +4,7 @@ exports.Integer = exports.MIN_INTEGER = exports.MAX_INTEGER = exports.DIGITS = v
4
4
  exports.toInteger = toInteger;
5
5
  exports.roundHalfAwayFromZero = roundHalfAwayFromZero;
6
6
  const throw_error_1 = require("../throw_error");
7
+ const date_1 = require("./date");
7
8
  const float_1 = require("./float");
8
9
  const hex_1 = require("./hex");
9
10
  const xstring_1 = require("./xstring");
@@ -12,6 +13,8 @@ const hex_uint8_1 = require("./hex_uint8");
12
13
  const character_1 = require("./character");
13
14
  const string_1 = require("./string");
14
15
  const decfloat34_1 = require("./decfloat34");
16
+ const time_1 = require("./time");
17
+ const field_symbol_1 = require("./field_symbol");
15
18
  exports.DIGITS = new RegExp(/^\s*-?\+?\d+\.?\d* *$/i);
16
19
  exports.MAX_INTEGER = 2147483647;
17
20
  exports.MIN_INTEGER = -2147483648;
@@ -70,6 +73,16 @@ class Integer {
70
73
  this.constant = true;
71
74
  return this;
72
75
  }
76
+ fromText(text) {
77
+ try {
78
+ return toInteger(text);
79
+ }
80
+ catch (e) {
81
+ // a system clears the target before it raises, so the handler sees it initial
82
+ this.value = 0;
83
+ throw e;
84
+ }
85
+ }
73
86
  set(value) {
74
87
  if (this.constant === true) {
75
88
  throw new Error("Changing constant");
@@ -81,17 +94,32 @@ class Integer {
81
94
  this.set(value.get());
82
95
  }
83
96
  else if (value instanceof character_1.Character) {
84
- this.value = toInteger(value.get());
97
+ this.value = this.fromText(value.get());
85
98
  }
86
99
  else if (value instanceof string_1.String) {
87
- this.value = toInteger(value.get());
100
+ this.value = this.fromText(value.get());
88
101
  }
89
102
  else if (value instanceof integer8_1.Integer8) {
90
103
  this.set(Number(value.get()));
91
104
  }
105
+ else if (value instanceof field_symbol_1.FieldSymbol) {
106
+ // dispatch on the type the field symbol points to, get() would only give its plain value
107
+ if (value.getPointer() === undefined) {
108
+ throw new Error("GETWA_NOT_ASSIGNED");
109
+ }
110
+ this.set(value.getPointer());
111
+ }
112
+ else if (value instanceof time_1.Time) {
113
+ // t is converted to the number of seconds since midnight, not the HHMMSS digits
114
+ this.value = value.getNumeric();
115
+ }
92
116
  else if (value instanceof float_1.Float || value instanceof decfloat34_1.DecFloat34) {
93
117
  this.set(roundHalfAwayFromZero(value.getRaw()));
94
118
  }
119
+ else if (value instanceof date_1.Date) {
120
+ // d is converted to the number of days since 01.01.0001, not the YYYYMMDD digits
121
+ this.value = value.getNumeric();
122
+ }
95
123
  else if (value instanceof hex_1.Hex || value instanceof xstring_1.XString || value instanceof hex_uint8_1.HexUInt8) {
96
124
  // the last four bytes, 00 on the left, as a signed integer; an empty xstring is 0
97
125
  const hex = value.get().slice(-8);
@@ -102,7 +130,7 @@ class Integer {
102
130
  this.set(num);
103
131
  }
104
132
  else if (typeof value === "string") {
105
- this.value = toInteger(value);
133
+ this.value = this.fromText(value);
106
134
  }
107
135
  else {
108
136
  this.set(value.get());
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Integer8 = void 0;
4
4
  const throw_error_1 = require("../throw_error");
5
+ const date_1 = require("./date");
5
6
  const float_1 = require("./float");
6
7
  const hex_1 = require("./hex");
7
8
  const xstring_1 = require("./xstring");
@@ -10,6 +11,8 @@ const get_bit_1 = require("../statements/get_bit");
10
11
  const character_1 = require("./character");
11
12
  const hex_uint8_1 = require("./hex_uint8");
12
13
  const decfloat34_1 = require("./decfloat34");
14
+ const time_1 = require("./time");
15
+ const field_symbol_1 = require("./field_symbol");
13
16
  const digits = new RegExp(/^\s*-?\+?\d+\.?\d* *$/i);
14
17
  class Integer8 {
15
18
  value;
@@ -42,13 +45,30 @@ class Integer8 {
42
45
  value = "0";
43
46
  }
44
47
  else if (digits.test(value) === false) {
48
+ // a system clears the target before it raises, so the handler sees it initial
49
+ this.value = 0n;
45
50
  (0, throw_error_1.throwError)("CX_SY_CONVERSION_NO_NUMBER");
46
51
  }
47
52
  this.value = BigInt(value);
48
53
  }
54
+ else if (value instanceof date_1.Date) {
55
+ // d is converted to the number of days since 01.01.0001, not the YYYYMMDD digits
56
+ this.value = BigInt(value.getNumeric());
57
+ }
49
58
  else if (value instanceof float_1.Float || value instanceof decfloat34_1.DecFloat34) {
50
59
  this.set((0, integer_1.roundHalfAwayFromZero)(value.getRaw()));
51
60
  }
61
+ else if (value instanceof field_symbol_1.FieldSymbol) {
62
+ // dispatch on the type the field symbol points to, get() would only give its plain value
63
+ if (value.getPointer() === undefined) {
64
+ throw new Error("GETWA_NOT_ASSIGNED");
65
+ }
66
+ this.set(value.getPointer());
67
+ }
68
+ else if (value instanceof time_1.Time) {
69
+ // t is converted to the number of seconds since midnight, not the HHMMSS digits
70
+ this.value = BigInt(value.getNumeric());
71
+ }
52
72
  else if (value instanceof hex_1.Hex || value instanceof xstring_1.XString || value instanceof hex_uint8_1.HexUInt8) {
53
73
  if (value.get().length === 16) {
54
74
  const lv_bit = new character_1.Character();
@@ -2,9 +2,12 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Packed = void 0;
4
4
  const float_1 = require("./float");
5
+ const date_1 = require("./date");
5
6
  const throw_error_1 = require("../throw_error");
6
7
  const integer8_1 = require("./integer8");
7
8
  const decfloat34_1 = require("./decfloat34");
9
+ const time_1 = require("./time");
10
+ const field_symbol_1 = require("./field_symbol");
8
11
  const digits = new RegExp(/^\s*-?\+?\d*\.?\d*(?:E[+-]?\d+)? *$/i);
9
12
  function pow10(exp) {
10
13
  return 10n ** BigInt(exp);
@@ -104,6 +107,8 @@ class Packed {
104
107
  return this;
105
108
  }
106
109
  else if (digits.test(value) === false) {
110
+ // a system clears the target before it raises, so the handler sees it initial
111
+ this.value = 0n;
107
112
  (0, throw_error_1.throwError)("CX_SY_CONVERSION_NO_NUMBER");
108
113
  }
109
114
  this.value = this.stringToScaled(value);
@@ -111,9 +116,24 @@ class Packed {
111
116
  else if (value instanceof integer8_1.Integer8) {
112
117
  this.value = value.get() * pow10(this.decimals);
113
118
  }
119
+ else if (value instanceof date_1.Date) {
120
+ // d is converted to the number of days since 01.01.0001, not the YYYYMMDD digits
121
+ this.value = BigInt(value.getNumeric()) * pow10(this.decimals);
122
+ }
114
123
  else if (value instanceof float_1.Float || value instanceof decfloat34_1.DecFloat34) {
115
124
  this.value = this.numberToScaled(value.getRaw());
116
125
  }
126
+ else if (value instanceof field_symbol_1.FieldSymbol) {
127
+ // dispatch on the type the field symbol points to, get() would only give its plain value
128
+ if (value.getPointer() === undefined) {
129
+ throw new Error("GETWA_NOT_ASSIGNED");
130
+ }
131
+ this.set(value.getPointer());
132
+ }
133
+ else if (value instanceof time_1.Time) {
134
+ // t is converted to the number of seconds since midnight, not the HHMMSS digits
135
+ this.value = BigInt(value.getNumeric()) * pow10(this.decimals);
136
+ }
117
137
  else {
118
138
  this.set(value.get());
119
139
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@abaplint/runtime",
3
- "version": "2.14.1",
3
+ "version": "2.14.3",
4
4
  "description": "Transpiler - Runtime",
5
5
  "main": "build/src/index.js",
6
6
  "typings": "build/src/index.d.ts",