All files / src/abap/types function_module_definition.ts

69.44% Statements 25/36
55% Branches 11/20
100% Functions 6/6
69.44% Lines 25/36

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 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 1011x   1x 1x 1x 1x 1x                 1x           10x       4x       2x       10x           10x     10x 10x 10x   10x 3x 3x     3x               10x                         10x                         10x 2x 2x     2x                    
import {xmlToArray} from "../../xml_utils";
 
export enum FunctionModuleParameterDirection {
  importing = "importing",
  exporting = "exporting",
  changing = "changing",
  tables = "tables",
}
 
export interface IFunctionModuleParameter {
  name: string;
  direction: FunctionModuleParameterDirection;
  type: string | undefined;
}
 
export class FunctionModuleDefinition {
  private name: string;
  private description: string | undefined;
  private parameters: IFunctionModuleParameter[];
 
  public constructor(data: any) {
    this.parse(data);
  }
 
  public getParameters(): readonly IFunctionModuleParameter[] {
    return this.parameters;
  }
 
  public getDescription(): string | undefined {
    return this.description;
  }
 
  public getName(): string {
    return this.name;
  }
 
///////////////
 
  private parse(data: any) {
    Iif (data.FUNCNAME === undefined) {
      throw new Error("Function module name undefined");
    }
    this.name = data.FUNCNAME;
    this.description = data.SHORT_TEXT;
    this.parameters = [];
 
    if (data.IMPORT) {
      for (const param of xmlToArray(data.IMPORT.RSIMP)) {
        Iif (param.PARAMETER === undefined) {
          throw new Error("Function module name parameter undefined, importing");
        }
        this.parameters.push({
          name: param.PARAMETER,
          direction: FunctionModuleParameterDirection.importing,
          type: param.TYP,
        });
      }
    }
 
    Iif (data.CHANGING) {
      for (const param of xmlToArray(data.CHANGING.RSCHA)) {
        if (param.PARAMETER === undefined) {
          throw new Error("Function module name parameter undefined, changing");
        }
        this.parameters.push({
          name: param.PARAMETER,
          direction: FunctionModuleParameterDirection.changing,
          type: param.TYP,
        });
      }
    }
 
    Iif (data.EXPORT) {
      for (const param of xmlToArray(data.EXPORT.RSEXP)) {
        if (param.PARAMETER === undefined) {
          throw new Error("Function module name parameter undefined, exporting");
        }
        this.parameters.push({
          name: param.PARAMETER,
          direction: FunctionModuleParameterDirection.exporting,
          type: param.TYP,
        });
      }
    }
 
    if (data.TABLES) {
      for (const param of xmlToArray(data.TABLES.RSTBL)) {
        Iif (param.PARAMETER === undefined) {
          throw new Error("Function module name parameter undefined, tables");
        }
        this.parameters.push({
          name: param.PARAMETER,
          direction: FunctionModuleParameterDirection.tables,
          type: param.DBSTRUCT,
        });
      }
    }
 
  }
 
}