UNPKG

@abaplint/transpiler

Version:
168 lines • 7.64 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.PopulateTables = void 0; class PopulateTables { hasREPOSRC; hasSEOSUBCO; hasSEOSUBCODF; hasSEOSUBCOTX; hasT000; hasT100; hasTADIR; hasWWWPARAMS; constructor(reg) { this.hasREPOSRC = reg.getObject("TABL", "REPOSRC") !== undefined; this.hasSEOSUBCO = reg.getObject("TABL", "SEOSUBCO") !== undefined; this.hasSEOSUBCODF = reg.getObject("TABL", "SEOSUBCODF") !== undefined; this.hasSEOSUBCOTX = reg.getObject("TABL", "SEOSUBCOTX") !== undefined; this.hasT000 = reg.getObject("TABL", "T000") !== undefined; this.hasT100 = reg.getObject("TABL", "T100") !== undefined; this.hasTADIR = reg.getObject("TABL", "TADIR") !== undefined; this.hasWWWPARAMS = reg.getObject("TABL", "WWWPARAMS") !== undefined; } insertREPOSRC(obj) { if (!this.hasREPOSRC) { return ""; } const name = obj.getName().toUpperCase(); const raw = obj.getMainABAPFile()?.getRaw(); if (raw === undefined) { return ""; } return `INSERT INTO reposrc ('PROGNAME', 'DATA') VALUES ('${name.padEnd(40, " ")}', '${this.escape(raw)}');`; } insertT100(msag) { // ignore if T100 is unknown if (!this.hasT100) { return []; } const ret = []; for (const m of msag.getMessages()) { ret.push(`INSERT INTO "t100" ("sprsl", "arbgb", "msgnr", "text") VALUES ('E', '${msag.getName().padEnd(20, " ")}', '${m.getNumber()}', '${this.escape(m.getMessage().padEnd(73, " "))}');`); } return ret; } insertSEOSUBCO(obj) { const def = obj.getDefinition(); const ret = []; if (def === undefined || !this.hasSEOSUBCO) { return []; } for (const method of def.getMethodDefinitions().getAll()) { for (const parameter of method.getParameters().getAll()) { ret.push(`INSERT INTO "seosubco" ("clsname", "cmpname", "sconame") VALUES ('${obj.getName()}', '${method.getName().toUpperCase()}', '${parameter.getName().toUpperCase()}');`); } } return ret; } insertSEOSUBCODF(obj) { const def = obj.getDefinition(); const ret = []; if (def === undefined || !this.hasSEOSUBCODF) { return []; } for (const method of def.getMethodDefinitions().getAll()) { let editorder = 0; const optionalParameters = method.getParameters().getOptional(); for (const parameter of method.getParameters().getAll()) { editorder++; let pardecltyp = ""; if (parameter.getMeta().includes("importing" /* abaplint.IdentifierMeta.MethodImporting */)) { pardecltyp = "0"; } else if (parameter.getMeta().includes("changing" /* abaplint.IdentifierMeta.MethodChanging */)) { pardecltyp = "2"; } else if (parameter.getMeta().includes("returning" /* abaplint.IdentifierMeta.MethodReturning */)) { pardecltyp = "3"; } else if (parameter.getMeta().includes("exporting" /* abaplint.IdentifierMeta.MethodExporting */)) { pardecltyp = "1"; } const name = parameter.getName().toUpperCase(); const paroptionl = (optionalParameters.some(o => o.toUpperCase() === name) || method.getParameters().getParameterDefault(name) !== undefined) ? "X" : " "; const type = parameter.getType().getQualifiedName()?.toUpperCase() || ""; const parvalue = method.getParameters().getParameterDefault(name)?.concatTokens() || ""; ret.push(`INSERT INTO "seosubcodf" ("clsname", "cmpname", "sconame", "version", "editorder", "pardecltyp", "type", "paroptionl", "parvalue") VALUES ('${obj.getName()}', '${method.getName().toUpperCase()}', '${name}', '1', ${editorder}, '${pardecltyp}', '${type}', '${paroptionl}', '${this.escape(parvalue)}');`); } } return ret; } insertSEOSUBCOTX(obj) { const def = obj.getDefinition(); const ret = []; if (def === undefined || !this.hasSEOSUBCOTX) { return []; } const descriptions = []; const xml = obj.getXML(); if (xml) { const parsed = obj.parseRaw2(); const sub = parsed?.abapGit["asx:abap"]["asx:values"]?.DESCRIPTIONS?.SEOSUBCOTX; if (sub) { if (Array.isArray(sub)) { descriptions.push(...sub); } else { descriptions.push(sub); } } } for (const method of def.getMethodDefinitions().getAll()) { for (const parameter of method.getParameters().getAll()) { const mName = method.getName().toUpperCase(); const pName = parameter.getName().toUpperCase(); let descript = ""; for (const d of descriptions) { if (d.CMPNAME?.toUpperCase() === mName && d.SCONAME?.toUpperCase() === pName) { descript = d.DESCRIPT || ""; break; } } ret.push(`INSERT INTO "seosubcotx" ("clsname", "cmpname", "sconame", "langu", "descript") VALUES ('${obj.getName()}', '${mName}', '${pName}', 'E', '${this.escape(descript)}');`); } } return ret; } insertT000() { if (!this.hasT000) { return ""; } // todo, this should take the client number from the json abap_transpile.json settings return `INSERT INTO t000 ("mandt", "cccategory", "ccnocliind") VALUES ('123', '', '');`; } insertTADIR(obj) { if (!this.hasTADIR) { return ""; } const type = obj.getType().toUpperCase(); const name = obj.getName().toUpperCase(); return `INSERT INTO "tadir" ("pgmid", "object", "obj_name", "devclass", "korrnum", "srcsystem", "delflag", "genflag", "edtflag", "masterlang") VALUES ('R3TR', '${type}', '${this.escape(name)}', '$TMP', '', 'ABC', '', '', '', 'E');`; } insertWWWPARAMS(obj) { if (!this.hasWWWPARAMS) { return []; } const ret = []; const name = obj.getName().toUpperCase(); for (const [key, value] of Object.entries(obj.getParameters())) { ret.push(`INSERT INTO "wwwparams" ("relid", "objid", "name", "value") VALUES ('MI', '${name}', '${this.escape(key)}', '${this.escape(value)}');`); } const value = obj.getDataFile()?.getRaw().length.toString() || "0"; ret.push(`INSERT INTO "wwwparams" ("relid", "objid", "name", "value") VALUES ('MI', '${name}', 'filesize', '${this.escape(value)}');`); const desc = obj.getDescription() || ""; ret.push(`INSERT INTO "wwwparams" ("relid", "objid", "name", "value") VALUES ('MI', '${name}', 'description', '${this.escape(desc)}');`); return ret; } escape(value) { let ret = value.replace(/\'/g, "''"); // statements are inside a javascript string stemplate ret = ret.replace(/\\/g, "\\\\"); ret = ret.replace(/`/g, "\\`"); ret = ret.replace(/\${/g, "\\${"); return ret; } } exports.PopulateTables = PopulateTables; //# sourceMappingURL=populate_tables.js.map