@abaplint/core
Version:
abaplint - Core API
306 lines • 13.4 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Table = exports.TableCategory = exports.EnhancementCategory = void 0;
const Types = require("../abap/types/basic");
const _abstract_object_1 = require("./_abstract_object");
const xml_utils_1 = require("../xml_utils");
const ddic_1 = require("../ddic");
const _typed_identifier_1 = require("../abap/types/_typed_identifier");
const basic_1 = require("../abap/types/basic");
const version_1 = require("../version");
var EnhancementCategory;
(function (EnhancementCategory) {
EnhancementCategory["NotClassified"] = "0";
EnhancementCategory["CannotBeEnhanced"] = "1";
EnhancementCategory["Character"] = "2";
EnhancementCategory["CharacterOrNumeric"] = "3";
EnhancementCategory["Deep"] = "4";
})(EnhancementCategory || (exports.EnhancementCategory = EnhancementCategory = {}));
var TableCategory;
(function (TableCategory) {
TableCategory["Transparent"] = "TRANSP";
TableCategory["Structure"] = "INTTAB";
TableCategory["Cluster"] = "CLUSTER";
TableCategory["Pooled"] = "POOL";
TableCategory["View"] = "VIEW";
TableCategory["Append"] = "APPEND";
})(TableCategory || (exports.TableCategory = TableCategory = {}));
class Table extends _abstract_object_1.AbstractObject {
constructor() {
super(...arguments);
this.parsedType = undefined;
}
getType() {
return "TABL";
}
getDescription() {
var _a;
if (this.parsedData === undefined) {
this.parseXML();
}
return (_a = this.parsedData) === null || _a === void 0 ? void 0 : _a.description;
}
getAllowedNaming() {
let length = 30;
const regex = /^((\/[A-Z_\d]{3,8}\/)|[a-zA-Z0-9]{3})\w+$/;
if (this.getTableCategory() === TableCategory.Transparent) {
length = 16;
}
return {
maxLength: length,
allowNamespace: true,
customRegex: regex,
};
}
setDirty() {
this.parsedData = undefined;
this.parsedType = undefined;
super.setDirty();
}
listKeys(reg) {
if (this.parsedData === undefined) {
this.parseXML();
}
if (this.parsedData === undefined) {
return [];
}
const ret = [];
for (const p of this.parsedData.fields) {
if (p.KEYFLAG === "X" && p.FIELDNAME === ".INCLUDE") {
const lookup = new ddic_1.DDIC(reg).lookupTableOrView(p.PRECFIELD).type;
if (lookup instanceof Types.StructureType) {
for (const c of lookup.getComponents()) {
ret.push(c.name);
}
}
}
else if (p.KEYFLAG === "X") {
ret.push(p.FIELDNAME);
}
}
return ret;
}
parseType(reg) {
var _a, _b;
if (this.parsedData === undefined) {
this.parseXML();
if (this.parsedData === undefined) {
return new Types.UnknownType("Table, parser error");
}
}
if (reg.getConfig().getVersion() === version_1.Version.Cloud
&& this.parsedData.dataClass === "USER3") {
return new Types.UnknownType("Data class = USER3 not allowed in cloud");
}
if (this.parsedType) {
return this.parsedType;
}
const references = [];
const components = [];
const ddic = new ddic_1.DDIC(reg);
for (const field of this.parsedData.fields) {
const comptype = field.COMPTYPE ? field.COMPTYPE : "";
if (comptype === "E") { // data element
const lookup = ddic.lookupDataElement(field.ROLLNAME);
components.push({ name: field.FIELDNAME, type: lookup.type });
if (lookup.object) {
references.push({ object: lookup.object });
}
}
else if (field.FIELDNAME === ".INCLUDE"
|| field.FIELDNAME.startsWith(".INCLU-")) {
if (field.PRECFIELD === undefined) {
return new Types.UnknownType("Table, parser error, PRECFIELD undefined, " + this.getName());
}
const lookup = ddic.lookupTableOrView(field.PRECFIELD);
let found = lookup.type;
if (lookup.object) {
references.push({ object: lookup.object });
}
if (found instanceof _typed_identifier_1.TypedIdentifier) {
found = found.getType();
}
if (found instanceof Types.StructureType) {
if (field.GROUPNAME !== undefined) {
components.push({ name: field.GROUPNAME, type: found, asInclude: true });
}
if (field.FIELDNAME.startsWith(".INCLU-") === false
|| field.FIELDNAME === ".INCLU--AP") {
for (const c of found.getComponents()) {
components.push({ name: c.name, type: c.type });
}
}
}
else if ((((_a = field.PRECFIELD) === null || _a === void 0 ? void 0 : _a.startsWith("CI_")) || ((_b = field.PRECFIELD) === null || _b === void 0 ? void 0 : _b.startsWith("SI_")))
&& found instanceof Types.UnknownType) {
continue;
}
else if (found instanceof Types.UnknownType) {
return found;
}
else if (found instanceof Types.VoidType) {
// set the full structure to void
return found;
}
else {
components.push({ name: field.FIELDNAME, type: found });
}
}
else if (comptype === "S") {
const lookup = ddic.lookupTableOrView(field.ROLLNAME);
components.push({ name: field.FIELDNAME, type: lookup.type });
if (lookup.object) {
references.push({ object: lookup.object });
}
}
else if (comptype === "R") {
if (field.ROLLNAME === undefined) {
throw new Error("Expected ROLLNAME");
}
if (field.ROLLNAME === "DATA") {
components.push({
name: field.FIELDNAME,
type: new basic_1.DataReference(basic_1.AnyType.get())
});
}
else if (field.ROLLNAME === "OBJECT") {
components.push({
name: field.FIELDNAME,
type: new basic_1.GenericObjectReferenceType()
});
}
else if (field.REFTYPE === "S") {
const lookup = ddic.lookupTableOrView(field.ROLLNAME);
components.push({ name: field.FIELDNAME, type: new basic_1.DataReference(lookup.type) });
if (lookup.object) {
references.push({ object: lookup.object });
}
}
else if (field.REFTYPE === "L") {
const lookup = ddic.lookupTableType(field.ROLLNAME);
components.push({ name: field.FIELDNAME, type: new basic_1.DataReference(lookup.type) });
if (lookup.object) {
references.push({ object: lookup.object });
}
}
else if (field.REFTYPE === "E") {
const lookup = ddic.lookupDataElement(field.ROLLNAME);
components.push({ name: field.FIELDNAME, type: new basic_1.DataReference(lookup.type) });
if (lookup.object) {
references.push({ object: lookup.object });
}
}
else {
const lookup = ddic.lookupObject(field.ROLLNAME);
components.push({ name: field.FIELDNAME, type: lookup.type });
if (lookup.object) {
references.push({ object: lookup.object });
}
}
}
else if (comptype === "L") {
const lookup = ddic.lookupTableType(field.ROLLNAME);
components.push({ name: field.FIELDNAME, type: lookup.type });
if (lookup.object) {
references.push({ object: lookup.object });
}
}
else if (comptype === "") { // built in
const datatype = field.DATATYPE;
if (datatype === undefined) {
throw new Error("Expected DATATYPE, while parsing TABL " + this.getName());
}
const length = field.LENG ? field.LENG : field.INTLEN;
components.push({
name: field.FIELDNAME,
type: ddic.textToType({
text: datatype,
length: length,
decimals: field.DECIMALS,
infoText: this.getName() + "-" + field.FIELDNAME,
description: field.DDTEXT,
})
});
}
else {
components.push({
name: field.FIELDNAME,
type: new Types.UnknownType("Table " + this.getName() + ", unknown component type \"" + comptype + "\"")
});
}
if (field.CHECKTABLE) {
const lookup = ddic.lookupTableOrView2(field.CHECKTABLE);
if (lookup) {
references.push({ object: lookup });
}
}
}
if (components.length === 0) {
return new Types.UnknownType("Table/Structure " + this.getName() + " does not contain any components");
}
reg.getDDICReferences().setUsing(this, references);
this.parsedType = new Types.StructureType(components, this.getName(), this.getName(), this.getDescription());
return this.parsedType;
}
getTableCategory() {
var _a;
if (this.parsedData === undefined) {
this.parseXML();
}
return (_a = this.parsedData) === null || _a === void 0 ? void 0 : _a.tableCategory;
}
getEnhancementCategory() {
var _a;
if (this.parsedData === undefined) {
this.parseXML();
}
if (((_a = this.parsedData) === null || _a === void 0 ? void 0 : _a.enhancementCategory) === undefined) {
return EnhancementCategory.NotClassified;
}
return this.parsedData.enhancementCategory;
}
///////////////
parseXML() {
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
const parsed = super.parseRaw2();
if (parsed === undefined) {
return;
}
this.parsedData = { fields: [] };
if (parsed.abapGit === undefined) {
return;
}
// enhancement category
if (((_b = (_a = parsed.abapGit["asx:abap"]["asx:values"]) === null || _a === void 0 ? void 0 : _a.DD02V) === null || _b === void 0 ? void 0 : _b.EXCLASS) === undefined) {
this.parsedData.enhancementCategory = EnhancementCategory.NotClassified;
}
else {
this.parsedData.enhancementCategory = (_d = (_c = parsed.abapGit["asx:abap"]["asx:values"]) === null || _c === void 0 ? void 0 : _c.DD02V) === null || _d === void 0 ? void 0 : _d.EXCLASS;
}
// table category
this.parsedData.tableCategory = (_f = (_e = parsed.abapGit["asx:abap"]["asx:values"]) === null || _e === void 0 ? void 0 : _e.DD02V) === null || _f === void 0 ? void 0 : _f.TABCLASS;
this.parsedData.description = (_h = (_g = parsed.abapGit["asx:abap"]["asx:values"]) === null || _g === void 0 ? void 0 : _g.DD02V) === null || _h === void 0 ? void 0 : _h.DDTEXT;
this.parsedData.dataClass = (_k = (_j = parsed.abapGit["asx:abap"]["asx:values"]) === null || _j === void 0 ? void 0 : _j.DD09L) === null || _k === void 0 ? void 0 : _k.TABART;
// fields
const fields = (_l = parsed.abapGit["asx:abap"]["asx:values"]) === null || _l === void 0 ? void 0 : _l.DD03P_TABLE;
for (const field of (0, xml_utils_1.xmlToArray)(fields === null || fields === void 0 ? void 0 : fields.DD03P)) {
this.parsedData.fields.push({
FIELDNAME: field.FIELDNAME,
ROLLNAME: field.ROLLNAME,
COMPTYPE: field.COMPTYPE,
PRECFIELD: field.PRECFIELD,
LENG: field.LENG,
INTLEN: field.INTLEN,
DATATYPE: field.DATATYPE,
DECIMALS: field.DECIMALS,
KEYFLAG: field.KEYFLAG,
GROUPNAME: field.GROUPNAME,
CHECKTABLE: field.CHECKTABLE,
REFTYPE: field.REFTYPE,
DDTEXT: field.DDTEXT,
});
}
}
}
exports.Table = Table;
//# sourceMappingURL=table.js.map