UNPKG

@abaplint/runtime

Version:
53 lines 1.67 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.updateDatabase = updateDatabase; const prefix_1 = require("../prefix"); const types_1 = require("../types"); const insert_database_1 = require("./insert_database"); async function updateDatabase(table, options, context) { if (options.table instanceof types_1.FieldSymbol) { options.table = options.table.getPointer(); } if (options.from instanceof types_1.FieldSymbol) { options.from = options.from.getPointer(); } if (typeof table !== "string") { table = table.get(); } // @ts-ignore const keys = abap.DDIC[table.toUpperCase()].keyFields; const where = []; const set = []; if (options.from) { const structure = options.from.get(); for (const k of Object.keys(structure)) { const str = k + " = " + (0, insert_database_1.toValue)(structure[k].get()); if (keys.includes(k.toUpperCase())) { where.push(str); } else { set.push(str); } } } else if (options.set) { if (options.where) { where.push(options.where); } set.push(...options.set); } else { throw "updateDatabase, todo"; } const { subrc, dbcnt } = await context.defaultDB().update({ table: (0, prefix_1.buildDbTableName)(table), where: where.join(" AND "), set, }); // @ts-ignore abap.builtin.sy.get().subrc.set(subrc); // @ts-ignore abap.builtin.sy.get().dbcnt.set(dbcnt); return subrc; } //# sourceMappingURL=update_database.js.map