From acd40b6aa03e688124d05648294331552fa3b235 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 30 Jul 2026 11:02:36 +0000 Subject: [PATCH 1/2] Initial plan From ce2e5e049f83d55e5f27e570c0bc587c3b78ae59 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 30 Jul 2026 11:07:18 +0000 Subject: [PATCH 2/2] Fix hex to int conversion sign handling for offsets/xstring --- packages/runtime/src/types/integer.ts | 10 ++++---- test/types/integer.ts | 33 +++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 5 deletions(-) diff --git a/packages/runtime/src/types/integer.ts b/packages/runtime/src/types/integer.ts index 674e5884d..e304a3872 100644 --- a/packages/runtime/src/types/integer.ts +++ b/packages/runtime/src/types/integer.ts @@ -88,11 +88,11 @@ export class Integer implements INumeric { } else if (value instanceof Float || value instanceof DecFloat34) { this.set(Math.round(value.getRaw())); } else if (value instanceof Hex || value instanceof XString || value instanceof HexUInt8) { - let num = parseInt(value.get(), 16); -// handle two complement, - if ((value instanceof Hex || value instanceof HexUInt8) - && value.getLength() >= 4) { - const maxVal = Math.pow(2, value.get().length / 2 * 8); + const hex = value.get(); + let num = parseInt(hex, 16); +// handle two complement, the first bit is the sign + if (hex.length >= 8) { + const maxVal = Math.pow(2, hex.length / 2 * 8); if (num > maxVal / 2 - 1) { num = num - maxVal; } diff --git a/test/types/integer.ts b/test/types/integer.ts index 5fd92ecf9..e63075cea 100644 --- a/test/types/integer.ts +++ b/test/types/integer.ts @@ -173,6 +173,39 @@ describe("Running Examples - Integer type", () => { expect(abap.console.get()).to.equal("45141"); }); + it("hex to int, first bit is the sign", async () => { + const code = ` + DATA lv_hex TYPE x LENGTH 4 VALUE 'FFFFFFFF'. + DATA lv_int TYPE i. + lv_int = lv_hex. + ASSERT lv_int = -1.`; + const js = await run(code); + const f = new AsyncFunction("abap", js); + await f(abap); + }); + + it("hex offset to int, first bit is the sign", async () => { + const code = ` + DATA lv_hex TYPE x LENGTH 5 VALUE '00FFFFFFFF'. + DATA lv_int TYPE i. + lv_int = lv_hex+1. + ASSERT lv_int = -1.`; + const js = await run(code); + const f = new AsyncFunction("abap", js); + await f(abap); + }); + + it("hex offset length to int, positive", async () => { + const code = ` + DATA lv_hex TYPE x LENGTH 5 VALUE '00FFFFFFFF'. + DATA lv_int TYPE i. + lv_int = lv_hex+1(2). + ASSERT lv_int = 65535.`; + const js = await run(code); + const f = new AsyncFunction("abap", js); + await f(abap); + }); + it("preceding zeros", async () => { const code = ` DATA int TYPE i.