All files / src/abap/5_syntax/statements read_table.ts

97.5% Statements 39/40
87.5% Branches 21/24
100% Functions 1/1
97.5% Lines 39/40

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 731x     1x 1x 1x 1x 1x 1x     1x     13x   13x 13x 4x     13x 13x 13x   13x   13x   13x 1x     12x 11x     12x 20x 12x   8x     11x 11x 10x 10x 2x 2x     8x 8x 3x 2x                   5x 5x 3x 2x        
import * as Expressions from "../../2_statements/expressions";
import {StatementNode} from "../../nodes";
import {CurrentScope} from "../_current_scope";
import {VoidType, TableType} from "../../types/basic";
import {Source} from "../expressions/source";
import {InlineData} from "../expressions/inline_data";
import {Target} from "../expressions/target";
import {FSTarget} from "../expressions/fstarget";
import {ComponentCompareSimple} from "../expressions/component_compare_simple";
import {StatementSyntax} from "../_statement_syntax";
 
export class ReadTable implements StatementSyntax {
  public runSyntax(node: StatementNode, scope: CurrentScope, filename: string): void {
 
    const sources = node.findDirectExpressions(Expressions.Source);
 
    const components = node.findDirectExpression(Expressions.ComponentCompareSimple);
    if (components !== undefined) {
      new ComponentCompareSimple().runSyntax(components, scope, filename);
    }
 
    let firstSource = node.findDirectExpression(Expressions.SimpleSource2);
    Eif (firstSource === undefined) {
      firstSource = sources[0];
    }
    let sourceType = firstSource ? new Source().runSyntax(firstSource, scope, filename) : undefined;
 
    Iif (sourceType === undefined) {
      throw new Error("No source type determined, read table");
    } else if (!(sourceType instanceof TableType) && !(sourceType instanceof VoidType)) {
      throw new Error("Read table, not a table type");
    }
 
    if (sourceType instanceof TableType) {
      sourceType = sourceType.getRowType();
    }
 
    for (const s of sources) {
      if (s === firstSource) {
        continue;
      }
      new Source().runSyntax(s, scope, filename);
    }
 
    const target = node.findDirectExpression(Expressions.ReadTableTarget);
    if (target) {
      const inline = target.findFirstExpression(Expressions.InlineData);
      if (inline) {
        new InlineData().runSyntax(inline, scope, filename, sourceType);
        return;
      }
 
      const fst = target.findDirectExpression(Expressions.FSTarget);
      if (fst) {
        new FSTarget().runSyntax(fst, scope, filename, sourceType);
        return;
      }
/*
      const inlinefs = target.findFirstExpression(Expressions.InlineFS);
      if (inlinefs) {
        new InlineFS().runSyntax(inlinefs, scope, filename, sourceType);
        return;
      }
*/
 
      const t = target.findFirstExpression(Expressions.Target);
      if (t) {
        new Target().runSyntax(t, scope, filename);
        return;
      }
    }
  }
}