Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions packages/runtime/src/statements/insert_internal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
20 changes: 20 additions & 0 deletions test/statements/insert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
});

});
Loading