@abaplint/runtime 1.7.33 → 1.7.37

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.
@@ -19,6 +19,8 @@ function append(input) {
19
19
  }
20
20
  }
21
21
  }
22
+ // @ts-ignore
23
+ abap.builtin.sy.get().tabix.set(input.target.array().length);
22
24
  }
23
25
  exports.append = append;
24
26
  //# sourceMappingURL=append.js.map
@@ -1,11 +1,12 @@
1
- import { ABAPObject, DataReference, Structure, Table } from "../types";
1
+ import { ABAPObject, DataReference, FieldSymbol, Structure, Table } from "../types";
2
2
  import { ICharacter } from "../types/_character";
3
3
  import { INumeric } from "../types/_numeric";
4
- declare type PointerType = INumeric | Table | ICharacter | ABAPObject | undefined | Structure;
4
+ declare type PointerType = INumeric | Table | ICharacter | ABAPObject | undefined | Structure | FieldSymbol;
5
5
  export interface ICreateDataOptions {
6
6
  table?: boolean;
7
7
  name?: string;
8
8
  type?: PointerType;
9
+ likeLineOf?: FieldSymbol | Table;
9
10
  }
10
11
  export declare function createData(target: DataReference, options?: ICreateDataOptions): void;
11
12
  export {};
@@ -2,7 +2,9 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.createData = void 0;
4
4
  const clone_1 = require("../clone");
5
+ const types_1 = require("../types");
5
6
  function createData(target, options) {
7
+ // console.dir(options);
6
8
  if ((options === null || options === void 0 ? void 0 : options.name) && (options === null || options === void 0 ? void 0 : options.table)) {
7
9
  // @ts-ignore
8
10
  if (abap.DDIC[options.name] === undefined) {
@@ -30,6 +32,12 @@ function createData(target, options) {
30
32
  else if (options === null || options === void 0 ? void 0 : options.type) {
31
33
  target.assign((0, clone_1.clone)(options.type));
32
34
  }
35
+ else if (options === null || options === void 0 ? void 0 : options.likeLineOf) {
36
+ if (options.likeLineOf instanceof types_1.FieldSymbol) {
37
+ options.likeLineOf = options.likeLineOf.getPointer();
38
+ }
39
+ target.assign((0, clone_1.clone)(options.likeLineOf.getRowType()));
40
+ }
33
41
  else {
34
42
  target.assign((0, clone_1.clone)(target.getType()));
35
43
  }
@@ -19,6 +19,7 @@ import { insertDatabase } from "./insert_database";
19
19
  import { insertInternal } from "./insert_internal";
20
20
  import { loop } from "./loop";
21
21
  import { message } from "./message";
22
+ import { modifyDatabase } from "./modify_database";
22
23
  import { modifyInternal } from "./modify_internal";
23
24
  import { moveCorresponding } from "./move_corresponding";
24
25
  import { readTable } from "./read_table";
@@ -30,6 +31,7 @@ import { shift } from "./shift";
30
31
  import { sort } from "./sort";
31
32
  import { split } from "./split";
32
33
  import { translate } from "./translate";
34
+ import { updateDatabase } from "./update_database";
33
35
  import { write } from "./write";
34
36
  export declare class Statements {
35
37
  append: typeof append;
@@ -55,6 +57,8 @@ export declare class Statements {
55
57
  modifyInternal: typeof modifyInternal;
56
58
  moveCorresponding: typeof moveCorresponding;
57
59
  readTable: typeof readTable;
60
+ updateDatabase: typeof updateDatabase;
61
+ modifyDatabase: typeof modifyDatabase;
58
62
  replace: typeof replace;
59
63
  rollback: typeof rollback;
60
64
  select: typeof select;
@@ -21,6 +21,7 @@ const insert_database_1 = require("./insert_database");
21
21
  const insert_internal_1 = require("./insert_internal");
22
22
  const loop_1 = require("./loop");
23
23
  const message_1 = require("./message");
24
+ const modify_database_1 = require("./modify_database");
24
25
  const modify_internal_1 = require("./modify_internal");
25
26
  const move_corresponding_1 = require("./move_corresponding");
26
27
  const read_table_1 = require("./read_table");
@@ -32,6 +33,7 @@ const shift_1 = require("./shift");
32
33
  const sort_1 = require("./sort");
33
34
  const split_1 = require("./split");
34
35
  const translate_1 = require("./translate");
36
+ const update_database_1 = require("./update_database");
35
37
  const write_1 = require("./write");
36
38
  // this is a class, as statements like SELECT needs access to the database object instance
37
39
  // and WRITE will access the Console
@@ -60,6 +62,8 @@ class Statements {
60
62
  this.modifyInternal = modify_internal_1.modifyInternal;
61
63
  this.moveCorresponding = move_corresponding_1.moveCorresponding;
62
64
  this.readTable = read_table_1.readTable;
65
+ this.updateDatabase = update_database_1.updateDatabase;
66
+ this.modifyDatabase = modify_database_1.modifyDatabase;
63
67
  this.replace = replace_1.replace;
64
68
  this.rollback = rollback_1.rollback;
65
69
  this.select = select_1.select;
@@ -3,4 +3,4 @@ import { ICharacter } from "../types/_character";
3
3
  export interface IInsertDatabaseOptions {
4
4
  values: Structure;
5
5
  }
6
- export declare function insertDatabase(table: string | ICharacter, options: IInsertDatabaseOptions): void;
6
+ export declare function insertDatabase(table: string | ICharacter, options: IInsertDatabaseOptions): number;
@@ -13,18 +13,22 @@ function insertDatabase(table, options) {
13
13
  // todo, integers should not be surrounded by '"'?
14
14
  values.push('"' + structure[k].get() + '"');
15
15
  }
16
+ if (typeof table !== "string") {
17
+ table = table.get();
18
+ }
16
19
  const sql = `INSERT INTO ${table} (${columns.join(",")}) VALUES (${values.join(",")})`;
17
20
  // console.dir(sql);
21
+ let subrc = 0;
18
22
  try {
19
23
  this.db.exec(sql);
20
- // @ts-ignore
21
- abap.builtin.sy.get().subrc.set(0);
22
24
  }
23
25
  catch (error) {
24
26
  // eg "UNIQUE constraint failed" errors
25
- // @ts-ignore
26
- abap.builtin.sy.get().subrc.set(4);
27
+ subrc = 4;
27
28
  }
29
+ // @ts-ignore
30
+ abap.builtin.sy.get().subrc.set(subrc);
31
+ return subrc;
28
32
  }
29
33
  exports.insertDatabase = insertDatabase;
30
34
  //# sourceMappingURL=insert_database.js.map
@@ -5,7 +5,7 @@ export interface IInsertInternalOptions {
5
5
  index?: INumeric;
6
6
  initial?: boolean;
7
7
  data?: INumeric | ICharacter | Structure | ABAPObject | Table | string;
8
- table: Table;
8
+ table: Table | FieldSymbol;
9
9
  referenceInto?: DataReference;
10
10
  assigning?: FieldSymbol;
11
11
  lines?: boolean;
@@ -8,6 +8,9 @@ const read_table_1 = require("./read_table");
8
8
  const sort_1 = require("./sort");
9
9
  function insertInternal(options) {
10
10
  var _a;
11
+ if (options.table instanceof types_1.FieldSymbol) {
12
+ options.table = options.table.getPointer();
13
+ }
11
14
  const tableOptions = options.table.getOptions();
12
15
  const isSorted = (tableOptions === null || tableOptions === void 0 ? void 0 : tableOptions.type) === types_1.TableAccessType.sorted || (tableOptions === null || tableOptions === void 0 ? void 0 : tableOptions.type) === types_1.TableAccessType.hashed;
13
16
  if (isSorted) {
@@ -0,0 +1,7 @@
1
+ import { FieldSymbol, Structure, Table } from "../types";
2
+ import { ICharacter } from "../types/_character";
3
+ export interface IInsertDatabaseOptions {
4
+ from?: Structure | FieldSymbol;
5
+ table?: Table | FieldSymbol;
6
+ }
7
+ export declare function modifyDatabase(table: string | ICharacter, options: IInsertDatabaseOptions): void;
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.modifyDatabase = void 0;
4
+ const types_1 = require("../types");
5
+ const insert_database_1 = require("./insert_database");
6
+ const update_database_1 = require("./update_database");
7
+ function modifyDatabase(table, options) {
8
+ if (this.db === undefined) {
9
+ throw new Error("Runtime, database not initialized");
10
+ }
11
+ if (options.table instanceof types_1.FieldSymbol) {
12
+ options.table = options.table.getPointer();
13
+ }
14
+ if (options.from instanceof types_1.FieldSymbol) {
15
+ options.from = options.from.getPointer();
16
+ }
17
+ if (options.table) {
18
+ for (const row of options.table.array()) {
19
+ const subrc = insert_database_1.insertDatabase.bind(this)(table, { values: row });
20
+ if (subrc !== 0) {
21
+ update_database_1.updateDatabase.bind(this)(table, { from: row });
22
+ }
23
+ }
24
+ }
25
+ else if (options.from) {
26
+ const subrc = insert_database_1.insertDatabase.bind(this)(table, { values: options.from });
27
+ if (subrc !== 0) {
28
+ update_database_1.updateDatabase.bind(this)(table, { from: options.from });
29
+ }
30
+ }
31
+ else {
32
+ throw "modifyDatabase todo";
33
+ }
34
+ }
35
+ exports.modifyDatabase = modifyDatabase;
36
+ //# sourceMappingURL=modify_database.js.map
@@ -0,0 +1,7 @@
1
+ import { FieldSymbol, Structure, Table } from "../types";
2
+ import { ICharacter } from "../types/_character";
3
+ export interface IInsertDatabaseOptions {
4
+ from?: Structure | FieldSymbol;
5
+ table?: Table | FieldSymbol;
6
+ }
7
+ export declare function updateDatabase(table: string | ICharacter, options: IInsertDatabaseOptions): number;
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.updateDatabase = void 0;
4
+ const types_1 = require("../types");
5
+ function updateDatabase(table, options) {
6
+ if (this.db === undefined) {
7
+ throw new Error("Runtime, database not initialized");
8
+ }
9
+ if (options.table instanceof types_1.FieldSymbol) {
10
+ options.table = options.table.getPointer();
11
+ }
12
+ if (options.from instanceof types_1.FieldSymbol) {
13
+ options.from = options.from.getPointer();
14
+ }
15
+ if (typeof table !== "string") {
16
+ table = table.get();
17
+ }
18
+ // @ts-ignore
19
+ const keys = abap.DDIC[table.toUpperCase()].keyFields;
20
+ const where = [];
21
+ const set = [];
22
+ if (options.from) {
23
+ const structure = options.from.get();
24
+ for (const k of Object.keys(structure)) {
25
+ // todo, integers should not be surrounded by '"'?
26
+ const str = k + ' = "' + structure[k].get() + '"';
27
+ if (keys.includes(k.toUpperCase())) {
28
+ where.push(str);
29
+ }
30
+ else {
31
+ set.push(str);
32
+ }
33
+ }
34
+ }
35
+ else {
36
+ throw "updateDatabase, todo";
37
+ }
38
+ const sql = `UPDATE ${table} SET ${set.join(", ")} WHERE ${where.join(" AND ")}`;
39
+ let subrc = 0;
40
+ try {
41
+ this.db.exec(sql);
42
+ }
43
+ catch (error) {
44
+ subrc = 4;
45
+ }
46
+ // @ts-ignore
47
+ abap.builtin.sy.get().subrc.set(subrc);
48
+ return subrc;
49
+ }
50
+ exports.updateDatabase = updateDatabase;
51
+ //# sourceMappingURL=update_database.js.map
@@ -16,6 +16,16 @@ class Integer {
16
16
  this.value = 0;
17
17
  }
18
18
  else if (typeof value === "string") {
19
+ if (/[a-z]/i.test(value) === true) { // todo, match more here?
20
+ // @ts-ignore
21
+ if (abap.Classes["CX_SY_CONVERSION_NO_NUMBER"] !== undefined) {
22
+ // @ts-ignore
23
+ throw new abap.Classes["CX_SY_CONVERSION_NO_NUMBER"]();
24
+ }
25
+ else {
26
+ throw "Global class CX_SY_CONVERSION_NO_NUMBER not found";
27
+ }
28
+ }
19
29
  this.value = parseInt(value, 10);
20
30
  }
21
31
  else if (value instanceof float_1.Float) {
@@ -8,6 +8,7 @@ export declare class Numc implements ICharacter {
8
8
  length?: number;
9
9
  });
10
10
  set(value: INumeric | ICharacter | Hex | string | number): this | undefined;
11
+ getLength(): number;
11
12
  clear(): void;
12
13
  get(): string;
13
14
  }
@@ -28,6 +28,9 @@ class Numc {
28
28
  }
29
29
  return this;
30
30
  }
31
+ getLength() {
32
+ return this.length;
33
+ }
31
34
  clear() {
32
35
  this.value = "0".repeat(this.length);
33
36
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@abaplint/runtime",
3
- "version": "1.7.33",
3
+ "version": "1.7.37",
4
4
  "description": "Transpiler - Runtime",
5
5
  "main": "build/src/index.js",
6
6
  "typings": "build/src/index.d.ts",