Skip to content

Instantly share code, notes, and snippets.

@MarkTiedemann
Created June 16, 2024 13:33
Show Gist options
  • Save MarkTiedemann/025f89ad4ae1a4f595830cc58ff417ac to your computer and use it in GitHub Desktop.
Save MarkTiedemann/025f89ad4ae1a4f595830cc58ff417ac to your computer and use it in GitHub Desktop.
Run ABAP in Node
CLASS main DEFINITION
PUBLIC
FINAL
CREATE PUBLIC.
PUBLIC SECTION.
METHODS say_hello
IMPORTING
name TYPE string
RETURNING
VALUE(result) TYPE string.
METHODS run.
PROTECTED SECTION.
PRIVATE SECTION.
ENDCLASS.
CLASS main IMPLEMENTATION.
METHOD say_hello.
result = |Hello, { name }!|.
ENDMETHOD.
METHOD run.
WRITE say_hello( `World` ).
ENDMETHOD.
ENDCLASS.
{
"devDependencies": {
"@abaplint/runtime": "^2.8.27",
"@abaplint/transpiler": "^2.8.27"
}
}
import { readFile } from "node:fs/promises";
import { createContext, runInContext } from "node:vm";
import { ABAP, MemoryConsole } from "@abaplint/runtime";
import { Transpiler } from "@abaplint/transpiler";
const filename = "main.prog.abap";
const contents = await readFile(filename, "utf-8");
const transpiler = new Transpiler();
const result = await transpiler.runRaw([{ filename, contents }]);
const code = result.objects[0].chunk.getCode();
const abap = new ABAP({ console: new MemoryConsole() });
const context = { abap };
createContext(context);
runInContext(code, context);
const main = new context.abap.Classes["MAIN"]();
await main.run();
console.log(context.abap.console.get());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment