Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
larshp committed Jul 7, 2024
1 parent 956eb81 commit 02b174a
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 6 deletions.
11 changes: 5 additions & 6 deletions packages/runtime/src/statements/delete_internal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,11 @@ export async function deleteInternal(target: Table | HashedTable | FieldSymbol,
return;
}

// @ts-ignore
const originalTabix = abap.builtin.sy.get().tabix.get();
// short form, "DELETE tab"
if (options === undefined) {
target.deleteIndex((target as Table).getCurrentLoopIndex());
return;
}

for await (const i of loop(target)) {
// @ts-ignore
Expand All @@ -109,10 +112,6 @@ export async function deleteInternal(target: Table | HashedTable | FieldSymbol,
target.deleteIndex(index);
} else if (options?.from && options.from.get() <= index + 1) {
target.deleteIndex(index);
} else if (options === undefined && originalTabix === index + 1) {
// short form, "DELETE tab"
target.deleteIndex(index);
break;
}
}
}
8 changes: 8 additions & 0 deletions packages/runtime/src/types/table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,14 @@ export class Table implements ITable {
return l;
}

public getCurrentLoopIndex() {
if (this.loops.size !== 1) {
throw new Error("More than one LOOP");
}

return Array.from(this.loops)[0].index;
}

public unregisterLoop(loop: LoopController) {
this.loops.delete(loop);
}
Expand Down
32 changes: 32 additions & 0 deletions test/statements/delete_internal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,38 @@ LOOP AT tab TRANSPORTING NO FIELDS WHERE field <= 5.
EXIT.
ENDLOOP.
LOOP AT tab INTO row.
WRITE / row-field.
ENDLOOP.`;
const js = await run(code);
const f = new AsyncFunction("abap", js);
await f(abap);
expect(abap.console.get()).to.equal("6\n3\n10");
});

it("DELETE, messing with sy-tabix", async () => {
const code = `
TYPES: BEGIN OF ty,
field TYPE i,
END OF ty.
DATA tab TYPE STANDARD TABLE OF ty WITH DEFAULT KEY.
DATA row LIKE LINE OF tab.
row-field = 6.
INSERT row INTO TABLE tab.
row-field = 3.
INSERT row INTO TABLE tab.
row-field = 3.
INSERT row INTO TABLE tab.
row-field = 10.
INSERT row INTO TABLE tab.
LOOP AT tab TRANSPORTING NO FIELDS WHERE field <= 5.
sy-tabix = 1.
DELETE tab.
EXIT.
ENDLOOP.
LOOP AT tab INTO row.
WRITE / row-field.
ENDLOOP.`;
Expand Down

0 comments on commit 02b174a

Please sign in to comment.