All files / src/objects table_type.ts

79.49% Statements 31/39
75% Branches 18/24
71.43% Functions 5/7
79.49% Lines 31/39

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 851x   1x   1x   1x 12x               15x                               11x 11x       7x   7x     7x   7x 2x 5x   5x   5x 1x 4x 4x 4x         7x           7x       7x   7x 7x       7x 7x 7x 7x 7x 7x        
import {AbstractObject} from "./_abstract_object";
import {AbstractType} from "../abap/types/basic/_abstract_type";
import * as Types from "../abap/types/basic";
import {IRegistry} from "../_iregistry";
import {DDIC} from "../ddic";
 
export class TableType extends AbstractObject {
  private parsedXML: {
    rowtype?: string,
    rowkind?: string
    datatype?: string
    leng?: string
    decimals?: string} | undefined = undefined;
 
  public getType(): string {
    return "TTYP";
  }
 
  public getAllowedNaming() {
    return {
      maxLength: 30,
      allowNamespace: true,
    };
  }
 
  public getDescription(): string | undefined {
    // todo
    return undefined;
  }
 
  public setDirty(): void {
    this.parsedXML = undefined;
    super.setDirty();
  }
 
  public parseType(reg: IRegistry): AbstractType {
    this.parseXML();
 
    const ddic = new DDIC(reg);
 
    let type: AbstractType;
    Iif (this.parsedXML === undefined || this.parsedXML === {}) {
      type = new Types.UnknownType("Table Type, parser error", this.getName());
    } else if (this.parsedXML.rowkind === "S") {
      type = new Types.TableType(ddic.lookupTableOrView(this.parsedXML.rowtype), {withHeader: false}, this.getName());
    } else Iif (this.parsedXML.rowkind === "E") {
      type = new Types.TableType(ddic.lookupDataElement(this.parsedXML.rowtype), {withHeader: false}, this.getName());
    } else Iif (this.parsedXML.rowkind === "L") {
      type = new Types.TableType(ddic.lookupTableType(this.parsedXML.rowtype), {withHeader: false}, this.getName());
    } else if (this.parsedXML.rowkind === "R" && this.parsedXML.rowtype !== undefined) {
      type = new Types.TableType(ddic.lookupObject(this.parsedXML.rowtype), {withHeader: false}, this.getName());
    } else Eif (this.parsedXML.rowkind === "") {
      const row = ddic.textToType(this.parsedXML.datatype, this.parsedXML.leng, this.parsedXML.decimals, this.getName(), false);
      type = new Types.TableType(row, {withHeader: false}, this.getName());
    } else {
      type = new Types.UnknownType("Table Type, unknown kind \"" + this.parsedXML.rowkind + "\"" + this.getName(), this.getName());
    }
 
    return type;
  }
 
////////////////////
 
  private parseXML() {
    Iif (this.parsedXML !== undefined) {
      return;
    }
 
    this.parsedXML = {};
 
    const parsed = super.parseRaw2();
    Iif (parsed === undefined) {
      return;
    }
 
    const dd40v = parsed.abapGit["asx:abap"]["asx:values"].DD40V;
    this.parsedXML.rowtype = dd40v.ROWTYPE ? dd40v.ROWTYPE : "";
    this.parsedXML.rowkind = dd40v.ROWKIND ? dd40v.ROWKIND : "";
    this.parsedXML.datatype = dd40v.DATATYPE;
    this.parsedXML.leng = dd40v.LENG;
    this.parsedXML.decimals = dd40v.DECIMALS;
  }
 
}