All files / src/abap/types function_module_definition.ts

72.54% Statements 74/102
53.33% Branches 8/15
100% Functions 5/5
72.54% Lines 74/102

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 101 1021x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 10x 10x 1x 1x 4x 4x 1x 1x 2x 2x 1x 1x 10x 10x 1x 1x 1x 1x 10x     10x 10x 10x 10x 10x 3x 3x     3x 3x 3x 3x 3x 3x 3x 10x 10x                       10x 10x                       10x 10x 2x 2x     2x 2x 2x 2x 2x 2x 2x 2x 10x 10x 1x 1x
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) {
    if (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)) {
        if (param.PARAMETER === undefined) {
          throw new Error("Function module name parameter undefined, importing");
        }
        this.parameters.push({
          name: param.PARAMETER,
          direction: FunctionModuleParameterDirection.importing,
          type: param.TYP || param.DBFIELD,
        });
      }
    }
 
    if (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 || param.DBFIELD,
        });
      }
    }
 
    if (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 || param.DBFIELD,
        });
      }
    }
 
    if (data.TABLES) {
      for (const param of xmlToArray(data.TABLES.RSTBL)) {
        if (param.PARAMETER === undefined) {
          throw new Error("Function module name parameter undefined, tables");
        }
        this.parameters.push({
          name: param.PARAMETER,
          direction: FunctionModuleParameterDirection.tables,
          // table types are stored in TYP
          type: param.DBSTRUCT || param.TYP,
        });
      }
    }
 
  }
 
}