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
18 changes: 11 additions & 7 deletions packages/runtime/src/statements/concatenate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,22 @@ export function concatenate(input: IConcatenateInput) {
}

if (input.lines === true) {
const list: string[] = [];
let result = "";
const tab = input.source[0];
if (tab instanceof Table) {
for (const l of tab.array()) {
if (input.respectingBlanks !== true) {
list.push(l.get().trimEnd());
} else {
list.push(l.get());
const array = tab.array();
const length = array.length;
const respectingBlanks = input.respectingBlanks === true;
const hasSeparator = sep.length > 0;
for (let i = 0; i < length; i++) {
if (hasSeparator === true && i > 0) {
result += sep;
}
const value = array[i].get();
result += respectingBlanks === true ? value : value.trimEnd();
}
}
input.target.set(list.join(sep));
input.target.set(result);

} else {
let result = "";
Expand Down
2 changes: 2 additions & 0 deletions performance/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import {test39} from "./test39";
import {test40} from "./test40";
import {test41} from "./test41";
import {test42} from "./test42";
import {test43} from "./test43";

// NOTE: does not run via Mocha

Expand Down Expand Up @@ -102,6 +103,7 @@ const tests: Tests = [
{name: "40: eq string", abap: test40},
{name: "41: eq char, different lengths", abap: test41},
{name: "42: eq int with numc", abap: test42},
{name: "43: CONCATENATE LINES OF", abap: test43},
];

async function execute(t: Test) {
Expand Down
12 changes: 12 additions & 0 deletions performance/test43.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
export const test43 = `
DATA lt_tab TYPE STANDARD TABLE OF string WITH DEFAULT KEY.
DATA lv_str TYPE string.

DO 2000 TIMES.
APPEND 'foobar' TO lt_tab.
ENDDO.

DO 1000 TIMES.
CONCATENATE LINES OF lt_tab INTO lv_str SEPARATED BY ','.
ENDDO.
`;
40 changes: 40 additions & 0 deletions test/statements/concatenate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,46 @@ WRITE count.`;
expect(abap.console.get()).to.equal("5");
});

it("CONCATENATE LINES OF, empty table", async () => {
const code = `
DATA lt_tab TYPE STANDARD TABLE OF string WITH DEFAULT KEY.
DATA res TYPE string.
res = 'foo'.
CONCATENATE LINES OF lt_tab INTO res SEPARATED BY '-'.
ASSERT res IS INITIAL.`;
const js = await run(code);
const f = new AsyncFunction("abap", js);
await f(abap);
});

it("CONCATENATE LINES OF, single line", async () => {
const code = `
DATA lt_tab TYPE STANDARD TABLE OF string WITH DEFAULT KEY.
DATA res TYPE string.
APPEND 'foo' TO lt_tab.
CONCATENATE LINES OF lt_tab INTO res SEPARATED BY '--'.
ASSERT res = 'foo'.`;
const js = await run(code);
const f = new AsyncFunction("abap", js);
await f(abap);
});

it("CONCATENATE LINES OF, char table, trailing blanks removed", async () => {
const code = `
TYPES char5 TYPE c LENGTH 5.
DATA lt_tab TYPE STANDARD TABLE OF char5 WITH DEFAULT KEY.
DATA res TYPE string.
APPEND 'ab' TO lt_tab.
APPEND 'cd' TO lt_tab.
CONCATENATE LINES OF lt_tab INTO res SEPARATED BY '--'.
ASSERT res = 'ab--cd'.
CONCATENATE LINES OF lt_tab INTO res.
ASSERT res = 'abcd'.`;
const js = await run(code);
const f = new AsyncFunction("abap", js);
await f(abap);
});

it("Separated by INTF constant", async () => {
const code = `
INTERFACE lif.
Expand Down
Loading