diff --git a/packages/runtime/src/statements/insert_internal.ts b/packages/runtime/src/statements/insert_internal.ts index 3ecf303fa..50d47ad67 100644 --- a/packages/runtime/src/statements/insert_internal.ts +++ b/packages/runtime/src/statements/insert_internal.ts @@ -114,6 +114,19 @@ export function insertInternal(options: IInsertInternalOptions): void { } } } else if (options.initial === true) { + if (options.table instanceof HashedTable) { + const {value: val, subrc: subrc} = options.table.insert(options.table.getRowType()); + if (subrc === 0) { + if (options.assigning) { + options.assigning.assign(val); + } + if (options.referenceInto) { + options.referenceInto.assign(val); + } + } + abap.builtin.sy.get().subrc.set(subrc); + return; + } let index = options.table.getArrayLength(); if (options.index) { index = options.index.get() - 1; diff --git a/test/statements/insert.ts b/test/statements/insert.ts index 4473853a6..e32e0a35c 100644 --- a/test/statements/insert.ts +++ b/test/statements/insert.ts @@ -339,4 +339,24 @@ WRITE / sy-subrc.`; expect(abap.console.get()).to.equal("0"); }); + it("INSERT INITIAL LINE INTO hashed table", async () => { + const code = ` +TYPES: BEGIN OF ty, + field1 TYPE c LENGTH 10, + field2 TYPE c LENGTH 10, + END OF ty. +TYPES ty2 TYPE HASHED TABLE OF ty WITH UNIQUE KEY field1. +DATA tab2 TYPE ty2. +INSERT INITIAL LINE INTO TABLE tab2. +WRITE / sy-subrc. +WRITE / lines( tab2 ). +INSERT INITIAL LINE INTO TABLE tab2. +WRITE / sy-subrc. +WRITE / lines( tab2 ).`; + const js = await run(code); + const f = new AsyncFunction("abap", js); + await f(abap); + expect(abap.console.get()).to.equal("0\n1\n4\n1"); + }); + }); \ No newline at end of file